init
This commit is contained in:
142
modules/EcmStockOperations/summary_report.php
Normal file
142
modules/EcmStockOperations/summary_report.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
if(!$_GET['date_from'])$date_from=date("Y-m-d");
|
||||
else $date_from=$GLOBALS['timedate']->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");
|
||||
?>
|
||||
<table cellspacing="0" cellpadding="0" border="0"><tr><td><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="" width="16" border="0" height="16"></td><td><h2>Raport operacji magazynowych</h2></td></tr></table><br />
|
||||
<ul class="tablist" style="width:100%;">
|
||||
<li>
|
||||
<a class="current" href="#">Opcje</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form action="index.php" method="get" name="search_reports">
|
||||
<input type="hidden" name="module" value="EcmStockOperations" />
|
||||
<input type="hidden" name="action" value="summary_report" />
|
||||
<input type="hidden" name="process" value="1" />
|
||||
<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="dataLabel" width="5%" nowrap="nowrap">
|
||||
Od daty </td>
|
||||
<td class="dataField" width="20%" nowrap="nowrap">
|
||||
<input autocomplete="off" name="date_from" id="date_from" value="<? echo $GLOBALS['timedate']->to_display_date($date_from);?>" title="" tabindex="" size="11" maxlength="10" type="text">
|
||||
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_from_trigger" align="absmiddle" border="0">
|
||||
<script type="text/javascript">
|
||||
Calendar.setup ({
|
||||
inputField : "date_from",
|
||||
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
|
||||
button : "date_from_trigger",
|
||||
singleClick : true,
|
||||
dateStr : "",
|
||||
step : 1
|
||||
}
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
<td class="dataLabel" width="5%" nowrap="nowrap">
|
||||
Do daty</td>
|
||||
<td class="dataField" width="20%" nowrap="nowrap">
|
||||
<input autocomplete="off" name="date_to" id="date_to" value="<? echo $GLOBALS['timedate']->to_display_date($date_to);?>" title="" tabindex="" size="11" maxlength="10" type="text">
|
||||
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_to_trigger" align="absmiddle" border="0">
|
||||
<script type="text/javascript">
|
||||
Calendar.setup ({
|
||||
inputField : "date_to",
|
||||
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
|
||||
button : "date_to_trigger",
|
||||
singleClick : true,
|
||||
dateStr : "",
|
||||
step : 1
|
||||
}
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<input class="button" name="submit" value="Wykonaj" type="submit">
|
||||
<input class="button" name="clear" value="Wyczyść" type="button" onclick="location.href='index.php?module=EcmReports&action=index6';">
|
||||
|
||||
<?php
|
||||
if ($_REQUEST['process']!='1') return;
|
||||
if (!$_REQUEST['date_from']) return;
|
||||
if (!$_REQUEST['date_to']) return;
|
||||
|
||||
$date_from=$GLOBALS['timedate']->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 = '<br><br><table border="1" cellspacing="0" cellpadding="0" border="0" style="">';
|
||||
//header
|
||||
$table.='<tr style="background-color: #f6f6f6;"><td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">Typ dokumentu</td>';
|
||||
foreach ($groups as $g) $table.='<td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">'.$g.'</td>';
|
||||
$table.='<td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">Razem</td></tr>';
|
||||
//results
|
||||
$group_sum = array();
|
||||
$sum_rows = 0;
|
||||
foreach ($operations as $type=>$row) {
|
||||
$row_sum = 0;
|
||||
$table.='<tr><td class="oddListRowS1" style="text-align:center; width:250px; border-bottom: 1px solid #cccccc;">'.$map[$type].'</td>';
|
||||
foreach ($groups as $g) {
|
||||
if (!$group_sum[$g]) $group_sum[$g] = 0;
|
||||
if ($row[$g]) $val = $row[$g]; else $val = 0;
|
||||
$table.='<td class="oddListRowS1" style="text-align:center; width:250px; border-bottom: 1px solid #cccccc;">'.format_number($val).'</td>';
|
||||
$row_sum+=$val;
|
||||
$group_sum[$g] += $val;
|
||||
}
|
||||
$table.='<td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">'.format_number($row_sum).'</td></tr>';
|
||||
$sum_rows +=$row_sum;
|
||||
}
|
||||
//group summary
|
||||
$table.='<tr><td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">Razem</td>';
|
||||
$sum_group = 0;
|
||||
foreach ($groups as $g) {
|
||||
if ($group_sum[$g]) $val = $group_sum[$g]; else $val = 0;
|
||||
$table.='<td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">'.format_number($val).'</td>';
|
||||
$sum_group+=$val;
|
||||
}
|
||||
$table.='<td class="listViewThS1" height:48px;"="" "width:250px;="" style="text-align:center;">'.$sum_group.'</td></tr></table>';
|
||||
//echo '<br>sum_group= '.$sum_group;
|
||||
//echo '<br>sum_row= '.$sum_rows;
|
||||
|
||||
echo $table;
|
||||
?>
|
||||
Reference in New Issue
Block a user