diff --git a/.gitignore b/.gitignore index 4270dc1..b381ae5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock /nbproject/private/ /vendor/ -/debian/debhelper-build-stamp \ No newline at end of file +/debian/debhelper-build-stamp +/clover.log \ No newline at end of file diff --git a/FlexiPeeHP/Bricks/ParovacFaktur.php b/FlexiPeeHP/Bricks/ParovacFaktur.php index d150362..d86ae52 100644 --- a/FlexiPeeHP/Bricks/ParovacFaktur.php +++ b/FlexiPeeHP/Bricks/ParovacFaktur.php @@ -26,12 +26,6 @@ class ParovacFaktur extends \Ease\Sand */ public $daysBack = 1; - /** - * Invoice Types Cache - * @var array - */ - public $docTypes = []; - /** * Párovač faktur */ @@ -42,27 +36,6 @@ public function __construct() $this->banker = new \FlexiPeeHP\Banka(); } - /** - * - * @return array - */ - public function getDocumentTypes() - { - $types = []; - $evbackup = $this->invoicer->getEvidence(); - $defbackup = $this->invoicer->defaultUrlParams; - $this->invoicer->setEvidence('typ-faktury-vydane'); - $this->invoicer->defaultUrlParams = ['limit' => 0]; - $typesRaw = $this->invoicer->getColumnsFromFlexibee([ - 'kod', 'typDoklK']); - $this->invoicer->setEvidence($evbackup); - $this->invoicer->defaultUrlParams = $defbackup; - foreach ($typesRaw as $rawtype) { - $types[$rawtype['kod']] = $rawtype['typDoklK']; - } - return $types; - } - /** * Start set date * @@ -112,9 +85,10 @@ public function getPaymentsToProcess($daysBack = 1) */ public function getInvoicesToProcess() { - $result = []; - $this->invoicer->defaultUrlParams['order'] = 'datVyst@A'; - $invoices = $this->invoicer->getColumnsFromFlexibee([ + $result = []; + $this->invoicer->defaultUrlParams['order'] = 'datVyst@A'; + $this->invoicer->defaultUrlParams['includes'] = '/faktura-vydana/typDokl'; + $invoices = $this->invoicer->getColumnsFromFlexibee([ 'id', 'kod', 'stavUhrK', @@ -123,6 +97,7 @@ public function getInvoicesToProcess() 'buc', 'varSym', 'specSym', + 'typDokl(typDoklK,kod)', 'sumCelkem', 'duzpPuv', 'typDokl', @@ -133,6 +108,7 @@ public function getInvoicesToProcess() if ($this->invoicer->lastResponseCode == 200) { $result = $invoices; } + unset($this->invoicer->defaultUrlParams['includes']); return $result; } @@ -162,7 +138,12 @@ public function invoicesMatchingByBank() $payment = new \FlexiPeeHP\Banka($paymentData); foreach ($invoices as $invoiceID => $invoiceData) { - $invoice = new \FlexiPeeHP\FakturaVydana((int) $invoiceData['id']); + + $typDokl = $invoiceData['typDokl'][0]; + $docType = $typDokl['typDoklK']; + $invoiceData['typDokl'] = \FlexiPeeHP\FlexiBeeRO::code($typDokl['kod']); + + $invoice = new \FlexiPeeHP\FakturaVydana($invoiceData); /* * Standardní faktura (typDokladu.faktura) @@ -174,8 +155,9 @@ public function invoicesMatchingByBank() * Pohyb Kč / Zůstatek Kč (typBanUctu.kc) * Pohyb měna / Zůstatek měna (typBanUctu.mena) */ - $docType = $this->getOriginDocumentType($invoiceData['typDokl']); + switch ($docType) { + case 'typDokladu.zalohFaktura': case 'typDokladu.faktura': if ($this->settleInvoice($invoice, $payment)) ; break; @@ -190,7 +172,7 @@ public function invoicesMatchingByBank() default: $this->addStatusMessage( sprintf(_('Unsupported document type: %s %s'), - $docType.': '.$invoiceData['typDokl'], + $typDokl['typDoklK@showAs'].' ('.$docType.'): '.$invoiceData['typDokl'], $invoice->getApiURL() ), 'warning'); break; @@ -218,6 +200,9 @@ public function invoicesMatchingByInvoices() foreach ($this->getInvoicesToProcess() as $invoiceData) { $payments = $this->findPayments($invoiceData); if (!empty($payments) && count(current($payments))) { + $typDokl = $invoiceData['typDokl'][0]; + $docType = $typDokl['typDoklK']; + $invoiceData['typDokl'] = \FlexiPeeHP\FlexiBeeRO::code($typDokl['kod']); $invoice = new \FlexiPeeHP\FakturaVydana($invoiceData); $this->invoicer->setMyKey($invoiceData['id']); /* @@ -231,10 +216,10 @@ public function invoicesMatchingByInvoices() * Pohyb měna / Zůstatek měna (typBanUctu.mena) */ - $docType = $this->getOriginDocumentType($invoiceData['typDokl']); foreach ($payments as $paymentData) { $payment = new \FlexiPeeHP\Banka($paymentData); switch ($docType) { + case 'typDokladu.zalohFaktura': case 'typDokladu.faktura': if ($this->settleInvoice($invoice, $payment)) { @@ -247,9 +232,11 @@ public function invoicesMatchingByInvoices() $this->settleCreditNote($invoice, $payments); break; default: - $this->addStatusMessages(sprintf(_('Unsupported invoice type: %s'), - 'warning'), - $docType.': '.$invoiceData['typDokl']); + $this->addStatusMessage( + sprintf(_('Unsupported document type: %s %s'), + $typDokl['typDoklK@showAs'].' ('.$docType.'): '.$invoiceData['typDokl'], + $invoice->getApiURL() + ), 'warning'); break; } } @@ -561,14 +548,14 @@ public function findInvoices($paymentData) // } // - if (count($vInvoices)) { + if (!empty($vInvoices) && count($vInvoices)) { foreach ($vInvoices as $invoiceID => $invoice) { if (!array_key_exists($invoiceID, $invoices)) { $invoices[$invoiceID] = $invoice; } } } - if (count($sInvoices)) { + if (!empty($sInvoices) && count($sInvoices)) { foreach ($sInvoices as $invoiceID => $invoice) { if (!array_key_exists($invoiceID, $invoices)) { $invoices[$invoiceID] = $invoice; @@ -648,15 +635,16 @@ public function findPayments($invoiceData) */ public function findInvoice($what) { - $result = null; - $this->invoicer->defaultUrlParams['order'] = 'datVyst@A'; - $payments = $this->invoicer->getColumnsFromFlexibee([ + $result = null; + $this->invoicer->defaultUrlParams['order'] = 'datVyst@A'; + $this->invoicer->defaultUrlParams['includes'] = '/faktura-vydana/typDokl'; + $payments = $this->invoicer->getColumnsFromFlexibee([ 'id', 'varSym', 'specSym', 'buc', 'kod', - 'typDokl', + 'typDokl(typDoklK,kod)', 'sumCelkem', 'stitky', 'datVyst'], @@ -665,7 +653,7 @@ public function findInvoice($what) if ($this->invoicer->lastResponseCode == 200) { $result = $payments; } - + unset($this->invoicer->defaultUrlParams['includes']); return $result; } diff --git a/FlexiPeeHP/Bricks/Upominac.php b/FlexiPeeHP/Bricks/Upominac.php index 14ebcf1..994ff51 100644 --- a/FlexiPeeHP/Bricks/Upominac.php +++ b/FlexiPeeHP/Bricks/Upominac.php @@ -43,10 +43,12 @@ public function __construct($init = null, $options = array()) /** * Obtain customer debths Array + * + * @param array $skipLables labels of Customer (Addressbook) to skip * * @return Customer */ - public function getDebths() + public function getDebths($skipLabels = []) { $allDebts = []; $this->addStatusMessage(_('Getting clients'), 'debug'); @@ -56,21 +58,38 @@ public function getDebths() $this->addStatusMessage(sprintf(_('%s Clients Found'), count($clients))); $this->addStatusMessage(_('Getting debts'), 'debug'); foreach ($clients as $cid => $clientIDs) { - $stitky = $clientIDs['stitky']; - $debts = $this->customer->getCustomerDebts((int) $clientIDs['id']); - if (count($debts)) { + $stitky = \FlexiPeeHP\Stitek::listToArray($clientIDs['stitky']); + if (count($skipLabels) && array_intersect($skipLabels, $stitky)) { + continue; + } + + $debts = $this->customer->getCustomerDebts((int) $clientIDs['id']); + if (!empty($debts) && count($debts)) { foreach ($debts as $did => $debtInfo) { $allDebts[$cid][$did] = $debtInfo; $debtCount++; } } else { //All OK - $this->enableCustomer($stitky, $cid); + $this->everythingPaidOff($cid, $stitky); } } $this->addStatusMessage(sprintf(_('%s Debts Found'), $debtCount)); return $allDebts; } + /** + * What to do when no debts found for customer + * + * @param int $clientID AddressBook ID + * @param array $stitky Customer's labels + * + * @return boolean customer well processed + */ + public function everythingPaidOff($clientID, $stitky) + { + return $this->enableCustomer(implode(',', $stitky), $clientID); + } + /** * Enable customer * @@ -106,11 +125,13 @@ function enableCustomer($stitky, $cid) /** * Process All Debts of All Customers * + * @param array $skipLabels Skip Customers (AddressBook) with any of given labels + * * @return int All Debts count */ - public function processAllDebts() + public function processAllDebts($skipLabels = []) { - $allDebths = $this->getDebths(); + $allDebths = $this->getDebths($skipLabels); $this->addStatusMessage(sprintf(_('%d clients to remind process'), count($allDebths))); $counter = 0;