Commit old changes

This commit is contained in:
2024-12-03 09:55:11 +00:00
parent 6a37a77895
commit 87010acdcc
19 changed files with 3167 additions and 1320 deletions

View File

@@ -0,0 +1,190 @@
/*jshint esversion: 6 */
$(document).ready(function () {
$.tablesorter.addParser({
id: "production_date",
is: function () {
return false;
},
format: function (s, table, cell) {
return $(cell).find("input[id^=production-date]").val() || "1970-01-01";
},
parsed: false,
type: "text"
});
$("#allTable").tablesorter({
sortList: [[3, 1]],
theme: "blue",
widthFixed: true,
widgets: ["filter", "zebra", "stickyHeaders"],
fixedWidth: true,
widgetOptions: {
resizable: false,
filter_formatter: {
7: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
8: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
9: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
10: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
12: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
13: function (cell, index) {
return $.tablesorter.filterFormatter.select2(cell, index, {
match: true
});
},
},
filter_functions: {
3: function (e, f, i) {
return f.includes(i);
}
}
},
headers: {
3: { sorter: "production_date" },
},
});
$("#duplicateBtn").click(() => duplicatePositions());
$("#deleteBtn").click(() => { removePositions(); });
$("#excelBtn").click(() => { exportExcel(); });
$("#pdfBtn").click(() => { window.alert("In progress."); });
$("#productionBtn").click(() => { window.alert("In progress."); });
});
function editQty(id) {
$("#edit-" + id).css("display", "none");
$("#qty-" + id).css("display", "none");
$("#qtyInput-" + id).css("display", "inline");
$("#qtyInput-" + id).select();
$("#save-" + id).css("display", "inline-block");
}
function saveQty(id) {
showLoader("Trwa aktualizacja...");
$("#edit-" + id).css("display", "inline-block");
$("#qty-" + id).css("display", "inline");
$("#qtyInput-" + id).css("display", "none");
$("#save-" + id).css("display", "none");
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveQty&id=" + id + "&qty=" + $("#qtyInput-" + id).val(),
success: function () {
$("#qty-" + id).html($("#qtyInput-" + id).val());
hideLoader();
},
});
}
function duplicatePositions() {
var ids = [];
$("input.allCheck:checkbox:checked").each(function () {
ids.push($(this).val());
});
if (ids.length === 0) {
window.alert("Wybierz pozycje zamówień");
return;
}
var userResponse = window.confirm("Zduplikować pozycje?");
if (!userResponse) { return; }
showLoader("Duplikowanie...");
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=duplicatePositions&ids=" + ids.join("|"),
success: function () {
window.location.reload();
},
});
}
function removePositions() {
var ids = [];
$("input.allCheck:checkbox:checked").each(function () {
ids.push($(this).val());
});
if (ids.length === 0) {
window.alert("Wybierz pozycje zamówień");
return;
}
var userResponse = window.confirm("Usunąć pozycje?");
if (!userResponse) { return; }
showLoader("Usuwanie...");
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=removePositions&ids=" + ids.join("|"),
success: function ()
{
window.location.reload();
},
});
}
function saveProductionDate(id) {
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveProductionDate&id=" + id + "&date=" + $("#production-date-" + id).val(),
});
}
function editDescription(id) {
$("#edit-description-" + id).css("display", "none");
$("#description-" + id).css("display", "none");
$("#descriptionInput-" + id).css("display", "inline");
$("#descriptionInput-" + id).select();
$("#save-description-" + id).css("display", "inline-block");
}
function saveDescription(id) {
$("#edit-description-" + id).css("display", "inline-block");
$("#description-" + id).css("display", "inline");
$("#descriptionInput-" + id).css("display", "none");
$("#save-description-" + id).css("display", "none");
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveProductDescription&id=" + id + "&description=" + $("#descriptionInput-" + id).val(),
success: function (data) {
$("#description-" + id).html($("#descriptionInput-" + id).val());
},
});
}
function showLoader(msg = "Pobieranie danych") {
$.blockUI({
css: {
border: "none",
padding: "15px",
backgroundColor: "#000",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 0.5,
"font-weight": "bold",
"font-size": "16px",
color: "#fff",
},
message: msg
});
}
function hideLoader() {
$.unblockUI();
}
function exportExcel() {
showLoader("Generowanie pliku...");
$.ajax({
method: "get",
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportExcel",
success: function (data)
{
window.console.log(data);
},
});
}

View File

