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

//the global file operation

// 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');
	//Supplier
	require_once('../models/dao/SupplierDAO.class.php');
	require_once('../models/dto/Supplier.class.php');
	require_once('../models/mysql/SupplierMySqlDAO.class.php');
	require_once('../models/mysql/ext/SupplierMySqlExtDAO.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");

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

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

$mProductHistoryEX = new MProducthistoryMySqlExtDAO();

$supplierDAO = new SupplierMySqlDAO();

$MComreceiptDetailEX = new MComreceiptdetailMySqlExtDAO();
//check and use the condetion that suite this action
if (empty($do)||$do=="all") {
    //print_r('branchId='.$_SESSION['branchId']);
	$checkData=$mCheckEX->queryByBranchEX($_SESSION['branchId']);
	foreach($checkData as $row)
	{
		$data =$mProductHistoryEX->GetStatusOfSerialWithMaxDate($row->ourSerial);
		/*print_r('<pre>');
	print_r($data);
	print_r('</pre>');*/
		$row->productHistoryStatus = $data->status;
		$row->stageFrom = $data->stageFrom;
		$row->m_stageTitle = $data->stageTitle;
		
		$mydata=$MComreceiptDetailEX->getProblemAndcommentByOurserialEX($row->ourSerial);
		$row->problem = $mydata->problem;
		$row->comment = $mydata->comment;
	}
	
	$suppliers=$supplierDAO->queryAll();
	$today = date("Y-m-d");
	$smarty->assign("today",$today);
	$smarty->assign("suppliers",$suppliers);
	$smarty->assign("checkData",$checkData);
	/*print_r('<pre>');
	print_r($checkData);
	print_r('</pre>');*/
	
	
	
	$smarty->assign("title1",'الصيانة');
	$smarty->assign("title2",'إدارة الفحص');
	$smarty->assign("title3",'عرض المنتجات تحت الفحص ');
	$smarty->assign("link",'#');
	$smarty->display("maintennanceHeader.html");
	
	
    $smarty->display("checkReportView/checkReport.html");
}
//here the global templates
$smarty->assign("customValidation",1);
$smarty->assign("customCheckReport",1);
$smarty->assign("GeneralSearch",1);
$smarty->display("footer.html");

////****************************  Functions  ********************///
?>