// Параметри за калкулация
 $paramCalculation = new ParamCalculation();
 $paramCalculation->setBroughtToOffice(!is_null($pickingData->bringToOfficeId));
 $paramCalculation->setToBeCalled(!is_null($pickingData->takeFromOfficeId));
 $paramCalculation->setParcelsCount($pickingData->parcelsCount);
 $paramCalculation->setWeightDeclared($pickingData->weightDeclared);
 $paramCalculation->setDocuments($pickingData->documents);
 $paramCalculation->setPalletized($pickingData->palletized);
 $paramCalculation->setFragile($pickingData->fragile);
 //При изпозване на $paramCalculation->setSenderSiteId($senderSiteId) вместо paramCalculation.setSenderId($senderClientData->getClientId())
 //не се използват преференциите на подателя по договор
 //$paramCalculation->setSenderSiteId($senderSiteId);
 $paramCalculation->setSenderId($senderClientData->getClientId());
 $paramCalculation->setReceiverSiteId($receiverSiteId);
 $paramCalculation->setPayerType($pickingData->payerType);
 $paramCalculation->setAmountCodBase($pickingData->amountCODBase);
 $paramCalculation->setTakingDate($pickingData->takingDate);
 $paramCalculation->setAutoAdjustTakingDate($pickingData->autoAdjust);
 // Adjust to first allowed taking date
 if (count($arrFinalServices) == 1) {
     // Имаме точно една налична услуга
     $serviceTypeID = $arrFinalServices[0];
     // Задаване на услугата в параметрите за калкулация
     $paramCalculation->setServiceTypeId($serviceTypeID);
     echo "<br><br>";
     echo "----------------------<br>";
     echo "Калкулация [calculate]<br>";
     echo "----------------------<br>";
     echo "Параметри на калкулацията:<br>";
     var_dump($paramCalculation);
     // Калкулация. Резултатът съдържа цена и компоненти на ценоообразуването, както и срокове за вземане и доставка.
Exemplo n.º 2
0
 /** Calculate base data
  * @param $data
  * @return array
  */
 public function calculate($data)
 {
     $this->_error = '';
     $resultCalculation = array();
     if (isset($this->resultLogin)) {
         try {
             $paramCalculation = new \ParamCalculation();
             $paramCalculation->setSenderId($this->resultLogin->getClientId());
             $paramCalculation->setBroughtToOffice($this->config->get('speedy_from_office') && $this->config->get('speedy_office_id'));
             $paramCalculation->setToBeCalled($data['to_office'] && $data['office_id']);
             $paramCalculation->setParcelsCount($data['count']);
             $paramCalculation->setWeightDeclared($data['weight']);
             $paramCalculation->setDocuments($this->config->get('speedy_documents'));
             $paramCalculation->setPalletized(false);
             if (!empty($data['fixed_time'])) {
                 $paramCalculation->setFixedTimeDelivery($data['fixed_time']);
             } else {
                 $paramCalculation->setFixedTimeDelivery(null);
             }
             if (isset($data['loading'])) {
                 if ($data['insurance']) {
                     if ($data['fragile']) {
                         $paramCalculation->setFragile(true);
                     } else {
                         $paramCalculation->setFragile(false);
                     }
                     $paramCalculation->setAmountInsuranceBase($data['totalNoShipping']);
                     $paramCalculation->setPayerTypeInsurance(\ParamCalculation::PAYER_TYPE_RECEIVER);
                 } else {
                     $paramCalculation->setFragile(false);
                 }
             } elseif ($this->config->get('speedy_insurance')) {
                 if ($this->config->get('speedy_fragile')) {
                     $paramCalculation->setFragile(true);
                 } else {
                     $paramCalculation->setFragile(false);
                 }
                 $paramCalculation->setAmountInsuranceBase($data['totalNoShipping']);
                 $paramCalculation->setPayerTypeInsurance(\ParamCalculation::PAYER_TYPE_RECEIVER);
             } else {
                 $paramCalculation->setFragile(false);
             }
             if (!($data['to_office'] && $data['office_id'])) {
                 $paramCalculation->setReceiverSiteId($data['city_id']);
             }
             $paramCalculation->setPayerType(\ParamCalculation::PAYER_TYPE_RECEIVER);
             if ($data['cod']) {
                 $paramCalculation->setAmountCodBase($data['total']);
             } else {
                 $paramCalculation->setAmountCodBase(0);
             }
             $paramCalculation->setTakingDate($data['taking_date']);
             $paramCalculation->setAutoAdjustTakingDate(true);
             if ($this->config->get('speedy_from_office') && $this->config->get('speedy_office_id')) {
                 $paramCalculation->setWillBringToOfficeId($this->config->get('speedy_office_id'));
             }
             if ($data['to_office'] && $data['office_id']) {
                 $paramCalculation->setOfficeToBeCalledId($data['office_id']);
             } else {
                 $paramCalculation->setOfficeToBeCalledId(null);
             }
             $resultCalculation = $this->ePSFacade->calculateMultipleServices($paramCalculation, $this->config->get('speedy_allowed_methods'));
             foreach ($resultCalculation as $key => $service) {
                 if ($service->getErrorDescription()) {
                     unset($resultCalculation[$key]);
                 }
             }
             $resultCalculation = array_values($resultCalculation);
         } catch (\Exception $e) {
             $this->_error = $e->getMessage();
             $this->log->addError('Speedy :: calculate :: ' . $e->getMessage());
         }
     }
     return $resultCalculation;
 }