@@ -0,0 +1,172 @@
<?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;
if (!isset($_GET['ajaxAction'])) {
if (isset($_GET['date_from'])) {
$dateFrom = date("Y-m-d", strtotime($_GET['date_from']));
} else {
$dateFrom = date("Y-m-d");
}
if (isset($_GET['date_to'])) {
$dateTo = date("Y-m-d", strtotime($_GET['date_to']));
} else {
$dateTo = date("Y-m-d", strtotime("+ 1 month"));
}
$query = "SELECT s.id, s.document_no, s.status, s.parent_name, s.parent_id, s.send_date, s.type,
p.code, p.name, ps.ecmproduct_id, ps.description,
si.quantity, p.vendor_part_no as kind, p.brand, p.part_no as size, p.shape,
ss.quantity as stockState, si.id as item_id, s.shipping_address_name, ps.production_date,
ps.quantity as scheduledQuantity, ps.id as id
FROM productionScheduler AS ps
LEFT JOIN ecmsaleitems AS si
ON ps.ecmsaleitem_id = si.id
LEFT JOIN ecmsales AS s
ON ps.ecmsale_id = s.id
INNER JOIN ecmproducts AS p
ON ps.ecmproduct_id = p.id
LEFT JOIN ecmstockstates AS ss
ON ss.product_id = ps.ecmproduct_id AND ss.stock_id = 'c7afd71a-4c3a-bde4-138d-4acaee1644e4'
WHERE ps.deleted = 0 AND ps.production_date >= '$dateFrom' AND ps.production_date <= '$dateTo'
ORDER BY s.delivery_date, s.register_date, s.document_no";
$rows = $db->query($query);
$data = array();
$i = 0;
while ($r = $db->fetchByAssoc($rows)) {
$row = array();
$i++;
$row['position'] = $i;
$row['id'] = $r['id'];
$row['productName'] = strlen($r['name']) > 55 ? substr($r['name'], 0, 55) . "..." : $r['name'];
$row['productFullName'] = $r['name'];
$row['productCode'] = strlen($r['code']) > 20 ? substr($r['code'], 0, 20) . "..." : $r['code'];
$row['productFullCode'] = $r['code'];
$row['productId'] = $r['ecmproduct_id'];
$row['productQty'] = $r['quantity'];
$row['qty'] = $r['scheduledQuantity'];
$row['productKind'] = $r['kind'];
$row['productSize'] = $r['size'];
$row['productShape'] = $app_list_strings['ecmproducts_shape_dom'][$r['shape']];
$row['productBrand'] = $app_list_strings['ecmproducts_brand_dom'][$r['brand']];
$row['orderNo'] = $r['document_no'];
$row['orderId'] = $r['id'];
$row['orderStatus'] = $app_list_strings['ecmsales_status_dom'][$r['status']];
$row['orderType'] = $app_list_strings['ecmsales_type_dom'][$r['type']];
$row['orderParent'] = $r['parent_name'];
$row['orderParentId'] = $r['parent_id'];
$row['orderSendDate'] = $r['send_date'];
$row['orderItemId'] = $r['item_id'];
$row['description'] = strlen($r['description']) > 0 ? substr($r['description'], 0, 30) : '';
$row['fullDescription'] = $r['description'];
$row['shippingTo'] = ($r['shipping_address_name'] == 'Adres korespondencyjny' ? '' : $r['shipping_address_name']);
$row['productionDate'] = $r['production_date'] == '0000-00-00' ? '' : $r['production_date'];
$row['productStockState'] = $r['stockState'] | 0;
$data[] = $row;
}
$smarty = new Sugar_Smarty();
$smarty->assign("data", $data);
$smarty->assign("dateFrom", $GLOBALS['timedate']->to_display_date($dateFrom));
$smarty->assign("dateTo", $GLOBALS['timedate']->to_display_date($dateTo));
echo $smarty->display('modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.tpl');
} else {
switch ($_GET['ajaxAction']) {
case 'saveQty':
saveQty($_GET['id'], $_GET['qty']);
break;
case 'duplicatePositions':
duplicatePositions($_GET['ids']);
break;
case 'removePositions':
removePositions($_GET['ids']);
break;
case 'saveProductionDate':
saveProductionDate($_GET['id'], $_GET['date']);
break;
case 'saveProductDescription':
saveProductDescription($_GET['id'], $_GET['description']);
break;
case 'exportExcel':
exportExcel();
break;
}
}
function saveQty($id, $qty)
{
$db = $GLOBALS['db'];
$query = sprintf("UPDATE productionScheduler SET quantity='%d' WHERE id='%s'", $qty, $id);
$db->query($query);
}
function duplicatePositions($ids)
{
$db = $GLOBALS['db'];
global $current_user;
$ids = explode("|", $ids);
foreach ($ids as $id) {
$res = $db->fetchByAssoc($db->query("SELECT * FROM productionScheduler WHERE id ='$id'"));
$query = sprintf("INSERT INTO productionScheduler VALUES ('%s', '%s', '%s', '%d', NOW(), NOW(), '%s', '%s', 0, '%s', '%d', '%s', '%s');",
generateUuidV4(), $res['ecmsaleitem_id'], $res['ecmsale_id'], $res['quantity'], $current_user->id, $current_user->id, $res['ecmproduct_id'],
$res['is_component'], $res['production_date'], $res['description']);
$db->query($query);
}
}
function removePositions($ids)
{
$db = $GLOBALS['db'];
global $current_user;
$ids = explode("|", $ids);
$query = sprintf("UPDATE productionScheduler SET deleted=1, modified_user_id='%s', date_modified=NOW() WHERE id IN ('%s')",
$current_user->id, join("','", $ids));
$db->query($query);
}
function saveProductionDate($id, $date)
{
$db = $GLOBALS['db'];
$date = date("Y-m-d", strtotime($date));
if ($date == '1970-01-01') {
$db->query("UPDATE productionScheduler SET production_date=NULL WHERE id='$id'");
} else {
$db->query("UPDATE productionScheduler SET production_date='$date' WHERE id='$id'");
}
}
function saveProductDescription($id, $description)
{
$db = $GLOBALS['db'];
$description = mysql_escape_string($description);
$db->query("UPDATE productionScheduler SET description='$description' WHERE id='$id'");
echo "UPDATE productionScheduler SET description='$description' WHERE id='$id'";
}
function exportExcel() {
echo 'bhhh';
require_once 'modules/EcmReports/BimIT-Reports/lib/xlsxGenerator.php';
echo 'qqqqqq';
$books = [
['ISBN', 'title', 'author', 'publisher', 'ctry' ],
[618260307, 'The Hobbit', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA'],
[908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ']
];
echo 'a';
$xlsx = Shuchkin\SimpleXLSXGen::fromArray( $books );
echo json_encode($xlsx);
$xlsx->saveAs('books.xlsx');
echo 'done';
}
function generateUuidV4()
{
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

View File

@@ -0,0 +1,202 @@
<script type="text/javascript" src="modules/EcmReports/javascript/jquery.js"></script>
<link rel="stylesheet" href="modules/EcmReports/BimIT-Reports/lib/tablesorter-2.31.3/dist/css/theme.blue.min.css">
<script type="text/javascript"
src="modules/EcmReports/BimIT-Reports/lib/tablesorter-2.31.3/dist/js/jquery.tablesorter.js"></script>
<script type="text/javascript"
src="modules/EcmReports/BimIT-Reports/lib/tablesorter-2.31.3/dist/js/jquery.tablesorter.widgets.js">
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.min.js"></script>
<script type="text/javascript"
src="modules/EcmReports/BimIT-Reports/lib/tablesorter-2.31.3/dist/js/widgets/widget-filter-formatter-select2.min.js">
</script>
<script type="text/javascript" src="modules/EcmReports/javascript/jquery.blockUI.js"></script>
<script type="text/javascript" src="modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js"></script>
<!-- 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>Harmonogram Produkcji</h2>
</td>
</tr>
</table>
<br>
<!-- SEARCH -->
<form action="index.php" method="get" name="searchProductBySales">
<input type="hidden" name="module" value="EcmReports"/>
<input type="hidden" name="action" value="index"/>
<input type="hidden" name="reportName" value="productionSchedule"/>
<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td class="dataLabel" width="5%" nowrap="nowrap">
Data produkcji: od
&nbsp;
<input id="date_from" name="date_from" type="text" maxlength="10" size="11" tabindex="" title=""
value="{$dateFrom}" 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>
&nbsp;
do
&nbsp;
<input autocomplete="off" name="date_to" id="date_to" value="{$dateTo}" title="" tabindex="" size="11"
maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_to_trigger">
<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>
&nbsp;&nbsp;<input class="button" id="submitForm" name="submit" value="Filtruj" type="submit">
</td>
</tr>
</table>
</form>
<input class="button" id="duplicateBtn" value="Duplikuj" type="button">
<input class="button" id="deleteBtn" value="Usuń" type="button">&nbsp;&nbsp;&nbsp;
<input class="button" id="excelBtn" value="Excel" type="button">
<input class="button" id="pdfBtn" value="PDF" type="button">
<input class="button" id="productionBtn" value="RW/PW" type="button">
<div id="1">
<table id="allTable">
<thead>
<tr>
<th>&nbsp;</th>
<th>Indeks</th>
<th>Nazwa</th>
<th>Data produkcji</th>
<th>Ilość</th>
<th>Ilość ZS</th>
<th>Stan</th>
<th>ZS E5</th>
<th>Typ</th>
<th>Status</th>
<th>Zamawiający</th>
<th>Odbiorca</th>
<th>Forma</th>
<th>Marka</th>
<th>Data wysyłki</th>
<th>Uwagi</th>
</tr>
</thead>
<tbody aria-live="polite" aria-relevant="all">
{foreach from=$data item=ROW name=loop}
<tr>
<td>
<input type="checkbox" value="{$ROW.id}" class="allCheck"/>
<!--
<img src="modules/EcmQuotes/images/add_position.gif" style="margin-top: 3px; margin-right: 3px; cursor: pointer" width="12" alt="Duplikuj" onclick="duplicatePosition('{$ROW.id}')">
<img src="modules/EcmQuotes/images/deleterow.gif" style="margin-top: 3px; margin-right: 3px; cursor: pointer" width="12" alt="Usuń" onclick="removePosition('{$ROW.id}')">
-->
</td>
<td>
<a title="{$ROW.productFullCode}" target="_blank"
href="index.php?module=EcmProducts&action=DetailView&record={$ROW.productId}">
{$ROW.productCode}
</a>
</td>
<td title="{$ROW.productFullName}">
{$ROW.productName}
</td>
<td>
<input id="production-date-{$ROW.id}" name="production-date-{$ROW.id}" type="text"
maxlength="10" size="11" tabindex="" title="" value="{$ROW.productionDate}" autocomplete="off"
id="production-date-{$ROW.id}" onchange="saveProductionDate('{$ROW.id}')">
<img id="production-date-trigger-{$ROW.id}" src="themes/default/images/jscalendar.gif"
style="width: 13px;">
<script language="JavaScript" type="text/javascript">
Calendar.setup({ldelim}
inputField: "production-date-{$ROW.id}",
daFormat: "%Y-%m-%d",
button: "production-date-trigger-{$ROW.id}",
singleClick: true,
dateStr: "",
step: 1
{rdelim}
);
</script>
</td>
<td style="white-space: nowrap;">
<div id="edit-{$ROW.id}" class="ui-icon ui-icon-pencil"
onclick="editQty('{$ROW.id}')" style="display: inline-block;"></div>
<div id="save-{$ROW.id}" class="ui-icon ui-icon-check"
onclick="saveQty('{$ROW.id}')" style="display: none;"></div>
<div id="qty-{$ROW.id}" style="display: inline; width: 300px;">{$ROW.qty}
</div>
<input id="qtyInput-{$ROW.id}" value="{$ROW.qty}" style="width: 50px; display: none;" type="number"/>
</td>
<td>
{$ROW.productQty}
</td>
<td>
{$ROW.productStockState}
</td>
<td>
<a target="_blank" href="index.php?module=EcmSales&action=DetailView&record={$ROW.orderId}">
{$ROW.orderNo}
</a>
</td>
<td>
{$ROW.orderType}
</td>
<td>
{$ROW.orderStatus}
</td>
<td>
<a target="_blank" href="index.php?module=Accounts&action=DetailView&record={$ROW.orderParentId}">
{$ROW.orderParent}
</a>
</td>
<td>
{$ROW.shippingTo}
</td>
<td>
{$ROW.productShape}
</td>
<td>
{$ROW.productBrand}
</td>
<td>
{$ROW.orderSendDate}
</td>
<td>
<div id="edit-description-{$ROW.id}" class="ui-icon ui-icon-pencil"
onclick="editDescription('{$ROW.id}')" style="display: inline-block;"></div>
<div id="save-description-{$ROW.id}" class="ui-icon ui-icon-check"
onclick="saveDescription('{$ROW.id}')" style="display: none;"></div>
<div id="description-{$ROW.id}" style="display: inline; width: 300px;">{$ROW.description}
</div>
<textarea id="descriptionInput-{$ROW.id}"
style="display: none;">{$ROW.fullDescription}</textarea>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>