示例#1
0
 function DeductOrder($ID, $val, $description = "", $bAutoDeduction = true, $arStoreBarcodeOrderFormData = array(), $recurringID = 0)
 {
     global $DB, $USER;
     $ID = IntVal($ID);
     $val = $val != "Y" ? "N" : "Y";
     $description = Trim($description);
     $recurringID = IntVal($recurringID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGO_NO_ORDER_ID"), "NO_ORDER_ID");
         return false;
     }
     $arOrder = CSaleOrder::GetByID($ID);
     if (!$arOrder) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGO_NO_ORDER")), "NO_ORDER");
         return false;
     }
     if ($arOrder["DEDUCTED"] == $val) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGO_DUB_DEDUCTION")), "ALREADY_FLAG");
         return false;
     }
     foreach (GetModuleEvents("sale", "OnSaleBeforeDeductOrder", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID, $val, $description, $bAutoDeduction, $arStoreBarcodeOrderFormData, $recurringID)) === false) {
             return false;
         }
     }
     unset($GLOBALS["SALE_ORDER"]["SALE_ORDER_CACHE_" . $ID]);
     if ($recurringID <= 0) {
         if (IntVal($arOrder["RECURRING_ID"]) > 0) {
             $recurringID = IntVal($arOrder["RECURRING_ID"]);
         }
     }
     $arDeductResult = CSaleBasket::OrderDeduction($ID, $val == "N" ? true : false, $recurringID, $bAutoDeduction, $arStoreBarcodeOrderFormData);
     if (array_key_exists("ERROR", $arDeductResult)) {
         CSaleOrder::SetMark($ID, GetMessage("SKGB_DEDUCT_ERROR", array("#MESSAGE#" => $arDeductResult["ERROR"]["MESSAGE"])));
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGB_DEDUCT_ERROR", array("#MESSAGE#" => $arDeductResult["ERROR"]["MESSAGE"])), "DEDUCTION_ERROR");
         return false;
     } else {
         CSaleOrder::UnsetMark($ID);
     }
     if ($arDeductResult["RESULT"]) {
         if ($val == "Y") {
             $arFields = array("DEDUCTED" => "Y", "EMP_DEDUCTED_ID" => IntVal($USER->GetID()) > 0 ? IntVal($USER->GetID()) : false, "=DATE_DEDUCTED" => $DB->GetNowFunction());
         } else {
             $arFields = array("DEDUCTED" => "N", "EMP_DEDUCTED_ID" => IntVal($USER->GetID()) > 0 ? IntVal($USER->GetID()) : false, "=DATE_DEDUCTED" => $DB->GetNowFunction());
             if (strlen($description) > 0) {
                 $arFields["REASON_UNDO_DEDUCTED"] = $description;
             }
         }
         $res = CSaleOrder::Update($ID, $arFields);
     } else {
         $res = false;
     }
     foreach (GetModuleEvents("sale", "OnSaleDeductOrder", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $val));
     }
     if ($res) {
         return $res;
     } else {
         return false;
     }
 }