Merged changes in main trunk up to 2.0.6 (see CHANGELOG)
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Dec 2008 16:21:30 +0000 (16:21 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 8 Dec 2008 16:21:30 +0000 (16:21 +0000)
31 files changed:
admin/create_coy.php
admin/db/maintenance_db.inc
gl/includes/db/gl_db_banking.inc
gl/includes/db/gl_db_trans.inc
includes/banking.inc
includes/current_user.inc
manufacturing/view/wo_production_view.php
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/supp_payment_db.inc
reporting/includes/pdf_report.inc
reporting/rep107.php
reporting/rep109.php
reporting/rep110.php
reporting/rep209.php
reporting/rep302.php
reporting/rep303.php
sales/customer_delivery.php
sales/includes/cart_class.inc
sales/includes/db/payment_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/sales_db.inc
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc
sales/view/view_credit.php
sales/view/view_dispatch.php
sales/view/view_invoice.php
sales/view/view_sales_order.php
taxes/tax_calc.inc
update.html
update_db.php

index dc420a16a3d5eaee2ad3e2bd5778f802818e9c26..9811d9946b02f9bd6ab4d3a1ea1eefc50bf4aefe 100644 (file)
@@ -146,19 +146,10 @@ function handle_submit()
        {
                return false;
        }
-       $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
 
        if ($new)
        {
-           $cdir = $comp_path.'/'.$id;
-           @mkdir($cdir);
-           save_to_file($cdir.'/'.'index.php', 0, $index);
-
-           foreach($comp_subdirs as $dir)
-           {
-                       @mkdir($cdir.'/'.$dir);
-                       save_to_file($cdir.'/'.$dir.'/'.'index.php', 0, $index);
-           }
+               create_comp_dirs("$comp_path/$id", $comp_subdirs);
        }
        return true;
 }
index ff7db9ca9c7ec5e5b56033551626ebc671dc8269..1d9a027380273950d44cb58f32aa6ba175f6c2fe 100644 (file)
@@ -642,5 +642,21 @@ function save_to_file($backupfile, $zip, $fileData)
     }
 }
 
-
+function create_comp_dirs($comp_path, $comp_subdirs)
+{
+               $index = "<?php\nheader(\"Location: ../index.php\");\n?>";
+           $cdir = $comp_path;
+           @mkdir($cdir);
+               $f = @fopen("$cdir/index.php", "wb");
+               @fwrite($f, $index);
+               @fclose($f);
+
+           foreach($comp_subdirs as $dir)
+           {
+                       @mkdir($cdir.'/'.$dir);
+                       $f = @fopen("$cdir/$dir/index.php", "wb");
+                       @fwrite($f, $index);
+                       @fclose($f);
+           }
+}
 ?>
\ No newline at end of file
index 518e73c1f9c3fa9b16f49273c48fe71866053d4c..ca3d5867442caf51d1443bf37e4d1425878e73a1 100644 (file)
@@ -20,8 +20,9 @@ function add_bank_transfer($from_account, $to_account, $date_,
        $from_gl_account = get_bank_gl_account($from_account);
        $to_gl_account = get_bank_gl_account($to_account);
 
+       $total = 0;
        // do the source account postings
-    add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
+    $total += add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
                -$amount, $currency);
 
     add_bank_trans($trans_type, $trans_no, $from_account, $ref,
@@ -30,9 +31,11 @@ function add_bank_transfer($from_account, $to_account, $date_,
                "Cannot insert a source bank transaction");
 
        // do the destination account postings
-       add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
+       $total += add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
                $amount, $currency);
-
+       /*Post a balance post if $total != 0 */
+       add_gl_balance($trans_type, $trans_no, $date_, -$total);        
+       
        add_bank_trans($trans_type, $trans_no, $to_account, $ref,
                $date_, $amount, payment_person_types::misc(), "",
                $currency, "Cannot insert a destination bank transaction");
@@ -108,9 +111,11 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
        -$total_amount, $currency, $person_type_id, $person_id);
 
     add_bank_trans($trans_type, $trans_no, $from_account, $ref,
-       $date_, -$total_amount, $person_type_id, $person_id,
-       $currency, "Cannot insert a source bank transaction");
-
+       $date_, -$total_amount,
+       $person_type_id, $person_id,
+       $currency,
+       "Cannot insert a source bank transaction");
+       $total = 0;
        foreach ($items->gl_items as $gl_item)
        {
                $is_bank_to = is_bank_account($gl_item->code_id);
@@ -122,7 +127,7 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
                }
 
        // do the destination account postings
-       add_gl_trans($trans_type, $trans_no, $date_, $gl_item->code_id,
+       $total += 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);
 
@@ -134,6 +139,10 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_,
        }
        }
 
+       // do the source account postings
+    add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, "",
+       -$total, null, $person_type_id, $person_id);
+
        add_comments($trans_type, $trans_no, $date_, $memo_);
 
        references::save_last($ref, $trans_type);
index 30750bbbd4fb4042b1cf0276b402fef7e19a2109..af74ee3c86900e993d2dcfae9c7df86377883fe0 100644 (file)
@@ -18,10 +18,10 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
                if ($rate == 0)
                        $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
                else
-                       $amount_in_home_currency = round($amount * $rate,  user_price_dec());
+                       $amount_in_home_currency = round2($amount * $rate,  user_price_dec());
        }               
        else
-               $amount_in_home_currency = $amount;
+               $amount_in_home_currency = round2($amount, user_price_dec());
        if ($dimension == null || $dimension < 0)
                $dimension = 0;
        if ($dimension2 == null || $dimension2 < 0)
