Allegro returns - KS document
This commit is contained in:
81
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php
Normal file
81
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
|
||||
$smarty = new Sugar_Smarty();
|
||||
|
||||
if (isset($_REQUEST['date_from'])) {
|
||||
$DEBUG = $_REQUEST['debug'] == '1' ? true : false;
|
||||
$smarty->assign('debug', $DEBUG ? '1' : '');
|
||||
|
||||
$invoices = getInvoices($_REQUEST['date_from'], $_REQUEST['date_to']);
|
||||
|
||||
$invoiceIds = array();
|
||||
foreach ($invoices as $invoice) {
|
||||
$invoiceIds[] = $invoice['id'];
|
||||
}
|
||||
$sessionId = create_guid();
|
||||
$_SESSION[$sessionId] = $invoiceIds;
|
||||
$smarty->assign('sessionId', $sessionId);
|
||||
|
||||
$invoiceNo = array();
|
||||
foreach ($invoices as $invoice) {
|
||||
$invoiceNo[] = $invoice['document_no'];
|
||||
}
|
||||
$smarty->assign('invoicesNo', join(", ", $invoiceNo));
|
||||
|
||||
$smarty->assign('date_from', $_REQUEST['date_from']);
|
||||
$smarty->assign('date_to', $_REQUEST['date_to']);
|
||||
echo $smarty->display(getcwd() . '/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl');
|
||||
} else {
|
||||
$smarty->assign('date_from', date('d.m.Y'));
|
||||
$smarty->assign('date_to', date('d.m.Y'));
|
||||
echo $smarty->display(getcwd() . '/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl');
|
||||
}
|
||||
|
||||
function getInvoices($dateFrom, $dateTo) {
|
||||
$db = $GLOBALS['db'];
|
||||
$invoices = array();
|
||||
$dateFrom = date('Y-m-d', strtotime($dateFrom));
|
||||
$dateTo = date('Y-m-d', strtotime($dateTo));
|
||||
$query = "SELECT ip.ecmproduct_id, ip.code, i.document_no, SUM(ip.quantity) AS quantity, i.register_date, i.id
|
||||
FROM ecommerce_invoices_products AS ip
|
||||
INNER JOIN ecommerce_invoices AS i ON ip.invoice_id = i.id AND i.register_date BETWEEN '$dateFrom' AND '$dateTo' AND i.type='correcting'
|
||||
AND i.origin IN ('allegro', 'shop')
|
||||
WHERE ip.ecmproduct_id != '' AND ip.ecmproduct_id !='165f364e-9301-25ac-5906-58e38f1de4ca' AND ip.quantity > 0
|
||||
AND i.ecmstockdoccorrect_id IS NULL
|
||||
GROUP BY i.id, ip.ecmproduct_id
|
||||
ORDER BY i.register_date;";
|
||||
$res = $db->query($query);
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
if (!isset($invoices[$row['document_no']])) {
|
||||
$invoices[$row['document_no']] = array();
|
||||
$invoices[$row['document_no']]['document_no'] = $row['document_no'];
|
||||
$invoices[$row['document_no']]['register_date'] = $row['register_date'];
|
||||
$invoices[$row['document_no']]['id'] = $row['id'];
|
||||
$invoices[$row['document_no']]['products'] = array();
|
||||
$invoices[$row['document_no']]['products'][] = array (
|
||||
'ecmproduct_id' => $row['ecmproduct_id'],
|
||||
'code' => $row['code'],
|
||||
'quantity' => $row['quantity'],
|
||||
);
|
||||
} else {
|
||||
$invoices[$row['document_no']]['products'][] = array (
|
||||
'ecmproduct_id' => $row['ecmproduct_id'],
|
||||
'code' => $row['code'],
|
||||
'quantity' => $row['quantity'],
|
||||
);
|
||||
}
|
||||
}
|
||||
$invoices = array_values($invoices);
|
||||
usort($invoices, function($a, $b) {
|
||||
return $a['id'] - $b['id'];
|
||||
});
|
||||
return $invoices;
|
||||
}
|
||||
|
||||
|
||||
69
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
Normal file
69
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
Normal file
@@ -0,0 +1,69 @@
|
||||
<!-- HEADER -->
|
||||
<table id="tableMenu" cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="themes/Sugar5/images/CaseReports.gif" style="margin-top: 3px; margin-right: 3px;" width="16"
|
||||
height="16">
|
||||
</td>
|
||||
<td>
|
||||
<h2>ZS E-Commerce</h2>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- FILTERS -->
|
||||
<form action="index.php" method="get">
|
||||
<input type="hidden" name="module" value="EcmStockDocCorrects">
|
||||
<input type="hidden" name="action" value="eCommerceKS">
|
||||
<table class="tabForm" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px;width:100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="5%">Zakres dat:</td>
|
||||
<td width="10%">
|
||||
<input id="date_from" name="date_from" type="text" maxlength="10" size="11" tabindex="" title=""
|
||||
value="{$date_from}" autocomplete="off">
|
||||
<img id="date_from_trigger" src="themes/default/images/jscalendar.gif">
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
Calendar.setup({ ldelim }
|
||||
inputField: "date_from",
|
||||
daFormat: "%d.%m.%Y",
|
||||
button: "date_from_trigger",
|
||||
singleClick: true,
|
||||
dateStr: "",
|
||||
step: 1
|
||||
{ rdelim }
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
<td>
|
||||
<input id="date_to" name="date_to" type="text" maxlength="10" size="11" tabindex="" title=""
|
||||
value="{$date_to}" autocomplete="off">
|
||||
<img id="date_to_trigger" src="themes/default/images/jscalendar.gif">
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
Calendar.setup({ ldelim }
|
||||
inputField: "date_to",
|
||||
daFormat: "%d.%m.%Y",
|
||||
button: "date_to_trigger",
|
||||
singleClick: true,
|
||||
dateStr: "",
|
||||
step: 1
|
||||
{ rdelim }
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="submit" class="button" value="Filtruj">
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
KS zbiorcza dla FVKOR:<br> {$invoicesNo}
|
||||
<br><br>
|
||||
<input title="Wystaw KS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw KS"
|
||||
onclick="window.open('index.php?module=EcmStockDocCorrects&action=EditView&ecommerceKS={$sessionId}')">
|
||||
Reference in New Issue
Block a user