Bug in calculating exchange rates in Reports Supplier Balances and Customer Balances.
clone replacement do_clone() for both PHP 4 and PHP 5.
! -> Note
$ -> Affected files
+09-Mar-2008 Joe Hunt
+ - Removed redundant form_types functions and the file /reporting/includes/form_types.inc. Removed table form_items
+ $ /dimensions/includes/dimensions_db.inc
+ /gl/includes/db/gl_db_banking.inc
+ /includes/main.inc
+ /inventory/includes/db/items_adjust_db.inc
+ /manufacturing/includes/db/work_order_issues_db.inc
+ /manufacturing/includes/db/work_order_produce_items_db.inc
+ /manufacturing/includes/db/work_orders_db.inc
+ /manufacturing/includes/db/work_orders_quick_db.inc
+ /purchasing/includes/db/grn_db.inc
+ /purchasing/includes/db/po_db.inc
+ /purchasing/includes/db/supp_payment_db.inc
+ /reporting/includes/form_types.inc (File removed)
+ /sales/includes/db/sales_delivery_db.inc
+ /sales/includes/db/sales_invoice_db.inc
+ /sales/includes/db/sales_order_db.inc
+ /sql/alter.sql
+ # Bug in calculating exchange rates in Reports Supplier Balances and Customer Balances
+ $ /reporting/rep101.php
+ /reporting/rep201.php
+ # clone replacement do_clone() for both PHP 4 and PHP 5.
+ $ /includes/ui/ui_view.inc (at the very bottom)
+ /sales/includes/cart_class.inc
+
07-Mar-2008 Janusz Dobrowolski
! Changed name tax type uniqueness constraint to (name, rate)
$ /includes/ui/ui_lists.inc
add_comments(systypes::dimension(), $id, $date_, $memo_);
- add_forms_for_sys_type(systypes::dimension(), $id);
-
references::save_last($reference, systypes::dimension());
commit_transaction();
delete_comments(systypes::dimension(), $id);
- delete_forms_for_systype(systypes::dimension(), $id);
-
commit_transaction();
}
{
if ($html)
$dim = " ";
- else
+ else
$dim = "";
- }
+ }
else
{
$row = get_dimension($id, true);
$dim = $row['reference'] . $space . $row['name'];
}
-
+
return $dim;
}
//----------------------------------------------------------------------------------
-function add_bank_transfer($from_account, $to_account, $date_,
+function add_bank_transfer($from_account, $to_account, $date_,
$amount, $payment_type, $ref, $memo_)
{
begin_transaction();
-
+
$trans_type = systypes::bank_transfer();
-
+
$currency = get_bank_account_currency($from_account);
$trans_no = get_next_trans_no($trans_type);
-
+
// do the source account postings
- add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
- -$amount, $currency);
-
- add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $date_, $payment_type, -$amount,
- payment_person_types::misc(), "", $currency,
+ add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
+ -$amount, $currency);
+
+ add_bank_trans($trans_type, $trans_no, $from_account, $ref,
+ $date_, $payment_type, -$amount,
+ payment_person_types::misc(), "", $currency,
"Cannot insert a source bank transaction");
-
+
// do the destination account postings
add_gl_trans($trans_type, $trans_no, $date_, $to_account, 0, 0, "",
$amount, $currency);
-
- add_bank_trans($trans_type, $trans_no, $to_account, $ref,
+
+ add_bank_trans($trans_type, $trans_no, $to_account, $ref,
$date_, $payment_type, $amount,
- payment_person_types::misc(), "",
- $currency,
+ payment_person_types::misc(), "",
+ $currency,
"Cannot insert a destination bank transaction");
-
- add_comments($trans_type, $trans_no, $date_, $memo_);
-
- add_forms_for_sys_type($trans_type, $trans_no, $from_account, $to_account);
-
- references::save_last($ref, $trans_type);
-
+
+ add_comments($trans_type, $trans_no, $date_, $memo_);
+
+ references::save_last($ref, $trans_type);
+
commit_transaction();
-
- return $trans_no;
+
+ return $trans_no;
}
//----------------------------------------------------------------------------------
display_db_error("Invalid type ($trans_type) sent to add_bank_transaction");
begin_transaction();
-
- $currency = get_bank_account_currency($from_account);
-
+
+ $currency = get_bank_account_currency($from_account);
+
// the gl items are already inversed/negated for type 2 (deposit)
$total_amount = $items->gl_items_total();
-
- if ($person_type_id == payment_person_types::customer())
+
+ if ($person_type_id == payment_person_types::customer())
{
// we need to add a customer transaction record
-
+
// convert to customer currency
$cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_);
-
+
$trans_no = add_customer_trans($trans_type, $person_id, $person_detail_id, $date_,
- $ref, $cust_amount);
+ $ref, $cust_amount);
- }
- elseif ($person_type_id == payment_person_types::supplier())
+ }
+ elseif ($person_type_id == payment_person_types::supplier())
{
// we need to add a supplier transaction record
// convert to supp currency
$supp_amount = exchange_from_to($total_amount, $currency, get_supplier_currency($person_id), $date_);
-
- // we need to negate it too
+
+ // we need to negate it too
$supp_amount = -$supp_amount;
$trans_no = add_supp_trans($trans_type, $person_id, $date_, '',
$ref, "", $supp_amount, 0, 0);
- }
- else
+ }
+ else
{
$trans_no = get_next_trans_no($trans_type);
- }
-
+ }
+
// do the source account postings
add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
- -$total_amount, $currency, $person_type_id, $person_id);
-
- add_bank_trans($trans_type, $trans_no, $from_account, $ref,
+ -$total_amount, $currency, $person_type_id, $person_id);
+
+ add_bank_trans($trans_type, $trans_no, $from_account, $ref,
$date_, $type, -$total_amount,
- $person_type_id, $person_id,
- $currency,
+ $person_type_id, $person_id,
+ $currency,
"Cannot insert a source bank transaction");
-
+
foreach ($items->gl_items as $gl_item)
{
$is_bank_to = is_bank_account($gl_item->code_id);
-
- if ($trans_type == 1 AND $is_bank_to)
+
+ if ($trans_type == 1 AND $is_bank_to)
{
// we don't allow payments to go to a bank account. use transfer for this !
display_db_error("invalid payment entered. Cannot pay to another bank account", "");
- }
-
+ }
+
// do the destination account postings
- add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
- $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
+ add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
+ $gl_item->dimension_id, $gl_item->dimension2_id, $gl_item->reference,
$gl_item->amount, $currency, $person_type_id, $person_id);
-
- if ($is_bank_to)
+
+ if ($is_bank_to)
{
- add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
+ add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
$date_, $type, $gl_item->amount,
- $person_type_id, $person_id, $currency,
- "Cannot insert a destination bank transaction");
- }
+ $person_type_id, $person_id, $currency,
+ "Cannot insert a destination bank transaction");
+ }
}
-
+
add_comments($trans_type, $trans_no, $date_, $memo_);
-
- add_forms_for_sys_type($trans_type, $trans_no, $person_type_id, $person_id);
-
- references::save_last($ref, $trans_type);
-
+
+ references::save_last($ref, $trans_type);
+
commit_transaction();
-
+
return array($trans_type, $trans_no);
}
//----------------------------------------------------------------------------------------
-function add_bank_payment($from_account, $items, $date_,
+function add_bank_payment($from_account, $items, $date_,
$person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
{
return add_bank_transaction(systypes::bank_payment(), $from_account, $items, $date_,
//---------------------------------------------------------------------------------------------
-function add_bank_deposit($from_account, $items, $date_,
+function add_bank_deposit($from_account, $items, $date_,
$person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
{
return add_bank_transaction(systypes::bank_deposit(), $from_account, $items, $date_,
include_once($path_to_root . "/includes/systypes.inc");
include_once($path_to_root . "/includes/references.inc");
include_once($path_to_root . "/includes/prefs/sysprefs.inc");
- include_once($path_to_root . "/includes/db/comments_db.inc");
- include_once($path_to_root . "/includes/db/sql_functions.inc");
-
- include_once($path_to_root . "/reporting/includes/form_types.inc");
-
- include_once($path_to_root . "/admin/db/users_db.inc");
-
- function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
+ include_once($path_to_root . "/includes/db/comments_db.inc");
+ include_once($path_to_root . "/includes/db/sql_functions.inc");
+
+ include_once($path_to_root . "/admin/db/users_db.inc");
+
+ function page($title, $no_menu=false, $is_index=false, $onload="", $js="")
{
-
+
global $path_to_root;
-
+
$hide_menu = $no_menu;
-
+
include($path_to_root . "/includes/page/header.inc");
-
+
page_header($title, $no_menu, $is_index, $onload, $js);
- }
-
- function end_page($no_menu=false, $is_index=false)
+ }
+
+ function end_page($no_menu=false, $is_index=false)
{
global $path_to_root;
-
+
$hide_menu = $no_menu;
-
+
include($path_to_root . "/includes/page/footer.inc");
-
- page_footer($no_menu, $is_index);
+
+ page_footer($no_menu, $is_index);
}
?>
\ No newline at end of file
}
}
+/* ************************************** Backward compatible */
+function do_clone($object)
+{
+ if (version_compare(phpversion(), '5.0') < 0)
+ {
+ return $object;
+ }
+ else
+ {
+ return @clone($object);
+ }
+}
+
?>
\ No newline at end of file
function add_stock_adjustment($items, $location, $date_, $type, $increase, $reference, $memo_)
{
begin_transaction();
-
+
$adj_id = get_next_trans_no(systypes::inventory_adjustment());
-
- foreach ($items as $line_item)
+
+ foreach ($items as $line_item)
{
-
+
if (!$increase)
$line_item->quantity = -$line_item->quantity;
-
- add_stock_adjustment_item($adj_id, $line_item->stock_id, $location, $date_, $type, $reference,
+
+ add_stock_adjustment_item($adj_id, $line_item->stock_id, $location, $date_, $type, $reference,
$line_item->quantity, $line_item->standard_cost, $memo_);
}
-
- add_comments(systypes::inventory_adjustment(), $adj_id, $date_, $memo_);
-
- add_forms_for_sys_type(systypes::inventory_adjustment(), $adj_id, $increase, $location);
-
- references::save_last($reference, systypes::inventory_adjustment());
-
+
+ add_comments(systypes::inventory_adjustment(), $adj_id, $date_, $memo_);
+
+ references::save_last($reference, systypes::inventory_adjustment());
+
commit_transaction();
- return $adj_id;
+ return $adj_id;
}
//-------------------------------------------------------------------------------------------------------------
function get_stock_adjustment_items($trans_no)
{
$result = get_stock_moves(systypes::inventory_adjustment(), $trans_no);
-
- if (db_num_rows($result) == 0)
+
+ if (db_num_rows($result) == 0)
{
- return null;
+ return null;
}
-
+
return $result;
}
//--------------------------------------------------------------------------------------------------
-function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type, $reference,
+function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type, $reference,
$quantity, $standard_cost, $memo_)
{
$mb_flag = get_mb_flag($stock_id);
-
+
if (is_service($mb_flag))
{
- display_db_error("Cannot do inventory adjustment for Service item : $stock_id", "");
- }
-
+ display_db_error("Cannot do inventory adjustment for Service item : $stock_id", "");
+ }
+
add_stock_move(systypes::inventory_adjustment(), $stock_id, $adj_id, $location,
- $date_, $reference, $quantity, $standard_cost, $type);
+ $date_, $reference, $quantity, $standard_cost, $type);
if ($standard_cost > 0)
{
-
+
$stock_gl_codes = get_stock_gl_code($stock_id);
-
- add_gl_trans_std_cost(systypes::inventory_adjustment(), $adj_id, $date_,
+
+ add_gl_trans_std_cost(systypes::inventory_adjustment(), $adj_id, $date_,
$stock_gl_codes['adjustment_account'], $stock_gl_codes['dimension_id'], $stock_gl_codes['dimension2_id'], $memo_, ($standard_cost * -($quantity)));
-
- add_gl_trans_std_cost(systypes::inventory_adjustment(), $adj_id, $date_, $stock_gl_codes['inventory_account'], 0, 0, $memo_, ($standard_cost * $quantity));
+
+ add_gl_trans_std_cost(systypes::inventory_adjustment(), $adj_id, $date_, $stock_gl_codes['inventory_account'], 0, 0, $memo_, ($standard_cost * $quantity));
}
}
function add_stock_transfer($Items, $location_from, $location_to, $date_, $type, $reference, $memo_)
{
begin_transaction();
-
+
$transfer_id = get_next_trans_no(systypes::location_transfer());
-
- foreach ($Items as $line_item)
+
+ foreach ($Items as $line_item)
{
- add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from,
+ add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from,
$location_to, $date_, $type, $reference, $line_item->quantity);
}
-
- add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);
-
- add_forms_for_sys_type(systypes::location_transfer(), $transfer_id, $location_from, $location_to);
-
- references::save_last($reference, systypes::location_transfer());
-
+
+ add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);
+
+ references::save_last($reference, systypes::location_transfer());
+
commit_transaction();
- return $transfer_id;
+ return $transfer_id;
}
//-------------------------------------------------------------------------------------------------------------
// std_cost is in HOME currency
// it seems the standard_cost field is not used at all
-function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
+function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
$date_, $type, $reference, $quantity)
{
add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_from,
- $date_, $reference, -$quantity, 0, $type);
-
+ $date_, $reference, -$quantity, 0, $type);
+
add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_to,
- $date_, $reference, $quantity, 0, $type);
-
+ $date_, $reference, $quantity, 0, $type);
+
}
//-------------------------------------------------------------------------------------------------------------
function get_stock_transfer($trans_no)
{
$result = get_stock_transfer_items($trans_no);
- if (db_num_rows($result) < 2)
+ if (db_num_rows($result) < 2)
{
- display_db_error("transfer with less than 2 items : $trans_no", "");
+ display_db_error("transfer with less than 2 items : $trans_no", "");
}
-
+
// this function is very bad that it assumes that 1st record and 2nd record contain the
// from and to locations - if get_stock_moves uses a different ordering than trans_no then
// it will bomb
$move1 = db_fetch($result);
$move2 = db_fetch($result);
-
+
// return an array of (From, To)
if ($move1['qty'] < 0)
return array($move1, $move2);
function get_stock_transfer_items($trans_no)
{
$result = get_stock_moves(systypes::location_transfer(), $trans_no);
-
- if (db_num_rows($result) == 0)
+
+ if (db_num_rows($result) == 0)
{
- return null;
+ return null;
}
-
+
return $result;
}
//--------------------------------------------------------------------------------------
-function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $workcentre,
+function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $workcentre,
$date_, $memo_)
{
begin_transaction();
$details = get_work_order($woid);
-
- if (strlen($details[0]) == 0)
+
+ if (strlen($details[0]) == 0)
{
echo _("The order number sent is not valid.");
cancel_transaction();
exit;
}
-
- if (work_order_is_closed($woid))
+
+ if (work_order_is_closed($woid))
{
display_error("UNEXPECTED : Issuing items for a closed Work Order");
cancel_transaction();
exit;
- }
-
+ }
+
// insert the actual issue
- $sql = "INSERT INTO ".TB_PREF."wo_issues (workorder_id, reference, issue_date, loc_code, workcentre_id)
+ $sql = "INSERT INTO ".TB_PREF."wo_issues (workorder_id, reference, issue_date, loc_code, workcentre_id)
VALUES ($woid, '$ref', '" .
date2sql($date_) . "', '$location', $workcentre)";
db_query($sql,"The work order issue could not be added");
-
+
$number = db_insert_id();
-
- foreach ($items as $item)
+
+ foreach ($items as $item)
{
-
+
if ($to_work_order)
$item->quantity = -$item->quantity;
// insert a -ve stock move for each item
- add_stock_move(28, $item->stock_id, $number,
+ add_stock_move(28, $item->stock_id, $number,
$location, $date_, $memo_, -$item->quantity, 0);
-
- $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
+
+ $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
VALUES ('$number', '$item->stock_id', $item->quantity)";
db_query($sql,"A work order issue item could not be added");
}
-
+
if ($memo_)
- add_comments(28, $number, $date_, $memo_);
-
- add_forms_for_sys_type(28, $number, $to_work_order, $location);
-
+ add_comments(28, $number, $date_, $memo_);
+
references::save_last($ref, 28);
-
+
commit_transaction();
}
function get_work_order_issue($issue_no)
{
- $sql = "SELECT DISTINCT ".TB_PREF."wo_issues.*, ".TB_PREF."workorders.stock_id,
- ".TB_PREF."stock_master.description, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreName
+ $sql = "SELECT DISTINCT ".TB_PREF."wo_issues.*, ".TB_PREF."workorders.stock_id,
+ ".TB_PREF."stock_master.description, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreName
FROM ".TB_PREF."wo_issues, ".TB_PREF."workorders, ".TB_PREF."stock_master, ".TB_PREF."locations, ".TB_PREF."workcentres
WHERE issue_no='$issue_no'
AND ".TB_PREF."workorders.id = ".TB_PREF."wo_issues.workorder_id
AND ".TB_PREF."workcentres.id = ".TB_PREF."wo_issues.workcentre_id
AND ".TB_PREF."stock_master.stock_id = ".TB_PREF."workorders.stock_id";
$result = db_query($sql, "A work order issue could not be retrieved");
-
+
return db_fetch($result);
}
function get_work_order_issue_details($issue_no)
{
- $sql = "SELECT ".TB_PREF."wo_issue_items.*,".TB_PREF."stock_master.description, ".TB_PREF."stock_master.units
+ $sql = "SELECT ".TB_PREF."wo_issue_items.*,".TB_PREF."stock_master.description, ".TB_PREF."stock_master.units
FROM ".TB_PREF."wo_issue_items, ".TB_PREF."stock_master
WHERE issue_id=$issue_no
AND ".TB_PREF."stock_master.stock_id=".TB_PREF."wo_issue_items.stock_id
function exists_work_order_issue($issue_no)
{
$sql = "SELECT issue_no FROM ".TB_PREF."wo_issues WHERE issue_no=$issue_no";
- $result = db_query($sql, "Cannot retreive a wo issue");
-
- return (db_num_rows($result) > 0);
-}
+ $result = db_query($sql, "Cannot retreive a wo issue");
+
+ return (db_num_rows($result) > 0);
+}
//--------------------------------------------------------------------------------------
function void_work_order_issue($type_no)
{
begin_transaction();
-
+
// void the actual issue items and their quantities
$sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id=$type_no";
db_query($sql,"A work order issue item could not be voided");
-
+
// void all related stock moves
void_stock_move(28, $type_no);
-
+
// void any related gl trans
- void_gl_trans(28, $type_no, true);
-
+ void_gl_trans(28, $type_no, true);
+
commit_transaction();
}
begin_transaction();
$details = get_work_order($woid);
-
- if (strlen($details[0]) == 0)
+
+ if (strlen($details[0]) == 0)
{
echo _("The order number sent is not valid.");
exit;
}
-
- if (work_order_is_closed($woid))
+
+ if (work_order_is_closed($woid))
{
display_error("UNEXPECTED : Producing Items for a closed Work Order");
cancel_transaction();
exit;
- }
-
+ }
+
$date = date2sql($date_);
-
+
$sql = "INSERT INTO ".TB_PREF."wo_manufacture (workorder_id, reference, quantity, date_)
VALUES ($woid, '$ref', $quantity, '$date')";
db_query($sql,"A work order manufacture could not be added");
-
- $id = db_insert_id();
-
+
+ $id = db_insert_id();
+
// insert a +ve stock move for the item being manufactured
// negative means "unproduce" or unassemble
add_stock_move(29, $details["stock_id"], $id,
- $details["loc_code"], $date_, $memo_, $quantity, 0);
-
+ $details["loc_code"], $date_, $memo_, $quantity, 0);
+
// update wo quantity and close wo if requested
work_order_update_finished_quantity($woid, $quantity, $close_wo);
-
+
if ($memo_)
- add_comments(29, $id, $date_, $memo_);
-
- add_forms_for_sys_type(29, $id, $quantity, $details["loc_code"]);
-
- references::save_last($ref, 29);
-
- commit_transaction();
+ add_comments(29, $id, $date_, $memo_);
+
+ references::save_last($ref, 29);
+
+ commit_transaction();
}
//--------------------------------------------------------------------------------------------
function get_work_order_produce($id)
{
- $sql = "SELECT ".TB_PREF."wo_manufacture.*,".TB_PREF."workorders.stock_id, ".TB_PREF."stock_master.description AS StockDescription
- FROM ".TB_PREF."wo_manufacture, ".TB_PREF."workorders, ".TB_PREF."stock_master
+ $sql = "SELECT ".TB_PREF."wo_manufacture.*,".TB_PREF."workorders.stock_id, ".TB_PREF."stock_master.description AS StockDescription
+ FROM ".TB_PREF."wo_manufacture, ".TB_PREF."workorders, ".TB_PREF."stock_master
WHERE ".TB_PREF."wo_manufacture.workorder_id=".TB_PREF."workorders.id
AND ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
AND ".TB_PREF."wo_manufacture.id=$id";
$result = db_query($sql, "The work order production could not be retrieved");
-
- return db_fetch($result);
+
+ return db_fetch($result);
}
//--------------------------------------------------------------------------------------
function exists_work_order_produce($id)
{
$sql = "SELECT id FROM ".TB_PREF."wo_manufacture WHERE id=$id";
- $result = db_query($sql, "Cannot retreive a wo production");
-
- return (db_num_rows($result) > 0);
-}
+ $result = db_query($sql, "Cannot retreive a wo production");
+
+ return (db_num_rows($result) > 0);
+}
//--------------------------------------------------------------------------------------------
function void_work_order_produce($type_no)
{
- begin_transaction();
-
+ begin_transaction();
+
$row = get_work_order_produce($type_no);
-
+
// deduct the quantity of this production from the parent work order
work_order_update_finished_quantity($row["workorder_id"], -$row["quantity"]);
-
+
// clear the production record
- $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=$type_no";
+ $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=$type_no";
db_query($sql, "Cannot void a wo production");
-
+
// void all related stock moves
- void_stock_move(29, $type_no);
-
+ void_stock_move(29, $type_no);
+
// void any related gl trans
- void_gl_trans(29, $type_no, true);
-
- commit_transaction();
+ void_gl_trans(29, $type_no, true);
+
+ commit_transaction();
}
add_comments(systypes::work_order(), $woid, $required_by, $memo_);
- add_forms_for_sys_type(systypes::work_order(), $woid);
-
references::save_last($wo_ref, systypes::work_order());
commit_transaction();
delete_comments(systypes::work_order(), $woid);
- delete_forms_for_systype(systypes::work_order(), $woid);
-
commit_transaction();
}
add_comments(systypes::work_order(), $woid, $date_, $memo_);
- add_forms_for_sys_type(systypes::work_order(), $woid, $type);
-
references::save_last($wo_ref, systypes::work_order());
commit_transaction();
} /*quantity received is != 0 */
} /*end of order_line loop */
- add_forms_for_sys_type(25, $grn, $location);
-
references::save_last($reference, 25);
commit_transaction();
function add_po(&$po_obj)
{
- begin_transaction();
-
+ begin_transaction();
+
/*Insert to purchase order header record */
$sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, requisition_no, into_stock_location, delivery_address) VALUES(";
- $sql .= "'" . $po_obj->supplier_id . "', '" .
- db_escape($po_obj->Comments) . "','" .
- date2sql($po_obj->orig_order_date) . "', '" .
- $po_obj->reference . "', '" .
- $po_obj->requisition_no . "', '" .
- $po_obj->Location . "', '" .
+ $sql .= "'" . $po_obj->supplier_id . "', '" .
+ db_escape($po_obj->Comments) . "','" .
+ date2sql($po_obj->orig_order_date) . "', '" .
+ $po_obj->reference . "', '" .
+ $po_obj->requisition_no . "', '" .
+ $po_obj->Location . "', '" .
$po_obj->delivery_address . "')";
-
+
db_query($sql, "The purchase order header record could not be inserted");
-
+
/*Get the auto increment value of the order number created from the sql above */
$po_obj->order_no = db_insert_id();
-
+
/*Insert the purchase order detail records */
- foreach ($po_obj->line_items as $po_line)
+ foreach ($po_obj->line_items as $po_line)
{
- if ($po_line->Deleted == false)
+ if ($po_line->Deleted == false)
{
$sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date, unit_price, quantity_ordered) VALUES (";
- $sql .= $po_obj->order_no . ", '" . $po_line->stock_id . "','" .
- $po_line->item_description . "','" .
- date2sql($po_line->req_del_date) . "'," .
- $po_line->price . ", " .
+ $sql .= $po_obj->order_no . ", '" . $po_line->stock_id . "','" .
+ $po_line->item_description . "','" .
+ date2sql($po_line->req_del_date) . "'," .
+ $po_line->price . ", " .
$po_line->quantity . ")";
db_query($sql, "One of the purchase order detail records could not be inserted");
}
- }
-
- add_forms_for_sys_type(systypes::po(), $po_obj->order_no);
-
- references::save_last($po_obj->reference, systypes::po());
-
- //add_comments(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
-
- commit_transaction();
-
+ }
+
+ references::save_last($po_obj->reference, systypes::po());
+
+ //add_comments(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
+
+ commit_transaction();
+
return $po_obj->order_no;
}
function update_po(&$po_obj)
{
- begin_transaction();
+ begin_transaction();
/*Update the purchase order header with any changes */
- $sql = "UPDATE ".TB_PREF."purch_orders SET Comments='" . db_escape($po_obj->Comments) . "',
- requisition_no= '" . $po_obj->requisition_no . "',
- into_stock_location='" . $po_obj->Location . "',
+ $sql = "UPDATE ".TB_PREF."purch_orders SET Comments='" . db_escape($po_obj->Comments) . "',
+ requisition_no= '" . $po_obj->requisition_no . "',
+ into_stock_location='" . $po_obj->Location . "',
ord_date='" . date2sql($po_obj->orig_order_date) . "',
delivery_address='" . $po_obj->delivery_address . "'";
$sql .= " WHERE order_no = " . $po_obj->order_no;
db_query($sql, "The purchase order could not be updated");
/*Now Update the purchase order detail records */
- foreach ($po_obj->line_items as $po_line)
+ foreach ($po_obj->line_items as $po_line)
{
- if ($po_line->Deleted==True)
+ if ($po_line->Deleted==True)
{
// Sherifoz 21.06.03 Handle deleting existing lines
- if ($po_line->po_detail_rec!='')
+ if ($po_line->po_detail_rec!='')
{
$sql = "DELETE FROM ".TB_PREF."purch_order_details WHERE po_detail_item='" . $po_line->po_detail_rec . "'";
db_query($sql, "could not query purch order details");
}
- }
- else if ($po_line->po_detail_rec == '')
+ }
+ else if ($po_line->po_detail_rec == '')
{
// Sherifoz 21.06.03 Handle adding new lines vs. updating. if no key(po_detail_rec) then it's a new line
$sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date, unit_price, quantity_ordered) VALUES (";
- $sql .= $po_obj->order_no . ", '" .
- $po_line->stock_id . "','" .
- $po_line->item_description . "','" .
- date2sql($po_line->req_del_date) . "'," .
+ $sql .= $po_obj->order_no . ", '" .
+ $po_line->stock_id . "','" .
+ $po_line->item_description . "','" .
+ date2sql($po_line->req_del_date) . "'," .
$po_line->price . ", " . $po_line->quantity . ")";
- }
- else
+ }
+ else
{
- $sql = "UPDATE ".TB_PREF."purch_order_details SET item_code='" . $po_line->stock_id . "',
+ $sql = "UPDATE ".TB_PREF."purch_order_details SET item_code='" . $po_line->stock_id . "',
description ='" . $po_line->item_description . "',
- delivery_date ='" . date2sql($po_line->req_del_date) . "',
- unit_price=" . $po_line->price . ",
- quantity_ordered=" . $po_line->quantity . "
+ delivery_date ='" . date2sql($po_line->req_del_date) . "',
+ unit_price=" . $po_line->price . ",
+ quantity_ordered=" . $po_line->quantity . "
WHERE po_detail_item=" . $po_line->po_detail_rec;
}
db_query($sql, "One of the purchase order detail records could not be updated");
}
-
- //add_comments(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
-
- commit_transaction();
-
- return $po_obj->order_no;
+
+ //add_comments(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
+
+ commit_transaction();
+
+ return $po_obj->order_no;
}
//----------------------------------------------------------------------------------------
function read_po_header($order_no, &$order)
{
- $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name,
- ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name
- FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
+ $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name,
+ ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name
+ FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
- AND ".TB_PREF."locations.loc_code = into_stock_location
+ AND ".TB_PREF."locations.loc_code = into_stock_location
AND ".TB_PREF."purch_orders.order_no = " . $order_no;
$result = db_query($sql, "The order cannot be retrieved");
-
- if (db_num_rows($result) == 1)
+
+ if (db_num_rows($result) == 1)
{
$myrow = db_fetch($result);
-
+
$order->order_no = $order_no;
$order->supplier_id = $myrow["supplier_id"];
$order->supplier_name = $myrow["supp_name"];
$order->curr_code = $myrow["curr_code"];
-
+
$order->orig_order_date = sql2date($myrow["ord_date"]);
$order->Comments = $myrow["comments"];
$order->Location = $myrow["into_stock_location"];
$order->requisition_no = $myrow["requisition_no"];
$order->reference = $myrow["reference"];
$order->delivery_address = $myrow["delivery_address"];
-
+
return true;
- }
-
+ }
+
display_db_error("FATAL : duplicate purchase order found", "", true);
return false;
}
{
/*now populate the line po array with the purchase order details records */
- $sql = "SELECT ".TB_PREF."purch_order_details.*, units
- FROM ".TB_PREF."purch_order_details
- LEFT JOIN ".TB_PREF."stock_master
- ON ".TB_PREF."purch_order_details.item_code=".TB_PREF."stock_master.stock_id
+ $sql = "SELECT ".TB_PREF."purch_order_details.*, units
+ FROM ".TB_PREF."purch_order_details
+ LEFT JOIN ".TB_PREF."stock_master
+ ON ".TB_PREF."purch_order_details.item_code=".TB_PREF."stock_master.stock_id
WHERE order_no =$order_no ";
-
+
if ($open_items_only)
- $sql .= " AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
-
+ $sql .= " AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
+
$sql .= " ORDER BY po_detail_item";
- $result = db_query($sql, "The lines on the purchase order cannot be retrieved");
+ $result = db_query($sql, "The lines on the purchase order cannot be retrieved");
- if (db_num_rows($result) > 0)
+ if (db_num_rows($result) > 0)
{
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch($result))
{
if (is_null($myrow["units"]))
{
$units = "";
- }
- else
+ }
+ else
{
$units = $myrow["units"];
}
- $order->add_to_order($order->lines_on_order+1, $myrow["item_code"],
- $myrow["quantity_ordered"],$myrow["description"],
+ $order->add_to_order($order->lines_on_order+1, $myrow["item_code"],
+ $myrow["quantity_ordered"],$myrow["description"],
$myrow["unit_price"],$units, sql2date($myrow["delivery_date"]),
$myrow["qty_invoiced"], $myrow["quantity_received"]);
-
+
$order->line_items[$order->lines_on_order]->po_detail_rec = $myrow["po_detail_item"];
$order->line_items[$order->lines_on_order]->standard_cost = $myrow["std_cost_unit"]; /*Needed for receiving goods and GL interface */
} /* line po from purchase order details */
function read_po($order_no, &$order, $open_items_only=false)
{
- $result = read_po_header($order_no, $order);
-
+ $result = read_po_header($order_no, $order);
+
if ($result)
- read_po_items($order_no, $order, $open_items_only);
+ read_po_items($order_no, $order, $open_items_only);
}
//----------------------------------------------------------------------------------------
$amount, $discount, $ref, $memo_)
{
begin_transaction();
-
+
$supplier_currency = get_supplier_currency($supplier_id);
$bank_account_currency = get_bank_account_currency($bank_account);
-
+
$supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
$supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
-
+
// it's a supplier payment
$trans_type = 22;
/* Create a supp_trans entry for the supplier payment */
- $payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
- $ref, "", -$supp_amount, 0, -$supp_discount);
+ $payment_id = add_supp_trans($trans_type, $supplier_id, $date_, $date_,
+ $ref, "", -$supp_amount, 0, -$supp_discount);
- // Now debit creditors account with payment + discount
+ // Now debit creditors account with payment + discount
$supplier_accounts = get_supplier_accounts($supplier_id);
-
+
add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
- $supp_amount + $supp_discount, $supplier_id);
-
+ $supp_amount + $supp_discount, $supplier_id);
+
// Now credit discount received account with discounts
if ($supp_discount != 0)
{
add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
- -$supp_discount, $supplier_id);
+ -$supp_discount, $supplier_id);
}
-
- if ($supp_amount != 0)
+
+ if ($supp_amount != 0)
{
add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
-$supp_amount, $supplier_id);
- }
+ }
/*now enter the bank_trans entry */
- add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
- $date_, $payment_type, -($amount), payment_person_types::supplier(),
- $supplier_id, $bank_account_currency,
+ add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
+ $date_, $payment_type, -($amount), payment_person_types::supplier(),
+ $supplier_id, $bank_account_currency,
"Could not add the supplier payment bank transaction");
-
- add_comments($trans_type, $payment_id, $date_, $memo_);
-
- add_forms_for_sys_type($trans_type, $payment_id, payment_person_types::supplier(), $supplier_id);
-
- references::save_last($ref, $trans_type);
-
- commit_transaction();
-
+
+ add_comments($trans_type, $payment_id, $date_, $memo_);
+
+ references::save_last($ref, $trans_type);
+
+ commit_transaction();
+
return $payment_id;
}
function void_supp_payment($type, $type_no)
{
begin_transaction();
-
+
void_bank_trans($type, $type_no, true);
void_gl_trans($type, $type_no, true);
- void_supp_allocations($type, $type_no);
+ void_supp_allocations($type, $type_no);
void_supp_trans($type, $type_no);
-
+
commit_transaction();
}
+++ /dev/null
-<?php
-
-$form_types = array (
-
- 10=> array('code' => 'si', 'name' => _("Sales Invoice")),
- 11=> array('code' => 'si', 'name' => _("Sales Credit Note")),
- 30=> array('code' => 'so', 'name' => _("Sales Order")),
-
- 18=> array('code' => 'po', 'name' => _("Purchase Order")),
-
- 26=> array('code' => 'wo', 'name' => _("Work Order")),
- 28=> array('code' => 'wo', 'name' => _("Work Order Issue")),
- 29=> array('code' => 'wo', 'name' => _("Work Order Production")),
-
- 40=> array('code' => 'qw', 'name' => _("Cheque Withdrawal")),
- 41=> array('code' => 'qd', 'name' => _("Cheque Deposit")),
-
- 50=> array('code' => 'cw', 'name' => _("Cash Withdrawal")),
- 51=> array('code' => 'cd', 'name' => _("Cash Deposit")),
-
- 60=> array('code' => 'ir', 'name' => _("Inventory Release")),
- 61=> array('code' => 'ia', 'name' => _("Inventory Add")),
- 62=> array('code' => 'it', 'name' => _("Inventory Return"))
- );
-
-function getFormTypeName($type)
-{
- global $form_types;
- return $form_types[$type]['name'];
-}
-
-function add_forms_for_sys_type($trans_type, $trans_id, $ParamFrom=null, $ParamTo=null)
-{
- switch ($trans_type) {
- case 1 : // bank payment
- case 22 : // payment to supplier
- add_form_entry(50, $trans_type, $trans_id, $ParamFrom, $ParamTo);
- break;
-
- case 12: // payment from customer
- case 2 : // bank deposit
- add_form_entry(51, $trans_type, $trans_id, $ParamFrom, $ParamTo);
- break;
-
- case 4 : // bank transfer - withdraw and deposit
- add_form_entry(50, $trans_type, $trans_id, $ParamFrom, $ParamTo);
- add_form_entry(51, $trans_type, $trans_id, $ParamTo, $ParamFrom);
- break;
-
- case 10 : // sales invoice - invoice form
- add_form_entry(10, $trans_type, $trans_id);
- break;
-
- case 13 : // sales dispatch - inventory release
- add_form_entry(60, $trans_type, $trans_id, $ParamFrom);
- break;
-
- case 11 : // sales credit - inventory return and credit note forms
- add_form_entry(62, $trans_type, $trans_id, $ParamFrom);
- add_form_entry(11, $trans_type, $trans_id);
- break;
-
- case 16 : // location transfer
- add_form_entry(60, $trans_type, $trans_id, $ParamFrom);
- add_form_entry(61, $trans_type, $trans_id, $ParamTo);
- break;
-
- case systypes::inventory_adjustment() : // inventory adjustment
-
- // $ParamFrom : if 1 inventory add, 0 inventory release
- if ($ParamFrom)
- add_form_entry(61, $trans_type, $trans_id, $ParamTo);
- else
- add_form_entry(60, $trans_type, $trans_id, $ParamTo);
- break;
-
- case systypes::po() : // purchase order
- add_form_entry(18, $trans_type, $trans_id);
- break;
-
- case 25 : // purchase order delivery
- add_form_entry(61, $trans_type, $trans_id, $ParamFrom);
- break;
-
- case systypes::work_order() : // work order
- add_form_entry(26, $trans_type, $trans_id);
- break;
-
- case 28 : // work order issue
- // $ParamFrom : if 1 inventory add, 0 inventory release
- if ($ParamFrom)
- add_form_entry(61, $trans_type, $trans_id, $ParamTo);
- else
- add_form_entry(60, $trans_type, $trans_id, $ParamTo);
- break;
-
- case 29 : // work order production
- // $ParamFrom is the quantity - if +ve inventory add, -ve inventory release
- if ($ParamFrom >= 0)
- add_form_entry(61, $trans_type, $trans_id, $ParamTo);
- else
- add_form_entry(60, $trans_type, $trans_id, $ParamTo);
- break;
-
- case 30 : // sales order - sales order form
- add_form_entry(30, $trans_type, $trans_id);
- break;
- }
-}
-
-function add_form_entry($form_type, $trans_type, $trans_id, $param1=null, $param2=null)
-{
- $sql = "SELECT max(form_id) FROM ".TB_PREF."form_items WHERE form_type=$form_type";
- $result = db_query($sql, "could not get next form_id");
- $row = db_fetch_row($result);
- $form_id = $row[0] + 1;
-
- $sql = "INSERT INTO ".TB_PREF."form_items (form_id, form_type, trans_type, trans_id, param1, param2)
- VALUES ($form_id, $form_type, $trans_type, $trans_id, '$param1', '$param2')";
- $result = db_query($sql, "could not add form entry for $trans_type, $trans_id");
-}
-
-function delete_forms_for_systype($trans_type, $trans_id)
-{
- $sql = "DELETE FROM ".TB_PREF."form_items WHERE trans_type=$trans_type AND trans_id=$trans_id";
- $result = db_query($sql, "could not delete form entry for $trans_type, $trans_id");
-}
-
-function get_form_entries($trans_type, $trans_id)
-{
- $sql = "SELECT * FROM ".TB_PREF."form_items WHERE trans_type=$trans_type AND trans_id=$trans_id";
- $result = db_query($sql, "could not query form entry for $trans_type, $trans_id");
-
- return $result;
-}
-
-?>
\ No newline at end of file
function get_transactions($debtorno, $date)
{
$date = date2sql($date);
-
- $sql = "SELECT ".TB_PREF."debtor_trans.*, ".TB_PREF."sys_types.type_name,
+
+ $sql = "SELECT ".TB_PREF."debtor_trans.*, ".TB_PREF."sys_types.type_name,
(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount)
AS TotalAmount, ".TB_PREF."debtor_trans.alloc AS Allocated,
((".TB_PREF."debtor_trans.type = 10)
_('Allocated'), _('Outstanding'));
$aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
-
+
$params = array( 0 => $comments,
1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''),
2 => array('text' => _('Customer'), 'from' => $from, 'to' => ''),
$sql .= "ORDER BY name";
$result = db_query($sql, "The customers could not be retrieved");
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch($result))
{
if (!$convert && $currency != $myrow['curr_code'])
continue;
$rep->fontSize += 2;
$rep->TextCol(0, 3, $myrow['name']);
if ($convert)
- {
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
$rep->TextCol(3, 4, $myrow['curr_code']);
- }
- else
- $rate = 1.0;
$rep->fontSize -= 2;
$rep->NewLine(1, 2);
$res = get_transactions($myrow['debtor_no'], $to);
if (db_num_rows($res)==0)
continue;
$rep->Line($rep->row + 4);
- $total[0] = $total[1] = $total[2] = $total[3] = 0.0;
+ $total[0] = $total[1] = $total[2] = $total[3] = 0.0;
while ($trans = db_fetch($res))
{
$rep->NewLine(1, 2);
$rep->TextCol(0, 1, $trans['type_name']);
$rep->TextCol(1, 2, $trans['reference']);
- $rep->TextCol(2, 3, sql2date($trans['tran_date']));
- if ($trans['type'] == 10)
+ $date = sql2date($trans['tran_date']);
+ $rep->TextCol(2, 3, $date);
+ if ($trans['type'] == 10)
$rep->TextCol(3, 4, sql2date($trans['due_date']));
- $item[0] = $item[1] = 0.0;
- if ($trans['TotalAmount'] > 0.0)
+ $item[0] = $item[1] = 0.0;
+ if ($convert)
+ $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ else
+ $rate = 1.0;
+ if ($trans['TotalAmount'] > 0.0)
{
- $item[0] = abs($trans['TotalAmount']) * $rate;
+ $item[0] = abs($trans['TotalAmount']) * $rate;
$rep->TextCol(4, 5, number_format2($item[0], $dec));
- }
- else
+ }
+ else
{
- $item[1] = Abs($trans['TotalAmount']) * $rate;
+ $item[1] = Abs($trans['TotalAmount']) * $rate;
$rep->TextCol(5, 6, number_format2($item[1], $dec));
- }
+ }
$item[2] = $trans['Allocated'] * $rate;
$rep->TextCol(6, 7, number_format2($item[2], $dec));
if ($trans['type'] == 10)
- $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
- else
- $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
+ $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
+ else
+ $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
$rep->TextCol(7, 8, number_format2($item[3], $dec));
for ($i = 0; $i < 4; $i++)
{
$total[$i] += $item[$i];
$grandtotal[$i] += $item[$i];
- }
+ }
}
$rep->Line($rep->row - 8);
$rep->NewLine(2);
{
$fromdate = date2sql($from);
$todate = date2sql($to);
-
+
$sql= "SELECT ".TB_PREF."sales_orders.order_no,
".TB_PREF."sales_orders.debtor_no,
".TB_PREF."sales_orders.branch_code,
".TB_PREF."stock_master.description,
".TB_PREF."stock_master.units,
".TB_PREF."sales_order_details.quantity,
- ".TB_PREF."sales_order_details.qty_invoiced
+ ".TB_PREF."sales_order_details.qty_sent
FROM ".TB_PREF."sales_orders
INNER JOIN ".TB_PREF."sales_order_details
ON ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
if ($location != null)
$sql .= " AND ".TB_PREF."sales_orders.from_stk_loc='$location'";
if ($backorder)
- $sql .= "AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced > 0";
- $sql .= " ORDER BY ".TB_PREF."sales_orders.order_no";
-
+ $sql .= "AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent > 0";
+ $sql .= " ORDER BY ".TB_PREF."sales_orders.order_no";
+
return db_query($sql, "Error getting order details");
}
-
+
//----------------------------------------------------------------------------------------------------
function print_order_status_list()
{
global $path_to_root;
-
+
include_once($path_to_root . "reporting/includes/pdf_report.inc");
-
+
$from = $_POST['PARAM_0'];
$to = $_POST['PARAM_1'];
$category = $_POST['PARAM_2'];
$comments = $_POST['PARAM_5'];
$dec = user_qty_dec();
-
+
if ($category == reserved_words::get_all_numeric())
$category = 0;
if ($location == reserved_words::get_all())
$back = _('All Orders');
else
$back = _('Back Orders Only');
-
+
$cols = array(0, 60, 150, 260, 325, 385, 450, 515);
-
+
$headers2 = array(_('Order'), _('Customer'), _('Branch'), _('Customer Ref'),
_('Ord Date'), _('Del Date'), _('Loc'));
-
+
$aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right');
$headers = array(_('Code'), _('Description'), _('Ordered'), _('Invoiced'),
_('Outstanding'), '');
-
+
$params = array( 0 => $comments,
1 => array( 'text' => _('Period'), 'from' => $from, 'to' => $to),
2 => array( 'text' => _('Category'), 'from' => $cat,'to' => ''),
$cols2 = $cols;
$aligns2 = $aligns;
-
+
$rep = new FrontReport(_('Order Status Listing'), "OrderStatusListing.pdf", user_pagesize());
$rep->Font();
$rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
$orderno = 0;
$result = GetSalesOrders($from, $to, $category, $location, $backorder);
-
+
while ($myrow=db_fetch($result))
{
if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
{
$orderno = 0;
$rep->Header();
- }
+ }
$rep->NewLine(0, 2, false, $orderno);
if ($orderno != $myrow['order_no'])
{
$rep->TextCol(5, 6, sql2date($myrow['delivery_date']));
$rep->TextCol(6, 7, $myrow['from_stk_loc']);
$rep->NewLine(2);
- $orderno = $myrow['order_no'];
+ $orderno = $myrow['order_no'];
}
$rep->TextCol(0, 1, $myrow['stk_code']);
$rep->TextCol(1, 2, $myrow['description']);
$rep->TextCol(2, 3, number_format2($myrow['quantity'], $dec));
$rep->TextCol(3, 4, number_format2($myrow['qty_invoiced'], $dec));
- $rep->TextCol(4, 5, number_format2($myrow['quantity'] - $myrow['qty_invoiced'], $dec));
- if ($myrow['quantity'] - $myrow['qty_invoiced'] > 0)
+ $rep->TextCol(4, 5, number_format2($myrow['quantity'] - $myrow['qty_sent'], $dec));
+ if ($myrow['quantity'] - $myrow['qty_sent'] > 0)
{
$rep->Font('italic');
$rep->TextCol(5, 6, _('Outstanding'));
$rep->Font();
- }
+ }
$rep->NewLine();
if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
{
$orderno = 0;
$rep->Header();
- }
- }
+ }
+ }
$rep->Line($rep->row);
$rep->End();
}
function getTransactions($supplier_id, $date)
{
$date = date2sql($date);
-
- $sql = "SELECT ".TB_PREF."supp_trans.*, ".TB_PREF."sys_types.type_name,
+
+ $sql = "SELECT ".TB_PREF."supp_trans.*, ".TB_PREF."sys_types.type_name,
(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)
AS TotalAmount, ".TB_PREF."supp_trans.alloc AS Allocated,
((".TB_PREF."supp_trans.type = 20)
$fromsupp = $_POST['PARAM_1'];
$currency = $_POST['PARAM_2'];
$comments = $_POST['PARAM_3'];
-
+
if ($fromsupp == reserved_words::get_all_numeric())
$from = _('All');
else
$sql .= "WHERE supplier_id=$fromsupp ";
$sql .= "ORDER BY supp_name";
$result = db_query($sql, "The customers could not be retrieved");
-
- while ($myrow=db_fetch($result))
+
+ while ($myrow=db_fetch($result))
{
if (!$convert && $currency != $myrow['curr_code'])
continue;
$rep->fontSize += 2;
$rep->TextCol(0, 3, $myrow['name']);
if ($convert)
- {
- $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
$rep->TextCol(3, 4, $myrow['curr_code']);
- }
- else
- $rate = 1.0;
$rep->fontSize -= 2;
$rep->NewLine(1, 2);
$res = getTransactions($myrow['supplier_id'], $to);
if (db_num_rows($res)==0)
continue;
$rep->Line($rep->row + 4);
- $total[0] = $total[1] = $total[2] = $total[3] = 0.0;
+ $total[0] = $total[1] = $total[2] = $total[3] = 0.0;
while ($trans=db_fetch($res))
{
$rep->NewLine(1, 2);
$rep->TextCol(0, 1, $trans['type_name']);
$rep->TextCol(1, 2, $trans['reference']);
- $rep->TextCol(2, 3, sql2date($trans['tran_date']));
- if ($trans['type'] == 20)
+ $date = sql2date($trans['tran_date']);
+ $rep->TextCol(2, 3, $date);
+ if ($trans['type'] == 20)
$rep->TextCol(3, 4, sql2date($trans['due_date']));
- $item[0] = $item[1] = 0.0;
- if ($trans['TotalAmount'] > 0.0)
+ $item[0] = $item[1] = 0.0;
+ if ($convert)
+ $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
+ else
+ $rate = 1.0;
+ if ($trans['TotalAmount'] > 0.0)
{
- $item[0] = Abs($trans['TotalAmount']) * $rate;
+ $item[0] = Abs($trans['TotalAmount']) * $rate;
$rep->TextCol(4, 5, number_format2($item[0], $dec));
- }
- else
+ }
+ else
{
- $item[1] = Abs($trans['TotalAmount']) * $rate;
+ $item[1] = Abs($trans['TotalAmount']) * $rate;
$rep->TextCol(5, 6, number_format2($item[1], $dec));
- }
+ }
$item[2] = $trans['Allocated'] * $rate;
$rep->TextCol(6, 7, number_format2($item[2], $dec));
if ($trans['type'] == 20)
- $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
- else
- $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
+ $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
+ else
+ $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
$rep->TextCol(7, 8, number_format2($item[3], $dec));
for ($i = 0; $i < 4; $i++)
{
$total[$i] += $item[$i];
$grandtotal[$i] += $item[$i];
- }
+ }
}
$rep->Line($rep->row - 8);
$rep->NewLine(2);
{
$rep->TextCol($i + 4, $i + 5, number_format2($total[$i], $dec));
$total[$i] = 0.0;
- }
+ }
$rep->Line($rep->row - 4);
$rep->NewLine(2);
}
function getCustQty($stockid, $location)
{
- $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced) AS qty_demand
+ $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS qty_demand
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders
WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND
function getCustAsmQty($stockid, $location)
{
- $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced)*".TB_PREF."bom.quantity)
+ $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity)
AS Dem
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders,
WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND
".TB_PREF."sales_orders.from_stk_loc='$location' AND
- ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced > 0 AND
+ ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
".TB_PREF."bom.component='$stockid' AND
".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
".TB_PREF."stock_master.mb_flag='A'";
$category = $_POST['PARAM_0'];
$location = $_POST['PARAM_1'];
$comments = $_POST['PARAM_2'];
-
+
$dec = user_qty_dec();
if ($category == reserved_words::get_all_numeric())
$per3 = strftime('%b',mktime(0,0,0,date('m')-3,date('d'),date('Y')));
$per4 = strftime('%b',mktime(0,0,0,date('m')-4,date('d'),date('Y')));
- $headers = array(_('Category'), '', $per4, $per3, $per2, $per1, $per0, '3*M',
+ $headers = array(_('Category'), '', $per4, $per3, $per2, $per1, $per0, '3*M',
_('QOH'), _('Cust Ord'), _('Supp Ord'), _('Sugg Ord'));
$aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right',
$catt = $trans['cat_description'];
$rep->NewLine();
}
-
+
$custqty = getCustQty($trans['stock_id'], $trans['loc_code']);
$custqty += getCustAsmQty($trans['stock_id'], $trans['loc_code']);
$suppqty = getSuppQty($trans['stock_id'], $trans['loc_code']);
$rep->TextCol(4, 5, number_format2($period['prd2'], $dec));
$rep->TextCol(5, 6, number_format2($period['prd3'], $dec));
$rep->TextCol(6, 7, number_format2($period['prd4'], $dec));
-
+
$MaxMthSales = Max($period['prd0'], $period['prd1'], $period['prd2'], $period['prd3']);
$IdealStockHolding = $MaxMthSales * 3;
$rep->TextCol(7, 8, number_format2($IdealStockHolding, $dec));
-
+
$rep->TextCol(8, 9, number_format2($trans['qty_on_hand'], $dec));
$rep->TextCol(9, 10, number_format2($custqty, $dec));
$rep->TextCol(10, 11, number_format2($suppqty, $dec));
-
+
$SuggestedTopUpOrder = $IdealStockHolding - $trans['qty_on_hand'] + $custqty - $suppqty;
if ($SuggestedTopUpOrder < 0.0)
- $SuggestedTopUpOrder = 0.0;
+ $SuggestedTopUpOrder = 0.0;
$rep->TextCol(11, 12, number_format2($SuggestedTopUpOrder, $dec));
}
$rep->Line($rep->row - 4);
function getDemandQty($stockid, $location)
{
- $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced) AS QtyDemand
+ $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders
WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND
function getDemandAsmQty($stockid, $location)
{
- $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced)*".TB_PREF."bom.quantity)
+ $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity)
AS Dem
FROM ".TB_PREF."sales_order_details,
".TB_PREF."sales_orders,
WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND
".TB_PREF."sales_orders.from_stk_loc='$location' AND
- ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_invoiced > 0 AND
+ ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
".TB_PREF."bom.component='$stockid' AND
".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
".TB_PREF."stock_master.mb_flag='A'";
$location = $_POST['PARAM_1'];
$pictures = $_POST['PARAM_2'];
$comments = $_POST['PARAM_3'];
-
+
$dec = user_qty_dec();
if ($category == reserved_words::get_all_numeric())
$user_comp = user_company();
else
$user_comp = "";
-
+
$rep = new FrontReport(_('Stock Check Sheets'), "StockCheckSheet.pdf", user_pagesize());
$rep->Font();
$rep->row -= $pic_height;
$rep->NewLine();
}
- }
+ }
}
$rep->Line($rep->row - 4);
$rep->End();
function write($policy=0) {
if (count($this->src_docs) == 0 && ($this->trans_type == 10 || $this->trans_type == 13)) {
// direct document -> first add parent
- $src = $this; // make local copy of this cart
+ $src = do_clone($this);
$src->trans_type = get_parent_type($src->trans_type);
$src->reference = 'auto';
add_comments(13, $delivery_no, $delivery->document_date, $delivery->Comments);
if ($trans_no == 0) {
- // add_forms_for_sys_type(13, $delivery_no, $delivery->Location);
if ($delivery->reference!='auto')
references::save_last($delivery->reference, 13);
}
add_comments(10, $invoice_no, $date_, $invoice->Comments);
if ($trans_no == 0) {
- //add_forms_for_sys_type(10, $invoice_no, $invoice->Location);
references::save_last($invoice->reference, 10);
}
} /* inserted line items into sales order details */
- add_forms_for_sys_type(systypes::sales_order(), $order_no);
-
commit_transaction();
if ($loc_notification == 1 && count($st_ids) > 0)
$sql = "DELETE FROM ".TB_PREF."sales_order_details WHERE order_no =" . $order_no;
db_query($sql, "order Detail Delete");
- delete_forms_for_systype(systypes::sales_order(), $order_no);
-
commit_transaction();
}
//----------------------------------------------------------------------------------------
// Mark changes in sales_order_details
//
-function update_sales_order_version($order)
+function update_sales_order_version($order)
{
foreach ($order as $so_num => $so_ver) {
$sql= 'UPDATE '.TB_PREF.'sales_orders SET version=version+1 WHERE order_no='. $so_num.
}
}
}
- $sql = "INSERT INTO ".TB_PREF."sales_order_details
- (order_no, stk_code, description, unit_price, quantity,
- discount_percent, qty_sent)
+ $sql = "INSERT INTO ".TB_PREF."sales_order_details
+ (order_no, stk_code, description, unit_price, quantity,
+ discount_percent, qty_sent)
VALUES (";
$sql .= $order_no . ",'"
.$line->stock_id . "','"
$subject = _("Stocks below Re-Order Level at " . $loc['location_name']);
$msg = "\n";
for ($i = 0; $i < count($st_ids); $i++)
- $msg .= $st_ids[$i] . " " . $st_names[$i] . ", "
- . _("Re-Order Level") . ": " . $st_reorder[$i] . ", "
+ $msg .= $st_ids[$i] . " " . $st_names[$i] . ", "
+ . _("Re-Order Level") . ": " . $st_reorder[$i] . ", "
. _("Below") . ": " . $st_num[$i] . "\n";
$msg .= "\n" . _("Please reorder") . "\n\n";
$msg .= $company['coy_name'];
function get_sales_order_details($order_no) {
$sql = "SELECT id, stk_code, unit_price, "
.TB_PREF."sales_order_details.description,"
- .TB_PREF."sales_order_details.quantity,
+ .TB_PREF."sales_order_details.quantity,
discount_percent,
qty_sent as qty_done, "
.TB_PREF."stock_master.units,
$order->so_type = $myrow["type"];
$order->trans_no = array($order_no=> $myrow["version"]);
- $order->set_customer($myrow["debtor_no"], $myrow["name"],
+ $order->set_customer($myrow["debtor_no"], $myrow["name"],
$myrow["curr_code"], $myrow["discount"]);
$order->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
$order->set_location($myrow["from_stk_loc"], $myrow["location_name"]);
- $order->set_delivery($myrow["ship_via"], $myrow["deliver_to"],
+ $order->set_delivery($myrow["ship_via"], $myrow["deliver_to"],
$myrow["delivery_address"], $myrow["freight_cost"]);
-
+
$order->cust_ref = $myrow["customer_ref"];
$order->default_sales_type =$myrow["order_type"];
$order->Comments = $myrow["comments"];
}
function get_branch_to_order($customer_id, $branch_id) {
-
+
// the branch was also selected from the customer selection so default the delivery details from the customer branches table cust_branch. The order process will ask for branch details later anyway
$sql = "SELECT ".TB_PREF."cust_branch.br_name, "
.TB_PREF."cust_branch.br_address, "
-- ALTER TABLE
--
+DROP TABLE IF EXISTS `0_form_items`;
ALTER TABLE `0_tax_types` DROP INDEX `name`, ADD UNIQUE `name` ( `name` , `rate` );