@@ -52,7 +52,8 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
        if ($err_msg == "")
                $err_msg = "The GL transaction could not be inserted";
 
-       return db_query($sql, $err_msg);
+       db_query($sql, $err_msg);
+       return $amount_in_home_currency;
 }
 
 //--------------------------------------------------------------------------------
@@ -68,9 +69,20 @@ function add_gl_trans_std_cost($type, $trans_id, $date_, $account, $dimension, $
                return add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
                        $amount, null, $person_type_id, $person_id, $err_msg);
        else
-               return null;
+               return 0;
 }
 
+// Function for even out rounding problems
+function add_gl_balance($type, $trans_id, $date_, $amount, $person_type_id=null, $person_id=null)
+{
+       $amount = round2($amount, user_price_dec());
+       if ($amount != 0)
+               return add_gl_trans($type, $trans_id, $date_, get_company_pref('exchange_diff_act'), 0, 0, "",
+                       $amount, null, $person_type_id, $person_id, "The balanced GL transaction could not be inserted");
+       else
+               return 0;
+}      
+
 //--------------------------------------------------------------------------------
 
 function get_gl_transactions($from_date, $to_date, $trans_no=0,
index 39b904c8b43b3c63515e11b886c478532f57e30c..49fb68b1e62680396cd33a81df55f70ce09b115f 100644 (file)
@@ -116,7 +116,7 @@ function get_exchange_rate_to_home_currency($currency_code, $date_)
 function to_home_currency($amount, $currency_code, $date_)
 {
        $ex_rate = get_exchange_rate_to_home_currency($currency_code, $date_);
-       return round($amount / $ex_rate,  user_price_dec());
+       return round2($amount / $ex_rate,  user_price_dec());
 }
 
 //----------------------------------------------------------------------------------
@@ -174,8 +174,8 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am
        }
        if (is_company_currency($curr))
                return;
-       $inv_amt = round($amount * $trans['rate'], user_price_dec()); 
-       $pay_amt = round($amount * $pyt_trans['rate'], user_price_dec());
+       $inv_amt = round2($amount * $trans['rate'], user_price_dec()); 
+       $pay_amt = round2($amount * $pyt_trans['rate'], user_price_dec());
        if ($inv_amt != $pay_amt)
        {
                $diff = $inv_amt - $pay_amt;
index 1a9396d3f9c7a715ac22b1e2c74269aeeaa8c617..fbd54bf1dc05e59aab376f5850219e7c106b0b9d 100644 (file)
@@ -123,12 +123,20 @@ class current_user
 
 //--------------------------------------------------------------------------
 
+function round2($number, $decimals=0)
+{
+       $delta = ($number < 0 ? -.000001 : .000001);
+       return round($number+$delta, $decimals);
+}
+
 function number_format2($number, $decimals=0)
 {
        global $thoseps, $decseps;
        $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
        $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
-       return number_format($number, $decimals, $dsep, $tsep);
+       //return number_format($number, $decimals, $dsep,       $tsep);
+       $delta = ($number < 0 ? -.000001 : .000001);
+       return number_format($number+$delta, $decimals, $dsep,  $tsep);
 }
 //
 //     Current ui mode.
index 64e287e73ba174fc1e7be82e14ec154524e4984e..1558f67cbcddedad032ee1830058161febda810d 100644 (file)
@@ -5,7 +5,10 @@ $path_to_root="../..";
 
 include_once($path_to_root . "/includes/session.inc");
 
-page(_("View Work Order Production"), true);
+$js = "";
+if ($use_popup_windows)
+       $js .= get_js_open_window(900, 500);
+page(_("View Work Order Production"), true, false, "", $js);
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/manufacturing.inc");
index ab76757cc925cdd0654023f742110e6991f452df..96fa45ce6f132851bea01518a1d921c37e652fe6 100644 (file)
@@ -91,12 +91,20 @@ function get_deliveries_between($stock_id, $from, $to)
 {
        $from = date2sql($from);
        $to = date2sql($to);
-       $sql = "SELECT SUM(-qty), AVG(standard_cost) FROM ".TB_PREF."stock_moves
+       $sql = "SELECT SUM(-qty), SUM(-qty*standard_cost) FROM ".TB_PREF."stock_moves
                WHERE type=13 AND stock_id='$stock_id' AND
                        tran_date>='$from' AND tran_date<='$to' GROUP BY stock_id";
        $result = db_query($sql, "The deliveries could not be updated");
        return db_fetch_row($result);
 }
+
+function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amount2)
+{
+       $currency = get_supplier_currency($supplier);
+       $amount1 = to_home_currency($amount1, $currency, $old_date);
+       $amount2 = to_home_currency($amount2, $currency, $date);
+       return $amount2 - $amount1;
+}
 //----------------------------------------------------------------------------------------
 
 function add_supp_invoice($supp_trans) // do not receive as ref because we change locally
@@ -133,9 +141,10 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                $supp_trans->reference, $supp_trans->supp_reference,
                $invoice_items_total, $tax_total, $supp_trans->ov_discount);
 
+       $total = 0;
     /* Now the control account */
     $supplier_accounts = get_supplier_accounts($supp_trans->supplier_id);
-    add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0,
+    $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0,
                -($invoice_items_total +  $tax_total + $supp_trans->ov_discount),
                $supp_trans->supplier_id,
                "The general ledger transaction for the control total could not be added");
@@ -151,7 +160,6 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
     between the std cost and the currency cost charged as converted at the ex rate of of the invoice is written off
     to the purchase price variance account applicable to the item being invoiced.
     */
