<?php
 namespace App\Config\SupplierInvoice; class VatsFromServiceCalculations extends \App\Config\DbMultiAssocVarsAbstract { protected $dbTablePkCols = ['serviceCode', 'location', 'calculationType', 'rowType']; protected $dbTableValueCol = 'supplierInvoiceRowVatText'; protected function getDbTableName() { global $DBTSupplierInvoiceRowsVatsFromServices; return $DBTSupplierInvoiceRowsVatsFromServices; } public function setAssociation($serviceCode, $location, $calculationType, $rowType, array $vatText) { $pkFields = [ 'serviceCode' => $serviceCode, 'location' => $location, 'calculationType' => $calculationType, 'rowType' => $rowType, ]; if (!$vatText['fixedPercent'] and !($vatText['varPercentWithVat'] and $vatText['varPercentWithoutVat'])) { throw new \App\Config\MessageException("The `vatText` should have either 'fixedPercent' or 'varPercentWithVat' & 'varPercentWithoutVat'"); } return $this->set($pkFields, serialize($vatText)); } public function getAssociations($serviceCode, $location, $calculationType) { $searchFields = [ 'serviceCode' => $serviceCode, 'location' => $location, 'calculationType' => $calculationType, ]; $associations = []; $results = $this->searchAssoc($searchFields); foreach ($results as $rowType => $serializedResult) { $associations[$rowType] = unserialize($serializedResult); } return $associations; } protected function save_check() { return true; } }