<?php

//the global file operation
include("../public/impOpreation.php");

// get the config file 
include_once("../public/config.php");

//here the db files that include in the file
include("../public/include_dao.php");
	//MCheck
	require_once('../models/dao/MCheckDAO.class.php');
	require_once('../models/dto/MCheck.class.php');
	require_once('../models/mysql/MCheckMySqlDAO.class.php');
	require_once('../models/mysql/ext/MCheckMySqlExtDAO.class.php');
	//MProducthistory
	require_once('../models/dao/MProducthistoryDAO.class.php');
	require_once('../models/dto/MProducthistory.class.php');
	require_once('../models/mysql/MProducthistoryMySqlDAO.class.php');
	require_once('../models/mysql/ext/MProducthistoryMySqlExtDAO.class.php');
	
	//MComreceipt
	require_once('../models/dao/MComreceiptDAO.class.php');
	require_once('../models/dto/MComreceipt.class.php');
	require_once('../models/mysql/MComreceiptMySqlDAO.class.php');
	require_once('../models/mysql/ext/MComreceiptMySqlExtDAO.class.php');
	
	//MComreceiptdetail
	require_once('../models/dao/MComreceiptdetailDAO.class.php');
	require_once('../models/dto/MComreceiptdetail.class.php');
	require_once('../models/mysql/MComreceiptdetailMySqlDAO.class.php');
	require_once('../models/mysql/ext/MComreceiptdetailMySqlExtDAO.class.php');
	

//get the do the action 
$do = $_GET['do'];

//here the global templates
$smarty->display("header.html");
//$smarty->display("maintennanceHeader.html");

//here goes the instances and general variables
//$mCheckDAO = new MCheckMySqlDAO();
$mCheckEX = new MCheckMySqlExtDAO();

$MProductHistory = new MProducthistory();
$MProductHistoryDAO = new MProducthistoryMySqlDAO();
$mProductHistoryEX = new MProducthistoryMySqlExtDAO();

//$supplierDAO = new SupplierMySqlDAO();

$MComreceipt = new MComreceipt();
$MComreceiptDAO = new MComreceiptMySqlDAO();
$MComreceiptEX = new MComreceiptMySqlExtDAO();
	
$MComreceiptDetailEX = new MComreceiptdetailMySqlExtDAO();
//check and use the condetion that suite this action
if (empty($do)||$do=="all") {
    
	
	
	$allReceiptSerials=$MComreceiptDetailEX->getRecitSerialsByBranchEX($_SESSION['branchId']);
	$smarty->assign("allReceiptSerials",$allReceiptSerials);
	
	$serials=$MComreceiptDetailEX->getSerialsByBranchEX($_SESSION['branchId']);
	$smarty->assign("serials",$serials);
	
	$clients=$MComreceiptDetailEX->getClientsByBranchEX($_SESSION['branchId']);
	$smarty->assign("clients",$clients);
	
	$receiptSerial=$_POST["receiptSerial"];
	$ourserial=$_POST["ourserial"];
	$clientid=$_POST["clientid"];
	$queryString = '';
	
	if(isset($receiptSerial)&&$receiptSerial!=-1)
	{
		$queryString .= ' AND  m_comreceipt.receiptserial = '.$receiptSerial;
	}
	
	if(isset($ourserial)&&$ourserial!=-1)
	{
		$queryString .= ' AND  m_comreceiptdetail.ourserial = "'.$ourserial.'"';
	}
	
	if(isset($clientid)&&$clientid!=-1)
	{
		$queryString .= ' AND  client.clientid = '.$clientid;
	}
	
	if($queryString != '')
	{
		$queryString .= ' AND  m_comreceiptdetail.branchid = '.$_SESSION['branchId'];
		$archiveData=$MComreceiptDetailEX->queryByBranchInDetailEX3($queryString);
		$smarty->assign("archiveData",$archiveData);
	}
		
	
	/*$today = date("Y-m-d");
	$smarty->assign("today",$today);*/
	
	/*print_r('<pre>');
	print_r($clients);
	print_r('</pre>');*/
	
	
	 $smarty->assign("title1",'الصيانة');
	 $smarty->assign("title2",'ادارة التسليم');
	 $smarty->assign("title3",' عرض المنتجات');
	 $smarty->assign("link",'#');
	 $smarty->display("maintennanceHeader.html");
	 
	 
	
    $smarty->display("maintennanceArchiveView/maintennanceArchive.html");
}
$smarty->assign("GeneralSearch",1);
$smarty->display("footer.html");

////****************************  Functions  ********************///

?>