-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathInvoicTest.php
executable file
·151 lines (135 loc) · 4.44 KB
/
InvoicTest.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
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
<?php
namespace GeneratorTest;
use EDI\Encoder;
use EDI\Generator\EdifactException;
use EDI\Generator\Interchange;
use EDI\Generator\Invoic;
use PHPUnit\Framework\TestCase;
/**
* Class InvoicTest
* @package GeneratorTest
*/
final class InvoicTest extends TestCase
{
public function testBeginOfMessage()
{
$encoder = new Encoder(
[Invoic::addBGMSegment('INV1234', '380')],
true
);
$this->assertEquals(
'BGM+380::89+INV1234\'',
$encoder->get()
);
}
public function testFreeText()
{
$this->assertEquals(
'FTX+OSI++HAE:89+reduction of fees text\'',
(new Encoder([
Invoic::addFTXSegment(
'reduction of fees text',
'OSI',
'HAE'
)]))->get()
);
}
public function testCurrency()
{
$this->assertEquals(
'CUX+2:EUR:9\'',
(new Encoder([
(new Invoic)->setCurrency()->getCurrency()]))->get()
);
}
public function testInvoice()
{
$interchange = (new Interchange(
'UNB-Identifier-Sender',
'UNB-Identifier-Receiver'
))
->setCharset('UNOC', '3');
$invoice = new Invoic();
try {
$invoice
->setInvoiceNumber('INV12345')
->setInvoiceDate($this->getDateTime())
->setDeliveryDate($this->getDateTime())
->setReductionOfFeesText('reduction')
->setExcludingVatText('excluding Vat text with more as 70 characters used for testing')
->setInvoiceDescription('invoiceDescription')
->setManufacturerAddress(
'Name 1',
'Name 2',
'Name 3',
'Street',
'99999',
'city',
'DE'
)->setWholesalerAddress(
'Name 1',
'Name 2',
'Name 3',
'Street',
'99999',
'city',
'DE'
)->setDeliveryAddress(
'Name 1',
'Name 2',
'Name 3',
'Street',
'99999',
'city',
'DE'
)->setContactPerson('John Doe')
->setMailAddress('john.doe@company.com')
->setPhoneNumber('+49123456789')
->setFaxNumber('+49123456789-11')
->setVatNumber('DE 123456789')
->setCurrency('EUR')
;
$item = new Invoic\Item();
$item
->setPosition('1', 'articleId')
->setQuantity('5')
->setAdditionalText('additionalText')
->setInvoiceDescription('this is a longer description for testing inside item position')
->setNetPrice('22.50')
->setGrossPrice('26.775')
->setOrderNumberWholeSaler('545.SWEB-05622249-002')
->setOrderDate($this->getDateTime())
->setDeliveryNotePosition('20')
->setDeliveryNoteNumber('deliverNoteNumber')
->setDeliveryNoteDate($this->getDateTime())
;
$item->addDiscount(-20.34, Invoic\Item::DISCOUNT_TYPE_ABSOLUTE);
$item->addDiscount(3);
$invoice->addItem($item);
$invoice
->setTotalPositionsAmount(100.22)
->setBasisAmount(80)
->setTaxableAmount(80)
->setPayableAmount(100.22)
->setTax(19, 19.11);
$invoice->compose();
$encoder = new Encoder($interchange->addMessage($invoice)->getComposed(), true);
$encoder->setUNA(":+,? '");
$message = str_replace("'", "'\n", $encoder->get());
// fwrite(STDOUT, "\n\nINVOICE\n" . $message);
$this->assertStringContainsString('UNT+40', $message);
} catch (EdifactException $e) {
fwrite(STDOUT, "\n\nINVOICE\n" . $e->getMessage());
}
}
/**
* @return \DateTime
* @throws \Exception
*/
private function getDateTime()
{
return (new \DateTime())
->setDate(2018, 1, 23)
->setTime(10, 0, 0);
}
}