-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathGenerator.php
More file actions
52 lines (39 loc) · 1.65 KB
/
Copy pathGenerator.php
File metadata and controls
52 lines (39 loc) · 1.65 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
<?php
namespace NumNum\UBL;
use Sabre\Xml\Service;
class Generator
{
public static $currencyID;
public static function invoice(Invoice $invoice, $currencyId = 'EUR', array $additionalNamespaces = [])
{
self::$currencyID = $currencyId;
$xmlService = new Service();
$xmlService->namespaceMap = [
'urn:oasis:names:specification:ubl:schema:xsd:' . $invoice->xmlTagName . '-2' => '',
'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' => 'cbc',
'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' => 'cac'
];
if ($invoice->getExtensions()) {
$xmlService->namespaceMap['urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2'] = 'ext';
}
foreach ($additionalNamespaces as $namespace => $prefix) {
$xmlService->namespaceMap[$namespace] = $prefix;
}
return $xmlService->write($invoice->xmlTagName, [
$invoice
]);
}
public static function creditNote(CreditNote $creditNote, $currencyId = 'EUR')
{
self::$currencyID = $currencyId;
$xmlService = new Service();
$xmlService->namespaceMap = [
'urn:oasis:names:specification:ubl:schema:xsd:' . $creditNote->xmlTagName . '-2' => '',
'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' => 'cbc',
'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' => 'cac'
];
return $xmlService->write($creditNote->xmlTagName, [
$creditNote
]);
}
}