export stock addresses
This commit is contained in:
@@ -134,6 +134,23 @@ function isProductValid(id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function exportFile() {
|
||||
$("#loader").show();
|
||||
$.ajax({
|
||||
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=export&to_pdf=1",
|
||||
}).done(function (data) {
|
||||
$("#loader").hide();
|
||||
if (data.status === 'Error') {
|
||||
alert('Błąd: ' + data.msg);
|
||||
} else {
|
||||
console.log(data);
|
||||
downloadFile(data.fileContent, data.fileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
}
|
||||
}).fail(() => {
|
||||
$("#loader").hide();
|
||||
alert('Błąd serwera.');
|
||||
});
|
||||
}
|
||||
$(document).ready(function () {
|
||||
$("#address").mask("AB.CD.E.F", {
|
||||
placeholder: "__.__._._",
|
||||
@@ -189,12 +206,49 @@ $(document).ready(function () {
|
||||
$("#searchByIndexForm").submit();
|
||||
}
|
||||
});
|
||||
$("#exportTrigger").click(() => {
|
||||
exportFile();
|
||||
});
|
||||
$('[name^="showAddress').click((event) => {
|
||||
$("#address").val(event.target.name.split('-')[1]);
|
||||
if (isAddressValid()) {
|
||||
$("#searchByAddressForm").submit();
|
||||
}
|
||||
|
||||
});
|
||||
//bind buttons
|
||||
});
|
||||
|
||||
function downloadFile(base64Data, fileName, mimeType) {
|
||||
// Stwórz blob z danych base64
|
||||
const byteCharacters = atob(base64Data);
|
||||
const byteArrays = [];
|
||||
|
||||
for (let offset = 0; offset < byteCharacters.length; offset += 512) {
|
||||
const slice = byteCharacters.slice(offset, offset + 512);
|
||||
|
||||
const byteNumbers = new Array(slice.length);
|
||||
for (let i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
|
||||
const blob = new Blob(byteArrays, {type: mimeType});
|
||||
|
||||
// Stwórz link do pobrania
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = fileName;
|
||||
|
||||
// Dodaj link do dokumentu i kliknij go
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
// Usuń link z dokumentu
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', 1);
|
||||
$db = $GLOBALS['db'];
|
||||
if ($_GET['ajax']) {
|
||||
//error_reporting(E_ALL);
|
||||
//ini_set('display_errors', 1);
|
||||
$db = $GLOBALS['db'];
|
||||
if ($_GET['ajax']) {
|
||||
switch ($_GET['ajax']) {
|
||||
case 'addAddress':
|
||||
$productId = $_GET['productId'];
|
||||
@@ -11,21 +11,21 @@
|
||||
// check if product exists
|
||||
$productId = $db->fetchByAssoc($db->query("SELECT id FROM ecmproducts WHERE id = '$productId'"))['id'];
|
||||
if ($productId == null) {
|
||||
echo json_encode(array('status' => 'Error', 'msg' => 'Nie znalaziono produktu w bazie: '.$index ));
|
||||
echo json_encode(array('status' => 'Error', 'msg' => 'Nie znalaziono produktu w bazie: ' . $index));
|
||||
}
|
||||
// check if location is empty
|
||||
$location = $db->fetchByAssoc($db->query("SELECT stock_address FROM ecmproducts_stock_addresses WHERE stock_address = '$address'"));
|
||||
if ($location != null) {
|
||||
echo json_encode(array('status' => 'Error', 'msg' => 'Wskazana lokalizacja jest zajęta: '.$address ));
|
||||
echo json_encode(array('status' => 'Error', 'msg' => 'Wskazana lokalizacja jest zajęta: ' . $address));
|
||||
return;
|
||||
}
|
||||
$db->query("INSERT INTO ecmproducts_stock_addresses (ecmproduct_id, stock_address, is_not_full) VALUES ('$productId','$address', $isNotFull)");
|
||||
echo json_encode(array('status' => 'Success', 'msg' => 'addAddress' ));
|
||||
echo json_encode(array('status' => 'Success', 'msg' => 'addAddress'));
|
||||
break;
|
||||
case 'removeAddress':
|
||||
$address = $_GET['address'];
|
||||
$db->query("DELETE FROM ecmproducts_stock_addresses WHERE stock_address='$address'");
|
||||
echo json_encode(array('status' => 'Success', 'msg' => 'removeAddress' ));
|
||||
echo json_encode(array('status' => 'Success', 'msg' => 'removeAddress'));
|
||||
break;
|
||||
case 'setIsNotFull':
|
||||
$address = $_GET['address'];
|
||||
@@ -33,39 +33,40 @@
|
||||
$db->query("UPDATE ecmproducts_stock_addresses SET is_not_full=$isNotFull WHERE stock_address='$address'");
|
||||
echo json_encode(array('status' => 'Success', 'msg' => 'setIsNotFull'));
|
||||
break;
|
||||
case 'export':
|
||||
exportExcel();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
$pRes = $db->query("SELECT DISTINCT id, code FROM ecmproducts WHERE deleted=0;");
|
||||
$codes = array();
|
||||
while ($p = $db -> fetchByAssoc($pRes)) {
|
||||
while ($p = $db->fetchByAssoc($pRes)) {
|
||||
$index = str_replace("'", "'", $p['code']);
|
||||
array_push($codes, ['id' => $p['id'], 'code' => $index]);
|
||||
}
|
||||
|
||||
$smarty = new Sugar_Smarty ();
|
||||
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'address')
|
||||
{
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'address') {
|
||||
$address = $_GET['address'];
|
||||
$product = $db->fetchByAssoc($db->query("
|
||||
SELECT a.ecmproduct_id, p.name, p.code, p.ems_qty_in_stock AS stock_state, a.is_not_full FROM ecmproducts_stock_addresses AS a
|
||||
INNER JOIN ecmproducts as p ON p.id=a.ecmproduct_id
|
||||
WHERE stock_address='$address';"));
|
||||
$state = $db->fetchByAssoc($db->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$product['ecmproduct_id']."'"));
|
||||
$state = $db->fetchByAssoc($db->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='" . $product['ecmproduct_id'] . "'"));
|
||||
$product['stock_state'] = $state['qty'];
|
||||
$smarty->assign("PROCESS", "ADDRESS");
|
||||
$smarty->assign("PRODUCT", $product);
|
||||
}
|
||||
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'index')
|
||||
{
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'index') {
|
||||
$id = $_GET['productId'];
|
||||
$res = $db->query("
|
||||
SELECT a.ecmproduct_id, a.stock_address, a.is_not_full, p.name, p.code FROM ecmproducts_stock_addresses AS a
|
||||
INNER JOIN ecmproducts as p ON p.id=a.ecmproduct_id
|
||||
WHERE p.id='$id' AND p.deleted=0;");
|
||||
$addresses = array();
|
||||
while ($r = $db -> fetchByAssoc($res)) {
|
||||
while ($r = $db->fetchByAssoc($res)) {
|
||||
array_push($addresses, $r);
|
||||
}
|
||||
$product = $db->fetchByAssoc($db->query("SELECT id, name, code, ems_qty_in_stock FROM ecmproducts WHERE id = '$id';"));
|
||||
@@ -76,8 +77,7 @@
|
||||
$smarty->assign("ADDRESSES", $addresses);
|
||||
}
|
||||
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'allAddresses')
|
||||
{
|
||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'allAddresses') {
|
||||
if ($_GET['onlyFull'] == "on") {
|
||||
$allAddresses = getAllAddresses(true);
|
||||
} else {
|
||||
@@ -87,12 +87,12 @@
|
||||
SELECT a.ecmproduct_id, a.stock_address, a.is_not_full, p.name, p.code, p.ems_qty_in_stock FROM ecmproducts_stock_addresses AS a
|
||||
INNER JOIN ecmproducts as p ON p.id=a.ecmproduct_id");
|
||||
$used = array();
|
||||
while ($r = $db -> fetchByAssoc($res)) {
|
||||
while ($r = $db->fetchByAssoc($res)) {
|
||||
array_push($used, $r);
|
||||
}
|
||||
$addresses = array();
|
||||
$sum = 0;
|
||||
foreach ($allAddresses as $a ) {
|
||||
foreach ($allAddresses as $a) {
|
||||
$i = array_search($a, array_column($used, 'stock_address'));
|
||||
$element = ($i !== false ? $used[$i] : null);
|
||||
$row = array();
|
||||
@@ -102,7 +102,7 @@
|
||||
$row['name'] = $element['name'];
|
||||
$row['code'] = $element['code'];
|
||||
$row['ecmproduct_id'] = $element['ecmproduct_id'];
|
||||
$state = $db->fetchByAssoc($db->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$element['ecmproduct_id']."'"));
|
||||
$state = $db->fetchByAssoc($db->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='" . $element['ecmproduct_id'] . "'"));
|
||||
$row['stock_state'] = $state['qty'];
|
||||
}
|
||||
if ($_GET['allType'] == 'used' && $element) {
|
||||
@@ -127,25 +127,60 @@
|
||||
$smarty->assign("CODES", json_encode($codes));
|
||||
$smarty->assign("CURRENT_ADDRESS", $_GET['address']);
|
||||
$smarty->assign("CURRENT_INDEX", $_GET['index']);
|
||||
echo $smarty->display ( 'modules/EcmProducts/tpls/stockAddress.tpl' );
|
||||
}
|
||||
echo $smarty->display('modules/EcmProducts/tpls/stockAddress.tpl');
|
||||
}
|
||||
|
||||
function getAllAddresses($onlyFull) {
|
||||
function getAllAddresses($onlyFull)
|
||||
{
|
||||
$addresses = array();
|
||||
for ($i = 1; $i <= 17; $i++) {
|
||||
$s1 = (strlen($i) == 1) ? '0'.$i : $i;
|
||||
$s1 = (strlen($i) == 1) ? '0' . $i : $i;
|
||||
for ($j = 1; $j <= 15; $j++) {
|
||||
$s2 = (strlen($j) == 1) ? '0'.$j : $j;
|
||||
for ($k = 1; $k <=3; $k++) {
|
||||
$s2 = (strlen($j) == 1) ? '0' . $j : $j;
|
||||
for ($k = 1; $k <= 3; $k++) {
|
||||
if ($onlyFull) {
|
||||
array_push($addresses, $s1.'.'.$s2.'.'.$k.'.0');
|
||||
array_push($addresses, $s1 . '.' . $s2 . '.' . $k . '.0');
|
||||
} else {
|
||||
for ($l = 0; $l <=2; $l++) {
|
||||
array_push($addresses, $s1.'.'.$s2.'.'.$k.'.'.$l);
|
||||
for ($l = 0; $l <= 2; $l++) {
|
||||
array_push($addresses, $s1 . '.' . $s2 . '.' . $k . '.' . $l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
function exportExcel()
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
$address = $_GET['address'];
|
||||
$res = $db->query("SELECT p.code, s.stock_address
|
||||
FROM ecmproducts_stock_addresses AS s
|
||||
INNER JOIN ecmproducts AS p
|
||||
ON p.id = s.ecmproduct_id
|
||||
ORDER BY s.stock_address;");
|
||||
$result = array();
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
array_push($result, $row);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Indeks', 'Adres'
|
||||
];
|
||||
|
||||
$sheetData = array_merge([$headers], $result);
|
||||
|
||||
require_once 'modules/EcmReports/BimIT-Reports/lib/xlsxGenerator.php';
|
||||
|
||||
$xlsx = Shuchkin\SimpleXLSXGen::fromArray($sheetData);
|
||||
$xlsx_content = (string)$xlsx;
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'fileContent' => base64_encode($xlsx_content),
|
||||
'fileName' => 'adresy_magazynowe.xlsx'
|
||||
]);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="loader" id="loader">
|
||||
<img src="themes/default/images/loading.gif" />
|
||||
<img src="themes/default/images/loading.gif"/>
|
||||
</div>
|
||||
<script>
|
||||
var CODES = {$CODES};
|
||||
@@ -17,10 +17,10 @@
|
||||
<input type="text" name="address" id="address" size="30" value="{$CURRENT_ADDRESS}">
|
||||
</td>
|
||||
<td>
|
||||
<input type="hidden" name="module" value="EcmProducts" />
|
||||
<input type="hidden" name="action" value="stockAddress" />
|
||||
<input type="hidden" name="searchType" value="address" />
|
||||
<input type="button" id="searchByAddressTrigger" value="Szukaj adresu " class="button" />
|
||||
<input type="hidden" name="module" value="EcmProducts"/>
|
||||
<input type="hidden" name="action" value="stockAddress"/>
|
||||
<input type="hidden" name="searchType" value="address"/>
|
||||
<input type="button" id="searchByAddressTrigger" value="Szukaj adresu " class="button"/>
|
||||
<span style="color: red;" id="addressError"></span>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -34,11 +34,11 @@
|
||||
<input type='text' name="index" id="index" size="30" value="{$CURRENT_INDEX}">
|
||||
</td>
|
||||
<td>
|
||||
<input type="hidden" name="module" value="EcmProducts" />
|
||||
<input type="hidden" name="action" value="stockAddress" />
|
||||
<input type="hidden" name="searchType" value="index" />
|
||||
<input type="hidden" name="productId" id="productId" value="" />
|
||||
<input type="button" id="searchByIndexTrigger" value="Szukaj indeksu" class="button" />
|
||||
<input type="hidden" name="module" value="EcmProducts"/>
|
||||
<input type="hidden" name="action" value="stockAddress"/>
|
||||
<input type="hidden" name="searchType" value="index"/>
|
||||
<input type="hidden" name="productId" id="productId" value=""/>
|
||||
<input type="button" id="searchByIndexTrigger" value="Szukaj indeksu" class="button"/>
|
||||
<span style="color: red;" id="indexError"></span>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -57,13 +57,23 @@
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input type="hidden" name="module" value="EcmProducts" />
|
||||
<input type="hidden" name="action" value="stockAddress" />
|
||||
<input type="hidden" name="searchType" value="allAddresses" />
|
||||
<input type="submit" id="searchByIndexTrigger" value="Pokaż adresy" class="button" />
|
||||
<input type="hidden" name="module" value="EcmProducts"/>
|
||||
<input type="hidden" name="action" value="stockAddress"/>
|
||||
<input type="hidden" name="searchType" value="allAddresses"/>
|
||||
<input type="submit" id="searchByIndexTrigger" value="Pokaż adresy" class="button"/>
|
||||
</td>
|
||||
</tr>
|
||||
</form>
|
||||
<tr>
|
||||
<td scope="row" nowrap="nowrap" width="1%">
|
||||
<input type="hidden" name="module" value="EcmProducts"/>
|
||||
<input type="hidden" name="action" value="stockAddress"/>
|
||||
<input type="hidden" name="searchType" value="export"/>
|
||||
<input type="button" id="exportTrigger" value="Eksport Excel" class="button"/>
|
||||
</td>
|
||||
<td nowrap="nowrap" width="1%"> </td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{if $PROCESS && $PROCESS=='ADDRESS'}
|
||||
@@ -92,10 +102,11 @@
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="button" value="Karta produktu" class="button"
|
||||
onclick="openProductCard('{$PRODUCT.ecmproduct_id}');" />
|
||||
onclick="openProductCard('{$PRODUCT.ecmproduct_id}');"/>
|
||||
<input type="button" value="Wyszukaj wszystkie adresy" class="button"
|
||||
onclick="searchByIndex('{$PRODUCT.code}')" />
|
||||
<input type="button" value="Usuń produkt z adresu" class="button" onclick="removeProductFromAddress()" />
|
||||
onclick="searchByIndex('{$PRODUCT.code}')"/>
|
||||
<input type="button" value="Usuń produkt z adresu" class="button"
|
||||
onclick="removeProductFromAddress()"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -118,7 +129,7 @@
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="button" value="Dodaj produkt" class="button" onclick="addProductToAddress()" />
|
||||
<input type="button" value="Dodaj produkt" class="button" onclick="addProductToAddress()"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -126,7 +137,10 @@
|
||||
{/if}
|
||||
{if $PROCESS && $PROCESS=='PRODUCT'}
|
||||
<h2>{$PRODUCT.code} {$PRODUCT.name} ( Stan: {$PRODUCT.ems_qty_in_stock} ) <input type="button"
|
||||
value="Karta produktu" class="button" onclick="openProductCard('{$PRODUCT.id}');" /></h2>
|
||||
value="Karta produktu"
|
||||
class="button"
|
||||
onclick="openProductCard('{$PRODUCT.id}');"/>
|
||||
</h2>
|
||||
<table cellpadding="0" cellspacing="0" class="list view">
|
||||
<tr class="oddListRowS1">
|
||||
<th style="width: 15%;"><b>Adres</b></td>
|
||||
@@ -142,28 +156,28 @@
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="checkbox" {if $item.is_not_full}checked{/if}
|
||||
onclick="setAddressIsNotFull('{$item.stock_address}', this)" />
|
||||
onclick="setAddressIsNotFull('{$item.stock_address}', this)"/>
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="button" value="Usuń lokalizację" class="button"
|
||||
onclick="removeAddressFromProduct('{$item.stock_address}')" />
|
||||
onclick="removeAddressFromProduct('{$item.stock_address}')"/>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
<tr class="oddListRowS1">
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="text" size="10" id="newAddress" />
|
||||
<input type="text" size="10" id="newAddress"/>
|
||||
<span style="color: red;" id="newAddressError"></span>
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="checkbox" id="isNotFull" />
|
||||
<input type="checkbox" id="isNotFull"/>
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="button" value="Dodaj lokalizację" class="button" onclick="addAddressToProduct();" />
|
||||
<input type="button" value="Dodaj lokalizację" class="button" onclick="addAddressToProduct();"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -186,11 +200,11 @@
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="checkbox" {if $item.is_not_full}checked{/if} disabled />
|
||||
<input type="checkbox" {if $item.is_not_full}checked{/if} disabled/>
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
<input type="button" value="Pokaż adres" class="button" name="showAddress-{$item.stock_address}" />
|
||||
<input type="button" value="Pokaż adres" class="button" name="showAddress-{$item.stock_address}"/>
|
||||
</td>
|
||||
<td valign="top" class="oddListRowS1"
|
||||
style="padding:5px !important;border-bottom:1px solid #cccccc;vertical-align:top;">
|
||||
@@ -236,7 +250,8 @@
|
||||
background-color: rgba(16, 16, 16, 0.5);
|
||||
}
|
||||
|
||||
.loader>img {}
|
||||
.loader > img {
|
||||
}
|
||||
|
||||
{/literal}
|
||||
</style>
|
||||
Reference in New Issue
Block a user