File: /home/mostafedeg/public_html/erp/controllers/storereportAjaxController.php
<?php
//the global file operation
//include("../public/impOpreation.php");
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
// GOES HERE ....................
include("../public/include_dao.php");
//Storemovement
require_once('../models/dao/StoremovementDAO.class.php');
require_once('../models/dto/Storemovement.class.php');
require_once('../models/mysql/StoremovementMySqlDAO.class.php');
require_once('../models/mysql/ext/StoremovementMySqlExtDAO.class.php');
//Storerawmaterialdetail
require_once('../models/dao/StorerawmaterialdetailsDAO.class.php');
require_once('../models/dto/Storerawmaterialdetail.class.php');
require_once('../models/mysql/StorerawmaterialdetailsMySqlDAO.class.php');
require_once('../models/mysql/ext/StorerawmaterialdetailsMySqlExtDAO.class.php');
//Rawmaterials
require_once('../models/dao/RawmaterialsDAO.class.php');
require_once('../models/dto/Rawmaterial.class.php');
require_once('../models/mysql/RawmaterialsMySqlDAO.class.php');
require_once('../models/mysql/ext/RawmaterialsMySqlExtDAO.class.php');
//Storerawmaterial
require_once('../models/dao/StorerawmaterialsDAO.class.php');
require_once('../models/dto/Storerawmaterial.class.php');
require_once('../models/mysql/StorerawmaterialsMySqlDAO.class.php');
require_once('../models/mysql/ext/StorerawmaterialsMySqlExtDAO.class.php');
//get the do the action
$do = $_GET['do'];
/* ======================
Controller Name :- photographyCTRL
OPERTATION in Controller
1-load save data
2-display show form
======================== */
//here goes the instances and general variables
$myStoremovementEx = new StoremovementMySqlExtDAO();
$myStoremovementRecord = new StoremovementMySqlDAO();
$myRawmaterialRecord = new RawmaterialsMySqlDAO();
$myStorerawmaterialRecord = new StorerawmaterialsMySqlDAO();
$myStorerawmaterialdetail = new StorerawmaterialdetailsMySqlDAO();
if ($do == "show") {
// here the function that do the action
$rawmaterialData = loadMaterial();
$smarty->assign("rawmaterialData", $rawmaterialData);
$storeData = loadStore();
$smarty->assign("storeData", $storeData);
$materialId = $_REQUEST['materialid'];
$stmaterialId = $_REQUEST['stmaterialid'];
if (isset($materialId) && $materialId != "-1") {
$storemovementData = showBymaterialName();
$sumValue = sumCredit();
} elseif (isset($stmaterialId) && $stmaterialId != "-1") {
$storemovementData = showBystorerawMaterial();
$sumValue = sumCreditById($stmaterialId);
}
$smarty->assign('storemovementData', $storemovementData);
$smarty->assign('sumValue', $sumValue);
//here the smarty templates
$smarty->display("storemovementview/storemovement.html");
}
/* ===============================
function in this CONTROLLER
================================ */
//select all rawmaterial data
function loadMaterial() {
//to use the variable out side the funcion
global $myRawmaterialRecord;
//load all rawmaterial data
$rawmaterialData = $myRawmaterialRecord->queryAll();
return $rawmaterialData;
}
//select all storerawmaterials data
function loadStore() {
//to use the variable out side the funcion
global $myStorerawmaterialRecord;
//load all storerawmaterials data
$storeData = $myStorerawmaterialRecord->queryByTempdelete(0);
return $storeData;
}
function sumCredit() {
//to use the variable out side the funcion
global $myStorerawmaterialdetail;
//select all data from Storerawmaterialdetail tbl
$StorerawmaterialdetailData = $myStorerawmaterialdetail->queryAll();
//get the sum of multiplying for rawmaterialamount and rawmaterialprice
$sumValue = 0;
foreach ($StorerawmaterialdetailData as $Storerawmaterialdetail) {
$amount = $Storerawmaterialdetail->rawmaterialamount;
$price = $Storerawmaterialdetail->rawmaterialprice;
$total = $amount * $price;
$sumValue = $total + $sumValue;
}
return $sumValue;
}
function sumCreditById($id) {
//to use the variable out side the funcion
global $myStorerawmaterialdetail;
//load data from Storerawmaterialdetail tbl by id
$StorerawmaterialdetailData = $myStorerawmaterialdetail->load($id);
//get the sum of multiplying for rawmaterialamount and rawmaterialprice
$amount = $StorerawmaterialdetailData->rawmaterialamount;
$price = $StorerawmaterialdetailData->rawmaterialprice;
$total = $amount * $price;
$sumValue = $total;
return $sumValue;
}
// show the form by material name
function showBymaterialName() {
//to use the variable out side the funcion
global $myStoremovementRecord;
global $myStoremovementEx;
$materialId = $_REQUEST['materialid'];
//select all data from storemovement by rawmaterialid
$storemovementData = $myStoremovementEx->queryAllWithMaterial($materialId);
return $storemovementData;
}
// show the form by store name
function showBystorerawMaterial() {
//to use the variable out side the funcion
global $myStoremovementEx;
$stmaterialId = $_REQUEST['stmaterialid'];
//select all data from storemovement by storerawmaterialsid
$storemovementData = $myStoremovementEx->queryAllWithStore($stmaterialId);
return $storemovementData;
}
?>