static function OnBeforeDocumentDelete($id) { global $DB; $id = intval($id); $dbElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $id)); while ($arElement = $dbElements->Fetch()) { if (!$DB->Query("DELETE FROM b_catalog_docs_barcode WHERE DOC_ELEMENT_ID = " . $arElement["ID"] . " ", true)) { return false; } } foreach (GetModuleEvents("catalog", "OnDocumentBarcodeDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($id)); } }
/** * @param $arFields * @return array|bool */ public static function cancellationDocument($arFields) { global $DB; $id = intval($arFields["ID"]); $i = 0; $dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $id)); while ($arDocElement = $dbDocElements->Fetch()) { $arResult = array(); $arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]); $newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"]; $arResult["QUANTITY_RESERVED"] = $newReserved; $dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true); if ($arAmount = $dbAmount->Fetch()) { $arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved); if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR")); return false; } } $i++; } if ($i > 0) { return true; } return false; }
public static function OnIBlockElementDelete($productID) { global $DB; $productID = (int) $productID; if ($productID > 0) { $dbDeleteElements = CCatalogStoreDocsElement::getList(array(), array("ELEMENT_ID" => $productID), false, false, array('ID')); while ($arDeleteElements = $dbDeleteElements->fetch()) { CCatalogStoreDocsElement::delete($arDeleteElements["ID"]); } return $DB->Query("delete from b_catalog_store_barcode where PRODUCT_ID = " . $productID, true); } }
/** * @param $documentId * @param $userId * @return bool */ public static function cancellationDocument($documentId, $userId) { global $DB, $APPLICATION; $documentId = (int) $documentId; $i = 0; $dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $documentId)); while ($arDocElement = $dbDocElements->Fetch()) { $arResult = array(); $arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]); $newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"]; $arResult["QUANTITY_RESERVED"] = $newReserved; $dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true); if ($arAmount = $dbAmount->Fetch()) { $arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved); if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) { $APPLICATION->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR")); return false; } if (self::isNeedClearPublicCache($arProductInfo['QUANTITY'], $arResult['QUANTITY'], $arProductInfo['QUANTITY_TRACE'], $arProductInfo['CAN_BUY_ZERO'])) { $productInfo = array('CAN_BUY_ZERO' => $arProductInfo['CAN_BUY_ZERO'], 'NEGATIVE_AMOUNT_TRACE' => $arProductInfo['NEGATIVE_AMOUNT_TRACE'], 'QUANTITY_TRACE' => $arProductInfo['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProductInfo['QUANTITY'], 'QUANTITY' => $arResult['QUANTITY'], 'DELTA' => $arResult['QUANTITY'] - $arProductInfo['QUANTITY']); self::clearPublicCache($arProductInfo['ID'], $productInfo); } } $i++; } return $i > 0; }
if (isset($_REQUEST['CONTRACTOR_ID'])) { $arResult['CONTRACTOR_ID'] = (int)$_REQUEST['CONTRACTOR_ID']; $str_CONTRACTOR_ID = $arResult['CONTRACTOR_ID']; } if (isset($_REQUEST['CAT_CURRENCY_STORE'])) { $arResult['CURRENCY'] = (string)$_REQUEST['CAT_CURRENCY_STORE']; $str_CURRENCY = $arResult['CURRENCY']; } } } if(!isset($_REQUEST["AJAX_MODE"])) { $dbDocumentElement = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $ID), false, false, array("ID", "STORE_FROM", "STORE_TO", "ELEMENT_ID", "AMOUNT", "PURCHASING_PRICE", "IS_MULTIPLY_BARCODE", "RESERVED")); while($arDocumentElements = $dbDocumentElement->Fetch()) { $arAllDocumentElement[] = $arDocumentElements; } } elseif(isset($_REQUEST["PRODUCT"]) && is_array($_REQUEST["PRODUCT"]) || isset($_REQUEST["ELEMENT_ID"])) { $arElements = array(); if(isset($_REQUEST["PRODUCT"]) && is_array($_REQUEST["PRODUCT"])) $arElements = $_REQUEST["PRODUCT"]; if(isset($_REQUEST["ELEMENT_ID"]) && is_array($_REQUEST["ELEMENT_ID"])) { $arElements[] = array("PRODUCT_ID" => $_REQUEST["ELEMENT_ID"][0], "SELECTED_BARCODE" => $_REQUEST["HIDDEN_BARCODE"][0], "AMOUNT" => $_REQUEST["HIDDEN_QUANTITY"][0]); } $arAllAddedProductsId = $arAjaxElementInfo = array();
if (strlen($_REQUEST["CAT_DOC_TOTAL_SAVE"]) > 0) { $arGeneral["TOTAL"] = doubleval($_REQUEST["CAT_DOC_TOTAL_SAVE"]); } if ($ID > 0) { if (CCatalogDocs::update($ID, $arGeneral)) { $docId = $ID; } } else { $docId = CCatalogDocs::add($arGeneral); } if (isset($_POST["PRODUCT"]) && is_array($_POST["PRODUCT"]) && $docId) { if ($_REQUEST["cancellation"] == 1) { LocalRedirect("/bitrix/admin/cat_store_document_edit.php?lang=" . LANG . "&ID=" . $docId . "&action=cancellation&sessid=" . $_REQUEST["sessid"] . "&" . GetFilterParams("filter_", false)); } if ($ID > 0) { $dbElement = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $ID)); while ($arElement = $dbElement->Fetch()) { CCatalogStoreDocsElement::delete($arElement["ID"]); } } foreach ($_POST["PRODUCT"] as $key => $val) { $storeTo = $val["CAT_DOC_STORE_TO"]; $storeFrom = $val["CAT_DOC_STORE_FROM"]; $arAdditional = array("AMOUNT" => $val["QUANTITY"], "ELEMENT_ID" => $val["PRODUCT_ID"], "PURCHASING_PRICE" => $val["PRICE"], "STORE_TO" => $storeTo, "STORE_FROM" => $storeFrom, "ENTRY_ID" => $key, "DOC_ID" => $docId); $docElementId = CCatalogStoreDocsElement::add($arAdditional); if ($docElementId && isset($val["BAR_CODE"]) && is_array($val["BAR_CODE"])) { foreach ($val["BAR_CODE"] as $barCode) { if (!empty($barCode)) { CCatalogStoreDocsBarcode::add(array("BARCODE" => $barCode, "DOC_ELEMENT_ID" => $docElementId)); } }