-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakturaPrijata.php
More file actions
160 lines (143 loc) · 4.97 KB
/
FakturaPrijata.php
File metadata and controls
160 lines (143 loc) · 4.97 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace AbraFlexi\Processor\Plugins;
/**
* Description of FakturaPrijata
*
* @author vitex
*/
class FakturaPrijata extends \AbraFlexi\Processor\Plugin
{
use \AbraFlexi\subItems;
/**
* Order Data
* @var array
*/
public $orderData = null;
/**
* Handle Incoming change of Incoming Invoice
*
* @param int $id changed record id
* @param array $options
*/
public function __construct($id, $options)
{
\AbraFlexi\Processor\Engine::init(['ABRAFLEXI_OST_ZAVAZEK']);
parent::__construct($id, $options);
}
/**
*
* @var string
*/
public $evidence = 'faktura-prijata';
/**
* Keep History for current object's evidence
* @var boolean
*/
public $keepHistory = true;
/**
* Invoice was inserted. What to do now ?
*
* @return boolean Change was processed. Ok remeber it
*/
public function create()
{
$this->addStatusMessage(sprintf(
'New invoice %s was accepted',
$this->getDataValue('kod')
) . ' ' . $this->getDataValue('firma')->showAs . ' Celkem: ' . $this->getDataValue('sumCelkem') . ' Zbyva uh.: ' . $this->getDataValue('zbyvaUhradit') . ' ' . $this->getDataValue('mena')->showAs);
switch (\AbraFlexi\RO::uncode($this->getDataValue('typDokl'))) {
case 'ZAVAZEK':
$copyer = new \AbraFlexi\Bricks\Convertor(
$this,
new \AbraFlexi\Zavazek(['typDokl' => 'code:' . \Ease\Functions::cfg('OST-ZAVAZEK'), 'stitky' => 'SYSTEM'])
);
$zavazek = $copyer->conversion();
if ($zavazek->sync()) {
$zavazek->addStatusMessage(sprintf(
_('new commitment %s'),
$zavazek->getApiUrl()
), 'success');
if (!$this->deleteFromAbraFlexi()) {
$this->addStatusMessage(sprintf(
'error removig %s',
$this
));
}
} else {
$zavazek->addStatusMessage(sprintf(
_('error creating commitment from %s'),
$this
), 'error');
}
break;
default:
break;
}
return true;
}
/**
* Is invoice Settled
*
* @return boolean
*/
public function bankOrderSent()
{
$changes = $this->getChanges();
return isset($changes['stavUzivK']) && ($changes['datUhr'] == 'stavUziv.celPrikaz') ? true : false;
}
// /**
// * Invoice was updated. What to do now ?
// *
// * @return boolean Change was processed. Ok remeber it
// */
// public function update()
// {
// if ($this->bankOrderSent()) {
// $this->addStatusMessage(sprintf('Bank order to settle Invoice %s was sent',
// $this->getDataValue('kod')));
//
// if (\AbraFlexi\RO::uncode($this->getDataValue('typDokl')) == 'FAKTURA') {
//
// if (!empty($this->getDataValue('kontaktEmail'))) {
// $notify = $this->getDataValue('kontaktEmail');
// } else {
// $adrHelper = new \AbraFlexi\Adresar($this->getDataValue('firma'));
// $notify = \SpojeNet\System\Mailer::getNotificationEmailAddres($adrHelper);
// unset($adrHelper);
// }
//
// if (!empty($notify)) {
//// if (!strstr($this->getDataValue('stitky'), 'SETTLE_NOTIFIED')) {
// $this->setDataValue('email', $notify);
// $potvrzovac = new \SpojeNet\System\PotvrzeniOdeslaniUhrady($this);
// if ($potvrzovac->send()) {
//// $this->insertToAbraFlexi(['id' => $this->getRecordID(),
//// 'stitky' => 'SETTLE_NOTIFIED']);
//// }
// }
// } else {
// $this->addStatusMessage(
// sprintf(_('No notify email for %s %s'),
// \AbraFlexi\RO::uncode($this->getDataValue('firma')),
// \SpojeNet\System\ParovacFaktur::apiUrlToLink($this->apiURL)
// )
// , 'warning');
// }
// }
// }
// return true;
// }
/**
* take deata from attachment order.json
*/
public function loadOrderData()
{
$attachments = \AbraFlexi\Priloha::getAttachmentsList($this);
foreach ($attachments as $attachment) {
if ($attachment['nazSoub'] == 'order.json') {
$orderJson = \AbraFlexi\Priloha::getAttachment($attachment['id']);
$this->orderData = json_decode($orderJson, true)[0];
}
}
}
}