-
     foreach ($supp_trans->gl_codes as $entered_gl_code)
     {
 
@@ -162,7 +170,7 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                        $entered_gl_code->amount = -$entered_gl_code->amount;
 
                $memo_ = $entered_gl_code->memo_;
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
                        $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2, $entered_gl_code->amount, $supp_trans->supplier_id);
 
                add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code,
@@ -181,7 +189,7 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                $line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
                $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
 
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
                        $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
                        $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
        // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
@@ -197,41 +205,39 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                         
                        $old_price = $old[2];
 
-               
-
                        /*
                        If statement is removed. Should always check for deliveries nomatter if there has been a price change. 
                        */
                        //if ($old_price != $entered_grn->chg_price) // price-change, so update
                        //{
-                               $diff = $entered_grn->chg_price - $old_price;
-                               $old_date = sql2date($old[1]);
-                               // only update the diff (last parameter, adj_only is set to true).
-                               $mat_cost = update_average_material_cost($supp_trans->supplier_id, $entered_grn->item_code,
-                                       $diff, $entered_grn->this_quantity_inv, $old_date, true);
-                               // added 2008-12-08 Joe Hunt. Update the purchase data table
-                               add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price); 
-                                       
-                               // function just above this
-                               $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, $date_);
-                               if ($deliveries[0] != 0) // have deliveries been done during the period?
+                       //$diff = $entered_grn->chg_price - $old_price;
+                       $old_date = sql2date($old[1]);
+                       $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, 
+                               $entered_grn->chg_price);
+                       // always return due to change in currency.
+                       $mat_cost = update_average_material_cost(null, $entered_grn->item_code,
+                               $diff, $entered_grn->this_quantity_inv, $old_date, true);
+                       // added 2008-12-08 Joe Hunt. Update the purchase data table
+                       add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price); 
+                       $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, Today()); // extend the period, if invoice is before any deliveries.
+                       if ($deliveries[0] != 0) // have deliveries been done during the period?
+                       {
+                               $deliveries[1] /= $deliveries[0];
+                               $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
+                               if ($amt != 0.0)
                                {
-
-                                       $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
-                                       if ($amt != 0.0)
-                                       {
-                                               add_gl_trans($trans_type, $invoice_id, $date_,  $stock_gl_code["cogs_account"],
-                                                       $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
-                                                       $amt, null, null, null,
-                                                       "The general ledger transaction could not be added for the price variance of the inventory item");
-                                               add_gl_trans($trans_type, $invoice_id, $date_,  $stock_gl_code["inventory_account"],
-                                                       0, 0, _("Cost diff."), -$amt, null, null, null,
-                                                       "The general ledger transaction could not be added for the price variance of the inventory item");
-                                       }               
-                                       update_stock_move_pid(13, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
-                               }
-                               update_stock_move_pid(25, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
-                       //}
+                                       add_gl_trans($trans_type, $invoice_id, $date_,  $stock_gl_code["cogs_account"],
+                                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+                                               $amt, null, null, null,
+                                               "The general ledger transaction could not be added for the price variance of the inventory item");
+                                       add_gl_trans($trans_type, $invoice_id, $date_,  $stock_gl_code["inventory_account"],
+                                               0, 0, _("Cost diff."), -$amt, null, null, null,
+                                               "The general ledger transaction could not be added for the price variance of the inventory item");
+                               }               
+                               update_stock_move_pid(13, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
+                       }
+                       update_stock_move_pid(25, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
+               //}
                }
        // ----------------------------------------------------------------------
 
@@ -251,12 +257,16 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                        add_supp_invoice_tax_item($trans_type, $invoice_id, $taxitem['tax_type_id'],
                                $taxitem['rate'], 0, $taxitem['Value']);
 
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_,
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_,
                        $taxitem['purchasing_gl_code'], 0, 0, $taxitem['Value'],
                        $supp_trans->supplier_id,
                        "A general ledger transaction for the tax amount could not be added");
        }
     }
+       
+       /*Post a balance post if $total != 0 */
+       add_gl_balance($trans_type, $invoice_id, $date_, -$total, payment_person_types::supplier(), $supp_trans->supplier_id);  
+
        add_comments($trans_type, $invoice_id, $date_, $supp_trans->Comments);
 
        references::save_last($supp_trans->reference, $trans_type);
@@ -371,20 +381,22 @@ function void_supp_invoice($type, $type_no)
                                $old = update_supp_received_items_for_invoice($details_row["grn_item_id"],
                                        $details_row["po_detail_item_id"], -$details_row["quantity"], $details_row["FullUnitPrice"]); 
                                
-                               $diff = $details_row["FullUnitPrice"] - $old[2];
+                               //$diff = $details_row["FullUnitPrice"] - $old[2];
                                $old_date = sql2date($old[1]);
                                
                                $batch = get_grn_batch_from_item($details_row["grn_item_id"]);  
                                $grn = get_grn_batch($batch);
                                
