4 // ----------------------------------------------------------------
8 // Title: Print Invoices
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "sales/includes/sales_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
22 //----------------------------------------------------------------------------------------------------
24 function print_invoices()
28 include_once($path_to_root . "reporting/includes/pdf_report.inc");
30 $from = $_POST['PARAM_0'];
31 $to = $_POST['PARAM_1'];
32 $currency = $_POST['PARAM_2'];
33 $bankaccount = $_POST['PARAM_3'];
34 $email = $_POST['PARAM_4'];
35 $paylink = $_POST['PARAM_5'];
36 $comments = $_POST['PARAM_6'];
42 $dec =user_price_dec();
44 $fno = explode("-", $from);
45 $tno = explode("-", $to);
47 $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
49 // $headers in doctext.inc
50 $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
52 $params = array('comments' => $comments,
53 'bankaccount' => $bankaccount);
55 $baccount = get_bank_account($params['bankaccount']);
56 $cur = get_company_Pref('curr_default');
60 $rep = new FrontReport(_('INVOICE'), "InvoiceBulk.pdf", user_pagesize());
61 $rep->currency = $cur;
63 $rep->Info($params, $cols, null, $aligns);
66 for ($i = $fno[0]; $i <= $tno[0]; $i++)
68 for ($j = 10; $j <= 11; $j++)
70 if (isset($_POST['PARAM_7']) && $_POST['PARAM_7'] != $j)
72 if (!exists_customer_trans($j, $i))
74 $myrow = get_customer_trans($i, $j);
75 $branch = get_branch($myrow["branch_code"]);
76 $branch['disable_branch'] = $paylink; // helper
78 $sales_order = get_sales_order($myrow["order_"]);
83 $rep = new FrontReport("", "", user_pagesize());
84 $rep->currency = $cur;
88 $rep->title = _('INVOICE');
89 $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
93 $rep->title = _('CREDIT NOTE');
94 $rep->filename = "CreditNote" . $myrow['reference'] . ".pdf";
96 $rep->Info($params, $cols, null, $aligns);
99 $rep->title = ($j == 10) ? _('INVOICE') : _('CREDIT NOTE');
100 $rep->Header2($myrow, $branch, $sales_order, $baccount, $j);
102 $result = get_customer_trans_details($j, $i);
104 while ($myrow2=db_fetch($result))
106 $Net = ((1 - $myrow2["discount_percent"]) * $myrow2["FullUnitPrice"] * -$myrow2["quantity"]);
108 $DisplayPrice = number_format2($myrow2["FullUnitPrice"],$dec);
109 $DisplayQty = number_format2(-$myrow2["quantity"],user_qty_dec());
110 $DisplayNet = number_format2($Net,$dec);
111 if ($myrow2["discount_percent"]==0)
112 $DisplayDiscount ="";
114 $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
115 $rep->TextCol(0, 1, $myrow2['stock_id'], -2);
116 $rep->TextCol(1, 2, $myrow2['StockDescription'], -2);
117 $rep->TextCol(2, 3, $DisplayQty, -2);
118 $rep->TextCol(3, 4, $myrow2['units'], -2);
119 $rep->TextCol(4, 5, $DisplayPrice, -2);
120 $rep->TextCol(5, 6, $DisplayDiscount, -2);
121 $rep->TextCol(6, 7, $DisplayNet, -2);
123 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
124 $rep->Header2($myrow, $branch, $sales_order, $baccount,$j);
127 $comments = get_comments($j, $i);
128 if ($comments && db_num_rows($comments))
131 while ($comment=db_fetch($comments))
132 $rep->TextColLines(0, 6, $comment['memo_'], -2);
135 $DisplaySubTot = number_format2($SubTotal,$dec);
136 $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
138 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
141 if ($rep->currency != $myrow['curr_code'])
143 include($path_to_root . "reporting/includes/doctext2.inc");
147 include($path_to_root . "reporting/includes/doctext.inc");
150 $rep->TextCol(3, 6, $doc_Sub_total, -2);
151 $rep->TextCol(6, 7, $DisplaySubTot, -2);
153 $rep->TextCol(3, 6, $doc_Shipping, -2);
154 $rep->TextCol(6, 7, $DisplayFreight, -2);
156 $tax_items = get_customer_trans_tax_details($j, $i);
157 while ($tax_item = db_fetch($tax_items))
159 $DisplayTax = number_format2($tax_item['amount'], $dec);
160 if ($tax_item['included_in_price'])
162 $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] .
163 " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
167 $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" .
168 $tax_item['rate'] . "%)", -2);
169 $rep->TextCol(6, 7, $DisplayTax, -2);
174 $DisplayTotal = number_format2($myrow["ov_freight"] + $myrow["ov_gst"] +
175 $myrow["ov_amount"],$dec);
177 $rep->TextCol(3, 6, $doc_TOTAL_INVOICE, - 2);
178 $rep->TextCol(6, 7, $DisplayTotal, -2);
182 $myrow['dimension_id'] = $paylink; // helper for pmt link
183 if ($myrow['email'] == '')
185 $myrow['email'] = $branch['email'];
186 $myrow['DebtorName'] = $branch['br_name'];
188 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow, $j);