/
tiki-view_invoice.php
63 lines (55 loc) · 1.74 KB
/
tiki-view_invoice.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
<?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-view_invoice.php 44444 2013-01-05 21:24:24Z changi67 $
require_once('tiki-setup.php');
$trklib = TikiLib::lib('trk');
$access->check_feature('feature_invoice');
$access->check_permission('tiki_p_admin');
//check if profile is created
if ($trklib->get_tracker_by_name("Invoice Items") < 1) {
$smarty->assign('msg', tra('You need to apply the "Invoice" profile'));
$smarty->display("error.tpl");
die;
}
(int)$_REQUEST['InvoiceId'] = $_REQUEST['InvoiceId'];
$smarty->assign('InvoiceId', $_REQUEST['InvoiceId']);
$invoice = Tracker_Query::tracker("Invoices")
->byName()
->equals($_REQUEST['InvoiceId'])
->getOne();
$amount = 0;
if (is_array($invoice["Item Amounts"])) {
foreach ($invoice["Item Amounts"] as $key => $sum) {
$amount += $invoice["Item Amounts"][$key] * $invoice["Item Quantities"][$key];
}
} else {
$amount = $invoice["Item Amounts"] * $invoice["Item Quantities"];
}
$smarty->assign("invoice", $invoice);
$smarty->assign("amount", $amount);
$smarty->assign(
"client",
Tracker_Query::tracker("Invoice Clients")
->fields(array("Client Id"))->equals(array($invoice['Client Id']))
->byName()
->getOne()
);
$smarty->assign(
"setting",
Tracker_Query::tracker("Invoice Settings")
->byName()
->query()
);
$smarty->assign(
"invoiceItems",
Tracker_Query::tracker("Invoice Items")
->fields(array("Invoice Id"))->equals(array($_REQUEST['InvoiceId']))
->byName()
->query()
);
// Display the template
$smarty->assign('mid', 'tiki-view_invoice.tpl');
$smarty->display("tiki.tpl");