示例#1
0
 /**
  * Returns prepared request
  * @return WebServiceSoap\SveaRequest
  */
 public function prepareRequest($priceIncludingVat = NULL)
 {
     $errors = $this->validateRequest();
     $sveaDeliverOrder = new WebServiceSoap\SveaDeliverOrder();
     $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
     $orderInformation = new WebServiceSoap\SveaDeliverOrderInformation($this->orderBuilder->orderType);
     $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
     $orderInformation->OrderType = $this->orderBuilder->orderType;
     if ($this->orderBuilder->orderType == \ConfigurationProvider::INVOICE_TYPE) {
         $invoiceDetails = new WebServiceSoap\SveaDeliverInvoiceDetails();
         $invoiceDetails->InvoiceDistributionType = $this->orderBuilder->distributionType;
         $invoiceDetails->IsCreditInvoice = isset($this->orderBuilder->invoiceIdToCredit) ? TRUE : FALSE;
         // required
         if (isset($this->orderBuilder->invoiceIdToCredit)) {
             $invoiceDetails->InvoiceIdToCredit = $this->orderBuilder->invoiceIdToCredit;
             // optional
         }
         $invoiceDetails->NumberOfCreditDays = isset($this->orderBuilder->numberOfCreditDays) ? $this->orderBuilder->numberOfCreditDays : 0;
         $formatter = new WebServiceRowFormatter($this->orderBuilder, $priceIncludingVat);
         $orderRow['OrderRow'] = $formatter->formatRows();
         $invoiceDetails->OrderRows = $orderRow;
         $orderInformation->DeliverInvoiceDetails = $invoiceDetails;
     }
     $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
     $object = new WebServiceSoap\SveaRequest();
     $object->request = $sveaDeliverOrder;
     return $object;
 }
 private function formatFixedDiscountRows($row)
 {
     // only amountIncVat (i.e. amount) was specified:
     if (isset($row->amount) && !isset($row->vatPercent) && !isset($row->amountExVat)) {
         $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountIncVatOnly($row));
     }
     // only amountExVat was specified:
     if (!isset($row->amount) && !isset($row->vatPercent) && isset($row->amountExVat)) {
         $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountExVatOnly($row));
     }
     // amountIncVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
     if (isset($row->amount) && isset($row->vatPercent) && !isset($row->amountExVat)) {
         $orderRow = new WebServiceSoap\SveaOrderRow();
         if (isset($row->discountId)) {
             $orderRow->ArticleNumber = $row->discountId;
         }
         $orderRow->Description = $this->formatRowNameAndDescription($row);
         if (isset($row->unit)) {
             $orderRow->Unit = $row->unit;
         }
         $orderRow->DiscountPercent = 0;
         //no discount on discount
         $orderRow->NumberOfUnits = 1;
         //only one discount per row
         //calculate discount
         $vatRate = $row->vatPercent;
         $discountAtThisVatRateIncVat = $row->amount;
         //                    $discountAtThisVatRateExVat =
         //                            WebServiceRowFormatter::convertIncVatToExVat( $discountAtThisVatRateIncVat, $vatRate );
         $orderRow->PricePerUnit = -1 * ($this->priceIncludingVat ? $discountAtThisVatRateIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amount, \Svea\Helper::bround($row->vatPercent)));
         $orderRow->VatPercent = $vatRate;
         $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
         $this->newRows[] = $orderRow;
     }
     // amountExVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
     if (!isset($row->amount) && isset($row->vatPercent) && isset($row->amountExVat)) {
         $orderRow = new WebServiceSoap\SveaOrderRow();
         if (isset($row->discountId)) {
             $orderRow->ArticleNumber = $row->discountId;
         }
         $orderRow->Description = $this->formatRowNameAndDescription($row);
         if (isset($row->unit)) {
             $orderRow->Unit = $row->unit;
         }
         $orderRow->DiscountPercent = 0;
         //no discount on discount
         $orderRow->NumberOfUnits = 1;
         //only one discount per row
         //calculate discount
         $vatRate = $row->vatPercent;
         $discountAtThisVatRate = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, \Svea\Helper::bround($row->vatPercent)) : $row->amountExVat;
         $orderRow->PricePerUnit = -1 * $discountAtThisVatRate;
         $orderRow->VatPercent = $vatRate;
         $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
         $this->newRows[] = $orderRow;
     }
 }
 /**
  * Format Order row with svea_soap package and calculate vat
  * @param type $rows
  * @return \SveaCreateOrderInformation
  */
 protected function formatOrderInformationWithOrderRows($rows)
 {
     $orderInformation = new WebServiceSoap\SveaCreateOrderInformation(isset($this->order->campaignCode) ? $this->order->campaignCode : "", isset($this->order->sendAutomaticGiroPaymentForm) ? $this->order->sendAutomaticGiroPaymentForm : 0);
     // rewrite order rows to soap_class order rows
     $formatter = new WebServiceRowFormatter($this->order);
     $formattedOrderRows = $formatter->formatRows();
     foreach ($formattedOrderRows as $formattedOrderRow) {
         $orderInformation->addOrderRow($formattedOrderRow);
     }
     return $orderInformation;
 }