diff --git a/modules/EcmReports/ReportStocks.php b/modules/EcmReports/ReportStocks.php
index 91753477..22b3def8 100644
--- a/modules/EcmReports/ReportStocks.php
+++ b/modules/EcmReports/ReportStocks.php
@@ -1,6 +1,6 @@
query ( $queryStocks );
+$rowsStocks = $db->query($queryStocks);
-while ( $rowStocks = $db->fetchByAssoc ( $rowsStocks ) ) {
- $stocks ["name"] = $rowStocks ["name"];
- $stocks ["id"] = $rowStocks ["id"];
- $datastocks [] = $stocks;
+while ($rowStocks = $db->fetchByAssoc($rowsStocks)) {
+ $stocks["name"] = $rowStocks["name"];
+ $stocks["id"] = $rowStocks["id"];
+ $datastocks[] = $stocks;
}
$query = "SELECT
@@ -80,20 +80,20 @@ ON ss.product_id = p.id
WHERE
p.deleted = '0' AND ss.quantity IS NOT NULL";
-if ($_GET ['selectStock'] != "")
- $query .= " AND ss.stock_id = '" . $_GET ["selectStock"] . "' ";
+if ($_GET['selectStock'] != "")
+ $query .= " AND ss.stock_id = '" . $_GET["selectStock"] . "' ";
-if ($_GET ['selectProductActive'] != "")
- $query .= " AND p.product_active = '" . $_GET ["selectProductActive"] . "' ";
+if ($_GET['selectProductActive'] != "")
+ $query .= " AND p.product_active = '" . $_GET["selectProductActive"] . "' ";
-if ($_GET ['selectProductEol'] != "") {
- if ($_GET ['selectProductEol'] == "1")
- $query .= " AND p.status='end_of_line' ";
- if ($_GET ['selectProductEol'] == "0")
+if ($_GET['selectProductEol'] != "") {
+ if ($_GET['selectProductEol'] == "1")
+ $query .= " AND p.status='end_of_line' ";
+ if ($_GET['selectProductEol'] == "0")
$query .= " AND p.status!='end_of_line' ";
}
-if($_GET['productKS']!=''){
- $query .= " AND p.group_ks = '" . $_GET ["productKS"] . "' ";
+if ($_GET['productKS'] != '') {
+ $query .= " AND p.group_ks = '" . $_GET["productKS"] . "' ";
}
$query .= " GROUP BY p.id";
@@ -106,86 +106,96 @@ $query .= " GROUP BY p.id";
/**
* **************************************************
*/
-$rows = $db->query ( $query );
+$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 ["quantity"] = $r ["quantity"];
- $row ["price"] = $r ["price"] ;
-
+while ($r = $db->fetchByAssoc($rows)) {
+ $row = array();
+ $row["id"] = $r["id"];
+ $row["name"] = $r["name"];
+ $row["code"] = $r["code"];
+ $row["quantity"] = $r["quantity"];
+ $row["price"] = $r["price"];
+
+ // stock addresses
+ $a = $db->query("SELECT stock_address FROM ecmproducts_stock_addresses WHERE ecmproduct_id='" . $r['id'] . "' ORDER BY stock_address");
+ $addresses = array();
+ while ($addr = $db->fetchByAssoc($a)) {
+ $addresses[] = $addr['stock_address'];
+ }
+ $row['stock_address'] = implode(", ", $addresses);
+
$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"] . "'
+ WHERE bean.bean_id='" . $row["id"] . "'
and bean.position = '1'
and bean.deleted = '0'
and category.deleted = '0';";
- $rowsSubCategory = $db->query ( $querySubCategory );
- $row["podkategoria"] ="";
- while ( $rowSubCategory = $db->fetchByAssoc ( $rowsSubCategory ) ) {
- $row ["podkategoria"] = $rowSubCategory ["podkategoria"];
+ $rowsSubCategory = $db->query($querySubCategory);
+ $row["podkategoria"] = "";
+ 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"] . "'
+ WHERE bean.bean_id='" . $row["id"] . "'
and bean.position = '0'
and bean.deleted = '0'
and category.deleted = '0';";
- $rowscategory = $db->query ( $queryCategory );
+ $rowscategory = $db->query($queryCategory);
$row["kategoria"] = "";
- while ( $rowcategory = $db->fetchByAssoc ( $rowscategory ) ) {
- $row ["kategoria"] = $rowcategory ["kategoria"];
+ while ($rowcategory = $db->fetchByAssoc($rowscategory)) {
+ $row["kategoria"] = $rowcategory["kategoria"];
}
- $data [] = $row;
+ $data[] = $row;
}
// //////////////// SUM /////////////////////////////////
-foreach ( $data as $key => &$element ) {
- $categoryArray1 [$element ["kategoria"] == "" ? "Inne" : $element ["kategoria"]] [$element ["podkategoria"] == "" ? "Reszta" : $element ["podkategoria"]] [$key] = $element;
+foreach ($data as $key => &$element) {
+ $categoryArray1[$element["kategoria"] == "" ? "Inne" : $element["kategoria"]][$element["podkategoria"] == "" ? "Reszta" : $element["podkategoria"]][$key] = $element;
}
-function cmp($a, $b) {
- if ($a ["name"] == $b ["name"]) {
+function cmp($a, $b)
+{
+ if ($a["name"] == $b["name"]) {
return 0;
}
- return ($a ["name"] < $b ["name"]) ? - 1 : 1;
+ return ($a["name"] < $b["name"]) ? -1 : 1;
}
// grupowanie po kategoriach
-foreach ( $categoryArray1 as $key1 => &$element1 ) {
- foreach ( $element1 as $key2 => &$element2 ) {
- usort ( $element2, "cmp" );
+foreach ($categoryArray1 as $key1 => &$element1) {
+ foreach ($element1 as $key2 => &$element2) {
+ usort($element2, "cmp");
$i = 0;
- $tmp2 [$key1] [$key2] [0] = array (
- 'name' => null
+ $tmp2[$key1][$key2][0] = array(
+ 'name' => null
);
$counter = 0;
-
- foreach ( $element2 as $count => &$element3 ) {
- if ($element3 ["id"] != $tmp2 [$key1] [$key2] [$i] ["id"]) {
-
- if ($tmp2 [$key1] [$key2] [$i] ["id"] != null) {
- $i ++;
+
+ foreach ($element2 as $count => &$element3) {
+ if ($element3["id"] != $tmp2[$key1][$key2][$i]["id"]) {
+
+ if ($tmp2[$key1][$key2][$i]["id"] != null) {
+ $i++;
}
-
- $tmp2 [$key1] [$key2] [$i] ["id"] = $element3 ["id"];
- $tmp2 [$key1] [$key2] [$i] ["name"] = $element3 ["name"];
- $tmp2 [$key1] [$key2] [$i] ["code"] = $element3 ["code"];
- $tmp2 [$key1] [$key2] [$i] ["quantity"] = $element3 ["quantity"];
- $tmp2 [$key1] [$key2] [$i] ["price"] = $element3 ["price"];
+
+ $tmp2[$key1][$key2][$i]["id"] = $element3["id"];
+ $tmp2[$key1][$key2][$i]["name"] = $element3["name"];
+ $tmp2[$key1][$key2][$i]["code"] = $element3["code"];
+ $tmp2[$key1][$key2][$i]["stock_address"] = $element3["stock_address"];
+ $tmp2[$key1][$key2][$i]["quantity"] = $element3["quantity"];
+ $tmp2[$key1][$key2][$i]["price"] = $element3["price"];
}
-
+
$counter += 1;
-
+
/*
if ($element2 [$count] ["name"] != $element2 [$count + 1] ["name"]) {
$tmp2 [$key1] [$key2] [$i] ["marza"] = $tmp2 [$key1] [$key2] [$i] ["marza"] / $counter;
@@ -197,67 +207,67 @@ foreach ( $categoryArray1 as $key1 => &$element1 ) {
$categoryArray = $tmp2;
}
}
-foreach ( $categoryArray as $key => &$element ) {
+foreach ($categoryArray as $key => &$element) {
$count = 0;
- foreach ( $element as $keyy => &$elementt ) {
- foreach ( $elementt as $keyyy => &$elementtt ) {
- $sumSub ["QuantitySum"] [$key] += $elementtt ["quantity"];
- $sumSub ["PriceSum"] [$key] += $elementtt ["price"];
-
- $sumSub2 ["QuantitySum"] [$key] [$keyy] += $elementtt ["quantity"];
- $sumSub2 ["PriceSum"] [$key] [$keyy] += $elementtt ["price"];
+ foreach ($element as $keyy => &$elementt) {
+ foreach ($elementt as $keyyy => &$elementtt) {
+ $sumSub["QuantitySum"][$key] += $elementtt["quantity"];
+ $sumSub["PriceSum"][$key] += $elementtt["price"];
+
+ $sumSub2["QuantitySum"][$key][$keyy] += $elementtt["quantity"];
+ $sumSub2["PriceSum"][$key][$keyy] += $elementtt["price"];
}
- $count += sizeof ( $elementt );
-
- $categoryArray [$key] [$keyy] ["QuantitySum2"] = $sumSub2 ["QuantitySum"] [$key] [$keyy];
- $categoryArray [$key] [$keyy] ["PriceSum2"] = $sumSub2 ["PriceSum"] [$key] [$keyy];
+ $count += sizeof($elementt);
+
+ $categoryArray[$key][$keyy]["QuantitySum2"] = $sumSub2["QuantitySum"][$key][$keyy];
+ $categoryArray[$key][$keyy]["PriceSum2"] = $sumSub2["PriceSum"][$key][$keyy];
}
- $categoryArray [$key] ["QuantitySum"] = $sumSub ["QuantitySum"] [$key];
- $categoryArray [$key] ["PriceSum"] = $sumSub ["PriceSum"] [$key];
+ $categoryArray[$key]["QuantitySum"] = $sumSub["QuantitySum"][$key];
+ $categoryArray[$key]["PriceSum"] = $sumSub["PriceSum"][$key];
}
-foreach ( $categoryArray as $key => &$element ) {
- $sum ["QuantitySumSum"] += $sumSub ["QuantitySum"] [$key];
- $sum ["PriceSumSum"] += $sumSub ["PriceSum"] [$key];
+foreach ($categoryArray as $key => &$element) {
+ $sum["QuantitySumSum"] += $sumSub["QuantitySum"][$key];
+ $sum["PriceSumSum"] += $sumSub["PriceSum"][$key];
}
-foreach ( $categoryArray as $key1 => &$element ) {
- foreach ( $element as $key2 => &$elements ) {
- foreach ( $element as $key3 => &$element2 ) {
- if ($sumSub2 ["PriceSum"] [$key1] [$key2] > $sumSub2 ["PriceSum"] [$key1] [$key3]) {
- $tmp = $sumSub2 ["PriceSum"] [$key1] [$key2];
- $sumSub2 ["PriceSum"] [$key1] [$key2] = $sumSub2 ["PriceSum"] [$key1] [$key3];
- $sumSub2 ["PriceSum"] [$key1] [$key3] = $tmp;
+foreach ($categoryArray as $key1 => &$element) {
+ foreach ($element as $key2 => &$elements) {
+ foreach ($element as $key3 => &$element2) {
+ if ($sumSub2["PriceSum"][$key1][$key2] > $sumSub2["PriceSum"][$key1][$key3]) {
+ $tmp = $sumSub2["PriceSum"][$key1][$key2];
+ $sumSub2["PriceSum"][$key1][$key2] = $sumSub2["PriceSum"][$key1][$key3];
+ $sumSub2["PriceSum"][$key1][$key3] = $tmp;
}
}
}
}
-foreach ( $sumSub ["PriceSum"] as $key1 => &$element ) {
- foreach ( $sumSub ["PriceSum"] as $key2 => &$element2 ) {
- if ($sumSub ["PriceSum"] [$key1] > $sumSub ["PriceSum"] [$key2]) {
- $tmp = $sumSub ["PriceSum"] [$key1];
- $sumSub ["PriceSum"] [$key1] = $sumSub ["PriceSum"] [$key2];
- $sumSub ["PriceSum"] [$key2] = $tmp;
+foreach ($sumSub["PriceSum"] as $key1 => &$element) {
+ foreach ($sumSub["PriceSum"] as $key2 => &$element2) {
+ if ($sumSub["PriceSum"][$key1] > $sumSub["PriceSum"][$key2]) {
+ $tmp = $sumSub["PriceSum"][$key1];
+ $sumSub["PriceSum"][$key1] = $sumSub["PriceSum"][$key2];
+ $sumSub["PriceSum"][$key2] = $tmp;
}
}
}
// //////////////// SORT array /////////////////////////////////
$newArray2;
-foreach ( $sumSub ["PriceSum"] as $key1 => &$element1 ) {
- foreach ( $categoryArray as $key2 => &$element2 ) {
- if ($sumSub ["PriceSum"] [$key1] == $categoryArray [$key2] ["PriceSum"]) {
- $newArray2 [$key2] = $categoryArray [$key2];
+foreach ($sumSub["PriceSum"] as $key1 => &$element1) {
+ foreach ($categoryArray as $key2 => &$element2) {
+ if ($sumSub["PriceSum"][$key1] == $categoryArray[$key2]["PriceSum"]) {
+ $newArray2[$key2] = $categoryArray[$key2];
}
}
}
$newArray1;
-foreach ( $newArray2 as $key1 => &$element1 ) {
- foreach ( $element1 as $key2 => &$element2 ) {
- foreach ( $element1 as $key3 => &$element3 ) {
- if ($sumSub2 ["PriceSum"] [$key1] [$key2] == $newArray2 [$key1] [$key3] ["PriceSum2"]) {
- $newArray1 [$key1] [$key3] = $newArray2 [$key1] [$key3];
+foreach ($newArray2 as $key1 => &$element1) {
+ foreach ($element1 as $key2 => &$element2) {
+ foreach ($element1 as $key3 => &$element3) {
+ if ($sumSub2["PriceSum"][$key1][$key2] == $newArray2[$key1][$key3]["PriceSum2"]) {
+ $newArray1[$key1][$key3] = $newArray2[$key1][$key3];
}
}
}
@@ -274,17 +284,15 @@ foreach ( $newArray2 as $key1 => &$element1 ) {
* **************************************************
*/
// create & execute smarty
-$smarty = new Sugar_Smarty ();
+$smarty = new Sugar_Smarty();
global $mod_strings;
-$smarty->assign ( "MOD", $mod_strings );
-$smarty->assign ( "DATA", $newArray1 );
-$smarty->assign ( "SUM", $sum );
-$smarty->assign ('KSGROUPS',$KSGROUPS);
-$smarty->assign ( "STOCKS", $datastocks );
-$smarty->assign ( "selectStock", $selectStock );
-$smarty->assign ('selectKS',$_GET['productKS']);
-$smarty->assign ( "selectProductActive", $selectProductActive );
-$smarty->assign ( "selectProductEol", $selectProductEol );
-echo $smarty->display ( 'modules/EcmReports/tpls/ReportStocks.tpl' );
-
-?>
+$smarty->assign("MOD", $mod_strings);
+$smarty->assign("DATA", $newArray1);
+$smarty->assign("SUM", $sum);
+$smarty->assign('KSGROUPS', $KSGROUPS);
+$smarty->assign("STOCKS", $datastocks);
+$smarty->assign("selectStock", $selectStock);
+$smarty->assign('selectKS', $_GET['productKS']);
+$smarty->assign("selectProductActive", $selectProductActive);
+$smarty->assign("selectProductEol", $selectProductEol);
+echo $smarty->display('modules/EcmReports/tpls/ReportStocks.tpl');
diff --git a/modules/EcmReports/tpls/ReportStocks.tpl b/modules/EcmReports/tpls/ReportStocks.tpl
index 5603a1e9..14bd470f 100644
--- a/modules/EcmReports/tpls/ReportStocks.tpl
+++ b/modules/EcmReports/tpls/ReportStocks.tpl
@@ -1,7 +1,7 @@
-
-
-
-
+
+
+
+
@@ -14,7 +14,7 @@