Passed
Push — master ( c19d9e...2cc707 )
by Vítězslav
24:55
created

getOverdueInvoices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 25
rs 9.6333
cc 2
nc 2
nop 1
1
#!/usr/bin/php -f
2
<?php
3
/**
4
 * FlexiPeeHP - Odeslat Upomínky ?
5
 *
6
 * @author     Vítězslav Dvořák <[email protected]>
7
 * @copyright  (G) 2017-2019 Vitex Software
8
 */
9
10
namespace Example\FlexiPeeHP;
11
12
include_once './config.php';
13
include_once '../vendor/autoload.php';
14
15
$invoicer = new \FlexiPeeHP\FakturaVydana();
16
17
function getOverdueInvoices($invoicer)
18
{
19
20
21
    $result                                  = null;
22
    $invoicer->defaultUrlParams['order']     = 'datVyst@A';
23
    $invoicer->defaultUrlParams['relations'] = 'adresar,kontakt';
24
    $invoices                                = $invoicer->getColumnsFromFlexibee([
25
        'id',
26
        'kod',
27
        'stavUhrK',
28
        'firma',
29
        'buc',
30
        'varSym',
31
        'specSym',
32
        'sumCelkem',
33
        'duzpPuv',
34
        'datVyst'],
35
        "(stavUhrK is null OR stavUhrK eq 'stavUhr.castUhr') AND storno eq false",
36
        'id');
37
38
    if ($invoicer->lastResponseCode == 200) {
39
        $result = $invoices;
40
    }
41
    return $result;
42
}
43
$firmer = new \FlexiPeeHP\Adresar();
44
45
foreach (getOverdueInvoices($invoicer) as $invoice) {
46
    $invoicer->setData($invoice, true);
47
48
    $firmer->setMyKey($invoicer->getDataValue('firma'));
49
50
    $mail = new \Ease\Mailer($firmer->getNotificationEmailAddress(),
51
        sprintf(_('Overdue invoice: %s'), $invoice['kod']),
52
        sprintf(_('Please pay %s,-'), $invoice['sumCelkem']));
53
54
    $mail->addFile($invoicer->downloadInFormat('pdf', '/tmp/'),
55
        \FlexiPeeHP\Formats::$formats['PDF']['content-type']);
56
    $mail->addFile($invoicer->downloadInFormat('isdocx', '/tmp/'),
57
        \FlexiPeeHP\Formats::$formats['ISDOCx']['content-type']);
58
59
    $mail->send();
60
}
61