<?php

//the global file operation
include("../public/impOpreation.php");
include("../library/regenerateSession.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
include("../public/include_dao.php");

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

//Storereport
require_once('../models/dao/StorereportDAO.class.php');
require_once('../models/dto/Storereport.class.php');
require_once('../models/mysql/StorereportMySqlDAO.class.php');
require_once('../models/mysql/ext/StorereportMySqlExtDAO.class.php');

//Sellbill
require_once('../models/dao/SellbillDAO.class.php');
require_once('../models/dto/Sellbill.class.php');
require_once('../models/mysql/SellbillMySqlDAO.class.php');
require_once('../models/mysql/ext/SellbillMySqlExtDAO.class.php');

//Sellbilldetail
require_once('../models/dao/SellbilldetailDAO.class.php');
require_once('../models/dto/Sellbilldetail.class.php');
require_once('../models/mysql/SellbilldetailMySqlDAO.class.php');
require_once('../models/mysql/ext/SellbilldetailMySqlExtDAO.class.php');

//Returnsellbill
require_once('../models/dao/ReturnsellbillDAO.class.php');
require_once('../models/dto/Returnsellbill.class.php');
require_once('../models/mysql/ReturnsellbillMySqlDAO.class.php');
require_once('../models/mysql/ext/ReturnsellbillMySqlExtDAO.class.php');

//Returnsellbilldetail
require_once('../models/dao/ReturnsellbilldetailDAO.class.php');
require_once('../models/dto/Returnsellbilldetail.class.php');
require_once('../models/mysql/ReturnsellbilldetailMySqlDAO.class.php');
require_once('../models/mysql/ext/ReturnsellbilldetailMySqlExtDAO.class.php');

//Sellbillandrutern
require_once('../models/dao/SellbillandruternDAO.class.php');
require_once('../models/dto/Sellbillandrutern.class.php');
require_once('../models/mysql/SellbillandruternMySqlDAO.class.php');
require_once('../models/mysql/ext/SellbillandruternMySqlExtDAO.class.php');

//Sellandruternbilldetail
require_once('../models/dao/SellandruternbilldetailDAO.class.php');
require_once('../models/dto/Sellandruternbilldetail.class.php');
require_once('../models/mysql/SellandruternbilldetailMySqlDAO.class.php');
require_once('../models/mysql/ext/SellandruternbilldetailMySqlExtDAO.class.php');

//productUnit
require_once('../models/dao/ProductunitDAO.class.php');
require_once('../models/dto/Productunit.class.php');
require_once('../models/mysql/ProductunitMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductunitMySqlExtDAO.class.php');

//Product
require_once('../models/dao/ProductDAO.class.php');
require_once('../models/dto/Product.class.php');
require_once('../models/mysql/ProductMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductMySqlExtDAO.class.php');

//Programsetting
require_once('../models/dao/ProgramsettingsDAO.class.php');
require_once('../models/dto/Programsetting.class.php');
require_once('../models/mysql/ProgramsettingsMySqlDAO.class.php');
require_once('../models/mysql/ext/ProgramsettingsMySqlExtDAO.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');

/* --------------------------------------------------------------------------------------------------------------------------------------- */


//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");
//$userID = $_SESSION['userid'];

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

  Controller Name :- Setting Operation

  OPERTATION in Controller

  1- add operation
  2- edit opration
  3- delete operation

  ======================== */
//here the global templates
$smarty->display("header.html");
//here goes the instances and general variables
//Programsetting
$ProgramsettingDAO = new ProgramsettingsMySqlDAO();

//Store
$store = new Store();
$storeDAO = new StoreMySqlDAO();
$myStoreEx = new StoreMySqlExtDAO();

//Storedetail
$storedetail = new Storedetail();
$storedetailDAO = new StoredetailMySqlDAO();
$storedetailEx = new StoredetailMySqlExtDAO();

//store report
$storeReport = new Storereport();
$storeReportDAO = new StorereportMySqlDAO();
$storeReportEx = new StorereportMySqlExtDAO();

//sell bill
$sellBill = new Sellbill();
$sellBillDAO = new SellbillMySqlDAO();
$sellBillEx = new SellbillMySqlExtDAO();

//Sellbilldetail
$sellbilldetail = new Sellbilldetail();
$sellbilldetailDAO = new SellbilldetailMySqlDAO();
$sellbilldetailEx = new SellbilldetailMySqlExtDAO();

//return sell bill
$returnSellBill = new Returnsellbill();
$returnSellBillDAO = new ReturnsellbillMySqlDAO();
$returnSellBillEX = new ReturnsellbillMySqlExtDAO();

//Returnsellbilldetail
$returnsellbilldetail = new Returnsellbilldetail();
$returnsellbilldetailDAO = new ReturnsellbilldetailMySqlDAO();
$returnsellbilldetailEx = new ReturnsellbilldetailMySqlExtDAO();

//sellBillAndReturn
$sellBillAndReturn = new Sellbillandrutern();
$sellBillAndReturnDAO = new SellbillandruternMySqlDAO();
$sellBillAndReturnEx = new SellbillandruternMySqlExtDAO();

//Sellandruternbilldetail
$sellandruternbilldetail = new Sellandruternbilldetail();
$sellandruternbilldetailDAO = new SellandruternbilldetailMySqlDAO();
$sellandruternbilldetailEx = new SellandruternbilldetailMySqlExtDAO();

//Productunit
$myProductunitEx = new ProductunitMySqlExtDAO();

//product
$product = new Product();
$productDAO = new ProductMySqlDAO();

$ProgramsettingDAO = new ProgramsettingsMySqlDAO();

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

$myUserGroupRecord = new UsergroupMySqlDAO();
$loadData = $myUserGroupRecord->load($_SESSION['usergroupid']);
$smarty->assign("loadData", $loadData);

//all
if ($do == "all") {
    include_once("../public/authentication.php");
    try {

        $Programsetting = $ProgramsettingDAO->load(1);
        $smarty->assign('programsettingsdata', $Programsetting);
        //date
        $smarty->assign("today", date("Y-m-d "));

         $smarty->assign("searchinonestore", $_SESSION['searchinonestore']);
        if ($_SESSION['searchinonestore'] == 0) {
            if ($_SESSION['storeids'] == 0) {
                $stores = $myStoreEx->queryByConditions();
            }else{
                $stores = $myStoreEx->queryByConditions(' and store.storeId in (' . $_SESSION['storeids'] . ')');
            }
            $smarty->assign("allStore", $stores);
            $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
            $smarty->assign("storedef", $storedef);
            $smarty->assign("storeid", $_SESSION['storeid']);
        }else{
            $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
            $smarty->assign("storedef", $storedef);
            $smarty->assign("storeid", $_SESSION['storeid']);
        }



        //allStore
        // $allStore = $storeDAO->queryAll();
        // $smarty->assign("allStore", $allStore);

        $storeId = $_POST['store'];
        $dateFrom = $_POST['dateFrom'];
        $dateTo = $_POST['dateTo'];
        $buyPriceType = $_POST["buyPriceType"];

        $youtubes = $youtubeLinkDAO->queryAll();
        $smarty->assign("youtubes", $youtubes);
        //sellBill
        $queryString = ' WHERE';
        if (isset($storeId) && $storeId != -1) {
            $queryString .= '  sellbill.sellbillstoreid = ' . $storeId . ' AND';
        }else if ($_SESSION['searchinonestore'] == 0) {
            if ($_SESSION['storeids'] != 0) {
            $queryString .= ' sellbill.sellbillstoreid in (' . $_SESSION['storeids'] . ') AND';
            }
        }else{
            $queryString .= ' sellbill.sellbillstoreid = '.$_SESSION['storeid'].' AND';
        }

        if (isset($dateFrom) && !empty($dateFrom) && isset($dateTo) && !empty($dateTo)) {
            $queryString .= ' DATE( sellbill.sellbillsysdate )  >= "' . $dateFrom . '" AND DATE( sellbill.sellbillsysdate ) <= "' . $dateTo . '"';
        }

        //explode string on space character to remove last AND occurence
        $arr = explode(' ', $queryString);
        //print_r($arr);
        if (isset($arr) && count($arr) > 0) {
            $lastWord = end($arr);
            if ($lastWord == 'AND') {//remove it
                array_pop($arr);
                //form the string again
                $queryString = implode(' ', $arr);
            } else if ($lastWord == 'WHERE') {//remove it
                array_pop($arr);
                $queryString = ' ';
            }
        }
        if ($queryString == ' ') {
            $today = date("Y-m-d");
            $queryString .= ' WHERE DATE( sellbill.sellbillsysdate )  >= "' . $today . '" AND DATE( sellbill.sellbillsysdate ) <= "' . $today . '" and sellbill.deletedsellid = 0 ';
        }
        $sellBill = $sellBillEx->getSellBillsUsingQueryString($queryString);


        foreach ($sellBill as $mysellBill) {

            $totalBuy = 0;
            // print_r("sellbillid = ".$mysellBill->sellbillid."<br>");
            $sellbillid = $mysellBill->sellbillid;
            $smarty->assign("sellbillid", $sellbillid);
            $SellBillDetail = $sellbilldetailDAO->queryBySellbillid($mysellBill->sellbillid);

            foreach ($SellBillDetail as $mySellBillDetail) {
                $unitId = $mySellBillDetail->productunitid;
                $productId = $mySellBillDetail->sellbilldetailproductid;
                $productunitData = loadProductUnitWithProductAndUnit($productId, $unitId);
                $overAllAveragePrice = $productunitData->overAllAveragePrice;
                $myproductNumber = $productunitData->productnumber;
                switch ($buyPriceType) {
                    case "first":
                        $buyprice = (float) $mySellBillDetail->buyprice;
                        break;
                    case "last":
                        $buyprice = (float) $mySellBillDetail->lastbuyprice;
                        break;
                    case "mean":
                        $buyprice = (float) $mySellBillDetail->meanbuyprice;
                        break;
                    case "last_discount":
                        $buyprice = (float) $mySellBillDetail->lastbuyprice_withDiscount;
                        break;
                    case "mean_discount":
                        $buyprice = (float) $mySellBillDetail->meanbuyprice_withDiscount;
                        break;
                    case "generalPrice":
                        $buyprice = (float) $overAllAveragePrice;
                        break;
                    case "tax":
                        $buyprice = (float) $mySellBillDetail->lastbuyprice_withTax;
                        break;
                    case "mean_tax":
                        $buyprice = (float) $mySellBillDetail->meanbuyprice_withTax;
                        break;
                }
                //سعر الشراء للمنتج
                $myBuyPrice = $buyprice * ($mySellBillDetail->sellbilldetailquantity * $myproductNumber);

                $thisProfits += ($mySellBillDetail->sellbilldetailtotalprice) - $myBuyPrice;
                $totalBuy += $myBuyPrice;
                $totalSell += $mySellBillDetail->sellbilldetailtotalprice;

                //	print_r('</br>productId ='.$productId.'</br>');
            }
            $sellbilldiscounttype = $mysellBill->sellbilldiscounttype;
            $sellbilldiscount = $mysellBill->sellbilldiscount;

            if ($sellbilldiscounttype == 1) {
                $sellBillTotal = $mysellBill->sellbilldiscount;            //($totalSell - $totalBuy)- $sellbilldiscount;
            } elseif ($sellbilldiscounttype == 2) {
                //$sellBillTotal = ($totalSell - $totalBuy)- ($sellbilldiscount/100);
                $sellBillTotal = ($mysellBill->sellbilldiscount / 100) * $mysellBill->sellbilltotalbill;
            }

            $mysellBill->sellBillTotalx = $sellBillTotal;
            $mysellBill->totalBuyx = $totalBuy;
            $mysellBill->totalSellx = $totalSell;

            //$totalOfTotal += $sellBillTotal;

            $totalOfTotal += ($mysellBill->sellbillaftertotalbill - $mysellBill->totalBuyx);
            /* print_r('</br>totalBuy ='.$totalBuy.'</br>');
              print_r('</br>sellbillaftertotalbill  ='.$mysellBill->sellbillaftertotalbill.'</br>');
              echo "<br> ------------------------  </br>"; */
        }
        $smarty->assign("sellBill", $sellBill);
        $smarty->assign("totalOfTotal", $totalOfTotal);


        //returnBill
        $queryString2 = ' WHERE';
        if (isset($storeId) && $storeId != -1) {
            $queryString2 .= '  returnsellbill.returnsellbillstoreid = ' . $storeId . ' AND';
        }else if ($_SESSION['searchinonestore'] == 0) {
            if ($_SESSION['storeids'] != 0) {
            $queryString2 .= ' returnsellbill.returnsellbillstoreid in (' . $_SESSION['storeids'] . ') AND';
            }
        }else{
            $queryString2 .= ' returnsellbill.returnsellbillstoreid = '.$_SESSION['storeid'].' AND';
        }

        if (isset($dateFrom) && !empty($dateFrom) && isset($dateTo) && !empty($dateTo)) {
            $queryString2 .= ' DATE( returnsellbill.returnsellbillsysdate )  >= "' . $dateFrom . '" AND DATE( returnsellbill.returnsellbillsysdate ) <= "' . $dateTo . '"';
        }

        //explode string on space character to remove last AND occurence
        $arr = explode(' ', $queryString2);
        //print_r($arr);
        if (isset($arr) && count($arr) > 0) {
            $lastWord = end($arr);
            if ($lastWord == 'AND') {//remove it
                array_pop($arr);
                //form the string again
                $queryString2 = implode(' ', $arr);
            } else if ($lastWord == 'WHERE') {//remove it
                array_pop($arr);
                $queryString2 = ' ';
            }
        }
        if ($queryString2 == ' ') {
            $today = date("Y-m-d");
            $queryString2 .= ' WHERE DATE( returnsellbill.returnsellbillsysdate )  >= "' . $today . '" AND DATE( returnsellbill.returnsellbillsysdate ) <= "' . $today . '"';
        }
        $returnSellBill = $returnSellBillEX->getSellBillsUsingQueryString($queryString2);
        foreach ($returnSellBill as $myReturnSellBill) {
            //print_r("returnsellbillid = " . $myReturnSellBill->returnsellbillid . "<br>");
            $returnsellbillid = $myReturnSellBill->returnsellbillid;
            $smarty->assign("returnsellbillid", $returnsellbillid);

            $returnsellbilldetail = $returnsellbilldetailDAO->queryByReturnsellbillid($returnsellbillid);

            $totalBuyReturn = 0;
            $totalSellReturn = 0;
            foreach ($returnsellbilldetail as $myReturnSellBillDetail) {
                $unitId = $myReturnSellBillDetail->productunitid;
                $productId = $myReturnSellBillDetail->returnsellbilldetailproductid;
                $productunitData = loadProductUnitWithProductAndUnit($productId, $unitId);
                $overAllAveragePrice = $productunitData->overAllAveragePrice;
                $myproductNumber = $productunitData->productnumber;
                $discountvalue = $myReturnSellBillDetail->discountvalue;

                switch ($buyPriceType) {
                    case "first":
                        $buyprice = (float) $myReturnSellBillDetail->buyprice;
                        break;
                    case "last":
                        $buyprice = (float) $myReturnSellBillDetail->lastbuyprice;
                        break;
                    case "mean":
                        $buyprice = (float) $myReturnSellBillDetail->meanbuyprice;
                        break;
                    case "last_discount":
                        $buyprice = (float) $myReturnSellBillDetail->lastbuyprice_withDiscount;
                        break;
                    case "mean_discount":
                        $buyprice = (float) $myReturnSellBillDetail->meanbuyprice_withDiscount;
                        break;
                    case "generalPrice":
                        $buyprice = (float) $overAllAveragePrice;
                        break;
                    case "tax":
                        $buyprice = (float) $myReturnSellBillDetail->lastbuyprice_withTax;
                        break;
                    case "mean_tax":
                        $buyprice = (float) $myReturnSellBillDetail->meanbuyprice_withTax;
                        break;
                }
                $myBuyPrice = $buyprice * ($myReturnSellBillDetail->returnsellbilldetailquantity * $myproductNumber);

                $totalBuyReturn += $myBuyPrice;

                $totalSellReturn += $myReturnSellBillDetail->returnsellbilldetailtotalprice;

                /* print_r('<pre>');
                  print_r('</br>myBuyPrice='.$myBuyPrice.'</br>');
                  print_r('</br>buyprice='.$buyprice.'</br>');
                  print_r('</br>discountvalue='.$discountvalue.'</br>');
                  print_r('</br>sellbilldetailtotalprice='.$myReturnSellBillDetail->returnsellbilldetailtotalprice.'</br>');
                  print_r('</pre>'); */
            }

            $myReturnSellBill->totalBuyReturnx = $totalBuyReturn;
            $myReturnSellBill->totalSellReturnx = $totalSellReturn;

            /* print_r('</br>totalBuyReturn ='.$totalBuyReturn.'</br>');
              print_r('</br>totalSellReturn ='.$totalSellReturn.'</br>');
              print_r('</br>returnsellbilldiscount ='.$myReturnSellBill->returnsellbilldiscount.'</br>');
              print_r('</br>returnsellbilltotalpayed  ='.$myReturnSellBill->returnsellbilltotalpayed .'</br>'); */


            $returnsellbilldiscounttype = $myReturnSellBill->returnsellbilldiscounttype;
            $returnsellbilldiscount = $myReturnSellBill->returnsellbilldiscount;

            if ($returnsellbilldiscounttype == 1) {
                $returnSellBillTotal = ($totalSellReturn - $totalBuyReturn) - $returnsellbilldiscount;
            } elseif ($returnsellbilldiscounttype == 2) {
                $returnSellBillTotal = ($totalSellReturn - $totalBuyReturn) - ($returnsellbilldiscount / 100);
            }


            $myReturnSellBill->returnSellBillTotalx = $returnSellBillTotal;

            $totalOfTotalReturn += $returnSellBillTotal;
        }

        $smarty->assign("returnSellBill", $returnSellBill);
        $smarty->assign("totalOfTotalReturn", $totalOfTotalReturn);


        //sellbillandrutern
        $queryString3 = ' WHERE';
        if (isset($storeId) && $storeId != -1) {
            $queryString3 .= '  sellbillandrutern.sellbillstoreid = ' . $storeId . ' AND';
        }else if ($_SESSION['searchinonestore'] == 0) {
            if ($_SESSION['storeids'] != 0) {
            $queryString3 .= ' sellbillandrutern.sellbillstoreid in (' . $_SESSION['storeids'] . ') AND';
            }
        }else{
            $queryString3 .= ' sellbillandrutern.sellbillstoreid = '.$_SESSION['storeid'].' AND';
        }

        if (isset($dateFrom) && !empty($dateFrom) && isset($dateTo) && !empty($dateTo)) {
            $queryString3 .= ' DATE( sellbillandrutern.sellbillsysdate )  >= "' . $dateFrom . '" AND DATE( sellbillandrutern.sellbillsysdate ) <= "' . $dateTo . '"';
        }

        //explode string on space character to remove last AND occurence
        $arr = explode(' ', $queryString3);
        //print_r($arr);
        if (isset($arr) && count($arr) > 0) {
            $lastWord = end($arr);
            if ($lastWord == 'AND') {//remove it
                array_pop($arr);
                //form the string again
                $queryString3 = implode(' ', $arr);
            } else if ($lastWord == 'WHERE') {//remove it
                array_pop($arr);
                $queryString3 = ' ';
            }
        }
        if ($queryString3 == ' ') {
            $today = date("Y-m-d");
            $queryString3 .= ' WHERE DATE( sellbillandrutern.sellbillsysdate )  >= "' . $today . '" AND DATE( sellbillandrutern.sellbillsysdate ) <= "' . $today . '"';
        }

        $sellBillAndReturn = $sellBillAndReturnEx->getSellBillsUsingQueryString($queryString3);
        foreach ($sellBillAndReturn as $mySellBillAndReturn) {
            //print_r("sellbillid = ".$mySellBillAndReturn->sellbillid."<br>");
            $sellbillid1 = $mySellBillAndReturn->sellbillid;
            $smarty->assign("sellbillid1", $sellbillid1);

            $sellandruternbilldetail = $sellandruternbilldetailDAO->queryBySellbillid($sellbillid1);

            foreach ($sellandruternbilldetail as $mySellandruternbilldetail) {
                $unitId = $mySellandruternbilldetail->productunitid;
                $productId = $mySellandruternbilldetail->sellbilldetailproductid;
                $productunitData = loadProductUnitWithProductAndUnit($productId, $unitId);
                $overAllAveragePrice = $productunitData->overAllAveragePrice;
                $myproductNumber = $productunitData->productnumber;
                switch ($buyPriceType) {
                    case "first":
                        $buyprice = (float) $mySellandruternbilldetail->buyprice;
                        break;
                    case "last":
                        $buyprice = (float) $mySellandruternbilldetail->lastbuyprice;
                        break;
                    case "mean":
                        $buyprice = (float) $mySellandruternbilldetail->meanbuyprice;
                        break;
                    case "last_discount":
                        $buyprice = (float) $mySellandruternbilldetail->lastbuyprice_withDiscount;
                        break;
                    case "mean_discount":
                        $buyprice = (float) $mySellandruternbilldetail->meanbuyprice_withDiscount;
                        break;
                    case "generalPrice":
                        $buyprice = (float) $overAllAveragePrice;
                        break;
                }
                $myBuyPrice1 = $buyprice * ($mySellandruternbilldetail->sellbilldetailquantity * $myproductNumber);

                $totalBuyReturnSellBill += $myBuyPrice1;

                $totalSellReturnSellBill += $mySellandruternbilldetail->sellbilldetailtotalprice;

                /* print_r('<pre>');
                  print_r('</br>myBuyPrice='.$myBuyPrice.'</br>');
                  print_r('</br>buyprice='.$mySellBillDetail->buyprice.'</br>');
                  print_r('</br>myproductNumber='.$myproductNumber.'</br>');
                  print_r('</br>sellbilldetailtotalprice='.$mySellBillDetail->sellbilldetailtotalprice.'</br>');
                  print_r('</pre>'); */
            }

            $mySellBillAndReturn->totalBuyReturnSellBillx = $totalBuyReturnSellBill;
            $mySellBillAndReturn->totalSellReturnSellBillx = $totalSellReturnSellBill;

            /* print_r('</br>totalBuyReturn ='.$totalBuyReturn.'</br>');
              print_r('</br>totalSellReturn ='.$totalSellReturn.'</br>');
              print_r('</br>returnsellbilldiscount ='.$myReturnSellBill->returnsellbilldiscount.'</br>');
              print_r('</br>returnsellbilldiscounttype ='.$myReturnSellBill->returnsellbilldiscounttype.'</br>'); */


            $sellbilldiscounttype = $mySellBillAndReturn->sellbilldiscounttype;
            $sellbilldiscount = $mySellBillAndReturn->sellbilldiscount;

            if ($sellbilldiscounttype == 1) {
                $returnAndSellBillTotal = ($totalSellReturnSellBill - $totalBuyReturnSellBill) - $sellbilldiscount;
            } elseif ($sellbilldiscounttype == 2) {
                $returnAndSellBillTotal = ($totalSellReturnSellBill - $totalBuyReturnSellBill) - ($sellbilldiscount / 100);
            }


            $mySellBillAndReturn->returnAndSellBillTotalx = $returnAndSellBillTotal;

            $totalOfTotalReturnAndsell += $returnAndSellBillTotal;
        }

        $smarty->assign("sellBillAndReturn", $sellBillAndReturn);
        $smarty->assign("totalOfTotalReturnAndsell", $totalOfTotalReturnAndsell);



        //header("location:?do=sucess");
    } catch (Exception $e) {
        echo $e;
        //header("location:?do=error");
    }
    $smarty->display("storeProfitView/show.html");
} elseif ($do == "sucess") {
    //here the smarty templates
    $smarty->display("succes.html");
} elseif ($do == "error") {
    //here the smarty templates
    $smarty->display("error.html");
}

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

/* ===============================
  function in this CONTROLLER
  ================================ */

function loadProductUnitWithProductAndUnit($productId, $unitId) {

    //to use the variable out side the funcion
    global $myProductunitEx;

    // select all data from productunit tbl
    $productunitData = $myProductunitEx->queryWithProductIdAndUnitId($productId, $unitId);

    return $productunitData;
}

?>