<?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");
//Productcat
require_once('../models/dao/ProductcatDAO.class.php');
require_once('../models/dto/Productcat.class.php');
require_once('../models/mysql/ProductcatMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductcatMySqlExtDAO.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');
//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');
//Unit
require_once('../models/dao/UnitDAO.class.php');
require_once('../models/dto/Unit.class.php');
require_once('../models/mysql/UnitMySqlDAO.class.php');
require_once('../models/mysql/ext/UnitMySqlExtDAO.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');
//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');
//Productcatunit
require_once('../models/dao/ProductcatunitDAO.class.php');
require_once('../models/dto/Productcatunit.class.php');
require_once('../models/mysql/ProductcatunitMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductcatunitMySqlExtDAO.class.php');

//Buybill
require_once('../models/dao/BuybillDAO.class.php');
require_once('../models/dto/Buybill.class.php');
require_once('../models/mysql/BuybillMySqlDAO.class.php');
require_once('../models/mysql/ext/BuybillMySqlExtDAO.class.php');
//Buybilldetail
require_once('../models/dao/BuybilldetailDAO.class.php');
require_once('../models/dto/Buybilldetail.class.php');
require_once('../models/mysql/BuybilldetailMySqlDAO.class.php');
require_once('../models/mysql/ext/BuybilldetailMySqlExtDAO.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');


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

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

  Controller Name :- productController

  OPERTATION in Controller

  1- display add form, add product cat and product with ajax
  2- add in product tbl
  2.1- insert into product unit tbl
  2.2- insert into storedetail tbl
  2.3- insert new row into storereport tbl
  3- display show and tempdelete
  4- edit product
  5- update product
  5.1- update product tbl with productId
  5.2- delete product units associated to this product from productunit tbl, then insert it again
  6- تقرير الأصناف وسعر الشراء
  ======================== */

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

//here goes the instances and general variables
//Buybill
$buyBill = new Buybill();
$buyBillDAO = new BuybillMySqlDAO();
$buyBillExt = new BuybillMySqlExtDAO();
//Buybilldetail
$buyBillDetail = new Buybilldetail();
$buyBillDetailDAO = new BuybilldetailMySqlDAO();
$buyBillDetailExt = new BuybilldetailMySqlExtDAO();
//Productcat
$productCat = new Productcat();
$productCatDAO = new ProductcatMySqlDAO();
$productCatExt = new ProductcatMySqlExtDAO();
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productExt = new ProductMySqlExtDAO();
//Storedetail
$storeDetail = new Storedetail();
$storeDetailDAO = new StoredetailMySqlDAO();
$storeDetailExt = new StoredetailMySqlExtDAO();
//Storereport
$storeReport = new Storereport();
$storeReportDAO = new StorereportMySqlDAO();
//Unit
$unitDAO = new UnitMySqlDAO();
$unitExt = new UnitMySqlExtDAO();
//Productunit
$productUnit = new Productunit();
$productUnitDAO = new ProductunitMySqlDAO();
$productUnitExt = new ProductunitMySqlExtDAO();
//progsetting
$Programsettings = new Programsetting();
$ProgramsettingsDAO = new ProgramsettingsMySqlDAO();
$ProgramsettingsExt = new ProgramsettingsMySqlExtDAO();
//Store
$storeDAO = new StoreMySqlDAO();
//Unit
$unitDAO = new UnitMySqlDAO();
$unitExt = new UnitMySqlExtDAO();

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



//Productcatunit
$Productcatunit= new Productcatunit();
$ProductcatunitDAO= new ProductcatunitMySqlDAO();


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


/*
  $allproductdata=$productExt->queryAllnothaveunit();
  print_r('allproductdata'.$allproductdata);

  foreach($allproductdata as $myproduct)
  {



  $productUnit->conditions=0;
  $productUnit->productid=$myproduct->productId;
  $productUnit->unitid=1;
  $productUnit->productnumber=1;
  $productUnit->productunitdate=$today;
  $productUnit->userid=1;

  $productUnitDAO->insert($productUnit);


  } 
  */
  $allproductcatdata=$productCatExt->queryAllnothaveunit();
	print_r($allproductcatdata);
	
	foreach($allproductcatdata as $mycatproduct)
	{
		
		
		
		$Productcatunit->conditions=0;
		$Productcatunit->productcatid=$mycatproduct->productCatId;
		$Productcatunit->unitid=1;
		$Productcatunit->productnumber=1;
		$Productcatunit->productcatunitdate=$today;
		$Productcatunit->userid=1;
		
		$ProductcatunitDAO->insert($Productcatunit);
		
		
	}
	
	

/*

  $i=0;
  $allproductdata=$productExt->queryAllnotinstor();

  //$allstore=$storeDAO->queryAll();
  //foreach($allstore as  $mystore)
  {
  //$storeId=$mystore->storeId;
  foreach($allproductdata  as $mypro)
  {
  $productId=$mypro->productId;

  $storeDetail->productid=$productId;
  $storeDetail->storeid=1;
  $storeDetail->productquantity=0;
  $storeDetail->userid=1;
  $storeDetail->storedetaildate=date("Y-d-m");

  $storeDetailDAO->insert($storeDetail);
  $i ++;

  }

  }

  print_r('<br>fffff'.count($allproductdata));
  print_r('<br>i'.($i));

 */
?>