<?php
 namespace Entity; class OfferItem extends \App\Entity\GeneralMtAbstract { protected $saveInsideTransaction = false; protected $addAndUpdateDateTimeFormat = 'timestamp'; protected function setTableGroup(): void { global $DBTReservationServiceOfferItems; $this->tableGroup=$DBTReservationServiceOfferItems; } static public function update($id) { throw new \Exception(__CLASS__.'::'.__METHOD__.' will not be developed.'); } static public function delete($id) { throw new \Exception(__CLASS__.'::'.__METHOD__.' will not be developed.'); } protected function getAttribute($var) { switch ($var) { case 'idCustomer': case 'customerType': case 'productMultiplier': case 'quantity': case 'supplierInitialValue': case 'supplierInitialVat': case 'supplierInitialCurrency': case 'supplierWorkValue': case 'supplierWorkVat': case 'commissionPercent': case 'commissionInitialValue': case 'commissionInitialCurrency': case 'commissionWorkValue': case 'commissionWorkVat': case 'discountPercent': case 'discountInitialValue': case 'discountInitialCurrency': case 'discountWorkValue': case 'discountWorkVat': case 'serviceFeePercent': case 'serviceFeeInitialValue': case 'serviceFeeInitialCurrency': case 'serviceFeeWorkValue': case 'serviceFeeWorkVat': case 'taxInitialValue': case 'taxInitialVat': case 'taxInitialCurrency': case 'taxWorkValue': case 'taxWorkVat': case 'netCompanyWorkTotal': case 'offerWorkTotal': { return $this->fields[$var]; } default: { return parent::getAttribute($var); } } } protected function setAttribute($var, $value) { if ($this->operation!='insert') { throw new \Exception("You cannot use __set magic method with `{$this->operation}` operation in `".__CLASS__."` class."); } switch ($var) { case 'productMultiplier': case 'quantity': case 'supplierInitialValue': case 'supplierInitialVat': case 'commissionPercent': case 'commissionInitialValue': case 'discountPercent': case 'discountInitialValue': case 'serviceFeePercent': case 'serviceFeeInitialValue': case 'taxInitialValue': case 'taxInitialVat': case 'supplierInitialCurrency': case 'commissionInitialCurrency': case 'discountInitialCurrency': case 'serviceFeeInitialCurrency': case 'taxInitialCurrency': { $this->fields[$var]=$value; break; } case 'idCustomer': { if ($value and (!is_numeric($value) or $value<0) ) throw new \Exception('Customer id must be a positive numeric value in `'.__CLASS__.'` class.'); $this->fields[$var]=$value; break; } case 'customerType': { global $CFG; if ($value and !in_array($value, $CFG['generalData']['personTypes'])) throw new \Exception("The customer type `$value` is not valid."); $this->fields[$var]=$value; break; } default: { throw new \Exception("Wrong var ({$var}) for '".__METHOD__."'."); } } } public function populateFromOfferItem(\Entity\OfferItem $offerItem) { if ($offerItem->getOperation()!='select' or $this->getOperation()!='insert') { throw new \Exception("Invalid operation for '".__METHOD__."'."); } $this->idCustomer = $offerItem->idCustomer; $this->customerType = $offerItem->customerType; $this->productMultiplier = $offerItem->productMultiplier; $this->quantity = $offerItem->quantity; if ($offerItem->supplierInitialCurrency) { $this->supplierInitialValue = $offerItem->supplierInitialValue; $this->supplierInitialVat = $offerItem->supplierInitialVat; $this->supplierInitialCurrency = $offerItem->supplierInitialCurrency; } if ($offerItem->commissionInitialCurrency) { $this->commissionInitialValue = $offerItem->commissionInitialValue; $this->commissionInitialCurrency= $offerItem->commissionInitialCurrency; $this->commissionPercent = $offerItem->commissionPercent; } if ($offerItem->discountInitialCurrency) { $this->discountInitialValue = $offerItem->discountInitialValue; $this->discountInitialCurrency = $offerItem->discountInitialCurrency; $this->discountPercent = $offerItem->discountPercent; } if ($offerItem->serviceFeeInitialCurrency) { $this->serviceFeeInitialValue = $offerItem->serviceFeeInitialValue; $this->serviceFeeInitialCurrency= $offerItem->serviceFeeInitialCurrency; } if ($offerItem->taxInitialCurrency) { $this->taxInitialValue = $offerItem->taxInitialValue; $this->taxInitialVat = $offerItem->taxInitialVat; $this->taxInitialCurrency = $offerItem->taxInitialCurrency; } } } 