+                               $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($grn["supplier_id"], $details_row["stock_id"],
-                                               $diff, -$details_row["quantity"], $date_, true);
+                               $mat_cost = update_average_material_cost(null, $details_row["stock_id"],
+                                       $diff, -$details_row["quantity"], $date_, true);
 
                                $deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_);
                                if ($deliveries[0] != 0) // have deliveries been done during the period?
                                {
-
+                                       $deliveries[1] /= $deliveries[0];
                                        $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
                                        if ($amt != 0.0)
                                        {
index d15deb80930d789fa22a8608c47f4e37554a8cda..5d9b382b1fc95469c9cd50add5c38feba7f2b684 100644 (file)
@@ -16,8 +16,8 @@ function add_supp_payment($supplier_id, $date_, $bank_account,
        }
        else
        {
-               $supp_amount = $amount / $rate;
-               $supp_discount = $discount / $rate;
+               $supp_amount = round($amount / $rate, user_price_dec());
+               $supp_discount = round($discount / $rate, user_price_dec());
        }
        
 
@@ -30,24 +30,27 @@ function add_supp_payment($supplier_id, $date_, $bank_account,
 
        // Now debit creditors account with payment + discount
 
+       $total = 0;
     $supplier_accounts = get_supplier_accounts($supplier_id);
-
-       add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
+       $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
                $supp_amount + $supp_discount, $supplier_id, "", $rate);
 
        // 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,
+               $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
                        -$supp_discount, $supplier_id, "", $rate);
        }
 
        if ($supp_amount != 0)
        {
-               add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
+               $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
                        -$supp_amount, $supplier_id, "", $rate);
        }
 
+       /*Post a balance post if $total != 0 */
+       add_gl_balance($trans_type, $payment_id, $date_, -$total, payment_person_types::supplier(), $supplier_id);      
+
    /*now enter the bank_trans entry */
        add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
                $date_, -($amount), payment_person_types::supplier(),
index 007ee29aff9fec4fa5c39aed84f9214a0fd62fd5..07d83546638daf144c956502eaedad4ad0ad6f72 100644 (file)
@@ -361,7 +361,7 @@ class FrontReport extends Cpdf
        function NewLine($l=1, $np=0)
        {
                $this->row -= ($l * $this->lineHeight);
-               if ($np > 0 &&  $this->row < $this->bottomMargin + ($np * $this->lineHeight))
+               if ($this->row < $this->bottomMargin + ($np * $this->lineHeight))
                        $this->Header();
        }
 
index 1288e5173e6a0fa90192d049ee7b7c606978bd90..05b28c3fdaf68f85636d1127c7edbbbcd311e328 100644 (file)
@@ -104,7 +104,7 @@ function print_invoices()
                        $SubTotal = 0;
                        while ($myrow2=db_fetch($result))
                        {
-                               $Net = round($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+                               $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                                   user_price_dec());
                                $SubTotal += $Net;
                        $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
index 1bbf662a94bebc10df8ab9395e6f4d88069d43d2..2a89aeeb55066f79b615dd8757b86d2fae8de438 100644 (file)
@@ -92,7 +92,7 @@ function print_sales_orders()
                $SubTotal = 0;
                while ($myrow2=db_fetch($result))
                {
-                       $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+                       $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                           user_price_dec());
                        $SubTotal += $Net;
                        $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
index 659a4a490e3774b7f09c1f0bfc38bf7c2ea7b2d5..3ec500381a8cbcacda99bafca85888d4ee3f0810 100644 (file)
@@ -83,7 +83,7 @@ function print_deliveries()
                        $SubTotal = 0;
                        while ($myrow2=db_fetch($result))
                        {
-                               $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+                               $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                                   user_price_dec());
                                $SubTotal += $Net;
                        $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
index b59ca1ad8689f1f6a479a05e922c6397176af883..41d0ca3d99629ec5dc3862139459a059752c2a41 100644 (file)
@@ -116,7 +116,7 @@ function print_po()
                                        $myrow2['quantiry_ordered'] = round($myrow2['quantiry_ordered'] / $data['conversion_factor'], user_qty_dec());
                                }
                        }       
