<?php

session_start();
ob_start();


//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// 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/sql/Connection.class.php');
require_once('../models/sql/ConnectionFactory.class.php');
require_once('../models/sql/ConnectionProperty.class.php');
require_once('../models/sql/QueryExecutor.class.php');
require_once('../models/sql/Transaction.class.php');
require_once('../models/sql/SqlQuery.class.php');
require_once('../models/core/ArrayList.class.php');
require_once('../models/dao/DAOFactory.class.php');

require_once('../models/dao/EmployeepersonnelDAO.class.php');
require_once('../models/dto/Employeepersonnel.class.php');
require_once('../models/mysql/EmployeepersonnelMySqlDAO.class.php');
require_once('../models/mysql/ext/EmployeepersonnelMySqlExtDAO.class.php');

require_once('../models/dao/SaveDAO.class.php');
require_once('../models/dto/Save.class.php');
require_once('../models/mysql/SaveMySqlDAO.class.php');
require_once('../models/mysql/ext/SaveMySqlExtDAO.class.php');

require_once('../models/dao/SalaryreportDAO.class.php');
require_once('../models/dto/Salaryreport.class.php');
require_once('../models/mysql/SalaryreportMySqlDAO.class.php');
require_once('../models/mysql/ext/SalaryreportMySqlExtDAO.class.php');

require_once('../models/dao/SavedailyDAO.class.php');
require_once('../models/dto/Savedaily.class.php');
require_once('../models/mysql/SavedailyMySqlDAO.class.php');
require_once('../models/mysql/ext/SavedailyMySqlExtDAO.class.php');

require_once('../models/dao/EmployeeDAO.class.php');
require_once('../models/dto/Employee.class.php');
require_once('../models/mysql/EmployeeMySqlDAO.class.php');
require_once('../models/mysql/ext/EmployeeMySqlExtDAO.class.php');

//save dailay
require_once('../models/dao/SavedailyDAO.class.php');
require_once('../models/dto/Savedaily.class.php');
require_once('../models/mysql/SavedailyMySqlDAO.class.php');
require_once('../models/mysql/ext/SavedailyMySqlExtDAO.class.php');








//$saveId=$BranchDAO->querysaveid($_SESSION['branchid']);
//creat object from employeePersonal
$EmployeepersonnelDAO = new EmployeepersonnelMySqlDAO();
$Employeepersonnel = new Employeepersonnel();
$EmployeepersonnelEX = new EmployeepersonnelMySqlExtDAO();




//save
$mySave = new Save();
$mySaveRecord = new SaveMySqlDAO();
$mySaveEx = new SaveMySqlExtDAO();
//savedaily
$mySavedaily = new Savedaily();
$mySavedailyRecord = new SavedailyMySqlDAO();
$mySavedailyEx = new SavedailyMySqlExtDAO();



//creat object from employee
$empDao = new EmployeeMySqlDAO();
$emp = new Employee();
$empEX = $myEmpEX = new EmployeeMySqlExtDAO();

$salaryReportDAO = new SalaryreportMySqlDAO;
$salaryReport = new Salaryreport;

//create object from savedailay
$SavedailyDAO = new SavedailyMySqlDAO();
$Savedaily = new Savedaily();
$SavedailyEX = new SavedailyMySqlExtDAO();

$do = $_GET['do'];


//dispaly  add form
if (!isset($_GET['do'])) {

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


    //echo 'kkkkkkkkkkkkkkkk';
    $id = $_GET["id"];

    $myempdata = $empDao->load($id);

    echo $myempdata->empdept;
}elseif ($do == "absentEmploye") {


        $id = filter_input(INPUT_POST, 'id');

        $employes = $empEX->queryAllFromdayhistoty($id);
        echo json_encode($employes);


} elseif ($do == "getNetSalary") {
    $id = $_GET["id"];
    //$myempdata = $empDao->load($id);

    $today = date("Y-m-d");
    $from = date("Y-m");
    if ($from != "") {
        $start = $from . '-01';
        $end = $from . '-31';
        //
        $x[] = array();
        $allsalarys = $myEmpEX->getall($id);

        if ($allsalarys->employeeBouns == null || $allsalarys->employeeBouns == "") {
            $allsalarys->employeeBouns = 0;
        }
        if ($allsalarys->empdept == null || $allsalarys->empdept == "" || $allsalarys->empdept == 0) {
            $allsalarys->empdept = 0;
        }
        if ($allsalarys->Reward == null || $allsalarys->Reward == "") {
            $allsalarys->Reward = 0;
        }
        if ($allsalarys->Discount == null || $allsalarys->Discount == "") {
            $allsalarys->Discount = 0;
        }
        if ($allsalarys->Withdraw == null || $allsalarys->Withdraw == "") {
            $allsalarys->Withdraw = 0;
        }
        if ($allsalarys->Absence == null || $allsalarys->Absence == "") {
            $allsalarys->Absence = 0;
        }
        if ($allsalarys->Repayment == null || $allsalarys->Repayment == "") {
            $allsalarys->Repayment = 0;
        }
        if ($allsalarys->permission == null || $allsalarys->permission == "") {
            $allsalarys->permission = 0;
        }
        if ($allsalarys->allLeave == null || $allsalarys->allLeave == "") {
            $allsalarys->allLeave = 0;
        }

        $x[0] = $allsalarys->employeeId;
        $x[1] = $allsalarys->employeeName;
        $x[2] = $allsalarys->employeeSalary;

        $x[3] = $allsalarys->employeeBouns;
        $x[4] = $allsalarys->Reward;
        $x[5] = $allsalarys->Discount;

        $x[6] = $allsalarys->Withdraw;
        $x[7] = $allsalarys->Absence;
        $x[9] = $allsalarys->Repayment;
        $x[10] = ($allsalarys->empdept) - ($allsalarys->Repayment); //current dept
        $x[11] = $allsalarys->permission;
        $x[12] = $allsalarys->allLeave;



        $total = (($allsalarys->employeeBouns) + ($allsalarys->Reward) + ($allsalarys->employeeSalary)) -
                (($allsalarys->Discount) + ($allsalarys->Withdraw) + ($allsalarys->Absence) + ($allsalarys->Repayment) + ($allsalarys->permission) + ($allsalarys->allLeave));

        $x[8] = $total; //net salary
        echo $x[8] . "*" . $x[10];
        //$smarty->assign('salarymonthdate', $from);
    }
}
?>