-
Notifications
You must be signed in to change notification settings - Fork 8
/
NewInvoice.php
73 lines (61 loc) · 2.07 KB
/
NewInvoice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/php -f
<?php
declare(strict_types=1);
/**
* This file is part of the EaseCore package.
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Example\AbraFlexi;
use AbraFlexi\FakturaVydana;
use AbraFlexi\RO;
\define('EASE_LOGGER', 'syslog|console');
include_once './config.php';
include_once '../vendor/autoload.php';
/**
* Prepare Testing Invoice.
*
* @param array $initialData
* @param mixed $dayBack
* @param mixed $evidence
*
* @return FakturaVydana
*/
function makeInvoice($initialData = [], $dayBack = 1, $evidence = 'vydana')
{
$yesterday = new \DateTime();
$yesterday->modify('-'.$dayBack.' day');
$testCode = 'INV_'.\Ease\Sand::randomString();
$invoice = new FakturaVydana(null, ['evidence' => 'faktura-'.$evidence]);
$invoice->takeData(array_merge([
'kod' => $testCode,
'varSym' => \Ease\Sand::randomNumber(1111, 9999),
'specSym' => \Ease\Sand::randomNumber(111, 999),
'bezPolozek' => true,
'popis' => 'php-abraflexi-matcher Test invoice',
'datVyst' => RO::dateToFlexiDate($yesterday),
'typDokl' => RO::code('FAKTURA'),
], $initialData));
if ($invoice->sync()) {
$invoice->addStatusMessage($invoice->getApiURL().' '.
RO::uncode($invoice->getDataValue('typDokl')).' '.
RO::uncode($invoice->getRecordIdent()).' '.
RO::uncode($invoice->getDataValue('sumCelkem')).' '.
RO::uncode($invoice->getDataValue('mena')), 'success');
} else {
$invoice->addStatusMessage(json_encode($invoice->getData()), 'debug');
}
return $invoice;
}
$invoice = makeInvoice(['id' => 'ext:example:1']);
// Set due date by DateTime object
$nextMonth = new \DateTime();
$nextMonth->modify('+1 month');
$invoice->setDataValue('datSplat', $nextMonth);
$invoice->addStatusMessage(
_('Invoice').': '.$invoice->getRecordIdent().' '.$invoice->getRecordCode(),
$invoice->sync() ? 'success' : 'error',
);