This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
InvoiceCopy.php
82 lines (71 loc) · 2.53 KB
/
InvoiceCopy.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
74
75
76
77
78
79
80
81
82
#!/usr/bin/php -f
<?php
/**
* FlexiPeeHP - Example how to copy Invoice
*
* @author Vítězslav Dvořák <[email protected]>
* @copyright (G) 2017 Vitex Software
*/
namespace Example\FlexiPeeHP;
include_once './config.php';
include_once '../vendor/autoload.php';
/**
* Copy an invoice to new one
*
* @param \FlexiPeeHP\FakturaVydana $invoice
* @param array $extraValues Extra values for invoice Copy
*
* @return \FlexiPeeHP\FakturaVydana
*/
function invoiceCopy(\FlexiPeeHP\FakturaVydana $invoice, $extraValues = [])
{
$invoice2 = new \FlexiPeeHP\FakturaVydana(array_merge(
$extraValues, $invoice->getData()));
$invoice2->unsetDataValue('id');
$invoice2->unsetDataValue('kod');
if ($invoice2->getDataValue('stavUhrK') != 'stavUhr.uhrazenoRucne') {
$invoice2->unsetDataValue('stavUhrK');
}
$invoiceItems = $invoice2->getDataValue('polozkyFaktury');
if (count($invoiceItems)) {
foreach ($invoiceItems as $pid => $invoiceItem) {
unset($invoiceItems[$pid]['id']);
unset($invoiceItems[$pid]['doklFak']);
unset($invoiceItems[$pid]['doklFak@showAs']);
unset($invoiceItems[$pid]['doklFak@ref']);
}
$invoice2->setDataValue('polozkyFaktury', $invoiceItems);
// $invoice2->addArrayToBranch($invoiceItems, 'polozkyFaktury');
}
$invoice2->setDataValue('typDokl', 'code:FAKTURA');
$invoice2->unsetDataValue('external-ids');
$today = date('Y-m-d');
$invoice2->setDataValue('duzpPuv', $today);
$invoice2->setDataValue('duzpUcto', $today);
$invoice2->setDataValue('datUcto', $today);
$invoice2->insertToFlexiBee();
if ($invoice2->lastResponseCode == 201) {
$invoice->addStatusMessage(sprintf(_('Invoice copy from %s to id:%s done'),
(string) $invoice, (string) $invoice2), 'success');
}
return $invoice2;
}
include_once './common.php';
$invoiceID = askForFlexiBeeID();
/*
* FlexiPeeHP Classes accept this form of initial identifier:
*
* (int) 2588
* (string) ext:ESHOP:oi1978
* (array) ['varSym'=>'20080015']
*/
$originalInvoice = new \FlexiPeeHP\FakturaVydana($invoiceID);
if ($originalInvoice->getMyKey()) {
$invoiceCopy = invoiceCopy($originalInvoice,
['poznam' => 'FlexiPeeHP php library example - this is copy of '.$invoiceID]);
if ($invoiceCopy->lastResponseCode == 201) {
echo $invoiceCopy->getEvidenceURL().'/'.(string) $invoiceCopy;
}
} else {
$originalInvoice->addStatusMessage('Source Invoice does not exists');
}