Esempio n. 1
0
 public static function loadAllStoreNames($active = true)
 {
     $active = $active === true;
     self::$storeNames = array();
     $filter = $active ? array('ACTIVE' => 'Y') : array();
     $storeIterator = CCatalogStore::GetList(array(), $filter, false, false, array('ID', 'ADDRESS', 'TITLE'));
     while ($store = $storeIterator->Fetch()) {
         $store['ID'] = (int) $store['ID'];
         $store['ADDRESS'] = (string) $store['ADDRESS'];
         $store['TITLE'] = (string) $store['TITLE'];
         self::$storeNames[$store['ID']] = $store['TITLE'] !== '' ? $store['TITLE'] . ' (' . $store['ADDRESS'] . ')' : $store['ADDRESS'];
     }
     unset($store, $storeIterator, $filter);
 }
Esempio n. 2
0
 if ('Y' == $useStore || 'D' == $useStore && 'Y' == $availCanBuyZero) {
     $negativeAmount = $useStore;
 } else {
     $negativeAmount = $_POST['NEGATIVE_AMOUNT'];
     if (!$negativeAmount || $negativeAmount == '') {
         $negativeAmount = 'D';
     }
 }
 $barcodeMultiply = $_POST["CAT_BARCODE_MULTIPLY"];
 if (!$barcodeMultiply || $barcodeMultiply == '') {
     $barcodeMultiply = 'N';
 }
 if (isset($_REQUEST["AR_BARCODE_ID"]) && $barcodeMultiply == 'Y') {
     $countBarCode = 0;
     $arBarCodeResult = array();
     $dbAmount = CCatalogStoreControlUtil::getQuantityInformation($PRODUCT_ID);
     if (is_object($dbAmount) && ($arAmount = $dbAmount->Fetch())) {
         $dbBarCode = CCatalogStoreBarCode::GetList(array(), array("PRODUCT_ID" => $PRODUCT_ID), false, false, array("ID", "BARCODE", "PRODUCT_ID", "STORE_ID"));
         while ($arBarCode = $dbBarCode->Fetch()) {
             $arBarCodeResult[] = $arBarCode;
             if ($arBarCode["STORE_ID"] != 0) {
                 $countBarCode++;
             }
         }
         if ($arAmount["SUM"] + $arAmount["RESERVED"] != 0 || $countBarCode > 0) {
             $strWarning .= GetMessage("C2IT_ERROR_USE_MULTIBARCODE", array("#COUNT#" => $arAmount["SUM"] - $countBarCode));
             $barcodeMultiply = 'N';
             unset($_REQUEST["AR_BARCODE_ID"]);
         } else {
             foreach ($arBarCodeResult as $barCode) {
                 CCatalogStoreBarCode::Delete($barCode["ID"]);
Esempio n. 3
0
 /**
  * @param $arFields
  * @return array|bool
  */
 public static function conductDocument($arFields)
 {
     global $DB;
     $id = intval($arFields["ID"]);
     $arResult = array();
     $i = 0;
     $dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $id));
     while ($arDocElement = $dbDocElements->Fetch()) {
         if (!self::checkAmountField($arDocElement)) {
             return false;
         }
         $arResult["ELEMENTS"][$i] = array("PRODUCT_ID" => $arDocElement["ELEMENT_ID"], "AMOUNT" => $arDocElement["AMOUNT"]);
         $arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]);
         $newReserved = $arProductInfo["QUANTITY_RESERVED"] - $arDocElement["AMOUNT"];
         if ($newReserved >= 0) {
             if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], array("QUANTITY_RESERVED" => $newReserved))) {
                 return false;
             }
             $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()) {
                 $arFields = array();
                 $arFields["QUANTITY"] = doubleval($arAmount["SUM"] - $arAmount["RESERVED"]);
                 if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arFields)) {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
                     return false;
                 }
             }
         } else {
             $productInfo = CCatalogStoreControlUtil::getProductInfo($arDocElement["ELEMENT_ID"]);
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_WRONG_RESERVED_AMOUNT", array("#PRODUCT#" => '"' . $productInfo["NAME"] . '"')));
             return false;
         }
         $i++;
     }
     if ($i > 0) {
         return true;
     }
     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_WRONG_ELEMENT_COUNT"));
     return false;
 }
