production scheduler fix
This commit is contained in:
@@ -143,7 +143,7 @@
|
|||||||
$new->parent_nip = "8792676609";
|
$new->parent_nip = "8792676609";
|
||||||
$new->parent_iln = "5909000837119";
|
$new->parent_iln = "5909000837119";
|
||||||
$new->pricebook_id = "13b29aa1-48f0-de58-7630-59c22756c5e4";
|
$new->pricebook_id = "13b29aa1-48f0-de58-7630-59c22756c5e4";
|
||||||
$new->status = "s10";
|
$new->status = "s30";
|
||||||
$new->type = "sales_order";
|
$new->type = "sales_order";
|
||||||
$new->name = $sale->name;
|
$new->name = $sale->name;
|
||||||
$new->ecmpaymentcondition_name = "90 dni";
|
$new->ecmpaymentcondition_name = "90 dni";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// created: 2025-02-10 11:34:48
|
// created: 2025-03-31 14:19:04
|
||||||
$customDoms = array (
|
$customDoms = array (
|
||||||
'ecmproducts_attribute_dom' =>
|
'ecmproducts_attribute_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -73,6 +73,8 @@ $customDoms = array (
|
|||||||
'cb66a685-53e1-5f87-0a25-66967c7cb63b' => 'Doypack 210x285mm',
|
'cb66a685-53e1-5f87-0a25-66967c7cb63b' => 'Doypack 210x285mm',
|
||||||
'75f4bd2a-51a8-0767-635e-66dde15af79e' => 'Foam 200ml',
|
'75f4bd2a-51a8-0767-635e-66dde15af79e' => 'Foam 200ml',
|
||||||
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
|
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
|
||||||
|
'e6900d92-6fde-90e6-b872-67d1938745e6' => 'Słoik 400 ml',
|
||||||
|
'e3e0c9da-6d08-e1e0-b9ba-67eaa437cb84' => 'Bottle B1_30ml',
|
||||||
),
|
),
|
||||||
'ecmproducts_brand_dom' =>
|
'ecmproducts_brand_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -156,6 +158,11 @@ $customDoms = array (
|
|||||||
'7ceeacc7-e79b-4eb0-2aa3-676529593a3c' => 'PureNest',
|
'7ceeacc7-e79b-4eb0-2aa3-676529593a3c' => 'PureNest',
|
||||||
'ca4ee928-3385-d7f8-090e-678e697c3b8e' => 'gc clean!',
|
'ca4ee928-3385-d7f8-090e-678e697c3b8e' => 'gc clean!',
|
||||||
'9d630708-a3f3-de9b-bbe0-67a9dfd114a2' => 'MPM',
|
'9d630708-a3f3-de9b-bbe0-67a9dfd114a2' => 'MPM',
|
||||||
|
'842115cd-b258-862b-1f7e-67b437f1358e' => 'Praxs',
|
||||||
|
'c1e01314-cf64-a48f-9b24-67b58e00952b' => '3mk',
|
||||||
|
'661388b9-ac42-d5a8-2503-67b856a06f52' => 'Coffeeano',
|
||||||
|
'1f9d4c5d-670e-4c77-d4de-67cddc908559' => 'DeCal',
|
||||||
|
'5c883b90-f1fb-83d1-6347-67dbd49469f0' => 'EntertainME',
|
||||||
),
|
),
|
||||||
'ecmproducts_category_dom' =>
|
'ecmproducts_category_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -197,6 +204,7 @@ $customDoms = array (
|
|||||||
'f2156355-d06b-2904-d759-67923795c77b' => 'Oven Cleaners',
|
'f2156355-d06b-2904-d759-67923795c77b' => 'Oven Cleaners',
|
||||||
'27697ebf-0d8e-5156-528e-679237ffd78f' => 'Toilet Cleaners',
|
'27697ebf-0d8e-5156-528e-679237ffd78f' => 'Toilet Cleaners',
|
||||||
'f03ef1ce-e218-97eb-623e-679d00f02f98' => 'Car Cleaning',
|
'f03ef1ce-e218-97eb-623e-679d00f02f98' => 'Car Cleaning',
|
||||||
|
'30f0082f-6f41-a3ee-cb9a-67caecd873ab' => 'Impregantors',
|
||||||
),
|
),
|
||||||
'ecmquotes_status_dom' =>
|
'ecmquotes_status_dom' =>
|
||||||
array (
|
array (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// created: 2025-02-10 11:34:48
|
// created: 2025-03-31 14:19:04
|
||||||
$customDoms = array (
|
$customDoms = array (
|
||||||
'ecmproducts_attribute_dom' =>
|
'ecmproducts_attribute_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -73,6 +73,8 @@ $customDoms = array (
|
|||||||
'cb66a685-53e1-5f87-0a25-66967c7cb63b' => 'Doypack 210x285mm',
|
'cb66a685-53e1-5f87-0a25-66967c7cb63b' => 'Doypack 210x285mm',
|
||||||
'75f4bd2a-51a8-0767-635e-66dde15af79e' => 'Pianka 200ml',
|
'75f4bd2a-51a8-0767-635e-66dde15af79e' => 'Pianka 200ml',
|
||||||
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
|
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
|
||||||
|
'e6900d92-6fde-90e6-b872-67d1938745e6' => 'Słoik 400 ml',
|
||||||
|
'e3e0c9da-6d08-e1e0-b9ba-67eaa437cb84' => 'Butelka B1_30ml',
|
||||||
),
|
),
|
||||||
'ecmproducts_brand_dom' =>
|
'ecmproducts_brand_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -156,6 +158,11 @@ $customDoms = array (
|
|||||||
'7ceeacc7-e79b-4eb0-2aa3-676529593a3c' => 'PureNest',
|
'7ceeacc7-e79b-4eb0-2aa3-676529593a3c' => 'PureNest',
|
||||||
'ca4ee928-3385-d7f8-090e-678e697c3b8e' => 'gc clean!',
|
'ca4ee928-3385-d7f8-090e-678e697c3b8e' => 'gc clean!',
|
||||||
'9d630708-a3f3-de9b-bbe0-67a9dfd114a2' => 'MPM',
|
'9d630708-a3f3-de9b-bbe0-67a9dfd114a2' => 'MPM',
|
||||||
|
'842115cd-b258-862b-1f7e-67b437f1358e' => 'Praxs',
|
||||||
|
'c1e01314-cf64-a48f-9b24-67b58e00952b' => '3mk',
|
||||||
|
'661388b9-ac42-d5a8-2503-67b856a06f52' => 'Coffeeano',
|
||||||
|
'1f9d4c5d-670e-4c77-d4de-67cddc908559' => 'DeCal',
|
||||||
|
'5c883b90-f1fb-83d1-6347-67dbd49469f0' => 'EntertainME',
|
||||||
),
|
),
|
||||||
'ecmproducts_category_dom' =>
|
'ecmproducts_category_dom' =>
|
||||||
array (
|
array (
|
||||||
@@ -197,6 +204,7 @@ $customDoms = array (
|
|||||||
'f2156355-d06b-2904-d759-67923795c77b' => 'Środki do czyszczenia piekarnika',
|
'f2156355-d06b-2904-d759-67923795c77b' => 'Środki do czyszczenia piekarnika',
|
||||||
'27697ebf-0d8e-5156-528e-679237ffd78f' => 'Środki do czyszczenia toalet',
|
'27697ebf-0d8e-5156-528e-679237ffd78f' => 'Środki do czyszczenia toalet',
|
||||||
'f03ef1ce-e218-97eb-623e-679d00f02f98' => 'Środki do czyszczenia samochodów',
|
'f03ef1ce-e218-97eb-623e-679d00f02f98' => 'Środki do czyszczenia samochodów',
|
||||||
|
'30f0082f-6f41-a3ee-cb9a-67caecd873ab' => 'Środki do impregnacji powierzchni',
|
||||||
),
|
),
|
||||||
'ecmquotes_status_dom' =>
|
'ecmquotes_status_dom' =>
|
||||||
array (
|
array (
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ function showBlock(id)
|
|||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
<div id="details_block" style="display:block;">
|
<div id="details_block" style="display:block;">
|
||||||
|
|
||||||
<table width="100%" border="0" cellspacing="{GRIDLINE}" cellpadding="0">
|
<table width="100%" border="0" cellspacing="{GRIDLINE}" cellpadding="0">
|
||||||
{PAGINATION1}
|
{PAGINATION1}
|
||||||
<th class="dataLabel" align="left" colspan="8">
|
<th class="dataLabel" align="left" colspan="8">
|
||||||
|
|||||||
@@ -316,8 +316,8 @@ class EcmProduct extends SugarBean {
|
|||||||
$this->url9 = '<a href="'.$this->url9.'" target="_blank"/>'.$this->url9.'</a>';
|
$this->url9 = '<a href="'.$this->url9.'" target="_blank"/>'.$this->url9.'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$this->id."'"));
|
//$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$this->id."'"));
|
||||||
$this->ems_qty_in_stock = $r['qty'];
|
//$this->ems_qty_in_stock = $r['qty'];
|
||||||
}
|
}
|
||||||
function getSale($date){
|
function getSale($date){
|
||||||
foreach($date as $d){
|
foreach($date as $d){
|
||||||
|
|||||||
@@ -478,6 +478,7 @@ function addToProductionScheduler(orderItemId) {
|
|||||||
success: function ()
|
success: function ()
|
||||||
{
|
{
|
||||||
hideLoader();
|
hideLoader();
|
||||||
|
$("#productScheduled-"+orderItemId).css('visibility', 'visible');
|
||||||
window.alert("Dodano do harmonogramu produkcji.");
|
window.alert("Dodano do harmonogramu produkcji.");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -353,9 +353,9 @@ function getProductRawMaterials($productId, $quantity)
|
|||||||
function addToProductionScheduler($orderItemId) {
|
function addToProductionScheduler($orderItemId) {
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
global $current_user;
|
global $current_user;
|
||||||
$res = $db->fetchByAssoc($db->query("SELECT quantity, ecmproduct_id, production_date, description, ecmsale_id FROM ecmsaleitems WHERE id ='$orderItemId'"));
|
$res = $db->fetchByAssoc($db->query("SELECT quantity, ecmproduct_id, description, ecmsale_id FROM ecmsaleitems WHERE id ='$orderItemId'"));
|
||||||
$query = sprintf("INSERT INTO productionScheduler VALUES ('%s', '%s', '%s', '%d', NOW(), NOW(), '%s', '%s', 0, '%s', 0, '%s', '%s');",
|
$query = sprintf("INSERT INTO productionScheduler VALUES ('%s', '%s', '%s', '%d', NOW(), NOW(), '%s', '%s', 0, '%s', 0, '','%s');",
|
||||||
generateUuidV4(), $orderItemId, $res['ecmsale_id'], $res['quantity'], $current_user->id, $current_user->id, $res['ecmproduct_id'], $res['production_date'], $res['description']);
|
generateUuidV4(), $orderItemId, $res['ecmsale_id'], $res['quantity'], $current_user->id, $current_user->id, $res['ecmproduct_id'], $res['description']);
|
||||||
$db->query($query);
|
$db->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,9 +178,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<input type="checkbox" value="{$ROW.orderItemId}" class="allCheck"/>
|
<input type="checkbox" value="{$ROW.orderItemId}" class="allCheck"/>
|
||||||
<br><img src="modules/EcmQuotes/images/add_position.gif" style="margin-top: 3px; margin-right: 3px; cursor: pointer" width="12" alt="" onclick="addToProductionScheduler('{$ROW.orderItemId}')">
|
<br><img src="modules/EcmQuotes/images/add_position.gif" style="margin-top: 3px; margin-right: 3px; cursor: pointer" width="12" alt="" onclick="addToProductionScheduler('{$ROW.orderItemId}')">
|
||||||
{if $ROW.scheduled > 0}
|
<div id="productScheduled-{$ROW.orderItemId}" style="background-color: green; width: 8px; height: 8px; border-radius: 50%; margin-top: 2px; margin-left: 2px; visibility: {if $ROW.scheduled > 0}visible{else}hidden{/if};"></div>
|
||||||
<div style="background-color: green; width: 8px; height: 8px; border-radius: 50%; margin-top: 2px; margin-left: 2px;"></div>
|
|
||||||
{/if}
|
|
||||||
<input type="hidden" id="productId-{$ROW.orderItemId}" value="{$ROW.productId}"/>
|
<input type="hidden" id="productId-{$ROW.orderItemId}" value="{$ROW.productId}"/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -1,88 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
if (! defined('sugarEntry') || ! sugarEntry)
|
||||||
die ( 'Not A Valid Entry Point' );
|
die('Not A Valid Entry Point');
|
||||||
|
|
||||||
/*****************************************************/
|
|
||||||
/*********************** PREPARE *********************/
|
|
||||||
/*****************************************************/
|
|
||||||
$db = $GLOBALS ['db'];
|
|
||||||
|
|
||||||
global $app_list_strings;
|
|
||||||
$all_groups_ks = $app_list_strings["ecmproducts_group_ks_dom"];
|
|
||||||
|
|
||||||
if($_GET['selectUser']!="")
|
/*****************************************************/
|
||||||
{
|
/*********************** PREPARE *********************/
|
||||||
$selectUser=$_GET['selectUser'];
|
/*****************************************************/
|
||||||
}else{
|
$db = $GLOBALS['db'];
|
||||||
$selectUser="";
|
|
||||||
}
|
|
||||||
|
|
||||||
if($_GET['selectPdfType']!="")
|
|
||||||
{
|
|
||||||
$selectPdfType=$_GET['selectPdfType'];
|
|
||||||
}else{
|
|
||||||
$selectPdfType="";
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
$categoryArray = array();
|
|
||||||
|
|
||||||
$sum = array();
|
|
||||||
$sumSub = array();
|
|
||||||
$sumSub2 = array();
|
|
||||||
$searchBy = $_GET['groupByProducentsOrProducts'];
|
|
||||||
if(!$_GET['date_from'])
|
|
||||||
$date_from = date("Y-m-01");
|
|
||||||
else
|
|
||||||
$date_from = $_GET["date_from"];
|
|
||||||
|
|
||||||
if(!$_GET['date_to'])
|
global $app_list_strings;
|
||||||
$date_to = date("Y-m-d");
|
$all_groups_ks = $app_list_strings["ecmproducts_group_ks_dom"];
|
||||||
else
|
|
||||||
$date_to = $_GET["date_to"];
|
|
||||||
|
|
||||||
$contractorName = $_GET['account_name'];
|
|
||||||
$contractorId = $_GET['account_id'];
|
|
||||||
$searchByType = $_GET['type'];
|
|
||||||
|
|
||||||
$group_ks = $_GET["group_ks"];
|
if ($_GET['selectUser'] != "") {
|
||||||
|
$selectUser = $_GET['selectUser'];
|
||||||
if( $group_ks == '' )
|
} else {
|
||||||
$group_ks = "%";
|
$selectUser = "";
|
||||||
|
}
|
||||||
|
|
||||||
$date_from_to_query = new DateTime($date_from);
|
if ($_GET['selectPdfType'] != "") {
|
||||||
$date_to_to_query = new DateTime($date_to);
|
$selectPdfType = $_GET['selectPdfType'];
|
||||||
|
} else {
|
||||||
$addTwinpol = (isset($_REQUEST['twinpol']) ? 1 : 0);
|
$selectPdfType = "";
|
||||||
|
}
|
||||||
$datausers = array();
|
|
||||||
$users = array();
|
$data = array();
|
||||||
$queryUsers="SELECT
|
$categoryArray = array();
|
||||||
|
|
||||||
|
$sum = array();
|
||||||
|
$sumSub = array();
|
||||||
|
$sumSub2 = array();
|
||||||
|
$searchBy = $_GET['groupByProducentsOrProducts'];
|
||||||
|
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'];
|
||||||
|
|
||||||
|
$group_ks = $_GET["group_ks"];
|
||||||
|
|
||||||
|
if ($group_ks == '')
|
||||||
|
$group_ks = "%";
|
||||||
|
|
||||||
|
$date_from_to_query = new DateTime($date_from);
|
||||||
|
$date_to_to_query = new DateTime($date_to);
|
||||||
|
|
||||||
|
$addTwinpol = (isset($_REQUEST['twinpol']) ? 1 : 0);
|
||||||
|
|
||||||
|
$datausers = array();
|
||||||
|
$users = array();
|
||||||
|
$queryUsers = "SELECT
|
||||||
first_name as 'first',
|
first_name as 'first',
|
||||||
last_name as 'last',
|
last_name as 'last',
|
||||||
id
|
id
|
||||||
FROM users
|
FROM users
|
||||||
where deleted= 0
|
where deleted= 0
|
||||||
and status = 'Active';";
|
and status = 'Active';";
|
||||||
$rowsUsers= $db->query ($queryUsers);
|
$rowsUsers = $db->query($queryUsers);
|
||||||
while($rowUser = $db->fetchByAssoc ( $rowsUsers ))
|
while ($rowUser = $db->fetchByAssoc($rowsUsers)) {
|
||||||
{
|
$users["first"] = $rowUser["first"];
|
||||||
$users["first"] = $rowUser["first"];
|
$users["last"] = $rowUser["last"];
|
||||||
$users["last"] = $rowUser["last"];
|
$users["id"] = $rowUser["id"];
|
||||||
$users["id"] = $rowUser["id"];
|
$datausers[] = $users;
|
||||||
$datausers [] = $users;
|
}
|
||||||
}
|
|
||||||
|
if ($searchBy == "contractor") {
|
||||||
if($searchBy=="contractor")
|
$groupBy = "name";
|
||||||
{
|
} else {
|
||||||
$groupBy="name";
|
$groupBy = "id";
|
||||||
}else{
|
}
|
||||||
$groupBy="id";
|
|
||||||
}
|
if ($searchBy == "product") {
|
||||||
|
$query = "SELECT
|
||||||
if($searchBy=="product")
|
|
||||||
{
|
|
||||||
$query = "SELECT
|
|
||||||
pozycja.name,
|
pozycja.name,
|
||||||
pozycja.ecmproduct_id as 'id',
|
pozycja.ecmproduct_id as 'id',
|
||||||
faktura.parent_id as 'parent_id',
|
faktura.parent_id as 'parent_id',
|
||||||
@@ -127,7 +122,14 @@
|
|||||||
pozycja.price_purchase*pozycja.quantity_corrected
|
pozycja.price_purchase*pozycja.quantity_corrected
|
||||||
END
|
END
|
||||||
) as koszt,
|
) as koszt,
|
||||||
(SELECT SUM(s.quantity) FROM ecmstockstates s WHERE s.product_id = pozycja.ecmproduct_id) as state
|
(SELECT SUM(s.quantity) FROM ecmstockstates s WHERE s.product_id = pozycja.ecmproduct_id) as state,
|
||||||
|
(SELECT SUM(si.quantity)
|
||||||
|
FROM ecmsaleitems si
|
||||||
|
JOIN ecmsales sa ON si.ecmsale_id = sa.id
|
||||||
|
WHERE si.ecmproduct_id = pozycja.ecmproduct_id
|
||||||
|
AND sa.status = 's30'
|
||||||
|
AND sa.type = 'sales_order'
|
||||||
|
AND sa.send_date >= NOW()) AS ordered_quantity
|
||||||
FROM
|
FROM
|
||||||
ecminvoiceoutitems pozycja
|
ecminvoiceoutitems pozycja
|
||||||
JOIN
|
JOIN
|
||||||
@@ -136,27 +138,26 @@
|
|||||||
ecmproducts produkt ON pozycja.ecmproduct_id = produkt.id
|
ecmproducts produkt ON pozycja.ecmproduct_id = produkt.id
|
||||||
WHERE
|
WHERE
|
||||||
faktura.register_date BETWEEN
|
faktura.register_date BETWEEN
|
||||||
'".$date_from_to_query->format('Y-m-d')."' AND
|
'" . $date_from_to_query->format('Y-m-d') . "' AND
|
||||||
'".$date_to_to_query->format('Y-m-d')."'
|
'" . $date_to_to_query->format('Y-m-d') . "'
|
||||||
and faktura.type like '".$searchByType."'
|
and faktura.type like '" . $searchByType . "'
|
||||||
and faktura.canceled = 0
|
and faktura.canceled = 0
|
||||||
and faktura.deleted= 0";
|
and faktura.deleted= 0";
|
||||||
if ($selectPdfType!="")
|
if ($selectPdfType != "")
|
||||||
$query.= " and faktura.pdf_type='$selectPdfType'";
|
$query .= " and faktura.pdf_type='$selectPdfType'";
|
||||||
$query .= " and pozycja.deleted= 0 ";
|
$query .= " and pozycja.deleted= 0 ";
|
||||||
|
|
||||||
if($addTwinpol ===0 ){
|
if ($addTwinpol === 0) {
|
||||||
$query .= " and faktura.parent_id <> '1b9643ca-5b1a-8f9b-b809-586b5619b068' ";
|
$query .= " and faktura.parent_id <> '1b9643ca-5b1a-8f9b-b809-586b5619b068' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($group_ks!='%'){
|
if ($group_ks != '%') {
|
||||||
$query .= "AND produkt.group_ks LIKE '$group_ks'";
|
$query .= "AND produkt.group_ks LIKE '$group_ks'";
|
||||||
}
|
}
|
||||||
$query .= "GROUP BY pozycja.id
|
$query .= "GROUP BY pozycja.id
|
||||||
COLLATE utf8_polish_ci;";
|
COLLATE utf8_polish_ci;";
|
||||||
|
} else if ($searchBy == "contractor") {
|
||||||
}else if ($searchBy=="contractor"){
|
$query = "SELECT
|
||||||
$query = "SELECT
|
|
||||||
faktura.parent_name as 'name',
|
faktura.parent_name as 'name',
|
||||||
faktura.parent_id as 'parent_id',
|
faktura.parent_id as 'parent_id',
|
||||||
pozycja.name as 'product_name',
|
pozycja.name as 'product_name',
|
||||||
@@ -209,350 +210,309 @@
|
|||||||
accounts acco ON acco.id = faktura.parent_id
|
accounts acco ON acco.id = faktura.parent_id
|
||||||
WHERE
|
WHERE
|
||||||
faktura.register_date BETWEEN
|
faktura.register_date BETWEEN
|
||||||
'".$date_from_to_query->format('Y-m-d')."' AND
|
'" . $date_from_to_query->format('Y-m-d') . "' AND
|
||||||
'".$date_to_to_query->format('Y-m-d')."'
|
'" . $date_to_to_query->format('Y-m-d') . "'
|
||||||
and faktura.type like '".$searchByType."'
|
and faktura.type like '" . $searchByType . "'
|
||||||
and faktura.canceled = 0
|
and faktura.canceled = 0
|
||||||
and faktura.deleted= 0";
|
and faktura.deleted= 0";
|
||||||
if ($selectPdfType!="")
|
if ($selectPdfType != "")
|
||||||
$query.= " and faktura.pdf_type='$selectPdfType'";
|
$query .= " and faktura.pdf_type='$selectPdfType'";
|
||||||
$query .= " and pozycja.deleted= 0
|
$query .= " and pozycja.deleted= 0
|
||||||
and produkt.group_ks LIKE '$group_ks'";
|
and produkt.group_ks LIKE '$group_ks'";
|
||||||
|
|
||||||
if($addTwinpol ===0 ){
|
|
||||||
$query .= " and faktura.parent_id <> '1b9643ca-5b1a-8f9b-b809-586b5619b068' ";
|
|
||||||
}
|
|
||||||
|
|
||||||
$query .= "GROUP BY pozycja.id
|
if ($addTwinpol === 0) {
|
||||||
|
$query .= " and faktura.parent_id <> '1b9643ca-5b1a-8f9b-b809-586b5619b068' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query .= "GROUP BY pozycja.id
|
||||||
COLLATE utf8_polish_ci;";
|
COLLATE utf8_polish_ci;";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************/
|
/*****************************************************/
|
||||||
/*************** GET DATA FROM DB*********************/
|
/*************** GET DATA FROM DB*********************/
|
||||||
/*****************************************************/
|
/*****************************************************/
|
||||||
$rows = $db->query ($query);
|
$rows = $db->query($query);
|
||||||
// prepare data for Smarty
|
// prepare data for Smarty
|
||||||
while($r = $db->fetchByAssoc ( $rows ))
|
while ($r = $db->fetchByAssoc($rows)) {
|
||||||
{
|
$row = array();
|
||||||
$row = array();
|
$row["id"] = $r["id"];
|
||||||
$row["id"] = $r["id"];
|
if ($r["parent2"] == 1249)
|
||||||
if( $r["parent2"] == 1249)
|
$row["name"] = "Media Saturn Holding";
|
||||||
$row["name"] = "Media Saturn Holding";
|
else
|
||||||
else
|
$row["name"] = $r["name"];
|
||||||
$row["name"] = $r["name"];
|
|
||||||
|
$row["code"] = $r["code"];
|
||||||
$row["code"]=$r["code"];
|
$row["state"] = $r["state"];
|
||||||
$row["state"]=$r["state"];
|
$row["ordered_quantity"] = $r["ordered_quantity"];
|
||||||
$row["parent_id"]=$r["parent_id"];
|
$row["parent_id"] = $r["parent_id"];
|
||||||
$row["type"]=$r["type"];
|
$row["type"] = $r["type"];
|
||||||
|
|
||||||
$userBool=1;
|
$userBool = 1;
|
||||||
if($selectUser!="")
|
if ($selectUser != "") {
|
||||||
{
|
$userBool = 0;
|
||||||
$userBool=0;
|
$querySelectUsers = "SELECT user.id,
|
||||||
$querySelectUsers="SELECT user.id,
|
|
||||||
first_name as 'first',
|
first_name as 'first',
|
||||||
last_name as 'last'
|
last_name as 'last'
|
||||||
FROM
|
FROM
|
||||||
accounts acc
|
accounts acc
|
||||||
JOIN
|
JOIN
|
||||||
users user ON acc.assigned_user_id=user.id
|
users user ON acc.assigned_user_id=user.id
|
||||||
WHERE acc.id='".$r["parent_id"]."';";
|
WHERE acc.id='" . $r["parent_id"] . "';";
|
||||||
$rowsSelectUsers = $db->query ($querySelectUsers);
|
$rowsSelectUsers = $db->query($querySelectUsers);
|
||||||
while($rowSelectUser = $db->fetchByAssoc ( $rowsSelectUsers ))
|
while ($rowSelectUser = $db->fetchByAssoc($rowsSelectUsers)) {
|
||||||
{
|
if ($rowSelectUser["id"] == $selectUser) {
|
||||||
if($rowSelectUser["id"]==$selectUser)
|
$userBool = 1;
|
||||||
{
|
} else {
|
||||||
$userBool=1;
|
$userBool = 0;
|
||||||
}else{
|
}
|
||||||
$userBool=0;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($userBool==1)
|
|
||||||
{
|
|
||||||
if($searchBy=="contractor")
|
|
||||||
{
|
|
||||||
$row["product_name"]=$r["product_name"];
|
|
||||||
}else{
|
|
||||||
$row["product_name"]=$r["name"];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($userBool == 1) {
|
||||||
$querySubCategory="SELECT category.name as 'podkategoria'
|
if ($searchBy == "contractor") {
|
||||||
|
$row["product_name"] = $r["product_name"];
|
||||||
|
} else {
|
||||||
|
$row["product_name"] = $r["name"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$querySubCategory = "SELECT category.name as 'podkategoria'
|
||||||
FROM
|
FROM
|
||||||
ecmproductcategories_bean bean
|
ecmproductcategories_bean bean
|
||||||
JOIN
|
JOIN
|
||||||
ecmproductcategories category ON bean.ecmproductcategory_id = category.id
|
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.position = '1'
|
||||||
and bean.deleted = '0'
|
and bean.deleted = '0'
|
||||||
and category.deleted = '0';";
|
and category.deleted = '0';";
|
||||||
$rowsSubCategory = $db->query ($querySubCategory);
|
$rowsSubCategory = $db->query($querySubCategory);
|
||||||
while($rowSubCategory = $db->fetchByAssoc ( $rowsSubCategory ))
|
while ($rowSubCategory = $db->fetchByAssoc($rowsSubCategory)) {
|
||||||
{
|
$row["podkategoria"] = $rowSubCategory["podkategoria"];
|
||||||
$row["podkategoria"] = $rowSubCategory["podkategoria"];
|
}
|
||||||
}
|
|
||||||
|
$queryCategory = "SELECT category.name as 'kategoria'
|
||||||
$queryCategory="SELECT category.name as 'kategoria'
|
|
||||||
FROM
|
FROM
|
||||||
ecmproductcategories_bean bean
|
ecmproductcategories_bean bean
|
||||||
JOIN
|
JOIN
|
||||||
ecmproductcategories category ON bean.ecmproductcategory_id = category.id
|
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.position = '0'
|
||||||
and bean.deleted = '0'
|
and bean.deleted = '0'
|
||||||
and category.deleted = '0';";
|
and category.deleted = '0';";
|
||||||
$rowscategory = $db->query ($queryCategory);
|
$rowscategory = $db->query($queryCategory);
|
||||||
while($rowcategory = $db->fetchByAssoc ( $rowscategory ))
|
while ($rowcategory = $db->fetchByAssoc($rowscategory)) {
|
||||||
{
|
|
||||||
|
$row["kategoria"] = $rowcategory["kategoria"];
|
||||||
$row["kategoria"] = $rowcategory["kategoria"];
|
}
|
||||||
}
|
$row["ilosc"] = $r["ilosc"];
|
||||||
$row["ilosc"] = $r["ilosc"];
|
$row["netto"] = $r["netto"];
|
||||||
$row["netto"] = $r["netto"];
|
$row["srednia"] = $row["netto"] / $row["ilosc"];
|
||||||
$row["srednia"] = $row["netto"]/$row["ilosc"];
|
$row["koszt"] = $r["koszt"];
|
||||||
$row["koszt"] = $r["koszt"];
|
//if($row["netto"]>$row["koszt"])
|
||||||
//if($row["netto"]>$row["koszt"])
|
//{
|
||||||
//{
|
$row["marza"] = ($row["netto"] - $row["koszt"]) / ($row["netto"]) * 100;
|
||||||
$row["marza"] = ($row["netto"]-$row["koszt"])/($row["netto"])*100;
|
//}else{
|
||||||
//}else{
|
//$row["marza"] = 0;
|
||||||
//$row["marza"] = 0;
|
//}
|
||||||
//}
|
|
||||||
|
$data[] = $row;
|
||||||
$data [] = $row;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if($searchBy!="")
|
|
||||||
|
if ($searchBy != "") {
|
||||||
|
////////////////// SUM /////////////////////////////////
|
||||||
|
foreach ($data as $key => &$element) {
|
||||||
|
if ($element["netto"] != 0) {
|
||||||
|
$categoryArray[$element["kategoria"] == "" ? "Inne" : $element["kategoria"]][$element["podkategoria"] == "" ? "Reszta" : $element["podkategoria"]][$key] = $element;
|
||||||
|
} else {
|
||||||
|
//echo "Nie przechodzi: <br>";
|
||||||
|
//print_r( $element );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($categoryArray as $key => &$element) {
|
||||||
|
foreach ($element as $keyy => &$elementt) {
|
||||||
|
foreach ($elementt as $keyyy => &$elementtt) {
|
||||||
|
$sumSub["IloscSum"][$key] += $elementtt["ilosc"];
|
||||||
|
$sumSub["SoldSum"][$key] += $elementtt["netto"];
|
||||||
|
//if($elementtt["type"]=="normal")
|
||||||
|
//{
|
||||||
|
$sumSub["SoldSumNormal"][$key] += $elementtt["netto"];
|
||||||
|
$sumSub["IloscNormal"][$key] += $elementtt["ilosc"];
|
||||||
|
//}else{
|
||||||
|
// $sumSub["SoldSumNormal"][$key] += 0;
|
||||||
|
//$sumSub["IloscNormal"][$key] += 0;
|
||||||
|
// }
|
||||||
|
$sumSub["KosztSum"][$key] += $elementtt["koszt"];
|
||||||
|
|
||||||
|
$sumSub2["IloscSum"][$key][$keyy] += $elementtt["ilosc"];
|
||||||
|
$sumSub2["SoldSum"][$key][$keyy] += $elementtt["netto"];
|
||||||
|
//if($elementtt["type"]=="normal")
|
||||||
|
//{
|
||||||
|
$sumSub2["SoldSumNormal"][$key][$keyy] += $elementtt["netto"];
|
||||||
|
$sumSub2["IloscNormal"][$key][$keyy] += $elementtt["ilosc"];
|
||||||
|
//}else{
|
||||||
|
// $sumSub2["SoldSumNormal"][$key][$keyy] += 0;
|
||||||
|
// $sumSub2["IloscNormal"][$key][$keyy] += 0;
|
||||||
|
//}
|
||||||
|
$sumSub2["KosztSum"][$key][$keyy] += $elementtt["koszt"];
|
||||||
|
}
|
||||||
|
$categoryArray[$key][$keyy]["IloscSum2"] = $sumSub2["IloscSum"][$key][$keyy];
|
||||||
|
$categoryArray[$key][$keyy]["SoldSum2"] = $sumSub2["SoldSum"][$key][$keyy];
|
||||||
|
$categoryArray[$key][$keyy]["SoldSumNormal2"] = $sumSub2["SoldSumNormal"][$key][$keyy];
|
||||||
|
$categoryArray[$key][$keyy]["IloscNormal2"] = $sumSub2["IloscNormal"][$key][$keyy];
|
||||||
|
$categoryArray[$key][$keyy]["KosztSum2"] = $sumSub2["KosztSum"][$key][$keyy];
|
||||||
|
}
|
||||||
|
$categoryArray[$key]["IloscSum"] = $sumSub["IloscSum"][$key];
|
||||||
|
$categoryArray[$key]["SoldSum"] = $sumSub["SoldSum"][$key];
|
||||||
|
$categoryArray[$key]["SoldSumNormal"] = $sumSub["SoldSumNormal"][$key];
|
||||||
|
$categoryArray[$key]["IloscNormal"] = $sumSub["IloscNormal"][$key];
|
||||||
|
$categoryArray[$key]["KosztSum"] = $sumSub["KosztSum"][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($categoryArray as $key => &$element) {
|
||||||
|
$sum["IloscSumSum"] += $sumSub["IloscSum"][$key];
|
||||||
|
$sum["SoldSumSum"] += $sumSub["SoldSum"][$key];
|
||||||
|
$sum["SoldSumSumNormal"] += $sumSub["SoldSumNormal"][$key];
|
||||||
|
$sum["IloscNormal"] += $sumSub["IloscNormal"][$key];
|
||||||
|
$sum["KosztSumSum"] += $sumSub["KosztSum"][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$sum["SredniaSumSum"] = $sum["SoldSumSumNormal"] / $sum["IloscNormal"];
|
||||||
|
$sum["MarzaSumSum"] = ($sum["SoldSumSumNormal"] - $sum["KosztSumSum"]) / $sum["SoldSumSumNormal"] * 100;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cmp($a, $b)
|
||||||
{
|
{
|
||||||
////////////////// SUM /////////////////////////////////
|
if ($a['name'] == $b['name']) {
|
||||||
foreach( $data as $key=>&$element )
|
return 0;
|
||||||
{ if($element["netto"]!=0)
|
}
|
||||||
{
|
return ($a['name'] < $b['name']) ? -1 : 1;
|
||||||
$categoryArray[$element["kategoria"] == "" ? "Inne" : $element["kategoria"]][$element["podkategoria"] == "" ? "Reszta" : $element["podkategoria"]][$key] = $element;
|
}
|
||||||
} else {
|
|
||||||
//echo "Nie przechodzi: <br>";
|
|
||||||
//print_r( $element );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach( $categoryArray as $key=>&$element )
|
|
||||||
{
|
|
||||||
foreach( $element as $keyy=>&$elementt )
|
|
||||||
{
|
|
||||||
foreach( $elementt as $keyyy=>&$elementtt )
|
|
||||||
{
|
|
||||||
$sumSub["IloscSum"][$key] += $elementtt["ilosc"];
|
|
||||||
$sumSub["SoldSum"][$key] += $elementtt["netto"];
|
|
||||||
//if($elementtt["type"]=="normal")
|
|
||||||
//{
|
|
||||||
$sumSub["SoldSumNormal"][$key] += $elementtt["netto"];
|
|
||||||
$sumSub["IloscNormal"][$key] += $elementtt["ilosc"];
|
|
||||||
//}else{
|
|
||||||
// $sumSub["SoldSumNormal"][$key] += 0;
|
|
||||||
//$sumSub["IloscNormal"][$key] += 0;
|
|
||||||
// }
|
|
||||||
$sumSub["KosztSum"][$key] += $elementtt["koszt"];
|
|
||||||
|
|
||||||
$sumSub2["IloscSum"][$key][$keyy] += $elementtt["ilosc"];
|
|
||||||
$sumSub2["SoldSum"][$key][$keyy] += $elementtt["netto"];
|
|
||||||
//if($elementtt["type"]=="normal")
|
|
||||||
//{
|
|
||||||
$sumSub2["SoldSumNormal"][$key][$keyy] += $elementtt["netto"];
|
|
||||||
$sumSub2["IloscNormal"][$key][$keyy] += $elementtt["ilosc"];
|
|
||||||
//}else{
|
|
||||||
// $sumSub2["SoldSumNormal"][$key][$keyy] += 0;
|
|
||||||
// $sumSub2["IloscNormal"][$key][$keyy] += 0;
|
|
||||||
//}
|
|
||||||
$sumSub2["KosztSum"][$key][$keyy] += $elementtt["koszt"];
|
|
||||||
}
|
|
||||||
$categoryArray[$key][$keyy]["IloscSum2"] = $sumSub2["IloscSum"][$key][$keyy];
|
|
||||||
$categoryArray[$key][$keyy]["SoldSum2"] = $sumSub2["SoldSum"][$key][$keyy];
|
|
||||||
$categoryArray[$key][$keyy]["SoldSumNormal2"] = $sumSub2["SoldSumNormal"][$key][$keyy];
|
|
||||||
$categoryArray[$key][$keyy]["IloscNormal2"] = $sumSub2["IloscNormal"][$key][$keyy];
|
|
||||||
$categoryArray[$key][$keyy]["KosztSum2"] = $sumSub2["KosztSum"][$key][$keyy];
|
|
||||||
|
|
||||||
}
|
function cmp2($a, $b)
|
||||||
$categoryArray[$key]["IloscSum"] = $sumSub["IloscSum"][$key];
|
{
|
||||||
$categoryArray[$key]["SoldSum"] = $sumSub["SoldSum"][$key];
|
if ($a['id'] == $b['id']) {
|
||||||
$categoryArray[$key]["SoldSumNormal"] = $sumSub["SoldSumNormal"][$key];
|
return 0;
|
||||||
$categoryArray[$key]["IloscNormal"] = $sumSub["IloscNormal"][$key];
|
}
|
||||||
$categoryArray[$key]["KosztSum"] = $sumSub["KosztSum"][$key];
|
return ($a['id'] < $b['id']) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( $categoryArray as $key=>&$element )
|
|
||||||
{
|
|
||||||
$sum["IloscSumSum"] += $sumSub["IloscSum"][$key];
|
|
||||||
$sum["SoldSumSum"] += $sumSub["SoldSum"][$key];
|
|
||||||
$sum["SoldSumSumNormal"] += $sumSub["SoldSumNormal"][$key];
|
|
||||||
$sum["IloscNormal"] += $sumSub["IloscNormal"][$key];
|
|
||||||
$sum["KosztSumSum"] += $sumSub["KosztSum"][$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
$sum["SredniaSumSum"] = $sum["SoldSumSumNormal"]/$sum["IloscNormal"];
|
|
||||||
$sum["MarzaSumSum"] = ($sum["SoldSumSumNormal"]-$sum["KosztSumSum"])/$sum["SoldSumSumNormal"]*100;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function cmp($a, $b)
|
|
||||||
{
|
|
||||||
if ($a['name'] == $b['name']) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ($a['name'] < $b['name']) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function cmp2($a, $b)
|
|
||||||
{
|
|
||||||
if ($a['id'] == $b['id']) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ($a['id'] < $b['id']) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// grupowanie po kontrahentach
|
|
||||||
foreach($categoryArray as $key1=>&$element1)
|
|
||||||
{
|
|
||||||
foreach($element1 as $key2=>&$element2)
|
|
||||||
{
|
|
||||||
$tmp2[$key1][$key2]["IloscSum2"] = $categoryArray[$key1][$key2]["IloscSum2"];
|
|
||||||
$tmp2[$key1][$key2]["SoldSum2"] = $categoryArray[$key1][$key2]["SoldSum2"];
|
|
||||||
$tmp2[$key1][$key2]["SoldSumNormal2"] = $categoryArray[$key1][$key2]["SoldSumNormal2"];
|
|
||||||
$tmp2[$key1][$key2]["IloscNormal2"] = $categoryArray[$key1][$key2]["IloscNormal2"];
|
|
||||||
$tmp2[$key1][$key2]["KosztSum2"] = $categoryArray[$key1][$key2]["KosztSum2"];
|
|
||||||
|
|
||||||
if($searchBy=="contractor")
|
|
||||||
{
|
|
||||||
usort($element2, "cmp");
|
|
||||||
}else{
|
|
||||||
usort($element2, "cmp2");
|
|
||||||
}
|
|
||||||
$i=0;
|
|
||||||
$tmp2[$key1][$key2][0]= array ('name' => null);
|
|
||||||
foreach($element2 as $count=>&$element3)
|
|
||||||
{
|
|
||||||
if($element3[$groupBy]!=$tmp2[$key1][$key2][$i][$groupBy])
|
|
||||||
{
|
|
||||||
if($tmp2[$key1][$key2][$i][$groupBy]!=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]["state"]=$element3["state"];
|
|
||||||
$tmp2[$key1][$key2][$i]["parent_id"]=$element3["parent_id"];
|
|
||||||
}
|
|
||||||
//if($element3["type"]=="normal")
|
|
||||||
//{
|
|
||||||
$tmp2[$key1][$key2][$i]["nettoNormal"] += $element3["netto"];
|
|
||||||
$tmp2[$key1][$key2][$i]["IloscNormal"] += $element3["ilosc"];
|
|
||||||
//}
|
|
||||||
$tmp2[$key1][$key2][$i]["ilosc"] += $element3["ilosc"];
|
|
||||||
$tmp2[$key1][$key2][$i]["netto"] += $element3["netto"];
|
|
||||||
$tmp2[$key1][$key2][$i]["koszt"] += $element3["koszt"];
|
|
||||||
}
|
|
||||||
$tmp2[$key1]["IloscSum"] = $categoryArray[$key1]["IloscSum"];
|
|
||||||
$tmp2[$key1]["SoldSum"] = $categoryArray[$key1]["SoldSum"];
|
|
||||||
$tmp2[$key1]["SoldSumNormal"] = $categoryArray[$key1]["SoldSumNormal"];
|
|
||||||
$tmp2[$key1]["IloscNormal"] = $categoryArray[$key1]["IloscNormal"];
|
|
||||||
$tmp2[$key1]["KosztSum"] = $categoryArray[$key1]["KosztSum"];
|
|
||||||
|
|
||||||
|
|
||||||
$sumSub2["MarzaSum"][$key1][$key2] = ($tmp2[$key1][$key2]["SoldSumNormal2"]-$tmp2[$key1][$key2]["KosztSum2"])/$tmp2[$key1][$key2]["SoldSumNormal2"]*100;
|
|
||||||
$sumSub2["SredniaSum"][$key1][$key2] = $tmp2[$key1][$key2]["SoldSumNormal2"]/$tmp2[$key1][$key2]["IloscNormal2"];
|
|
||||||
if($key2=="Reszta")
|
|
||||||
{
|
|
||||||
if(is_array($sumSub2["SredniaSum"][$key1][$key2]) || $sumSub2["SredniaSum"][$key1][$key2]=='')
|
|
||||||
{
|
|
||||||
$sumSub2["SredniaSum"][$key1][$key2]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$count1 ++;
|
|
||||||
|
|
||||||
$tmp2[$key1][$key2]["SredniaSum2"] = $sumSub2["SredniaSum"][$key1][$key2];
|
|
||||||
$tmp2[$key1][$key2]["MarzaSum2"] = $sumSub2["MarzaSum"][$key1][$key2];
|
|
||||||
}
|
|
||||||
$sumSub["MarzaSum"][$key1] = ($tmp2[$key1]["SoldSumNormal"]-$tmp2[$key1]["KosztSum"])/$tmp2[$key1]["SoldSumNormal"]*100;
|
|
||||||
$sumSub["SredniaSum"][$key1] = $tmp2[$key1]["SoldSumNormal"]/$tmp2[$key1]["IloscNormal"];
|
|
||||||
|
|
||||||
$tmp2[$key1]["SredniaSum"] = $sumSub["SredniaSum"][$key1];
|
|
||||||
$tmp2[$key1]["MarzaSum"] = $sumSub["MarzaSum"][$key1];
|
|
||||||
$categoryArray1=$tmp2;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////// SORT sumSub /////////////////////////////////
|
// grupowanie po kontrahentach
|
||||||
foreach( $categoryArray1 as $key1=>&$element )
|
foreach ($categoryArray as $key1 => &$element1) {
|
||||||
{
|
foreach ($element1 as $key2 => &$element2) {
|
||||||
foreach( $element as $key2=>&$elements )
|
$tmp2[$key1][$key2]["IloscSum2"] = $categoryArray[$key1][$key2]["IloscSum2"];
|
||||||
{
|
$tmp2[$key1][$key2]["SoldSum2"] = $categoryArray[$key1][$key2]["SoldSum2"];
|
||||||
foreach( $element as $key3=>&$element2 )
|
$tmp2[$key1][$key2]["SoldSumNormal2"] = $categoryArray[$key1][$key2]["SoldSumNormal2"];
|
||||||
{
|
$tmp2[$key1][$key2]["IloscNormal2"] = $categoryArray[$key1][$key2]["IloscNormal2"];
|
||||||
if($sumSub2["SoldSum"][$key1][$key2]>$sumSub2["SoldSum"][$key1][$key3])
|
$tmp2[$key1][$key2]["KosztSum2"] = $categoryArray[$key1][$key2]["KosztSum2"];
|
||||||
{
|
|
||||||
$tmp=$sumSub2["SoldSum"][$key1][$key2];
|
if ($searchBy == "contractor") {
|
||||||
$sumSub2["SoldSum"][$key1][$key2]=$sumSub2["SoldSum"][$key1][$key3];
|
usort($element2, "cmp");
|
||||||
$sumSub2["SoldSum"][$key1][$key3]=$tmp;
|
} else {
|
||||||
}
|
usort($element2, "cmp2");
|
||||||
|
}
|
||||||
|
$i = 0;
|
||||||
|
$tmp2[$key1][$key2][0] = array('name' => null);
|
||||||
|
foreach ($element2 as $count => &$element3) {
|
||||||
|
if ($element3[$groupBy] != $tmp2[$key1][$key2][$i][$groupBy]) {
|
||||||
|
if ($tmp2[$key1][$key2][$i][$groupBy] != 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]["state"] = $element3["state"];
|
||||||
|
$tmp2[$key1][$key2][$i]["ordered_quantity"] = $element3["ordered_quantity"];
|
||||||
|
$tmp2[$key1][$key2][$i]["parent_id"] = $element3["parent_id"];
|
||||||
|
}
|
||||||
|
//if($element3["type"]=="normal")
|
||||||
|
//{
|
||||||
|
$tmp2[$key1][$key2][$i]["nettoNormal"] += $element3["netto"];
|
||||||
|
$tmp2[$key1][$key2][$i]["IloscNormal"] += $element3["ilosc"];
|
||||||
|
//}
|
||||||
|
$tmp2[$key1][$key2][$i]["ilosc"] += $element3["ilosc"];
|
||||||
|
$tmp2[$key1][$key2][$i]["netto"] += $element3["netto"];
|
||||||
|
$tmp2[$key1][$key2][$i]["koszt"] += $element3["koszt"];
|
||||||
|
}
|
||||||
|
$tmp2[$key1]["IloscSum"] = $categoryArray[$key1]["IloscSum"];
|
||||||
|
$tmp2[$key1]["SoldSum"] = $categoryArray[$key1]["SoldSum"];
|
||||||
|
$tmp2[$key1]["SoldSumNormal"] = $categoryArray[$key1]["SoldSumNormal"];
|
||||||
|
$tmp2[$key1]["IloscNormal"] = $categoryArray[$key1]["IloscNormal"];
|
||||||
|
$tmp2[$key1]["KosztSum"] = $categoryArray[$key1]["KosztSum"];
|
||||||
|
|
||||||
|
|
||||||
|
$sumSub2["MarzaSum"][$key1][$key2] = ($tmp2[$key1][$key2]["SoldSumNormal2"] - $tmp2[$key1][$key2]["KosztSum2"]) / $tmp2[$key1][$key2]["SoldSumNormal2"] * 100;
|
||||||
|
$sumSub2["SredniaSum"][$key1][$key2] = $tmp2[$key1][$key2]["SoldSumNormal2"] / $tmp2[$key1][$key2]["IloscNormal2"];
|
||||||
|
if ($key2 == "Reszta") {
|
||||||
|
if (is_array($sumSub2["SredniaSum"][$key1][$key2]) || $sumSub2["SredniaSum"][$key1][$key2] == '') {
|
||||||
|
$sumSub2["SredniaSum"][$key1][$key2] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$count1++;
|
||||||
foreach( $sumSub["SoldSum"] as $key1=>&$element )
|
|
||||||
{
|
$tmp2[$key1][$key2]["SredniaSum2"] = $sumSub2["SredniaSum"][$key1][$key2];
|
||||||
foreach( $sumSub["SoldSum"] as $key2=>&$element2 )
|
$tmp2[$key1][$key2]["MarzaSum2"] = $sumSub2["MarzaSum"][$key1][$key2];
|
||||||
{
|
}
|
||||||
if($sumSub["SoldSum"][$key1]>$sumSub["SoldSum"][$key2])
|
$sumSub["MarzaSum"][$key1] = ($tmp2[$key1]["SoldSumNormal"] - $tmp2[$key1]["KosztSum"]) / $tmp2[$key1]["SoldSumNormal"] * 100;
|
||||||
{
|
$sumSub["SredniaSum"][$key1] = $tmp2[$key1]["SoldSumNormal"] / $tmp2[$key1]["IloscNormal"];
|
||||||
$tmp=$sumSub["SoldSum"][$key1];
|
|
||||||
$sumSub["SoldSum"][$key1]=$sumSub["SoldSum"][$key2];
|
$tmp2[$key1]["SredniaSum"] = $sumSub["SredniaSum"][$key1];
|
||||||
$sumSub["SoldSum"][$key2]=$tmp;
|
$tmp2[$key1]["MarzaSum"] = $sumSub["MarzaSum"][$key1];
|
||||||
}
|
$categoryArray1 = $tmp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////// SORT sumSub /////////////////////////////////
|
||||||
|
foreach ($categoryArray1 as $key1 => &$element) {
|
||||||
|
foreach ($element as $key2 => &$elements) {
|
||||||
|
foreach ($element as $key3 => &$element2) {
|
||||||
|
if ($sumSub2["SoldSum"][$key1][$key2] > $sumSub2["SoldSum"][$key1][$key3]) {
|
||||||
|
$tmp = $sumSub2["SoldSum"][$key1][$key2];
|
||||||
|
$sumSub2["SoldSum"][$key1][$key2] = $sumSub2["SoldSum"][$key1][$key3];
|
||||||
|
$sumSub2["SoldSum"][$key1][$key3] = $tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////// SORT array /////////////////////////////////
|
|
||||||
$newArray2;
|
|
||||||
foreach( $sumSub["SoldSum"] as $key1=>&$element1 )
|
|
||||||
{
|
|
||||||
foreach( $categoryArray1 as $key2=>&$element2 )
|
|
||||||
{
|
|
||||||
if($sumSub["SoldSum"][$key1]==$categoryArray1[$key2]["SoldSum"])
|
|
||||||
{
|
|
||||||
$newArray2[$key2]=$categoryArray1[$key2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$newArray1;
|
|
||||||
foreach( $newArray2 as $key1=>&$element1 )
|
|
||||||
{
|
|
||||||
foreach( $element1 as $key2=>&$element2 )
|
|
||||||
{
|
|
||||||
foreach( $element1 as $key3=>&$element3 )
|
|
||||||
{
|
|
||||||
if($sumSub2["SoldSum"][$key1][$key2]==$newArray2[$key1][$key3]["SoldSum2"])
|
|
||||||
{
|
|
||||||
$newArray1[$key1][$key3]=$newArray2[$key1][$key3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//wyliczanie dokładne marży i średniej dla produktów
|
|
||||||
foreach( $newArray1 as $key1=>&$element1 )
|
|
||||||
{
|
|
||||||
foreach( $element1 as $key2=>&$element2 )
|
|
||||||
{
|
|
||||||
foreach( $element2 as $key3=>&$element3 )
|
|
||||||
{
|
|
||||||
$newArray1[$key1][$key2][$key3]["marza"] = ($newArray1[$key1][$key2][$key3]["nettoNormal"]-$newArray1[$key1][$key2][$key3]["koszt"])/$newArray1[$key1][$key2][$key3]["nettoNormal"]*100;
|
|
||||||
$newArray1[$key1][$key2][$key3]["srednia"] = $newArray1[$key1][$key2][$key3]["nettoNormal"]/$newArray1[$key1][$key2][$key3]["IloscNormal"];
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
}
|
||||||
|
|
||||||
|
foreach ($sumSub["SoldSum"] as $key1 => &$element) {
|
||||||
|
foreach ($sumSub["SoldSum"] as $key2 => &$element2) {
|
||||||
|
if ($sumSub["SoldSum"][$key1] > $sumSub["SoldSum"][$key2]) {
|
||||||
|
$tmp = $sumSub["SoldSum"][$key1];
|
||||||
|
$sumSub["SoldSum"][$key1] = $sumSub["SoldSum"][$key2];
|
||||||
|
$sumSub["SoldSum"][$key2] = $tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
////////////////// SORT array /////////////////////////////////
|
||||||
|
$newArray2;
|
||||||
|
foreach ($sumSub["SoldSum"] as $key1 => &$element1) {
|
||||||
|
foreach ($categoryArray1 as $key2 => &$element2) {
|
||||||
|
if ($sumSub["SoldSum"][$key1] == $categoryArray1[$key2]["SoldSum"]) {
|
||||||
|
$newArray2[$key2] = $categoryArray1[$key2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newArray1;
|
||||||
|
foreach ($newArray2 as $key1 => &$element1) {
|
||||||
|
foreach ($element1 as $key2 => &$element2) {
|
||||||
|
foreach ($element1 as $key3 => &$element3) {
|
||||||
|
if ($sumSub2["SoldSum"][$key1][$key2] == $newArray2[$key1][$key3]["SoldSum2"]) {
|
||||||
|
$newArray1[$key1][$key3] = $newArray2[$key1][$key3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//wyliczanie dokładne marży i średniej dla produktów
|
||||||
|
foreach ($newArray1 as $key1 => &$element1) {
|
||||||
|
foreach ($element1 as $key2 => &$element2) {
|
||||||
|
foreach ($element2 as $key3 => &$element3) {
|
||||||
|
$newArray1[$key1][$key2][$key3]["marza"] = ($newArray1[$key1][$key2][$key3]["nettoNormal"] - $newArray1[$key1][$key2][$key3]["koszt"]) / $newArray1[$key1][$key2][$key3]["nettoNormal"] * 100;
|
||||||
|
$newArray1[$key1][$key2][$key3]["srednia"] = $newArray1[$key1][$key2][$key3]["nettoNormal"] / $newArray1[$key1][$key2][$key3]["IloscNormal"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -247,7 +247,8 @@
|
|||||||
<th width="30%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="0" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_PRODUCTS}</th>
|
<th width="30%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="0" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_PRODUCTS}</th>
|
||||||
{if $searchBy=="product"}
|
{if $searchBy=="product"}
|
||||||
<th width="10%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Indeks</th>
|
<th width="10%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Indeks</th>
|
||||||
<th width="10%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Stan</th>
|
<th width="5%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Stan</th>
|
||||||
|
<th width="5%" class="sorter-text tablesorter-header tablesorter-headerUnSorted" data-column="1" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">Zamówiona ilość</th>
|
||||||
{/if}
|
{/if}
|
||||||
<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="2" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_SOLD_AMOUNT}</th>
|
<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="2" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_SOLD_AMOUNT}</th>
|
||||||
<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="3" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_VALUE_SALES}</th>
|
<th width="10%" class="sorter-saas tablesorter-header tablesorter-headerUnSorted" data-column="3" tabindex="0" scope="col" role="columnheader" aria-disabled="false" unselectable="on" style="-moz-user-select: none;" aria-sort="none" aria-label="Name: No sort applied, activate to apply an ascending sort">{$MOD.LBL_VALUE_SALES}</th>
|
||||||
@@ -271,6 +272,7 @@
|
|||||||
{if $searchBy=="product"}
|
{if $searchBy=="product"}
|
||||||
<td class="oddListRowS1 alignLeft" ></td>
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
<td class="oddListRowS1 alignLeft" ></td>
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
{/if}
|
{/if}
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.IloscSum|number_format:0:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.IloscSum|number_format:0:",":"." }</b></td>
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.SoldSum|number_format:2:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$DATA.$CATNAME.SoldSum|number_format:2:",":"." }</b></td>
|
||||||
@@ -292,6 +294,7 @@
|
|||||||
{if $searchBy=="product"}
|
{if $searchBy=="product"}
|
||||||
<td class="oddListRowS1 alignLeft" ></td>
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
<td class="oddListRowS1 alignLeft" ></td>
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
|
<td class="oddListRowS1 alignLeft" ></td>
|
||||||
{/if}
|
{/if}
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.IloscSum2|number_format:0:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.IloscSum2|number_format:0:",":"." }</b></td>
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SoldSum2|number_format:2:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$CAT.$CAT2NAME.SoldSum2|number_format:2:",":"." }</b></td>
|
||||||
@@ -330,6 +333,7 @@
|
|||||||
{if $searchBy=="product"}
|
{if $searchBy=="product"}
|
||||||
<td class="oddListRowS1 alignLeft" >{$ROW.code}</td>
|
<td class="oddListRowS1 alignLeft" >{$ROW.code}</td>
|
||||||
<td class="oddListRowS1 alignRight" >{$ROW.state}</td>
|
<td class="oddListRowS1 alignRight" >{$ROW.state}</td>
|
||||||
|
<td class="oddListRowS1 alignRight" >{$ROW.ordered_quantity}</td>
|
||||||
{/if}
|
{/if}
|
||||||
<td class="oddListRowS1" >{$ROW.ilosc|number_format:0:",":"."}</td>
|
<td class="oddListRowS1" >{$ROW.ilosc|number_format:0:",":"."}</td>
|
||||||
<td class="oddListRowS1" >{$ROW.netto|number_format:2:",":"."}</td>
|
<td class="oddListRowS1" >{$ROW.netto|number_format:2:",":"."}</td>
|
||||||
@@ -352,6 +356,7 @@
|
|||||||
{if $searchBy=="product"}
|
{if $searchBy=="product"}
|
||||||
<td class="oddListRowS1" ></td>
|
<td class="oddListRowS1" ></td>
|
||||||
<td class="oddListRowS1" ></td>
|
<td class="oddListRowS1" ></td>
|
||||||
|
<td class="oddListRowS1" ></td>
|
||||||
{/if}
|
{/if}
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$SUM.IloscSumSum|number_format:0:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$SUM.IloscSumSum|number_format:0:",":"." }</b></td>
|
||||||
<td class="oddListRowS1 sumRow" ><b>{$SUM.SoldSumSum|number_format:2:",":"." }</b></td>
|
<td class="oddListRowS1 sumRow" ><b>{$SUM.SoldSumSum|number_format:2:",":"." }</b></td>
|
||||||
|
|||||||
@@ -214,9 +214,9 @@ class EcmStockState extends SugarBean {
|
|||||||
$GLOBALS['db']->query(
|
$GLOBALS['db']->query(
|
||||||
"UPDATE ecmproducts as p
|
"UPDATE ecmproducts as p
|
||||||
INNER JOIN (
|
INNER JOIN (
|
||||||
SELECT round(sum(quantity*price)/sum(quantity),2) as avg_price, product_id FROM ecmstockstates GROUP BY product_id
|
SELECT round(sum(quantity*price)/sum(quantity),2) as avg_price, product_id, SUM(quantity) as stock_state FROM ecmstockstates GROUP BY product_id
|
||||||
) s ON p.id=s.product_id
|
) s ON p.id=s.product_id
|
||||||
SET p.ems_price = s.avg_price
|
SET p.ems_price = s.avg_price, p.ems_qty_in_stock = s.stock_state
|
||||||
WHERE p.id='$product_id'"
|
WHERE p.id='$product_id'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user