production - restore old version

This commit is contained in:
Michał Zieliński
2025-09-08 09:48:14 +02:00
parent c70ab619e6
commit cbf5645912

View File

@@ -135,7 +135,7 @@ if (!isset($_GET['ajaxAction'])) {
} else { } else {
switch ($_GET['ajaxAction']) { switch ($_GET['ajaxAction']) {
case 'getComponents': case 'getComponents':
echo getComponents($_POST['ids']); getComponents3($_POST['ids']);
break; break;
case 'getRawMaterials': case 'getRawMaterials':
echo getRawMaterials($_POST['ids'], $_POST['type']);; echo getRawMaterials($_POST['ids'], $_POST['type']);;
@@ -162,6 +162,7 @@ function findProduct($array, $value)
} }
return -1; return -1;
} }
function getComponents($ids, $dateFrom, $dateTo) function getComponents($ids, $dateFrom, $dateTo)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -236,94 +237,59 @@ function getComponents($ids, $dateFrom, $dateTo)
} }
echo json_encode($componentsData); echo json_encode($componentsData);
} }
function getComponents3($ids) {
function getComponents3($ids)
{
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
global $current_user; global $app_list_strings;
$products = array();
$componentsData = array();
foreach ($ids as $id) { foreach ($ids as $id) {
$saleInfo = $db->fetchByAssoc($db->query("SELECT quantity, ecmproduct_id, description, ecmsale_id FROM ecmsaleitems WHERE id ='$id'")); $saleInfo = $db->fetchByAssoc($db->query("SELECT quantity, ecmproduct_id, description, ecmsale_id FROM ecmsaleitems WHERE id ='$id'"));
$products = array( $saleQuery = "SELECT s.document_no, s.id, s.type, s.status, s.send_date, s.shipping_address_name
array( FROM ecmsales AS s
'ecmproduct_id' => $saleInfo['ecmproduct_id'], WHERE s.id = '" . $saleInfo['ecmsale_id'] . "'";
'quantity' => $saleInfo['quantity'] $saleData = $db->fetchByAssoc($db->query($saleQuery));
)
); $products = array();
$products = array_merge(getProductComponents($saleInfo['ecmproduct_id'], $saleInfo['quantity']), $products); $products = array_merge(getProductComponents($saleInfo['ecmproduct_id'], $saleInfo['quantity']), $products);
}
$grouppedProducts = array_reduce($products, function ($carry, $item) { $mainProduct = $db->fetchByAssoc($db->query(sprintf("SELECT code FROM ecmproducts WHERE id = '%s'", $saleInfo['ecmproduct_id'])));
if (isset($carry[$item['ecmproduct_id']])) {
$carry[$item['ecmproduct_id']]['productQty'] += $item['quantity'];
} else {
$carry[$item['ecmproduct_id']] = $item;
}
return $carry;
});
$a = 2; foreach ($products as $product) {
$prodQuery = sprintf("SELECT p.id, p.code, p.name, p.shape, p.brand, p.ems_qty_in_stock,
/* p.vendor_part_no as kind, p.part_no as size
while ($r = $db->fetchByAssoc($rows)) { FROM ecmproducts AS p WHERE p.id = '%s' AND p.deleted = 0", $product['ecmproduct_id']);
$componentsQuery = "SELECT p.code, p.name, c.quantity, p.unit_id, c.ecmcomponent_id, p.ems_qty_in_stock as stockState, $p = $db->fetchByAssoc($db->query($prodQuery));
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 = array();
$row['productId'] = $cr['ecmcomponent_id']; $row['mainProductId'] = $saleInfo['ecmproduct_id'];
$row['productName'] = strlen($cr['name']) > 55 ? substr($cr['name'], 0, 55) . "..." : $cr['name']; $row['mainProductCode'] = $mainProduct['code'];
$row['productFullName'] = $cr['name']; $row['productId'] = $p['id'];
$row['productCode'] = strlen($cr['code']) > 20 ? substr($cr['code'], 0, 20) . "..." : $cr['code']; $row['productName'] = strlen($p['name']) > 55 ? substr($p['name'], 0, 55) . "..." : $p['name'];
$row['productFullCode'] = $cr['code']; $row['productFullName'] = $p['name'];
$row['productUnit'] = $app_list_strings['ecmproducts_unit_dom'][$cr['unit_id']]; $row['productCode'] = strlen($p['code']) > 20 ? substr($p['code'], 0, 20) . "..." : $p['code'];
$row['productOrdered'] = (!empty($ordered['ordered'])) ? $ordered['ordered'] : 0; $row['productFullCode'] = $p['code'];
$row['productVendorName'] = $vendor ? $vendor['name'] : ''; $row['productKind'] = $p['kind'] != null ? $p['kind'] : "";
$row['productVendorId'] = $vendor ? $vendor['parent_id'] : ''; $row['productSize'] = $p['size'];
$row['productQty'] = $r['quantity'] * $cr['quantity']; $row['productShape'] = $app_list_strings['ecmproducts_shape_dom'][$p['shape']];
$row['productGroupKS'] = $cr['group_ks']; $row['productBrand'] = $app_list_strings['ecmproducts_brand_dom'][$p['brand']];
$row['orders'] = $orders; $row['productQty'] = $product['quantity'];
$row['productStockState'] = (!empty($cr['stockState'])) ? $cr['stockState'] : 0; $row['productStockState'] = $p['ems_qty_in_stock'] | 0;
$row['scheduled'] = $cr['scheduled']; $row['orderNo'] = $saleData['document_no'];
$row['orderId'] = $saleData['id'];
$row['orderStatus'] = $app_list_strings['ecmsales_status_dom'][$saleData['status']];
$row['orderType'] = $app_list_strings['ecmsales_type_dom'][$saleData['type']];
$row['orderParent'] = (isset($saleData['shipping_address_name']) && $saleData['shipping_address_name'] != 'Adres korespondencyjny' ? $saleData['shipping_address_name'] : '');
$row['orderSendDate'] = $saleData['send_date'];
$componentsData[] = $row; $componentsData[] = $row;
} }
} }
echo json_encode($componentsData);
} }
*/
}
function getRawMaterials2($ids, $type) function getRawMaterials2($ids, $type)
{ {
global $app_list_strings; global $app_list_strings;
@@ -425,6 +391,7 @@ function getRawMaterials2($ids, $type)
} }
return json_encode($response); return json_encode($response);
} }
function getRawMaterials($ids, $cids) function getRawMaterials($ids, $cids)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -510,6 +477,7 @@ function getRawMaterials($ids, $cids)
echo json_encode($rawMaterialsData); echo json_encode($rawMaterialsData);
} }
function getProductRawMaterials($productId, $quantity) function getProductRawMaterials($productId, $quantity)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -544,6 +512,7 @@ WHERE
} }
return $response; return $response;
} }
function addToProductionScheduler($orderItemId) function addToProductionScheduler($orderItemId)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -572,6 +541,7 @@ function addToProductionScheduler($orderItemId)
$db->query($query); $db->query($query);
} }
} }
function addComponentToProductionScheduler($productId, $qty) function addComponentToProductionScheduler($productId, $qty)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -580,6 +550,7 @@ function addComponentToProductionScheduler($productId, $qty)
generateUuidV4(), $qty, $current_user->id, $current_user->id, $productId); generateUuidV4(), $qty, $current_user->id, $current_user->id, $productId);
$db->query($query); $db->query($query);
} }
function getComponents2($ids) function getComponents2($ids)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -626,9 +597,9 @@ function getComponents2($ids)
$componentsData[] = $row; $componentsData[] = $row;
} }
} }
return json_encode($componentsData); return json_encode($componentsData);
} }
function getProductComponents($productId, $quantity) function getProductComponents($productId, $quantity)
{ {
$db = $GLOBALS['db']; $db = $GLOBALS['db'];
@@ -668,6 +639,7 @@ HAVING
return $response; return $response;
} }
} }
function generateUuidV4() function generateUuidV4()
{ {
$data = openssl_random_pseudo_bytes(16); $data = openssl_random_pseudo_bytes(16);