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)
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);
88 if (isset($_POST['_tran_date_changed'])) {
89 $Ajax->activate('_ex_rate');
90 $supp_trans->tran_date = $_POST['tran_date'];
91 get_duedate_from_terms($supp_trans);
92 $_POST['due_date'] = $supp_trans->due_date;
93 $Ajax->activate('due_date');
96 date_row(_("Due Date") . ":", 'due_date');
98 label_row(_("Terms:"), $supp_trans->terms_description);
102 echo "</td><td class='tableseparator'>"; // outer
104 echo "<table width=100%>";
106 $supplier_currency = get_supplier_currency($supp_trans->supplier_id);
108 $company_currency = get_company_currency();
110 if ($supplier_currency != $company_currency)
112 label_row(_("Supplier's Currency:"), "<b>" . $supplier_currency . "</b>");
113 exchange_rate_display($supplier_currency, $company_currency, $_POST['tran_date']);
116 label_row(_("Tax Group:"), $supp_trans->tax_description);
121 end_table(); // outer
124 //--------------------------------------------------------------------------------------------------
126 function invoice_totals(&$supp_trans)
128 global $table_style, $table_style2;
130 copy_to_trans($supp_trans);
132 start_table("$table_style width=95%");
133 label_row(_("Sub-total:"), price_format( $supp_trans->ov_amount), "align=right", "align=right");
135 $taxes = $supp_trans->get_taxes($supp_trans->tax_group_id);
136 $tax_total = display_edit_tax_items($taxes, 1, 0); // tax_included==0 (we are the company)
138 $display_total = price_format($supp_trans->ov_amount + $tax_total);
140 if ($supp_trans->is_invoice)
141 label_row(_("Invoice Total:"), $display_total, "align=right", "align=right");
143 label_row("<font color=red>" . _("Credit Note Total:") . "</font>",
144 "<font color=red><b>$display_total</b></font>", "align=right", "nowrap align=right");
148 start_table($table_style2);
149 textarea_row(_("Memo:"), "Comments", null, 50, 3);
154 //--------------------------------------------------------------------------------------------------
155 function display_gl_controls(&$supp_trans)
157 global $table_style, $Ajax;
159 div_start('gl_ctrls'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
161 $accs = get_supplier_accounts($supp_trans->supplier_id);
162 $_POST['gl_code'] = $accs['purchase_account'];
164 alt_table_row_color($k);
165 gl_all_accounts_list('gl_code', null, true, false, true);
166 $dim = get_company_pref('use_dimension');
168 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
170 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
171 amount_cells(null, 'amount');
173 text_cells_ex(null, 'memo_', 35, 50, null, null, null, hidden('dimension_id', 0, false).hidden('dimension2_id', 0, false));
175 text_cells_ex(null, 'memo_', 35, 50, null, null, null, hidden('dimension2_id', 0, false));
177 text_cells_ex(null, 'memo_', 35, 50, null, null, null);
178 submit_cells('AddGLCodeToTrans', _("Add"), "",
179 _('Add GL Line'), true);
180 submit_cells('ClearFields', _("Reset"), "",
181 _("Clear all GL entry fields"), true);
186 // $mode = 0 none at the moment
187 // = 1 display on invoice/credit page
188 // = 2 display on view invoice
189 // = 3 display on view credit
191 function display_gl_items(&$supp_trans, $mode=0)
193 global $table_style, $path_to_root;
195 // if displaying in form, and no items, exit
196 if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
201 start_table("width=95%");
202 echo "<tr><td>"; // outertable
204 if ($supp_trans->is_invoice)
205 $heading = _("GL Items for this Invoice");
207 $heading = _("GL Items for this Credit Note");
209 echo "<table width=100%>";
210 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
211 echo "</tr></table>";
213 echo "</td></tr><tr><td>"; // ouer table
215 div_start('gl_items');
216 echo "<table width=100% $table_style>";
218 $dim = get_company_pref('use_dimension');
220 $th = array(_("Account"), _("Name"), _("Dimension")." 1", _("Dimension")." 2", _("Amount"), _("Memo"));
222 $th = array(_("Account"), _("Name"), _("Dimension"), _("Amount"), _("Memo"));
224 $th = array(_("Account"), _("Name"), _("Amount"), _("Memo"));
235 if (count($supp_trans->gl_codes) > 0)
238 foreach ($supp_trans->gl_codes as $entered_gl_code)
241 alt_table_row_color($k);
244 $entered_gl_code->amount = -$entered_gl_code->amount;
246 label_cell($entered_gl_code->gl_code);
247 label_cell($entered_gl_code->gl_act_name);
250 label_cell(get_dimension_string($entered_gl_code->gl_dim, true));
252 label_cell(get_dimension_string($entered_gl_code->gl_dim2, true));
254 amount_cell($entered_gl_code->amount);
255 label_cell($entered_gl_code->memo_);
259 edit_button_cell("Delete2" . $entered_gl_code->Counter, _("Delete"),
260 _('Remove line from document'));
265 $total_gl_value += $entered_gl_code->amount;
277 display_gl_controls(&$supp_trans);
278 $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
279 label_row(_("Total"), price_format($total_gl_value),
280 "colspan=".$colspan." align=right", "nowrap align=right");
287 end_table(); // outertable
288 return $total_gl_value;
291 //--------------//-----------------------------------------------------------------------------------------
293 function display_grn_items_for_selection(&$supp_trans)
297 div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
298 if ($supp_trans->is_invoice)
299 $result = get_grn_items(0, $supp_trans->supplier_id, true);
301 $result = get_grn_items(0, $supp_trans->supplier_id, false, true);
303 if (db_num_rows($result) == 0)
305 if ($supp_trans->is_invoice)
306 display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
309 display_note(_("There are no received items for the selected supplier that have been invoiced."));
310 display_note(_("Credits can only be applied to invoiced items."), 0, 1);
312 div_end(); // Changed 2008-10-18 Joe Hunt
316 /*Set up a table to show the outstanding GRN items for selection */
320 while ($myrow = db_fetch($result))
322 $grn_already_on_invoice = false;
324 foreach ($supp_trans->grn_items as $entered_grn)
326 if ($entered_grn->id == $myrow["id"])
328 $grn_already_on_invoice = true;
331 if ($grn_already_on_invoice == false)
334 alt_table_row_color($k);
337 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
338 label_cell($myrow["id"].
339 hidden('qty_recd'.$n, $myrow["qty_recd"], false).
340 hidden('item_code'.$n, $myrow["item_code"], false).
341 hidden('item_description'.$n, $myrow["description"], false).
342 hidden('prev_quantity_inv'.$n, $myrow['quantity_inv'], false).
343 hidden('order_price'.$n, $myrow['unit_price'], false).
344 hidden('std_cost_unit'.$n, $myrow['std_cost_unit'], false).
345 hidden('po_detail_item'.$n, $myrow['po_detail_item'], false));
346 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
347 label_cell($myrow["item_code"]);
348 label_cell($myrow["description"]);
349 label_cell(sql2date($myrow["delivery_date"]));
350 $dec = get_qty_dec($myrow["item_code"]);
351 qty_cell($myrow["qty_recd"], false, $dec);
352 qty_cell($myrow["quantity_inv"], false, $dec);
353 if ($supp_trans->is_invoice)
354 qty_cells(null, 'this_quantity_inv'.$n, number_format2($myrow["qty_recd"] - $myrow["quantity_inv"], $dec),
357 qty_cells(null, 'This_QuantityCredited'.$n, number_format2(max($myrow["quantity_inv"], 0), $dec),
359 amount_cells(null, 'ChgPrice'.$n, price_format($myrow["unit_price"]));
360 if ($supp_trans->is_invoice)
361 amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]), user_price_dec()));
363 amount_cell(round($myrow["unit_price"] * max($myrow['quantity_inv'], 0), user_price_dec()));
364 if ($supp_trans->is_invoice)
365 submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Invoice"), true);
367 submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Credit Note"), true);
368 if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
369 submit_cells('void_item_id'.$n, _("Remove"), '', _("WARNING! Be careful with removal. The operation is executed immediately and cannot be undone !!!"), true);
377 //------------------------------------------------------------------------------------
379 // $mode = 0 none at the moment
380 // = 1 display on invoice/credit page
381 // = 2 display on view invoice
382 // = 3 display on view credit
384 function display_grn_items(&$supp_trans, $mode=0)
386 global $table_style, $path_to_root;
388 // if displaying in form, and no items, exit
389 if (($mode == 2 || $mode == 3) && count($supp_trans->grn_items) == 0)
392 start_table("width=95%");
393 echo "<tr><td>"; // outertable
397 if ($supp_trans->is_invoice)
399 $heading = _("Items Received Yet to be Invoiced");
400 if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
401 $heading2 = _("WARNING! Be careful with removal. The operation is executed immediately and cannot be undone !!!");
404 $heading = _("Delivery Item Selected For Adding To A Supplier Credit Note");
408 if ($supp_trans->is_invoice)
409 $heading = _("Received Items Charged on this Invoice");
411 $heading = _("Received Items Credited on this Note");
413 echo "<table width=100% >";
414 echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
415 if ($mode == 1 && $heading2 != "")
418 display_note($heading2, 0, 0, "class='overduefg'");
421 echo "</tr></table>";
423 echo "</td></tr><tr><td>"; // outer table
425 div_start('grn_items');
426 echo "<table width=100% $table_style>";
429 $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
430 _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
431 _("Qty Yet To Invoice"), _("Order Price"), _("Total"), "");
432 if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
434 if (!$supp_trans->is_invoice)
436 $th[8] = _("Qty Yet To Credit");
440 $th = array(_("Delivery"), _("Item"), _("Description"),
441 _("Quantity"), _("Price"), _("Line Value"));
444 $total_grn_value = 0;
447 if (count($supp_trans->grn_items) > 0)
450 foreach ($supp_trans->grn_items as $entered_grn)
453 alt_table_row_color($k);
455 $grn_batch = get_grn_batch_from_item($entered_grn->id);
456 label_cell(get_trans_view_str(25,$grn_batch));
459 label_cell($entered_grn->id);
460 label_cell(""); // PO
462 label_cell($entered_grn->item_code);
463 label_cell($entered_grn->item_description);
464 $dec = get_qty_dec($entered_grn->item_code);
468 qty_cell($entered_grn->qty_recd, false, $dec);
469 qty_cell($entered_grn->prev_quantity_inv, false, $dec);
471 qty_cell(abs($entered_grn->this_quantity_inv), false, $dec);
472 amount_cell($entered_grn->chg_price);
473 amount_cell( round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv)), user_price_dec());
477 edit_button_cell("Delete" . $entered_grn->id, _("Delete"),
478 _('Remove item from document'));
479 if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2)
484 $total_grn_value += round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv),
497 display_grn_items_for_selection($supp_trans);
502 label_row(_("Total"), price_format($total_grn_value),
503 "colspan=$colspan align=right", "nowrap align=right");
508 end_table(); // outertable
509 return $total_grn_value;
512 //--------------------------------------------------------------------------------------------------
513 function get_duedate_from_terms(&$supp_trans)
515 if (!is_date($supp_trans->tran_date))
517 $supp_trans->tran_date = Today();
519 if (substr( $supp_trans->terms, 0, 1) == "1")
520 { /*Its a day in the following month when due */
521 $supp_trans->due_date = add_days(end_month($supp_trans->tran_date), (int) substr( $supp_trans->terms,1));
524 { /*Use the Days Before Due to add to the invoice date */
525 $supp_trans->due_date = add_days($supp_trans->tran_date, (int) substr( $supp_trans->terms,1));
529 //--------------------------------------------------------------------------------------------------