| | |
| | | }, |
| | | "config": { |
| | | "platform": { |
| | | "php": "7.3.26" |
| | | "php": "8.1" |
| | | } |
| | | }, |
| | | "require": { |
| | | "php": ">=7.3", |
| | | "ubnt/ucrm-plugin-sdk": "^0.8.1", |
| | | "php": ">=8.1", |
| | | "ubnt/ucrm-plugin-sdk": "^0.9.0", |
| | | "umulmrum/holiday": "^0.6.0" |
| | | } |
| | | } |
| | |
| | | "displayName": "Holidays skipper", |
| | | "description": "Changes invoice due date if it is on a day off (holiday, weekend)", |
| | | "url": "https://github.com/jacekkow/ucrm-holidays", |
| | | "version": "0.1", |
| | | "version": "1.0", |
| | | "ucrmVersionCompliancy": { |
| | | "min": "3.0.0-beta2", |
| | | "min": "4.0.0", |
| | | "max": null |
| | | }, |
| | | "unmsVersionCompliancy": { |
| | |
| | | use Umulmrum\Holiday\Model\HolidayList; |
| | | |
| | | class HolidaySkipper { |
| | | protected $helper; |
| | | protected $skipDays = null; |
| | | protected $holidays = null; |
| | | protected UcrmHelper $helper; |
| | | protected ?array $skipDays = null; |
| | | protected ?HolidayList $holidays = null; |
| | | |
| | | function __construct(UcrmHelper $ucrmHelper) { |
| | | $this->helper = $ucrmHelper; |
| | | } |
| | | |
| | | protected function configure(array $years) { |
| | | protected function configure(array $years): void { |
| | | $config = $this->helper->getConfig(); |
| | | |
| | | if ($this->skipDays === NULL) { |
| | |
| | | } |
| | | } |
| | | |
| | | function processInvoice(string $invoiceId) { |
| | | function processInvoice(string $invoiceId): bool { |
| | | $crm = $this->helper->getApi(); |
| | | $invoiceData = $crm->get('/invoices/' . $invoiceId); |
| | | if ($invoiceData['status'] != 0) { |
| | |
| | | } else { |
| | | echo 'Invoice ' . $invoiceId . ': nothing to do' . "\n"; |
| | | } |
| | | |
| | | return $changed > 0; |
| | | } |
| | | } |
| | |
| | | namespace SIPL\UCRM\Holidays; |
| | | |
| | | class UcrmHelper { |
| | | protected $rootDirectory; |
| | | protected $api = NULL; |
| | | protected $config = NULL; |
| | | protected string $rootDirectory; |
| | | protected ?\Ubnt\UcrmPluginSdk\Service\UcrmApi $api = NULL; |
| | | protected ?array $config = NULL; |
| | | protected $event = NULL; |
| | | |
| | | function __construct(?string $rootDirectory = NULL) { |
| | |
| | | $this->rootDirectory = $rootDirectory; |
| | | } |
| | | |
| | | function getRootDirectory() { |
| | | function getRootDirectory(): string { |
| | | return $this->rootDirectory; |
| | | } |
| | | |
| | | function getApi() { |
| | | function getApi(): \Ubnt\UcrmPluginSdk\Service\UcrmApi { |
| | | if ($this->api === NULL) { |
| | | $this->api = \Ubnt\UcrmPluginSdk\Service\UcrmApi::create($this->rootDirectory); |
| | | } |
| | | return $this->api; |
| | | } |
| | | |
| | | function getConfig() { |
| | | function getConfig(): array { |
| | | if ($this->config === NULL) { |
| | | $configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create($this->rootDirectory); |
| | | $this->config = $configManager->loadConfig(); |
| | |
| | | return $this->config; |
| | | } |
| | | |
| | | function getCurrentEvent() { |
| | | function getCurrentEvent(): array { |
| | | if ($this->event === NULL) { |
| | | try { |
| | | if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') { |
| | |
| | | throw new \RuntimeException('Failed to process event - event not found'); |
| | | } |
| | | |
| | | if (!is_int($event['entityId'])) { |
| | | if (!ctype_digit($event['entityId'])) { |
| | | throw new \RuntimeException('Failed to process event - invalid entity ID'); |
| | | } |
| | | |