File: /home/mostafedeg/public_html/erp/controllers/reportfunctions.php
<?php
include("../public/include_dao.php");
//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productExt = new ProductMySqlExtDAO();
//Productcat
$productCatDAO = new ProductcatMySqlDAO();
$productCatExt = new ProductcatMySqlExtDAO();
//Productunit
$myProductunitEx = new ProductunitMySqlExtDAO();
//user
$user = new User();
$userDAO = new UserMySqlDAO();
$userEX = new UserMySqlExtDAO();
//bill
$bills = new Bill();
$billsDAO = new BillsMySqlDAO();
$billsEX = new BillsMySqlExtDAO();
//billsproducts
$billsProducts = new Billsproduct();
$billsProductsDAO = new BillsproductsMySqlDAO();
$billsProductsEX = new BillsproductsMySqlExtDAO();
//Branch
$Branch = new Branch();
$BranchDAO = new BranchMySqlDAO();
$BranchEX = new BranchMySqlExtDAO();
//paymentnetworks
$paymentNetworks = new Paymentnetwork();
$paymentNetworksDAO = new PaymentnetworksMySqlDAO();
//Store
$myStoreRecord = new StoreMySqlDAO();
//doctorkashf
$doctorKashf = new Doctorkashf();
$doctorKashfDAO = new DoctorkashfMySqlDAO();
$doctorKashfEX = new DoctorkashfMySqlExtDAO();
$storeDetail = new Storedetail();
$storeDetailDAO = new StoredetailMySqlDAO();
$storeDetailEX = new StoredetailMySqlExtDAO();
$mySave = new Save();
$mySaveDAO = new SaveMySqlDAO();
$mySaveEx = new SaveMySqlExtDAO();
//Storereport
$myStorereport = new Storereport();
$myStorereportRecord = new StorereportMySqlDAO();
$myStorereportEx = new StorereportMySqlExtDAO();
//Clientdebtchange
$myClientdebtchange = new Clientdebtchange();
$myClientdebtchangeRecord = new ClientdebtchangeMySqlDAO();
$myClientdebtchangeEx = new ClientdebtchangeMySqlExtDAO();
//user
$user = new User();
$userDAO = new UserMySqlDAO();
$userEX = new UserMySqlExtDAO();
function getCategoryChilds($parentid = 0, $service = -1) {
global $productCatExt;
global $productCatDAO;
$serviceQS = '';
if (!empty($service) && $service != -1) {
$serviceQS = ' and ( opticServices = "" or opticServices LIKE "%' . $service . '%") ';
}
//load cat
$parentobject = $productCatDAO->load($parentid);
$childsArray = $productCatExt->getChilds($parentid, $serviceQS);
return array($parentobject, $childsArray);
}
function getCatProducts($catid) {
global $productExt;
global $productCatDAO;
global $productDAO;
if ($catid > 0) {
//load cat
$parentobject = $productCatDAO->load($catid);
$productsArray = $productExt->getCatProducts($catid);
return array($parentobject, $productsArray);
}
}
function getSizeColor($catid) {
global $productExt;
global $productCatDAO;
global $productDAO;
if ($catid > 0) {
//load cat
$parentobject = $productCatDAO->load($catid);
$productsArray = $productExt->getSizeColor($catid);
return array($parentobject, $productsArray);
}
}
###########################################################################################################################################################
function loadStore() {
global $myStoreRecord;
// select all data from Storetbl
$storeData = $myStoreRecord->queryByConditions(0);
return $storeData;
}
function loadBranch() {
global $BranchDAO;
// select all data from Storetbl
$branchData = $BranchDAO->queryAll();
return $branchData;
}
function getClientData() {
global $clientExt;
$alldata = $clientExt->queryAllsup();
return $alldata;
}
// select from user tbl
function loadseller() {
//to use the variable out side the funcion
global $userEX;
// select all data from user
$userData = $userEX->queryWithLevel(3);
return $userData;
}
function loadusers() {
//to use the variable out side the funcion
global $userDAO;
// select all data from user
$userData = $userDAO->queryByConditions(0);
return $userData;
}
############################################################################################################################################
#################### add bill ####################################################################################################
function getBillDetails($billId) {
global $smarty;
global $clientDAO;
global $billsDAO;
global $doctorKashfDAO;
global $insuranceCompaniesDAO;
global $paymentNetworksDAO;
global $BranchDAO;
## bill data
$bill = $billsDAO->load($billId);
//$dayName = DateTime::createFromFormat('Y-m-d', $bill->billdate);
$dayName = new DateTime($bill->billdate); //by fatma
$smarty->assign("dayName", $dayName->format('D') . 'day');
$smarty->assign("billDate", $dayName->format('d-m-Y'));
if ($bill->branchid == 0) {
$smarty->assign("shopName", '');
} else {
$Branch = $BranchDAO->load($bill->branchid);
$smarty->assign("Branch", $Branch);
}
//$receivedate = DateTime::createFromFormat('Y-m-d H:i:s', $bill->receivedate);
$receivedate = new DateTime($bill->receivedate); //by fatma
$smarty->assign("date", $receivedate->format('d-m-Y'));
$smarty->assign("time", $receivedate->format('g:i A'));
## client name
$client = $clientDAO->load($bill->clientid);
$bill->clientname = $client->clientname;
## insurance company
if ($bill->insurance == 1 && $bill->insurancecompanyid) {
$insurancecompanies = $insuranceCompaniesDAO->load($bill->insurancecompanyid);
$bill->companyname = $insurancecompanies->name;
$smarty->assign("instruction", $insurancecompanies->instruction);
}
## payment network
if ($bill->card == 1 && $bill->paymentnetworkid) {
$paymentnetworks = $paymentNetworksDAO->load($bill->paymentnetworkid);
$bill->networkname = $paymentnetworks->name;
}
## bill kashf
$kashf = $doctorKashfDAO->load($bill->kashfid);
$smarty->assign("kashf", $kashf);
## bill products
$billProducts = getBillProducts($bill->id);
$smarty->assign("billProducts", $billProducts);
$smarty->assign("billProductsCount", count($billProducts));
## bill
$smarty->assign("bill", $bill);
print_r('<pre>');
print_r($bill);
print_r('<pre>');
}
function getBillProducts($billId) {
global $productDAO;
global $productCatDAO;
global $billsProductsEX;
$opCount = 1;
$frameCount = 1;
$billProducts = $billsProductsEX->queryByBillIdAndDeleted($billId, 0);
$i = 1;
$categories;
if (count($billProducts) > 0) {
foreach ($billProducts as $pro) {
$product = $productDAO->load($pro->productid);
$pro->productName = $product->productName;
$productCat = $productCatDAO->load($product->productCatId);
$pro->productCatName = $productCat->productCatName;
$parentId = $product->productCatId;
$pathArr = getProductPath_recursive($parentId, $categories);
$pro->productName = $product->productName . '/' . $pathArr;
if ($pro->service == "Frame") {
$no = strlen($frameCount);
$itr = $frameCount;
$pro->productCode = 'FRM';
$frameCount = $frameCount + 001;
} else {
$no = strlen($opCount);
$itr = $opCount;
$pro->productCode = 'OPT';
$opCount = $opCount + 001;
}
if ($no == 3) {
} elseif ($no == 2) {
$itr = '0' . $itr;
} else {
$itr = '00' . $itr;
}
$pro->productCode .= $itr;
}
}
return $billProducts;
}
function getProductPath_recursive($parentid, $categories) {
global $productCatExt;
$catData = $productCatExt->getCategoryAndParentByCatId($parentid);
if (count($catData) > 0) {
$categories .= $catData->productCatName . '/';
$newParentId = $catData->productCatParent;
return getProductPath_recursive($newParentId, $categories);
}
$categories = substr($categories, 0, strlen($categories) - 1);
return $categories;
}
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;
}
?>