<?php
 namespace App\OfferProfileRules; class OfferDetails_ServiceFee implements OfferDetailsInterface { public $mode; public $percentSource; public $percent; public $value; public $currency; public function check(\App\MessagesCollector $msgs) { $return = true; if ($this->mode!='value' and $this->mode!='percent' and $this->mode!='segment' and $this->mode!='duration') { $msgs->addError('Service fee mode is not valid - it must be set as `value`, `percent`, `segment`, `duration`.'); $return = false; } if ($this->percentSource!='servicePrice' and $this->percentSource!='servicePrice+tax') { $msgs->addError('Service fee percent source is not valid - it must be set as `servicePrice`, `servicePrice+tax`.'); $return = false; } $value = (string)$this->value; $percent = (string)$this->percent; if (!strlen($value) and !strlen($percent)) { $msgs->addWarning('You must set the service fee percent or value.'); $return = false; } if (strlen($value) and strlen($percent)) { $msgs->addWarning('The absolute value and the percent cannot be both set at the same time.'); $return = false; } if (strlen($percent)) { if (!is_numeric($percent) or $percent<0) { $msgs->addWarning('Service fee percent must be set as e a positive value.'); $return = false; } if ($this->mode!='percent') { $msgs->addWarning('You cannot set the percent value unless the applying mode is `percent`.'); $return = false; } } if (strlen($value)) { if (!is_numeric($value) or $value<0) { $msgs->addError('The service fee value must be a positive value.'); $return = false; } if (!\App\Config\Currencies::getInstance()->check($this->currency)) { $msgs->addError('Service fee currency is not valid.'); $return = false; } } if ($this->mode=='percent' and !strlen($percent)) { $msgs->addWarning('You did not set the percent value of the service fee.'); $return = false; } return $return; } public function getDescription($fullDescription=true) { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $return = ''; if ($this->percent!==null) { if ($fullDescription) { $return .= $this->percent.'% - '.$_LANG['OfferProfileRules']['serviceFee']['percentSource'][$this->percentSource]; } else { $return .= $this->percent.'%'; } } elseif ($this->value!==null) { $return .= \App\Utils\PriceFormat::format($this->value, $this->currency); } if ($this->mode=='segment') { $return .= ' / '.$_LANG['OfferProfileRules']['serviceFee']['mode_segment']; } elseif ($this->mode=='duration') { $return .= ' / '.$_LANG['OfferProfileRules']['serviceFee']['mode_duration']; } return $return; } } 