<?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
include_once("../public/config.php");


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

//Store
require_once('../models/dao/StoreDAO.class.php');
require_once('../models/dto/Store.class.php');
require_once('../models/mysql/StoreMySqlDAO.class.php');
require_once('../models/mysql/ext/StoreMySqlExtDAO.class.php');

//Storedetail
require_once('../models/dao/StoredetailDAO.class.php');
require_once('../models/dto/Storedetail.class.php');
require_once('../models/mysql/StoredetailMySqlDAO.class.php');
require_once('../models/mysql/ext/StoredetailMySqlExtDAO.class.php');


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');

//Breadcrumb
require_once("../library/breadcrumb.php");


//get the do the action

$do = $_GET['do'];
$langs = $_SESSION['erp_lang'];
include_once("../views/languages/$langs/success.php");
include_once("../views/languages/$langs/error.php");

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

  Controller Name :-storeCTRL

  OPERTATION in Controller

  1-display add form
  2- add in storerawmaterails tble
  3-display sucess or error
  4-display show and delete
  5-display edit
  ======================== */


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



//Store
$myStore = new Store();
$myStoreRecord = new StoreMySqlDAO();
$myStoreEx = new StoreMySqlExtDAO();

//Storedetail
$myStoredetailRecord = new StoredetailMySqlDAO();

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


//Breadcrumb
$breadcrumbObject = new Breadcrumb();

if (empty($do)) {
    //here the permssion check
    //include_once("../public/authentication.php");
    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);

    $getDeatilas = 1;
    if ($getDeatilas == 1) {
        $storeData = $myStoreEx->storeEvaluationAtAllPricesDetailed();
        foreach($storeData as $data)
        {
            $scstoreData = $myStoreEx->storeEvaluationAtAllPricesDetailedNew($data->storeId);
            $data->totQty += $scstoreData->totQty;
            $data->totQty_n += $scstoreData->totQty_n;
            $data->tot_productBuyPrice += $scstoreData->tot_productBuyPrice;
            $data->tot_productBuyPrice_n += $scstoreData->tot_productBuyPrice_n;
            $data->tot_productSellAllPrice += $scstoreData->tot_productSellAllPrice;
            $data->tot_productSellAllPrice_n += $scstoreData->tot_productSellAllPrice_n;
            $data->tot_productSellUnitPrice += $scstoreData->tot_productSellUnitPrice;
            $data->tot_productSellUnitPrice_n += $scstoreData->tot_productSellUnitPrice_n;
            $data->tot_productSellHalfPrice += $scstoreData->tot_productSellHalfPrice;
            $data->tot_productSellHalfPrice_n += $scstoreData->tot_productSellHalfPrice_n;
            $data->tot_lastbuyprice += $scstoreData->tot_lastbuyprice;
            $data->tot_lastbuyprice_n += $scstoreData->tot_lastbuyprice_n;
            $data->tot_lastbuyprice_withDiscount += $scstoreData->tot_lastbuyprice_withDiscount;
            $data->tot_lastbuyprice_withDiscount_n += $scstoreData->tot_lastbuyprice_withDiscount_n;
            $data->tot_meanbuyprice += $scstoreData->tot_meanbuyprice;
            $data->tot_meanbuyprice_n += $scstoreData->tot_meanbuyprice_n;
            $data->tot_meanbuyprice_withDiscount += $scstoreData->tot_meanbuyprice_withDiscount;
            $data->tot_meanbuyprice_withDiscount_n += $scstoreData->tot_meanbuyprice_withDiscount_n;
            
        }
        $smarty->assign("storeData", $storeData);
        $smarty->display("storeEvaluationAtAllPricesView/showDetailed.html");
    } else {

        $storeData = $myStoreEx->storeEvaluationAtAllPrices();
        $smarty->assign("storeData", $storeData);
        $smarty->display("storeEvaluationAtAllPricesView/show.html");
    }


    //$smarty->assign("customBank", 1);
} elseif ($do == "sucess") {

    //here the smarty templates
    $smarty->display("succes.html");
} elseif ($do == "error") {

    //here the smarty templates
    $smarty->display("error.html");
}

$smarty->assign("customStore", 1);
$smarty->assign("customValidation", 1);
//here the global templates
$smarty->display("footer.html");

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