Esempio n. 4
0
 /** The method works with barcodes. If necessary, check the uniqueness of multiple barcodes.
  * @param $arFields
  * @param $userId
  * @return bool|int
  */
 protected function applyBarCode($arFields, $userId)
 {
     global $APPLICATION;
     $barCode = $arFields["BARCODE"];
     $elementId = $arFields["PRODUCT_ID"];
     $storeToId = isset($arFields["STORE_ID"]) ? $arFields["STORE_ID"] : 0;
     $storeFromId = isset($arFields["STORE_FROM"]) ? $arFields["STORE_FROM"] : 0;
     $newStore = 0;
     $userId = (int) $userId;
     $result = false;
     $rsProps = CCatalogStoreBarCode::GetList(array(), array("BARCODE" => $barCode), false, false, array('ID', 'STORE_ID', 'PRODUCT_ID'));
     if ($arBarCode = $rsProps->Fetch()) {
         if ($storeFromId > 0) {
             if ($storeToId > 0) {
                 if ($arBarCode["STORE_ID"] == $storeFromId && $arBarCode["PRODUCT_ID"] == $elementId) {
                     $newStore = $storeToId;
                 } else {
                     $storeName = CCatalogStoreControlUtil::getStoreName($storeFromId);
                     $APPLICATION->ThrowException(GetMessage("CAT_DOC_WRONG_STORE_BARCODE", array("#STORE#" => '"' . $storeName . '"', "#PRODUCT#" => '"' . $arFields["ELEMENT_NAME"] . '"', "#BARCODE#" => '"' . $barCode . '"')));
                     return false;
                 }
             }
         } else {
             $APPLICATION->ThrowException(GetMessage("CAT_DOC_BARCODE_ALREADY_EXIST", array("#PRODUCT#" => '"' . $arFields["ELEMENT_NAME"] . '"', "#BARCODE#" => '"' . $barCode . '"')));
             return false;
         }
         if ($newStore > 0) {
             $result = CCatalogStoreBarCode::update($arBarCode["ID"], array("STORE_ID" => $storeToId, "MODIFIED_BY" => $userId));
         } else {
             $result = CCatalogStoreBarCode::delete($arBarCode["ID"]);
         }
     } else {
         if ($storeFromId > 0) {
             $storeName = CCatalogStoreControlUtil::getStoreName($storeFromId);
             $APPLICATION->ThrowException(GetMessage("CAT_DOC_WRONG_STORE_BARCODE", array("#STORE#" => '"' . $storeName . '"', "#PRODUCT#" => '"' . $arFields["ELEMENT_NAME"] . '"', "#BARCODE#" => '"' . $barCode . '"')));
             return false;
         } elseif ($storeToId > 0) {
             $result = CCatalogStoreBarCode::Add(array("PRODUCT_ID" => $elementId, "STORE_ID" => $storeToId, "BARCODE" => $barCode, "MODIFIED_BY" => $userId, "CREATED_BY" => $userId));
         }
     }
     return $result;
 }
		"content" => GetMessage("CAT_DOC_BARCODE"),
		"default" => ($requiredFields["BAR_CODE"]["required"] == 'Y') ? true : false
	);
}

$lAdmin->AddHeaders($arHeaders);