-                       $Net = round(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
+                       $Net = round2(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
                          user_price_dec());
                        $SubTotal += $Net;
                        $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
index 47bf8448c8c2212dd4cb1d255ed30cb14fef7539..68758cd4dbeb5c492eb6dfed82e47f2bba3e46d0 100644 (file)
@@ -26,23 +26,22 @@ function getTransactions($category, $location)
                        ".TB_PREF."stock_category.description AS cat_description,
                        ".TB_PREF."stock_master.stock_id,
                        ".TB_PREF."stock_master.description,
-                       ".TB_PREF."stock_moves.loc_code,
-                       SUM(".TB_PREF."stock_moves.qty) AS qty_on_hand
-               FROM ".TB_PREF."stock_master,
-                       ".TB_PREF."stock_category,
-                       ".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
+                       IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
+                       SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS qty_on_hand
+               FROM (".TB_PREF."stock_master,
+                       ".TB_PREF."stock_category)
+               LEFT JOIN ".TB_PREF."stock_moves ON
+                       (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
+               WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
                AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
        if ($category != 0)
                $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
        if ($location != 'all')
                $sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
        $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
-               ".TB_PREF."stock_master.description,
                ".TB_PREF."stock_category.description,
-               ".TB_PREF."stock_moves.stock_id,
-               ".TB_PREF."stock_master.stock_id
+               ".TB_PREF."stock_master.stock_id,
+               ".TB_PREF."stock_master.description
                ORDER BY ".TB_PREF."stock_master.category_id,
                ".TB_PREF."stock_master.stock_id";
 
@@ -55,9 +54,10 @@ function getCustQty($stockid, $location)
        $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
-                                       ".TB_PREF."sales_orders.from_stk_loc ='$location' AND
-                                       ".TB_PREF."sales_order_details.stk_code = '$stockid'";
+                               WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND ";
+       if ($location != "")
+               $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+       $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'";
 
     $TransResult = db_query($sql,"No transactions were returned");
        $DemandRow = db_fetch($TransResult);
@@ -73,9 +73,10 @@ function getCustAsmQty($stockid, $location)
                                                ".TB_PREF."bom,
                                                ".TB_PREF."stock_master
                                   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_sent > 0 AND
+                                  ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
+       if ($location != "")
+               $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+       $sql .= 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'";
@@ -98,8 +99,9 @@ function getSuppQty($stockid, $location)
                                FROM ".TB_PREF."purch_order_details,
                                        ".TB_PREF."purch_orders
                                WHERE ".TB_PREF."purch_order_details.order_no = ".TB_PREF."purch_orders.order_no
-                               AND ".TB_PREF."purch_order_details.item_code = '$stockid'
-                               AND ".TB_PREF."purch_orders.into_stock_location= '$location'";
+                               AND ".TB_PREF."purch_order_details.item_code = '$stockid'";
+       if ($location != "")                    
+               $sql .= " AND ".TB_PREF."purch_orders.into_stock_location= '$location'";
 
     $TransResult = db_query($sql,"No transactions were returned");
        $DemandRow = db_fetch($TransResult);
@@ -196,10 +198,13 @@ function print_inventory_planning()
                        $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']);
+               if ($location == 'all')
+                       $loc_code = "";
+               else
+                       $loc_code = $trans['loc_code'];
+               $custqty = getCustQty($trans['stock_id'], $loc_code);
+               $custqty += getCustAsmQty($trans['stock_id'], $loc_code);
+               $suppqty = getSuppQty($trans['stock_id'], $loc_code);
                $period = getPeriods($trans['stock_id'], $trans['loc_code']);
                $rep->NewLine();
                $dec = get_qty_dec($trans['stock_id']);
index c984b3cb2fe679b4da45b345a98e1204f6e7f325..bc04f7694e6fba1afdf97e2f90fe2af2b93897a1 100644 (file)
@@ -26,13 +26,13 @@ function getTransactions($category, $location)
                        ".TB_PREF."stock_category.description AS cat_description,
                        ".TB_PREF."stock_master.stock_id,
                        ".TB_PREF."stock_master.description,
-                       ".TB_PREF."stock_moves.loc_code,
-                       SUM(".TB_PREF."stock_moves.qty) AS QtyOnHand
-               FROM ".TB_PREF."stock_master,
-                       ".TB_PREF."stock_category,
-                       ".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
+                       IF(".TB_PREF."stock_moves.stock_id IS NULL, '', ".TB_PREF."stock_moves.loc_code) AS loc_code,
+                       SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand
+               FROM (".TB_PREF."stock_master,
+                       ".TB_PREF."stock_category)
+               LEFT JOIN ".TB_PREF."stock_moves ON
+                       (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id OR ".TB_PREF."stock_master.stock_id IS NULL)
+               WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
                AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M')";
        if ($category != 0)
                $sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
@@ -53,9 +53,10 @@ function getDemandQty($stockid, $location)
        $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
-                                       ".TB_PREF."sales_orders.from_stk_loc ='$location' AND
-                                       ".TB_PREF."sales_order_details.stk_code = '$stockid'";
+                               WHERE ".TB_PREF."sales_order_details.order_no=".TB_PREF."sales_orders.order_no AND ";
+       if ($location != "")
+               $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+       $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'";
 
     $TransResult = db_query($sql,"No transactions were returned");
        $DemandRow = db_fetch($TransResult);
@@ -71,9 +72,10 @@ function getDemandAsmQty($stockid, $location)
                                                ".TB_PREF."bom,
                                                ".TB_PREF."stock_master
                                   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_sent > 0 AND
+                                  ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
+       if ($location != "")
+               $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
+       $sql .= 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'";
@@ -163,8 +165,12 @@ function print_stock_check()
                        $catt = $trans['cat_description'];
                        $rep->NewLine();
                }
-               $demandqty = getDemandQty($trans['stock_id'], $trans['loc_code']);
-               $demandqty += getDemandAsmQty($trans['stock_id'], $trans['loc_code']);
+               if ($location == 'all')
+                       $loc_code = "";
+               else
+                       $loc_code = $trans['loc_code'];
+               $demandqty = getDemandQty($trans['stock_id'], $loc_code);
+               $demandqty += getDemandAsmQty($trans['stock_id'], $loc_code);
                $rep->NewLine();
                $dec = get_qty_dec($trans['stock_id']);
                $rep->TextCol(0, 1, $trans['stock_id']);
index 8e5da8e8b8efa69c67045591a3fe1cb6a6fe2b02..3c275dbbf9aeeab2ce0148491699d1633209fea0 100644 (file)
@@ -366,13 +366,13 @@ $th = array(_("Item Code"), _("Item Description"), _("Ordered"), _("Units"), _("
 table_header($th);
 $k = 0;
 $has_marked = false;
-$show_qoh = true;
 
 foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) {
        if ($ln_itm->quantity==$ln_itm->qty_done) {
                continue; //this line is fully delivered
        }
        // if it's a non-stock item (eg. service) don't show qoh
+       $show_qoh = true;
        if (sys_prefs::allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) ||
                $ln_itm->qty_dispatched == 0) {
                $show_qoh = false;
index 628ab43a3ea5e3fd34ea59ed2f03db2b65e769db..96faeb1ca0e765287f20aa95ebae52b0db616d43 100644 (file)
@@ -306,7 +306,7 @@ class cart
 
        function remove_from_cart($line_no)
        {
-               unset($this->line_items[$line_no]);
+               array_splice($this->line_items, $line_no, 1);
        }
 
        function clear_items()
index 15ec358461e68cf139c0df01b10c7750a7969b1e..c960dd33b471a8aad029e15f2f382898c5c4e654 100644 (file)
@@ -20,9 +20,9 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
          void_gl_trans(12, $trans_no, true);
          void_cust_allocations(12, $trans_no, $date_);
        }
-
+       $total = 0;
        /* Bank account entry first */
-       add_gl_trans_customer(12, $payment_no, $date_,
+       $total += add_gl_trans_customer(12, $payment_no, $date_,
                $bank_gl_account, 0, 0, $amount,  $customer_id,
                "Cannot insert a GL transaction for the bank account debit", $rate);
 
@@ -40,18 +40,20 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        if (($discount + $amount) != 0) {
                /* Now Credit Debtors account with receipts + discounts */
-               add_gl_trans_customer(12, $payment_no, $date_,
+               $total += add_gl_trans_customer(12, $payment_no, $date_,
                        $debtors_account, 0, 0, -($discount + $amount), $customer_id,
                        "Cannot insert a GL transaction for the debtors account credit", $rate);
        }
-
        if ($discount != 0)     {
                /* Now Debit discount account with discounts allowed*/
-               add_gl_trans_customer(12, $payment_no, $date_,
+               $total += add_gl_trans_customer(12, $payment_no, $date_,
                        $discount_account, 0, 0, $discount, $customer_id,
                        "Cannot insert a GL transaction for the payment discount debit", $rate);
        }
 
+       /*Post a balance post if $total != 0 */
+       add_gl_balance(12, $payment_no, $date_, -$total, payment_person_types::customer(), $customer_id);       
+
        /*now enter the bank_trans entry */
        add_bank_trans(12, $payment_no, $bank_account, $ref,
                $date_, $amount, payment_person_types::customer(), $customer_id,
index 94dbe8a235b291a0edd7becd0f4ad331772b0b59..16efab69a4883868e252ba221a5548b6c20a308d 100644 (file)
@@ -98,7 +98,7 @@ function write_credit_note($credit_note, $write_off_acc)
                }
        }
 
-
+       $total = 0;
        foreach ($credit_note->line_items as $credit_line) {
 
                if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) {
@@ -120,7 +120,7 @@ function write_credit_note($credit_note, $write_off_acc)
                add_credit_movements_item($credit_note, $credit_line,
                        $credit_type, $line_taxfree_price+$line_tax, $credit_invoice);
 
-               add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
+               $total += add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
                    $credit_date, $credit_type, $write_off_acc, $branch_data);
        } /*end of credit_line loop */
 
@@ -129,14 +129,14 @@ function write_credit_note($credit_note, $write_off_acc)
 
        if (($credit_note_total + $credit_note->freight_cost) != 0) {
 
-               add_gl_trans_customer(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
+               $total += add_gl_trans_customer(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
                        -($credit_note_total + $credit_note->freight_cost + $items_added_tax + $freight_added_tax),
                        $credit_note->customer_id,
                        "The total debtor GL posting for the credit note could not be inserted");
        }
 
        if ($credit_note->freight_cost !=0) {
-               add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
                        $credit_note->get_tax_free_shipping(), $credit_note->customer_id,
                        "The freight GL posting for this credit note could not be inserted");
        }
@@ -147,11 +147,14 @@ function write_credit_note($credit_note, $write_off_acc)
                        add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'],
                                $taxitem['rate'], $credit_note->tax_included, $taxitem['Value']);
 
-                       add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
+                       $total += add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
                                $taxitem['Value'], $credit_note->customer_id,
                                "A tax GL posting for this credit note could not be inserted");
                }
        }
