to_db_date($_GET['date_from']); $exp=explode("-",$date_from); $date_from=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600); if(!$date_from)$date_from=date("Y-m-d"); if(!$_GET['date_to'])$date_to=date("Y-m-d"); else $date_to=$GLOBALS['timedate']->to_db_date($_GET['date_to']); $exp=explode("-",$date_to); $date_to=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600); if(!$date_to)$date_to=date("Y-m-d"); ?>

Raport operacji magazynowych


Od daty Enter Date Do daty Enter Date
to_db_date($_GET['date_from']); $date_to=$GLOBALS['timedate']->to_db_date($_GET['date_to']); global $db; //get groups $groups = array(); $res=$db->query("SELECT DISTINCT group_ks FROM ecmproducts ORDER BY group_ks"); while ($row=$db->fetchByAssoc($res)) $groups[] = $row['group_ks']; //get operations $query = " SELECT (CASE so.type WHEN '1' THEN so.price*so.quantity*-1 WHEN '0' THEN so.price*so.quantity END) as val, so.type, so.parent_type as type, p.group_ks as group_ks FROM ecmstockoperations as so LEFT JOIN ecmproducts as p ON p.id=so.product_id WHERE so.date_entered BETWEEN '$date_from' AND '$date_to' GROUP BY so.parent_type, p.group_ks ORDER BY so.parent_type"; echo $query; $res = $db->query($query); $operations = array(); while ($row = $db->fetchByAssoc($res)) { if (!is_array($operations[$row['type']])) $operations[$row['type']] = array(); $operations[$row['type']][$row['group_ks']] = $row['val']; } //doc_map $map = array( 'EcmInvoiceOuts' => 'FV', 'EcmStockDocIns' => 'PZ', 'EcmStockDocOuts' => 'WZ', 'EcmStockDocInsideIns' => 'PW', 'EcmStockDocInsideOuts' => 'RW', 'EcmStockDocMoves' => 'MM', 'EcmStockDocCorrects' => 'KS', ); //draw results $table = '

'; //header $table.=''; foreach ($groups as $g) $table.=''; $table.=''; //results $group_sum = array(); $sum_rows = 0; foreach ($operations as $type=>$row) { $row_sum = 0; $table.=''; foreach ($groups as $g) { if (!$group_sum[$g]) $group_sum[$g] = 0; if ($row[$g]) $val = $row[$g]; else $val = 0; $table.=''; $row_sum+=$val; $group_sum[$g] += $val; } $table.=''; $sum_rows +=$row_sum; } //group summary $table.=''; $sum_group = 0; foreach ($groups as $g) { if ($group_sum[$g]) $val = $group_sum[$g]; else $val = 0; $table.=''; $sum_group+=$val; } $table.='
Typ dokumentu'.$g.'Razem
'.$map[$type].''.format_number($val).''.format_number($row_sum).'
Razem'.format_number($val).''.$sum_group.'
'; //echo '
sum_group= '.$sum_group; //echo '
sum_row= '.$sum_rows; echo $table; ?>