<?php

//the global file operation
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");

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

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

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

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

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


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


//here goes the instances and general variables
//////////////////store///////////////////
$StoreDAO = new StoreMySqlDAO();
$Store = new Store();
$StoreEX = new StoreMySqlExtDAO();

///////////////////store detail//////////////
$StoredetailDAO = new StoredetailMySqlDAO();
$Storedetail = new Storedetail();
$StoredetailEX = new StoredetailMySqlExtDAO();

///////////////product///////////////
$ProductDAO = new ProductMySqlDAO();
$Product = new Product();
$ProductEX = new ProductMySqlExtDAO();

////////////////kempila//////////////////
$KempialaDAO = new KempialaMySqlDAO();
$Kempiala = new Kempiala();
$KempialaEX = new KempialaMySqlExtDAO();

////////////////sellbilland return///////////////

$ReturnsellbilldetailDAO = new ReturnsellbilldetailMySqlDAO();
$Returnsellbilldetail = new Returnsellbilldetail();
$ReturnsellbilldetailEX = new ReturnsellbilldetailMySqlExtDAO();


//////////////////////sellbilldetail///////////////
$SellbilldetailDAO = new SellbilldetailMySqlDAO();
$Sellbilldetail = new Sellbilldetail();
$SellbilldetailEX = new SellbilldetailMySqlExtDAO();

if ($do == "show") {

    $allproduct = showallproductbystorename();
    //$allkempila= showallkempila();
    $allstore = loadstore();
    $storeid = loadstorename();
    $allsell = productnotsellbystorename();
    //$allcheck=showallcheck();

    $smarty->assign("allstore", $allstore);
    $smarty->assign("storeid", $storeid);
    $smarty->assign("allsell", $allsell);
    $smarty->assign("allproduct", $allproduct);
    //$smarty->assign("allkempila",$allkempila);
    //$smarty->assign("allcheck",$allcheck);
    $smarty->display("noticesview/show.html");
}

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

function loadstore() {
    global $StoreDAO;

    $allstore = $StoreDAO->queryAll();

    return $allstore;
}

function loadstorename() {
    global $StoreDAO;
    $storename = $_POST['supplierid'];
    $storeid = $StoreDAO->load($storename);

    return $storeid;
}

function showallproductbystorename() {

    global $ProductEX;
    $storename = $_POST['supplierid'];

    //echo $storename;
    $allproduct = $ProductEX->queryWithStoreId22($storename);
    return $allproduct;
}

///////////////////////show all product/////////////////////////
function showallproductx2() {

    global $ProductEX;
    $allproduct = $ProductEX->queryallproduct();
    return $allproduct;
}

function productnotsell() {
    global $SellbilldetailEX;

    $today = date("Y-m-d");
    $todayfor7days = date("Y-m-d", strtotime($today . ' - 7 day'));

    $allsell = $SellbilldetailEX->queryproductnotsell($todayfor7days, $today);

    return $allsell;
}

function productnotsellbystorename() {
    global $SellbilldetailEX;
    $today = date("Y-m-d");
    $todayfor7days = date("Y-m-d", strtotime($date . ' - 7 day'));
    $storename = $_POST['supplierid2'];

    $allsell = $SellbilldetailEX->queryproductnotsellwithstorename($todayfor7days, $today, $storename);

    return $allsell;
}
