/** * @static * @param $arFields * @return bool|int */ static function add($arFields) { global $DB; foreach (GetModuleEvents("catalog", "OnBeforeDocumentAdd", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } if (array_key_exists('DATE_CREATE', $arFields)) { unset($arFields['DATE_CREATE']); } if (array_key_exists('DATE_MODIFY', $arFields)) { unset($arFields['DATE_MODIFY']); } $arFields['~DATE_MODIFY'] = $DB->GetNowFunction(); $arFields['~DATE_CREATE'] = $DB->GetNowFunction(); if (!self::CheckFields('ADD', $arFields)) { return false; } $arInsert = $DB->PrepareInsert("b_catalog_store_docs", $arFields); $strSql = "INSERT INTO b_catalog_store_docs (" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")"; $res = $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (!$res) { return false; } $lastId = intval($DB->LastID()); if (isset($arFields["ELEMENT"]) && is_array($arFields["ELEMENT"])) { foreach ($arFields["ELEMENT"] as $arElement) { $lastDocElementId = 0; if (isset($arElement["ID"])) { unset($arElement["ID"]); } $arElement["DOC_ID"] = $lastId; if (is_array($arElement)) { $lastDocElementId = CCatalogStoreDocsElement::add($arElement); } if (isset($arElement["BARCODE"]) && $lastDocElementId) { if (is_array($arElement["BARCODE"])) { foreach ($arElement["BARCODE"] as $barcode) { CCatalogStoreDocsBarcode::add(array("DOC_ELEMENT_ID" => $lastDocElementId, "BARCODE" => $barcode)); } } } } } foreach (GetModuleEvents("catalog", "OnDocumentAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($lastId, $arFields)); } return $lastId; }
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();
for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; }*/ if (!empty($data)) { //$line=explode("\n",$data); //—оздаем документ, если с данными все хорошо if (empty($docId)) { $docId = CCatalogDocs::add($arGeneral); } $res = CIBlockElement::GetByID(intval($data[0])); if ($ar_res = $res->GetNext()) { $stock = intval($data[1]); $z++; $arAdditional = array("AMOUNT" => $stock, "ELEMENT_ID" => $ar_res["ID"], "PURCHASING_PRICE" => floatval($data[2]), "STORE_TO" => $_REQUEST["STORE_TO"] ? intval($_REQUEST["STORE_TO"]) : 1, "ENTRY_ID" => $z, "DOC_ID" => $docId); $total += $arAdditional["PURCHASING_PRICE"] * $stock; $docElementId = CCatalogStoreDocsElement::add($arAdditional); } else { $notice .= GetMessage("ELCORSO_WAREHOUSECSVIMPORT_ELEMENT") . $data[0] . ' ' . GetMessage("ELCORSO_WAREHOUSECSVIMPORT_NE_NAYDEN") . "\r\n"; } } } //CCatalogDocs::conductDocument($docId, $USER->GetID()); CCatalogDocs::update($docId, array("TOTAL" => $total)); LocalRedirect("/bitrix/admin/warehouse_import_admin.php?ID=" . $ID . "&mess=import&docId=" . $docId . "&z=" . $z . "&lang=" . LANG); fclose($handle); } } // else // { // $message = new CAdminMessage(GetMessage("ELCORSO_WAREHOUSECSVIMPORT_PUSTOY_FAYL")); // }
orderPrice = res[0]["PRICE_WITH_DISCOUNT"]; } } } function fEnableSub() { if (document.getElementById('tbl_sale_order_edit')) document.getElementById('tbl_sale_order_edit').style.zIndex = 10000; } </script> <?php if ($ID > 0) { $arSelect = array("ID", "DOC_ID", "STORE_FROM", "STORE_TO", "ELEMENT_ID", "AMOUNT", "PURCHASING_PRICE", "IS_MULTIPLY_BARCODE"); $dbResult = CCatalogStoreDocsElement::GetList(array(), array('DOC_ID' => $ID), false, false, $arSelect); while ($product = $dbResult->GetNext()) { $docElementId = $product["ID"]; $product = array_merge($product, CCatalogStoreControlUtil::getProductInfo($product["ELEMENT_ID"])); $product["BARCODE"] = ''; if ($product["IS_MULTIPLY_BARCODE"] == 'N') { $dbBarCode = CCatalogStoreBarCode::getList(array(), array("PRODUCT_ID" => $product["ELEMENT_ID"])); if ($arBarCode = $dbBarCode->GetNext()) { $product["BARCODE"] = $arBarCode["BARCODE"]; } } elseif ($product["IS_MULTIPLY_BARCODE"] == 'Y') { $dbBarCodes = CCatalogStoreDocsBarcode::getList(array(), array("DOC_ELEMENT_ID" => $docElementId)); while ($arBarCode = $dbBarCodes->GetNext()) { $product["BARCODE"][] = $arBarCode["BARCODE"]; } }