3 //--------------------------------------------------------------------------------------------------
5 function copy_from_trans(&$supp_trans)
7 $_POST['Comments'] = $supp_trans->Comments;
8 $_POST['tran_date'] = $supp_trans->tran_date;
9 $_POST['due_date'] = $supp_trans->due_date;
10 $_POST['supp_reference'] = $supp_trans->supp_reference;
11 $_POST['reference'] = $supp_trans->reference;
12 $_POST['supplier_id'] = $supp_trans->supplier_id;
13 $_POST['tax_group_id'] = $supp_trans->tax_group_id;
16 //--------------------------------------------------------------------------------------------------
18 function copy_to_trans(&$supp_trans)
20 $supp_trans->Comments = $_POST['Comments'];
21 $supp_trans->tran_date = $_POST['tran_date'];
22 $supp_trans->due_date = $_POST['due_date'];
23 $supp_trans->supp_reference = $_POST['supp_reference'];
24 $supp_trans->reference = $_POST['reference'];
25 $supp_trans->tax_group_id = $_POST['tax_group_id'];
28 $supp_trans->ov_amount = 0; /* for starters */
29 if (count($supp_trans->grn_items) > 0)
31 foreach ( $supp_trans->grn_items as $grn)
33 $supp_trans->ov_amount += ($grn->this_quantity_inv * $grn->chg_price);
36 if (count($supp_trans->gl_codes) > 0)
38 foreach ( $supp_trans->gl_codes as $gl_line)
40 $supp_trans->ov_amount += $gl_line->amount;
45 //--------------------------------------------------------------------------------------------------
47 function invoice_header(&$supp_trans)
49 // if vars have been lost, recopy
50 if (!isset($_POST['tran_date']))
51 copy_from_trans($supp_trans);
53 start_table("width=100%", 5);
57 echo "<table width=100%>";
59 if (!isset($_POST['supplier_id']) && (get_global_supplier() != reserved_words::get_all()))
60 $_POST['supplier_id'] = get_global_supplier();
62 supplier_list_row(_("Supplier:"), 'supplier_id', $_POST['supplier_id'], false, true);
64 if ($supp_trans->supplier_id != $_POST['supplier_id'])
66 // supplier has changed
67 // delete all the order items - drastic but necessary because of
68 // change of currency, etc
69 $supp_trans->clear_items();
70 read_supplier_details_to_trans($supp_trans, $_POST['supplier_id']);
71 copy_from_trans($supp_trans);
74 if ($supp_trans->is_invoice)
75 ref_row(_("Reference:"), 'reference', references::get_next(20));
77 ref_row(_("Reference:"), 'reference', references::get_next(21));
79 text_row(_("Supplier's Ref.:"), 'supp_reference', $_POST['supp_reference'], 20, 20);
83 echo "</td><td class='tableseparator'>"; // outer
85 echo "<table width=100%>";
87 date_row(_("Date") . ":", 'tran_date', null, 0, 0, 0, "", true);
89 date_row(_("Due Date") . ":", 'due_date', null);
91 label_row(_("Terms:"), $supp_trans->terms_description);
95 echo "</td><td class='tableseparator'>"; // outer
97 echo "<table width=100%>";
99 $supplier_currency = get_supplier_currency($supp_trans->supplier_id);
101 $company_currency = get_company_currency();
103 if ($supplier_currency != $company_currency)
105 label_row(_("Supplier's Currency:"), "<b>" . $supplier_currency . "</b>");
106 exchange_rate_display($supplier_currency, $company_currency, $_POST['tran_date']);
110 if (!isset($_POST['tax_group_id']))
111 $_POST['tax_group_id'] = $supp_trans->tax_group_id;
112 tax_groups_list_row(_("Tax Group:"), 'tax_group_id', $_POST['tax_group_id'], true);
118 end_table(); // outer
121 //--------------------------------------------------------------------------------------------------
123 function invoice_totals(&$supp_trans)
125 global $table_style, $table_style2;
127 copy_to_trans($supp_trans);
129 start_table("$table_style width=95%");
130 label_row(_("Sub-total:"), number_format2( $supp_trans->ov_amount,user_price_dec()), "align=right", "align=right");
132 $taxes = $supp_trans->get_taxes($_POST['tax_group_id']);
133 $tax_total = display_edit_tax_items($taxes, 1, 0); // tax_included==0 (we are the company)
135 $display_total = number_format2(( $supp_trans->ov_amount + $tax_total), user_price_dec());
137 if ($supp_trans->is_invoice)
138 label_row(_("Invoice Total:"), $display_total, "align=right", "align=right");
140 label_row("<font color=red>" . _("Credit Note Total:") . "</font>",
141 "<font color=red><b>$display_total</b></font>", "align=right", "nowrap align=right");
145 start_table($table_style2);
146 textarea_row(_("Memo:"), "Comments", null, 50, 3);
151 //--------------------------------------------------------------------------------------------------
153 // $mode = 0 display on invoice page
154 // = 1 display on gl items edit page
155 // = 2 display on view invoice
156 // = 3 display on view credit
158 function display_gl_items(&$supp_trans, $mode=0)
160 global $table_style, $path_to_root;
162 if ($mode == 0 && isset($_POST["InvGL"]))
164 copy_to_trans($supp_trans);
165 meta_forward("$path_to_root/purchasing/supplier_trans_gl.php");
169 // if displaying in form, and no items, exit
170 if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
175 start_table("width=95%");
176 echo "<tr><td>"; // outertable
178 if ($supp_trans->is_invoice)
179 $heading = _("GL Items for this Invoice");
181 $heading = _("GL Items for this Credit Note");
183 echo "<table width=100%>";
184 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
187 submit_cells('InvGL', _("Edit"), "align=right");
189 echo "</tr></table>";
191 echo "</td></tr><tr><td>"; // ouer table
193 echo "<table width=100% $table_style>";
195 $dim = get_company_pref('use_dimension');
197 $th = array(_("Account"), _("Name"), _("Dimension")." 1", _("Dimension")." 2", _("Amount"), _("Memo"));
199 $th = array(_("Account"), _("Name"), _("Dimension"), _("Amount"), _("Memo"));
201 $th = array(_("Account"), _("Name"), _("Amount"), _("Memo"));
207 if (count($supp_trans->gl_codes) > 0)
210 foreach ($supp_trans->gl_codes as $entered_gl_code)
213 alt_table_row_color($k);
216 $entered_gl_code->amount = -$entered_gl_code->amount;
218 label_cell($entered_gl_code->gl_code);
219 label_cell($entered_gl_code->gl_act_name);
222 label_cell(get_dimension_string($entered_gl_code->gl_dim, true));
224 label_cell(get_dimension_string($entered_gl_code->gl_dim2, true));
226 amount_cell($entered_gl_code->amount);
227 label_cell($entered_gl_code->memo_);
230 delete_link_cell(SID . "Delete=" . $entered_gl_code->Counter);
234 $total_gl_value += $entered_gl_code->amount;
245 $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
246 label_row(_("Total"), number_format2($total_gl_value,user_price_dec()),
247 "colspan=".$colspan." align=right", "nowrap align=right");
253 end_table(); // outertable
255 return $total_gl_value;
258 //--------------------------------------------------------------------------------------------------
260 // $mode = 0 display on invoice page
261 // = 1 display on grn items edit page
262 // = 2 display on view invoice
263 // = 3 display on view credit
265 function display_grn_items(&$supp_trans, $mode=0)
267 global $table_style, $path_to_root;
269 if ($mode == 0 && isset($_POST["InvGRN"]))
271 copy_to_trans($supp_trans);
272 if ($supp_trans->is_invoice)
273 meta_forward("$path_to_root/purchasing/supplier_invoice_grns.php");
275 meta_forward("$path_to_root/purchasing/supplier_credit_grns.php");
279 // if displaying in form, and no items, exit
280 if (($mode == 2 || $mode == 3) && count($supp_trans->grn_items) == 0)
283 start_table("width=95%");
284 echo "<tr><td>"; // outertable
286 if ($supp_trans->is_invoice)
287 $heading = _("Received Items Charged on this Invoice");
289 $heading = _("Received Items Credited on this Note");
291 echo "<table width=100% >";
292 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
295 submit_cells('InvGRN', _("Edit"), "align=right");
297 echo "</tr></table>";
299 echo "</td></tr><tr><td>"; // outer table
301 echo "<table width=100% $table_style>";
302 $th = array(_("Delivery Sequence #"), _("Item"), _("Description"),
303 _("Quantity"), _("Price"), _("Line Value"));
306 $total_grn_value = 0;
309 if (count($supp_trans->grn_items) > 0)
312 foreach ($supp_trans->grn_items as $entered_grn)
315 alt_table_row_color($k);
317 label_cell(get_trans_view_str(25,$entered_grn->id));
318 label_cell($entered_grn->item_code);
319 label_cell($entered_grn->item_description);
320 qty_cell(abs($entered_grn->this_quantity_inv));
321 amount_cell($entered_grn->chg_price);
322 amount_cell($entered_grn->chg_price * abs($entered_grn->this_quantity_inv));
325 delete_link_cell(SID . "Delete=" . $entered_grn->id);
329 $total_grn_value += ($entered_grn->chg_price * abs($entered_grn->this_quantity_inv));
340 label_row(_("Total"), number_format2($total_grn_value,user_price_dec()),
341 "colspan=5 align=right", "nowrap align=right");
346 end_table(); // outertable
348 return $total_grn_value;
351 //--------------------------------------------------------------------------------------------------
352 function get_duedate_from_terms(&$supp_trans)
354 if (!is_date($supp_trans->tran_date))
356 $supp_trans->tran_date = Today();
358 if (substr( $supp_trans->terms, 0, 1) == "1")
359 { /*Its a day in the following month when due */
360 $supp_trans->due_date = add_days(end_month($supp_trans->tran_date), (int) substr( $supp_trans->terms,1));
363 { /*Use the Days Before Due to add to the invoice date */
364 $supp_trans->due_date = add_days($supp_trans->tran_date, (int) substr( $supp_trans->terms,1));
368 //--------------------------------------------------------------------------------------------------