Merged changes from main trunk up to version_2_1_4
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 31 Jul 2009 17:07:51 +0000 (17:07 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 31 Jul 2009 17:07:51 +0000 (17:07 +0000)
27 files changed:
CHANGELOG.txt
admin/attachments.php
config.php
gl/includes/db/gl_db_banking.inc
gl/includes/db/gl_db_trans.inc
gl/manage/bank_accounts.php
includes/db/manufacturing_db.inc
inventory/purchasing_data.php
purchasing/includes/db/invoice_db.inc
purchasing/includes/purchasing_db.inc
purchasing/manage/suppliers.php
purchasing/view/view_grn.php
purchasing/view/view_supp_payment.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
reporting/reports_main.php
sales/create_recurrent_invoices.php
sales/includes/db/cust_trans_db.inc
sales/sales_order_entry.php
sales/view/view_receipt.php

index 88a8e032fc4a153fd88c3efd0f342fd5dce4b4de..4f8e73cfc906233a3327547bdd556a00b4733c04 100644 (file)
@@ -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
index 773ac80bd34a8450c9aacb0cb2ac64156990116c..8a7dba1cabc8330e9bea5683f7033cbbedd17bb0 100644 (file)
@@ -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();
+               }
        }       
 }
 
index a25d938dbeaeab857470be5c510f080945c4d68a..d6eeddf280e5daa2a902bb3e4f7ff2181178074b 100644 (file)
@@ -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"));
index a47dd73a0ea4f0af3b1633225b3d55516de601ee..e73e1e3ac877aab3f5fa7020f5c95cdba0f50893 100644 (file)
@@ -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_);
        }
 
index 5b559d33987a094334242f3620f30f066c3c45a3..111d4e331a8a579f899cc6dac0e54d0fc19f5dca 100644 (file)
@@ -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_);
index 26fe90d5437ba2da3bea056095c0d654c009732a..20f492b73730aa18480eae05e789aca566004921 100644 (file)
@@ -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']);
index c2f34d9be21aac04c17bd4fcde878753313fe158..1153010d725e78cb92f1b7592c999c6c6f7ba435 100644 (file)
@@ -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'";
index 69d4b91eedcfd4f8f92370705fca736ab8028f61..503689018ed0015251767bdcefee702c638b51d1 100644 (file)
@@ -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");
index 41918591af43e3eab57200e003b0860ef97a46ef..56961e85ee6f366b78875b495bfb473b00bfcc9f 100644 (file)
@@ -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?
                                {
index da038358b1faf5fb95d3cf13e42f1745a6112f88..850d22910f8821a4c87c851f96cbfb7fb55c7aa1 100644 (file)
@@ -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;
index 45c4d1198d49039c1012d018fc765c828a8a7f12..809ebb3cab29ecedf8d35e120f12f54b0e410501 100644 (file)
@@ -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']). ", "
index 299cf5b6fdaaef706dce3ebe025c9319a8e3f510..9a8cbc7fb6b5233c822103ecf62083398a8fcb4b 100644 (file)
@@ -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");
 
index 3b6d75333842a119c9551d7e23525ec4e0c7950b..793f6d417c4c83219a5135991115bd474bbd46ce 100644 (file)
@@ -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);
index f29822a701d3ee663e2669ad1f1194311ae7d4d5..dfd8f62991a1d235cfd89b9613af6d36287d19f1 100644 (file)
@@ -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");
index 16460053bebe45fb9b014c1024c163072de0b89a..92f27507146a60b36ca82ba2c53d600d5f591f3a 100644 (file)
@@ -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";
index a857da9b957af4d5ff59538d9c01e5fa6ced39c1..fd48fba92ff16b869678724f60d01407b3b68e8c 100644 (file)
                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;
index b0277f1eda17de64b9bdd71c384b8ce9c0e60598..3d072e660a2dfd7c2cc53340913ca810d1a6e94f 100644 (file)
@@ -9,6 +9,7 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+$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 = "<br>From: " . $from;
-                               $msg2 .= "<br>To: " . $to;
-                               $msg2 .= "<br>Subject: " . $subject;
-                               $msg2 .= "<br>Msg: " . nl2br($msg);
-                               $msg2 .= nl2br($sender) . "<br>";
-                               $msg2 .= "<br>Filepath: " . $fname . "<br>Filename: " . $this->filename . "<br>";
-                       }
                                if (!$ret)
                                        display_error(_("Sending document by email failed"));
                                else
                                        display_notification($this->title . " " . $myrow['reference'] . " " 
                                                . _("has been sent by email."));
+                               unlink($fname);         
                        }
                        else
                        {
index 9476d543e715d3787d175dd3d0ef4ec669fb5051..d8f37c77a74e3ad6bc5553625517bfe183461e2e 100644 (file)
@@ -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];
index 7c57da3f3f643afd30ff6d7ba4dda7ee85c3d351..00b06d2ef1f2c513bcf288a527f8e419f9fe6162 100644 (file)
@@ -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);
                }
        }
index 45ce3ef988440856c762033aa6ed96cc31b3ce77..756e83c64ab696fdd9d9bcc9c610c3bb75bc6313 100644 (file)
@@ -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];
index 8929b1e6f3410a95f89c5500ba30ffa88dd499ec..bb4006f1a28e9da72842447c14e64020fbdecdb6 100644 (file)
@@ -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();
index 861527e2f97dc1e09503c2c6227985fd419151ca..57183a884a6ff64fe97a0d78d13d1f9da2bcde5c 100644 (file)
@@ -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 {
index df7019f57d664657ee6b25395e1abbfe33739297..15f47d543a41073e4c679b1b5927ed718e6c1fb7 100644 (file)
@@ -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'),
index 517bd34e33a943b8b4ba8b36af61130cbd046543..603eef15eef5c4713ac67f0ada6abe8d850b883f 100644 (file)
@@ -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];
index fb98b62fe284ce0e5bf4e580b0c39efe19774035..2e681f7f7e11e464b9fb286555fccabc68436b39 100644 (file)
@@ -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);
index 4df319c7641413d2a10dd6657f4b8e33d218985b..b1a52c7ec1ee9329a601ee7467d4ac14d56ffc7f 100644 (file)
@@ -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;
                }
index 10dfd0c848b197ac9a97376cb54b2cd6a997e03e..458e9071d9f460d93653c944c888e4dadda73cfd 100644 (file)
@@ -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();