2 files added
6 files modified
| | |
| | | "php": ">=8.1", |
| | | "ext-json": "*", |
| | | "ubnt/ucrm-plugin-sdk": "^0.9.0", |
| | | "webit/w-firma-api": "^2.6.0" |
| | | "webit/w-firma-api": "^2.6.0", |
| | | "chillerlan/php-qrcode": "^5.0" |
| | | } |
| | | } |
| New file |
| | |
| | | <?php |
| | | require_once(__DIR__ . '/vendor/autoload.php'); |
| | | require_once(__DIR__ . '/hook_enable.php'); |
| | |
| | | "displayName": "wFirma.pl integration", |
| | | "description": "Synchronizes customers and invoices with Polish invoicing system wFirma.pl", |
| | | "url": "https://github.com/jacekkow/ucrm-wfirma", |
| | | "version": "3.0", |
| | | "version": "4.0", |
| | | "ucrmVersionCompliancy": { |
| | | "min": "4.0.0", |
| | | "max": null |
| | |
| | | require_once(__DIR__ . '/vendor/autoload.php'); |
| | | |
| | | try { |
| | | require_once(__DIR__ . '/hook_enable.php'); |
| | | if (isset($_GET['barcode'])) { |
| | | header('Content-Type: image/svg+xml'); |
| | | echo (new \chillerlan\QRCode\QRCode(new \chillerlan\QRCode\QROptions([ |
| | | 'outputBase64' => false, |
| | | 'addQuietzone' => false, |
| | | 'drawLightModules' => false, |
| | | 'connectPaths' => true, |
| | | ])))->render($_GET['barcode']); |
| | | die(); |
| | | } |
| | | |
| | | $helper = new \SIPL\UCRM\wFirma\UcrmHelper(); |
| | | $event = $helper->getCurrentEvent(); |
| | |
| | | } elseif ($event['entity'] === 'client') { |
| | | $synchronizer = new \SIPL\UCRM\wFirma\ContractorSynchronizer($wFirmaApi, $helper); |
| | | } elseif ($event['entity'] === 'invoice') { |
| | | $qrSync = new \SIPL\UCRM\wFirma\InvoiceQrCodeSynchronizer($helper); |
| | | $qrSync->synchronize($event['entityId'], $event['extraData']['entityBeforeEdit'] ?? null); |
| | | |
| | | $synchronizer = new \SIPL\UCRM\wFirma\InvoiceSynchronizer($wFirmaApi, $helper); |
| | | } elseif ($event['entity'] === 'payment') { |
| | | $synchronizer = new \SIPL\UCRM\wFirma\PaymentSynchronizer($wFirmaApi, $helper); |
| | |
| | | |
| | | if ($contractor->nip() != $client['companyTaxId']) { |
| | | $changed = TRUE; |
| | | $contractor->changeTaxId(Contractors\TaxIdType::nip()); |
| | | $contractor->changeNip($client['companyTaxId']); |
| | | } |
| | | |
| New file |
| | |
| | | <?php |
| | | |
| | | namespace SIPL\UCRM\wFirma; |
| | | |
| | | class InvoiceQrCodeSynchronizer { |
| | | protected UcrmHelper $helper; |
| | | |
| | | public function __construct(UcrmHelper $helper) { |
| | | $this->helper = $helper; |
| | | } |
| | | |
| | | public function synchronize(string $ucrmInvoiceId, array $previousEntity = []): void { |
| | | $ksefUrlAttribute = $this->helper->getAttributes()->getIdForCode('ksef-url'); |
| | | $ksefQrCodeAttribute = $this->helper->getAttributes()->getIdForCode('ksef-qr-code'); |
| | | |
| | | $invoice = $this->helper->getApi()->get('/invoices/' . $ucrmInvoiceId); |
| | | $currentUrl = ''; |
| | | $currentQrCode = ''; |
| | | foreach ($invoice['attributes'] ?? [] as $attribute) { |
| | | if ($attribute['customAttributeId'] == $ksefUrlAttribute) { |
| | | $currentUrl = $attribute['value']; |
| | | } |
| | | if ($attribute['customAttributeId'] == $ksefQrCodeAttribute) { |
| | | $currentQrCode = $attribute['value']; |
| | | } |
| | | } |
| | | |
| | | $newQrCode = null; |
| | | $expectedQrCodeUrl = $this->helper->getSelfUrl() . '_plugins/wfirma/public.php?barcode='; |
| | | if ($currentUrl == '' && $currentQrCode != '') { |
| | | $newQrCode = ''; |
| | | } |
| | | if ($currentUrl != '' && $currentQrCode != $expectedQrCodeUrl) { |
| | | $newQrCode = $expectedQrCodeUrl; |
| | | } |
| | | |
| | | if ($newQrCode != null) { |
| | | $this->helper->getApi()->patch('/invoices/' . $ucrmInvoiceId, [ |
| | | 'attributes' => [ |
| | | [ |
| | | 'customAttributeId' => $ksefQrCodeAttribute, |
| | | 'value' => $newQrCode, |
| | | ], |
| | | ], |
| | | ]); |
| | | $this->helper->getApi()->patch('/invoices/' . $ucrmInvoiceId . '/regenerate-pdf', []); |
| | | } |
| | | } |
| | | } |
| | |
| | | 'code' => 'invoice', |
| | | 'type' => 'invoice', |
| | | ], |
| | | 'KSeF Number' => [ |
| | | 'code' => 'ksef-number', |
| | | 'type' => 'invoice', |
| | | ], |
| | | 'KSeF URL' => [ |
| | | 'code' => 'ksef-url', |
| | | 'type' => 'invoice', |
| | | ], |
| | | 'KSeF QR Code' => [ |
| | | 'code' => 'ksef-qr-code', |
| | | 'type' => 'invoice', |
| | | ], |
| | | 'wFirma Payment ID' => [ |
| | | 'code' => 'payment', |
| | | 'type' => 'payment', |
| | |
| | | |
| | | namespace SIPL\UCRM\wFirma; |
| | | |
| | | use Ubnt\UcrmPluginSdk\Service\UcrmOptionsManager; |
| | | |
| | | class UcrmHelper { |
| | | protected string $rootDirectory; |
| | | protected ?\Ubnt\UcrmPluginSdk\Service\UcrmApi $api = NULL; |
| | |
| | | |
| | | function __construct(?string $rootDirectory = NULL) { |
| | | if ($rootDirectory === NULL) { |
| | | $rootDirectory = __DIR__ . '/..'; |
| | | $rootDirectory = dirname(__DIR__); |
| | | } |
| | | $this->rootDirectory = $rootDirectory; |
| | | } |
| | |
| | | return $this->api; |
| | | } |
| | | |
| | | function getSelfUrl(): string { |
| | | $ucrmOptionsManager = new UcrmOptionsManager($this->rootDirectory); |
| | | $options = $ucrmOptionsManager->loadOptions(); |
| | | return $options->ucrmLocalUrl ?? $options->ucrmPublicUrl ?? ''; |
| | | } |
| | | |
| | | function getAttributes(): UcrmAttributes { |
| | | if ($this->attributes === NULL) { |
| | | $this->attributes = new UcrmAttributes($this); |