update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
var SelectedTab = "";
|
||||
var TabsMainBlock = false;
|
||||
var Components;
|
||||
$(document).ready(function () {
|
||||
$.tablesorter.addParser({
|
||||
id: "production_date",
|
||||
@@ -85,14 +86,134 @@ $(document).ready(function () {
|
||||
} catch (e) { }
|
||||
}
|
||||
}, 500);
|
||||
$("#selectAll").click(function () {
|
||||
if (this.checked) {
|
||||
$(".allCheck").prop("checked", true);
|
||||
} else {
|
||||
$(".allCheck").prop("checked", false);
|
||||
}
|
||||
});
|
||||
$("#duplicateBtn").click(() => duplicatePositions());
|
||||
$("#deleteBtn").click(() => { removePositions(); });
|
||||
$("#excelBtn").click(() => { exportExcel(); });
|
||||
$("#pdfBtn").click(() => { window.alert("In progress."); });
|
||||
$("#productionBtn").click(() => { window.alert("In progress."); });
|
||||
$("#createInsideOrder").click(createInsideOrder);
|
||||
});
|
||||
|
||||
});
|
||||
function SetTab(tab_name) {
|
||||
if (TabsMainBlock) { return; }
|
||||
var TabMenu = document.getElementById("groupTabsPanels");
|
||||
var tabs = TabMenu.getElementsByTagName("li");
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
if ((tab_name + "_menu") === tabs[i].id) {
|
||||
tabs[i].className = "active";
|
||||
tabs[i].getElementsByTagName("a")[0].className = "current";
|
||||
} else {
|
||||
tabs[i].className = "";
|
||||
tabs[i].getElementsByTagName("a")[0].className = "";
|
||||
}
|
||||
}
|
||||
var prev = document.getElementById(SelectedTab);
|
||||
var curr = document.getElementById(tab_name);
|
||||
prev.style.display = "none";
|
||||
curr.style.display = "";
|
||||
SelectedTab = tab_name;
|
||||
if (SelectedTab === "3") {
|
||||
|
||||
}
|
||||
if (SelectedTab === "2") {
|
||||
getRawMaterials();
|
||||
}
|
||||
if (SelectedTab === "1") {
|
||||
}
|
||||
}
|
||||
function getRawMaterials() {
|
||||
var ids = [];
|
||||
$("input.allCheck:checkbox:checked").each(function () {
|
||||
// check if this element is visible on site
|
||||
if ($(this).parent().parent().css("display") === "table-row") {
|
||||
ids.push($(this).val());
|
||||
}
|
||||
});
|
||||
if (ids.length === 0) {
|
||||
window.alert("Wybierz pozycje zamówień");
|
||||
SetTab("1");
|
||||
return;
|
||||
}
|
||||
showLoader();
|
||||
var url = $(location).attr("href") + "&to_pdf=1&ajaxAction=getRawMaterials";
|
||||
$.ajax({
|
||||
method: "post",
|
||||
url: url,
|
||||
data: {
|
||||
ids
|
||||
},
|
||||
success: function (data) {
|
||||
var result = JSON.parse(data);
|
||||
Components = result;
|
||||
drawRawMaterials(result);
|
||||
//drawComponents(result);
|
||||
//updateComponentsPositions();
|
||||
hideLoader();
|
||||
},
|
||||
error: function () {
|
||||
window.alert("Błąd ładowania surowców");
|
||||
hideLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
function drawRawMaterials(data) {
|
||||
$("#rawMaterialsTableContainer").html(rawMaterialsTablePrototype());
|
||||
data.forEach((el, index) => {
|
||||
var tr = $("<tr></tr>");
|
||||
tr.append("<td><input type=\"checkbox\" value=" + el.id + " class=\"rawMaterialCheck\" /></td>");
|
||||
tr.append("<td>" + (index + 1) + "</td>");
|
||||
tr.append("<td><a target=\"_blank\" href=\"index.php?module=EcmProducts&action=DetailView&record=" + el.id + "\">" + el.code + "</a></td>");
|
||||
tr.append("<td title=\""+ el.fullName +"\">" + el.name + "</td>");
|
||||
tr.append("<td id=\"qty-" + el.id + "\">" + el.quantity + "</td>");
|
||||
tr.append("<td>" + el.unit + "</td>");
|
||||
tr.append("<td id=\"state-" + el.id + "\">" + el.stockState + "</td>");
|
||||
tr.append("<td id=\"ordered-" + el.id + "\">" + el.stockAddress + "</td>");
|
||||
$("#rawMaterialsTable > tbody").append(tr);
|
||||
});
|
||||
|
||||
$("#rawMaterialsTable").tablesorter({
|
||||
theme: "blue",
|
||||
widthFixed: true,
|
||||
widgets: ["filter", "stickyHeaders"],
|
||||
sortList: [[2, 0]],
|
||||
});
|
||||
$("#rawMaterialsTable").bind("filterEnd", function (event, config) {
|
||||
updateRawMaterialsPositions();
|
||||
});
|
||||
$("#rawMaterialsTable").bind("sortEnd", function (event, config) {
|
||||
updateRawMaterialsPositions();
|
||||
$("#rawMaterialsTable tfoot").find("td").each(function () {
|
||||
$(this).css("background-color", "white");
|
||||
});
|
||||
});
|
||||
$("#selectAllRawMaterials").attr('checked', false);
|
||||
$("#selectAllRawMaterials").click(function () {
|
||||
if (this.checked) {
|
||||
$(".rawMaterialCheck").prop('checked', true);
|
||||
} else {
|
||||
$(".rawMaterialCheck").prop('checked', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
function rawMaterialsTablePrototype() {
|
||||
return '<table id="rawMaterialsTable"><thead><tr><th class="filter-false"><input type="checkbox" id="selectAllRawMaterials" /></th><th>Pozycja</th><th>Indeks</th><th>Nazwa</th><th>Ilość</th><th>JM.</th><th>Stan</th><th>Adres magazynowy</th></tr></thead><tbody aria-live="polite" aria-relevant="all"></tbody></table>';
|
||||
}
|
||||
function updateRawMaterialsPositions() {
|
||||
var i = 0;
|
||||
$("#rawMaterialsTable").find("tr").each(function (index) {
|
||||
if (index >= 2 && $(this).css('display') === 'table-row' && $(this).find("td").length > 3) {
|
||||
i++;
|
||||
$($(this).find("td")[1]).html(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
function editQty(id) {
|
||||
$("#edit-" + id).css("display", "none");
|
||||
$("#qty-" + id).css("display", "none");
|
||||
@@ -212,7 +333,6 @@ function exportExcel() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function createInsideOrder() {
|
||||
var ids = [];
|
||||
$('input.allCheck:checkbox:checked').each(function () {
|
||||
|
||||
@@ -103,16 +103,88 @@ if (!isset($_GET['ajaxAction'])) {
|
||||
case 'exportExcel':
|
||||
exportExcel();
|
||||
break;
|
||||
case 'getRawMaterials':
|
||||
getRawMaterials($_POST['ids']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
function getRawMaterials($ids) {
|
||||
$response = array();
|
||||
$idsString = join("','", $ids);
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->query("SELECT ecmproduct_id, SUM(quantity) AS quantity FROM productionScheduler WHERE id IN ('$idsString') GROUP BY ecmproduct_id");
|
||||
$rawMaterials = array();
|
||||
while ($p = $db->fetchByAssoc($res)) {
|
||||
$rawMaterials = array_merge($rawMaterials, getProductRawMaterials($p['ecmproduct_id'], $p['quantity']));
|
||||
}
|
||||
|
||||
$groupedRawMaterials = [];
|
||||
foreach ($rawMaterials as $item) {
|
||||
$productId = $item['ecmproduct_id'];
|
||||
if (!isset($groupedRawMaterials[$productId])) {
|
||||
$groupedRawMaterials[$productId] = 0;
|
||||
}
|
||||
$groupedRawMaterials[$productId] += $item['quantity'];
|
||||
}
|
||||
|
||||
$rawMaterials = [];
|
||||
foreach ($groupedRawMaterials as $productId => $quantity) {
|
||||
$rawMaterials[] = ['ecmproduct_id' => $productId, 'quantity' => $quantity];
|
||||
}
|
||||
|
||||
global $app_list_strings;
|
||||
foreach ($rawMaterials as $raw) {
|
||||
$product = $db->fetchByAssoc($db->query("
|
||||
SELECT p.id, p.code, p.name, p.group_ks, p.unit_id, ss.quantity as stockState,
|
||||
GROUP_CONCAT(s.stock_address SEPARATOR ', ') AS stock_addresses
|
||||
FROM ecmproducts AS p
|
||||
LEFT JOIN ecmstockstates AS ss
|
||||
ON ss.product_id = p.id AND ss.stock_id = '368479db-22c5-0220-3a14-4bc426b1c709'
|
||||
LEFT JOIN ecmproducts_stock_addresses s ON p.id = s.ecmproduct_id
|
||||
WHERE p.id='" . $raw['ecmproduct_id'] . "'
|
||||
GROUP BY p.id
|
||||
"));
|
||||
$result['id'] = $product['id'];
|
||||
$result['name'] = strlen($product['name']) > 55 ? substr($product['name'], 0, 55) . "..." : $product['name'];
|
||||
$result['fullName'] = $product['name'];
|
||||
$result['code'] = strlen($product['code']) > 20 ? substr($product['code'], 0, 20) . "..." : $product['code'];
|
||||
$result['fullCode'] = $product['code'];
|
||||
$result['quantity'] = $raw['quantity'];
|
||||
$result['unit'] = $app_list_strings['ecmproducts_unit_dom'][$product['unit_id']];
|
||||
$result['stockState'] = (!empty($product['stockState'])) ? $product['stockState'] : 0;
|
||||
$result['stockAddress'] = (!empty($product['stock_addresses'])) ? $product['stock_addresses'] : "";
|
||||
$response[] = $result;
|
||||
}
|
||||
echo json_encode($response);
|
||||
}
|
||||
function getProductRawMaterials($productId, $quantity)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$response = array();
|
||||
$componentsQuery = "SELECT c.ecmcomponent_id, c.quantity
|
||||
FROM ecmproductcomponents as c
|
||||
WHERE c.ecmproduct_id = '$productId'";
|
||||
$crows = $db->query($componentsQuery);
|
||||
if ($crows->num_rows == 0) {
|
||||
return array(
|
||||
array(
|
||||
'ecmproduct_id' => $productId,
|
||||
'quantity' => $quantity
|
||||
)
|
||||
);
|
||||
} else {
|
||||
while ($c = $db->fetchByAssoc($crows)) {
|
||||
$response = array_merge($response, getProductRawMaterials($c['ecmcomponent_id'], $quantity * $c['quantity']));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
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'];
|
||||
@@ -126,7 +198,6 @@ function duplicatePositions($ids)
|
||||
$db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
function removePositions($ids)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
@@ -76,21 +76,67 @@
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<input class="button" id="duplicateBtn" value="Duplikuj" type="button">
|
||||
<input class="button" id="deleteBtn" value="Usuń" type="button">
|
||||
<input class="button" id="excelBtn" value="Excel" type="button">
|
||||
<input class="button" id="pdfBtn" value="PDF" type="button">
|
||||
<input class="button" value="Utwórz zamówienie wewnętrzne" type="button" id="createInsideOrder"/>
|
||||
<form action="index.php?module=EcmInsideOrders&action=EditView&fromProductsBySalesReport=true" method="post"
|
||||
target="_blank" id="createInsideOrderForm">
|
||||
<input id="insideOrderProducts" name="insideOrderProducts" type="hidden" value=""/>
|
||||
</form>
|
||||
|
||||
<!-- TAB MENU -->
|
||||
<ul class="subpanelTablist" style="margin-top:10px;" id="groupTabsPanels">
|
||||
<li class="active" id="1_menu">
|
||||
<script language="javascript">
|
||||
{literal}
|
||||
var set1 = function () {
|
||||
SetTab('1');
|
||||
};
|
||||
SelectedTab = '1';
|
||||
{/literal}
|
||||
</script>
|
||||
<a class="current" href="javascript:set1();">Produkty</a>
|
||||
</li>
|
||||
<li class="" id="2_menu">
|
||||
<script language="javascript">
|
||||
{literal}
|
||||
var set2 = function () {
|
||||
SetTab('2');
|
||||
};
|
||||
{/literal}
|
||||
</script>
|
||||
<a class="" href="javascript:set2();">Surowce</a>
|
||||
</li>
|
||||
<li class="" id="3_menu">
|
||||
<script language="javascript">
|
||||
{literal}
|
||||
var set3 = function () {
|
||||
SetTab('3');
|
||||
};
|
||||
{/literal}
|
||||
</script>
|
||||
<a class="" href="javascript:set3();">Receptury</a>
|
||||
</li>
|
||||
<li class="" id="4_menu">
|
||||
<script language="javascript">
|
||||
{literal}
|
||||
var set4 = function () {
|
||||
SetTab('4');
|
||||
};
|
||||
{/literal}
|
||||
</script>
|
||||
<a class="" href="javascript:set4();">Realizacja</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div id="1">
|
||||
<br>
|
||||
<input class="button" id="duplicateBtn" value="Duplikuj" type="button">
|
||||
<input class="button" id="deleteBtn" value="Usuń" type="button">
|
||||
<input class="button" id="excelBtn" value="Excel" type="button">
|
||||
<input class="button" id="pdfBtn" value="PDF" type="button">
|
||||
<input class="button" value="Utwórz przyjęcie produkcyjne" type="button" id="createInsideOrder"/>
|
||||
<table id="allTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th class="filter-false"><input type="checkbox" id="selectAll"></th>
|
||||
<th>Indeks</th>
|
||||
<th>Nazwa</th>
|
||||
<th>Data produkcji</th>
|
||||
@@ -205,3 +251,14 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="2" style="display: none">
|
||||
<div id="rawMaterialsTableContainer">
|
||||
</div>
|
||||
</div>
|
||||
<div id="3" style="display: none">
|
||||
Receptury
|
||||
</div>
|
||||
<div id="4" style="display: none">
|
||||
Realizacja
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
$(document).ready(function () {
|
||||
$("#allTable").tablesorter({
|
||||
sortList: [[13, 1]],
|
||||
theme: 'blue',
|
||||
theme: "blue",
|
||||
widthFixed: true,
|
||||
widgets: ['filter', 'zebra', 'stickyHeaders'],
|
||||
widgets: ["filter", "zebra", "stickyHeaders"],
|
||||
fixedWidth: true,
|
||||
widgetOptions: {
|
||||
resizable: false,
|
||||
@@ -70,9 +70,9 @@ $(document).ready(function () {
|
||||
|
||||
$("#selectAll").click(function () {
|
||||
if (this.checked) {
|
||||
$(".allCheck").prop('checked', true);
|
||||
$(".allCheck").prop("checked", true);
|
||||
} else {
|
||||
$(".allCheck").prop('checked', false);
|
||||
$(".allCheck").prop("checked", false);
|
||||
}
|
||||
});
|
||||
$("#orderComponents").click(orderComponents);
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<!-- TABS -->
|
||||
<div id="1">
|
||||
<br>
|
||||
<input class="button" name="submit" value="Utwórz zamówienie wewnętrzne" type="button" id="createInsideOrder"/>
|
||||
<input class="button" name="submit" value="Utwórz przyjęcie produkcyjne" type="button" id="createInsideOrder"/>
|
||||
<br>
|
||||
<form action="index.php?module=EcmInsideOrders&action=EditView&fromProductsBySalesReport=true" method="post"
|
||||
target="_blank" id="createInsideOrderForm">
|
||||
|
||||
Reference in New Issue
Block a user