! -> Note
$ -> Affected files
+23-Oct-2008 Joe Hunt
+! Merging the changes up to 2-0-4
+$ /purchasing/supplier_invoice.php
+ /purchasing/supplier_credit.php
+ /purchasing/includes/db/invoice_db.inc
+ /purchasing/includes/db/grn_db.inc
+ /purchasing/includes/ui/invoice_ui.inc
+ /purchasing/supplier_invoice_grns.php (File removed)
+ /purchasing/supplier_credit_grns.php (File removed)
+ /purchasing/supplier_trans_gl.php (File removed)
+ /gl/inquiry/gl_trial_balance.php
+ /gl/inquiry/gl_account_inquiry.php
+ /reporting/rep704.php
+ /reporting/rep708.php
+ /sql/en_US-demo.sql
+ /sales/includes/ui/sales_order_ui.inc
+ /sales/inquiry/sales_orders_view.php
+
20-Oct-2008 Janusz Dobrowolski
# Fix for pdf reports (php 5.2.4 issue)
$ /reporting/includes/pdf_report.inc
else
{
$begin = begin_fiscalyear();
- if ($_POST['TransFromDate'] < $begin)
+ if (date1_greater_date2($begin, $_POST['TransFromDate']))
$begin = $_POST['TransFromDate'];
$begin = add_days($begin, -1);
}
$k = 0;
+ $totprev = $totcurr = 0.0;
$accounts = get_gl_accounts();
while ($account = db_fetch($accounts))
else
{
$begin = begin_fiscalyear();
- if ($_POST['TransFromDate'] < $begin)
+ if (date1_greater_date2($begin, $_POST['TransFromDate']))
$begin = $_POST['TransFromDate'];
$begin = add_days($begin, -1);
}
$curr_balance = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate']);
if (check_value("NoZero") && !$prev_balance && !$curr_balance)
continue;
+ $totprev += $prev_balance;
+ $totcurr += $curr_balance;
alt_table_row_color($k);
$url = "<a href='$path_to_root/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
display_debit_or_credit_cells($prev_balance + $curr_balance);
end_row();
}
+ start_row("class='inquirybg'");
+ label_cell("<b>" . _("Ending Balance") ." - ".$_POST['TransToDate']. "</b>", "colspan=2");
+ display_debit_or_credit_cells($totprev);
+ display_debit_or_credit_cells($totcurr);
+ display_debit_or_credit_cells($totprev + $totcurr);
+ end_row();
end_table(1);
div_end();
return $row[0];
}
+function get_grn_batch($grn)
+{
+ $sql = "SELECT * FROM ".TB_PREF."grn_batch WHERE id=$grn";
+ $result = db_query($sql, "Could not retreive GRN batch id");
+ return db_fetch($result);
+}
+
function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
{
$mcost = update_average_material_cost($supplier, $entered_grn->item_code,
{
$amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
-
- add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
- $amt, null, null, null,
- "The general ledger transaction could not be added for the price variance of the inventory item");
- add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
- 0, 0, _("Cost diff."), -$amt, null, null, null,
- "The general ledger transaction could not be added for the price variance of the inventory item");
+ if ($amt != 0.0)
+ {
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+ $amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+ 0, 0, _("Cost diff."), -$amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ }
update_stock_move_pid(13, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
}
update_stock_move_pid(25, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
// now remove this invoice/credit from any GRNs/POs that it's related to
if (db_num_rows($result) > 0)
{
+ $date_ = Today();
while ($details_row = db_fetch($result))
{
if (strlen($details_row["grn_item_id"]) > 0) // it can be empty for GL items
{
- update_supp_received_items_for_invoice($details_row["grn_item_id"],
- $details_row["po_detail_item_id"], -$details_row["quantity"]);
+ // Changed 2008-10-17 by Joe Hunt to get the avg. material cost updated
+ $old = update_supp_received_items_for_invoice($details_row["grn_item_id"],
+ $details_row["po_detail_item_id"], -$details_row["quantity"], $details_row["FullUnitPrice"]);
+
+ $diff = $details_row["FullUnitPrice"] - $old[2];
+ $old_date = sql2date($old[1]);
+
+ $batch = get_grn_batch_from_item($details_row["grn_item_id"]);
+ $grn = get_grn_batch($batch);
+
+ // Only adjust the avg for the diff
+ $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"],
+ $diff, -$details_row["quantity"], $date_, true);
+
+ $deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_);
+ if ($deliveries[0] != 0) // have deliveries been done during the period?
+ {
+
+ $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
+ if ($amt != 0.0)
+ {
+ $stock_gl_code = get_stock_gl_code($details_row["stock_id"]);
+ add_gl_trans($type, $type_no, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+ -$amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ add_gl_trans($type, $type_no, $date_, $stock_gl_code["inventory_account"],
+ 0, 0, _("Cost diff."), $amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ }
+ update_stock_move_pid(13, $details_row["stock_id"], $old_date, $date_, 0, $mat_cost);
+ }
+ update_stock_move_pid(25, $details_row["stock_id"], $old_date, $old_date, $grn['supplier_id'], $mat_cost);
+
}
}
}
}
//--------------------------------------------------------------------------------------------------
+function display_gl_controls(&$supp_trans)
+{
+ global $table_style, $Ajax;
+
+ div_start('gl_ctrls'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
+
+ $accs = get_supplier_accounts($supp_trans->supplier_id);
+ $_POST['gl_code'] = $accs['purchase_account'];
+ $k = 0;
+ alt_table_row_color($k);
+ gl_all_accounts_list('gl_code', null, true, false, true);
+ $dim = get_company_pref('use_dimension');
+ if ($dim >= 1)
+ dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
+ if ($dim > 1)
+ dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
+ amount_cells(null, 'amount');
+ if ($dim < 1)
+ text_cells_ex(null, 'memo_', 35, 50, null, null, null, hidden('dimension_id', 0, false).hidden('dimension2_id', 0, false));
+ else if ($dim < 2)
+ text_cells_ex(null, 'memo_', 35, 50, null, null, null, hidden('dimension2_id', 0, false));
+ else
+ text_cells_ex(null, 'memo_', 35, 50, null, null, null);
+ submit_cells('AddGLCodeToTrans', _("Add"), "",
+ _('Add GL Line'), true);
+ submit_cells('ClearFields', _("Reset"), "",
+ _("Clear all GL entry fields"), true);
+ end_row();
+ div_end();
+}
-// $mode = 0 display on invoice page
-// = 1 display on gl items edit page
+// $mode = 0 none at the moment
+// = 1 display on invoice/credit page
// = 2 display on view invoice
// = 3 display on view credit
{
global $table_style, $path_to_root;
- if ($mode == 0 && isset($_POST["InvGL"]))
- {
- copy_to_trans($supp_trans);
- meta_forward("$path_to_root/purchasing/supplier_trans_gl.php");
- exit;
- }
-
// if displaying in form, and no items, exit
if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
- return;
+ return 0;
echo "<br>";
echo "<table width=100%>";
echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
- if ($mode == 0)
- {
- submit_cells('InvGL', _("Edit"), "align=right",
- _('Moves to additional costs posting page'), true);
- }
echo "</tr></table>";
echo "</td></tr><tr><td>"; // ouer table
else
$th = array(_("Account"), _("Name"), _("Amount"), _("Memo"));
+ if ($mode == 1)
+ {
+ $th[] = "";
+ $th[] = "";
+ }
table_header($th);
$total_gl_value=0;
$i = $k = 0;
label_cell($entered_gl_code->memo_);
if ($mode == 1)
- edit_button_cell("Delete" . $entered_gl_code->Counter, _("Delete"),
+ {
+ edit_button_cell("Delete2" . $entered_gl_code->Counter, _("Delete"),
_('Remove line from document'));
-
+ label_cell("");
+ }
end_row();
$total_gl_value += $entered_gl_code->amount;
}
}
+ if ($mode == 1)
+ display_gl_controls(&$supp_trans);
$colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
label_row(_("Total"), price_format($total_gl_value),
"colspan=".$colspan." align=right", "nowrap align=right");
return $total_gl_value;
}
-//--------------------------------------------------------------------------------------------------
-
-// $mode = 0 display on invoice page
-// = 1 display on grn items edit page
-// = 2 display on view invoice
-// = 3 display on view credit
+//--------------//-----------------------------------------------------------------------------------------
-function display_grn_items(&$supp_trans, $mode=0)
+function display_grn_items_for_selection(&$supp_trans)
{
- global $table_style, $path_to_root;
+ global $table_style;
- if ($mode == 0 && isset($_POST["InvGRN"]))
+ div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
+ if ($supp_trans->is_invoice)
+ $result = get_grn_items(0, $supp_trans->supplier_id, true);
+ else
+ $result = get_grn_items(0, $supp_trans->supplier_id, false, true);
+
+ if (db_num_rows($result) == 0)
{
- copy_to_trans($supp_trans);
if ($supp_trans->is_invoice)
- meta_forward("$path_to_root/purchasing/supplier_invoice_grns.php");
+ display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
else
- meta_forward("$path_to_root/purchasing/supplier_credit_grns.php");
- exit;
+ {
+ display_note(_("There are no received items for the selected supplier that have been invoiced."));
+ display_note(_("Credits can only be applied to invoiced items."), 0, 1);
+ }
+ div_end(); // Changed 2008-10-18 Joe Hunt
+ return;
+ }
+
+ /*Set up a table to show the outstanding GRN items for selection */
+
+ $k = 0;
+
+ while ($myrow = db_fetch($result))
+ {
+ $grn_already_on_invoice = false;
+
+ foreach ($supp_trans->grn_items as $entered_grn)
+ {
+ if ($entered_grn->id == $myrow["id"])
+ {
+ $grn_already_on_invoice = true;
+ }
+ }
+ if ($grn_already_on_invoice == false)
+ {
+
+ alt_table_row_color($k);
+
+ $n = $myrow["id"];
+ label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
+ label_cell($myrow["id"].
+ hidden('qty_recd'.$n, $myrow["qty_recd"], false).
+ hidden('item_code'.$n, $myrow["item_code"], false).
+ hidden('item_description'.$n, $myrow["description"], false).
+ hidden('prev_quantity_inv'.$n, $myrow['quantity_inv'], false).
+ hidden('order_price'.$n, $myrow['unit_price'], false).
+ hidden('std_cost_unit'.$n, $myrow['std_cost_unit'], false).
+ hidden('po_detail_item'.$n, $myrow['po_detail_item'], false));
+ label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
+ label_cell($myrow["item_code"]);
+ label_cell($myrow["description"]);
+ label_cell(sql2date($myrow["delivery_date"]));
+ $dec = get_qty_dec($myrow["item_code"]);
+ qty_cell($myrow["qty_recd"], false, $dec);
+ qty_cell($myrow["quantity_inv"], false, $dec);
+ if ($supp_trans->is_invoice)
+ qty_cells(null, 'this_quantity_inv'.$n, number_format2($myrow["qty_recd"] - $myrow["quantity_inv"], $dec),
+ null, null, $dec);
+ else
+ qty_cells(null, 'This_QuantityCredited'.$n, number_format2(max($myrow["quantity_inv"], 0), $dec),
+ null, null, $dec);
+ amount_cells(null, 'ChgPrice'.$n, price_format($myrow["unit_price"]));
+ if ($supp_trans->is_invoice)
+ amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]), user_price_dec()));
+ else
+ amount_cell(round($myrow["unit_price"] * max($myrow['quantity_inv'], 0), user_price_dec()));
+ if ($supp_trans->is_invoice)
+ submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Invoice"), true);
+ else
+ submit_cells('grn_item_id'.$n, _("Add"), '', _("Add to Credit Note"), true);
+ if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+ submit_cells('void_item_id'.$n, _("Remove"), '', _("WARNING! Be careful with removal. The operation is executed immediately and cannot be undone !!!"), true);
+ end_row();
+ }
}
+ div_end();
+}
+
+//------------------------------------------------------------------------------------
+
+// $mode = 0 none at the moment
+// = 1 display on invoice/credit page
+// = 2 display on view invoice
+// = 3 display on view credit
+
+function display_grn_items(&$supp_trans, $mode=0)
+{
+ global $table_style, $path_to_root;
+
// if displaying in form, and no items, exit
if (($mode == 2 || $mode == 3) && count($supp_trans->grn_items) == 0)
- return;
+ return 0;
br(1);
start_table("width=95%");
echo "<tr><td>"; // outertable
-
- if ($supp_trans->is_invoice)
- $heading = _("Received Items Charged on this Invoice");
+ $heading2 = "";
+ if ($mode == 1)
+ {
+ if ($supp_trans->is_invoice)
+ {
+ $heading = _("Items Received Yet to be Invoiced");
+ if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+ $heading2 = _("WARNING! Be careful with removal. The operation is executed immediately and cannot be undone !!!");
+ }
+ else
+ $heading = _("Delivery Item Selected For Adding To A Supplier Credit Note");
+ }
else
- $heading = _("Received Items Credited on this Note");
+ {
+ if ($supp_trans->is_invoice)
+ $heading = _("Received Items Charged on this Invoice");
+ else
+ $heading = _("Received Items Credited on this Note");
+ }
echo "<table width=100% >";
echo "<tr><td align=center><span class='headingtext'>$heading</span></td>";
- if ($mode == 0)
+ if ($mode == 1 && $heading2 != "")
{
- submit_cells('InvGRN', _("Edit"), "align=right",
- _('Moves to GRN selection page'), true);
- }
+ echo "</tr><td>";
+ display_note($heading2, 0, 0, "class='overduefg'");
+ echo "</td>\n";
+ }
echo "</tr></table>";
echo "</td></tr><tr><td>"; // outer table
- div_start('grn_items');
+ div_start('grn_items');
echo "<table width=100% $table_style>";
- $th = array(_("Delivery"), _("Item"), _("Description"),
- _("Quantity"), _("Price"), _("Line Value"));
+ if ($mode == 1)
+ {
+ $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
+ _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
+ _("Qty Yet To Invoice"), _("Order Price"), _("Total"), "");
+ if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+ $th[] = "";
+ if (!$supp_trans->is_invoice)
+ {
+ $th[8] = _("Qty Yet To Credit");
+ }
+ }
+ else
+ $th = array(_("Delivery"), _("Item"), _("Description"),
+ _("Quantity"), _("Price"), _("Line Value"));
table_header($th);
$total_grn_value = 0;
$grn_batch = get_grn_batch_from_item($entered_grn->id);
label_cell(get_trans_view_str(25,$grn_batch));
+ if ($mode == 1)
+ {
+ label_cell($entered_grn->id);
+ label_cell(""); // PO
+ }
label_cell($entered_grn->item_code);
label_cell($entered_grn->item_description);
- qty_cell(abs($entered_grn->this_quantity_inv), false, get_qty_dec($entered_grn->item_code));
+ $dec = get_qty_dec($entered_grn->item_code);
+ if ($mode == 1)
+ {
+ label_cell("");
+ qty_cell($entered_grn->qty_recd, false, $dec);
+ qty_cell($entered_grn->prev_quantity_inv, false, $dec);
+ }
+ qty_cell(abs($entered_grn->this_quantity_inv), false, $dec);
amount_cell($entered_grn->chg_price);
amount_cell( round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv)), user_price_dec());
if ($mode == 1)
+ {
edit_button_cell("Delete" . $entered_grn->id, _("Delete"),
_('Remove item from document'));
-
+ if ($supp_trans->is_invoice && $_SESSION["wa_current_user"]->access == 2)
+ label_cell("");
+ }
end_row();
$total_grn_value += round($entered_grn->chg_price * abs($entered_grn->this_quantity_inv),
}
}
}
-
+ if ($mode == 1)
+ {
+ display_grn_items_for_selection($supp_trans);
+ $colspan = 10;
+ }
+ else
+ $colspan = 5;
label_row(_("Total"), price_format($total_grn_value),
- "colspan=5 align=right", "nowrap align=right");
+ "colspan=$colspan align=right", "nowrap align=right");
echo "</table>";
div_end();
echo "</td></tr>";
$_SESSION['supp_trans']->is_invoice = false;
}
+function clear_fields()
+{
+ global $Ajax;
+
+ unset($_POST['gl_code']);
+ unset($_POST['dimension_id']);
+ unset($_POST['dimension2_id']);
+ unset($_POST['amount']);
+ unset($_POST['memo_']);
+ unset($_POST['AddGLCodeToTrans']);
+ $Ajax->activate('gl_ctrls');
+ set_focus('gl_code');
+}
+//------------------------------------------------------------------------------------------------
+// GL postings are often entered in the same form to two accounts
+// so fileds are cleared only on user demand.
+//
+if (isset($_POST['ClearFields']))
+{
+ clear_fields();
+}
+
+if (isset($_POST['AddGLCodeToTrans'])){
+
+ $Ajax->activate('gl_items');
+ $input_error = false;
+
+ $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
+ $result = db_query($sql,"get account information");
+ if (db_num_rows($result) == 0)
+ {
+ display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
+ set_focus('gl_code');
+ $input_error = true;
+ }
+ else
+ {
+ $myrow = db_fetch_row($result);
+ $gl_act_name = $myrow[1];
+ if (!check_num('amount'))
+ {
+ display_error(_("The amount entered is not numeric. This line cannot be added to the transaction."));
+ set_focus('amount');
+ $input_error = true;
+ }
+ }
+
+ if ($input_error == false)
+ {
+ $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
+ $_POST['dimension_id'], $_POST['dimension2_id'],
+ input_num('amount'), $_POST['memo_']);
+ set_focus('gl_code');
+ }
+}
+
+
//---------------------------------------------------------------------------------------------------
function check_data()
handle_commit_credit_note();
}
+function check_item_data($n)
+{
+ if (!check_num('This_QuantityCredited'.$n, 0))
+ {
+ display_error(_("The quantity to credit must be numeric and greater than zero."));
+ set_focus('This_QuantityCredited'.$n);
+ return false;
+ }
+
+ if (!check_num('ChgPrice'.$n, 0))
+ {
+ display_error(_("The price is either not numeric or negative."));
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------------------
+
+$id = find_submit('grn_item_id');
+if ($id != -1)
+{
+ if (check_item_data($id))
+ {
+ $complete = False;
+
+ //$_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
+ // $_POST['po_detail_item'], $_POST['item_code'],
+ // $_POST['item_description'], $_POST['qty_recd'],
+ // $_POST['prev_quantity_inv'], $_POST['This_QuantityCredited'],
+ // $_POST['order_price'], $_POST['ChgPrice'], $complete,
+ // $_POST['std_cost_unit'], $_POST['gl_code']);
+ $_SESSION['supp_trans']->add_grn_to_trans($id,
+ $_POST['po_detail_item'.$id], $_POST['item_code'.$id],
+ $_POST['item_description'.$id], $_POST['qty_recd'.$id],
+ $_POST['prev_quantity_inv'.$id], input_num('This_QuantityCredited'.$id),
+ $_POST['order_price'.$id], input_num('ChgPrice'.$id), $complete,
+ $_POST['std_cost_unit'.$id], "");
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+$id = find_submit('Delete');
+if ($id != -1)
+{
+ $_SESSION['supp_trans']->remove_grn_from_trans($id);
+ $Ajax->activate('grn_items');
+ $Ajax->activate('grn_table');
+ $Ajax->activate('inv_tot');
+}
+
+$id = find_submit('Delete2');
+if ($id != -1)
+{
+ $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
+ clear_fields();
+ $Ajax->activate('gl_items');
+ $Ajax->activate('inv_tot');
+}
+
+
//--------------------------------------------------------------------------------------------------
start_form(false, true);
-start_table("$table_style width=80%", 8);
+start_table("$table_style width=98%", 8);
echo "<tr><td valign=center>"; // outer table
echo "<center>";
else {
echo "</td></tr><tr><td valign=center>"; // outer table
- $total_grn_value = display_grn_items($_SESSION['supp_trans']);
+ $total_grn_value = display_grn_items($_SESSION['supp_trans'], 1);
- $total_gl_value = display_gl_items($_SESSION['supp_trans']);
+ $total_gl_value = display_gl_items($_SESSION['supp_trans'], 1);
echo "</td></tr><tr><td align=center colspan=2>"; // outer table
-
+ div_start('inv_tot');
invoice_totals($_SESSION['supp_trans']);
+ div_end();
}
echo "</td></tr>";
end_table(1); // outer table
+$id = find_submit('grn_item_id');
+if ($id != -1)
+{
+ $Ajax->activate('grn_table');
+ $Ajax->activate('grn_items');
+ $Ajax->activate('inv_tot');
+}
+
+if (get_post('AddGLCodeToTrans'))
+ $Ajax->activate('inv_tot');
+
+
submit_center('PostCreditNote', _("Enter Credit Note"), true, '', true);
echo "<br><br>";
+++ /dev/null
-<?php
-
-$page_security = 5;
-$path_to_root="..";
-
-include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
-include_once($path_to_root . "/includes/session.inc");
-include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
-include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
-
-$js = "";
-if ($use_date_picker)
- $js .= get_js_date_picker();
-if ($use_popup_windows)
- $js .= get_js_open_window(900, 500);
-page(_("Select Received Items to Add"), false, false, "", $js);
-
-if (!isset($_SESSION['supp_trans']))
-{
- display_note(_("To enter supplier transactions the supplier must first be selected from the supplier selection screen, then the link to enter a supplier credit note must be clicked on."));
- exit;
- /*It all stops here if there aint no supplier selected and credit note initiated ie $_SESSION['supp_trans'] started off*/
-}
-
-//-----------------------------------------------------------------------------------------
-
-display_heading($_SESSION['supp_trans']->supplier_name);
-echo "<br>";
-
-//-----------------------------------------------------------------------------------------
-
-function check_data()
-{
- if (!check_num('This_QuantityCredited', 0))
- {
- display_error(_("The quantity to credit must be numeric and greater than zero."));
- set_focus('This_QuantityCredited');
- return false;
- }
-
- if (!check_num('ChgPrice', 0))
- {
- display_error(_("The price is either not numeric or negative."));
- set_focus('ChgPrice');
- return false;
- }
-
- return true;
-}
-
-//-----------------------------------------------------------------------------------------
-
-if (isset($_POST['AddGRNToTrans']))
-{
-
- if (check_data())
- {
- $complete = False;
-
- //$_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
- // $_POST['po_detail_item'], $_POST['item_code'],
- // $_POST['item_description'], $_POST['qty_recd'],
- // $_POST['prev_quantity_inv'], $_POST['This_QuantityCredited'],
- // $_POST['order_price'], $_POST['ChgPrice'], $complete,
- // $_POST['std_cost_unit'], $_POST['gl_code']);
- $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
- $_POST['po_detail_item'], $_POST['item_code'],
- $_POST['item_description'], $_POST['qty_recd'],
- $_POST['prev_quantity_inv'], input_num('This_QuantityCredited'),
- $_POST['order_price'], input_num('ChgPrice'), $complete,
- $_POST['std_cost_unit'], "");
- }
-}
-
-//-----------------------------------------------------------------------------------------
-$id = find_submit('Delete');
-if ($id != -1)
-{
- $_SESSION['supp_trans']->remove_grn_from_trans($id);
- $Ajax->activate('grn_items');
- $Ajax->activate('grn_table');
-}
-
-//-----------------------------------------------------------------------------------------
-start_form(false,true);
-display_grn_items($_SESSION['supp_trans'], 1);
-end_form();
-echo "<br>";
-
-hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Return to Credit Note Entry"));
-echo "<hr>";
-
-//-----------------------------------------------------------------------------------------
-
-// get the supplier grns that have been invoiced
-$result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, false, true);
-
-if (db_num_rows($result) == 0)
-{
- display_note(_("There are no received items for the selected supplier that have been invoiced."));
- display_note(_("Credits can only be applied to invoiced items."));
-
- echo "<br>";
- end_page();
- exit;
-}
-
-/*Set up a table to show the GRN items outstanding for selection */
-start_form(false, true);
-
-div_start('grn_table');
-start_table("$table_style width=95%");
-$th = array(_("Delivery"), _("Sequence #"), _("Order"), _("Item Code"), _("Description"),
- _("Delivered"), _("Total Qty Received"), _("Qty Already Invoiced"),
- _("Qty Yet To Invoice"), _("Order Price"), _("Line Value"));
-table_header($th);
-$i = $k =0;
-while ($myrow = db_fetch($result))
-{
-
- $grn_already_on_credit = False;
-
- foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
- {
- if ($entered_grn->id == $myrow["id"])
- {
- $grn_already_on_credit = True;
- }
- }
- if ($grn_already_on_credit == False)
- {
-
- alt_table_row_color($k);
-
- label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
- submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
- label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
- label_cell($myrow["item_code"]);
- label_cell($myrow["description"]);
- label_cell(sql2date($myrow["delivery_date"]));
- $dec = get_qty_dec($myrow["item_code"]);
- qty_cell($myrow["qty_recd"], false, $dec);
- qty_cell($myrow["quantity_inv"], false, $dec);
- qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
- amount_cell($myrow["unit_price"]);
- amount_cell(round($myrow["unit_price"] * $myrow["quantity_inv"], user_price_dec()));
- end_row();
- $i++;
- if ($i > 15)
- {
- $i = 0;
- table_header($th);
- }
- }
-}
-
-end_table();
-div_end();
-
-//-----------------------------------------------------------------------------------------
-$id = find_submit('grn_item_id');
-if ($id || get_post('AddGRNToTrans'))
-{
- $Ajax->activate('grn_selector');
-}
-if (get_post('AddGRNToTrans'))
-{
- $Ajax->activate('grn_table');
- $Ajax->activate('grn_items');
-}
-
-
-div_start('grn_selector');
-$id = find_submit('grn_item_id');
-if ($id != -1)
-{
-
- $myrow = get_grn_item_detail($id);
-
- echo "<br>";
- display_heading2(_("Delivery Item Selected For Adding To A Supplier Credit Note"));
- start_table("$table_style width=80%");
- $th = array(_("Sequence #"), _("Item"), _("Qty Already Invoiced"),
- _("Quantity to Credit"), _("Order Price"), _("Credit Price"));
- table_header($th);
-
- start_row();
- label_cell($id);
- label_cell($myrow['item_code'] . " " . $myrow['description']);
- $dec = get_qty_dec($myrow['item_code']);
- qty_cell($myrow["quantity_inv"], false, $dec);
- qty_cells(null, 'This_QuantityCredited', number_format2(max($myrow['quantity_inv'],0), $dec), null, null, $dec);
- amount_cell($myrow['unit_price']);
- amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
- end_row();
- end_table(1);
-
- submit_center('AddGRNToTrans', _("Add to Credit Note"), true, '', true);
-
- hidden('GRNNumber', $id);
- hidden('item_code', $myrow['item_code']);;
- hidden('item_description', $myrow['description']);
- hidden('qty_recd', $myrow['qty_recd']);
- hidden('prev_quantity_inv', $myrow['quantity_inv']);
- hidden('order_price', $myrow['unit_price']);
- hidden('std_cost_unit', $myrow['std_cost_unit']);
-
- hidden('po_detail_item', $myrow['po_detail_item']);
-}
-div_end();
-
-end_form();
-echo '<br>';
-end_page(false, true);
-?>
}
//--------------------------------------------------------------------------------------------------
+function clear_fields()
+{
+ global $Ajax;
+
+ unset($_POST['gl_code']);
+ unset($_POST['dimension_id']);
+ unset($_POST['dimension2_id']);
+ unset($_POST['amount']);
+ unset($_POST['memo_']);
+ unset($_POST['AddGLCodeToTrans']);
+ $Ajax->activate('gl_ctrls');
+ set_focus('gl_code');
+}
+//------------------------------------------------------------------------------------------------
+// GL postings are often entered in the same form to two accounts
+// so fileds are cleared only on user demand.
+//
+if (isset($_POST['ClearFields']))
+{
+ clear_fields();
+}
+
+if (isset($_POST['AddGLCodeToTrans'])){
+
+ $Ajax->activate('gl_items');
+ $input_error = false;
+
+ $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
+ $result = db_query($sql,"get account information");
+ if (db_num_rows($result) == 0)
+ {
+ display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
+ set_focus('gl_code');
+ $input_error = true;
+ }
+ else
+ {
+ $myrow = db_fetch_row($result);
+ $gl_act_name = $myrow[1];
+ if (!check_num('amount'))
+ {
+ display_error(_("The amount entered is not numeric. This line cannot be added to the transaction."));
+ set_focus('amount');
+ $input_error = true;
+ }
+ }
+
+ if ($input_error == false)
+ {
+ $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
+ $_POST['dimension_id'], $_POST['dimension2_id'],
+ input_num('amount'), $_POST['memo_']);
+ set_focus('gl_code');
+ }
+}
+
+//------------------------------------------------------------------------------------------------
function check_data()
{
handle_commit_invoice();
}
+function check_item_data($n)
+{
+ global $check_price_charged_vs_order_price,
+ $check_qty_charged_vs_del_qty;
+ if (!check_num('this_quantity_inv'.$n, 0) || input_num('this_quantity_inv'.$n)==0)
+ {
+ display_error( _("The quantity to invoice must be numeric and greater than zero."));
+ set_focus('this_quantity_inv'.$n);
+ return false;
+ }
+
+ if (!check_num('ChgPrice'.$n))
+ {
+ display_error( _("The price is not numeric."));
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+
+ if ($check_price_charged_vs_order_price == True)
+ {
+ if ($_POST['order_price'.$n]!=input_num('ChgPrice'.$n)) {
+ if ($_POST['order_price'.$n]==0 ||
+ input_num('ChgPrice'.$n)/$_POST['order_price'.$n] >
+ (1 + (sys_prefs::over_charge_allowance() / 100)))
+ {
+ display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
+ _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+ }
+ }
+
+ if ($check_qty_charged_vs_del_qty == True)
+ {
+ if (input_num('this_quantity_inv'.$n) / ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]) >
+ (1+ (sys_prefs::over_charge_allowance() / 100)))
+ {
+ display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
+ . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+ set_focus('this_quantity_inv'.$n);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+$id = find_submit('grn_item_id');
+if ($id != -1)
+{
+ if (check_item_data($id))
+ {
+ if (input_num('this_quantity_inv'.$id) >= ($_POST['qty_recd'.$id] - $_POST['prev_quantity_inv'.$id]))
+ {
+ $complete = true;
+ }
+ else
+ {
+ $complete = false;
+ }
+
+ $_SESSION['supp_trans']->add_grn_to_trans($id, $_POST['po_detail_item'.$id],
+ $_POST['item_code'.$id], $_POST['item_description'.$id], $_POST['qty_recd'.$id],
+ $_POST['prev_quantity_inv'.$id], input_num('this_quantity_inv'.$id),
+ $_POST['order_price'.$id], input_num('ChgPrice'.$id), $complete,
+ $_POST['std_cost_unit'.$id], "");
+ }
+}
+
//--------------------------------------------------------------------------------------------------
+$id = find_submit('Delete');
+if ($id != -1)
+{
+ $_SESSION['supp_trans']->remove_grn_from_trans($id);
+ $Ajax->activate('grn_items');
+ $Ajax->activate('grn_table');
+ $Ajax->activate('inv_tot');
+}
+
+$id = find_submit('Delete2');
+if ($id != -1)
+{
+ $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
+ clear_fields();
+ $Ajax->activate('gl_items');
+ $Ajax->activate('inv_tot');
+}
start_form(false, true);
-start_table("$table_style2 width=80%", 8);
+start_table("$table_style2 width=98%", 8);
echo "<tr><td valign=center>"; // outer table
echo "<center>";
echo "<center>";
- display_grn_items($_SESSION['supp_trans']);
-
- display_gl_items($_SESSION['supp_trans']);
+ display_grn_items($_SESSION['supp_trans'], 1);
+ //display_grn_items_for_selection();
+ display_gl_items($_SESSION['supp_trans'], 1);
+ //display_gl_controls();
//echo "</td></tr><tr><td align=center colspan=2>"; // outer table
echo "<br>";
+ div_start('inv_tot');
invoice_totals($_SESSION['supp_trans']);
+ div_end();
}
echo "</td></tr>";
end_table(); // outer table
+//-----------------------------------------------------------------------------------------
+$id = find_submit('grn_item_id');
+$id2 = find_submit('void_item_id');
+if ($id != -1 || $id2 != -1)
+{
+ $Ajax->activate('grn_table');
+ $Ajax->activate('grn_items');
+ $Ajax->activate('inv_tot');
+}
+
+if (get_post('AddGLCodeToTrans'))
+ $Ajax->activate('inv_tot');
+
+if ($_SESSION["wa_current_user"]->access == 2)
+{
+ if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
+ {
+ begin_transaction();
+
+ $myrow = get_grn_item_detail($id2);
+
+ $grn = get_grn_batch($myrow['grn_batch_id']);
+
+ $sql = "UPDATE ".TB_PREF."purch_order_details
+ SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
+ db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
+
+ $sql = "UPDATE ".TB_PREF."grn_items
+ SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
+ db_query($sql, "The quantity invoiced off the items received record could not be updated");
+
+ update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
+ $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
+
+ add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+ -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+
+ commit_transaction();
+ }
+}
+
echo "<br>";
submit_center('PostInvoice', _("Enter Invoice"), true, '', true);
echo "<br>";
+++ /dev/null
-<?php
-
-$page_security = 5;
-$path_to_root="..";
-
-include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
-include_once($path_to_root . "/includes/session.inc");
-include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
-include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
-
-$js = "";
-if ($use_date_picker)
- $js .= get_js_date_picker();
-if ($use_popup_windows)
- $js .= get_js_open_window(900, 500);
-page(_("Select Received Items to Add"), false, false, "", $js);
-
-if (!isset($_SESSION['supp_trans']))
-{
- display_note("To enter supplier transactions the supplier must first be selected from the supplier selection screen, then the link to enter a supplier credit note must be clicked on.", 1, 0);;
- exit;
-}
-
-//-----------------------------------------------------------------------------------------
-
-display_heading($_SESSION['supp_trans']->supplier_name);
-
-echo "<br>";
-
-//-----------------------------------------------------------------------------------------
-
-function check_data()
-{
- global $check_price_charged_vs_order_price,
- $check_qty_charged_vs_del_qty;
- if (!check_num('this_quantity_inv', 0) || input_num('this_quantity_inv')==0)
- {
- display_error( _("The quantity to invoice must be numeric and greater than zero."));
- set_focus('this_quantity_inv');
- return false;
- }
-
- if (!check_num('ChgPrice'))
- {
- display_error( _("The price is not numeric."));
- set_focus('ChgPrice');
- return false;
- }
-
- if ($check_price_charged_vs_order_price == True)
- {
- if ($_POST['order_price']!=input_num('ChgPrice')) {
- if ($_POST['order_price']==0 ||
- input_num('ChgPrice')/$_POST['order_price'] >
- (1 + (sys_prefs::over_charge_allowance() / 100)))
- {
- display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
- _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
- set_focus('ChgPrice');
- return false;
- }
- }
- }
-
- if ($check_qty_charged_vs_del_qty == True)
- {
- if (input_num('this_quantity_inv') / ($_POST['qty_recd'] - $_POST['prev_quantity_inv']) >
- (1+ (sys_prefs::over_charge_allowance() / 100)))
- {
- display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
- . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
- set_focus('this_quantity_inv');
- return false;
- }
- }
-
- return true;
-}
-
-//-----------------------------------------------------------------------------------------
-
-if (isset($_POST['AddGRNToTrans']))
-{
-
- if (check_data())
- {
- if (input_num('this_quantity_inv') >= ($_POST['qty_recd'] - $_POST['prev_quantity_inv']))
- {
- $complete = true;
- }
- else
- {
- $complete = false;
- }
-
- $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
- $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
- $_POST['prev_quantity_inv'], input_num('this_quantity_inv'),
- $_POST['order_price'], input_num('ChgPrice'), $complete,
- $_POST['std_cost_unit'], "");
- }
-}
-
-//-----------------------------------------------------------------------------------------
-$id = find_submit('Delete');
-if ($id != -1)
-{
- $_SESSION['supp_trans']->remove_grn_from_trans($id);
- $Ajax->activate('grn_items');
- $Ajax->activate('grn_table');
-}
-
-//-----------------------------------------------------------------------------------------
-start_form(false,true);
-display_grn_items($_SESSION['supp_trans'], 1);
-end_form();
-echo "<br>";
-
-hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Supplier Invoice Entry"));
-echo "<hr>";
-
-//-----------------------------------------------------------------------------------------
-
-function display_grn_items_for_selection()
-{
- global $table_style;
-
- $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
-
- if (db_num_rows($result) == 0)
- {
- display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
- end_page();
- exit;
- }
-
- /*Set up a table to show the outstanding GRN items for selection */
- start_form(false, true);
-
- display_heading2(_("Items Received Yet to be Invoiced"));
- div_start('grn_table');
- start_table("$table_style colspan=7 width=95%");
- $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
- _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
- _("Uninvoiced Quantity"), _("Order Price"), _("Total"));
- table_header($th);
- $i = $k = 0;
-
- while ($myrow = db_fetch($result))
- {
- $grn_already_on_invoice = false;
-
- foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
- {
- if ($entered_grn->id == $myrow["id"])
- {
- $grn_already_on_invoice = true;
- }
- }
- if ($grn_already_on_invoice == false)
- {
-
- alt_table_row_color($k);
-
- label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
- //text_cells(null, 'grn_item_id', $myrow["id"]);
- submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
- label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
- label_cell($myrow["item_code"]);
- label_cell($myrow["description"]);
- label_cell(sql2date($myrow["delivery_date"]));
- $dec = get_qty_dec($myrow["item_code"]);
- qty_cell($myrow["qty_recd"], false, $dec);
- qty_cell($myrow["quantity_inv"], false, $dec);
- qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
- amount_cell($myrow["unit_price"]);
- amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
- user_price_dec()));
- end_row();
-
- $i++;
- if ($i > 15)
- {
- $i = 0;
- table_header($th);
- }
- }
- }
-
- end_table();
- div_end();
-}
-
-//-----------------------------------------------------------------------------------------
-if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
-{
- $Ajax->activate('grn_selector');
-}
-if (get_post('AddGRNToTrans'))
-{
- $Ajax->activate('grn_table');
- $Ajax->activate('grn_items');
-}
-
-display_grn_items_for_selection();
-
-//-----------------------------------------------------------------------------------------
-
-div_start('grn_selector');
-
-$id = find_submit('grn_item_id');
-if ($id != -1)
-{
-
- $myrow = get_grn_item_detail($id);
-
- echo "<br>";
- display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
- start_table("$table_style width=80%");
- $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
- _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
- table_header($th);
-
- start_row();
- label_cell($id);
- label_cell($myrow['item_code']);
- label_cell($myrow['description']);
- $dec = get_qty_dec($myrow['item_code']);
- qty_cell($myrow['QtyOstdg'], false, $dec);
- qty_cells(null, 'this_quantity_inv', number_format2($myrow['QtyOstdg'], $dec), null, null, $dec);
- amount_cell($myrow['unit_price']);
- small_amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
- end_row();
- end_table(1);;
-
- submit_center('AddGRNToTrans', _("Add to Invoice"), true, '', true);
-
- hidden('GRNNumber', $id);
- hidden('item_code', $myrow['item_code']);
- hidden('item_description', $myrow['description']);;
- hidden('qty_recd', $myrow['qty_recd']);
- hidden('prev_quantity_inv', $myrow['quantity_inv']);
- hidden('order_price', $myrow['unit_price']);
- hidden('std_cost_unit', $myrow['std_cost_unit']);
-
- hidden('po_detail_item', $myrow['po_detail_item']);
-}
-div_end();
-
-//----------------------------------------------------------------------------------------
-
-end_form();
-echo '<br>';
-end_page(false, true);
-
-?>
+++ /dev/null
-<?php
-
-$page_security=5;
-$path_to_root="..";
-
-include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
-include_once($path_to_root . "/includes/session.inc");
-
-include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
-$js = "";
-if ($use_date_picker)
- $js .= get_js_date_picker();
-page(_("Add GL Items"), false, false, "", $js);
-
-
-if (!isset($_SESSION['supp_trans']))
-{
- display_note(_("To enter a supplier invoice or credit note the supplier must first be selected."));
- exit;
- /*It all stops here if there aint no supplier selected and transaction initiated ie $_SESSION['supp_trans'] started off*/
-}
-
-//------------------------------------------------------------------------------------------------
-function clear_fields()
-{
- global $Ajax;
-
- unset($_POST['gl_code']);
- unset($_POST['dimension_id']);
- unset($_POST['dimension2_id']);
- unset($_POST['amount']);
- unset($_POST['memo_']);
- unset($_POST['AddGLCodeToTrans']);
- $Ajax->activate('gl_ctrls');
- set_focus('gl_code');
-}
-//------------------------------------------------------------------------------------------------
-// GL postings are often entered in the same form to two accounts
-// so fileds are cleared only on user demand.
-//
-if (isset($_POST['ClearFields']))
-{
- clear_fields();
-}
-
-if (isset($_POST['AddGLCodeToTrans'])){
-
- $Ajax->activate('gl_items');
- $input_error = false;
-
- $sql = "SELECT account_code, account_name FROM ".TB_PREF."chart_master WHERE account_code='" . $_POST['gl_code'] . "'";
- $result = db_query($sql,"get account information");
- if (db_num_rows($result) == 0)
- {
- display_error(_("The account code entered is not a valid code, this line cannot be added to the transaction."));
- set_focus('gl_code');
- $input_error = true;
- }
- else
- {
- $myrow = db_fetch_row($result);
- $gl_act_name = $myrow[1];
- if (!check_num('amount'))
- {
- display_error(_("The amount entered is not numeric. This line cannot be added to the transaction."));
- set_focus('amount');
- $input_error = true;
- }
- }
-
- if ($input_error == false)
- {
- $_SESSION['supp_trans']->add_gl_codes_to_trans($_POST['gl_code'], $gl_act_name,
- $_POST['dimension_id'], $_POST['dimension2_id'],
- input_num('amount'), $_POST['memo_']);
- set_focus('gl_code');
- }
-}
-
-//------------------------------------------------------------------------------------------------
-
-$id = find_submit('Delete');
-if ($id != -1)
-{
- $_SESSION['supp_trans']->remove_gl_codes_from_trans($id);
- clear_fields();
- $Ajax->activate('gl_items');
-}
-
-//------------------------------------------------------------------------------------------------
-
-display_heading($_SESSION['supp_trans']->supplier_name);
-
-start_form(false,true);
-display_gl_items($_SESSION['supp_trans'], 1);
-end_form();
-echo "<br>";
-
-if ($_SESSION['supp_trans']->is_invoice == true)
-{
- hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Invoice Entry"));
-}
-else
-{
- hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Back to Credit Note Entry"));
-}
-
-echo "<hr>";
-
-//------------------------------------------------------------------------------------------------
-
-/*Set up a form to allow input of new GL entries */
-start_form(false, true);
-
-display_heading2(_("Enter a GL Line"));
-
-div_start('gl_ctrls');
-start_table($table_style2);
-
-$accs = get_supplier_accounts($_SESSION['supp_trans']->supplier_id);
-$_POST['gl_code'] = $accs['purchase_account'];
-gl_all_accounts_list_row(_("GL Account Selection:"), 'gl_code', null);
-$dim = get_company_pref('use_dimension');
-if ($dim >= 1)
- dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
-if ($dim > 1)
- dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
-if ($dim < 1)
- hidden('dimension_id', 0);
-if ($dim < 2)
- hidden('dimension2_id', 0);
-amount_row( _("Amount:"), 'amount');
-
-textarea_row(_("Memo:"), "memo_", null, 40, 2);
-
-end_table();
-div_end();
-echo '<br>';
-submit_center_first('AddGLCodeToTrans', _("Add GL Line"), '', true);
-submit_center_last('ClearFields', _('Reset'), _("Clear all GL entry fields"), true);
-end_form();
-
-//------------------------------------------------------------------------------------------------
-echo '<br>';
-end_page(false, true);
-
-?>
$begin = "";
else
{
- if ($from < $begin)
- $begin = add_days($from, -1);
- else
- $begin = add_days(begin_fiscalyear(), -1);
+ $begin = begin_fiscalyear();
+ if (date1_greater_date2($begin, $from))
+ $begin = $from;
+ $begin = add_days($begin, -1);
}
$prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
$rep->Font();
$rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
$rep->Header();
+ $totprev = $totcurr = 0.0;
$accounts = get_gl_accounts();
$begin = "";
else
{
- if ($from < $begin)
- $begin = add_days($from, -1);
- else
- $begin = add_days(begin_fiscalyear(), -1);
+ $begin = begin_fiscalyear();
+ if (date1_greater_date2($begin, $from))
+ $begin = $from;
+ $begin = add_days($begin, -1);
}
$prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
if ($zero == 0 && !$prev_balance && !$curr_balance)
continue;
-
+ $totprev += $prev_balance;
+ $totcurr += $curr_balance;
$rep->TextCol(0, 1, $account['account_code']);
$rep->TextCol(1, 2, $account['account_name']);
- if ($prev_balance > 0.0)
+ if ($prev_balance >= 0.0)
$rep->TextCol(2, 3, number_format2(abs($prev_balance), $dec));
else
$rep->TextCol(3, 4, number_format2(abs($prev_balance), $dec));
- if ($curr_balance > 0.0)
+ if ($curr_balance >= 0.0)
$rep->TextCol(4, 5, number_format2(abs($curr_balance), $dec));
else
$rep->TextCol(5, 6, number_format2(abs($curr_balance), $dec));
- if ($curr_balance + $prev_balance > 0.0)
+ if ($curr_balance + $prev_balance >= 0.0)
$rep->TextCol(6, 7, number_format2(abs($curr_balance + $prev_balance), $dec));
else
$rep->TextCol(7, 8, number_format2(abs($curr_balance + $prev_balance), $dec));
}
}
$rep->Line($rep->row);
+ $rep->NewLine();
+ $rep->Font('bold');
+
+ $rep->TextCol(0, 2, _("Ending Balance"));
+
+ if ($totprev >= 0.0)
+ $rep->TextCol(2, 3, number_format2(abs($totprev), $dec));
+ else
+ $rep->TextCol(3, 4, number_format2(abs($totprev), $dec));
+ if ($totcurr >= 0.0)
+ $rep->TextCol(4, 5, number_format2(abs($totcurr), $dec));
+ else
+ $rep->TextCol(5, 6, number_format2(abs($totcurr), $dec));
+ if ($totcurr + $totprev >= 0.0)
+ $rep->TextCol(6, 7, number_format2(abs($totcurr + $totprev), $dec));
+ else
+ $rep->TextCol(7, 8, number_format2(abs($totcurr + $totprev), $dec));
+
+ $rep->Line($rep->row - 6);
+
$rep->End();
}
customer_branches_list_row(_("Branch:"),
$_POST['customer_id'], 'branch_id', null, false, true, true);
+ if( ($order->customer_id != get_post('customer_id', -1)) ||
+ ($order->Branch != get_post('branch_id', -1)) ||
+ list_updated('customer_id')) {
+
if (!isset($_POST['branch_id']) || $_POST['branch_id'] == "")
{
// ignore errors on customer search box call
$order->Branch = 0;
} else
{
- if( ($order->customer_id != get_post('customer_id', -1)) ||
- ($order->Branch != get_post('branch_id', -1))) {
$old_order = (PHP_VERSION<5) ? $order : clone( $order );
$customer_error = get_customer_details_to_order($order, $_POST['customer_id'], $_POST['branch_id']);
}
unset($old_order);
}
- } // changed branch
set_global_customer($_POST['customer_id']);
+ } // changed branch
}
if ($_SESSION['Items']->trans_type!=30) {
//-----------------------------------------------------------------------------------
if ($result)
{
+ print_hidden_script(30);
+
start_form();
/*show a table of the orders returned by the sql */
div_start('orders_tbl');
}
// $not_closed = $myrow['type'] && ($myrow["TotDelivered"] < $myrow["TotQuantity"]);
- // if overdue orders, then highlight as so
- if ($myrow['type'] == 0 && date1_greater_date2(Today(), $formated_del_date))
+ // if overdue orders, then highlight as so. 2008-10-15 added totdelivered < totquantity as well for qualifying overdue
+ if ($myrow['type'] == 0 && date1_greater_date2(Today(), $formated_del_date) && ($myrow["TotDelivered"] < $myrow["TotQuantity"]))
{
start_row("class='overduebg'");
$overdue_items = true;
$modify_page = $path_to_root . "/sales/sales_order_entry.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
label_cell("<a href='$modify_page'>" . _("Edit") . "</a>");
- label_cell(print_document_link($myrow['order_no'], _("Print"), true, 30));
+ label_cell(print_document_link($myrow['order_no'], _("Print")));
}
end_row();;
INSERT INTO `0_gl_trans` VALUES ('30', '10', '5', '2008-03-06', '2664', '', '-27', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('31', '11', '1', '2008-03-06', '4010', '', '-80', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('32', '11', '1', '2008-03-06', '1420', '', '80', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('33', '11', '1', '2008-03-06', '3000', '', '125', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('34', '11', '1', '0000-00-00', '1500', '', '-10', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('35', '11', '1', '0000-00-00', '3800', '', '8', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('36', '11', '1', '0000-00-00', '2664', '', '27', '0', '0', '2', '4');
+INSERT INTO `0_gl_trans` VALUES ('34', '11', '1', '2008-03-06', '1500', '', '-10', '0', '0', '2', '4');
+INSERT INTO `0_gl_trans` VALUES ('35', '11', '1', '2008-03-06', '3800', '', '8', '0', '0', '2', '4');
+INSERT INTO `0_gl_trans` VALUES ('36', '11', '1', '2008-03-06', '2664', '', '2', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('37', '13', '6', '2008-03-06', '4010', '', '80', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('38', '13', '6', '2008-03-06', '1420', '', '-80', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('39', '10', '6', '2008-03-06', '3000', '', '-100', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('54', '11', '2', '2008-03-06', '3000', '', '125', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('55', '11', '2', '2008-03-06', '1500', '', '-135', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('56', '11', '2', '2008-03-06', '3800', '', '8', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('57', '11', '2', '0000-00-00', '2664', '', '27', '0', '0', '2', '4');
+INSERT INTO `0_gl_trans` VALUES ('57', '11', '2', '2008-03-06', '2664', '', '2', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('58', '11', '3', '2008-03-06', '4010', '', '-80', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('59', '11', '3', '2008-03-06', '1420', '', '80', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('60', '11', '3', '2008-03-06', '3000', '', '100', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('61', '11', '3', '2008-03-06', '1500', '', '-135', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('62', '11', '3', '2008-03-06', '3800', '', '8', '0', '0', '2', '4');
-INSERT INTO `0_gl_trans` VALUES ('63', '11', '3', '0000-00-00', '2664', '', '27', '0', '0', '2', '4');
+INSERT INTO `0_gl_trans` VALUES ('63', '11', '3', '2008-03-06', '2664', '', '27', '0', '0', '2', '4');
INSERT INTO `0_gl_trans` VALUES ('64', '12', '9', '2008-03-07', '1700', '', '2000', '0', '0', '2', '1');
INSERT INTO `0_gl_trans` VALUES ('65', '12', '9', '2008-03-07', '1500', '', '-2000', '0', '0', '2', '1');
INSERT INTO `0_gl_trans` VALUES ('66', '11', '4', '2008-03-07', '3000', '', '100', '0', '0', '2', '1');
INSERT INTO `0_gl_trans` VALUES ('67', '11', '4', '2008-03-07', '1500', '', '-125', '0', '0', '2', '1');
-INSERT INTO `0_gl_trans` VALUES ('68', '11', '4', '0000-00-00', '2664', '', '25', '0', '0', '2', '1');
+INSERT INTO `0_gl_trans` VALUES ('68', '11', '4', '2008-03-07', '2664', '', '25', '0', '0', '2', '1');
INSERT INTO `0_gl_trans` VALUES ('69', '26', '7', '2008-03-07', '1420', '', '-80', '0', '0', NULL, NULL);
INSERT INTO `0_gl_trans` VALUES ('70', '26', '7', '2008-03-07', '1420', '', '-20', '0', '0', NULL, NULL);
INSERT INTO `0_gl_trans` VALUES ('71', '26', '7', '2008-03-07', '1420', '', '-18', '0', '0', NULL, NULL);
INSERT INTO `0_gl_trans` VALUES ('136', '20', '9', '2008-03-25', '1420', '', '19.82', '0', '0', '3', '2');
INSERT INTO `0_gl_trans` VALUES ('149', '20', '10', '2008-03-25', '2630', '', '-40.48', '0', '0', '3', '4');
INSERT INTO `0_gl_trans` VALUES ('150', '20', '10', '2008-03-25', '1420', '', '40.48', '0', '0', '3', '4');
-INSERT INTO `0_gl_trans` VALUES ('151', '20', '10', '2008-03-25', '2682', '', '8.1', '0', '0', '3', '4');
INSERT INTO `0_gl_trans` VALUES ('152', '20', '11', '2008-03-28', '2630', '', '-2618.19', '0', '0', '3', '4');
INSERT INTO `0_gl_trans` VALUES ('153', '20', '11', '2008-03-28', '1420', '', '2094.55', '0', '0', '3', '4');
INSERT INTO `0_gl_trans` VALUES ('154', '20', '11', '2008-03-28', '2682', '', '523.64', '0', '0', '3', '4');