<?php
namespace App\Bsp; class BspRow { public $group = 0; public $supplierCode3 = null; public $supplierCode2 = null; public $ticketNumber = null; public $ticketDate = null; public $locationType = null; public $priceSupplierCash = null; public $priceSupplierCc = null; public $priceTaxCash = null; public $priceTaxCc = null; public $priceCommissionPercent = null; public $priceCommission = null; public $priceCommissionVat = null; public $priceCommissionSupplementary = null; public $priceBalancePayable = null; public $formOfPayments = []; public $conjunctions = []; public $description = null; public $extraData = null; public $relations = null; public $rawData = null; public function __construct() { $this->priceSupplierCash = new BspRowPrice(); $this->priceSupplierCc = new BspRowPrice(); $this->priceTaxCash = new BspRowPriceTax(); $this->priceTaxCc = new BspRowPriceTax(); $this->priceCommission = new BspRowPrice(); $this->priceCommissionVat = new BspRowPrice(); $this->priceCommissionSupplementary = new BspRowPrice(); $this->priceBalancePayable = new BspRowPrice(); $this->extraData = new BspRowExtraData(); $this->relations = new BspRowRelations(); } public function validate() { if (!$this->ticketNumber) { throw new BspRowException(sprintf("Ticket number is not set")); } if (!$this->ticketDate) { throw new BspRowException(sprintf("Ticket date is not set, ticket %s", $this->ticketNumber)); } } public function addFormOfPayment($type) { $fop = new \App\Bsp\BspRowFormOfPaymentComponent(); $fop->type = $type; $this->formOfPayments[]= $fop; return $fop; } public function isPaidWith($type) { foreach($this->formOfPayments as $fop) { if ($fop->type==$type) { return true; } } return false; } public function get($type) { } public function invertSign() { $this->priceSupplierCash->invertSign(); $this->priceSupplierCc->invertSign(); $this->priceCommission->invertSign(); $this->priceCommissionVat->invertSign(); $this->priceCommissionSupplementary->invertSign(); $this->priceBalancePayable->invertSign(); $this->priceTaxCash->invertSign(); $this->priceTaxCc->invertSign(); return $this; } function getDefinedComponents() { $components = [ 'priceSupplierCash', 'priceSupplierCc', 'priceCommission', 'priceCommissionVat', 'priceCommissionSupplementary', 'priceBalancePayable', 'priceTaxCash', 'priceTaxCc', ]; $ret = []; foreach ($components as $component) { if ($this->{$component}->amount!=0) { $ret[]= $component; } } return $ret; } public function clampPrices() { foreach ($this->getDefinedComponents() as $comp) { $this->{$comp}->clampValue(); } return $this; } public function __get($key) { $ret = null; switch ($key) { case 'currency': $currencies = array_unique(array_filter([ $this->priceBalancePayable->currency, $this->priceSupplierCash->currency, $this->priceSupplierCc->currency, $this->priceTaxCash->currency, $this->priceTaxCc->currency, $this->priceCommission->currency, $this->priceCommissionVat->currency, ])); if (count($currencies)>1) { throw new BspRowException("This BSP row taxes contain more than one currency"); } $ret = reset($currencies); break; } return $ret; } public function __set($key, $value) { throw new BspRowException("Cannot set undefined property {$key}"); } } 