add *.inc files to project
This commit is contained in:
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