From 9b852b19c91b5af6400cf94a9ff65d37d1a730b4 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Fri, 31 Jul 2009 17:07:51 +0000 Subject: [PATCH] Merged changes from main trunk up to version_2_1_4 --- CHANGELOG.txt | 98 +++++++++++++++++ admin/attachments.php | 46 +++++--- config.php | 2 +- gl/includes/db/gl_db_banking.inc | 2 +- gl/includes/db/gl_db_trans.inc | 26 ++--- gl/manage/bank_accounts.php | 11 +- includes/db/manufacturing_db.inc | 2 +- inventory/purchasing_data.php | 8 +- purchasing/includes/db/invoice_db.inc | 42 ++++++-- purchasing/includes/purchasing_db.inc | 4 +- purchasing/manage/suppliers.php | 2 +- purchasing/view/view_grn.php | 6 +- purchasing/view/view_supp_payment.php | 4 +- reporting/includes/doctext.inc | 14 ++- reporting/includes/doctext2.inc | 14 ++- reporting/includes/header2.inc | 2 +- reporting/includes/pdf_report.inc | 26 ++--- reporting/rep101.php | 2 +- reporting/rep109.php | 1 + reporting/rep201.php | 2 +- reporting/rep304.php | 148 +++++++++++--------------- reporting/rep709.php | 4 +- reporting/reports_main.php | 2 +- sales/create_recurrent_invoices.php | 2 +- sales/includes/db/cust_trans_db.inc | 3 + sales/sales_order_entry.php | 2 +- sales/view/view_receipt.php | 2 +- 27 files changed, 308 insertions(+), 169 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 88a8e032..4f8e73cf 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,33 @@ Legend: ! -> Note $ -> Affected files +31-Jul-2009 Janusz Dobrowolski +! Merged changes from main trunk 2.1.3-2.1.4 (see below) +$ /admin/attachments.php + /inventory/purchasing_data.php + /includes/db/manufacturing.inc + /gl/manage/bank_accounts.php + /gl/includes/db/gl_db_banking.inc + /gl/includes/db/gl_db_trans.inc + /purchasing/includes/purchasing_db.inc + /purchasing/manage/suppliers.php + /purchasing/view/view_grn.php + /purchasing/includes/db/invoice_db.inc + /purchasing/view/view_supp_payment.php + /reporting/reports_main.php + /reporting/includes/doctext.inc + /reporting/includes/doctext2.inc + /reporting/includes/header2.inc + /reporting/includes/pdf_report.inc + /reporting/rep101.php + /reporting/rep109.php + /reporting/rep201.php + /reporting/rep304.php + /reporting/rep709.php + /sales/includes/db/cust_trans_db.inc + /sales/create_recurrent_invoices.php + /sales/sales_order_entry.php + /sales/view/view_receipt.php 27-Jul-2009 Janusz Dobrowolski # Fixed default selection in popup @@ -833,6 +860,77 @@ $ /.htaccess /sales/inquiry/sales_deliveries_view.php /sales/inquiry/sales_orders_view.php +------------------------------- Release 2.1.4 ---------------------------------- +30-Jul-2009 Joe Hunt +! Release 2.1.4 +$ config.php +# Bad right margin on Tax Report (papersize A4) +$ /reporting/rep709.php +# [0000146] Purch data description with a ' (apostrophe) fails +$ /inventory/purchasing_data.php + /purchasing/includes/purchasing_db.inc + +28-Jul-2009 Joe Hunt +# Bugs in sending documents as email. Seems to land in the spam filter due to bad text and scrambled name on attached documents +$ /reporting/rep109.php + /reporting/includes/doctext.inc + /reporting/includes/doctext2.inc + /reporting/includes/header2.inc + /reporting/includes/pdf_report.inc + +18-Jul-2009 Joe Hunt +# When saving a Payment to a Customer in Bank Payments (normally payment to suppliers) it was saved with wrong sign in debtor_trans (very rare). +$ /sales/includes/db/cust_trans_db.inc +# Wrong presentation in customer/supplier balance if using bank payments for customers and bank deposits for suppliers (very rare) +$ /reporting/rep101.php + /reporting/rep201.php + +13-Jul-2009 Joe Hunt +# Bug in Tax Inquiry and Tax Report when entering in Journal Entry +$ /gl/includes/db/gl_db_banking.inc + /gl/includes/db/gl_db_trans.inc + /reporting/rep709.php +! Comments should follow templates and recurrent invoices. +$ /sales/create_recurrent_invoices.php + /sales/sales_order_entry.php + +12-Jul-2009 Joe Hunt +# Wrong presentation of left to allocate if discount was given +$ /sales/view/view_receipt.php + /purchasing/view/view_supp_payment.php + +11-Jul-2009 Joe Hunt +! Improved Inventory Sales Report. Now by Customer and quantities as well. +$ /reporting/rep304.php + /reporting/reports_main.php + +10-Jul-2009 Joe Hunt +# [0000142] Purchase Order use the same header as Sales Order +$ /reporting/includes/doctext.inc + /reporting/includes/doctext2.inc +# Bug in demand qty +$ /includes/db/manufacturing.inc + +10-Jul-2009 Janusz Dobrowolski +# [0000141] Attachment view/download bug. +$ /admin/attachments.php +# [0000140] Numeric format bug in credit limit input. +$ /purchasing/manage/suppliers.php +# [0000143] Bad format of PO popup window (jackel7007). +$ /purchasing/view/view_grn.php + +09-Jul-2009 Janusz Dobrowolski +# [0000139] Change of bank account type after creation should not be allowed. +$ /gl/manage/bank_accounts.php + +01-Jul-2009 Joe Hunt +# Guess what :) [0000137] Material Cost Averaging Problem (again again again) when voiding. +$ /purchasing/includes/db/invoice_db.inc + +26-Jun-2009 Joe Hunt +# [0000137] Material Cost Averaging Problem (again again) when voiding. +$ /purchasing/includes/db/invoice_db.inc + ------------------------------- Release 2.1.3 ---------------------------------- 25-Jun-2009 Joe Hunt ! Release 2.1.3 diff --git a/admin/attachments.php b/admin/attachments.php index 773ac80b..8a7dba1c 100644 --- a/admin/attachments.php +++ b/admin/attachments.php @@ -18,36 +18,50 @@ include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/data_checks.inc"); +if (isset($_GET['vw'])) + $view_id = $_GET['vw']; +else $view_id = find_submit('view'); if ($view_id != -1) { $row = get_attachment($view_id); if ($row['filename'] != "") { - $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream'; - header("Content-type: ".$type); - header('Content-Length: '.$row['filesize']); - if ($type == 'application/octet-stream') - header('Content-Disposition: attachment; filename='.$row['filename']); - else - header("Content-Disposition: inline"); - echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); - exit(); + if(in_ajax()) { + $Ajax->popup($_SERVER['PHP_SELF'].'?vw='.$view_id); + } else { + $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream'; + header("Content-type: ".$type); + header('Content-Length: '.$row['filesize']); + if ($type == 'application/octet-stream') + header('Content-Disposition: attachment; filename='.$row['filename']); + else + header("Content-Disposition: inline"); + echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); + exit(); + } } } +if (isset($_GET['dl'])) + $download_id = $_GET['dl']; +else + $download_id = find_submit('download'); -$download_id = find_submit('download'); if ($download_id != -1) { $row = get_attachment($download_id); if ($row['filename'] != "") { - $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream'; - header("Content-type: ".$type); - header('Content-Length: '.$row['filesize']); - header('Content-Disposition: attachment; filename='.$row['filename']); - echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); - exit(); + if(in_ajax()) { + $Ajax->redirect($_SERVER['PHP_SELF'].'?dl='.$download_id); + } else { + $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream'; + header("Content-type: ".$type); + header('Content-Length: '.$row['filesize']); + header('Content-Disposition: attachment; filename='.$row['filename']); + echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); + exit(); + } } } diff --git a/config.php b/config.php index a25d938d..d6eeddf2 100644 --- a/config.php +++ b/config.php @@ -56,7 +56,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ // Main Title $app_title = "FrontAccounting"; // application version - $version = "2.2m3 CVS"; + $version = "2.2m4 CVS"; // Build for development purposes $build_version = date("d.m.Y", filemtime("$path_to_root/CHANGELOG.txt")); diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index a47dd73a..e73e1e3a 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -211,7 +211,7 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_, $amount = $gl_item->amount; $ex_rate = get_exchange_rate_from_home_currency($currency, $date_); - add_gl_tax_details($gl_item->code_id, $trans_type, $trans_no, $amount, + add_gl_tax_details($gl_item->code_id, $trans_type, $trans_no, -$amount, $ex_rate, $date_, $memo_); } diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index 5b559d33..111d4e33 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -260,8 +260,8 @@ function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, if(!$tax_type) return; // $gl_code is not tax account $tax = get_tax_type($tax_type); - if ($gl_code == $tax['sales_gl_code']) - $amount = -$amount; + //if ($gl_code == $tax['sales_gl_code']) + // $amount = -$amount; // we have to restore net amount as we cannot know the base amount if ($tax['rate'] == 0) { // display_warning(_("You should not post gl transactions @@ -329,14 +329,14 @@ function get_tax_summary($from, $to) $todate = date2sql($to); $sql = "SELECT - SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)* - IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output, - SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)* - IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable, - SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)* - IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input, - SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)* - IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible, + SUM(IF(trans_type=11 || trans_type=20,-1,1)* + IF(trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output, + SUM(IF(trans_type=11 || trans_type=20,-1,1)* + IF(trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable, + SUM(IF(trans_type=11 || trans_type=20,-1,1)* + IF(trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input, + SUM(IF(trans_type=11 || trans_type=20,-1,1)* + IF(trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible, taxrec.rate, ttype.id, ttype.name @@ -388,7 +388,7 @@ function write_journal_entries(&$cart, $reverse) } // store tax details if the gl account is a tax account add_gl_tax_details($journal_item->code_id, - $trans_type, $trans_id, -$journal_item->amount, 1, $date_, $memo_); + ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, -$journal_item->amount, 1, $date_, $memo_); } if ($new) { @@ -419,13 +419,13 @@ function write_journal_entries(&$cart, $reverse) if ($is_bank_to) { add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref, - $reversingDate, $journal_item->amount, + $reversingDate, -$journal_item->amount, 0, "", get_company_currency(), "Cannot insert a destination bank transaction"); } // store tax details if the gl account is a tax account add_gl_tax_details($journal_item->code_id, - $trans_type, $trans_id, $journal_item->amount, 1, $reversingDate, $memo_); + ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, $journal_item->amount, 1, $date, $memo_); } add_comments($trans_type, $trans_id_reverse, $reversingDate, $memo_); diff --git a/gl/manage/bank_accounts.php b/gl/manage/bank_accounts.php index 26fe90d5..20f492b7 100644 --- a/gl/manage/bank_accounts.php +++ b/gl/manage/bank_accounts.php @@ -157,14 +157,21 @@ if ($is_editing) } hidden('selected_id', $selected_id); hidden('account_code'); + hidden('account_type'); hidden('BankAccountCurrency', $_POST['BankAccountCurrency']); set_focus('bank_account_name'); } text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100); -bank_account_types_list_row(_("Account Type:"), 'account_type', null); - +if ($is_editing) +{ + label_row(_("Account Type:"), bank_account_types::name($_POST['account_type'])); +} +else +{ + bank_account_types_list_row(_("Account Type:"), 'account_type', null); +} if ($is_editing) { label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']); diff --git a/includes/db/manufacturing_db.inc b/includes/db/manufacturing_db.inc index c2f34d9b..1153010d 100644 --- a/includes/db/manufacturing_db.inc +++ b/includes/db/manufacturing_db.inc @@ -60,7 +60,7 @@ function stock_demand_manufacture($stock_id, $qty, $demand_id, $location, $level } $stock_qty = $qoh_stock[$stock_id]; if ($stock_qty == NULL) $stock_qty = 0; - if ($qty < $stock_qty) return $demand; + if ($qty <= $stock_qty) return $demand; $bom = $bom_list[$stock_id]; if ($bom == NULL) { $sql = "SELECT parent, component, quantity FROM ".TB_PREF."bom WHERE parent = '$stock_id'"; diff --git a/inventory/purchasing_data.php b/inventory/purchasing_data.php index 69d4b91e..50368901 100644 --- a/inventory/purchasing_data.php +++ b/inventory/purchasing_data.php @@ -59,17 +59,17 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom, conversion_factor, supplier_description) VALUES ("; $sql .= "'".$_POST['supplier_id']."', '" . $_POST['stock_id'] . "', " . - input_num('price') . ", '" . $_POST['suppliers_uom'] . "', " . - input_num('conversion_factor') . ", '" . $_POST['supplier_description'] . "')"; + input_num('price',0) . ", '" . $_POST['suppliers_uom'] . "', " . + input_num('conversion_factor') . ", " . db_escape($_POST['supplier_description']) . ")"; db_query($sql,"The supplier purchasing details could not be added"); display_notification(_("This supplier purchasing data has been added.")); } else { - $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price') . ", + $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price',0) . ", suppliers_uom='" . $_POST['suppliers_uom'] . "', conversion_factor=" . input_num('conversion_factor') . ", - supplier_description='" . $_POST['supplier_description'] . "' + supplier_description=" . db_escape($_POST['supplier_description']) . " WHERE stock_id='" . $_POST['stock_id'] . "' AND supplier_id='$selected_id'"; db_query($sql,"The supplier purchasing details could not be updated"); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 41918591..56961e85 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -401,10 +401,21 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans) //---------------------------------------------------------------------------------------- +function get_matching_invoice_item($stock_id, $po_item_id) +{ + $sql = "SELECT *, tran_date FROM ".TB_PREF."supp_invoice_items, ".TB_PREF."supp_trans + WHERE supp_trans_type = 20 AND stock_id = '$stock_id' AND po_detail_item_id = $po_item_id + AND supp_trans_no = trans_no"; + $result = db_query($sql, "Cannot retreive supplier transaction detail records"); + return db_fetch($result); +} + function void_supp_invoice($type, $type_no) { begin_transaction(); + $trans = get_supp_trans($type_no, $type); + void_bank_trans($type, $type_no, true); void_gl_trans($type, $type_no, true); @@ -433,22 +444,33 @@ function void_supp_invoice($type, $type_no) $batch = get_grn_batch_from_item($details_row["grn_item_id"]); $grn = get_grn_batch($batch); if ($type == 21) // credit note 2009-06-14 Joe Hunt Must restore the po and grn - { + { // We must get the corresponding invoice item to check for price chg. + $match = get_matching_invoice_item($details_row["stock_id"], $details_row["po_detail_item_id"]); + if ($match !== false) + $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"], + $match["unit_price"], -$details_row["quantity"], sql2date($match['tran_date']), $match['tran_date'] !== $trans['tran_date']); + else + $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"], + $details_row["FullUnitPrice"], -$details_row["quantity"], $old_date, $old[1] !== $trans['tran_date']); $sql = "UPDATE ".TB_PREF."purch_order_details - SET quantity_ordered = quantity_ordered + ".-$details_row["quantity"].", - quantity_received = quantity_received + ".-$details_row["quantity"]." + SET quantity_ordered = quantity_ordered + ".-$details_row["quantity"].", "; + if ($match !== false) + $sql .= "act_price=".$match['unit_price'].", "; + $sql .= "quantity_received = quantity_received + ".-$details_row["quantity"]." WHERE po_detail_item = ".$details_row["po_detail_item_id"]; db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed "); $sql = "UPDATE ".TB_PREF."grn_items SET qty_recd=qty_recd+".-$details_row["quantity"]." WHERE id=".$details_row["grn_item_id"]; db_query($sql); - } - $diff = get_diff_in_home_currency($grn["supplier_id"], $old_date, $date_, $old[2], - $details_row["FullUnitPrice"]); - // Only adjust the avg for the diff - $mat_cost = update_average_material_cost(null, $details_row["stock_id"], - $diff, -$details_row["quantity"], $old_date, true); - + } + else + { + $diff = get_diff_in_home_currency($grn["supplier_id"], $old_date, sql2date($trans['tran_date']), $old[2], + $details_row["FullUnitPrice"]); + // Only adjust the avg for the diff + $mat_cost = update_average_material_cost(null, $details_row["stock_id"], + $diff, -$details_row["quantity"], $old_date, true); + } $deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_); if ($deliveries[0] != 0) // have deliveries been done during the period? { diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index da038358..850d2291 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -98,7 +98,7 @@ function add_or_update_purchase_data($supplier_id, $stock_id, $price, $descripti { $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom, conversion_factor, supplier_description) VALUES ('$supplier_id', '$stock_id', - $price, '$uom', 1, '$description')"; + $price, '$uom', 1, ".db_escape($description).")"; db_query($sql,"The supplier purchasing details could not be added"); return; } @@ -107,7 +107,7 @@ function add_or_update_purchase_data($supplier_id, $stock_id, $price, $descripti if ($uom != "") $sql .= ",suppliers_uom='$uom'"; if ($description != "") - $sql .= ",supplier_description='$description'"; + $sql .= ",supplier_description=".db_escape($description); $sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'"; db_query($sql,"The supplier purchasing details could not be updated"); return true; diff --git a/purchasing/manage/suppliers.php b/purchasing/manage/suppliers.php index 45c4d119..809ebb3c 100644 --- a/purchasing/manage/suppliers.php +++ b/purchasing/manage/suppliers.php @@ -97,7 +97,7 @@ if (isset($_POST['submit'])) .db_escape($_POST['contact']). ", " .db_escape($_POST['supp_account_no']). ", " .db_escape($_POST['bank_account']). ", " - .db_escape($_POST['credit_limit']). ", " + .input_num('credit_limit',0). ", " .db_escape($_POST['dimension_id']). ", " .db_escape($_POST['dimension2_id']). ", " .db_escape($_POST['curr_code']). ", " diff --git a/purchasing/view/view_grn.php b/purchasing/view/view_grn.php index 299cf5b6..9a8cbc7f 100644 --- a/purchasing/view/view_grn.php +++ b/purchasing/view/view_grn.php @@ -14,7 +14,11 @@ $path_to_root="../.."; include($path_to_root . "/purchasing/includes/po_class.inc"); include($path_to_root . "/includes/session.inc"); -page(_("View Purchase Order Delivery"), true); + +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); +page(_("View Purchase Order Delivery"), true, false, "", $js); include($path_to_root . "/purchasing/includes/purchasing_ui.inc"); diff --git a/purchasing/view/view_supp_payment.php b/purchasing/view/view_supp_payment.php index 3b6d7533..793f6d41 100644 --- a/purchasing/view/view_supp_payment.php +++ b/purchasing/view/view_supp_payment.php @@ -66,7 +66,7 @@ if ($show_currencies) label_cells(_("Supplier's Currency"), $receipt['SupplierCurrCode'], "class='tableheader2'"); } if ($show_both_amounts) - label_cells(_("Amount"), number_format2(-$receipt['ov_amount'], user_price_dec()), "class='tableheader2'"); + label_cells(_("Amount"), number_format2(-$receipt['Total'], user_price_dec()), "class='tableheader2'"); label_cells(_("Reference"), $receipt['ref'], "class='tableheader2'"); end_row(); comments_display_row(22, $trans_no); @@ -78,7 +78,7 @@ $voided = is_voided_display(22, $trans_no, _("This payment has been voided.")); // now display the allocations for this payment if (!$voided) { - display_allocations_from(payment_person_types::supplier(), $receipt['supplier_id'], 22, $trans_no, -$receipt['ov_amount']); + display_allocations_from(payment_person_types::supplier(), $receipt['supplier_id'], 22, $trans_no, -$receipt['Total']); } end_page(true); diff --git a/reporting/includes/doctext.inc b/reporting/includes/doctext.inc index f29822a7..dfd8f629 100644 --- a/reporting/includes/doctext.inc +++ b/reporting/includes/doctext.inc @@ -13,8 +13,16 @@ if (isset($header2type)) { $doc_Cust_no = _("Cust no"); $doc_Date = _("Date"); - $doc_Charge_To = _("Charge To"); - $doc_Delivered_To = _("Delivered To"); + if ($doctype == 8) // Purchase Order + { + $doc_Charge_To = _("Order To"); + $doc_Delivered_To = _("Charge To"); + } + else + { + $doc_Charge_To = _("Charge To"); + $doc_Delivered_To = _("Delivered To"); + } $doc_Shipping_Company = _("Shipping Company"); if ($doctype == 9) $doc_Due_Date = _("Delivery Date"); @@ -87,7 +95,7 @@ if (isset($header2type)) } if (isset($emailtype)) { - $doc_Dear_Sirs = _("Dear Sirs"); + $doc_Dear_Sirs = _("Dear"); $doc_AttachedFile = _("Attached you will find "); $doc_Kindest_regards = _("Kindest regards"); $doc_Payment_Link = _("You can pay through"); diff --git a/reporting/includes/doctext2.inc b/reporting/includes/doctext2.inc index 16460053..92f27507 100644 --- a/reporting/includes/doctext2.inc +++ b/reporting/includes/doctext2.inc @@ -13,8 +13,16 @@ if (isset($header2type)) { $doc_Cust_no = "Cust no"; $doc_Date = "Date"; - $doc_Charge_To = "Charge To"; - $doc_Delivered_To = "Delivered To"; + if ($doctype == 8) // Purchase Order + { + $doc_Charge_To = "Order To"; + $doc_Delivered_To = "Charge To"; + } + else + { + $doc_Charge_To = "Charge To"; + $doc_Delivered_To = "Delivered To"; + } $doc_Shipping_Company = "Shipping Company"; if ($doctype == 9) $doc_Due_Date = "Delivery Date"; @@ -86,7 +94,7 @@ if (isset($header2type)) } if (isset($emailtype)) { - $doc_Dear_Sirs = "Dear Sirs"; + $doc_Dear_Sirs = "Dear"; $doc_AttachedFile = "Attached you will find "; $doc_Kindest_regards = "Kindest regards"; $doc_Payment_Link = "You can pay through"; diff --git a/reporting/includes/header2.inc b/reporting/includes/header2.inc index a857da9b..fd48fba9 100644 --- a/reporting/includes/header2.inc +++ b/reporting/includes/header2.inc @@ -312,7 +312,7 @@ if (($doctype == 10 || $doctype == 12) && $this->company['legal_text'] != "") { $this->TextWrap($ccol, $this->row, $right - $ccol, $this->company['legal_text'], 'C'); - $this->NewLine(); +// $this->NewLine(); } $this->Font(); $temp = $iline6 - $this->lineHeight - 2; diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index b0277f1e..3d072e66 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -9,6 +9,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +$page_security = 8; //include_once($path_to_root . "reporting/includes/class.pdf.inc"); include_once(dirname(__FILE__)."/class.pdf.inc"); include_once(dirname(__FILE__)."/printer_class.inc"); @@ -413,7 +414,10 @@ class FrontReport extends Cpdf } // do not use standard filenames or your sensitive company data // are world readable - $fname = $dir.'/'.uniqid('').'.pdf'; + if ($email == 1) + $fname = $dir.'/'.$this->filename; + else + $fname = $dir.'/'.uniqid('').'.pdf'; $this->Output($fname, 'F'); if ($email == 1) { @@ -428,12 +432,12 @@ class FrontReport extends Cpdf } require_once($path_to_root . "/reporting/includes/class.mail.inc"); $mail = new email($this->company['coy_name'], $this->company['email']); - $from = $this->company['coy_name'] . " <" . $this->company['email'] . ">"; - if ($myrow['email'] == '') $myrow['email'] = $myrow['contact_email']; + if (!isset($myrow['email']) || $myrow['email'] == '') + $myrow['email'] = $myrow['contact_email']; $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">"; $msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject . "\n\n"; - if ($myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links + if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links { if ($myrow['dimension_id'] == 1) { @@ -452,24 +456,12 @@ class FrontReport extends Cpdf $mail->text($msg . $sender); $mail->attachment($fname); $ret = $mail->send(); - if (1 == 1) // just for fun and for debugging purposes!! - { - $from = str_replace("<", "(", $from); - $from = str_replace(">", ")", $from); - $to = str_replace("<", "(", $to); - $to = str_replace(">", ")", $to); - $msg2 = "
From: " . $from; - $msg2 .= "
To: " . $to; - $msg2 .= "
Subject: " . $subject; - $msg2 .= "
Msg: " . nl2br($msg); - $msg2 .= nl2br($sender) . "
"; - $msg2 .= "
Filepath: " . $fname . "
Filename: " . $this->filename . "
"; - } if (!$ret) display_error(_("Sending document by email failed")); else display_notification($this->title . " " . $myrow['reference'] . " " . _("has been sent by email.")); + unlink($fname); } else { diff --git a/reporting/rep101.php b/reporting/rep101.php index 9476d543..d8f37c77 100644 --- a/reporting/rep101.php +++ b/reporting/rep101.php @@ -207,7 +207,7 @@ function print_customer_balances() else $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate; */ - if ($trans['type'] == 10) + if ($trans['type'] == 10 || $trans['type'] == 1) $item[3] = $item[0] + $item[1] - $item[2]; else $item[3] = $item[0] - $item[1] + $item[2]; diff --git a/reporting/rep109.php b/reporting/rep109.php index 7c57da3f..00b06d2e 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -163,6 +163,7 @@ function print_sales_orders() $myrow['contact_email'] = $branch['email']; $myrow['DebtorName'] = $branch['br_name']; } + $myrow['reference'] = $i; $rep->End($email, $doc_Invoice_no . " " . $i, $myrow); } } diff --git a/reporting/rep201.php b/reporting/rep201.php index 45ce3ef9..756e83c6 100644 --- a/reporting/rep201.php +++ b/reporting/rep201.php @@ -198,7 +198,7 @@ function print_supplier_balances() else $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate; */ - if ($trans['type'] == 20) + if ($trans['type'] == 20 || $trans['type'] == 2) $item[3] = $item[0] + $item[1] - $item[2]; else $item[3] = $item[0] - $item[1] + $item[2]; diff --git a/reporting/rep304.php b/reporting/rep304.php index 8929b1e6..bb4006f1 100644 --- a/reporting/rep304.php +++ b/reporting/rep304.php @@ -29,7 +29,7 @@ include_once($path_to_root . "/inventory/includes/db/items_category_db.inc"); print_inventory_sales(); -function getTransactions($category, $location, $from, $to) +function getTransactions($category, $location, $fromcust, $from, $to) { $from = date2sql($from); $to = date2sql($to); @@ -39,16 +39,19 @@ function getTransactions($category, $location, $from, $to) ".TB_PREF."stock_master.description, ".TB_PREF."stock_moves.loc_code, ".TB_PREF."debtor_trans.debtor_no, + ".TB_PREF."debtors_master.name AS debtor_name, ".TB_PREF."stock_moves.tran_date, - -".TB_PREF."stock_moves.qty*".TB_PREF."stock_moves.price*(1-".TB_PREF."stock_moves.discount_percent) AS amt, - -".TB_PREF."stock_moves.qty *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost) AS cost + SUM(-".TB_PREF."stock_moves.qty) AS qty, + SUM(-".TB_PREF."stock_moves.qty*".TB_PREF."stock_moves.price*(1-".TB_PREF."stock_moves.discount_percent)) AS amt, + SUM(-".TB_PREF."stock_moves.qty *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost)) AS cost FROM ".TB_PREF."stock_master, ".TB_PREF."stock_category, ".TB_PREF."debtor_trans, + ".TB_PREF."debtors_master, ".TB_PREF."stock_moves WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id - + AND ".TB_PREF."debtor_trans.debtor_no=".TB_PREF."debtors_master.debtor_no AND ".TB_PREF."stock_moves.type=".TB_PREF."debtor_trans.type AND ".TB_PREF."stock_moves.trans_no=".TB_PREF."debtor_trans.trans_no AND ".TB_PREF."stock_moves.tran_date>='$from' @@ -59,9 +62,10 @@ function getTransactions($category, $location, $from, $to) $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'"; if ($location != 'all') $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'"; - //$sql .= " AND SUM(".TB_PREF."stock_moves.qty) != 0 - $sql .= " ORDER BY ".TB_PREF."stock_master.category_id, - ".TB_PREF."stock_master.stock_id"; + if ($fromcust != -1) + $sql .= " AND ".TB_PREF."debtors_master.debtor_no = $fromcust"; + $sql .= " GROUP BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."debtors_master.name ORDER BY ".TB_PREF."stock_master.category_id, + ".TB_PREF."stock_master.stock_id, ".TB_PREF."debtors_master.name"; return db_query($sql,"No transactions were returned"); } @@ -76,7 +80,7 @@ function print_inventory_sales() $to = $_POST['PARAM_1']; $category = $_POST['PARAM_2']; $location = $_POST['PARAM_3']; - $detail = $_POST['PARAM_4']; + $fromcust = $_POST['PARAM_4']; $comments = $_POST['PARAM_5']; $destination = $_POST['PARAM_6']; if ($destination) @@ -100,16 +104,24 @@ function print_inventory_sales() else $loc = get_location_name($location); - $cols = array(0, 100, 250, 350, 450, 515); + if ($fromcust == reserved_words::get_all_numeric()) + $fromc = _('All'); + else + $fromc = get_customer_name($fromcust); + + $cols = array(0, 75, 175, 250, 300, 375, 450, 515); - $headers = array(_('Category'), '', _('Sales'), _('Cost'), _('Contribution')); + $headers = array(_('Category'), _('Description'), _('Customer'), _('Qty'), _('Sales'), _('Cost'), _('Contribution')); + if ($fromcust != reserved_words::get_all_numeric()) + $headers[2] = ''; - $aligns = array('left', 'left', 'right', 'right', 'right'); + $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right'); $params = array( 0 => $comments, 1 => array('text' => _('Period'),'from' => $from, 'to' => $to), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), - 3 => array('text' => _('Location'), 'from' => $loc, 'to' => '')); + 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''), + 4 => array('text' => _('Customer'), 'from' => $fromc, 'to' => '')); $rep = new FrontReport(_('Inventory Sales Report'), "InventorySalesReport", user_pagesize()); @@ -117,101 +129,71 @@ function print_inventory_sales() $rep->Info($params, $cols, $headers, $aligns); $rep->Header(); - $res = getTransactions($category, $location, $from, $to); + $res = getTransactions($category, $location, $fromcust, $from, $to); $total = $grandtotal = 0.0; $total1 = $grandtotal1 = 0.0; $total2 = $grandtotal2 = 0.0; - $amt = $cost = $cb = 0; - $catt = $stock_id = $stock_desc = ''; + $catt = ''; while ($trans=db_fetch($res)) { if ($catt != $trans['cat_description']) { if ($catt != '') { - if ($detail) - { - $rep->NewLine(2, 3); - $rep->TextCol(0, 2, _('Total')); - } - $rep->AmountCol(2, 3, $total, $dec); - $rep->AmountCol(3, 4, $total1, $dec); - $rep->AmountCol(4, 5, $total2, $dec); - if ($detail) - { - $rep->Line($rep->row - 2); - $rep->NewLine(); - } + $rep->NewLine(2, 3); + $rep->TextCol(0, 4, _('Total')); + $rep->AmountCol(4, 5, $total, $dec); + $rep->AmountCol(5, 6, $total1, $dec); + $rep->AmountCol(6, 7, $total2, $dec); + $rep->Line($rep->row - 2); + $rep->NewLine(); $rep->NewLine(); $total = $total1 = $total2 = 0.0; } $rep->TextCol(0, 1, $trans['category_id']); - $rep->TextCol(1, 2, $trans['cat_description']); + $rep->TextCol(1, 6, $trans['cat_description']); $catt = $trans['cat_description']; - if ($detail) - $rep->NewLine(); - } - if ($stock_id != $trans['stock_id']) - { - if ($stock_id != '') - { - if ($detail) - { - $rep->NewLine(); - $rep->fontsize -= 2; - $rep->TextCol(0, 1, $stock_id); - $rep->TextCol(1, 2, $stock_desc); - $rep->AmountCol(2, 3, $amt, $dec); - $rep->AmountCol(3, 4, $cost, $dec); - $rep->AmountCol(4, 5, $cb, $dec); - $rep->fontsize += 2; - } - $amt = $cost = $cb = 0; - } - $stock_id = $trans['stock_id']; - $stock_desc = $trans['description']; + $rep->NewLine(); } + $curr = get_customer_currency($trans['debtor_no']); $rate = get_exchange_rate_from_home_currency($curr, sql2date($trans['tran_date'])); $trans['amt'] *= $rate; - $amt += $trans['amt']; - $cost += $trans['cost']; - $cb1 = $trans['amt'] - $trans['cost']; - $cb += $cb1; + $cb = $trans['amt'] - $trans['cost']; + $rep->NewLine(); + $rep->fontsize -= 2; + $rep->TextCol(0, 1, $trans['stock_id']); + if ($fromcust == reserved_words::get_all_numeric()) + { + $rep->TextCol(1, 2, $trans['description']); + $rep->TextCol(2, 3, $trans['debtor_name']); + } + else + $rep->TextCol(1, 3, $trans['description']); + $rep->AmountCol(3, 4, $trans['qty'], get_qty_dec($trans['stock_id'])); + $rep->AmountCol(4, 5, $trans['amt'], $dec); + $rep->AmountCol(5, 6, $trans['cost'], $dec); + $rep->AmountCol(6, 7, $cb, $dec); + $rep->fontsize += 2; $total += $trans['amt']; $total1 += $trans['cost']; - $total2 += $cb1; + $total2 += $cb; $grandtotal += $trans['amt']; $grandtotal1 += $trans['cost']; - $grandtotal2 += $cb1; - } - if ($detail) - { - $rep->NewLine(); - $rep->fontsize -= 2; - $rep->TextCol(0, 1, $stock_id); - $rep->TextCol(1, 2, $stock_desc); - $rep->AmountCol(2, 3, $amt, $dec); - $rep->AmountCol(3, 4, $cost, $dec); - $rep->AmountCol(4, 5, $cb, $dec); - $rep->fontsize += 2; - - $rep->NewLine(2, 3); - $rep->TextCol(0, 2, _('Total')); - } - $rep->AmountCol(2, 3, $total, $dec); - $rep->AmountCol(3, 4, $total1, $dec); - $rep->AmountCol(4, 5, $total2, $dec); - if ($detail) - { - $rep->Line($rep->row - 2); - $rep->NewLine(); + $grandtotal2 += $cb; } + $rep->NewLine(2, 3); + $rep->TextCol(0, 4, _('Total')); + $rep->AmountCol(4, 5, $total, $dec); + $rep->AmountCol(5, 6, $total1, $dec); + $rep->AmountCol(6, 7, $total2, $dec); + $rep->Line($rep->row - 2); + $rep->NewLine(); $rep->NewLine(2, 1); - $rep->TextCol(0, 2, _('Grand Total')); - $rep->AmountCol(2, 3, $grandtotal, $dec); - $rep->AmountCol(3, 4, $grandtotal1, $dec); - $rep->AmountCol(4, 5, $grandtotal2, $dec); + $rep->TextCol(0, 4, _('Grand Total')); + $rep->AmountCol(4, 5, $grandtotal, $dec); + $rep->AmountCol(5, 6, $grandtotal1, $dec); + $rep->AmountCol(6, 7, $grandtotal2, $dec); $rep->Line($rep->row - 4); $rep->NewLine(); diff --git a/reporting/rep709.php b/reporting/rep709.php index 861527e2..57183a88 100644 --- a/reporting/rep709.php +++ b/reporting/rep709.php @@ -116,7 +116,7 @@ function print_tax_report() while ($trans=db_fetch($transactions)) { - if (in_array($trans['trans_type'], array(11,20,1))) { + if (in_array($trans['trans_type'], array(11,20))) { $trans['net_amount'] *= -1; $trans['amount'] *= -1; } @@ -141,7 +141,7 @@ function print_tax_report() $rep->Header(); } } - if (in_array($trans['trans_type'], array(0,2,10,11))) { + if (in_array($trans['trans_type'], array(2,10,11))) { $taxes[$trans['tax_type_id']]['taxout'] += $trans['amount']; $taxes[$trans['tax_type_id']]['out'] += $trans['net_amount']; } else { diff --git a/reporting/reports_main.php b/reporting/reports_main.php index df7019f5..15f47d54 100644 --- a/reporting/reports_main.php +++ b/reporting/reports_main.php @@ -159,7 +159,7 @@ $reports->addReport(_('Inventory'),304,_('Inventory &Sales Report'), new ReportParam(_('End Date'),'DATEENDM'), new ReportParam(_('Inventory Category'),'CATEGORIES'), new ReportParam(_('Location'),'LOCATIONS'), - new ReportParam(_('Detailed Report'),'YES_NO'), + new ReportParam(_('Customer'),'CUSTOMERS_NO_FILTER'), new ReportParam(_('Comments'),'TEXTBOX'), new ReportParam(_('Destination'),'DESTINATION'))); $reports->addReport(_('Inventory'),305,_('&GRN Valuation Report'), diff --git a/sales/create_recurrent_invoices.php b/sales/create_recurrent_invoices.php index 517bd34e..603eef15 100644 --- a/sales/create_recurrent_invoices.php +++ b/sales/create_recurrent_invoices.php @@ -42,7 +42,7 @@ function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no $doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date); $doc->reference = references::get_next($doc->trans_type); - $doc->Comments=''; + //$doc->Comments=''; foreach ($doc->line_items as $line_no=>$item) { $line = &$doc->line_items[$line_no]; diff --git a/sales/includes/db/cust_trans_db.inc b/sales/includes/db/cust_trans_db.inc index fb98b62f..2e681f7f 100644 --- a/sales/includes/db/cust_trans_db.inc +++ b/sales/includes/db/cust_trans_db.inc @@ -101,6 +101,9 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo, $SQLDueDate = "0000-00-00"; else $SQLDueDate = date2sql($due_date); + + if ($trans_type == systypes::bank_payment()) + $Total = -$Total; if ($new) { $trans_no = get_next_trans_no($trans_type); diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 4df319c7..b1a52c7e 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -457,7 +457,7 @@ function create_cart($type, $trans_no) } else $doc->due_date = $doc->document_date; $doc->reference = references::get_next($doc->trans_type); - $doc->Comments=''; + //$doc->Comments=''; foreach($doc->line_items as $line_no => $line) { $doc->line_items[$line_no]->qty_done = 0; } diff --git a/sales/view/view_receipt.php b/sales/view/view_receipt.php index 10dfd0c8..458e9071 100644 --- a/sales/view/view_receipt.php +++ b/sales/view/view_receipt.php @@ -41,7 +41,7 @@ label_cells(_("Date of Deposit"), sql2date($receipt['tran_date']), "class='table end_row(); start_row(); label_cells(_("Payment Currency"), $receipt['curr_code'], "class='tableheader2'"); -label_cells(_("Amount"), price_format($receipt['ov_amount']), "class='tableheader2'"); +label_cells(_("Amount"), price_format($receipt['Total'] - $receipt['ov_discount']), "class='tableheader2'"); label_cells(_("Discount"), price_format($receipt['ov_discount']), "class='tableheader2'"); end_row(); start_row(); -- 2.30.2