add *.inc files to project
This commit is contained in:
512
modules/EcmReports/ListDailySales.inc
Normal file
512
modules/EcmReports/ListDailySales.inc
Normal file
@@ -0,0 +1,512 @@
|
||||
<?php
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( 'Not A Valid Entry Point' );
|
||||
|
||||
/*****************************************************/
|
||||
/*********************** PREPARE *********************/
|
||||
/*****************************************************/
|
||||
$db = $GLOBALS ['db'];
|
||||
$data = array();
|
||||
$sum = array();
|
||||
|
||||
if(!$_GET['date_from'])
|
||||
$date_from = date("Y-m-01");
|
||||
else
|
||||
$date_from = $_GET["date_from"];
|
||||
|
||||
if(!$_GET['date_to'])
|
||||
$date_to = date("Y-m-d");
|
||||
else
|
||||
$date_to = $_GET["date_to"];
|
||||
|
||||
$contractorName = $_GET['account_name'];
|
||||
$contractorId = $_GET['account_id'];
|
||||
$searchByType = $_GET['type'];
|
||||
|
||||
$date_from_to_query = new DateTime($date_from);
|
||||
$date_to_to_query = new DateTime($date_to);
|
||||
|
||||
// Get value pdfType from multiple select
|
||||
$pdfTypeU = false;
|
||||
$pdfTypeK = false;
|
||||
$pdfTypeE = false;
|
||||
|
||||
if( $_GET['pdfType'] && $_GET['pdfType'] != "")
|
||||
foreach( $_GET['pdfType'] as $selectedOption )
|
||||
{
|
||||
switch($selectedOption)
|
||||
{
|
||||
case "U":
|
||||
$pdfTypeU = true;
|
||||
break;
|
||||
case "K":
|
||||
$pdfTypeK = true;
|
||||
break;
|
||||
case "E":
|
||||
$pdfTypeE = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************/
|
||||
/******************* QUERY MODEL *********************/
|
||||
/*****************************************************/
|
||||
|
||||
$query = "SELECT
|
||||
(SELECT
|
||||
name
|
||||
FROM
|
||||
accounts
|
||||
WHERE
|
||||
id = e.parent_id) as contractorName,
|
||||
e.id,
|
||||
e.parent_id,
|
||||
e.purchase_price,
|
||||
e.total_brutto as 'total',
|
||||
e.total_netto as 'subtotal',
|
||||
e.document_no,
|
||||
e.type,
|
||||
e.pdf_type,
|
||||
e.ecminvoiceout_id,
|
||||
e.register_date,
|
||||
e.currency_value,
|
||||
e.discount,
|
||||
e.deleted,
|
||||
e.canceled,
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
(i.total_netto)*e.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '1'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'subPriceGroupKS1',
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '2'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'subPriceGroupKS2',
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '3'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'subPriceGroupKS3',
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '4'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'subPriceGroupKS4',
|
||||
|
||||
(SELECT
|
||||
sum(i.quantity * i.price_purchase)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '1'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'purchasePriceGroupKS1',
|
||||
|
||||
(SELECT
|
||||
sum(i.quantity * i.price_purchase)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '2'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'purchasePriceGroupKS2',
|
||||
|
||||
(SELECT
|
||||
sum(i.quantity * i.price_purchase)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '3'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'purchasePriceGroupKS3',
|
||||
|
||||
(SELECT
|
||||
sum(i.quantity * i.price_purchase)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
inner join
|
||||
ecmproducts p ON i.ecmproduct_id = p.id
|
||||
WHERE
|
||||
i.ecminvoiceout_id = e.id AND p.group_ks = '4'
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
GROUP BY
|
||||
i.ecminvoiceout_id) as 'purchasePriceGroupKS4',
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
WHERE
|
||||
i.ecmvat_value = '0'
|
||||
AND e.id = i.ecminvoiceout_id
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
) as 'vata',
|
||||
|
||||
(SELECT
|
||||
sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
END)
|
||||
FROM
|
||||
ecminvoiceoutitems i
|
||||
WHERE
|
||||
i.ecmvat_value = '22'
|
||||
AND e.id = i.ecminvoiceout_id
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0'
|
||||
) as 'vatb',
|
||||
|
||||
(SELECT sum(
|
||||
CASE WHEN e.type!='correct'
|
||||
THEN
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto
|
||||
ELSE
|
||||
i.total_netto*e.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN i.old_ecminvoiceoutitem_id is null OR i.old_ecminvoiceoutitem_id = ''
|
||||
THEN
|
||||
0
|
||||
ELSE
|
||||
CASE WHEN e.currency_value is null or e.currency_value='' or e.currency_value=0
|
||||
THEN
|
||||
i.total_netto_corrected
|
||||
ELSE
|
||||
i.total_netto_corrected*e.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
END)
|
||||
FROM ecminvoiceoutitems i
|
||||
WHERE
|
||||
i.ecmvat_value = '23'
|
||||
AND e.id = i.ecminvoiceout_id
|
||||
AND e.canceled='0'
|
||||
AND e.deleted='0'
|
||||
AND i.deleted='0') as 'vatc'
|
||||
|
||||
FROM
|
||||
ecminvoiceouts e
|
||||
WHERE
|
||||
e.canceled=0
|
||||
AND e.deleted=0
|
||||
AND e.register_date BETWEEN '".$date_from_to_query->format('Y-m-d')."'
|
||||
AND '".$date_to_to_query->format('Y-m-d')."'
|
||||
|
||||
";
|
||||
|
||||
|
||||
// vata = 0%
|
||||
// vatb = 22%
|
||||
// vatc = 23%
|
||||
// If user want to see invoices from only one contractor
|
||||
if($contractorName && $contractorId)
|
||||
{
|
||||
$query .= " AND e.parent_id = '".$contractorId."'";
|
||||
}
|
||||
// If user want to see invoices by type
|
||||
if($searchByType)
|
||||
{
|
||||
$query .= " AND e.type = '".$searchByType."'";
|
||||
}
|
||||
// If user want to see invoices by pdfType
|
||||
if($pdfTypeU || $pdfTypeK || $pdfTypeE)
|
||||
{
|
||||
// One selection
|
||||
if($pdfTypeU && !$pdfTypeK && !$pdfTypeE)
|
||||
$query .= " AND e.pdf_type = 'U'";
|
||||
if(!$pdfTypeU && $pdfTypeK && !$pdfTypeE)
|
||||
$query .= " AND e.pdf_type = 'K'";
|
||||
if(!$pdfTypeU && !$pdfTypeK && $pdfTypeE)
|
||||
$query .= " AND e.pdf_type = 'E'";
|
||||
|
||||
// Two selections
|
||||
if($pdfTypeU && $pdfTypeK && !$pdfTypeE)
|
||||
$query .= " AND (e.pdf_type = 'U' OR e.pdf_type = 'K')";
|
||||
if($pdfTypeU && !$pdfTypeK && $pdfTypeE)
|
||||
$query .= " AND (e.pdf_type = 'U' OR e.pdf_type = 'E')";
|
||||
if(!$pdfTypeU && $pdfTypeK && $pdfTypeE)
|
||||
$query .= " AND (e.pdf_type = 'K' OR e.pdf_type = 'E')";
|
||||
|
||||
// Three selections
|
||||
if($pdfTypeU && $pdfTypeK && $pdfTypeE)
|
||||
$query .= " AND (e.pdf_type = 'U' OR e.pdf_type = 'K' OR e.pdf_type = 'E')";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************/
|
||||
/*************** GET DATA FROM DB*********************/
|
||||
/*****************************************************/
|
||||
$normalInvoicesCount = 0;
|
||||
$allInvoicesCount = 0;
|
||||
$rows = $db->query ($query);
|
||||
|
||||
// prepare data for Smarty
|
||||
while( $r = $db->fetchByAssoc ( $rows ))
|
||||
{
|
||||
$row = array();
|
||||
// If invoice is canceled or dleted don't display
|
||||
if(!$r["deleted"] && !$r["canceled"])
|
||||
{
|
||||
$row["id"] = $r["parent_id"];
|
||||
$row["invoiceoutId"] = $r["id"];
|
||||
$row["purchase_price"] = $r["purchase_price"];
|
||||
$row["document_no"] = $r["document_no"];
|
||||
$row["type"] = $r["type"];
|
||||
$row["pdf_type"] = $r["pdf_type"];
|
||||
$row["invoiceout_id"] = $r["ecminvoiceout_id"];
|
||||
$row["register_date"] = $r["register_date"];
|
||||
$row["vata"] = $r["vata"]; // 0%
|
||||
$row["vatb"] = $r["vatb"]; // 22%
|
||||
$row["vatc"] = $r["vatc"]; // 23%
|
||||
/////////////////////////////////////////////////////////
|
||||
$row["currency_value"] = $r["currency_value"] == 0 ? 1 : $r["currency_value"];
|
||||
$row["subtotal"] = $r["subtotal"]*$row["currency_value"];
|
||||
$row["total"] = $r["total"]*$row["currency_value"];
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
$row["discount"] = $r["discount"] * $row["currency_value"];
|
||||
$row["contractorName"] = $r["contractorName"];
|
||||
/////////////////// MARGIN AND COST /////////////////////
|
||||
if( $r['type'] == 'correcttttt' )
|
||||
{
|
||||
$row["margin"] = 0;
|
||||
$allInvoicesCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$normalInvoicesCount++;
|
||||
$allInvoicesCount++;
|
||||
$row["margin"] = ($row['subtotal'] - $row['purchase_price'])/($row['subtotal'])*100;
|
||||
}
|
||||
|
||||
$row["cost"] = $r['purchase_price'];
|
||||
////////////////// Price sum in GroupKS ////////////////
|
||||
|
||||
$row["subPriceGroupKS1"] = $r["subPriceGroupKS1"];
|
||||
$row["subPriceGroupKS2"] = $r["subPriceGroupKS2"];
|
||||
$row["subPriceGroupKS3"] = $r["subPriceGroupKS3"];
|
||||
$row["subPriceGroupKS4"] = $r["subPriceGroupKS4"];
|
||||
$row["purchasePriceGroupKS1"] = $r["purchasePriceGroupKS1"];
|
||||
$row["purchasePriceGroupKS2"] = $r["purchasePriceGroupKS2"];
|
||||
$row["purchasePriceGroupKS3"] = $r["purchasePriceGroupKS3"];
|
||||
$row["purchasePriceGroupKS4"] = $r["purchasePriceGroupKS4"];
|
||||
|
||||
|
||||
$data [] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////// SUM /////////////////////////////////
|
||||
foreach( $data as &$element )
|
||||
{
|
||||
|
||||
$sum["subtotalSum"] += $element["subtotal"];
|
||||
$sum["subPriceGroupKS1Sum"] += $element["subPriceGroupKS1"];
|
||||
$sum["subPriceGroupKS2Sum"] += $element["subPriceGroupKS2"];
|
||||
$sum["subPriceGroupKS3Sum"] += $element["subPriceGroupKS3"];
|
||||
$sum["subPriceGroupKS4Sum"] += $element["subPriceGroupKS4"];
|
||||
$sum["totalSum"] += $element["total"];
|
||||
$sum["costSum"] += $element["cost"];
|
||||
$sum["purchasePriceGroupKS1Sum"] += $element["purchasePriceGroupKS1"];
|
||||
$sum["purchasePriceGroupKS2Sum"] += $element["purchasePriceGroupKS2"];
|
||||
$sum["purchasePriceGroupKS3Sum"] += $element["purchasePriceGroupKS3"];
|
||||
$sum["purchasePriceGroupKS4Sum"] += $element["purchasePriceGroupKS4"];
|
||||
$sum["marginSum"] += $element["margin"];
|
||||
$sum["vataSum"] += $element["vata"];
|
||||
$sum["vatbSum"] += $element["vatb"];
|
||||
$sum["vatcSum"] += $element["vatc"];
|
||||
}
|
||||
|
||||
$sum["marginSum"] = ($sum["subtotalSum"] - $sum["costSum"]) / ($sum['subtotalSum']) * 100;
|
||||
?>
|
||||
92
modules/EcmReports/ReportBuyesByVat.inc
Normal file
92
modules/EcmReports/ReportBuyesByVat.inc
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/class/class.PurchaseInvoiceH.php';
|
||||
|
||||
/**
|
||||
* **************************************************
|
||||
*/
|
||||
/**
|
||||
* ****************** GET DATA **********************
|
||||
*/
|
||||
/**
|
||||
* **************************************************
|
||||
*/
|
||||
|
||||
// Ustawienia daty
|
||||
if (! $_GET ['date_from'])
|
||||
$date_from = date ( "Y-m-01" );
|
||||
else
|
||||
$date_from = $_GET ["date_from"];
|
||||
|
||||
if (! $_GET ['date_to'])
|
||||
$date_to = date ( "Y-m-d" );
|
||||
else
|
||||
$date_to = $_GET ["date_to"];
|
||||
|
||||
if (! isset ( $_GET ["type"] )) {
|
||||
$type = "fv";
|
||||
} else {
|
||||
$type = $_GET ["type"];
|
||||
}
|
||||
|
||||
$category = array ();
|
||||
|
||||
if (isset ( $_GET ['category'] )) {
|
||||
array_push($category, $_GET["category"]);
|
||||
}
|
||||
|
||||
$date_from_to_query = date_format(new DateTime($date_from), "Y-m-d");
|
||||
$date_to_to_query = date_format(new DateTime($date_to), "Y-m-d");
|
||||
|
||||
|
||||
// Sumowanie koЕ„cowych wartoЕ›ci
|
||||
$totalPurchasePrice = 0;
|
||||
$totalBruttoSum = 0;
|
||||
$totalNetto23 = 0;
|
||||
$totalNetto0 = 0;
|
||||
$totalVat23 = 0;
|
||||
$totalVat = 0;
|
||||
|
||||
foreach ( $data as $row ) { //TODO dynamiczna tablica wyciД…gajД…ca te vaty.
|
||||
$totalBruttoSum += $row ["total_brutto"];
|
||||
$totalNetto7 += $row ['netto7'];
|
||||
$totalVat7 += $row ["netto7"] * 0.07;
|
||||
$totalNetto8 += $row ['netto8'];
|
||||
$totalVat8 += $row ["netto8"] * 0.08;
|
||||
$totalNetto22 += $row ['netto22'];
|
||||
$totalVat22 += $row ["netto22"] * 0.22;
|
||||
$totalNetto23 += $row ["netto23"];
|
||||
$totalVat23 += $row ["netto23"] * 0.23;
|
||||
$totalNetto0 += $row ["netto0"];
|
||||
$totalVat += $row ["netto23"] * 0.23 + $row ['netto22'] * 0.22 + $row ['netto8'] * 0.08 + $row ['netto7'] * 0.07;
|
||||
$totalPurchasePrice += $row ["purchase_price"];
|
||||
}
|
||||
|
||||
$showNetto0 = false;
|
||||
$showNetto7 = false;
|
||||
$showNetto8 = false;
|
||||
$showNetto22 = false;
|
||||
$showNetto23 = false;
|
||||
foreach ( $data as $row ) {
|
||||
if ($row ["netto0"] != "" && $row ["netto0"] != "0" && $row ["netto0"] != NULL && $showNetto0 == false) {
|
||||
$showNetto0 = true;
|
||||
}
|
||||
if ($row ["netto7"] != "" && $row ["netto7"] != "0" && $row ["netto7"] != NULL && $showNetto7 == false) {
|
||||
$showNetto7 = true;
|
||||
}
|
||||
if ($row ["netto22"] != "" && $row ["netto22"] != "0" && $row ["netto22"] != NULL && $showNetto22 == false) {
|
||||
$showNetto22 = true;
|
||||
}
|
||||
if ($row ["netto23"] != "" && $row ["netto23"] != "0" && $row ["netto23"] != NULL && $showNetto23 == false) {
|
||||
$showNetto23 = true;
|
||||
}
|
||||
|
||||
if ($showNetto0 && $showNetto7 && $showNetto8 && $showNetto22 && $showNetto23) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo "<pre>";
|
||||
print_r($data);
|
||||
echo "</pre>";
|
||||
|
||||
?>
|
||||
547
modules/EcmReports/ReportSalesByContractor.inc
Normal file
547
modules/EcmReports/ReportSalesByContractor.inc
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( 'Not A Valid Entry Point' );
|
||||
|
||||
/*****************************************************/
|
||||
/*********************** PREPARE *********************/
|
||||
/*****************************************************/
|
||||
$db = $GLOBALS ['db'];
|
||||
|
||||
if($_GET['selectUser']!="")
|
||||
{
|
||||
$selectUser=$_GET['selectUser'];
|
||||
}else{
|
||||
$selectUser="";
|
||||
}
|
||||
|
||||
if($_GET['selectPdfType']!="")
|
||||
{
|
||||
$selectPdfType=$_GET['selectPdfType'];
|
||||
}else{
|
||||
$selectPdfType="";
|
||||
}
|
||||
|
||||
$group_media_saturn_holding = $_GET["group_media_saturn_holding"];
|
||||
$data = array();
|
||||
$categoryArray = array();
|
||||
|
||||
$sum = array();
|
||||
$sumContracor = array();
|
||||
$sumCategory = array();
|
||||
$sumSubCategory = array();
|
||||
if(!$_GET['date_from'])
|
||||
$date_from = date("Y-m-01");
|
||||
else
|
||||
$date_from = $_GET["date_from"];
|
||||
|
||||
if(!$_GET['date_to'])
|
||||
$date_to = date("Y-m-d");
|
||||
else
|
||||
$date_to = $_GET["date_to"];
|
||||
|
||||
$searchByType = $_GET['type'];
|
||||
|
||||
$date_from_to_query = new DateTime($date_from);
|
||||
$date_to_to_query = new DateTime($date_to);
|
||||
|
||||
$datausers = array();
|
||||
$users = array();
|
||||
$queryUsers="SELECT
|
||||
first_name as 'first',
|
||||
last_name as 'last',
|
||||
id
|
||||
FROM users
|
||||
;";
|
||||
// Usuniete z powyzszego zapytania na polecenie Michała
|
||||
//where deleted= 0
|
||||
//and status = 'Active'
|
||||
|
||||
$rowsUsers= $db->query ($queryUsers);
|
||||
while($rowUser = $db->fetchByAssoc ( $rowsUsers ))
|
||||
{
|
||||
$users["first"] = $rowUser["first"];
|
||||
$users["last"] = $rowUser["last"];
|
||||
$users["id"] = $rowUser["id"];
|
||||
$datausers [] = $users;
|
||||
}
|
||||
|
||||
$query = "SELECT
|
||||
faktura.parent_name as 'parent',
|
||||
acco.parent_id as 'parent_id',
|
||||
faktura.parent_id as 'cotructor_id',
|
||||
pozycja.name as 'name',
|
||||
pozycja.ecmproduct_id as 'id',
|
||||
pozycja.code,
|
||||
faktura.type as 'type',
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
CASE WHEN faktura.currency_value is null or faktura.currency_value='' or faktura.currency_value=0
|
||||
THEN
|
||||
pozycja.total_netto
|
||||
ELSE
|
||||
pozycja.total_netto*faktura.currency_value
|
||||
END
|
||||
ELSE
|
||||
|
||||
CASE WHEN faktura.currency_value is null or faktura.currency_value='' or faktura.currency_value=0
|
||||
THEN
|
||||
pozycja.total_netto_corrected
|
||||
ELSE
|
||||
pozycja.total_netto_corrected*faktura.currency_value
|
||||
END
|
||||
|
||||
END
|
||||
) as netto,
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
pozycja.quantity
|
||||
ELSE
|
||||
pozycja.quantity_corrected
|
||||
END
|
||||
) as ilosc,
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
pozycja.price_purchase*pozycja.quantity
|
||||
ELSE
|
||||
pozycja.price_purchase*pozycja.quantity_corrected
|
||||
END
|
||||
) as koszt
|
||||
FROM
|
||||
ecminvoiceoutitems pozycja
|
||||
JOIN
|
||||
ecminvoiceouts faktura ON pozycja.ecminvoiceout_id = faktura.id
|
||||
JOIN
|
||||
accounts acco ON acco.id = faktura.parent_id
|
||||
WHERE
|
||||
faktura.register_date BETWEEN
|
||||
'".$date_from_to_query->format('Y-m-d')."' AND
|
||||
'".$date_to_to_query->format('Y-m-d')."'
|
||||
and faktura.type like '".$searchByType."'
|
||||
and faktura.canceled = 0
|
||||
and faktura.deleted= 0";
|
||||
if ($selectPdfType!="")
|
||||
$query.= " and faktura.pdf_type='$selectPdfType'";
|
||||
$query .= " and pozycja.deleted= 0
|
||||
GROUP BY pozycja.id
|
||||
ORDER BY faktura.parent_name
|
||||
COLLATE utf8_polish_ci;";
|
||||
/*****************************************************/
|
||||
/*************** GET DATA FROM DB*********************/
|
||||
/*****************************************************/
|
||||
$rows = $db->query ($query);
|
||||
|
||||
// prepare data for Smarty
|
||||
while($r = $db->fetchByAssoc ( $rows ))
|
||||
{
|
||||
$row = array();
|
||||
$row["id"] = $r["id"];
|
||||
$row["name"] = $r["name"];
|
||||
$row["code"] = $r["code"];
|
||||
$row["type"] = $r["type"];
|
||||
|
||||
$userBool=1;
|
||||
if($selectUser!="")
|
||||
{
|
||||
$userBool=0;
|
||||
$querySelectUsers="SELECT user.id,
|
||||
first_name as 'first',
|
||||
last_name as 'last'
|
||||
FROM
|
||||
accounts acc
|
||||
JOIN
|
||||
users user ON acc.assigned_user_id=user.id
|
||||
WHERE acc.id='".$r["cotructor_id"]."';";
|
||||
$rowsSelectUsers = $db->query ($querySelectUsers);
|
||||
while($rowSelectUser = $db->fetchByAssoc ( $rowsSelectUsers ))
|
||||
{
|
||||
if($rowSelectUser["id"]==$selectUser)
|
||||
{
|
||||
$userBool=1;
|
||||
}else{
|
||||
$userBool=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($userBool==1)
|
||||
{
|
||||
|
||||
if($r["parent_id"]==1249 && $group_media_saturn_holding == "enabled")
|
||||
{
|
||||
$row["parent"] = "Media Saturn Holding";
|
||||
}else{
|
||||
$row["parent"] = $r["parent"];
|
||||
}
|
||||
|
||||
$querySubCategory="SELECT category.name as 'podkategoria'
|
||||
FROM
|
||||
ecmproductcategories_bean bean
|
||||
JOIN
|
||||
ecmproductcategories category ON bean.ecmproductcategory_id = category.id
|
||||
WHERE bean.bean_id='".$row["id"]."'
|
||||
and category.deleted=0
|
||||
and bean.deleted = '0'
|
||||
and bean.position = 1;";
|
||||
$rowsSubCategory = $db->query ($querySubCategory);
|
||||
while($rowSubCategory = $db->fetchByAssoc ( $rowsSubCategory ))
|
||||
{
|
||||
$row["podkategoria"] = $rowSubCategory["podkategoria"];
|
||||
}
|
||||
|
||||
$queryCategory="SELECT category.name as 'kategoria'
|
||||
FROM
|
||||
ecmproductcategories_bean bean
|
||||
JOIN
|
||||
ecmproductcategories category ON bean.ecmproductcategory_id = category.id
|
||||
WHERE bean.bean_id='".$row["id"]."'
|
||||
and category.deleted=0
|
||||
and bean.deleted = '0'
|
||||
and bean.position = 0;";
|
||||
|
||||
$rowscategory = $db->query ($queryCategory);
|
||||
while($rowcategory = $db->fetchByAssoc ( $rowscategory ))
|
||||
{
|
||||
//echo "assadad";
|
||||
$row["kategoria"] = $rowcategory["kategoria"];
|
||||
}
|
||||
|
||||
$row["ilosc"] = $r["ilosc"];
|
||||
$row["netto"] = $r["netto"];
|
||||
$row["srednia"] = $row["netto"]/$row["ilosc"];
|
||||
|
||||
$row["srednia"] = 5;
|
||||
|
||||
$row["koszt"] = $r["koszt"];
|
||||
|
||||
//if($row["netto"]>$row["koszt"])
|
||||
//{
|
||||
$row["marza"] = ($row["netto"]-$row["koszt"])/($row["netto"])*100;
|
||||
//}else{
|
||||
// $row["marza"] = 5;
|
||||
//$row["marza"] = ($row["netto"]-$row["koszt"])/($row["netto"])*100;
|
||||
//}
|
||||
$data [] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if($searchByType!="")
|
||||
{
|
||||
|
||||
////////////////// SUM /////////////////////////////////
|
||||
foreach( $data as $key=>&$element )
|
||||
{
|
||||
if($element["netto"]!=0)
|
||||
{
|
||||
$categoryArray[$element["parent"] == "" ? "Nieznany" : $element["parent"]][$element["kategoria"] == "" ? "Inne" : $element["kategoria"]][$element["podkategoria"] == "" ? "Reszta" : $element["podkategoria"]][$key] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $categoryArray as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category=>&$elementCategory )
|
||||
{
|
||||
foreach( $elementCategory as $subcategory=>&$elementSubCategory )
|
||||
{
|
||||
foreach( $elementSubCategory as $product=>&$elementProduct )
|
||||
{
|
||||
$sumContracor["IloscSum"][$parent] += $elementProduct["ilosc"];
|
||||
$sumContracor["SoldSum"][$parent] += $elementProduct["netto"];
|
||||
//if($elementProduct["type"]=="normal")
|
||||
//{
|
||||
$sumContracor["SoldSumNormal"][$parent] += $elementProduct["netto"];
|
||||
$sumContracor["IloscNormal"][$parent] += $elementProduct["ilosc"];
|
||||
// }else{
|
||||
// $sumContracor["SoldSumNormal"][$parent] += 0;
|
||||
// $sumContracor["IloscNormal"][$parent] += 0;
|
||||
//}
|
||||
$sumContracor["KosztSum"][$parent] += $elementProduct["koszt"];
|
||||
|
||||
$sumCategory["IloscSum"][$parent][$category] += $elementProduct["ilosc"];
|
||||
$sumCategory["SoldSum"][$parent][$category] += $elementProduct["netto"];
|
||||
//if($elementProduct["type"]=="normal")
|
||||
//{
|
||||
$sumCategory["SoldSumNormal"][$parent][$category] += $elementProduct["netto"];
|
||||
$sumCategory["IloscNormal"][$parent][$category] += $elementProduct["ilosc"];
|
||||
//}else{
|
||||
// $sumCategory["SoldSumNormal"][$parent][$category] += 0;
|
||||
// $sumCategory["IloscNormal"][$parent][$category] += 0;
|
||||
//}
|
||||
$sumCategory["KosztSum"][$parent][$category] += $elementProduct["koszt"];
|
||||
|
||||
$sumSubCategory["IloscSum"][$parent][$category][$subcategory] += $elementProduct["ilosc"];
|
||||
$sumSubCategory["SoldSum"][$parent][$category][$subcategory] += $elementProduct["netto"];
|
||||
//if($elementProduct["type"]=="normal")
|
||||
//{
|
||||
$sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory] += $elementProduct["netto"];
|
||||
$sumSubCategory["IloscNormal"][$parent][$category][$subcategory] += $elementProduct["ilosc"];
|
||||
//}else{
|
||||
// $sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory] += 0;
|
||||
// $sumSubCategory["IloscNormal"][$parent][$category][$subcategory] += 0;
|
||||
//}
|
||||
$sumSubCategory["KosztSum"][$parent][$category][$subcategory] += $elementProduct["koszt"];
|
||||
}
|
||||
$sumSubCategory["MarzaSum"][$parent][$category][$subcategory] = ($sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory]-$sumSubCategory["KosztSum"][$parent][$category][$subcategory])/$sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory]*100;
|
||||
$sumSubCategory["SredniaSum"][$parent][$category][$subcategory] = $sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory]/$sumSubCategory["IloscNormal"][$parent][$category][$subcategory];
|
||||
|
||||
$categoryArray[$parent][$category][$subcategory]["IloscSum"] = $sumSubCategory["IloscSum"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["SoldSum"] = $sumSubCategory["SoldSum"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["SoldSumNormal"] = $sumSubCategory["SoldSumNormal"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["IloscNormal"] = $sumSubCategory["IloscNormal"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["SredniaSum"] = $sumSubCategory["SredniaSum"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["KosztSum"] = $sumSubCategory["KosztSum"][$parent][$category][$subcategory];
|
||||
$categoryArray[$parent][$category][$subcategory]["MarzaSum"] = $sumSubCategory["MarzaSum"][$parent][$category][$subcategory];
|
||||
}
|
||||
$sumCategory["MarzaSum"][$parent][$category] = ($sumCategory["SoldSumNormal"][$parent][$category]-$sumCategory["KosztSum"][$parent][$category])/$sumCategory["SoldSumNormal"][$parent][$category]*100;
|
||||
$sumCategory["SredniaSum"][$parent][$category] = $sumCategory["SoldSumNormal"][$parent][$category]/$sumCategory["IloscNormal"][$parent][$category];
|
||||
|
||||
$categoryArray[$parent][$category]["IloscSum"] = $sumCategory["IloscSum"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["SoldSum"] = $sumCategory["SoldSum"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["SoldSumNormal"] = $sumCategory["SoldSumNormal"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["IloscNormal"] = $sumCategory["IloscNormal"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["SredniaSum"] = $sumCategory["SredniaSum"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["KosztSum"] = $sumCategory["KosztSum"][$parent][$category];
|
||||
$categoryArray[$parent][$category]["MarzaSum"] = $sumCategory["MarzaSum"][$parent][$category];
|
||||
}
|
||||
$sumContracor["MarzaSum"][$parent] = ($sumContracor["SoldSumNormal"][$parent]-$sumContracor["KosztSum"][$parent])/$sumContracor["SoldSumNormal"][$parent]*100;
|
||||
$sumContracor["SredniaSum"][$parent] = $sumContracor["SoldSumNormal"][$parent]/$sumContracor["IloscNormal"][$parent];
|
||||
|
||||
$categoryArray[$parent]["IloscSum"] = $sumContracor["IloscSum"][$parent];
|
||||
$categoryArray[$parent]["SoldSum"] = $sumContracor["SoldSum"][$parent];
|
||||
$categoryArray[$parent]["SoldSumNormal"] = $sumContracor["SoldSumNormal"][$parent];
|
||||
$categoryArray[$parent]["IloscNormal"] = $sumContracor["IloscNormal"][$parent];
|
||||
$categoryArray[$parent]["SredniaSum"] = $sumContracor["SredniaSum"][$parent];
|
||||
$categoryArray[$parent]["KosztSum"] = $sumContracor["KosztSum"][$parent];
|
||||
$categoryArray[$parent]["MarzaSum"] = $sumContracor["MarzaSum"][$parent];
|
||||
|
||||
}
|
||||
foreach( $categoryArray as $parent=>&$elementParent )
|
||||
{
|
||||
$sum["IloscSumSum"] += $sumContracor["IloscSum"][$parent];
|
||||
$sum["SoldSumSum"] += $sumContracor["SoldSum"][$parent];
|
||||
$sum["SoldSumNormal"] += $sumContracor["SoldSumNormal"][$parent];
|
||||
$sum["IloscNormal"] += $sumContracor["IloscNormal"][$parent];
|
||||
$sum["KosztSumSum"] += $sumContracor["KosztSum"][$parent];
|
||||
}
|
||||
$sum["MarzaSumSum"] = ($sum["SoldSumNormal"]-$sum["KosztSumSum"])/$sum["SoldSumNormal"]*100;
|
||||
$sum["SredniaSumSum"] = $sum["SoldSumNormal"]/$sum["IloscNormal"];
|
||||
|
||||
//mz: dotąd jest OK
|
||||
|
||||
function cmp($a, $b)
|
||||
{
|
||||
if ($a["id"] == $b["id"]) {
|
||||
return 0;
|
||||
}
|
||||
return ($a["id"] < $b["id"]) ? -1 : 1;
|
||||
}
|
||||
|
||||
// grupowanie po kontrahentach
|
||||
foreach($categoryArray as $parent=>&$elementParent )
|
||||
{
|
||||
$tmp2[$parent]["IloscSum"] = $categoryArray[$parent]["IloscSum"];
|
||||
$tmp2[$parent]["SoldSum"] = $categoryArray[$parent]["SoldSum"];
|
||||
$tmp2[$parent]["SoldSumNormal"] = $categoryArray[$parent]["SoldSumNormal"];
|
||||
$tmp2[$parent]["IloscNormal"] = $categoryArray[$parent]["IloscNormal"];
|
||||
$tmp2[$parent]["KosztSum"] = $categoryArray[$parent]["KosztSum"];
|
||||
$tmp2[$parent]["SredniaSum"] = 0;
|
||||
$tmp2[$parent]["SredniaSum"] = $categoryArray[$parent]["SredniaSum"];
|
||||
$tmp2[$parent]["MarzaSum"] = $categoryArray[$parent]["MarzaSum"];
|
||||
foreach($elementParent as $category=>&$elementCategory)
|
||||
{
|
||||
$tmp2[$parent][$category]["IloscSum"] = $categoryArray[$parent][$category]["IloscSum"];
|
||||
$tmp2[$parent][$category]["SoldSum"] = $categoryArray[$parent][$category]["SoldSum"];
|
||||
$tmp2[$parent][$category]["SoldSumNormal"] = $categoryArray[$parent][$category]["SoldSumNormal"];
|
||||
$tmp2[$parent][$category]["IloscNormal"] = $categoryArray[$parent][$category]["IloscNormal"];
|
||||
$tmp2[$parent][$category]["KosztSum"] = $categoryArray[$parent][$category]["KosztSum"];
|
||||
$tmp2[$parent][$category]["SredniaSum"] = $categoryArray[$parent][$category]["SredniaSum"];
|
||||
$tmp2[$parent][$category]["MarzaSum"] = $categoryArray[$parent][$category]["MarzaSum"];
|
||||
foreach( $elementCategory as $subcategory=>&$elementSubCategory )
|
||||
{
|
||||
|
||||
$tmp2[$parent][$category][$subcategory]["IloscSum"] = $categoryArray[$parent][$category][$subcategory]["IloscSum"];
|
||||
$tmp2[$parent][$category][$subcategory]["SoldSum"] = $categoryArray[$parent][$category][$subcategory]["SoldSum"];
|
||||
$tmp2[$parent][$category][$subcategory]["SoldSumNormal"] = $categoryArray[$parent][$category][$subcategory]["SoldSumNormal"];
|
||||
$tmp2[$parent][$category][$subcategory]["IloscNormal"] = $categoryArray[$parent][$category][$subcategory]["IloscNormal"];
|
||||
$tmp2[$parent][$category][$subcategory]["KosztSum"] = $categoryArray[$parent][$category][$subcategory]["KosztSum"];
|
||||
$tmp2[$parent][$category][$subcategory]["SredniaSum"] = $categoryArray[$parent][$category][$subcategory]["SredniaSum"];
|
||||
$tmp2[$parent][$category][$subcategory]["MarzaSum"] = $categoryArray[$parent][$category][$subcategory]["MarzaSum"];
|
||||
|
||||
|
||||
usort($elementSubCategory, "cmp");
|
||||
$i=0;
|
||||
$tmp2[$parent][$category][$subcategory][0]= array ('is' => null);
|
||||
foreach($elementSubCategory as $count=>&$element3)
|
||||
{
|
||||
if($element3["id"]!=$tmp2[$parent][$category][$subcategory][$i]["id"])
|
||||
{
|
||||
if($tmp2[$parent][$category][$subcategory][$i]["id"]!=null)
|
||||
{
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$tmp2[$parent][$category][$subcategory][$i]["id"]=$element3["id"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["name"]=$element3["name"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["code"]=$element3["code"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["parent_id"]=$element3["parent_id"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["stan"] = $element3["stan"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["wartosc"] = $element3["wartosc"];
|
||||
|
||||
$tmp2[$parent]["StanSum"] += $element3["stan"];
|
||||
$tmp2[$parent]["WartoscSum"] += $element3["wartosc"];
|
||||
|
||||
$tmp2[$parent][$category]["StanSum"] += $element3["stan"];
|
||||
$tmp2[$parent][$category]["WartoscSum"] += $element3["wartosc"];
|
||||
|
||||
$tmp2[$parent][$category][$subcategory]["StanSum"] += $element3["stan"];
|
||||
$tmp2[$parent][$category][$subcategory]["WartoscSum"] += $element3["wartosc"];
|
||||
|
||||
$tmp2[$parent][$category][$subcategory][$i]["nettoNormal"] += $element3["netto"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["IloscNormal"] += $element3["ilosc"];
|
||||
|
||||
$tmp2[$parent][$category][$subcategory][$i]["ilosc"] += $element3["ilosc"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["netto"] += $element3["netto"];
|
||||
$tmp2[$parent][$category][$subcategory][$i]["koszt"] += $element3["koszt"];
|
||||
|
||||
}
|
||||
if(is_array($tmp2[$parent][$category][$subcategory]["SredniaSum"]) || $tmp2[$parent][$category][$subcategory]["SredniaSum"]=="")
|
||||
{
|
||||
$tmp2[$parent][$category][$subcategory]["SredniaSum"] = 0;
|
||||
}
|
||||
}
|
||||
if(is_array($tmp2[$parent][$category]["SredniaSum"]))
|
||||
{
|
||||
$tmp2[$parent][$category]["SredniaSum"] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($tmp2[$parent]["SredniaSum"]))
|
||||
{
|
||||
$tmp2[$parent]["SredniaSum"] = 0;
|
||||
}
|
||||
|
||||
$categoryArray1=$tmp2;
|
||||
}
|
||||
////////////////// SORT sumSubCategory /////////////////////////////////
|
||||
foreach( $categoryArray1 as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category=>&$elementCategory )
|
||||
{
|
||||
foreach( $elementCategory as $SubCategory1=>&$elementSubCategory1)
|
||||
{
|
||||
foreach( $elementCategory as $SubCategory2=>&$elementSubCategory2 )
|
||||
{
|
||||
if($sumSubCategory["SoldSum"][$parent][$category][$SubCategory1]>$sumSubCategory["SoldSum"][$parent][$category][$SubCategory2])
|
||||
{
|
||||
$tmp=$sumSubCategory["SoldSum"][$parent][$category][$SubCategory1];
|
||||
$sumSubCategory["SoldSum"][$parent][$category][$SubCategory1]=$sumSubCategory["SoldSum"][$parent][$category][$SubCategory2];
|
||||
$sumSubCategory["SoldSum"][$parent][$category][$SubCategory2]=$tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////// SORT sumCategory /////////////////////////////////
|
||||
foreach( $categoryArray1 as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category1=>&$elementCategory1 )
|
||||
{
|
||||
foreach( $elementParent as $category2=>&$elementCategory2 )
|
||||
{
|
||||
if($sumCategory["SoldSum"][$parent][$category1]>$sumCategory["SoldSum"][$parent][$category2])
|
||||
{
|
||||
$tmp=$sumCategory["SoldSum"][$parent][$category1];
|
||||
$sumCategory["SoldSum"][$parent][$category1]=$sumCategory["SoldSum"][$parent][$category2];
|
||||
$sumCategory["SoldSum"][$parent][$category2]=$tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////// SORT $sumContracor /////////////////////////////////
|
||||
foreach( $categoryArray1 as $parent1=>&$elementParent1 )
|
||||
{
|
||||
foreach( $categoryArray1 as $parent2=>&$elementParent2 )
|
||||
{
|
||||
if($sumContracor["SoldSum"][$parent1]>$sumContracor["SoldSum"][$parent2])
|
||||
{
|
||||
$tmp=$sumContracor["SoldSum"][$parent1];
|
||||
$sumContracor["SoldSum"][$parent1]=$sumContracor["SoldSum"][$parent2];
|
||||
$sumContracor["SoldSum"][$parent2]=$tmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
////////////////// SORT array at sumContracor/////////////////////////////////
|
||||
$newArray2;
|
||||
foreach( $categoryArray1 as $parent1=>&$elementParent1 )
|
||||
{
|
||||
foreach( $categoryArray1 as $parent2=>&$elementParent2 )
|
||||
{
|
||||
if($sumContracor["SoldSum"][$parent1]==$categoryArray1[$parent2]["SoldSum"])
|
||||
{
|
||||
$newArray2[$parent2]=$categoryArray1[$parent2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////// SORT array at sumCategory/////////////////////////////////
|
||||
$newArray1;
|
||||
foreach( $newArray2 as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category1=>&$elementCategory1 )
|
||||
{
|
||||
foreach( $elementParent as $category2=>&$elementCategory2 )
|
||||
{
|
||||
if($sumCategory["SoldSum"][$parent][$category1]==$newArray2[$parent][$category2]["SoldSum"])
|
||||
{
|
||||
$newArray1[$parent][$category2]=$newArray2[$parent][$category2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////// SORT array at sumSubCategory/////////////////////////////////
|
||||
$newArray;
|
||||
foreach( $newArray1 as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category=>&$elementCategory )
|
||||
{
|
||||
foreach( $elementCategory as $subcategory1=>&$elementSubCategory )
|
||||
{
|
||||
foreach( $elementCategory as $subcategory2=>&$elementSubCategory )
|
||||
{
|
||||
if($sumSubCategory["SoldSum"][$parent][$category][$subcategory1]==$newArray1[$parent][$category][$subcategory2]["SoldSum2"])
|
||||
{
|
||||
$newArray[$parent][$category][$subcategory2]=$newArray1[$parent][$category][$subcategory2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$newArray[$parent]["IloscSum"]=$newArray1[$parent]["IloscSum"];
|
||||
$newArray[$parent]["SoldSum"]=$newArray1[$parent]["SoldSum"];
|
||||
$newArray[$parent]["SredniaSum"]=$newArray1[$parent]["SredniaSum"];
|
||||
$newArray[$parent]["KosztSum"]=$newArray1[$parent]["KosztSum"];
|
||||
$newArray[$parent]["MarzaSum"]=$newArray1[$parent]["MarzaSum"];
|
||||
}
|
||||
|
||||
//wyliczanie dokładne marży i średniej dla produktów
|
||||
foreach( $newArray as $parent=>&$elementParent )
|
||||
{
|
||||
foreach( $elementParent as $category=>&$elementCategory )
|
||||
{
|
||||
foreach( $elementCategory as $subcategory=>&$elementSubCategory )
|
||||
{
|
||||
foreach( $elementSubCategory as $key=>&$element )
|
||||
{
|
||||
$newArray[$parent][$category][$subcategory][$key]["marza"] = ($newArray[$parent][$category][$subcategory][$key]["nettoNormal"]-$newArray[$parent][$category][$subcategory][$key]["koszt"])/$newArray[$parent][$category][$subcategory][$key]["nettoNormal"]*100;
|
||||
$newArray[$parent][$category][$subcategory][$key]["srednia"] = $newArray[$parent][$category][$subcategory][$key]["nettoNormal"]/$newArray[$parent][$category][$subcategory][$key]["IloscNormal"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user