+       /*Post a balance post if $total != 0 */
+       add_gl_balance(11, $credit_no, $credit_date, -$total, payment_person_types::customer(), $credit_note->customer_id);     
+
        add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
 
        if ($trans_no == 0) {
@@ -213,12 +216,13 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
        $dim2 = ($order->dimension2_id != $customer['dimension2_id'] ? $order->dimension2_id : 
                ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_codes["dimension2_id"]));
 
+       $total = 0;
        /* insert gl_trans to credit stock and debit cost of sales at standard cost*/
        $standard_cost = get_standard_cost($order_line->stock_id);
        if ($standard_cost != 0) {
                /*first the cost of sales entry*/
 
-               add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
+               $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
                        $dim, $dim2, "", -($standard_cost * $order_line->qty_dispatched),
                        payment_person_types::customer(), $order->customer_id,
                        "The cost of sales GL posting could not be inserted");
@@ -231,7 +235,7 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
                        $stock_entry_account = $stock_gl_code["inventory_account"];
                }
 
-               add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
+               $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
                        "", ($standard_cost * $order_line->qty_dispatched),
                        payment_person_types::customer(), $order->customer_id,
                        "The stock side (or write off) of the cost of sales GL posting could not be inserted");
@@ -256,19 +260,20 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
                        $sales_account = $branch_data['sales_account'];
                else
                        $sales_account = $stock_gl_codes['sales_account'];
-               add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
+               $total += add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
                        ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
                        "The credit note GL posting could not be inserted");
 
                if ($order_line->discount_percent != 0) {
 
-                       add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
+                       $total += add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
                                $dim, $dim2, -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
                                $order->customer_id,
                                "The credit note discount GL posting could not be inserted");
 
                } /*end of if discount !=0 */
        } /*if line_price!=0 */
+       return $total;
 }
 
 ?>
