-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportInvoices.php
41 lines (28 loc) · 1.3 KB
/
importInvoices.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
<?php
$url = $_POST['url'] . '?InvoiceNo=' . $_POST['InvoiceNo'];
$InvoiceNotFound = json_encode(array('error'=> array('code' => 404,'reason'=>'Invoice not found')));
$json = file_get_contents($url,TRUE);
$jsonDecoded = json_decode($json,true);
if($json == $InvoiceNotFound) {
echo $InvoiceNotFound;
}
else {
$InvoiceDate = $jsonDecoded['InvoiceDate'];
$CustomerID = $jsonDecoded['CustomerID'];
$InvoiceNo = $jsonDecoded['InvoiceNo'];
$lineArray = $jsonDecoded['Line'];
$TaxPayable = $jsonDecoded['DocumentTotals']['TaxPayable'];
$NetTotal = $jsonDecoded['DocumentTotals']['NetTotal'];
$GrossTotal = $jsonDecoded['DocumentTotals']['GrossTotal'];
$lines = array();
$path = '?InvoiceDate=' . $jsonDecoded['InvoiceDate'] . '&CustomerID=' . $CustomerID;
foreach ($lineArray as $line) {
$taxes = $line['Tax'];
$path .= '&ProductCode[]=' . $line['ProductCode'] . '&Quantity[]=' . $line['Quantity'] . '&UnitPrice[]=' . $line['UnitPrice'] .
'&TaxType[]=' . $taxes['TaxType'] . '&TaxPercentage[]=' . $taxes['TaxPercentage'];
}
$path .= '&TaxPayable=' . $jsonDecoded['DocumentTotals']['TaxPayable'] . '&NetTotal=' . $jsonDecoded['DocumentTotals']['NetTotal'];
$redirect_url = "createInvoice.php" . $path;
header("Location: " . $redirect_url);
}
?>