<?php

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

//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
require_once('../models/dao/YoutubeLinkDAO.class.php');
require_once('../models/dto/YoutubeLink.class.php');
require_once('../models/mysql/YoutubeLinkMySqlDAO.class.php');
require_once('../models/mysql/ext/YoutubeLinkMySqlExtDAO.class.php');

include_once("../public/config.php");
include_once("dailyentryfun.php");

//here the db files that include in the file
include("../public/include_dao.php");


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

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

  Controller Name :- productController

  OPERTATION in Controller

  1- display add form, add supplier cat and supplier with ajax
  2- add in supplier tbl
  2.1- insert into supplier unit tbl
  2.2- insert into storedetail tbl
  2.3- insert new row into storereport tbl
  3- display show and tempdelete
  4- edit supplier
  5- update supplier
  5.1- update supplier tbl with supplierid
  5.2- delete supplier units associated to this supplier from productunit tbl, then insert it again

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

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

//here goes the instances and general variables
//Accountstree
$accountsTree = new Accountstree();
$accountsTreeDAO = new AccountstreeMySqlDAO();
$accountsTreeEX = new AccountstreeMySqlExtDAO();

//Supplierdebtchange
$Supplierdebtchange = new Supplierdebtchange();
$SupplierdebtchangeDAO = new SupplierdebtchangeMySqlDAO();
$SupplierdebtchangeEX = new SupplierdebtchangeMySqlExtDAO();

//Programsetting
$Programsetting = new Programsetting();
$ProgramsettingDAO = new ProgramsettingsMySqlDAO();
$ProgramsettingEX = new ProgramsettingsMySqlExtDAO();

$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();

//Dailyentry
$dailyEntry = new Dailyentry();
$dailyEntryDAO = new DailyentryMySqlDAO();
$dailyEntryEX = new DailyentryMySqlExtDAO();

//Dailyentrycreditor دائن
$dailyEntryCreditor = new Dailyentrycreditor();
$dailyEntryCreditorDAO = new DailyentrycreditorMySqlDAO();
$dailyEntryCreditorEX = new DailyentrycreditorMySqlExtDAO();

//Dailyentrydebtor مدين
$dailyEntryDebtor = new Dailyentrydebtor();
$dailyEntryDebtorDAO = new DailyentrydebtorMySqlDAO();
$dailyEntryDebtorEX = new DailyentrydebtorMySqlExtDAO();

$today = date("Y-m-d");

$Programsettingdata = $ProgramsettingDAO->load(1);
$smarty->assign("Programsettingdata", $Programsettingdata);


/* * * classes ** */
$rentProducts = new Rentproduct();
$myrentProducts = new RentproductMySqlDAO();
$extrentProducts = new RentproductMySqlExtDAO();

$rentStore = new Rentstore();
$myrentStore = new RentstoreMySqlDAO();
$extrentStore = new RentstoreMySqlExtDAO();

$supplier = new Supplier();
$mysupplier = new SupplierMySqlDAO();
$extsupplier = new SupplierMySqlExtDAO();

$client = new Client();
$myclient = new ClientMySqlDAO();
$extclient = new ClientMySqlExtDAO();

$save = new Save();
$mysave = new SaveMySqlDAO();
$extsave = new SaveMySqlExtDAO();

$Savedaily = new Savedaily();
$SavedailyDAO = new SavedailyMySqlDAO();


$rentbill = new Rentbill();
$myrentbill = new RentbillMySqlDAO();
$extrentbill = new RentbillMySqlExtDAO();

$rentbillpro = new Rentbillprop();
$myrentbillpro = new RentbillpropMySqlDAO();
$extrentbillpro = new RentbillpropMySqlExtDAO();


//check and use the condition that suite this action
if (empty($do)) {
    //here the permssion check
    include_once("../public/authentication.php");

    $products = $myrentProducts->queryAll();
    $smarty->assign('products', $products);

    $showsearch = 1;

    //search bu product - get history
    $allpros = $extrentbillpro->delays();
    foreach ($allpros as $sinpro) {
        $productinfo = $myrentProducts->load($sinpro->productid);
        $sinpro->productname = $productinfo->name;

        $billinfo = $myrentbill->load($sinpro->billid);
        //$sinpro->billid = $sinpro->billid;

        $clientinfo = $myclient->load($billinfo->clientid);
        $sinpro->clientname = $clientinfo->clientname;
    }
    $smarty->assign('allpros', $allpros);

    $smarty->assign('showsearch', $showsearch);

    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);
    //here the smarty templates
    $smarty->display("rent/reports/delays.html");
}
//here the global templates
$smarty->assign("rentjs", 1);
$smarty->display("footer.html");

/* ===============================
  function in this CONTROLLER
  ================================ */
?>