Jacek Kowalski
2022-08-15 279758dc82cc4993e90d948b86234b0f1339ba2f
Add possibility to synchronize deleted entries
1 files added
4 files modified
62 ■■■■■ changed files
public.php 8 ●●●●● patch | view | raw | blame | history
src/ContractorSynchronizer.php 12 ●●●● patch | view | raw | blame | history
src/InvoiceSynchronizer.php 12 ●●●● patch | view | raw | blame | history
src/PaymentSynchronizer.php 9 ●●●●● patch | view | raw | blame | history
src/Synchronizer.php 21 ●●●●● patch | view | raw | blame | history
public.php
@@ -26,11 +26,19 @@
        die();
    }
    if ($event['changeType'] === 'delete') {
        if($synchronizer->delete($event['extraData']['entity'])) {
            echo 'Object deleted';
        } else {
            echo 'Nothing to do';
        }
    } else {
    if ($synchronizer->synchronize($event['entityId'])) {
        echo 'Object synchronized';
    } else {
        echo 'Nothing to do';
    }
    }
} catch (Exception $e) {
    header('HTTP/1.1 500 Internal Server Error');
    echo $e;
src/ContractorSynchronizer.php
@@ -5,16 +5,8 @@
use \Webit\WFirmaSDK\Contractors as Contractors;
use \Webit\WFirmaSDK\Payments as Payments;
class ContractorSynchronizer {
    protected $wfirma;
    protected $helper;
    function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) {
        $this->wfirma = $wFirmaApi;
        $this->helper = $ucrmHelper;
    }
    function synchronize($ucrmClientId) {
class ContractorSynchronizer extends Synchronizer {
    function synchronize(int $ucrmClientId) {
        $crm = $this->helper->getApi();
        $wFirmaContractors = $this->wfirma->contractorsApi();
src/InvoiceSynchronizer.php
@@ -6,15 +6,7 @@
use \Webit\WFirmaSDK\Invoices as Invoices;
use \Webit\WFirmaSDK\Payments as Payments;
class InvoiceSynchronizer {
    protected $wfirma;
    protected $helper;
    function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) {
        $this->wfirma = $wFirmaApi;
        $this->helper = $ucrmHelper;
    }
class InvoiceSynchronizer extends Synchronizer {
    function getContractorId($clientId, $synchronize = TRUE) {
        if ($synchronize) {
            $synchronizer = new ContractorSynchronizer($this->wfirma, $this->helper);
@@ -55,7 +47,7 @@
            [$c2->name(), $c2->unit(), $c2->count(), $c2->price(), $c2->vat(), $c2->discount()];
    }
    function synchronize($ucrmInvoiceId) {
    function synchronize(int $ucrmInvoiceId) {
        $crm = $this->helper->getApi();
        $wFirmaInvoices = $this->wfirma->invoicesApi();
src/PaymentSynchronizer.php
@@ -5,14 +5,11 @@
use \Webit\WFirmaSDK\Invoices as Invoices;
use \Webit\WFirmaSDK\Payments as Payments;
class PaymentSynchronizer {
    protected $wfirma;
    protected $helper;
class PaymentSynchronizer extends Synchronizer {
    protected $ucrmMainDir;
    function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) {
        $this->wfirma = $wFirmaApi;
        $this->helper = $ucrmHelper;
        parent::__construct($wFirmaApi, $ucrmHelper);
        $backtrace = debug_backtrace();
        $backtrace = end($backtrace);
@@ -27,7 +24,7 @@
            [$p2->objectName(), $p2->objectId(), $p2->amount()->value(), $p2->date()->format('Y-m-d'), $p2->paymentMethod()];
    }
    function synchronize($ucrmPaymentId) {
    function synchronize(int $ucrmPaymentId) {
        $crm = $this->helper->getApi();
        $wFirmaPaymentsApi = $this->wfirma->paymentsApi();
src/Synchronizer.php
New file
@@ -0,0 +1,21 @@
<?php
namespace SIPL\UCRM\wFirma;
abstract class Synchronizer {
    protected $wfirma;
    protected $helper;
    function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) {
        $this->wfirma = $wFirmaApi;
        $this->helper = $ucrmHelper;
    }
    public function synchronize(int $entityId) {
        return FALSE;
    }
    public function delete(array $entity) {
        return FALSE;
    }
}