| | |
| | | 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); |
| | |
| | | [$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(); |
| | | |
| | |
| | | |
| | | return $changed; |
| | | } |
| | | |
| | | function delete(array $paymentData) { |
| | | $wFirmaPaymentsApi = $this->wfirma->paymentsApi(); |
| | | $paymentAttributeId = $this->helper->getAttributes()->getIdForCode('payment'); |
| | | |
| | | $wFirmaIds = ''; |
| | | foreach ($paymentData['attributes'] as $attribute) { |
| | | if ($attribute['customAttributeId'] === $paymentAttributeId) { |
| | | $wFirmaIds = $attribute['value']; |
| | | } |
| | | } |
| | | if (strlen($wFirmaIds) > 0) { |
| | | $wFirmaIds = explode(',', $wFirmaIds); |
| | | } else { |
| | | $wFirmaIds = []; |
| | | } |
| | | |
| | | $changed = FALSE; |
| | | |
| | | foreach($wFirmaIds as $wFirmaId) { |
| | | try { |
| | | $payment = $wFirmaPaymentsApi->get( |
| | | Payments\PaymentId::create($wFirmaId) |
| | | ); |
| | | $wFirmaPaymentsApi->delete($payment->id()); |
| | | $changed = TRUE; |
| | | } catch(\Webit\WFirmaSDK\Entity\Exception\NotFoundException $e) { |
| | | // do nothing |
| | | } |
| | | } |
| | | |
| | | return $changed; |
| | | } |
| | | } |