protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
 {
     $amount = 0;
     $orderRows = array();
     foreach ($builderOrderRows as $orderRow) {
         if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
             $amount = \Svea\WebService\WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
         } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
             $amount = $orderRow->amountIncVat;
         } else {
             $amount = $orderRow->amountIncVat;
             $orderRow->vatPercent = \Svea\WebService\WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
         }
         $orderRows[] = new \SoapVar(new AdminSoap\CancellationRow($amount, $this->formatRowNameAndDescription($orderRow), $orderRow->rowNumber, $orderRow->vatPercent), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
     }
     return $orderRows;
 }
 public function test_FixedDiscount_specified_using_amountIncVat_are_calculated_from_order_item_rows_only_multiple_vat_rates()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $order = WebPay::createOrder($config);
     $order->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(2))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(6)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setName("shipping with price 50 @6% = 106")->setAmountExVat(50.0)->setVatPercent(6))->addDiscount(WebPayItem::fixedDiscount()->setDiscountId("f100i")->setName("couponName")->setDescription("couponDesc")->setAmountIncVat(100)->setUnit("st"));
     $formatter = new WebServiceRowFormatter($order);
     $resultRows = $formatter->formatRows();
     // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
     $testedRow = $resultRows[3];
     $this->assertEquals("f100i", $testedRow->ArticleNumber);
     $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
     $this->assertEquals(-56.179775280899, $testedRow->PricePerUnit);
     $this->assertEquals(25, $testedRow->VatPercent);
     // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
     $testedRow = $resultRows[4];
     $this->assertEquals("f100i", $testedRow->ArticleNumber);
     $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
     $this->assertEquals(-28.089887640449, $testedRow->PricePerUnit);
     $this->assertEquals(6, $testedRow->VatPercent);
     // order total should be 250 + 106 - 100 +53= 256+53
     $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits + WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits + WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits + WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits + WebServiceRowFormatter::convertExVatToIncVat($resultRows[4]->PricePerUnit, $resultRows[4]->VatPercent) * $resultRows[4]->NumberOfUnits;
     $this->assertEquals(256.0 + 53, $total);
 }
 protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
 {
     $amount = 0;
     $orderRows = array();
     //if orderrownumber is set, create an orderrow with dummy values. Will be ignored in WebPay WS
     if (count($this->orderBuilder->rowsToCredit) > 0) {
         foreach ($this->orderBuilder->rowsToCredit as $rownumber) {
             $orderRows[] = new \SoapVar(new AdminSoap\CancellationRow(0.0, "Numbered row", 0, $rownumber), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
         }
     }
     //add orderrows if there are any
     foreach ($builderOrderRows as $orderRow) {
         if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
             $amount = \Svea\WebService\WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
         } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
             $amount = $orderRow->amountIncVat;
         } else {
             $amount = $orderRow->amountIncVat;
             $orderRow->vatPercent = \Svea\WebService\WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
         }
         $orderRows[] = new \SoapVar(new AdminSoap\CancellationRow($amount, $this->formatRowNameAndDescription($orderRow), $orderRow->vatPercent), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
     }
     return $orderRows;
 }
 protected function getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat)
 {
     $amount = 0;
     $numberedOrderRows = array();
     foreach ($builderOrderRows as $orderRow) {
         if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
             $amount = $priceIncludingVat ? \Svea\WebService\WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent) : $orderRow->amountExVat;
         } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
             $amount = $priceIncludingVat ? $orderRow->amountIncVat : \Svea\WebService\WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent);
         } else {
             $amount = $priceIncludingVat ? $orderRow->amountIncVat : $orderRow->amountExVat;
             $orderRow->vatPercent = \Svea\WebService\WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
         }
         $numberedOrderRows[] = new \SoapVar(new AdminSoap\NumberedOrderRow($orderRow->articleNumber, $this->formatRowNameAndDescription($orderRow), !isset($orderRow->discountPercent) ? 0 : $orderRow->discountPercent, $orderRow->quantity, $amount, $orderRow->unit, $orderRow->vatPercent, $orderRow->creditInvoiceId, $orderRow->invoiceId, $orderRow->rowNumber, $priceIncludingVat), SOAP_ENC_OBJECT, null, null, 'NumberedOrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
     }
     return $numberedOrderRows;
 }