$isDisable = $bReadOnly ? " disabled" : "";
$maxId = 0;
if(is_array($arResult["ELEMENT"]))
{
	foreach($arResult["ELEMENT"] as $code => $value)
	{
		$storesTo = $storesFrom = '';
		$isMultiply = 'Y' == $value["IS_MULTIPLY_BARCODE"];
		$arProductInfo = CCatalogStoreControlUtil::getProductInfo($value["ELEMENT_ID"]);
		if(is_array($arProductInfo))
			$value = array_merge($value, $arProductInfo);

		$arRes['ID'] = intval($code);
		$maxId = ($arRes['ID'] > $maxId) ? $arRes['ID'] : $maxId;
		foreach($arStores as $key => $val)
		{
			$selectedTo = ($value['STORE_TO'] == $val['ID']) ? " selected " : " ";
			$selectedFrom = ($value['STORE_FROM'] == $val['ID']) ? " selected " : " ";
			$store = ($val["TITLE"] != '') ? $val["TITLE"]." (".$val["ADDRESS"].")" : $val["ADDRESS"];
			$storesTo .= '<option'.$selectedTo.'value="'.$val['ID'].'">'.$store.'</option>';
			$storesFrom .= '<option'.$selectedFrom.'value="'.$val['ID'].'">'.$store.'</option>';
		}
		$arRows[$arRes['ID']] = $row =& $lAdmin->AddRow($arRes['ID']);
		$row->AddViewField("IMAGE", CFile::ShowImage($value['DETAIL_PICTURE'], 80, 80, "border=0", "", true));
Esempio n. 6
0
 static function Delete($id)
 {
     global $DB;
     $id = intval($id);
     if ($id > 0) {
         foreach (GetModuleEvents("catalog", "OnBeforeCatalogStoreDelete", true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array($id)) === false) {
                 return false;
             }
         }
         $dbDocs = $DB->Query("select ID from b_catalog_docs_element where STORE_FROM = " . $id . " or STORE_TO = " . $id, true);
         if ($bStoreHaveDocs = $dbDocs->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CS_STORE_HAVE_DOCS"));
             return false;
         }
         $DB->Query("delete from b_catalog_store_product where STORE_ID = " . $id, true);
         $DB->Query("delete from b_catalog_store where ID = " . $id, true);
         foreach (GetModuleEvents("catalog", "OnCatalogStoreDelete", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($id));
         }
         self::recalculateStoreBalances($id);
         CCatalogStoreControlUtil::clearStoreName($id);
         return true;
     }
     return false;
 }
				}
				break;
			case "cancellation":
				$DB->StartTransaction();
				$result = CCatalogDocs::cancellationDocument($ID, $userId);
				if($result == true)
					$DB->Commit();
				else
					$DB->Rollback();

				if($ex = $APPLICATION->GetException())
				{
					$strError = $ex->GetString();
					if(!empty($result) && is_array($result))
					{
						$strError .= CCatalogStoreControlUtil::showErrorProduct($result);
					}
					$lAdmin->AddGroupError($strError, $ID);
				}
				break;
			case "copy":
				$arResult = array();
				$DB->StartTransaction();
				$dbDocument = CCatalogDocs::getList(array(), array("ID" => $ID), false, false, array("DOC_TYPE", "SITE_ID", "CONTRACTOR_ID", "CURRENCY", "TOTAL"));
				if($arDocument = $dbDocument->Fetch())
				{
					foreach($arDocument as $key => $value)
					{
						$arResult[$key] = $value;
					}
					$arResult["DATE_DOCUMENT"] = 'now';
        $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"];
            }
        }
        $storeFromName = CCatalogStoreControlUtil::getStoreName($product["STORE_FROM"]);
        $storeToName = CCatalogStoreControlUtil::getStoreName($product["STORE_TO"]);
        ?>
		<script type="text/javascript">
			var arBarCodes = new Array();
			<?php 
        if (is_array($product["BARCODE"])) {
            foreach ($product["BARCODE"] as $barCode) {
                ?>
				arBarCodes.push("<?php 
                echo $barCode;
                ?>
");
				<?php 
            }
            $product["BARCODE"] = '';
        }