\ No newline at end of file
index 31f7a1a222ca776b9f1a4d444151b6491ef02b8b..1c9837f9fbd3ca56b6e6ab757e21cee54a3d89cc 100644 (file)
@@ -73,7 +73,7 @@ function write_sales_invoice(&$invoice)
                void_cust_allocations(10, $invoice_no); // ?
                void_customer_trans_tax_details(10, $invoice_no);
        }
-
+       $total = 0;
        foreach ($invoice->line_items as $invoice_line) {
 
                $line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
@@ -109,13 +109,13 @@ function write_sales_invoice(&$invoice)
                                        ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]));
                                $dim2 = ($invoice->dimension2_id != $customer['dimension2_id'] ? $invoice->dimension2_id : 
                                        ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]));
-                               add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
+                               $total += add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
                                        (-$line_taxfree_price * $invoice_line->qty_dispatched),
                                        $invoice->customer_id, "The sales price GL posting could not be inserted");
 
                                if ($invoice_line->discount_percent != 0) {
 
-                                       add_gl_trans_customer(10, $invoice_no, $date_,
+                                       $total += add_gl_trans_customer(10, $invoice_no, $date_,
                                                $branch_data["sales_discount_account"], $dim, $dim2,
                                                ($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent),
                                                $invoice->customer_id, "The sales discount GL posting could not be inserted");
@@ -124,14 +124,14 @@ function write_sales_invoice(&$invoice)
                } /*quantity dispatched is more than 0 */
        } /*end of delivery_line loop */
 
-       /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
        if (($items_total + $charge_shipping) != 0) {
-               add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
+               $total += add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
                        ($items_total + $charge_shipping + $items_added_tax + $freight_added_tax),
                        $invoice->customer_id, "The total debtor GL posting could not be inserted");
        }
+
        if ($charge_shipping != 0) {
-               add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
                        -$invoice->get_tax_free_shipping(), $invoice->customer_id,
                        "The freight GL posting could not be inserted");
        }
@@ -141,12 +141,15 @@ function write_sales_invoice(&$invoice)
                        add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'],
                                $taxitem['rate'], $invoice->tax_included, $taxitem['Value']);
 
-                       add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+                       $total += add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
                                (-$taxitem['Value']), $invoice->customer_id,
                                "A tax GL posting could not be inserted");
                }
        }
 
+       /*Post a balance post if $total != 0 */
+       add_gl_balance(10, $invoice_no, $date_, -$total, payment_person_types::customer(), $invoice->customer_id);      
+
        add_comments(10, $invoice_no, $date_, $invoice->Comments);
 
        if ($trans_no == 0) {
index a537894bb7c8bd0929a8fb8eec08e5f41f75e36d..ab35dc81ab2a957f5b7ec9ecbbd0e9a5a5070c38 100644 (file)
@@ -76,7 +76,9 @@ function get_price ($stock_id, $currency, $sales_type_id, $factor=null, $date=nu
        if ($factor == 0) return false; // auto price calculations off
 
        $base_id = get_base_sales_type();
-        $home_curr = get_company_currency();
+       if ($base_id <= 0) return 0; // auto price calculations off
+       
+    $home_curr = get_company_currency();
 
     // get all prices which we can use to guess the price.
     // alternative is make up to 2 additional sql queries
index f4725d3febdace0525b325f6cde00c173e2ab504..303a7e0fab7a90409ac25c39a9b33f7b6d78a9a8 100644 (file)
@@ -122,7 +122,10 @@ function display_credit_header(&$order)
 
        date_row(_("Date:"), 'OrderDate', '', null, 0, 0, 0, null, true);
        if (isset($_POST['_OrderDate_changed'])) {
-               $change_prices = 1;
+               if (!is_company_currency($order->customer_currency) 
+                       && (get_base_sales_type()>0)) {
+                               $change_prices = 1;
+               }
                $Ajax->activate('currency');
        }
        // 2008-11-12 Joe Hunt added dimensions
index 6e380105d354f71c3fcb26a963b18be83593cb5a..a1122708b8f16c05c1e63f572c600c9253cf83e7 100644 (file)
@@ -368,7 +368,10 @@ function display_order_header(&$order, $editable, $date_text, $display_tax_group
                date_row($date_text, 'OrderDate',
                  _('Date of order receive'), null, 0, 0, 0, null, true);
                if (isset($_POST['_OrderDate_changed'])) {
-                       $change_prices = 1;
+                       if (!is_company_currency($order->customer_currency) 
+                               && (get_base_sales_type()>0)) {
+                                       $change_prices = 1;
+                       }
                        $Ajax->activate('currency');
                        if ($order->trans_type == 10) {
                                $_POST['delivery_date'] = get_invoice_duedate(get_post('customer_id'), get_post('OrderDate'));
index f220fca140512116bcd29f3f7af4c1d8fe935855..05e73eb0f1f7549810301279d357b577ada190b5 100644 (file)
@@ -90,7 +90,7 @@ if (db_num_rows($result) > 0)
 
                alt_table_row_color($k);
 
-               $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+               $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                   user_price_dec());
                $sub_total += $value;
 
index 3d7d2e75253d70b0febbd844408e92b6a797f229..9bd01beb5927e08d8b0f74c465609bb14fe81d55 100644 (file)
@@ -111,7 +111,7 @@ if (db_num_rows($result) > 0)
                if($myrow2['quantity']==0) continue;
                alt_table_row_color($k);
 
-               $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+               $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                   user_price_dec());
                $sub_total += $value;
 
index 17900ba267c3c3fa3acbd02eccb23244d4560362..e430b45508f2b3ac1c9728875d6b76e1bd84cc43 100644 (file)
@@ -113,7 +113,7 @@ if (db_num_rows($result) > 0)
            if($myrow2["quantity"]==0) continue;
                alt_table_row_color($k);
 
-               $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
+               $value = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                   user_price_dec());
                $sub_total += $value;
 
index 333a11301284140d63818efc27cebc402988c9fd..782c951d6db165f13f16971521ea81c25b176172 100644 (file)
@@ -177,7 +177,7 @@ $k = 0;  //row colour counter
 
 foreach ($_SESSION['Items']->line_items as $stock_item) {
 
-       $line_total = round($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent),
+       $line_total = round2($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent),
           user_price_dec());
 
        alt_table_row_color($k);
index 9d1ba576097fba04bc6ccac1e86fdf24a4c4b6e1..acc8f0f0633d468aadd47b528f3ad2262b717bd9 100644 (file)
@@ -175,12 +175,14 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc
                        foreach ($item_taxes as $item_tax) 
                        {
                                $index = $item_tax['tax_type_id'];
-                               if($tax_included==1)
-                                 $ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate'] 
-                                       / ($item_tax['rate'] + 100),  user_price_dec());
+                               if($tax_included==1) // 2008-11-26 Joe Hunt Taxes are stored without roundings
+                                 //$ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate'] 
+                                 //    / ($item_tax['rate'] + 100),  user_price_dec());
+                                 $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / ($item_tax['rate'] + 100));
                                else
-                                 $ret_tax_array[$index]['Value'] += 
-                                       round($prices[$i] * $item_tax['rate'] / 100,  user_price_dec());
+                                 //$ret_tax_array[$index]['Value'] += 
+                                 //    round($prices[$i] * $item_tax['rate'] / 100,  user_price_dec());
+                                 $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100);
                        }
                }
        }
