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;
15 //--------------------------------------------------------------------------------------------------
17 function copy_to_trans(&$supp_trans)
19 $supp_trans->Comments = $_POST['Comments'];
20 $supp_trans->tran_date = $_POST['tran_date'];
21 $supp_trans->due_date = $_POST['due_date'];
22 $supp_trans->supp_reference = $_POST['supp_reference'];
23 $supp_trans->reference = $_POST['reference'];
25 $supp_trans->ov_amount = 0; /* for starters */
26 if (count($supp_trans->grn_items) > 0)
28 foreach ( $supp_trans->grn_items as $grn)
30 $supp_trans->ov_amount += round(($grn->this_quantity_inv * $grn->chg_price),
34 if (count($supp_trans->gl_codes) > 0)
36 foreach ( $supp_trans->gl_codes as $gl_line)
38 $supp_trans->ov_amount += $gl_line->amount;
43 //--------------------------------------------------------------------------------------------------
45 function invoice_header(&$supp_trans)
47 // if vars have been lost, recopy
48 if (!isset($_POST['tran_date']))
49 copy_from_trans($supp_trans);
51 start_table("width=100%", 5);
55 echo "<table width=100%>";
57 if (!isset($_POST['supplier_id']) && (get_global_supplier() != reserved_words::get_all()))
58 $_POST['supplier_id'] = get_global_supplier();
60 supplier_list_row(_("Supplier:"), 'supplier_id', $_POST['supplier_id'], false, true);
62 if ($supp_trans->supplier_id != $_POST['supplier_id'])
64 // supplier has changed
65 // delete all the order items - drastic but necessary because of
66 // change of currency, etc
67 $supp_trans->clear_items();
68 read_supplier_details_to_trans($supp_trans, $_POST['supplier_id']);
69 copy_from_trans($supp_trans);
72 if ($supp_trans->is_invoice)
73 ref_row(_("Reference:"), 'reference', '', references::get_next(20));
75 ref_row(_("Reference:"), 'reference', '', references::get_next(21));
77 text_row(_("Supplier's Ref.:"), 'supp_reference', $_POST['supp_reference'], 20, 20);
81 echo "</td><td class='tableseparator'>"; // outer
83 echo "<table width=100%>";
85 date_row(_("Date") . ":", 'tran_date', '', null, 0, 0, 0, "", true);
87 date_row(_("Due Date") . ":", 'due_date');
89 label_row(_("Terms:"), $supp_trans->terms_description);
93 echo "</td><td class='tableseparator'>"; // outer
95 echo "<table width=100%>";
97 $supplier_currency = get_supplier_currency($supp_trans->supplier_id);
99 $company_currency = get_company_currency();
101 if ($supplier_currency != $company_currency)
103 label_row(_("Supplier's Currency:"), "<b>" . $supplier_currency . "</b>");
104 exchange_rate_display($supplier_currency, $company_currency, $_POST['tran_date']);
107 label_row(_("Tax Group:"), $supp_trans->tax_description);
112 end_table(); // outer
115 //--------------------------------------------------------------------------------------------------
117 function invoice_totals(&$supp_trans)
119 global $table_style, $table_style2;
121 copy_to_trans($supp_trans);
123 start_table("$table_style width=95%");
124 label_row(_("Sub-total:"), price_format( $supp_trans->ov_amount), "align=right", "align=right");
126 $taxes = $supp_trans->get_taxes($supp_trans->tax_group_id);
127 $tax_total = display_edit_tax_items($taxes, 1, 0); // tax_included==0 (we are the company)
129 $display_total = price_format($supp_trans->ov_amount + $tax_total);
131 if ($supp_trans->is_invoice)
132 label_row(_("Invoice Total:"), $display_total, "align=right", "align=right");
134 label_row("<font color=red>" . _("Credit Note Total:") . "</font>",
135 "<font color=red><b>$display_total</b></font>", "align=right", "nowrap align=right");
139 start_table($table_style2);
140 textarea_row(_("Memo:"), "Comments", null, 50, 3);
145 //--------------------------------------------------------------------------------------------------
147 // $mode = 0 display on invoice page
148 // = 1 display on gl items edit page
149 // = 2 display on view invoice
150 // = 3 display on view credit
152 function display_gl_items(&$supp_trans, $mode=0)
154 global $table_style, $path_to_root;
156 if ($mode == 0 && isset($_POST["InvGL"]))
158 copy_to_trans($supp_trans);
159 meta_forward("$path_to_root/purchasing/supplier_trans_gl.php");
163 // if displaying in form, and no items, exit
164 if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
169 start_table("width=95%");
170 echo "<tr><td>"; // outertable
172 if ($supp_trans->is_invoice)
173 $heading = _("GL Items for this Invoice");
175 $heading = _("GL Items for this Credit Note");
177 echo "<table width=100%>";
178 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
181 submit_cells('InvGL', _("Edit"), "align=right");
183 echo "</tr></table>";
185 echo "</td></tr><tr><td>"; // ouer table
187 echo "<table width=100% $table_style>";
189 $dim = get_company_pref('use_dimension');
191 $th = array(_("Account"), _("Name"), _("Dimension")." 1", _("Dimension")." 2", _("Amount"), _("Memo"));
193 $th = array(_("Account"), _("Name"), _("Dimension"), _("Amount"), _("Memo"));
195 $th = array(_("Account"), _("Name"), _("Amount"), _("Memo"));
201 if (count($supp_trans->gl_codes) > 0)
204 foreach ($supp_trans->gl_codes as $entered_gl_code)
207 alt_table_row_color($k);
210 $entered_gl_code->amount = -$entered_gl_code->amount;
212 label_cell($entered_gl_code->gl_code);
213 label_cell($entered_gl_code->gl_act_name);
216 label_cell(get_dimension_string($entered_gl_code->gl_dim, true));
218 label_cell(get_dimension_string($entered_gl_code->gl_dim2, true));
220 amount_cell($entered_gl_code->amount);
221 label_cell($entered_gl_code->memo_);
224 delete_link_cell(SID . "Delete=" . $entered_gl_code->Counter);
228 $total_gl_value += $entered_gl_code->amount;
239 $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
240 label_row(_("Total"), price_format($total_gl_value),
241 "colspan=".$colspan." align=right", "nowrap align=right");
247 end_table(); // outertable
249 return $total_gl_value;
252 //--------------------------------------------------------------------------------------------------
254 // $mode = 0 display on invoice page
255 // = 1 display on grn items edit page
256 // = 2 display on view invoice
257 // = 3 display on view credit
259 function display_grn_items(&$supp_trans, $mode=0)
261 global $table_style, $path_to_root;
263 if ($mode == 0 && isset($_POST["InvGRN"]))
265 copy_to_trans($supp_trans);
266 if ($supp_trans->is_invoice)
267 meta_forward("$path_to_root/purchasing/supplier_invoice_grns.php");
269 meta_forward("$path_to_root/purchasing/supplier_credit_grns.php");
273 // if displaying in form, and no items, exit
274 if (($mode == 2 || $mode == 3) && count($supp_trans->grn_items) == 0)
277 start_table("width=95%");
278 echo "<tr><td>"; // outertable
280 if ($supp_trans->is_invoice)
281 $heading = _("Received Items Charged on this Invoice");
283 $heading = _("Received Items Credited on this Note");
285 echo "<table width=100% >";
286 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
289 submit_cells('InvGRN', _("Edit"), "align=right");
291 echo "</tr></table>";
293 echo "</td></tr><tr><td>"; // outer table
295 echo "<table width=100% $table_style>";
296 $th = array(_("Delivery Sequence #"), _("Item"), _("Description"),
297 _("Quantity"), _("Price"), _("Line Value"));
300 $total_grn_value = 0;
303 if (count($supp_trans->grn_items) > 0)
306 foreach ($supp_trans->grn_items as $entered_grn)
309 alt_table_row_color($k);
311 label_cell(get_trans_view_str(25,$entered_grn->id));
312 label_cell($entered_grn->item_code);
313 label_cell($entered_grn->item_description);
314 qty_cell(abs($entered_grn->this_quantity_inv), false, get_qty_dec($entered_grn->item_code));
315 amount_cell($entered_grn->chg_price);
316 amount_cell( round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv)), user_price_dec());
319 delete_link_cell(SID . "Delete=" . $entered_grn->id);
323 $total_grn_value += round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv),
335 label_row(_("Total"), price_format($total_grn_value),
336 "colspan=5 align=right", "nowrap align=right");
341 end_table(); // outertable
343 return $total_grn_value;
346 //--------------------------------------------------------------------------------------------------
347 function get_duedate_from_terms(&$supp_trans)
349 if (!is_date($supp_trans->tran_date))
351 $supp_trans->tran_date = Today();
353 if (substr( $supp_trans->terms, 0, 1) == "1")
354 { /*Its a day in the following month when due */
355 $supp_trans->due_date = add_days(end_month($supp_trans->tran_date), (int) substr( $supp_trans->terms,1));
358 { /*Use the Days Before Due to add to the invoice date */
359 $supp_trans->due_date = add_days($supp_trans->tran_date, (int) substr( $supp_trans->terms,1));
363 //--------------------------------------------------------------------------------------------------