Files
crm.twinpol.com/modules/EcmReportsBackUp20151106/AnalysisProductSale.php
2025-05-12 15:44:39 +00:00

83 lines
2.5 KiB
PHP
Executable File

<?php
require_once 'AnalysisProductSaleInclude.php';
require_once ('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
global $mod_strings, $app_list_strings;
$productCategoryList = getProductCategoryList();
$accountName = $_REQUEST["accountName"];
$accountId = $_REQUEST["accountId"];
$productName = $_REQUEST["productName"];
$productId = $_REQUEST["productId"];
if (isset($productId) && $productId != '') {
$where['productId'] = $productId;
} else if (!isset($productId) && isset($productName) && strlen($productName) > 0) {
$where['productName'] = $productName;
}
if (isset($accountId) && $accountId!='') {
$where['accountId'] = $accountId;
} else if (!isset($accountId) && isset($accountName) && strlen($accountName) > 0) {
$where['accountName'] = $accountName;
}
try {
$tmp = new DateTime(date('Y-m-31'));
$tmp2 = new DateTime(date('Y-m-01'));
$tmp2->sub(new DateInterval('P1Y'));
$where['register_date_to'] = $tmp->format('Y-m-d');
$where['register_date_from'] = $tmp2->format('Y-m-d');
// $where['register_date_to'] = '2015-07-31';
// $where['register_date_from'] = '2015-07-01';
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
//$where['type'] = 'correct';
//$where['type'] = 'normal';
$where['deleted'] = 0;
$where['canceled'] = 0;
$data = AnalysisProductSale($where);
$rows = array();
foreach ($data as $key => $value) {
$rows['netto'][] = $value['total_netto'];
// $rows['total_brutto'][] = $value['total_brutto'];
$rows['kupno'][] = $value['total_purchase'];
$rows['marza'][] = $value['total_netto'] - $value['total_purchase'];
$rows['marzaprocent'][] = (($value['total_netto'] - $value['total_purchase']) * 100) / $value['total_netto'];
}
$smarty = new Sugar_Smarty ();
$smarty->assign("MOD", $mod_strings);
$smarty->assign("DATA", $data);
$smarty->assign("ROWS", $rows);
$smarty->assign("productCategoryList", $productCategoryList);
$smarty->assign("productCategorySelected", $productCategorySelected);
$smarty->assign("accountName", $accountName);
$smarty->assign("accountId", $accountId);
$smarty->assign("productName", $productName);
$smarty->assign("productId", $productId);
if ($_GET ['to_pdf'] == '1') {
$output = $smarty->fetch('modules/EcmReports/tpls/PDF/AnalysisProductSale.tpl');
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF('', 'A4', NULL, 'helvetica', 10, 10, 10, 10, 5, 5);
$p->writeHTML($output);
$p->Output('RaportSprzedazy.pdf', 'I');
} else {
echo $smarty->display('modules/EcmReports/tpls/AnalysisProductSale.tpl');
}
?>