@@ -195,12 +197,14 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc
                        {
                                $index = $item_tax['tax_type_id'];
                                if(isset($ret_tax_array[$index])) {
-                                 if($tax_included==1)
-                                       $ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate'] 
-                                         / ($item_tax['rate'] + 100),  user_price_dec());
+                                 if($tax_included==1) // 2008-11-26 Joe Hunt Taxes are stored without roundings
+                                       //$ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate'] 
+                                       //  / ($item_tax['rate'] + 100),  user_price_dec());
+                                       $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / ($item_tax['rate'] + 100));
                                  else
-                                       $ret_tax_array[$index]['Value'] += 
-                                         round($shipping_cost * $item_tax['rate'] / 100,  user_price_dec());
+                                       //$ret_tax_array[$index]['Value'] += 
+                                       //  round($shipping_cost * $item_tax['rate'] / 100,  user_price_dec());
+                                       $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / 100);
                                }
                        }
                }
index cc0bb64d2f8530852bd3e2d7e5ff045c516ce658..5a87aafd2b4da3c9d7e8c162163a5e47c1740291 100644 (file)
@@ -38,7 +38,7 @@ these files too. </li>
       <li>Upload all the new files.
       </li>
       <li>Restore the files mentioned in #1. Be <strong>careful</strong> with
-        <strong>config.db</strong>. Look into variances. There might be new variables in
+        <strong>config.php</strong>. Look into variances. There might be new variables in
 the new version. It might be easier to <em>manually change your former values in
 the new file</em>.
       </li>
@@ -53,7 +53,7 @@ password and choose the update script from the local harddisk.</li>
 do this, before entering FrontAccounting!
 Enter the database user and the password and choose the alter.sql
 script. &nbsp;Do the same for the alter2.sql script. If you have
-already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company/0.<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
+already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company .<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
 </ul>
 
 <p>&nbsp;</p>
index 26c14ee5fc1f4e5246c83de37dd812a8931fa128..4ebbbc7450cc003e339dca07b39741974e8e66f2 100644 (file)
@@ -9,6 +9,8 @@ $js .= get_js_set_focus("user");
 $image = $path_to_root."/themes/default/images/logo_frontaccounting.png";
 $title = "Update All Company Databases";
 
+$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
+
 function get_js_png_fix()
 {
        $js = "<script type=\"text/javascript\">\n"
@@ -97,7 +99,17 @@ echo "<br>";
 
 if (isset($_POST["submit"]))
 {
-       if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
+       $perms_ok = is_writable($path_to_root.'/company') && is_writable($path_to_root.'/company/0');
+       $checkdirs = $comp_subdirs;
+       foreach ($checkdirs as $dir) {
+               $perms_ok &= is_writable($path_to_root.'/company/0/'.$dir);
+       }
+
+       if (!$perms_ok) {
+               display_error("'System 'company' directory or any of its subdirectories 
+                       is not writable.<br> Change webserver access permissions to those 
+                       directories.");
+       } elseif (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
        {
                display_error("You must select an SQL script for update");;
        }
@@ -127,6 +139,11 @@ if (isset($_POST["submit"]))
                                                display_notification("Database has been updated for company: "
                                                        . $id . " " .  $conn['name']);
                                }
+                               $cdir = "$path_to_root/company/$id";
+                               if (!file_exists($cdir))
+                               {
+                                       create_comp_dirs($cdir, $comp_subdirs);
+                               }
                        }
                }
        }
@@ -135,7 +152,7 @@ if (!isset($_POST['passwd']))
        $_POST['passwd'] = "";
 if (!isset($_POST['user']))
        $_POST['user'] = "";
-
+       
 echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
 
 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";