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 {
switch ($_GET['ajaxAction']) {
case 'getComponents':
echo getComponents($_POST['ids']);
getComponents3($_POST['ids']);
break;
case 'getRawMaterials':
echo getRawMaterials($_POST['ids'], $_POST['type']);;
@@ -162,6 +162,7 @@ function findProduct($array, $value)
}
return -1;
}
function getComponents($ids, $dateFrom, $dateTo)
{
$db = $GLOBALS['db'];
@@ -236,94 +237,59 @@ function getComponents($ids, $dateFrom, $dateTo)
}
echo json_encode($componentsData);
}
function getComponents3($ids) {
function getComponents3($ids)
{
$db = $GLOBALS['db'];
global $current_user;
$products = array();
global $app_list_strings;
$componentsData = 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']
)
);
$saleQuery = "SELECT s.document_no, s.id, s.type, s.status, s.send_date, s.shipping_address_name
FROM ecmsales AS s
WHERE s.id = '" . $saleInfo['ecmsale_id'] . "'";
$saleData = $db->fetchByAssoc($db->query($saleQuery));
$products = array();
$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;
});
$mainProduct = $db->fetchByAssoc($db->query(sprintf("SELECT code FROM ecmproducts WHERE id = '%s'", $saleInfo['ecmproduct_id'])));
$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"));
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
FROM ecmproducts AS p WHERE p.id = '%s' AND p.deleted = 0", $product['ecmproduct_id']);
$p = $db->fetchByAssoc($db->query($prodQuery));
$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'];
$row['mainProductId'] = $saleInfo['ecmproduct_id'];
$row['mainProductCode'] = $mainProduct['code'];
$row['productId'] = $p['id'];
$row['productName'] = strlen($p['name']) > 55 ? substr($p['name'], 0, 55) . "..." : $p['name'];
$row['productFullName'] = $p['name'];
$row['productCode'] = strlen($p['code']) > 20 ? substr($p['code'], 0, 20) . "..." : $p['code'];
$row['productFullCode'] = $p['code'];
$row['productKind'] = $p['kind'] != null ? $p['kind'] : "";
$row['productSize'] = $p['size'];
$row['productShape'] = $app_list_strings['ecmproducts_shape_dom'][$p['shape']];
$row['productBrand'] = $app_list_strings['ecmproducts_brand_dom'][$p['brand']];
$row['productQty'] = $product['quantity'];
$row['productStockState'] = $p['ems_qty_in_stock'] | 0;
$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;
}
}
}
*/
echo json_encode($componentsData);
}
function getRawMaterials2($ids, $type)
{
global $app_list_strings;
@@ -425,6 +391,7 @@ function getRawMaterials2($ids, $type)
}
return json_encode($response);
}
function getRawMaterials($ids, $cids)
{
$db = $GLOBALS['db'];
@@ -510,6 +477,7 @@ function getRawMaterials($ids, $cids)
echo json_encode($rawMaterialsData);
}
function getProductRawMaterials($productId, $quantity)
{
$db = $GLOBALS['db'];
@@ -544,6 +512,7 @@ WHERE
}
return $response;
}
function addToProductionScheduler($orderItemId)
{
$db = $GLOBALS['db'];
@@ -572,6 +541,7 @@ function addToProductionScheduler($orderItemId)
$db->query($query);
}
}
function addComponentToProductionScheduler($productId, $qty)
{
$db = $GLOBALS['db'];
@@ -580,6 +550,7 @@ function addComponentToProductionScheduler($productId, $qty)
generateUuidV4(), $qty, $current_user->id, $current_user->id, $productId);
$db->query($query);
}
function getComponents2($ids)
{
$db = $GLOBALS['db'];
@@ -626,9 +597,9 @@ function getComponents2($ids)
$componentsData[] = $row;
}
}
return json_encode($componentsData);
}
function getProductComponents($productId, $quantity)
{
$db = $GLOBALS['db'];
@@ -668,6 +639,7 @@ HAVING
return $response;
}
}
function generateUuidV4()
{
$data = openssl_random_pseudo_bytes(16);