<?php
 namespace App\QcRules; class Invoice_Filter_ServiceRemark extends FilterRemarkAbstract { public $serviceCode; public function __construct($operation=null, ?Array $values=null, $remarkVar=null, $serviceCode=null) { parent::__construct($operation, $values, $remarkVar); $this->serviceCode = $serviceCode; } public function checkInput(\App\MessagesCollector $msgs) { $OK = parent::checkInput($msgs); $serviceCodes = $this->serviceCode ? (array)$this->serviceCode : [] ; foreach ($serviceCodes as $serviceCode) { if (!\App\Config\Services_Basic::getInstance()->checkService($serviceCode)) { $msgs->addWarning(sprintf('The service code `%s` is not valid', $serviceCode)); $OK = false; } } return $OK; } public function checkFields(\App\QcRules\FieldsAbstract $fields, $context='') { $serviceCodes = $this->serviceCode ? (array)$this->serviceCode : [] ; $rmVals = []; $foundServices = false; foreach ($fields->rowsList as $row) { if (!$serviceCodes or in_array($row['serviceCode'], $serviceCodes)) { $foundServices = true; $rmVals[$row['processedRemarks'][$this->remarkVar]] = true; } } if (!$foundServices) { if ($context=='filter') { return false; } elseif ($context=='restriction') { return true; } else { throw new \Exception("Invalid context `{$context}` - it must be either `filter` or `restriction`."); } } $rmVals = array_keys($rmVals); if ( !$this->checkFields_multiValues($rmVals) ) { return false; } foreach ($rmVals as $rmVal) { $validators = []; if ($this->validatorType) { $validators['type'] = $this->validatorType; } if ($this->validatorLengthMin) { $validators['minLength'] = $this->validatorLengthMin; } if ($this->validatorLengthMax) { $validators['maxLength'] = $this->validatorLengthMax; } if ( $validators and \Engine\Validator::set($rmVal, $validators)->getProblems() ) { return false; } } return true; } public function createDescription() { $description = parent::createDescription(); if ($this->serviceCode) { $serviceCodes = $this->serviceCode ? (array)$this->serviceCode : [] ; $servicesNames = []; foreach ($serviceCodes as $serviceCode) { $servicesNames[] = \App\Config\Services_Basic::getInstance()->getServiceName($serviceCode); } $serviceName = implode(', ', $servicesNames); $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $description .= ' - '.$_LANG['QcRules']['filterServiceRemarkDescriptionList'].' '.$serviceName; } return $description; } } 