-
Notifications
You must be signed in to change notification settings - Fork 15
/
pohoda.php
62 lines (47 loc) · 1.99 KB
/
pohoda.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
<?php
class Pohoda {
public static $NS_INVOICE = 'http://www.stormware.cz/schema/version_2/invoice.xsd';
public static $NS_TYPE = 'http://www.stormware.cz/schema/version_2/type.xsd';
public $ico = '';
private $invoices = [];
private $lastId = 0;
public function __construct($ico) {
$this->ico = $ico;
}
public function setInvoice($invoice) {
$this->invoices[] = $invoice;
}
public function exportToFile($exportId, $application, $fileName, $errorsNo, $note = '') {
$xml = $this->export($exportId, $application, $note);
$incomplete = '';
if ($errorsNo > 0) {
$incomplete = '_incomplete';
}
$xml->asXML(dirname(__FILE__).'/'.$fileName.'_lastId-'.$this->lastId.$incomplete.'.xml');
}
public function exportAsXml($exportId, $application, $note = '') {
header ("Content-Type:text/xml; charset=utf-8");
$xml = $this->export($exportId, $application, $note);
echo $xml->asXML();
}
public function exportAsString($exportId, $application, $note = '') {
$xml = $this->export($exportId, $application, $note);
echo $xml->asXML();
}
private function export($exportId, $application, $note = '') {
$xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dat:dataPack id=\"".$exportId."\" ico=\"".$this->ico."\" application=\"".$application."\" version = \"2.0\" note=\"".$note."\" xmlns:dat=\"http://www.stormware.cz/schema/version_2/data.xsd\"></dat:dataPack>";
$xml = simplexml_load_string($xmlText);
$i = 0;
foreach ($this->invoices as $item) {
$i++;
$dataItem = $xml->addChild("dat:dataPackItem");
$dataItem->addAttribute('version', "2.0");
$dataItem->addAttribute('id', $exportId . '-' . $i);
$item->export($dataItem);
if ($item->varNum > $this->lastId) {
$this->lastId = $item->varNum;
}
}
return $xml;
}
}