Exemplo n.º 1
0
 function ExportOrders($arIDs)
 {
     global $APPLICATION;
     $MODULE_ID = "epages.pickpoint";
     $api_login = COption::GetOptionString($MODULE_ID, "pp_api_login", "");
     $api_password = COption::GetOptionString($MODULE_ID, "pp_api_password", "");
     $authResult = self::Login($api_login, $api_password);
     if (!is_array($authResult["ERROR"])) {
         $sessionId = $authResult;
         if (strlen($sessionId) > 0) {
             require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/epages.pickpoint/constants.php";
             $ikn_number = COption::GetOptionString($MODULE_ID, "pp_ikn_number", "");
             $store_city = COption::GetOptionString($MODULE_ID, "pp_from_city", "");
             $store_address = COption::GetOptionString($MODULE_ID, "pp_store_address", "");
             $store_phone = COption::GetOptionString($MODULE_ID, "pp_store_phone", "");
             $sEmbed = COption::GetOptionString($MODULE_ID, "pp_enclosure", "");
             $ClientReturnAddress = array("PhoneNumber" => $store_phone, "CityName" => $store_city, "Address" => $store_address);
             $arQuery = array("SessionId" => $sessionId);
             foreach ($arIDs as $iOrderID) {
                 $arSending = array("IKN" => $ikn_number);
                 $arInvoice = array();
                 $obOrder = CSaleOrder::GetList(array(), array("ID" => $iOrderID), false, false, array("ID", "PRICE", "PERSON_TYPE_ID", "PAY_SYSTEM_ID"));
                 if ($arOrder = $obOrder->Fetch()) {
                     $obData = CPickpoint::SelectOrderPostamat($arOrder["ID"]);
                     $arData = $obData->Fetch();
                     $arFIO = CPickpoint::GetParam($arOrder["ID"], $arOrder["PERSON_TYPE_ID"], "FIO");
                     $sFIO = current($arFIO);
                     $arSending["EDTN"] = $arOrder["ID"];
                     $arInvoice["SenderCode"] = $arOrder["ID"];
                     $arInvoice["Description"] = $sEmbed;
                     $arInvoice["RecipientName"] = $sFIO;
                     $arInvoice["PostamatNumber"] = $arData["POSTAMAT_ID"];
                     $arInvoice["MobilePhone"] = $arData["SMS_PHONE"];
                     $arEmail = CPickpoint::GetParam($arOrder["ID"], $arOrder["PERSON_TYPE_ID"], "EMAIL");
                     $sEmail = current($arEmail);
                     $arInvoice["Email"] = $sEmail;
                     //$arInvoice["PostageType"] = $arServiceTypesCodes[$_REQUEST["EXPORT"][$arOrder["ID"]]["SERVICE_TYPE"]];
                     if (CPickpoint::CheckPPPaySystem($arOrder["PAY_SYSTEM_ID"], $arOrder["PERSON_TYPE_ID"])) {
                         $arInvoice["PostageType"] = $arServiceTypesCodes[1];
                     } else {
                         $arInvoice["PostageType"] = $arServiceTypesCodes[0];
                     }
                     $arInvoice["GettingType"] = $arEnclosingTypesCodes[$_REQUEST["EXPORT"][$arOrder["ID"]]["ENCLOSING_TYPE"]];
                     $arInvoice["PayType"] = 1;
                     if (CPickpoint::CheckPPPaySystem($arOrder["PAY_SYSTEM_ID"], $arOrder["PERSON_TYPE_ID"]) || $_REQUEST["EXPORT"][$arOrder["ID"]]["PAYED"] > 0) {
                         //$iPrice = number_format($_REQUEST["EXPORT"][$arOrder["ID"]]["PAYED"],2,".","");
                         $iPrice = number_format($arOrder["PRICE"], 2, ".", "");
                     } else {
                         $iPrice = 0;
                     }
                     $arInvoice["Sum"] = $iPrice;
                     //$arInvoice["Width"] = $arSizes[$_REQUEST["EXPORT"][$arOrder["ID"]]["SIZE"]]["SIZE_X"];
                     //$arInvoice["Height"] = $arSizes[$_REQUEST["EXPORT"][$arOrder["ID"]]["SIZE"]]["SIZE_Y"];
                     //$arInvoice["Depth"] = $arSizes[$_REQUEST["EXPORT"][$arOrder["ID"]]["SIZE"]]["SIZE_Z"];
                     $arInvoice["ClientReturnAddress"] = $ClientReturnAddress;
                     $arInvoice["UnclaimedReturnAddress"] = $ClientReturnAddress;
                     $arSending["Invoice"] = $arInvoice;
                     $arQuery["Sendings"][] = $arSending;
                 }
             }
             if (count($arQuery["Sendings"]) > 0) {
                 $response = self::Query('createsending', $arQuery);
                 foreach ($response->CreatedSendings as $key => $createdSendings) {
                     if ($createdSendings->ErrorMessage) {
                         self::checkErrors($createdSendings);
                     } elseif (intval($createdSendings->InvoiceNumber) > 0) {
                         CPickpoint::SetOrderInvoice($arQuery["Sendings"][$key]["Invoice"]["SenderCode"], $createdSendings->InvoiceNumber);
                         //CPickpoint::SaveOrderOptions($arQuery["Sendings"][$key]["Invoice"]["SenderCode"]);
                     }
                 }
                 foreach ($response->RejectedSendings as $rejectedSending) {
                     self::checkErrors($rejectedSending);
                 }
             }
             self::Logout($sessionId);
         }
     } else {
         return $authResult;
     }
 }