Issues (103)

Examples/FindOverdueInvoices.php (2 issues)

1
#!/usr/bin/php -f
2
<?php
3
/**
4
 * FlexiPeeHP - Example how to find overdue invoices
5
 *
6
 * @author     Vítězslav Dvořák <[email protected]>
7
 * @copyright  (G) 2017 Vitex Software
8
 */
9
10
namespace Example\FlexiPeeHP;
11
12
include_once './config.php';
13
include_once '../vendor/autoload.php';
14
15
/**
16
 * Get Number of days overdue
17
 *
18
 * @param string $dueDate FlexiBee date
19
 * @return int
20
 */
21
function poSplatnosti($dueDate)
22
{
23
    return intval(date_diff(\FlexiPeeHP\FlexiBeeRO::flexiDateToDateTime($dueDate),
24
            new \DateTime())->format('%a'));
25
}
26
27
/**
28
 * Vrať faktury po splatnosti
29
 *
30
 * @param \FlexiPeeHP\FakturaVydana $invoicer
31
 * @return array
32
 */
33
function getOverdueInvoices($invoicer)
34
{
35
    $result                                  = null;
36
    $invoicer->defaultUrlParams['order']     = 'datVyst@A';
37
    $invoicer->defaultUrlParams['relations'] = 'adresar,kontakt';
38
    $invoices                                = $invoicer->getColumnsFromFlexibee([
0 ignored issues
show
Deprecated Code introduced by
The function FlexiPeeHP\RO::getColumnsFromFlexiBee() has been deprecated: since version 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
    $invoices                                = /** @scrutinizer ignore-deprecated */ $invoicer->getColumnsFromFlexibee([

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
39
        'id',
40
        'kod',
41
        'stavUhrK',
42
        'firma',
43
        'buc',
44
        'varSym',
45
        'specSym',
46
        'sumCelkem',
47
        'duzpPuv',
48
        'datSplat',
49
        'datVyst'],
50
        "(stavUhrK is null OR stavUhrK eq 'stavUhr.castUhr') AND storno eq false",
51
        'id');
52
53
    if ($invoicer->lastResponseCode == 200) {
54
        $result = $invoices;
55
    }
56
    return $result;
57
}
58
$statuser = new \FlexiPeeHP\Status();
59
$invoicer = new \FlexiPeeHP\FakturaVydana();
60
$firmer   = new \FlexiPeeHP\Adresar();
61
62
foreach (getOverdueInvoices($invoicer) as $invoice) {
63
    $kontakt = $firmer->getColumnsFromFlexibee(['nazev', 'email'],
0 ignored issues
show
Deprecated Code introduced by
The function FlexiPeeHP\RO::getColumnsFromFlexiBee() has been deprecated: since version 2.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

63
    $kontakt = /** @scrutinizer ignore-deprecated */ $firmer->getColumnsFromFlexibee(['nazev', 'email'],

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
64
        ['id' => $invoice['firma']]);
65
66
    if (isset($kontakt[0]['email'])) {
67
        $invoicer->setMyKey($invoice['id']);
68
69
        $to      = $kontakt[0]['email'];
70
        $subject = sprintf(_('Overdue invoice: %s - %s days'), $invoice['kod'],
71
            poSplatnosti($invoice['datSplat']));
72
        $body    = sprintf(_('Please pay %s,-'), $invoice['sumCelkem']);
73
74
        if ($statuser->getDataValue('licenseVariant') == 'basic') {
75
            $mail = new \Ease\Mailer($to, $subject, $body);
76
            $mail->addFile($invoicer->downloadInFormat('pdf', '/tmp/'));
77
            $mail->addFile($invoicer->downloadInFormat('isdoc', '/tmp/'));
78
            $mail->send();
79
        } else {
80
            if ($invoicer->sendByMail($to, $subject, $body)) {
81
                $invoicer->addStatusMessage(spritnf(_('Message sent: %s to %s'),
82
                        $subject, $to), 'mail');
83
            }
84
        }
85
    }
86
}
87