<?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");

require_once('../models/dao/CostcenterDAO.class.php');
require_once('../models/dto/Costcenter.class.php');
require_once('../models/mysql/CostcenterMySqlDAO.class.php');
require_once('../models/mysql/ext/CostcenterMySqlExtDAO.class.php');
require_once('../models/dao/CostcenterdetailDAO.class.php');
require_once('../models/dto/Costcenterdetail.class.php');
require_once('../models/mysql/CostcenterdetailMySqlDAO.class.php');
require_once('../models/mysql/ext/CostcenterdetailMySqlExtDAO.class.php');

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

/* ======================

  Controller Name :- clientTypeCTRL

  OPERTATION in Controller

  1-
  2-
  3-
  4-

  ======================== */
$userID = $_SESSION['userid'];

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

//here goes the instances and general variables

$Costcenterdetail = new Costcenterdetail();
$CostcenterdetailDAO = new CostcenterdetailMySqlDAO();
$CostcenterdetailEX = new CostcenterdetailMySqlExtDAO();

//Costcenter
$Costcenter = new Costcenter();
$CostcenterDAO = new CostcenterMySqlDAO();
$CostcenterEX = new CostcenterMySqlExtDAO();




//check and use the condetion that suite this action
if (empty($do)) {
    $allCostCenter = $CostcenterDAO->queryByCondation(0);
    $smarty->assign("allCostCenter", $allCostCenter);

    $smarty->display("costcenterview/report.html");

  } elseif ($do == "search") {

global $CostcenterdetailEX;

    $costCenterId = filter_input(INPUT_POST, 'costCenterId');
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $details = filter_input(INPUT_POST, 'detail');








$costcenter = " where 1 "; 

if ($start_date != '' &&  $end_date  != '' ) {
    $costcenter .= '  and  costdate  >= "' . $start_date . '" and costdate <= "' . $end_date . '" and costcenterid = "' . $costCenterId . '"' ;
} else {
    if ($start_date != '') {
        $costcenter .= 'and  costdate  >= "' . $start_date . '" and costcenterid = "' . $costCenterId . '"';
       
    }
    if ($end_date != '') {
       
        $costcenter .= 'and  costdate  <= "' . $end_date . '" and costcenterid = "' . $costCenterId . '"';
       
    }
}


$today = date('Y-m-d');
if ($costcenter == " where 1 ") {
    $costcenter .= '  and  costdate  >= "' . $today . '" and costdate <= "' . $today . '" and costcenterid = "' . $costCenterId . '"'   ;
}



$allDetails = $CostcenterdetailEX->getbydate($costcenter);





$smarty->assign("details", $details);

$smarty->assign("allDetails", $allDetails);

    $allCostCenter = $CostcenterDAO->queryByCondation(0);
    $smarty->assign("allCostCenter", $allCostCenter);


    $smarty->display("costcenterview/report.html");
} elseif ($_GET['do'] == "sucess") {
    $smarty->display("succes.html");
} elseif ($_GET['do'] == "error") {
    $smarty->display("error.html");
}



$smarty->assign("customValidation", 1);

$smarty->display("footer.html");
?>