From 7a3f58a551c98e301d64e0bb15f73f03e40c1c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Mon, 8 Sep 2025 08:50:32 +0200 Subject: [PATCH] production - restore old version --- .../productionSchedule/productionSchedule.js | 1 + .../productsBySales/productsBySales.js | 1 + .../productsBySales/productsBySales.php | 124 +++++++++++++----- 3 files changed, 92 insertions(+), 34 deletions(-) diff --git a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js index 4c83cbdb..99814865 100644 --- a/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js +++ b/modules/EcmReports/BimIT-Reports/productionSchedule/productionSchedule.js @@ -171,6 +171,7 @@ function getRawMaterials() { } function drawRawMaterials(data) { $("#rawMaterialsTableContainer").html(rawMaterialsTablePrototype()); + // TODO: tutraj czasami siÄ™ wiesza data.forEach((el, index) => { var tr = $(""); tr.append(""); diff --git a/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.js b/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.js index 83d6663f..7d3eda88 100644 --- a/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.js +++ b/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.js @@ -158,6 +158,7 @@ function SetTab(tab_name) { } } function getComnponents() { + console.log("getComnponents"); var ids = []; $('input.allCheck:checkbox:checked').each(function () { // check if this element is visible on site diff --git a/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.php b/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.php index 75eb3bda..f2264c87 100644 --- a/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.php +++ b/modules/EcmReports/BimIT-Reports/productsBySales/productsBySales.php @@ -135,10 +135,10 @@ if (!isset($_GET['ajaxAction'])) { } else { switch ($_GET['ajaxAction']) { case 'getComponents': - echo getComponents2($_POST['ids']); + echo getComponents($_POST['ids']); break; case 'getRawMaterials': - echo getRawMaterials2($_POST['ids'], $_POST['type']);; + echo getRawMaterials($_POST['ids'], $_POST['type']);; break; case 'saveProductDescription': saveProductDescription($_GET['itemId'], $_GET['description']); @@ -236,6 +236,94 @@ function getComponents($ids, $dateFrom, $dateTo) } echo json_encode($componentsData); } +function getComponents3($ids) { + $db = $GLOBALS['db']; + global $current_user; + $products = array(); + foreach ($ids as $id) { + $saleInfo = $db->fetchByAssoc($db->query("SELECT quantity, ecmproduct_id, description, ecmsale_id FROM ecmsaleitems WHERE id ='$id'")); + $products = array( + array( + 'ecmproduct_id' => $saleInfo['ecmproduct_id'], + 'quantity' => $saleInfo['quantity'] + ) + ); + $products = array_merge(getProductComponents($saleInfo['ecmproduct_id'], $saleInfo['quantity']), $products); + } + + $grouppedProducts = array_reduce($products, function ($carry, $item) { + if (isset($carry[$item['ecmproduct_id']])) { + $carry[$item['ecmproduct_id']]['productQty'] += $item['quantity']; + } else { + $carry[$item['ecmproduct_id']] = $item; + } + return $carry; + }); + + $a = 2; + + /* + while ($r = $db->fetchByAssoc($rows)) { + $componentsQuery = "SELECT p.code, p.name, c.quantity, p.unit_id, c.ecmcomponent_id, p.ems_qty_in_stock as stockState, + p.group_ks, COUNT(ps.id) AS scheduled + FROM ecmproductcomponents as c + INNER JOIN ecmproducts AS p + ON p.id = c.ecmcomponent_id + LEFT JOIN productionScheduler AS ps + ON p.id = ps.ecmproduct_id AND ps.is_component = 1 AND ps.deleted=0 + WHERE c.ecmproduct_id = '" . $r['ecmproduct_id'] . "' GROUP BY p.id"; + $crows = $db->query($componentsQuery); + while ($cr = $db->fetchByAssoc($crows)) { + $exists = findProduct($componentsData, $cr['ecmcomponent_id']); + if ($exists > -1) { + $componentsData[$exists]['productQty'] += $r['quantity'] * $cr['quantity']; + } else { + $ordered = $db->fetchByAssoc($db->query("SELECT SUM(poi.quantity) as ordered, GROUP_CONCAT(poi.ecmpurchaseorder_id SEPARATOR '|') AS orders + FROM ecmpurchaseorderitems as poi + INNER JOIN ecmpurchaseorders as po + ON poi.ecmpurchaseorder_id = po.id AND (po.status='registered' OR po.status='accepted') AND po.deleted=0 + WHERE poi.deleted=0 AND poi.ecmproduct_id = '" . $cr['ecmcomponent_id'] . "'")); + $orders = array(); + $ordersIds = explode('|', $ordered['orders']); + $ordersRes = $db->query("SELECT id, document_no, delivery_date FROM ecmpurchaseorders WHERE id IN ('" . join("','", $ordersIds) . "') ORDER BY date_entered DESC"); + while ($o = $db->fetchByAssoc($ordersRes)) { + $orders[] = array( + 'orderId' => $o['id'], + 'orderNr' => $o['document_no'], + 'orderDeliveryDate' => isset($o['delivery_date']) ? explode(' ', $o['delivery_date'])[0] : '' + ); + } + $vendor = $db->fetchByAssoc($db->query("SELECT d.parent_id, a.name + FROM ecmstockdocinitems AS i + INNER JOIN ecmstockdocins AS d + ON d.id = i.ecmstockdocin_id + INNER JOIN accounts AS a + ON a.id = d.parent_id + WHERE i.ecmproduct_id = '" . $cr['ecmcomponent_id'] . "' + ORDER BY d.register_date DESC + LIMIT 0,1")); + + $row = array(); + $row['productId'] = $cr['ecmcomponent_id']; + $row['productName'] = strlen($cr['name']) > 55 ? substr($cr['name'], 0, 55) . "..." : $cr['name']; + $row['productFullName'] = $cr['name']; + $row['productCode'] = strlen($cr['code']) > 20 ? substr($cr['code'], 0, 20) . "..." : $cr['code']; + $row['productFullCode'] = $cr['code']; + $row['productUnit'] = $app_list_strings['ecmproducts_unit_dom'][$cr['unit_id']]; + $row['productOrdered'] = (!empty($ordered['ordered'])) ? $ordered['ordered'] : 0; + $row['productVendorName'] = $vendor ? $vendor['name'] : ''; + $row['productVendorId'] = $vendor ? $vendor['parent_id'] : ''; + $row['productQty'] = $r['quantity'] * $cr['quantity']; + $row['productGroupKS'] = $cr['group_ks']; + $row['orders'] = $orders; + $row['productStockState'] = (!empty($cr['stockState'])) ? $cr['stockState'] : 0; + $row['scheduled'] = $cr['scheduled']; + $componentsData[] = $row; + } + } + } +*/ +} function getRawMaterials2($ids, $type) { global $app_list_strings; @@ -540,38 +628,6 @@ function getComponents2($ids) } return json_encode($componentsData); - - /* - * $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['orderId']; - $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; - $row['mainProductId'] = $r['main_product_id']; - $row['mainProductCode'] = $r['main_product_code']; - * - */ } function getProductComponents($productId, $quantity) {