export stock addresses
This commit is contained in:
@@ -134,6 +134,23 @@ function isProductValid(id) {
|
|||||||
return false;
|
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 () {
|
$(document).ready(function () {
|
||||||
$("#address").mask("AB.CD.E.F", {
|
$("#address").mask("AB.CD.E.F", {
|
||||||
placeholder: "__.__._._",
|
placeholder: "__.__._._",
|
||||||
@@ -189,12 +206,49 @@ $(document).ready(function () {
|
|||||||
$("#searchByIndexForm").submit();
|
$("#searchByIndexForm").submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$("#exportTrigger").click(() => {
|
||||||
|
exportFile();
|
||||||
|
});
|
||||||
$('[name^="showAddress').click((event) => {
|
$('[name^="showAddress').click((event) => {
|
||||||
$("#address").val(event.target.name.split('-')[1]);
|
$("#address").val(event.target.name.split('-')[1]);
|
||||||
if (isAddressValid()) {
|
if (isAddressValid()) {
|
||||||
$("#searchByAddressForm").submit();
|
$("#searchByAddressForm").submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
//bind buttons
|
//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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,6 +33,9 @@
|
|||||||
$db->query("UPDATE ecmproducts_stock_addresses SET is_not_full=$isNotFull WHERE stock_address='$address'");
|
$db->query("UPDATE ecmproducts_stock_addresses SET is_not_full=$isNotFull WHERE stock_address='$address'");
|
||||||
echo json_encode(array('status' => 'Success', 'msg' => 'setIsNotFull'));
|
echo json_encode(array('status' => 'Success', 'msg' => 'setIsNotFull'));
|
||||||
break;
|
break;
|
||||||
|
case 'export':
|
||||||
|
exportExcel();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$pRes = $db->query("SELECT DISTINCT id, code FROM ecmproducts WHERE deleted=0;");
|
$pRes = $db->query("SELECT DISTINCT id, code FROM ecmproducts WHERE deleted=0;");
|
||||||
@@ -44,8 +47,7 @@
|
|||||||
|
|
||||||
$smarty = new Sugar_Smarty ();
|
$smarty = new Sugar_Smarty ();
|
||||||
|
|
||||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'address')
|
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'address') {
|
||||||
{
|
|
||||||
$address = $_GET['address'];
|
$address = $_GET['address'];
|
||||||
$product = $db->fetchByAssoc($db->query("
|
$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
|
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
|
||||||
@@ -57,8 +59,7 @@
|
|||||||
$smarty->assign("PRODUCT", $product);
|
$smarty->assign("PRODUCT", $product);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'index')
|
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'index') {
|
||||||
{
|
|
||||||
$id = $_GET['productId'];
|
$id = $_GET['productId'];
|
||||||
$res = $db->query("
|
$res = $db->query("
|
||||||
SELECT a.ecmproduct_id, a.stock_address, a.is_not_full, p.name, p.code FROM ecmproducts_stock_addresses AS a
|
SELECT a.ecmproduct_id, a.stock_address, a.is_not_full, p.name, p.code FROM ecmproducts_stock_addresses AS a
|
||||||
@@ -76,8 +77,7 @@
|
|||||||
$smarty->assign("ADDRESSES", $addresses);
|
$smarty->assign("ADDRESSES", $addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'allAddresses')
|
if (strlen($_GET['searchType']) > 0 && $_GET['searchType'] == 'allAddresses') {
|
||||||
{
|
|
||||||
if ($_GET['onlyFull'] == "on") {
|
if ($_GET['onlyFull'] == "on") {
|
||||||
$allAddresses = getAllAddresses(true);
|
$allAddresses = getAllAddresses(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -130,7 +130,8 @@
|
|||||||
echo $smarty->display('modules/EcmProducts/tpls/stockAddress.tpl');
|
echo $smarty->display('modules/EcmProducts/tpls/stockAddress.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllAddresses($onlyFull) {
|
function getAllAddresses($onlyFull)
|
||||||
|
{
|
||||||
$addresses = array();
|
$addresses = array();
|
||||||
for ($i = 1; $i <= 17; $i++) {
|
for ($i = 1; $i <= 17; $i++) {
|
||||||
$s1 = (strlen($i) == 1) ? '0' . $i : $i;
|
$s1 = (strlen($i) == 1) ? '0' . $i : $i;
|
||||||
@@ -149,3 +150,37 @@
|
|||||||
}
|
}
|
||||||
return $addresses;
|
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'
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -64,6 +64,16 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</form>
|
</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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{if $PROCESS && $PROCESS=='ADDRESS'}
|
{if $PROCESS && $PROCESS=='ADDRESS'}
|
||||||
@@ -95,7 +105,8 @@
|
|||||||
onclick="openProductCard('{$PRODUCT.ecmproduct_id}');"/>
|
onclick="openProductCard('{$PRODUCT.ecmproduct_id}');"/>
|
||||||
<input type="button" value="Wyszukaj wszystkie adresy" class="button"
|
<input type="button" value="Wyszukaj wszystkie adresy" class="button"
|
||||||
onclick="searchByIndex('{$PRODUCT.code}')"/>
|
onclick="searchByIndex('{$PRODUCT.code}')"/>
|
||||||
<input type="button" value="Usuń produkt z adresu" class="button" onclick="removeProductFromAddress()" />
|
<input type="button" value="Usuń produkt z adresu" class="button"
|
||||||
|
onclick="removeProductFromAddress()"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -126,7 +137,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{if $PROCESS && $PROCESS=='PRODUCT'}
|
{if $PROCESS && $PROCESS=='PRODUCT'}
|
||||||
<h2>{$PRODUCT.code} {$PRODUCT.name} ( Stan: {$PRODUCT.ems_qty_in_stock} ) <input type="button"
|
<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">
|
<table cellpadding="0" cellspacing="0" class="list view">
|
||||||
<tr class="oddListRowS1">
|
<tr class="oddListRowS1">
|
||||||
<th style="width: 15%;"><b>Adres</b></td>
|
<th style="width: 15%;"><b>Adres</b></td>
|
||||||
@@ -236,7 +250,8 @@
|
|||||||
background-color: rgba(16, 16, 16, 0.5);
|
background-color: rgba(16, 16, 16, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.loader>img {}
|
.loader > img {
|
||||||
|
}
|
||||||
|
|
||||||
{/literal}
|
{/literal}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user