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

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

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

  Controller Name :- productReportsAjaxController

  OPERTATION in Controller

  1- تقرير حركة صنف
  ======================== */

//here goes the instances and general variables
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productExt = new ProductMySqlExtDAO();
//Storereport
$storeReportDAO = new StorereportMySqlDAO();
$storeReportExt = new StorereportMySqlExtDAO();
//Store
$storeDAO = new StoreMySqlDAO();

$today = date("Y-m-d");
$smarty->assign("today", $today);

//تقرير حركة صنف



$fromDate = $_REQUEST['from'];
$toDate = $_REQUEST['to'];
$productId = $_REQUEST['productId'];
$storeId = $_REQUEST['storeId'];
if (isset($productId) && $productId != "-1" && isset($storeId) && $storeId != "-1" && isset($fromDate) && isset($toDate)) {
    searchProductsChange($productId, $storeId, $fromDate, $toDate);
}

$smarty->display("productReportsview/productReportAjax.html");

////////////////////////////// Functions //////////////////////////
function searchProductsChange($productId, $storeId, $fromDate, $toDate) {
    global $productDAO;
    global $productExt;
    global $storeReportExt;
    global $smarty;

    //select from storereport tbl
    $productsData = $storeReportExt->queryWithProductAndStoreAndDateExt($productId, $storeId, $fromDate, $toDate);
    $smarty->assign('productsData', $productsData);
}

?>