Stable merged into unstable again (due to failure on binary file during previous...
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 3 Mar 2012 21:35:40 +0000 (22:35 +0100)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 3 Mar 2012 21:35:40 +0000 (22:35 +0100)
87 files changed:
1  2 
admin/db/fiscalyears_db.inc
admin/gl_setup.php
gl/gl_bank.php
gl/includes/db/gl_db_banking.inc
gl/includes/ui/gl_journal_ui.inc
gl/manage/close_period.php
includes/data_checks.inc
includes/date_functions.inc
includes/db/audit_trail_db.inc
includes/db/inventory_db.inc
includes/main.inc
includes/session.inc
includes/types.inc
includes/ui/ui_controls.inc
install/lang/new_language_template/LC_MESSAGES/empty.po
inventory/adjustments.php
inventory/cost_update.php
inventory/includes/db/items_trans_db.inc
inventory/inquiry/stock_movements.php
inventory/inquiry/stock_status.php
inventory/manage/items.php
manufacturing/includes/db/work_order_issues_db.inc
manufacturing/includes/db/work_order_produce_items_db.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
manufacturing/work_order_entry.php
manufacturing/work_order_issue.php
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/db/supp_trans_db.inc
purchasing/includes/db/suppalloc_db.inc
purchasing/includes/db/suppliers_db.inc
purchasing/includes/po_class.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/includes/ui/po_ui.inc
purchasing/inquiry/po_search_completed.php
purchasing/inquiry/supplier_inquiry.php
purchasing/manage/suppliers.php
purchasing/po_entry_items.php
purchasing/supplier_credit.php
purchasing/supplier_payment.php
purchasing/view/view_supp_invoice.php
reporting/includes/class.pdf.inc
reporting/includes/doctext.inc
reporting/includes/excel_report.inc
reporting/rep107.php
reporting/rep109.php
reporting/rep110.php
reporting/rep111.php
reporting/rep112.php
reporting/rep202.php
reporting/rep209.php
reporting/rep210.php
reporting/rep305.php
reporting/rep601.php
reporting/rep701.php
reporting/rep708.php
reporting/rep709.php
reporting/reports_main.php
sales/create_recurrent_invoices.php
sales/credit_note_entry.php
sales/customer_credit_invoice.php
sales/customer_delivery.php
sales/customer_invoice.php
sales/customer_payments.php
sales/includes/cart_class.inc
sales/includes/db/branches_db.inc
sales/includes/db/cust_trans_db.inc
sales/includes/db/customers_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/db/sales_order_db.inc
sales/inquiry/customer_inquiry.php
sales/inquiry/sales_orders_view.php
sales/manage/customer_branches.php
sales/manage/customers.php
sales/sales_order_entry.php
sales/view/view_sales_order.php
sql/alter2.3.php
sql/en_US-demo.sql
sql/en_US-new.sql
taxes/tax_calc.inc
update.html
version.php

index 8cb84044cc5c910c6d81ab643ea0ffd2ba32f0ee,c605c064d2b0aae5bd7abdf9d541ea1f304f99ee..9ace5d195ee0b3c684a1f1a811dae7cb56803ed1
@@@ -337,29 -337,21 +337,28 @@@ function delete_this_fiscalyear($select
        db_query($sql, "Could not delete exchange rates");
        $sql = "DELETE FROM ".TB_PREF."budget_trans WHERE tran_date <= '$to'";
        db_query($sql, "Could not delete exchange rates");
--      
 -      $sql = "SELECT account, SUM(amount) AS amount FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' GROUP by account";
 +      $sql = "SELECT account, SUM(amount) AS amount, person_type_id, person_id FROM "
 +              .TB_PREF."gl_trans WHERE tran_date <= '$to' GROUP by account, person_type_id, person_id";
-       $sql = "SELECT account, SUM(amount) AS amount FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' GROUP by account";
        $result = db_query($sql, "Could not retrieve gl trans");
        $trans_no = get_next_trans_no(ST_JOURNAL);
 +
 +      $last_account='';
        $new = false;
        while ($row = db_fetch($result))
        {
 -              $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' AND account = '{$row['account']}'";
 -              db_query($sql, "Could not delete gl trans");
 -              if (is_account_balancesheet($row['account']))
 +              if ($last_account != $row['account']) // deletes all subledgers postings, so do it once for account
 +              {
 +                      $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' AND account = '{$row['account']}'";
 +                      db_query($sql, "Could not delete gl trans");
 +                      $last_account = $row['account'];
 +              }
 +              if (is_account_balancesheet($row['account']) && $row['amount'])
                {
 -                      $sql = "INSERT INTO ".TB_PREF."gl_trans (type, type_no, tran_date, account, memo_, amount) VALUES
 -                              (".ST_JOURNAL.", $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']})";
 +                      $sql = "INSERT INTO ".TB_PREF."gl_trans (type, type_no, tran_date, account, memo_, amount, person_type_id, person_id) VALUES
 +                              (".ST_JOURNAL.", $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']}, "
 +                              .db_escape($row['person_type_id'], true).", ".db_escape($row['person_id'], true).")";
                        db_query($sql, "Could not insert gl trans");
+                       $new = true;
                }
        }
        if ($new)
index 1263be92747f82cce2063156f1beb066c195d0cd,1ef3e40e06c3272f150606f0907dee47161b4604..fe494679a0ea6ff885175eceacacecfcf2810945
@@@ -83,6 -83,11 +83,10 @@@ start_form()
  start_outer_table(TABLESTYLE2);
  
  table_section(1);
 -
+ if (get_company_pref('grn_clearing_act') === null) { // available form 2.3.1, can be not defined on pre-2.4 installations
+       set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
+       refresh_sys_prefs();
+ }
  
  $myrow = get_company_prefs();
  
diff --cc gl/gl_bank.php
Simple merge
index 608f4e8ce71c6129fce1e765081acd057911166a,4a88583a24a73138d080699f128edbbfa5f934ae..0650a0c654ceafd40c6bb60a5ca984a016ebdb97
@@@ -251,8 -252,8 +251,7 @@@ function add_bank_transfer($from_accoun
        if ($SysPrefs->auto_currency_revaluation())
        {
                $currency = get_bank_account_currency($to_account);
-               if ($exchanged || add_exchange_variation($trans_no1, $date_, $to_account, $to_gl_account,
 -      
+               if (add_exchange_variation($trans_no1, $date_, $to_account, $to_gl_account,     
                        $currency, PT_MISC, $person_id))
                        $exchanged = true;
        }
index f9e5585c975669d0c32ab96227828aa5041ca007,8c4aec6ae44d2b27e7db29c0c6013add32e4a7b4..d68f09140bbb951795a7687dc129fc8f905fe647
@@@ -277,8 -241,8 +277,3 @@@ function gl_options_controls(
  
          echo "</table>";
  }
--
--
--//---------------------------------------------------------------------------------
--
--?>
index fa21d00b05fdc4f22108fccf3326440bfa6fe739,0000000000000000000000000000000000000000..fc057c25827bb85c22e91ad5837dc3994ab7ddbb
mode 100644,000000..100644
--- /dev/null
@@@ -1,108 -1,0 +1,109 @@@
-       if (!is_date_in_fiscalyears($date, false))
 +<?php
 +/**********************************************************************
 +    Copyright (C) FrontAccounting, LLC.
 +      Released under the terms of the GNU General Public License, GPL, 
 +      as published by the Free Software Foundation, either version 3 
 +      of the License, or (at your option) any later version.
 +    This program is distributed in the hope that it will be useful,
 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 +    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 +***********************************************************************/
 +
 +$page_security = 'SA_GLCLOSE';
 +$path_to_root = "../..";
 +include_once($path_to_root . "/includes/session.inc");
 +
 +include_once($path_to_root . "/includes/date_functions.inc");
 +include_once($path_to_root . "/includes/ui.inc");
 +include_once($path_to_root . "/includes/banking.inc");
++include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
 +
 +$js = "";
 +if ($use_date_picker)
 +      $js .= get_js_date_picker();
 +page(_($help_context = "Closing GL Transactions"), false, false, "", $js);
 +
 +//---------------------------------------------------------------------------------------------
 +function check_data()
 +{
 +      global $Refs, $allow_gl_reopen;
 +      
 +      if (!is_date($_POST['date']) || date1_greater_date2($_POST['date'], Today()))
 +      {
 +              display_error( _("The entered date is invalid."));
 +              set_focus('date');
 +              return false;
 +      }
++      if (!is_date_in_fiscalyears($_POST['date'], false))
 +      {
 +              display_error(_("Selected date is not in fiscal year or the year is closed."));
 +              set_focus('date');
 +              return false;
 +      }
 +      if (date1_greater_date2(sql2date(get_company_pref('gl_closing_date')), $_POST['date']))
 +      {
 +              if (!$allow_gl_reopen) {
 +                      display_error(_("The entered date is earlier than date already selected as closing date."));
 +                      set_focus('date');
 +                      return false;
 +              } elseif (!user_check_access('SA_GLREOPEN')) {
 +                      display_error(_("You are not allowed to reopen already closed transactions."));
 +                      set_focus('date');
 +                      return false;
 +              }
 +      }
 +      return true;
 +}
 +
 +//---------------------------------------------------------------------------------------------
 +
 +function handle_submit()
 +{
 +      if (!check_data())
 +              return;
 +
 +      if (!close_transactions($_POST['date']))
 +      {
 +              display_notification(
 +                      sprintf( _("All transactions resulting in GL accounts changes up to %s has been closed for further edition."),
 +                      sql2date(get_company_pref('gl_closing_date'))) );
 +      }
 +
 +}
 +
 +
 +//---------------------------------------------------------------------------------------------
 +
 +function clear_data()
 +{
 +      unset($_POST['date_']);
 +}
 +
 +//---------------------------------------------------------------------------------------------
 +
 +if (get_post('submit'))
 +      handle_submit();
 +else
 +      display_note(_("Using this feature you can prevent entering new transactions <br>
 +      and disable edition of already entered transactions up to specified date.<br>
 +      Only transactions which can generate GL postings are subject to the constraint."));
 +
 +//---------------------------------------------------------------------------------------------
 +
 +br(1);
 +start_form();
 +start_table(TABLESTYLE2);
 +if (!isset($_POST['date'])) {
 +      $cdate = sql2date(get_company_pref('gl_closing_date'));
 +      $_POST['date'] = $cdate ;// ? end_month(add_months($cdate, 1)) : Today();
 +}
 +date_row(_("End date of closing period:"), 'date');
 +end_table(1);
 +
 +submit_center('submit', _("Close Transactions"), true, false);
 +end_form();
 +
 +end_page();
 +
 +?>
index 543a7d5936edb3767cdef001198cfd60fe343a95,798e84c4b5c10070a4526a2ccbc7a2ad987b0898..f50e94540319f94d40b1a684c2e93f7de3751081
@@@ -485,17 -485,5 +485,16 @@@ function check_num($postname, $min=null
      return 1;
  }
  
 -
 -?>
 +function check_is_closed($type, $type_no, $msg=null)
 +{
 +      global $systypes_array;
 +      
 +    if (($type_no > 0) && is_closed_trans($type, $type_no))
 +    {
 +      if (!$msg)
 +              $msg = sprintf(_("%s #%s is closed for further edition."), $systypes_array[$type], $type_no);
 +      display_error($msg, true);
 +      end_page();
 +      exit;
 +    }
 +}
index 343e56ad3540aa746c64012ccef5a655f7971b82,6f8379e072877bbf9413f274ca29366da2af68a6..d1aacdf8302f7fbbf80da6089a8b16e86b19fda3
@@@ -348,7 -345,7 +348,6 @@@ and converts to a yyyy/mm/dd format *
  
        $date_ = trim($date_);
      $year = $month = $day = 0;
--
      // Split up the date by the separator based on "how" to split it
      if ($how == 0) // MMDDYYYY
          list($month, $day, $year) = explode($sep, $date_);
index e19a659e7f13b8e0f6f43c695fe3a45ca9ba8838,f9efe9a01861a2d3016dbdbf21e7c4d1fcec4904..c25fdc5111526228c42f858afa8ed8756123b524
  
  function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
  {
 +      $date = date2sql($trans_date);
        $sql = "INSERT INTO ".TB_PREF."audit_trail"
 -              . " (type, trans_no, user, fiscal_year, gl_date, description, gl_seq)
 +              . " (type, trans_no, user, gl_date, description)
                        VALUES(".db_escape($trans_type).", ".db_escape($trans_no).","
 -                      . $_SESSION["wa_current_user"]->user. ","
 -                      . get_company_pref('f_year') .","
 -                      . "'". date2sql($trans_date) ."',"
 -                      . db_escape($descr). ", 0)";
 +                      . $_SESSION["wa_current_user"]->user . ","
 +                      . "'$date',". db_escape($descr). ")";
  
        db_query($sql, "Cannot add audit info");
--      
 -      // all audit records beside latest one should have gl_seq set to NULL
 +      // all audit records beside just inserted one should have gl_seq set to NULL
        // to avoid need for subqueries (not existing in MySQL 3) all over the code
 -      $sql = "UPDATE ".TB_PREF."audit_trail SET gl_seq = NULL"
 +      $sql = "UPDATE ".TB_PREF."audit_trail audit LEFT JOIN ".TB_PREF."fiscal_year year ON year.begin<='$date' AND year.end>='$date'
 +              SET audit.gl_seq = IF(audit.id=".db_insert_id().", 0, NULL),"
 +              ."audit.fiscal_year=year.id"
                . " WHERE type=".db_escape($trans_type)." AND trans_no="
 -              .db_escape($trans_no)." AND id!=".db_insert_id();
 +              . db_escape($trans_no);
  
        db_query($sql, "Cannot update audit gl_seq");
  }
@@@ -83,27 -78,51 +82,28 @@@ function close_transactions($todate) 
                        }
                        if ($last_year != $row['fiscal_year']) {
                                $last_year = $row['fiscal_year'];
 -                              $counter = 1; // reset counter on fiscal year change
 -                      } else
 -                              $counter++;
 -                      $sql2 = "UPDATE ".TB_PREF."audit_trail SET"
 -                              . " gl_seq=$counter"
 -                              . " WHERE id=".$row['id'];
 -                                                                                      
 -                      db_query($sql2, "Cannot reindex journal");
 +                              $counter = 0; // reset counter on fiscal year change
 +                      }
-                       
++
 +                      $seq = $row['closed'] ? ++$counter : 0;
 +                      if ($row['gl_seq'] != $seq)     { // update transaction status only when gl_seq has changed
 +                              $sql2 = "UPDATE ".TB_PREF."audit_trail SET"
 +                                      . " gl_seq=$seq"
 +                                      . " WHERE id=".$row['id'];
 +                              db_query($sql2, "Cannot reindex journal");
 +                      }
                }
        }
 -      
++
        if ($errors) 
                display_warning(_("Some transactions journal GL postings were not indexed due to lack of audit trail record."));
 -}
 -
 -/*
 -      Reopen all transactions for edition up from date $fromdate
 -*/
 -function open_transactions($fromdate) {
 -
 -      $sql = "SELECT a.id, a.gl_date, a.fiscal_year"
 -              ." FROM ".TB_PREF."gl_trans gl"
 -              ." LEFT JOIN ". TB_PREF."audit_trail a ON 
 -                      (gl.type=a.type AND gl.type_no=a.trans_no)"
 -              . " WHERE gl_date>='". date2sql($fromdate) ."'"
 -              . " AND !ISNULL(gl_seq)"
 -              . " ORDER BY a.fiscal_year, a.gl_date, a.id";
 -
 -      $result = db_query($sql, "Cannot select transactions for openning");
 +      else
 +              update_company_prefs(array('gl_closing_date'=> date2sql($todate)));
 +      commit_transaction();
  
 -      if (db_num_rows($result)) {
 -              $last_year = 0;
 -
 -              while ($row = db_fetch($result)) {
 -                      if ($row['fiscal_year'] == null) {
 -                              continue;
 -                      }
 -                      $sql2 = "UPDATE ".TB_PREF."audit_trail SET"
 -                              . " gl_seq=0"
 -                              . " WHERE id=".$row['id'];
 -                                                                                      
 -                      db_query($sql2, "Cannot clear journal order");
 -              }
 -      }
 +      return $errors;
  }
 +
  /*
        Closed transactions have gl_seq number assigned.
  */
index 80f552e919b535fa624e06c88cb5664311bede90,068c1645ee7451e48f1f63c7d8ec975bc52e9098..e0ea2ef7646f00d33338e2ab29246d0561b5dcf0
@@@ -173,22 -173,22 +173,22 @@@ function get_deliveries_from_trans($sto
              trans_id>='$from' GROUP BY stock_id";
        $result = db_query($sql, "The deliveries could not be updated");
        $row = db_fetch_row($result);
+       
 -    $sql = "SELECT IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost)\r
 -        FROM ".TB_PREF."stock_moves\r
 -        WHERE stock_id=".db_escape($stock_id)\r
 -            ." AND trans_id ='$from'";\r
 -    $result = db_query($sql, "The deliveries could not be updated");\r
 +    $sql = "SELECT IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost)
 +        FROM ".TB_PREF."stock_moves
 +        WHERE stock_id=".db_escape($stock_id)
 +            ." AND trans_id ='$from'";
 +    $result = db_query($sql, "The deliveries could not be updated");
      $cost = db_fetch_row($result);
 -      
 +
        // Adjusting QOH valuation 
        $sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves
                WHERE stock_id=".db_escape($stock_id)." AND
                        trans_id<'$from' GROUP BY stock_id";
        $result = db_query($sql, "The deliveries could not be updated");
        $qoh = db_fetch_row($result);
--      
 -      $qty = $row[0] - $qoh[0]; //QOH prior to -ve stock is subtracted\r
++
 +      $qty = $row[0] - $qoh[0]; //QOH prior to -ve stock is subtracted
        $final_cost = $row[1] - $qoh[0]*$cost[0];
        
        return array($qty,$final_cost); 
@@@ -428,8 -430,8 +428,3 @@@ function get_location_name($loc_code
  
        display_db_error("could not retreive the location name for $loc_code", $sql, true);
  }
--
--//--------------------------------------------------------------------------------------------------
--
--
--?>
index 8f2b3c33d56ea3912b97e3579d6b9488b45c9aa4,8f2b3c33d56ea3912b97e3579d6b9488b45c9aa4..98143cf9843626965a97036f555bf0008be2baff
@@@ -22,21 -22,21 +22,24 @@@ include_once($path_to_root . "/includes
  include_once($path_to_root . "/admin/db/users_db.inc");
  include_once($path_to_root . "/includes/ui/ui_view.inc");
  include_once($path_to_root . "/includes/ui/ui_controls.inc");
--      
++
++$page_nested = -1;
++
  function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false, $css='')
  {
  
--      global $path_to_root, $page_security;
++      global $path_to_root, $page_security, $page_nested;
  
++      if (++$page_nested) return;
  
        $hide_menu = $no_menu;
  
--      include($path_to_root . "/includes/page/header.inc");
++      include_once($path_to_root . "/includes/page/header.inc");
  
        page_header($title, $no_menu, $is_index, $onload, $js, $css);
        check_page_security($page_security);
  //    error_box();
--      if($script_only) {              
++      if($script_only) {
                echo '<noscript>';
                echo display_heading(_('This page is usable only with javascript enabled browsers.'));
                echo '</noscript>';
  
  function end_page($no_menu=false, $is_index=false, $final_screen=false, $type_no=0, $trans_no=0)
  {
--      global $path_to_root;
++      global $path_to_root, $page_nested;
++
++      if ($page_nested-- > 0) return;
  
        if (!$is_index && function_exists('hyperlink_back'))
                hyperlink_back(true, $no_menu, $type_no, $trans_no, $final_screen);
        div_end();      // end of _page_body section
  
--      include($path_to_root . "/includes/page/footer.inc");
++      include_once($path_to_root . "/includes/page/footer.inc");
        page_footer($no_menu, $is_index);
  }
  
Simple merge
index ec06fbaa62379cf8bc756bc45e2f29dbdab71f0d,79ef8be71c01699d87a8daf242fee733ad718fe3..94d5c4e026391ecf95fb7180025e63560fa7167b
@@@ -137,80 -137,6 +137,79 @@@ function payment_person_name($type, $pe
        }
  }
  
 +//
 +//    Returns counterparty (supplier/customer) name for selected transaction.
 +//
 +function get_counterparty_name($trans_type, $trans_no, $full=true)
 +{
 +      switch($trans_type)
 +      {
 +              case ST_SALESORDER:
 +              case ST_SALESQUOTE:
 +                      $sql = "SELECT order.customer_id as person_id, debtor.name as name
 +                      FROM ".TB_PREF."sales_orders order, ".TB_PREF."debtors_master debtor
 +                      WHERE order_no=".db_escape($trans_no)." AND trans_type=".db_escape($trans_type)
 +                      ." AND order.debtor_no=debtor.debtor_no";
 +                      break;
 +              case ST_SALESINVOICE :
 +              case ST_CUSTCREDIT :
 +              case ST_CUSTPAYMENT :
 +              case ST_CUSTDELIVERY :
 +                      $sql = "SELECT trans.debtor_no as person_id, debtor.name as name
 +                      FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master debtor
 +                      WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
 +                      ." AND trans.debtor_no=debtor.debtor_no";
 +                      break;
 +
 +              case ST_PURCHORDER :
 +                      $sql = "SELECT order.supplier_id as person_id, supp.supp_name as name
 +                      FROM ".TB_PREF."purch_orders order, ".TB_PREF."suppliers supp
 +                      WHERE order_no=".db_escape($trans_no)
 +                      ." AND order.supplier_id=supp.supplier_id";
 +                      break;
 +
 +              case ST_SUPPINVOICE :
 +              case ST_SUPPCREDIT :
 +              case ST_SUPPAYMENT :
 +                      $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
 +                      FROM ".TB_PREF."supp_trans trans, ".TB_PREF."suppliers supp
 +                      WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
 +                      ." AND trans.supplier_id=supp.supplier_id";
 +                      break;
 +
 +              case ST_SUPPRECEIVE :
 +                      $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
 +                      FROM ".TB_PREF."grn_batch trans, ".TB_PREF."suppliers supp
 +                      WHERE id=".db_escape($trans_no)
 +                      ." AND trans.supplier_id=supp.supplier_id";
 +                      break;
 +
 +              case ST_JOURNAL:        // FIXME - this one can have multiply counterparties of various types depending on person_type_id
 +
 +              default: 
 +              /*      // internal operations
 +              case ST_WORKORDER :
 +              case ST_INVADJUST : // GRN/DN returns ?
 +              case ST_BANKTRANSFER :
 +              case ST_LOCTRANSFER :
 +              case ST_MANUISSUE :
 +              case ST_MANURECEIVE :
 +              case ST_COSTUPDATE :
 +              case ST_BANKPAYMENT :   // generic bank transactions
 +              case ST_BANKDEPOSIT :*/
 +                      return null;
 +      }
 +
 +      $result = db_query($sql, 'cannot retrieve counterparty name');
 +      if (db_num_rows($result))
 +      {
 +              $row = db_fetch($result);
 +              return sprintf("[%05s] %s", $row['person_id'], $row['name']);
 +      }
 +
 +      return '';
 +}
 +
  function payment_person_has_items($type) {
        switch ($type)
        {
index d2e094ae45e7e462bb2d67a7969e42c4182f9ea5,bbe4c7f5142f3680055589e48ecbe906daaca390..0639124a5a236a4f6170ca70b57c0c7a5b637dd8
@@@ -32,10 -32,10 +32,15 @@@ function get_post($name, $dflt=''
                                ((!isset($_POST[$name]) || $_POST[$name] === '') ? $dflt : $_POST[$name]);
  }
  //---------------------------------------------------------------------------------
++$form_nested = -1;
  
  function start_form($multi=false, $dummy=false, $action="", $name="")
  {
        // $dummy - leaved for compatibility with 2.0 API
++      global $form_nested;
++
++      if (++$form_nested) return;
++
  
        if ($name != "")
                $name = "name='$name'";
@@@ -53,7 -53,7 +58,9 @@@
  
  function end_form($breaks=0)
  {
--      global $Ajax;
++      global $Ajax, $form_nested;
++
++      if ($form_nested-- > 0) return;
  
        $_SESSION['csrf_token'] = hash('sha256', uniqid(mt_rand(), true));
        if ($breaks)
index a874adedc353d4376a8c52eecda6e5f55d98e2d1,b82bd46a4fa36b77d39205ecfc2e7ec393b948e3..804d5ae202a8c9e176402edb869cfac220715293
@@@ -8,60 -8,66 +8,67 @@@ msgid "
  msgstr ""
  "Project-Id-Version: PACKAGE VERSION\n"
  "Report-Msgid-Bugs-To: \n"
- "POT-Creation-Date: 2010-08-13 15:12+0200\n"
++"POT-Creation-Date: 2012-02-29 09:49+0100\n"
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  "Language-Team: LANGUAGE <LL@li.org>\n"
+ "Language: \n"
  "MIME-Version: 1.0\n"
- "Content-Type: text/plain; charset=CHARSET\n"
+ "Content-Type: text/plain; charset=ISO-8859-2\n"
  "Content-Transfer-Encoding: 8bit\n"
  
- #: ../install/index.php:20 ../install/index.php:40
 -#: install/index.php:20 install/index.php:40
++#: install/index.php:20 install/index.php:41
  msgid "FrontAccouting ERP Installation Wizard"
  msgstr ""
  
- #: ../install/index.php:41
 -#: install/index.php:41
++#: install/index.php:42
  #, php-format
  msgid "Step %d: %s"
  msgstr ""
  
- #: ../install/index.php:48
 -#: install/index.php:48
++#: install/index.php:49
  msgid "Chart of accounts"
  msgstr ""
  
- #: ../install/index.php:48 ../install/index.php:75
 -#: install/index.php:48 install/index.php:75
++#: install/index.php:49 install/index.php:76
  msgid "Encoding"
  msgstr ""
  
- #: ../install/index.php:48 ../install/index.php:75
 -#: install/index.php:48 install/index.php:75
++#: install/index.php:49 install/index.php:76
  msgid "Description"
  msgstr ""
  
- #: ../install/index.php:48 ../install/index.php:75
 -#: install/index.php:48 install/index.php:75
++#: install/index.php:49 install/index.php:76
  msgid "Install"
  msgstr ""
  
- #: ../install/index.php:65 ../install/index.php:93
 -#: install/index.php:65 install/index.php:93
++#: install/index.php:66 install/index.php:94
  msgid "Installed"
  msgstr ""
  
- #: ../install/index.php:75
 -#: install/index.php:75
++#: install/index.php:76
  msgid "Language"
  msgstr ""
  
- #: ../install/index.php:156
 -#: install/index.php:123
++#: install/index.php:124
+ msgid ""
+ "Cannot connect to database. User or password is invalid or you have no "
+ "permittions to create database."
+ msgstr ""
 -#: install/index.php:159
++#: install/index.php:160
  msgid "Cannot save system configuration file 'config.php'."
  msgstr ""
  
- #: ../install/index.php:173
 -#: install/index.php:166
++#: install/index.php:167
  msgid "Cannot open 'config_db.php' configuration file."
  msgstr ""
  
- #: ../install/index.php:176
 -#: install/index.php:169
++#: install/index.php:170
  msgid "Cannot write to the 'config_db.php' configuration file."
  msgstr ""
  
- #: ../install/index.php:179
 -#: install/index.php:172
++#: install/index.php:173
  msgid ""
  "Configuration file 'config_db.php' is not writable. Change its permissions "
  "so it is, then re-run installation step."
@@@ -109,8 -115,8 +116,8 @@@ msgid "
  "Continue button below."
  msgstr ""
  
- #: ../install/index.php:330 ../install/index.php:356 ../install/index.php:363
- #: ../install/index.php:370 ../install/index.php:389
+ #: install/index.php:325 install/index.php:351 install/index.php:358
 -#: install/index.php:365 install/index.php:384
++#: install/index.php:365 install/index.php:389
  msgid "Continue >>"
  msgstr ""
  
@@@ -177,8 -183,8 +184,8 @@@ msgid "
  "connection right now. You can install them later."
  msgstr ""
  
- #: ../install/index.php:355 ../install/index.php:362 ../install/index.php:369
- #: ../install/index.php:388
+ #: install/index.php:350 install/index.php:357 install/index.php:364
 -#: install/index.php:383
++#: install/index.php:388
  msgid "<< Back"
  msgstr ""
  
@@@ -190,43 -196,43 +197,43 @@@ msgstr "
  msgid "Charts of Accounts Selection"
  msgstr ""
  
- #: ../install/index.php:379
 -#: install/index.php:374
++#: install/index.php:379
  msgid "Company Settings"
  msgstr ""
  
- #: ../install/index.php:381
 -#: install/index.php:376
++#: install/index.php:381
  msgid "Company Name:"
  msgstr ""
  
- #: ../install/index.php:382
 -#: install/index.php:377
++#: install/index.php:382
  msgid "Admin Login:"
  msgstr ""
  
- #: ../install/index.php:383
 -#: install/index.php:378
++#: install/index.php:383
  msgid "Admin Password:"
  msgstr ""
  
- #: ../install/index.php:384
 -#: install/index.php:379
++#: install/index.php:384
  msgid "Reenter Password:"
  msgstr ""
  
- #: ../install/index.php:385
 -#: install/index.php:380
++#: install/index.php:385
  msgid "Select Chart of Accounts:"
  msgstr ""
  
- #: ../install/index.php:386
 -#: install/index.php:381
++#: install/index.php:386
  msgid "Select Default Language:"
  msgstr ""
  
- #: ../install/index.php:393
 -#: install/index.php:388
++#: install/index.php:393
  msgid "FrontAccounting ERP has been installed successsfully."
  msgstr ""
  
- #: ../install/index.php:394
 -#: install/index.php:389
++#: install/index.php:394
  msgid "Please do not forget to remove install wizard folder."
  msgstr ""
  
- #: ../install/index.php:396
 -#: install/index.php:392
++#: install/index.php:397
  msgid "Click here to start."
  msgstr ""
  
@@@ -453,6 -459,38 +460,43 @@@ msgstr "
  msgid "Comments"
  msgstr ""
  
- #: ../includes/system_tests.inc:435
+ #: includes/system_tests.inc:435
  msgid "Ok"
  msgstr ""
 -#: includes/packages.inc:295
+ #: includes/packages.inc:190
+ #, php-format
+ msgid "No key field '%s' in file '%s'"
+ msgstr ""
 -#: includes/packages.inc:311
++#: includes/packages.inc:295 includes/packages.inc:329
++#, php-format
++msgid "Cannot delete outdated '%s' file."
++msgstr ""
++
++#: includes/packages.inc:299
+ msgid "Release file in repository is invalid, or public key is outdated."
+ msgstr ""
 -#: includes/packages.inc:325
++#: includes/packages.inc:316
+ msgid "Repository version does not match application version."
+ msgstr ""
 -#: includes/packages.inc:358
++#: includes/packages.inc:333
+ #, php-format
+ msgid ""
+ "Security alert: broken index file in repository '%s'. Please inform "
+ "repository administrator about this issue."
+ msgstr ""
 -#: includes/packages.inc:613 includes/packages.inc:664
++#: includes/packages.inc:366
+ #, php-format
+ msgid ""
+ "Security alert: broken package '%s' in repository. Please inform repository "
+ "administrator about this issue."
+ msgstr ""
++#: includes/packages.inc:621 includes/packages.inc:672
+ #, php-format
+ msgid "Package '%s' not found."
+ msgstr ""
Simple merge
index 03db733e309f9a1840015dfc4196fbb85e18b18f,b5ee125dd966fab6f3094b8360c60692e950d428..0e39a0c050c33f6fe5799b5e79f9bf40b46ed728
@@@ -38,8 -38,8 +38,8 @@@ if (isset($_GET['stock_id'])
  if (isset($_POST['UpdateData']))
  {
  
-       $old_cost = $_POST['OldMaterialCost'] + $_POST['OldLabourCost']
-           + $_POST['OldOverheadCost'];
+       $old_cost = get_standard_cost($_POST['stock_id']);
 -     
++
        $new_cost = input_num('material_cost') + input_num('labour_cost')
             + input_num('overhead_cost');
  
index 7292814d35c38d95e0f52befcb6dbd8227d9ce05,78930e81d9bce8ca9dc4132646aa25fa9664ef0e..923d18c4f79f5dc65690186196360203e78f1f16
@@@ -35,25 -44,26 +44,32 @@@ function stock_cost_update($stock_id, $
        $qoh = get_qoh_on_date($_POST['stock_id']);
        
        $date_ = Today();
+       if (!is_date_in_fiscalyear($date_))
+               $date_ = end_fiscalyear();
        if ($qoh > 0)
        {
-     
-               $update_no = get_next_trans_no(ST_COSTUPDATE);
-               if (!is_date_in_fiscalyear($date_))
-                       $date_ = end_fiscalyear();
-          
-               $stock_gl_code = get_stock_gl_code($stock_id);
                $new_cost = $material_cost + $labour_cost + $overhead_cost;
  
-               add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["inventory_account"], 0, 0, $memo_, 
-                       $value_of_change);
 +              $value_of_change = $qoh * ($new_cost - $last_cost);
 +
 +              $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh";
 +              add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["adjustment_account"], 
 +                      $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], $memo_, (-$value_of_change));     
 +
 -              }               
+               $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec());
+               if ($value_of_change != 0)
+               {
+                       $stock_gl_code = get_stock_gl_code($stock_id);
+                       $update_no = get_next_trans_no(ST_COSTUPDATE);
+                       $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh";
+                       add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["adjustment_account"], 
+                               $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], $memo_, (-$value_of_change));     
+                       add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["inventory_account"], 0, 0, $memo_, 
+                               $value_of_change);
++              }
        }
  
        add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
index 1dd1382733810d280c45e26ea2db506279e8ff2d,2c5aa0e044b6c77a139190e9850f43a56288c590..417b5df5c6ad7b9440e95aa89d970998bd1879c7
@@@ -18,13 -18,15 +18,12 @@@ include_once($path_to_root . "/includes
  include_once($path_to_root . "/sales/includes/sales_db.inc");
  
  include_once($path_to_root . "/includes/ui.inc");
 -if (!@$_GET['popup'])
 -{
 -      $js = "";
 -      if ($use_popup_windows)
 -              $js .= get_js_open_window(800, 500);
 -      if ($use_date_picker)
 -              $js .= get_js_date_picker();
 -      page(_($help_context = "Inventory Item Movement"), @$_GET['popup'], false, "", $js);
 -}     
 +$js = "";
 +if ($use_popup_windows)
 +      $js .= get_js_open_window(800, 500);
 +if ($use_date_picker)
 +      $js .= get_js_date_picker();
- page(_($help_context = "Inventory Item Movement"), false, false, "", $js);
++page(_($help_context = "Inventory Item Movement"), @$_GET['popup'], false, "", $js);
  //------------------------------------------------------------------------------------------------
  
  check_db_has_stock_items(_("There are no items defined in the system."));
@@@ -46,7 -49,8 +45,8 @@@ if (!isset($_POST['stock_id'])
  
  start_table(TABLESTYLE_NOBORDER);
  start_row();
- stock_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
 -if (!@$_GET['popup'])
++if (!$page_nested)
+       stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
  end_row();
  end_table();
  
index 1ccbca0db1d0273e3a1e5fc7a13ff48486b4803e,b6965d2961c78602852f29db014ef7ac9d65eb5b..146422fa6bfc5772fa8a924b0f364314901806e9
@@@ -13,13 -13,16 +13,11 @@@ $page_security = 'SA_ITEMSSTATVIEW'
  $path_to_root = "../..";
  include_once($path_to_root . "/includes/session.inc");
  
- if (isset($_GET['stock_id'])){
 -if (!@$_GET['popup'])
 -{
 -      if (isset($_GET['stock_id'])){
 -              page(_($help_context = "Inventory Item Status"), true);
 -      } else {
 -              page(_($help_context = "Inventory Item Status"));
 -      }
 -}
++page(_($help_context = "Inventory Item Status"));
++
+ if (isset($_GET['stock_id']))
        $_POST['stock_id'] = $_GET['stock_id'];
-       page(_($help_context = "Inventory Item Status"), true);
- } else {
-       page(_($help_context = "Inventory Item Status"));
- }
 +
  include_once($path_to_root . "/includes/date_functions.inc");
  include_once($path_to_root . "/includes/ui.inc");
  include_once($path_to_root . "/includes/manufacturing.inc");
@@@ -38,8 -42,11 +36,11 @@@ start_form()
  if (!isset($_POST['stock_id']))
        $_POST['stock_id'] = get_global_stock_item();
  
- echo "<center> " . _("Item:"). " ";
- echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
 -if (!@$_GET['popup'])
++if (!$page_nested)
+ {
+       echo "<center> " . _("Item:"). " ";
+       echo stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
 -}     
++}
  echo "<br>";
  
  echo "<hr></center>";
index 1391b825da10ae35f305a6165b31454b3535f813,666486f08b94ddd1295210e20c122d80e8547feb..70572f59fed52f10d7245ca162d4941a38af1864
  $page_security = 'SA_ITEM';
  $path_to_root = "../..";
  include($path_to_root . "/includes/session.inc");
- page(_($help_context = "Items"), @$_REQUEST['popup']);
 +
 -page(_($help_context = "Items"), false, false, "", $js);
+ $js = "";
+ if ($use_popup_windows)
+       $js .= get_js_open_window(900, 500);
+ if ($use_date_picker)
+       $js .= get_js_date_picker();
+       
++page(_($help_context = "Items"), @$_REQUEST['popup'], false, "", $js);
++
  
  include_once($path_to_root . "/includes/date_functions.inc");
  include_once($path_to_root . "/includes/ui.inc");
@@@ -239,194 -246,238 +253,237 @@@ if (isset($_POST['delete']) && strlen($
                $Ajax->activate('_page_body');
        }
  }
- //-------------------------------------------------------------------------------------------- 
- start_form(true);
  
if (db_has_stock_items()
function item_settings(&$stock_id
  {
-       start_table(TABLESTYLE_NOBORDER);
-       start_row();
-     stock_items_list_cells(_("Select an item:"), 'stock_id', null,
-         _('New item'), true, check_value('show_inactive'));
-       $new_item = get_post('stock_id')=='';
-       check_cells(_("Show inactive:"), 'show_inactive', null, true);
-       end_row();
-       end_table();
+       global $SysPrefs, $path_to_root, $new_item, $pic_height;
  
-       if (get_post('_show_inactive_update')) {
-               $Ajax->activate('stock_id');
-               set_focus('stock_id');
+       start_outer_table(TABLESTYLE2);
+       table_section(1);
+       table_section_title(_("Item"));
+       //------------------------------------------------------------------------------------
+       if ($new_item) 
+       {
+               text_row(_("Item Code:"), 'NewStockID', null, 21, 20);
+               $_POST['inactive'] = 0;
+       } 
+       else 
+       { // Must be modifying an existing item
+               if (get_post('NewStockID') != get_post('stock_id') || get_post('addupdate')) { // first item display
+                       $_POST['NewStockID'] = $_POST['stock_id'];
+                       $myrow = get_item($_POST['NewStockID']);
+                       $_POST['long_description'] = $myrow["long_description"];
+                       $_POST['description'] = $myrow["description"];
+                       $_POST['category_id']  = $myrow["category_id"];
+                       $_POST['tax_type_id']  = $myrow["tax_type_id"];
+                       $_POST['units']  = $myrow["units"];
+                       $_POST['mb_flag']  = $myrow["mb_flag"];
+                       $_POST['sales_account'] =  $myrow['sales_account'];
+                       $_POST['inventory_account'] = $myrow['inventory_account'];
+                       $_POST['cogs_account'] = $myrow['cogs_account'];
+                       $_POST['adjustment_account']    = $myrow['adjustment_account'];
+                       $_POST['assembly_account']      = $myrow['assembly_account'];
+                       $_POST['dimension_id']  = $myrow['dimension_id'];
+                       $_POST['dimension2_id'] = $myrow['dimension2_id'];
+                       $_POST['no_sale']       = $myrow['no_sale'];
+                       $_POST['del_image'] = 0;        
+                       $_POST['inactive'] = $myrow["inactive"];
+                       $_POST['editable'] = $myrow["editable"];
+               }
+               label_row(_("Item Code:"),$_POST['NewStockID']);
+               hidden('NewStockID', $_POST['NewStockID']);
+               set_focus('description');
        }
- }
  
- div_start('details');
- start_outer_table(TABLESTYLE2);
+       text_row(_("Name:"), 'description', null, 52, 200);
  
table_section(1);
      textarea_row(_('Description:'), 'long_description', null, 42, 3);
  
- table_section_title(_("Item"));
+       stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item);
+       if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) {
+               $category_record = get_item_category($_POST['category_id']);
+               $_POST['tax_type_id'] = $category_record["dflt_tax_type"];
+               $_POST['units'] = $category_record["dflt_units"];
+               $_POST['mb_flag'] = $category_record["dflt_mb_flag"];
+               $_POST['inventory_account'] = $category_record["dflt_inventory_act"];
+               $_POST['cogs_account'] = $category_record["dflt_cogs_act"];
+               $_POST['sales_account'] = $category_record["dflt_sales_act"];
+               $_POST['adjustment_account'] = $category_record["dflt_adjustment_act"];
+               $_POST['assembly_account'] = $category_record["dflt_assembly_act"];
+               $_POST['dimension_id'] = $category_record["dflt_dim1"];
+               $_POST['dimension2_id'] = $category_record["dflt_dim2"];
+               $_POST['no_sale'] = $category_record["dflt_no_sale"];
+               $_POST['editable'] = 0;
  
- //------------------------------------------------------------------------------------
- if ($new_item) 
- {
-       text_row(_("Item Code:"), 'NewStockID', null, 21, 20);
-       $_POST['inactive'] = 0;
- } 
- else 
- { // Must be modifying an existing item
-       if (get_post('NewStockID') != get_post('stock_id')) { // first item display
-               $_POST['NewStockID'] = $_POST['stock_id'];
-               $myrow = get_item($_POST['NewStockID']);
-               $_POST['long_description'] = $myrow["long_description"];
-               $_POST['description'] = $myrow["description"];
-               $_POST['category_id']  = $myrow["category_id"];
-               $_POST['tax_type_id']  = $myrow["tax_type_id"];
-               $_POST['units']  = $myrow["units"];
-               $_POST['mb_flag']  = $myrow["mb_flag"];
-               $_POST['sales_account'] =  $myrow['sales_account'];
-               $_POST['inventory_account'] = $myrow['inventory_account'];
-               $_POST['cogs_account'] = $myrow['cogs_account'];
-               $_POST['adjustment_account']    = $myrow['adjustment_account'];
-               $_POST['assembly_account']      = $myrow['assembly_account'];
-               $_POST['dimension_id']  = $myrow['dimension_id'];
-               $_POST['dimension2_id'] = $myrow['dimension2_id'];
-               $_POST['no_sale']       = $myrow['no_sale'];
-               $_POST['del_image'] = 0;        
-               $_POST['inactive'] = $myrow["inactive"];
-               $_POST['editable'] = $myrow["editable"];
        }
-       label_row(_("Item Code:"),$_POST['NewStockID']);
-       hidden('NewStockID', $_POST['NewStockID']);
-       set_focus('description');
- }
+       $fresh_item = !isset($_POST['NewStockID']) || $new_item 
+               || check_usage($_POST['stock_id'],false);
  
text_row(_("Name:"), 'description', null, 52, 200);
      item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null);
  
textarea_row(_('Description:'), 'long_description', null, 42, 3);
      stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item);
  
stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item);
      stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item);
  
- if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) {
+       check_row(_("Editable description:"), 'editable');
  
-       $category_record = get_item_category($_POST['category_id']);
+       check_row(_("Exclude from sales:"), 'no_sale');
  
-       $_POST['tax_type_id'] = $category_record["dflt_tax_type"];
-       $_POST['units'] = $category_record["dflt_units"];
-       $_POST['mb_flag'] = $category_record["dflt_mb_flag"];
-       $_POST['inventory_account'] = $category_record["dflt_inventory_act"];
-       $_POST['cogs_account'] = $category_record["dflt_cogs_act"];
-       $_POST['sales_account'] = $category_record["dflt_sales_act"];
-       $_POST['adjustment_account'] = $category_record["dflt_adjustment_act"];
-       $_POST['assembly_account'] = $category_record["dflt_assembly_act"];
-       $_POST['dimension_id'] = $category_record["dflt_dim1"];
-       $_POST['dimension2_id'] = $category_record["dflt_dim2"];
-       $_POST['no_sale'] = $category_record["dflt_no_sale"];
-       $_POST['editable'] = 0;
+       table_section(2);
  
- }
- $fresh_item = !isset($_POST['NewStockID']) || $new_item 
-       || check_usage($_POST['stock_id'],false);
+       $dim = get_company_pref('use_dimension');
+       if ($dim >= 1)
+       {
+               table_section_title(_("Dimensions"));
+               dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
+               if ($dim > 1)
+                       dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
+       }
+       if ($dim < 1)
+               hidden('dimension_id', 0);
+       if ($dim < 2)
+               hidden('dimension2_id', 0);
+       table_section_title(_("GL Accounts"));
  
item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null);
      gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
  
- stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item);
+       if (!is_service($_POST['mb_flag'])) 
+       {
+               gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
+               gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
+               gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
+       }
+       else 
+       {
+               gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
+               hidden('inventory_account', $_POST['inventory_account']);
+               hidden('adjustment_account', $_POST['adjustment_account']);
+       }
  
- stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item);
  
- check_row(_("Editable description:"), 'editable');
+       if (is_manufactured($_POST['mb_flag']))
+               gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'assembly_account', $_POST['assembly_account']);
+       else
+               hidden('assembly_account', $_POST['assembly_account']);
  
check_row(_("Exclude from sales:"), 'no_sale');
      table_section_title(_("Other"));
  
- table_section(2);
+       // Add image upload for New Item  - by Joe
+       file_row(_("Image File (.jpg)") . ":", 'pic', 'pic');
+       // Add Image upload for New Item  - by Joe
+       $stock_img_link = "";
+       $check_remove_image = false;
+       if (isset($_POST['NewStockID']) && file_exists(company_path().'/images/'
+               .item_img_name($_POST['NewStockID']).".jpg")) 
+       {
+        // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D.
+               $stock_img_link .= "<img id='item_img' alt = '[".$_POST['NewStockID'].".jpg".
+                       "]' src='".company_path().'/images/'.item_img_name($_POST['NewStockID']).
+                       ".jpg?nocache=".rand()."'"." height='$pic_height' border='0'>";
+               $check_remove_image = true;
+       } 
+       else 
+       {
+               $stock_img_link .= _("No image");
+       }
  
- $dim = get_company_pref('use_dimension');
- if ($dim >= 1)
- {
-       table_section_title(_("Dimensions"));
+       label_row("&nbsp;", $stock_img_link);
+       if ($check_remove_image)
+               check_row(_("Delete Image:"), 'del_image');
+       record_status_list_row(_("Item status:"), 'inactive');
+       end_outer_table(1);
+       div_start('controls');
+       if (!isset($_POST['NewStockID']) || $new_item) 
+       {
+               submit_center('addupdate', _("Insert New Item"), true, '', 'default');
+       } 
+       else 
+       {
+               submit_center_first('addupdate', _("Update Item"), '', 
+                       @$_REQUEST['popup'] ? true : 'default');
+               submit_return('select', get_post('stock_id'), 
+                       _("Select this items and return to document entry."), 'default');
+               submit('clone', _("Clone This Item"), true, '', true);
+               submit('delete', _("Delete This Item"), true, '', true);
+               submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
+       }
  
-       dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
-       if ($dim > 1)
-               dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
+       div_end();
  }
- if ($dim < 1)
-       hidden('dimension_id', 0);
- if ($dim < 2)
-       hidden('dimension2_id', 0);
  
- table_section_title(_("GL Accounts"));
+ //-------------------------------------------------------------------------------------------- 
  
gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
start_form(true);
  
- if (!is_service($_POST['mb_flag'])) 
+ if (db_has_stock_items()) 
  {
-       gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
-       gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
-       gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
+       start_table(TABLESTYLE_NOBORDER);
+       start_row();
+     stock_items_list_cells(_("Select an item:"), 'stock_id', null,
+         _('New item'), true, check_value('show_inactive'));
+       $new_item = get_post('stock_id')=='';
+       check_cells(_("Show inactive:"), 'show_inactive', null, true);
+       end_row();
+       end_table();
+       if (get_post('_show_inactive_update')) {
+               $Ajax->activate('stock_id');
+               set_focus('stock_id');
+       }
  }
- else 
+ else
  {
-       gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
-       hidden('inventory_account', $_POST['inventory_account']);
-       hidden('adjustment_account', $_POST['adjustment_account']);
+       hidden('stock_id', get_post('stock_id'));
  }
  
+ div_start('details');
  
- if (is_manufactured($_POST['mb_flag']))
-       gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'assembly_account', $_POST['assembly_account']);
- else
-       hidden('assembly_account', $_POST['assembly_account']);
- table_section_title(_("Other"));
- // Add image upload for New Item  - by Joe
- file_row(_("Image File (.jpg)") . ":", 'pic', 'pic');
- // Add Image upload for New Item  - by Joe
- $stock_img_link = "";
- $check_remove_image = false;
- if (isset($_POST['NewStockID']) && file_exists(company_path().'/images/'
-       .item_img_name($_POST['NewStockID']).".jpg")) 
- {
-  // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D.
-       $stock_img_link .= "<img id='item_img' alt = '[".$_POST['NewStockID'].".jpg".
-               "]' src='".company_path().'/images/'.item_img_name($_POST['NewStockID']).
-               ".jpg?nocache=".rand()."'"." height='$pic_height' border='0'>";
-       $check_remove_image = true;
- } 
- else 
- {
-       $stock_img_link .= _("No image");
- }
+ $stock_id = get_post('stock_id');
+ if (!$stock_id)
+       unset($_POST['_tabs_sel']); // force settings tab for new customer
  
- label_row("&nbsp;", $stock_img_link);
- if ($check_remove_image)
-       check_row(_("Delete Image:"), 'del_image');
+ tabbed_content_start('tabs', array(
+               'settings' => array(_('&General settings'), $stock_id),
+               'movement' => array(_('&Transactions'), $stock_id),
+               'status' => array(_('&Status'), $stock_id),
+       ));
        
- record_status_list_row(_("Item status:"), 'inactive');
- end_outer_table(1);
- div_end();
- div_start('controls');
- if (!isset($_POST['NewStockID']) || $new_item) 
- {
-       submit_center('addupdate', _("Insert New Item"), true, '', 'default');
- } 
- else 
- {
-       submit_center_first('addupdate', _("Update Item"), '', 
-               @$_REQUEST['popup'] ? true : 'default');
-       submit_return('select', get_post('stock_id'), 
-               _("Select this items and return to document entry."), 'default');
-       submit('clone', _("Clone This Item"), true, '', true);
-       submit('delete', _("Delete This Item"), true, '', true);
      submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
- }
+       switch (get_post('_tabs_sel')) {
+               default:
+               case 'settings':
+                       item_settings($stock_id); 
+                       break;
+               case 'movement':
+                       $_GET['stock_id'] = $stock_id;
+                       $_GET['popup'] = 1;
+                       include_once($path_to_root."/inventory/inquiry/stock_movements.php");
+                       break;
+               case 'status':
+                       $_GET['stock_id'] = $stock_id;
+                       $_GET['popup'] = 1;
+                       include_once($path_to_root."/inventory/inquiry/stock_status.php");
+                       break;
+       };
br();
+ tabbed_content_end();
  
  div_end();
 -
  hidden('popup', @$_REQUEST['popup']);
  end_form();
  
index 28167da7da3c9b7a43354280431229af03b06b49,ca2f4a86883b5d213f556cc460a5c738b3b41275..8b7f7f7db36c82d2ef12b505807a5f3b295743b9
@@@ -68,7 -70,14 +70,14 @@@ function add_work_order_issue($woid, $r
                $issue_cost = $standard_cost * $item->quantity;
                $issue = get_stock_gl_code($item->stock_id);
          $stockitem = get_item($item->stock_id);
-         $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"], 0, 0,
 -              
++
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
+                       $ivaccount = $issue["cogs_account"];            
 -              
++
+         $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
                  $date_.": "._("Issue of")." ".$stockitem["description"], -$issue_cost);                       
                $issue_total += $issue_cost;
        }       
@@@ -156,18 -166,63 +166,63 @@@ function void_work_order_issue($type_no
  {
        begin_transaction();
        hook_db_prevoid(ST_MANUISSUE, $type_no);
 -      
 +
+       //Chaitanya : Skip processing already voided entry i.e. explicitly voided
+       $void_entry = get_voided_entry(ST_MANUISSUE, $type_no);
+       if ($void_entry)
+               return;
        // void the actual issue items and their quantities
        $sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id="
                .db_escape($type_no);
        db_query($sql,"A work order issue item could not be voided");
  
-       // void all related stock moves
-       void_stock_move(ST_MANUISSUE, $type_no);
        // void any related gl trans
-       void_gl_trans(ST_MANUISSUE, $type_no, true);
+       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO
+       //void_gl_trans(ST_MANUISSUE, $type_no, true);
+       
+       //Chaitanya : Reverse the gl posting
+       $issue = get_work_order_issue($type_no);
+       $manf_stock_id = $issue["stock_id"];
+       $date_ = sql2date($issue["issue_date"]);
+       $woid = $issue["workorder_id"];
 -              
++
+       $result = get_stock_moves(ST_MANUISSUE, $type_no);
+       $total_cost = 0;
+       $issue_total = 0;
+       while ($myrow = db_fetch($result))
+       {
+               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];
+               $issue = get_stock_gl_code($myrow["stock_id"]);
+         $stockitem = get_item($myrow["stock_id"]);
 -              
++
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
 -                      $ivaccount = $issue["cogs_account"];            
 -              
++                      $ivaccount = $issue["cogs_account"];
++
+               if ($issue_cost != 0)
+               {
+                       $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
+                               $date_.": "._("Reversed the issue of")." ".$stockitem["description"],
 -                              -$issue_cost);                  
++                              -$issue_cost);
+                       $issue_total += $issue_cost;
+               }
+       }
+       if ($issue_total != 0)
+               //Chaitanya : Revese cost effect on manfactured stock item as adjustment only
+               add_issue_cost($manf_stock_id, 0, $date_, $issue_total, true);
+       $issue = get_stock_gl_code($manf_stock_id);
+     $stockitem = get_item($manf_stock_id);
+       if ($total_cost != 0)
+               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],
+                       0, 0, $date_.": "._("Reversed the issue to")." ".$stockitem["description"], 
+                       -$total_cost);  
 -      
++
+       //Chaitanya : Shifted below void all related stock moves
+       void_stock_move(ST_MANUISSUE, $type_no);
 -      
 +
        commit_transaction();
  }
  
index 9b2095c076141fdce58e949a8ab2c5ed1999d4d7,38af2add9b98efd04427682b1d22abdcb67aa694..dcac240cb831ba4020f5b989cac60b7672c86a85
@@@ -48,8 -48,18 +48,17 @@@ function work_order_produce($woid, $ref
        // -------------------------------------------------------------------------
  
        work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, $id);
 -      
        // -------------------------------------------------------------------------
 -      }       
+       // Chaitanya: stamp BOM cost to finished item
+       $m_cost = 0;
+     $result = get_bom($details["stock_id"]);
+       while ($bom_item = db_fetch($result))
+       {
+               $standard_cost = get_standard_cost($bom_item['component']);
+               $m_cost += ($bom_item['quantity'] * $standard_cost);
++      }
        // insert a +ve stock move for the item being manufactured
        // negative means "unproduce" or unassemble
        add_stock_move(ST_MANURECEIVE, $details["stock_id"], $id,
@@@ -109,18 -118,53 +117,52 @@@ function void_work_order_produce($type_
  {
        begin_transaction();
        hook_db_prevoid(ST_MANURECEIVE, $type_no);
 -      
 +
+       //Chaitanya : Skip processing already voided entry i.e. explicitly voided
+       $void_entry = get_voided_entry(ST_MANURECEIVE, $type_no);
+       if ($void_entry)
+               return; 
        $row = get_work_order_produce($type_no);
  
        // deduct the quantity of this production from the parent work order
        work_order_update_finished_quantity($row["workorder_id"], -$row["quantity"]);
  
-       work_order_quick_costs($row['workorder_id'], $row['stock_id'], -$row['quantity'], sql2date($row['date_']), $type_no);
+       //Chaitanya : skipped this step as BOM may have got changed
+       //work_order_quick_costs($row['workorder_id'], $row['stock_id'], -$row['quantity'], sql2date($row['date_']), $type_no);
  
 -              
+       // void any related gl trans
+       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO
+       //void_gl_trans(ST_MANURECEIVE, $type_no, true);
+       
+       $woid = $row["workorder_id"];
+       $date_ = sql2date($row["date_"]);
+               
+       $result = get_stock_moves(ST_MANURECEIVE, $type_no);
+       while ($myrow = db_fetch($result))
+       {
+               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];
+               $issue = get_stock_gl_code($myrow["stock_id"]);
+         $stockitem = get_item($myrow["stock_id"]);
 -                      $ivaccount = $issue["cogs_account"];            
 -              
++
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
 -      }       
 -                      
++                      $ivaccount = $issue["cogs_account"];
++
+               if ($issue_cost != 0)
+               {
+                       add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
+                               $date_.": "._("Reversed the production ")." ".$stockitem["description"],
+                               -$issue_cost);
+               }
++      }
        // clear the production record
        $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".db_escape($type_no);
 -      db_query($sql, "Cannot void a wo production");                  
 -      
 +      db_query($sql, "Cannot void a wo production");
 +
+       //Chaitanya : Shifted below
        // void all related stock moves
        void_stock_move(ST_MANURECEIVE, $type_no);
  
index e63aae816441fc0e0f7852c7117aee8bb5ef66f0,2aed7c1912876680a39523f78f77e181dc342497..eb31056809b6c4f81d88bc4b8b9faacfbce5ed2c
@@@ -173,7 -370,7 +173,7 @@@ function release_work_order($woid, $rel
        create_wo_requirements($woid, $stock_id);
  
        add_comments(ST_WORKORDER, $woid, $releaseDate, $memo_);
-       add_audit_trail(ST_WORKORDER, $woid, $myrow['date_'], _("Released."));
 -      add_audit_trail(ST_WORKORDER, $woid, $releaseDate,_("Released."));
++      add_audit_trail(ST_WORKORDER, $woid, sql2date($myrow['date_']), _("Released."));
  
        commit_transaction();
  }
index 5654caeb3d70ad07c38a6e616a98b0a5b2c42844,9b869d0a1b935d6a94372450e139c3d02c110084..bcf9688f0ef015e1d5270a564042ed5b91c95664
@@@ -116,15 -134,26 +116,16 @@@ function work_order_quick_costs($woid, 
                        $memo = $date_.": ".$memo; 
                        update_wo_requirement_issued($woid, $bom_item['component'], $bom_item["quantity"] * $units_reqd);                       
                        // insert a -ve stock move for each item
 -                      // Chaitanya: Updated to record price and cost as std_cost for work order issued item
 -                      $UnitCost = get_standard_cost($bom_item["component"]);                  
                        add_stock_move(ST_MANURECEIVE, $bom_item["component"], $advanced,
 -                              $bom_item["loc_code"], $date_, "", -$bom_item["quantity"] * $units_reqd, $UnitCost, 0, 1, $UnitCost);
 +                              $bom_item["loc_code"], $date_, "", -$bom_item["quantity"] * $units_reqd, 0);
                }
 -              
 -              //Chaitanya : Compatibility for Service Items
 -              if (!is_service($bom_accounts["mb_flag"]))
 -                      $ivaccount = $bom_accounts["inventory_account"];
 -              else
 -                      $ivaccount = $bom_accounts["cogs_account"];
 -              $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
 +              $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $bom_accounts["inventory_account"], 0, 0,
                        $memo, -$bom_cost);
 -              $total_material_cost += $bom_cost;
 +
        }
++      $item_accounts = get_stock_gl_code($stock_id);
        if ($advanced)
        {
 -              //Chaitanya: Material cost added at time of production as per BOM at the time and in adjustment mode.
 -              add_material_cost($stock_id, $units_reqd, $date_, true);        
 -      
                $wo = get_work_order($woid);
                // also take the additional issues
                // moved to work_order_issues_db.inc
                $lcost = get_gl_wo_cost($woid, WO_LABOUR);
                add_labour_cost($stock_id, $units_reqd, $date_, $lcost * $units_reqd / $wo['units_reqd']);
                $ocost = get_gl_wo_cost($woid, WO_OVERHEAD);
 -              add_overhead_cost($stock_id, $units_reqd, $date_, $ocost * $units_reqd / $wo['units_reqd']); */
 -      }
 -      // credit additional costs
 -      $item_accounts = get_stock_gl_code($stock_id);
 -      if ($costs != 0.0)
 -      {
 -              add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_acc,
 -                      0, 0, $wo_cost_types[WO_OVERHEAD], -$costs, PT_WORKORDER, WO_OVERHEAD);
 -              $is_bank_to = is_bank_account($cr_acc);
 -      if ($is_bank_to)
 -      {
 -              add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
 -                      $date_, -$costs, PT_WORKORDER, WO_OVERHEAD, get_company_currency(),
 -                      "Cannot insert a destination bank transaction");
 -      }
 -                      
 -              add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
 -                      $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_OVERHEAD], $costs, 
 -                      PT_WORKORDER, WO_OVERHEAD);
 -      }
 -      if ($labour != 0.0)
 -      {
 -              add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_lab_acc,
 -                      0, 0, $wo_cost_types[WO_LABOUR], -$labour, PT_WORKORDER, WO_LABOUR);
 -              $is_bank_to = is_bank_account($cr_lab_acc);
 -      if ($is_bank_to)
 -      {
 -              add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
 -                      $date_, -$labour, PT_WORKORDER, WO_LABOUR, get_company_currency(),
 -                      "Cannot insert a destination bank transaction");
 -      }
 -                      
 -              add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
 -                      $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_LABOUR], $labour, 
 -                      PT_WORKORDER, WO_LABOUR);
 +              add_overhead_cost($stock_id, $units_reqd, $date_, $ocost * $units_reqd / $wo['units_reqd']);
 +
 +      } else { // only for quick
 +              // credit additional costs
-               $item_accounts = get_stock_gl_code($stock_id);
 +
 +              if ($costs != 0.0)
 +              {
 +                      add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $item_accounts["assembly_account"],
 +                              $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
 +              }
 +              if ($labour != 0.0) // only for quick
 +              {
 +                      add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $item_accounts["assembly_account"],
 +                              $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
 +              }
        }
        // debit total components $total_cost
        $stockitem = get_item($stock_id);
Simple merge
index 77863d2767043a15d258244c22625233365a54cf,c7d1cd7cc5d43b15b14f31652f880f078e541d01..b5d6e4cc1f0058d6d264f1780b6039a1154fbcaf
@@@ -64,9 -62,9 +64,7 @@@ function handle_new_order(
                unset ($_SESSION['issue_items']);
        }
  
--     Session_register("issue_items");
--
-      $_SESSION['issue_items'] = new items_cart(28);
+      $_SESSION['issue_items'] = new items_cart(ST_MANUISSUE);
       $_SESSION['issue_items']->order_id = $_GET['trans_no'];
  }
  
index d1c35452b4bcb20eddd897a7e54c30c031eaa290,a31bc2ec83665bc9ebe9ff0a3dcfa47c7f96889f..00e088e0fbc489aa884ac5216080e0fa79c139b5
  //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
  function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, $adj_only=false)
  {
 -    //8-OCT-2011 : Skip negative inventory adjustment for case of adjust_only\r
 -    if (is_inventory_item($stock_id) && !$adj_only) \r
+       //Handle if inventory will become negative
++    //8-OCT-2011 : Skip negative inventory adjustment for case of adjust_only
++    if (is_inventory_item($stock_id) && !$adj_only)
+         handle_negative_inventory($stock_id, $qty, $price, $date);    
        // probably this function should be optimized
        // passing transaction cart as argument. This would
        // save a couple of db calls like get_supplier()
        }       
        else
                $price_in_home_currency = $price;
-       $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
 -      
++
+       $price_in_home_currency_ = $price_in_home_currency;
+       
+       $sql = "SELECT mb_flag, material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
        $result = db_query($sql);
        $myrow = db_fetch($result);
        $material_cost = $myrow['material_cost'];
-       if ($price > -0.0001 && $price < 0.0001)
-               return $material_cost;
+       
 -      //Price adjustment for manufactured item\r
 -      if (!$adj_only && $myrow['mb_flag'] == 'M') \r
++      //Price adjustment for manufactured item
++      if (!$adj_only && $myrow['mb_flag'] == 'M') 
+       {
+               $standard_cost = get_standard_cost($stock_id);
+               //reduce overhead_cost and labour_cost from price as those will remain as is
+               $price_in_home_currency = $price_in_home_currency - $myrow['labour_cost'] - $myrow['overhead_cost'];
+       }
 -      
++
        if ($adj_only)
                $exclude = ST_CUSTDELIVERY;
        else
                $exclude = 0;
        $cost_adjust = false;
-       //$qoh = get_qoh_on_date($stock_id, null, $date, $exclude);
++
        $qoh = get_qoh_on_date($stock_id);
-       
        if ($adj_only)
        {
                if ($qoh > 0)
                                $cost_adjust = true;
                        $qoh = 0;
                }
-               if ($qoh + $qty != 0)
+               if ($qoh + $qty > 0)
 -                      $material_cost 
 -= ($qoh * $material_cost + $qty * $price_in_home_currency) /  ($qoh + $qty);
 -      }       
 -      
 +                      $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) /     ($qoh + $qty);
-       }       
-       //$material_cost = round2($material_cost, $dec);
-       
-       if ($cost_adjust) // new 2010-02-10
-               adjust_deliveries($stock_id, $material_cost, $date);
++      }
++
+       if ($cost_adjust) // new 2010-02-10 //Chaitanya : Material_cost replaced with price
+               adjust_deliveries($stock_id, $price_in_home_currency_, $date);
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
                WHERE stock_id=".db_escape($stock_id);
        db_query($sql,"The cost details for the inventory item could not be updated");
@@@ -106,10 -117,10 +117,10 @@@ function add_grn(&$po
                                if ($clearing_act)
                                        $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $stock_gl_code["inventory_account"],
                                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
-                                               $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id);
 -                                              $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id, '', 0, $order_line->stock_id);\r
 -                              update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,\r
++                                              $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id, '', 0, $order_line->stock_id);
 +                              update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
                                        $order_line->receive_qty, $date_);
--                      }               
++                      }
                        //----------------------------------------------------------------------------------------------------------------
                        if ($order_line->qty_received == 0)
                        {
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts done automatically */
                        add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
                                $order_line->receive_qty, $order_line->standard_cost,
-                       $po->supplier_id, 1, $order_line->price);
 -                      $po->supplier_id, 1, $order_line->taxfree_charge_price($po));\r
++                      $po->supplier_id, 1, $order_line->taxfree_charge_price($po));
  
                } /*quantity received is != 0 */
        } /*end of order_line loop */
index 33cfd8710fd31f0c8cc4d263f0513492fef4380c,3ffc35d3abc23a8ac628a5a5f2f9074bb51f1096..0f7f9b53d01d7365c32166de61407e4ffc74573c
@@@ -50,16 -38,26 +50,19 @@@ function read_supplier_details_to_trans
                'description' => $myrow['terms'],
                'days_before_due' => $myrow['days_before_due'], 
                'day_in_following_month' => $myrow['day_in_following_month'] );
--              
++
        $supp_trans->credit = $myrow['cur_credit'];
  
        $supp_trans->tax_description = $myrow['tax_group_name'];
        $supp_trans->tax_group_id = $myrow['tax_group_id'];
  
 -    if ($supp_trans->tran_date == "")
 -    {
 -              $supp_trans->tran_date = Today();
 -              if (!is_date_in_fiscalyear($supp_trans->tran_date))
 -                      $supp_trans->tran_date = end_fiscalyear();
 -      }
 -    //if ($supp_trans->due_date=="") {
 -    //        get_duedate_from_terms($supp_trans);
 -    //}
 -    get_duedate_from_terms($supp_trans);
  }
  
--//--------------------------------------------------------------------------------------------------
--
++//-------------------------------------------------------------------------------------------------
++//    Updates invoiced quantity in PO and GRN line, and act_price in PO
++//  Returns:
++// if chg_price is set:        previous act_price, delivery date and unit_price from PO
++//
  function update_supp_received_items_for_invoice($id, $po_detail_item, $qty_invoiced, $chg_price=null)
  {
        if ($chg_price != null)
@@@ -146,10 -138,13 +149,10 @@@ function add_supp_invoice(&$supp_trans
                $item_added_tax = $tax_total;
        } else {
                $item_added_tax = 0;
 -              
        }
  
 -      $trans_type = $supp_trans->trans_type;
 -      
        if ($trans_type == ST_SUPPCREDIT)
-       { 
+       {
                // let's negate everything because it's a credit note
                $invoice_items_total = -$invoice_items_total;
                $tax_total = -$tax_total;
                                        $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
                                        $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate);
                                $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, 
-                                       $entered_grn->chg_price);       
-                       
+                                       $line_taxfree); 
 -                      
++
                                // 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); */
                                $mat_cost = update_average_material_cost(null, $entered_grn->item_code,
                                        $diff, $entered_grn->this_quantity_inv, null, true);
                                
                                $taxitem['tax_type_id'], $taxitem['rate'], $supp_trans->tax_included, $taxitem['Value'],
                                $taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference);
  
--              if ($trans_type == ST_SUPPCREDIT)
--                      $taxitem['Value'] = -$taxitem['Value'];
--              $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");
++                      if (isset($taxitem['purchasing_gl_code']))
++                      {
++                      if ($trans_type == ST_SUPPCREDIT)
++                              $taxitem['Value'] = -$taxitem['Value'];
++                      $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");
++                      }
        }
      }
        
@@@ -508,14 -548,18 +568,17 @@@ function void_supp_invoice($type, $type
                                $batch = get_grn_batch_from_item($details_row["grn_item_id"]);  
                                $grn = get_grn_batch($batch);
                        if ($type == ST_SUPPCREDIT) // 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)
 -                                      
+                                       //Chaitanya : Skipped costing block & handle in void_stock_move
+                                       // We must get the corresponding invoice item to check for price chg.
+                                       /*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']);
+                                                       $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"].", ";
                                if ($match !== false)
@@@ -576,62 -652,47 +671,66 @@@ function is_reference_already_there($su
  
  function remove_not_invoice_item($id)
  {
 -    begin_transaction();
 +      begin_transaction();
  
-       $myrow = get_grn_item_detail($id);
+     $myrow = get_grn_item_detail($id);
  
-       $grn = get_grn_batch($myrow['grn_batch_id']);
+     $grn = get_grn_batch($myrow['grn_batch_id']);
 -    
++
+     $supp = get_supplier($grn["supplier_id"]);
  
 -    $sql = "UPDATE ".TB_PREF."purch_order_details
 -        SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
 -    db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
 +      $sql = "UPDATE ".TB_PREF."purch_order_details
 +              SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
 +      db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
  
-       $sql = "UPDATE ".TB_PREF."grn_items
-               SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
-       db_query($sql, "The quantity invoiced off the items received record could not be updated");
-       update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
-               $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
-       add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
-               -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
-               
+     $sql = "UPDATE ".TB_PREF."grn_items
+         SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
+     db_query($sql, "The quantity invoiced off the items received record could not be updated");
+     update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
+         $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
+         
+     $price = $myrow['unit_price'];
+     if ($supp['tax_included'])
+         $price = get_tax_free_price_for_item($myrow['item_code'], $myrow['unit_price'], $supp['tax_group_id'], $supp['tax_included']);        
+     add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+         -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $price);
+         
      $clearing_act = get_company_pref('grn_clearing_act');
-       if ($clearing_act) {    // otherwise GRN clearing account is not used
-               if (is_inventory_item($myrow['item_code']))
-               {
-               $total = 0;
-                       $stock_gl_code = get_stock_gl_code($myrow['item_code']);
-                       $date = sql2date($grn["delivery_date"]);
-                       $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $stock_gl_code["inventory_account"],
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
-                               -$myrow['QtyOstdg'] * $myrow['unit_price'], $grn["supplier_id"], "", 0, _("GRN Removal"));
-                       $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $clearing_act,
-                               0, 0, -$total, null, "", 0, _("GRN Removal"));
-               }       
-       }
+     if ($clearing_act) {    // otherwise GRN clearing account is not used
+         if (is_inventory_item($myrow['item_code']))
+         {
+             $total = 0;
+             $stock_gl_code = get_stock_gl_code($myrow['item_code']);
+             $date = sql2date($grn["delivery_date"]);
+             $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $stock_gl_code["inventory_account"],
+                 $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+                 -$myrow['QtyOstdg'] * $price, $grn["supplier_id"], "", 0, _("GRN Removal"));
+             $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $clearing_act,
+                 0, 0, -$total, null, "", 0, _("GRN Removal"));
+         }    
+     }
  
-       commit_transaction();
+     commit_transaction();
  }
 -?>
 +
 +function find_src_invoices($cart)
 +{
 +      $invoices = $po_ids = array();
 +      foreach($cart->grn_items as $item)
 +              $po_ids[] = "'$item->po_detail_item'";  // credit item lines
 +
 +      if (count($po_ids)) {
 +              $sql = "SELECT DISTINCT trans.trans_no, trans.reference, trans.supp_reference
 +                      FROM ".TB_PREF."supp_invoice_items items
 +                      LEFT JOIN ".TB_PREF."supp_trans trans ON trans.trans_no=items.supp_trans_no AND trans.`type`=items.supp_trans_type
 +                      WHERE items.po_detail_item_id IN (" . implode(',', $po_ids). ")"." AND items.supp_trans_type=20";
 +              $result = db_query($sql, "cannot find source invoice details");
 +              while ($rec = db_fetch($result))
 +              {
 +                      $invoices[$rec['trans_no']] = $rec['supp_reference']; // array($rec['reference'], $rec['supp_reference']);
 +              }
 +      }
 +      return $invoices;
 +}
- ?>
index fd34fef16f0d605fec0b63dd2018b66972206f0e,e841d5e8caa34208d56c97069d823a5e096939f1..45810f1da0b9050b430457a06aaf3f0d64cb0370
@@@ -105,8 -105,9 +105,8 @@@ function update_po(&$po_obj
                        .db_escape($po_line->item_description). ",'"
                        .date2sql($po_line->req_del_date) . "',"
                        .db_escape($po_line->price) . ", "
-                       .db_escape($po_line->quantity) . ")";
+                       .db_escape($po_line->quantity) . ", "
+                       .db_escape($po_line->qty_received) . ")";
 -              
                db_query($sql, "One of the purchase order detail records could not be updated");
      }
  
@@@ -140,9 -140,9 +140,9 @@@ function read_po_header($order_no, &$or
  
                $order->trans_type = ST_PURCHORDER;
                $order->order_no = $order_no;
--              
++
                $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
 -                      $myrow['tax_group_id'], $myrow["tax_included"]);
 +                      $myrow['tax_group_id'], $myrow["tax_included"], @$myrow["tax_algorithm"]);
  
                $order->credit = get_current_supp_credit($order->supplier_id);
  
index f9eed1a86c0a9caf6decb11fc4d9c8dd4f1e1429,535e66c5a0208a3b79a44cc50e0447da8e51c1c3..6091e42e9092901d9ba2b50ffd990be80c126281
@@@ -173,9 -169,32 +169,33 @@@ function get_allocatable_to_supp_transa
                        AND trans.supplier_id=".db_escape($supplier_id));
        }
  
-       return db_query($sql." ORDER BY trans_no", "Cannot retreive alloc to transactions");
+       return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions");
+ }
+ //-------------------------------------------------------------------------------------------------------------
+ function get_allocatable_from_supp_transactions($supplier_id, $trans_no=null, $type=null)
+ {
+       if ($trans_no != null && $type!= null)
+       {
+               $sql = get_alloc_supp_sql("amt, supp_reference", "trans.trans_no = alloc.trans_no_from
+                       AND trans.type = alloc.trans_type_from
+                       AND alloc.trans_no_to=".db_escape($trans_no)."
+                       AND alloc.trans_type_to=".db_escape($type)."
+                       AND trans.supplier_id=".db_escape($supplier_id),
+                       TB_PREF."supp_allocations as alloc");
+       }
+       else
+       {
+               $sql = get_alloc_supp_sql(null, "round(ABS(ov_amount+ov_gst+ov_discount)-alloc,6) > 0
+                       AND trans.type != ".ST_SUPPAYMENT."
+                       AND trans.supplier_id=".db_escape($supplier_id));
+       }
+       return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions");
  }
  
++
  function get_sql_for_supplier_allocation_inquiry()
  {
        $date_after = date2sql($_POST['TransAfterDate']);
index 04228e9d5a721dd5fc5a12fc22421d0662fb6cee,dd9e49c906fa3cbb4689ba5e95e2387d368555e3..61cf2bdce8a8194ab8e4bdda72024cbffa38679d
@@@ -116,8 -120,8 +122,7 @@@ function get_supplier_details($supplier
                          ".TB_PREF."payment_terms.terms,
                          ".TB_PREF."payment_terms.days_before_due,
                          ".TB_PREF."payment_terms.day_in_following_month";
--
-     $result = db_query($sql,"The supplier details could not be retrieved");
+     $result = db_query($sql,"The customer details could not be retrieved");
      $supp = db_fetch($result);
  
      return $supp;
@@@ -175,12 -179,4 +180,10 @@@ function is_new_supplier($id
  
        return !key_in_foreign_table($id, $tables, 'supplier_id');
  }
 -?>
 +
 +function update_supp_tax_algorithm($supplier_id, $tax_algorithm)
 +{
 +      $sql = "UPDATE ".TB_PREF."suppliers SET tax_algorithm=".db_escape($tax_algorithm)
 +              . " WHERE supplier_id=".db_escape($supplier_id);
 +      return db_query($sql, "cannot update supplier's tax calculation algorithm");
 +}
- ?>
index 840569271349a309d4a6184fcedf351417bd8a98,b767e9ea9261f66e9ee64245c4f9067bae4bd475..c9ec00df2f32362d5ca993b480c1e699026266f4
@@@ -144,7 -141,8 +144,8 @@@ class purch_orde
                        $prices[] = round($ln_itm->price * ($receival ? $ln_itm->receive_qty : $ln_itm->quantity),  user_price_dec());
                }
                $taxes = get_tax_for_items($items, $prices, $shipping_cost,
 -                $this->tax_group_id, $this->tax_included,  $this->tax_group_array);
 +                $this->tax_group_id, $this->tax_included,  $this->tax_group_array, $this->tax_algorithm);
        // Adjustment for swiss franken, we always have 5 rappen = 1/20 franken
            if ($this->curr_code == 'CHF') {
                        $val = $taxes['1']['Value'];
index 60e5b7edadb00c95c402d96594d0c82f2e1af7fc,130354d7142516a28303246d7f4e9cf7fd2da9da..8178d30d1094affee1bf159c88b1058ebdbe7f8f
@@@ -42,30 -40,13 +42,31 @@@ class supp_tran
        var $ov_gst;
        var $gl_codes_counter=0;
        var $credit = 0;
 +      var $tax_algorithm;
 +      var $stored_algorithm;
 +      var $currency;
  
 -      function supp_trans($trans_type)
 +      function supp_trans($trans_type, $trans_no=0)
        {
+               $this->trans_type = $trans_type;
                /*Constructor function initialises a new Supplier Transaction object */
 -              $this->grn_items = array();
 -              $this->gl_codes = array();
 +              $this->read($trans_type, $trans_no);
 +      }
 +
 +      function read($trans_type, $trans_no)
 +      {
 +              $this->trans_type = $trans_type;
 +              $this->trans_no = $trans_no;
 +              $this->grn_items = array();
 +              $this->gl_codes = array();
 +              if ($trans_no) {
 +                      read_supp_invoice($trans_no, $trans_type, $this);
 +                      if ($trans_type == ST_SUPPCREDIT)
 +                      {
 +                              $this->src_docs = find_src_invoices($trans_no);
 +                      }
 +                      read_supplier_details_to_trans($this, $this->supplier_id);
 +              }
        }
  
        function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description, 
Simple merge
Simple merge
index ba77bf7a91222026e43ef12ea5b15f57192fb59e,9925ac6399a393387a286074b120a8e11c0e1492..90d869aa907acbe5cf0452e0e4047e293b59913b
  ***********************************************************************/
  $page_security = 'SA_SUPPTRANSVIEW';
  $path_to_root="../..";
- include($path_to_root . "/includes/db_pager.inc");
- include($path_to_root . "/includes/session.inc");
+ include_once($path_to_root . "/includes/db_pager.inc");
+ include_once($path_to_root . "/includes/session.inc");
  
- include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
+ include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
  include_once($path_to_root . "/reporting/includes/reporting.inc");
 -if (!@$_GET['popup'])
 -{
 -      $js = "";
 -      if ($use_popup_windows)
 -              $js .= get_js_open_window(900, 500);
 -      if ($use_date_picker)
 -              $js .= get_js_date_picker();
 -      page(_($help_context = "Search Purchase Orders"), false, false, "", $js);
 -}
 +$js = "";
 +if ($use_popup_windows)
 +      $js .= get_js_open_window(900, 500);
 +if ($use_date_picker)
 +      $js .= get_js_date_picker();
 +page(_($help_context = "Search Purchase Orders"), false, false, "", $js);
 +
  if (isset($_GET['order_number']))
  {
        $order_number = $_GET['order_number'];
@@@ -98,9 -101,11 +98,13 @@@ function trans_view($trans
  
  function edit_link($row) 
  {
-   return pager_link( _("Edit"),
-       "/purchasing/po_entry_items.php?" . SID 
-       . "ModifyOrderNumber=" . $row["order_no"], ICON_EDIT);
 -      if (@$_GET['popup'])
++      global $page_nested;
++
++      if ($page_nested)
+               return '';
+       return pager_link( _("Edit"),
+               "/purchasing/po_entry_items.php?" . SID 
+               . "ModifyOrderNumber=" . $row["order_no"], ICON_EDIT);
  }
  
  function prt_link($row)
index 3a341abeef10f1e29e70a25420644afee84975d1,ffb264b523420876cef4ae6fe3ca936e884faa09..af6c2216623c06cd168d7d8cd735143f5dfdfaca
  ***********************************************************************/
  $page_security = 'SA_SUPPTRANSVIEW';
  $path_to_root = "../..";
- include($path_to_root . "/includes/db_pager.inc");
- include($path_to_root . "/includes/session.inc");
+ include_once($path_to_root . "/includes/db_pager.inc");
+ include_once($path_to_root . "/includes/session.inc");
  
- include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
- include($path_to_root . "/reporting/includes/reporting.inc");
+ include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
+ include_once($path_to_root . "/reporting/includes/reporting.inc");
  
 -if (!@$_GET['popup'])
 -{
 -      $js = "";
 -      if ($use_popup_windows)
 -              $js .= get_js_open_window(900, 500);
 -      if ($use_date_picker)
 -              $js .= get_js_date_picker();
 -      page(_($help_context = "Supplier Inquiry"), isset($_GET['supplier_id']), false, "", $js);
 -}
 +$js = "";
 +if ($use_popup_windows)
 +      $js .= get_js_open_window(900, 500);
 +if ($use_date_picker)
 +      $js .= get_js_date_picker();
 +page(_($help_context = "Supplier Inquiry"), isset($_GET['supplier_id']), false, "", $js);
 +
  if (isset($_GET['supplier_id'])){
        $_POST['supplier_id'] = $_GET['supplier_id'];
  }
@@@ -44,7 -47,8 +44,8 @@@ if (!isset($_POST['supplier_id'])
  start_table(TABLESTYLE_NOBORDER);
  start_row();
  
- supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true);
 -if (!@$_GET['popup'])
 -      supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true, false, false, !@$_GET['popup']);
++if (!$page_nested)
++      supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true, false, false, true);
  
  date_cells(_("From:"), 'TransAfterDate', '', null, -30);
  date_cells(_("To:"), 'TransToDate');
@@@ -105,6 -109,6 +106,7 @@@ function systype_name($dummy, $type
        global $systypes_array;
        return $systypes_array[$type];
  }
++div_end();
  
  function trans_view($trans)
  {
@@@ -123,6 -127,8 +125,10 @@@ function gl_view($row
  
  function credit_link($row)
  {
 -      if (@$_GET['popup'])
++      global $page_nested;
++
++      if ($page_nested)
+               return '';
        return $row['type'] == ST_SUPPINVOICE && $row["TotalAmount"] - $row["Allocated"] > 0 ?
                pager_link(_("Credit This"),
                        "/purchasing/supplier_credit.php?New=1&invoice_no=".
@@@ -159,6 -160,6 +160,11 @@@ function check_overdue($row
        return $row['OverDue'] == 1
                && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
  }
++
++function edit_link($row)
++{
++      return edit_trans_link($row['type'], $row['trans_no']);
++}
  //------------------------------------------------------------------------------------------------
  
  $sql = get_sql_for_supplier_inquiry();
@@@ -185,8 -185,8 +191,6 @@@ if ($_POST['supplier_id'] != ALL_TEXT
        $cols[_("Supplier")] = 'skip';
        $cols[_("Currency")] = 'skip';
  }
--//------------------------------------------------------------------------------------------------
--
  
  /*show a table of the transactions returned by the sql */
  $table =& new_db_pager('trans_tbl', $sql, $cols);
index ca34975ea5a96765756e3fc7d5b23441a8c1e690,edfad13a6d9d3021e8f5d3c29a33b5b30a9e87f7..287849ff9d765c980a9fb1d73fa9da04aa6cff6c
@@@ -133,8 -124,13 +130,15 @@@ function supplier_settings(&$supplier_i
        gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account'],
                false, false, _("Use Item Inventory/COGS Account"));
        gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
-       if ($supplier_id) table_section(2);
+       if (!$supplier_id) {
+               table_section_title(_("Contact Data"));
+               text_row(_("Phone Number:"), 'phone', null, 32, 30);
+               text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
++              table_section_title(_("Contact Data"));
++              text_row(_("Fax Number:"), 'fax', null, 32, 30);
++              email_row(_("E-mail:"), 'email', null, 35, 55);
++              languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
+       }
 -
 -      table_section(2);
        $dim = get_company_pref('use_dimension');
        if ($dim >= 1)
        {
                hidden('dimension_id', 0);
        if ($dim < 2)
                hidden('dimension2_id', 0);
++      table_section(2);
  
  
        table_section_title(_("Addresses"));
        textarea_row(_("General Notes:"), 'notes', null, 35, 5);
        if ($supplier_id)
                record_status_list_row(_("Supplier status:"), 'inactive');
 -      else {
 -              table_section_title(_("Contact Data"));
 -              text_row(_("Contact Person:"), 'contact', null, 42, 40);
 -              text_row(_("Fax Number:"), 'fax', null, 32, 30);
 -              email_row(_("E-mail:"), 'email', null, 35, 55);
 -              languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
 -      }
        end_outer_table(1);
  
        div_start('controls');
index 294d4be50a57a3236b5a6977f82f4960c2051b48,a23b7a0754b94603dc9e8e1d22931b4d6df3f337..388eb772158c7449dee682d35dfc5b0d8e91705c
@@@ -330,7 -327,7 +330,7 @@@ function can_commit(
                set_focus('supplier_id');
                return false;
        } 
--      
++
        if (!is_date($_POST['OrderDate'])) 
        {
                display_error(_("The entered order date is invalid."));
                set_focus('due_date');
                return false;
        } 
--      
++
        if (!$_SESSION['PO']->order_no) 
        {
        if (!$Refs->is_valid(get_post('ref'))) 
                        set_focus('ref');
                return false;
        } 
--      
++
        if (!is_new_reference(get_post('ref'), $_SESSION['PO']->trans_type)) 
        {
                display_error(_("The entered reference is already in use."));
                return false;
        }
        }
--      
++
        if ($_SESSION['PO']->trans_type == ST_SUPPINVOICE && !$Refs->is_valid(get_post('supp_ref'))) 
        {
                display_error(_("You must enter a supplier's invoice reference."));
@@@ -446,11 -451,11 +455,12 @@@ function handle_commit_order(
                        $inv->reference = $ref;
                        $inv->supp_reference = $cart->supp_ref;
                        $inv->tax_included = $cart->tax_included;
 +                      $inv->tax_algorithm = $cart->tax_algorithm;
 +                      $inv->stored_algorithm = $cart->stored_algorithm;
                        $supp = get_supplier($cart->supplier_id);
                        $inv->tax_group_id = $supp['tax_group_id'];
 -//                    $inv->ov_discount 'this isn't used at all'
 -                      $inv->ov_amount = $inv->ov_gst = 0;
 -                      
 +                      $total = 0;
++
                        foreach($cart->line_items as $key => $line) {
                                $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id,
                                        $line->item_description, $line->receive_qty, 0, $line->receive_qty,
index 0f75493a3717088b8e2faf09b8bc917dab910ac3,038f50857d60e409647be029c6f4dbfb2ef23e15..e4805768230b53374c9aa4566b118ba7f3e63996
@@@ -30,42 -31,6 +30,42 @@@ if ($use_date_picker
  
  check_db_has_suppliers(_("There are no suppliers defined in the system."));
  
 +if (isset($_GET['ModifyCredit']))
 +      check_is_closed(ST_SUPPINVOICE, $_GET['ModifyCredit']);
 +
 +//---------------------------------------------------------------------------------------------------
 +
 +if (isset($_GET['New']))
 +{
 +      if (isset( $_SESSION['supp_trans']))
 +      {
 +              unset ($_SESSION['supp_trans']->grn_items);
 +              unset ($_SESSION['supp_trans']->gl_codes);
 +              unset ($_SESSION['supp_trans']);
 +      }
 +
 +      if (isset($_GET['invoice_no']))
 +      {
 +              $_SESSION['supp_trans'] = new supp_trans(ST_SUPPINVOICE, $_GET['invoice_no']);
 +              $_SESSION['supp_trans']->src_doc = $_GET['invoice_no'];
 +
 +
 +              $_SESSION['supp_trans']->trans_type = ST_SUPPCREDIT;
 +              $_SESSION['supp_trans']->trans_no = 0;
 +              $_SESSION['supp_trans']->supp_reference = '';
 +              //              $_SESSION['supp_trans']->supp_reference = $_POST['invoice_no'] = $_GET['invoice_no'];
 +              $help_context = "Supplier Credit Note";
 +              $_SESSION['page_title'] = _("Supplier Credit Note");
 +
 +              $_SESSION['supp_trans'] = new supp_trans(ST_SUPPCREDIT);
 +      } elseif (isset($_GET['ModifyInvoice'])) {
 +              $help_context = 'Modifying Purchase Invoice';
 +              $_SESSION['page_title'] = sprintf( _("Modifying Supplier Credit # %d"), $_GET['ModifyCredit']);
 +              $_SESSION['supp_trans'] = new supp_trans(ST_SUPPCREDIT, $_GET['ModifyCredit']);
 +      }
++}
 +page($_SESSION['page_title'], false, false, "", $js);
 +
  //---------------------------------------------------------------------------------------------------------------
  
  if (isset($_GET['AddedID'])) 
  
      hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Credit Note"), "New=1");
        hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$invoice_no");
--      
 -      display_footer_exit();
 -}
 -
 -//---------------------------------------------------------------------------------------------------
 -
 -if (isset($_GET['New']))
 -{
 -      if (isset( $_SESSION['supp_trans']))
 -      {
 -              unset ($_SESSION['supp_trans']->grn_items);
 -              unset ($_SESSION['supp_trans']->gl_codes);
 -              unset ($_SESSION['supp_trans']);
 -      }
 -      $_SESSION['supp_trans'] = new supp_trans(ST_SUPPCREDIT);
 -      if (isset($_GET['invoice_no']))
 -      {
 -              $_SESSION['supp_trans']->supp_reference = $_POST['invoice_no'] = $_GET['invoice_no'];
 -      }
 +      display_footer_exit();
  }
  
  function clear_fields()
  {
        global $Ajax;
@@@ -153,8 -135,8 +152,8 @@@ if (isset($_POST['AddGLCodeToTrans'])) 
  
  function check_data()
  {
-       global $total_grn_value, $total_gl_value, $Refs;
-       
+       global $total_grn_value, $total_gl_value, $Refs, $SysPrefs;
 -      
++
        if (!$_SESSION['supp_trans']->is_valid_trans_to_post())
        {
                display_error(_("The credit note cannot be processed because the there are no items or values on the invoice.  Credit notes are expected to have a charge."));
index 7bafd736055368eb21506929efa22bfdfb49af3b,ed8f5a089a9c50302c9e7614358e2e68b31fe496..6d9992a68666b0f87ffb2de0dda65ae89a09808a
@@@ -273,9 -273,14 +273,14 @@@ start_form()
      supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
  
        set_global_supplier($_POST['supplier_id']);
--      
++
+       if (!list_updated('bank_account'))
+               $_POST['bank_account'] = get_default_supplier_bank_account($_POST['supplier_id']);              
 -      
++
      bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
 -      
 +
+       bank_balance_row($_POST['bank_account']);
        table_section(2);
  
      ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_SUPPAYMENT));
index b13ef4160dca923e95bb2d263f7dbf47a8a8f9f5,025e6581ef0631b454e268e92def09729802873d..ad7030aaaadf47bdba28d5f7f00853c08c7d67b8
@@@ -13,6 -13,6 +13,7 @@@ $page_security = 'SA_SUPPTRANSVIEW'
  $path_to_root = "../..";
  
  include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
++include_once($path_to_root . "/includes/ui/items_cart.inc");
  include_once($path_to_root . "/includes/session.inc");
  
  include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
@@@ -69,7 -69,7 +70,7 @@@ display_supp_trans_tax_details($tax_ite
  
  $display_total = number_format2($supp_trans->ov_amount + $supp_trans->ov_gst,user_price_dec());
  
--label_row(_("TOTAL INVOICE"), $display_total, "colspan=1 align=right", "nowrap align=right");
++label_row(_("TOTAL INVOICE").' ('.$supplier_curr_code.')', $display_total, "colspan=1 align=right", "nowrap align=right");
  
  end_table(1);
  
index 44b62b4326d6b0c3664eda439f9ab5f11d8e9bd3,300cd40194987856fee4080535f9f81ba44f86ff..9bc222d3eaa82ef13e0d5f65e58d0bdc9458af39
@@@ -175,7 -175,14 +175,14 @@@ class Cpdf extends FPDI 
                                        default :               $fontname = "freesans5";        break;
                                }
                        }
-                       // else use built-in adobe fonts helvetica.
+                       elseif ($this->encoding === "ISO-8859-13")
+             {
+                 switch ($this->l['a_meta_language'])
+                 {
+                     default :        $fontname = "freesans13";     break;
+                 }
 -            }                 
++            }
+             // else use built-in adobe fonts helvetica.
                }
                $this->SetFont($fontname, $style);
        }
index 4f52bd2cb22ad6c69cfc2a2a53df6127f80dfe7a,7044cee4572eaa352406610d92d10b1ede016a04..f279283b10a93e50ae63c6d2cb20ba20495f7b7f
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
      See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
  ***********************************************************************/
- if (isset($header2type))
- {
-       $doc_Cust_no = _("Cust no");
-       $doc_Date = _("Date");
-       if ($doctype == ST_PURCHORDER || $doctype == ST_SUPPAYMENT) // Purchase Order
-       {
-               $doc_Charge_To = _("Order To");
-               if ($doctype == ST_PURCHORDER)
-                       $doc_Delivered_To = _("Deliver To");
-               else    
-                       $doc_Delivered_To = _("Charge To");
-       }
-       else
-       {
-               if ($doctype == ST_CUSTPAYMENT)
-                       $doc_Charge_To = _("With thanks from");
-               else    
-                       $doc_Charge_To = _("Charge To");
-               $doc_Delivered_To = _("Delivered To");
-       }       
-       $doc_Shipping_Company = _("Shipping Company");
-       if ($doctype == ST_SALESQUOTE)
-               $doc_Due_Date = _("Valid until");
-       elseif ($doctype == ST_SALESORDER)
-               $doc_Due_Date = _("Delivery Date");
-       else
-               $doc_Due_Date = _("Due Date");
-       $doc_Your_Ref = _("Your Ref");
-       if ($doctype == ST_WORKORDER)
-       {
-               $doc_Our_Ref = _("Type");
-               $doc_Your_VAT_no = _("Manufactured Item");
-               $doc_Payment_Terms = _("Required By");
-               $doc_Customers_Ref = _("Reference");
-               $doc_Our_Order_No = _("Into Location");
-               $doc_Due_Date = _("Quantity");
-       }       
-       else
-       {
-               if ($doctype == ST_SUPPAYMENT || $doctype == ST_CUSTPAYMENT)
-                       $doc_Our_Ref = _("Type");
-               else    
-                       $doc_Our_Ref = _("Sales Person");
-               $doc_Your_VAT_no = _("Your VAT no.");
-               $doc_Payment_Terms = _("Payment Terms");
-               $doc_Customers_Ref = _("Customers Reference");
-               $doc_Our_Order_No = _("Our Order No");
-       }
-       $doc_Our_VAT_no = _("Our VAT No.");
-       $doc_Domicile = _("Domicile");
-       $doc_Extra = "";
-       if($doctype == ST_CUSTDELIVERY || $doctype == ST_SALESQUOTE || $doctype == ST_PURCHORDER || $doctype == ST_SALESORDER ||
-               $doctype == ST_SUPPAYMENT || $doctype == ST_CUSTPAYMENT) {
-               if ($doctype == ST_CUSTPAYMENT)
-                       $doc_Extra = _("* Subject to Realisation of the Cheque.");
-               $doc_Bank_Account = '';
-               $doc_Please_Quote = _("All amounts stated in");
-   } else {
-        $doc_Bank_Account = _("Bank Account");
-        $doc_Please_Quote = $doctype==ST_SALESINVOICE ? 
-        _("Please quote Invoice no. when paying. All amounts stated in") :
-        _("Please quote Credit no. when paying. All amounts stated in");
-       }
-       $doc_Address = _("Address");
-       $doc_Phone_Fax_Email = _("Phone/Fax/Email");
-       $doc_Bank = _("Bank");
-       $doc_Payment_Link = _("You can pay through");
-       if ($doctype == ST_SALESQUOTE || $doctype == ST_PURCHORDER || $doctype == ST_SALESORDER || $doctype == ST_SALESINVOICE || 
-               $doctype == ST_CUSTCREDIT || $doctype == ST_CUSTDELIVERY || $doctype == ST_WORKORDER || $doctype == ST_SUPPAYMENT || 
-               $doctype == ST_CUSTPAYMENT)
+ /*****
+ *
+ *     Set document type dependent elements of common page layout.
+ *
+ */
+       $Addr1 = array(
+                       'title' => _("Charge To"),
+                       'name' => @$this->formData['br_name'] ? $this->formData['br_name'] : @$this->formData['DebtorName'],
+                       'address' => @$this->formData['br_address'] ? $this->formData['br_address'] : @$this->formData['address']
+       );
+       $Addr2 = array(
+                       'title' => _("Delivered To"),
+                       'name' => @$this->formData['deliver_to'],
+                       'address' => @$this->formData['delivery_address']
+       );
+       // default item column headers
+       $this->headers = array(_("Item Code"), _("Item Description"), _("Quantity"),
+               _("Unit"), _("Price"), _("Discount %"), _("Total"));
+       // for links use 'text' => 'url'
+       $Footer[0] = _("All amounts stated in") . " - " . @$this->formData['curr_code'];
+       switch ($this->formData['doctype'])
        {
-               if ($doctype == ST_SALESQUOTE)
+               case ST_SALESQUOTE:
                        $this->title = _("SALES QUOTATION");
-               elseif ($doctype == ST_PURCHORDER)
-                       $this->title = _("PURCHASE ORDER");
-               elseif ($doctype == ST_CUSTDELIVERY)
-                       $this->title = ($packing_slip==1 ? _("PACKING SLIP") : _("DELIVERY NOTE"));
-               elseif ($doctype == ST_SALESORDER)
+                       $this->formData['document_name'] =_("Quotation No.");
+                       $this->formData['document_date'] = $this->formData['ord_date'];
+                       $this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
+                               ? $this->formData['reference'] : $this->formData['order_no'];
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Sales Person") => get_salesman_name($this->formData['salesman']),
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Quotation No") => $this->formData['order_no'],
+                               _("Valid until") => sql2date($this->formData['delivery_date']),
+                       );
+                       break;
+               case ST_SALESORDER:
                        $this->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
-               elseif ($doctype == ST_SALESINVOICE)
+                       $this->formData['document_name'] =_("Order No.");
+                       $this->formData['document_date'] = $this->formData['ord_date'];
+                       $this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
+                               ? $this->formData['reference'] : $this->formData['order_no'];
+                       $this->formData['document_amount'] = $this->formData['order_no'];
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Sales Person") => get_salesman_name($this->formData['salesman']),
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => $this->formData['order_no'],
+                               _("Delivery Date") => sql2date($this->formData['delivery_date']),
+                       );
+                       break;
+               case ST_CUSTDELIVERY:
+                       $this->title = ($packing_slip==1 ? _("PACKING SLIP") : _("DELIVERY NOTE"));
+                       $this->formData['document_name'] = _("Delivery Note No.");
+                       if (@$packing_slip)
+                               $Payment_Terms = '';
+                       $ref = $this->formData['order_'];
+                       if ($print_invoice_no == 0)
+                       {
+                               $ref = get_reference(ST_SALESORDER, $this->formData['order_']);
+                               if (!$ref)
+                                       $ref = $this->formData['order_'];
+                       }
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Sales Person") => get_salesman_name($this->formData['salesman']),
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => $ref,
+                               _("To Be Invoiced Before") => sql2date($this->formData['due_date']),
+                       );
+                       break;
+               case ST_CUSTCREDIT:
+                       $this->title = _("CREDIT NOTE");
+                       $this->formData['document_name'] =_("Credit No.");
+                       $Footer[0] = _("Please quote Credit no. when paying. All amounts stated in") . " - " . $this->formData['curr_code'];
+                       $aux_info = array(
+                               _("Customers Reference") => @$this->formData["customer_ref"],
+                               _("Sales Person") => get_salesman_name($this->formData['salesman']),
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => $this->formData['order_'],
+                               _("Due Date") => '',
+                       );
+                       break;
+               case ST_SALESINVOICE:
                        $this->title = _("INVOICE");
-               elseif ($doctype == ST_WORKORDER)
-                       $this->title = _("WORK ORDER");
-               elseif ($doctype == ST_SUPPAYMENT)
+                       $this->formData['document_name'] =_("Invoice No.");
+                       $this->formData['domicile'] = $this->company['domicile'];
+                       $Footer[0] = _("Please quote Invoice no. when paying. All amounts stated in"). " - " . $this->formData['curr_code'];
+                       $deliveries = get_sales_parent_numbers(ST_SALESINVOICE, $this->formData['trans_no']);
+                       if ($print_invoice_no == 0)
+                       {
+                               foreach($deliveries as $n => $delivery) {
+                                       $deliveries[$n] = get_reference(ST_CUSTDELIVERY, $delivery);
+                               }
+                       }
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Sales Person") => get_salesman_name($this->formData['salesman']),
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Delivery Note No.") => implode(',', $deliveries),
+                               _("Due Date") => sql2date($this->formData['due_date']),
+                       );
+                       break;
+               case ST_SUPPAYMENT:
+                       global $systypes_array;
                        $this->title = _("REMITTANCE");
-               elseif ($doctype == ST_CUSTPAYMENT)
-                       $this->title = _("RECEIPT");
-               else
-                       $this->title = _("CREDIT NOTE");
-               if ($doctype == ST_PURCHORDER)
+                       $this->formData['document_name'] =_("Remittance No.");
+                       $Addr1['title'] = _("Order To");
+                       $Addr1['name'] = $this->formData['supp_name'];
+                       $Addr1['address'] = $this->formData['address'];
+                       $Addr2['title'] = _("Charge To");
+                       $Addr2['name'] = '';
+                       $Addr2['address'] = '';
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData['supp_account_no'],
+                               _("Type") =>$systypes_array[$this->formData["type"]],
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => '',
+                               _("Due Date") => sql2date($this->formData['tran_date']),
+                       );
+                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
+                       break;
+               case ST_PURCHORDER:
+                       $this->title = _("PURCHASE ORDER");
+                       $this->formData['document_name'] =_("Purchase Order No.");
+                       $Addr1['title'] = _("Order To");
+                       $Addr1['name'] = $this->formData['supp_name'];
+                       $Addr1['address'] = $this->formData['address'];
+                       $Addr2['title'] = _("Deliver To");
+                       $Addr2['name'] = $this->company['coy_name'];
+                       //$Addr2['address'] = $this->company['postal_address']; No, don't destroy delivery address!
+                       $this->formData['document_date'] = $this->formData['ord_date'];
+                       $this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
+                               ? $this->formData['reference'] : $this->formData['order_no'];
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData['supp_account_no'],
+                               _("Sales Person") => '',
+                               _("Your VAT no.") => '',
+                               _("Our Order No") => '',
+                               _("Due Date") => '',
+                       );
                        $this->headers = array(_("Item Code"), _("Item Description"),
                                _("Delivery Date"), _("Quantity"),      _("Unit"), _("Price"), _("Total"));
-               elseif ($doctype == ST_WORKORDER)
+                       break;
+               case ST_CUSTPAYMENT:
+                       global $systypes_array;
+                       $this->title = _("RECEIPT");
+                       $this->formData['document_name'] =_("Receipt No.");
+                       $Addr1['title'] = _("With thanks from");
+                       $aux_info = array(
+                               _("Customers Reference") => $this->formData["debtor_ref"],
+                               _("Type") =>$systypes_array[$this->formData["type"]],
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => $this->formData['order_'],
+                               _("Due Date") => sql2date($this->formData['tran_date']),
+                       );
+                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
+                       break;
+               case ST_WORKORDER:
+                       global $wo_types_array;
+                       $this->title = _("WORK ORDER");
+                       $this->formData['document_name'] =_("Work Order No.");
+                       $this->formData['document_date'] = $this->formData['date_'];
+                       $this->formData['document_number'] = $this->formData['id'];
+                       $Addr1['name'] = $this->formData['location_name'];
+                       $Addr1['address'] = $this->formData['delivery_address'];
+                       $aux_info = array(
+                               _("Reference") => $this->formData['wo_ref'],
+                               _("Type") => $wo_types_array[$this->formData["type"]],
+                               _("Manufactured Item") => $this->formData["StockItemName"],
+                               _("Into Location") => $this->formData["location_name"],
+                               _("Quantity") => $this->formData["units_issued"],
+                       );
+                       $Payment_Terms = _("Required By").": ".sql2date($this->formData["required_by"]);
                        $this->headers = array(_("Item Code"), _("Item Description"),
                                _("From Location"), _("Work Centre"),   _("Unit Quantity"), _("Total Quantity"), _("Units Issued"));
-               elseif ($doctype == ST_SUPPAYMENT || $doctype == ST_CUSTPAYMENT)
-                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
-               else
-                       $this->headers = array(_("Item Code"), _("Item Description"),   _("Quantity"),
-                               _("Unit"), _("Price"), _("Discount %"), _("Total"));
-       }
-       else if ($doctype == ST_STATEMENT)
-       {
-               $this->title = _("STATEMENT");
-               $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Charges"),
-                       _("Credits"), _("Allocated"), _("Outstanding"));
+                       unset($Footer[0]);
+                       break;
+               case ST_STATEMENT:
+                       $this->formData['document_name'] = '';
+                       $this->formData['domicile'] = $this->company['domicile'];
+                       $Payment_Terms = '';
+                       $this->title = _("STATEMENT");
+                       $aux_info = array(
+                               _("Customers Reference") => '',
+                               _("Sales Person") => '',
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Our Order No") => '',
+                               _("Delivery Date") => '',
+                       );
+                       $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Charges"),
+                               _("Credits"), _("Allocated"), _("Outstanding"));
        }
- }
- if (isset($emailtype))
- {
-       $doc_Dear_Sirs = _("Dear");
-       $doc_AttachedFile = _("Attached you will find ");
-       $doc_Kindest_regards = _("Kindest regards");
-       $doc_Payment_Link = _("You can pay through");
- }
- if (isset($header2type) || isset($linetype))
- {
-       $doc_Invoice_no = ($doctype==ST_CUSTDELIVERY ? _("Delivery Note No.") : 
-               ($doctype == ST_CUSTPAYMENT ? _("Receipt No.") :
-               ($doctype == ST_SUPPAYMENT ? _("Remittance No.") :
-               ($doctype == ST_PURCHORDER ? _("Purchase Order No.") :
-               ($doctype == ST_SALESORDER ? _("Order No.") :
-               ($doctype == ST_SALESQUOTE ? _("Quotation No.") :
-               ($doctype == ST_SALESINVOICE ? _("Invoice No.") :
-               ($doctype == ST_WORKORDER ? _("Work Order No.") : _("Credit No.")))))))));
-       $doc_Delivery_no = _("Delivery Note No.");
-       $doc_Order_no = _("Order No.");
- }
- if (isset($linetype))
- {
-       if ($doctype == ST_SALESQUOTE || $doctype == ST_PURCHORDER || $doctype == ST_SALESORDER || 
-               $doctype == ST_SALESINVOICE || $doctype == ST_CUSTCREDIT || $doctype == ST_CUSTDELIVERY)
+       // default values
+       if (!isset($this->formData['document_date']))
+               $this->formData['document_date'] = $this->formData['tran_date'];
+       if (!isset($this->formData['document_number']))
+               $this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
+                       ? $this->formData['reference'] : @$this->formData['trans_no'];
+       if (!isset($Payment_Terms))
        {
-               $doc_Sub_total = _("Sub-total");
-               $doc_Shipping = _("Shipping");
-               $doc_Included = _("Included");
-               $doc_Amount = _("Amount");
-               $doc_TOTAL_INVOICE = $doctype ==ST_SALESINVOICE ? _("TOTAL INVOICE") : _("TOTAL CREDIT");
-               $doc_TOTAL_ORDER = _("TOTAL ORDER EX VAT");
-               $doc_TOTAL_ORDER2 = _("TOTAL ORDER VAT INCL.");
-               $doc_TOTAL_PO = _("TOTAL PO");
-               $doc_TOTAL_DELIVERY = _("TOTAL DELIVERY INCL. VAT");
+               $id = $this->formData['payment_terms'];
+               $sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
+               $result = db_query($sql,"could not get paymentterms");
+               $row = db_fetch($result);
+               $Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
        }
-       elseif ($doctype == ST_SUPPAYMENT || $doctype == ST_CUSTPAYMENT)
+       // footer generic content
+       if (@$this->formData['bank_name'])
+               $Footer[] = _("Bank"). ": ".$this->formData['bank_name']. ", " . _("Bank Account") . ": " . $this->formData['bank_account_number'];
+       if (@$this->formData['payment_service'])        //payment link
        {
-               $doc_Towards = _("As advance / full / part / payment towards:");
-               $doc_by_Cheque = _("By Cash / Cheque* / Draft No.");
-               $doc_Dated = _("Dated");
-               $doc_Drawn = _("Drawn on Bank");
-               $doc_Drawn_Branch = _("Branch");
-               $doc_Received = _("Received / Sign");
-               $doc_Total_Allocated = _("Total Allocated");
-               $doc_Left_To_Allocate = _("Left to Allocate");
-               if ($doctype == ST_CUSTPAYMENT)
-                       $doc_Total_Payment = _("TOTAL RECEIPT");
-               else    
-                       $doc_Total_Payment = _("TOTAL REMITTANCE");
+               $amt = number_format($this->formData["ov_freight"] + $this->formData["ov_gst"] + $this->formData["ov_amount"], user_price_dec());
+               $service = $this->formData['payment_service'];
+               $url = payment_link($service, array(
+                       'company_email' => $this->company['email'],
+                       'amount' => $amt,
+                       'currency' => $this->formData['curr_code'],
+                       'comment' => $this->title . " " . $this->formData['reference']
+                       ));
+               $Footer[_("You can pay through"). " $service: "] = "$url";
        }
-       elseif ($doctype == ST_STATEMENT)
+       if ($this->formData['doctype'] == ST_CUSTPAYMENT)
+               $Footer[] = _("* Subject to Realisation of the Cheque.");
+       if ($this->params['comments'] != '')
+               $Footer[] = $this->params['comments'];
+       if (($this->formData['doctype'] == ST_SALESINVOICE || $this->formData['doctype'] == ST_STATEMENT) && $this->company['legal_text'] != "") 
        {
-               $doc_Outstanding = _("Outstanding Transactions");
-               $doc_Current = _("Current");
-               $doc_Total_Balance = _("Total Balance");
-               $doc_Statement = _("Statement");
-               $doc_as_of = _("as of");
-               $doc_Days = _("Days");
-               $doc_Over = _("Over");
+               foreach(explode("\n", $this->company['legal_text']) as $line)
+                       $Footer[] = $line;
        }
- }
 -
--?>
index 996d290c42338960b9c7794f0ac69009f06401bc,33ac54a529448ee627444c4679e9dd357a41b567..7d1379b43676d9bb45929b6173ac95cfed7ad060
@@@ -693,8 -693,9 +693,8 @@@ class FrontReport extends Spreadsheet_E
                return ($px / $unit_offset_length);
        }       
  
-       function End($email=0, $subject=null, $myrow=null, $doctype = 0)
+       function End($email=0, $subject='')
        {
 -              global $path_to_root;
                ++$this->y;
                for ($i = 0; $i < $this->numcols; $i++)
                        $this->sheet->writeBlank($this->y, $i, $this->formatFooter);
index e2a50b331b25028912153126a80e8022eed38d2f,5e044f2898df54935a36d3daf75de299c4b10cde..36acff5abcd21e3ca7e592cc14fa3ae72ae8a496
@@@ -135,11 -118,14 +118,14 @@@ function print_invoices(
                                $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
                                $newrow = $rep->row;
                                $rep->row = $oldrow;
-                               $rep->TextCol(2, 3,     $DisplayQty, -2);
-                               $rep->TextCol(3, 4,     $myrow2['units'], -2);
-                               $rep->TextCol(4, 5,     $DisplayPrice, -2);
-                               $rep->TextCol(5, 6,     $DisplayDiscount, -2);
-                               $rep->TextCol(6, 7,     $DisplayNet, -2);
+                               if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
+                               {
+                                       $rep->TextCol(2, 3,     $DisplayQty, -2);
+                                       $rep->TextCol(3, 4,     $myrow2['units'], -2);
+                                       $rep->TextCol(4, 5,     $DisplayPrice, -2);
+                                       $rep->TextCol(5, 6,     $DisplayDiscount, -2);
+                                       $rep->TextCol(6, 7,     $DisplayNet, -2);
 -                              }       
++                              }
                                $rep->row = $newrow;
                                //$rep->NewLine(1);
                                if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
                        $first = true;
                while ($tax_item = db_fetch($tax_items))
                {
-                               if ($tax_item['amount'] == 0)
-                                       continue;
+                       if ($tax_item['amount'] == 0)
+                               continue;
                        $DisplayTax = number_format2($sign*$tax_item['amount'], $dec);
--                      
++
                        if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
                                $tax_type_name = $tax_item['tax_type_name'];
                        else
index c775bb907769c08b2e787a57e7816e7d4af0cc72,c8b4a1ef3e782f8ac34fc86df9d67742fa5d13e0..08990e10babfbe463828ef9225cff3e3e14802bf
@@@ -124,11 -124,14 +124,14 @@@ function print_sales_orders(
                        $rep->TextColLines(1, 2, $myrow2['description'], -2);
                        $newrow = $rep->row;
                        $rep->row = $oldrow;
-                       $rep->TextCol(2, 3,     $DisplayQty, -2);
-                       $rep->TextCol(3, 4,     $myrow2['units'], -2);
-                       $rep->TextCol(4, 5,     $DisplayPrice, -2);
-                       $rep->TextCol(5, 6,     $DisplayDiscount, -2);
-                       $rep->TextCol(6, 7,     $DisplayNet, -2);
+                       if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
+                       {
+                               $rep->TextCol(2, 3,     $DisplayQty, -2);
+                               $rep->TextCol(3, 4,     $myrow2['units'], -2);
+                               $rep->TextCol(4, 5,     $DisplayPrice, -2);
+                               $rep->TextCol(5, 6,     $DisplayDiscount, -2);
+                               $rep->TextCol(6, 7,     $DisplayNet, -2);
 -                      }       
++                      }
                        $rep->row = $newrow;
                        //$rep->NewLine(1);
                        if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
index 06857a8da97770581c4570ac11e61bd45337f5d8,7b9318d0e845ac9ecd2920aa87580bb3d5456b78..856da3240a51fb35ccea69f6d235f177731e354a
@@@ -111,7 -111,7 +111,7 @@@ function print_deliveries(
                        {
                                if ($myrow2["quantity"] == 0)
                                        continue;
--                                      
++
                                $Net = round2(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
                                   user_price_dec());
                                $SubTotal += $Net;
                                $rep->TextColLines(1, 2, $myrow2['StockDescription'], -2);
                                $newrow = $rep->row;
                                $rep->row = $oldrow;
-                               $rep->TextCol(2, 3,     $DisplayQty, -2);
-                               $rep->TextCol(3, 4,     $myrow2['units'], -2);
-                               if ($packing_slip == 0)
+                               if ($Net != 0.0  || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
 -                              {                       
 +                              {
-                                       $rep->TextCol(4, 5,     $DisplayPrice, -2);
-                                       $rep->TextCol(5, 6,     $DisplayDiscount, -2);
-                                       $rep->TextCol(6, 7,     $DisplayNet, -2);
-                               }       
+                                       $rep->TextCol(2, 3,     $DisplayQty, -2);
+                                       $rep->TextCol(3, 4,     $myrow2['units'], -2);
+                                       if ($packing_slip == 0)
+                                       {
+                                               $rep->TextCol(4, 5,     $DisplayPrice, -2);
+                                               $rep->TextCol(5, 6,     $DisplayDiscount, -2);
+                                               $rep->TextCol(6, 7,     $DisplayNet, -2);
+                                       }
 -                              }       
++                              }
                                $rep->row = $newrow;
                                //$rep->NewLine(1);
                                if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
index 02285fca2452857bf62adac6119761a67dfd3a39,2662fca59d1221403d0a4cdff2785a063b24c8ac..be0c48c0c55a4007b23c22f4a0874918ac7926ba
@@@ -107,11 -111,14 +111,14 @@@ function print_sales_quotations(
                        $rep->TextColLines(1, 2, $myrow2['description'], -2);
                        $newrow = $rep->row;
                        $rep->row = $oldrow;
-                       $rep->TextCol(2, 3,     $DisplayQty, -2);
-                       $rep->TextCol(3, 4,     $myrow2['units'], -2);
-                       $rep->TextCol(4, 5,     $DisplayPrice, -2);
-                       $rep->TextCol(5, 6,     $DisplayDiscount, -2);
-                       $rep->TextCol(6, 7,     $DisplayNet, -2);
+                       if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0)
+                       {
+                               $rep->TextCol(2, 3,     $DisplayQty, -2);
+                               $rep->TextCol(3, 4,     $myrow2['units'], -2);
+                               $rep->TextCol(4, 5,     $DisplayPrice, -2);
+                               $rep->TextCol(5, 6,     $DisplayDiscount, -2);
+                               $rep->TextCol(6, 7,     $DisplayNet, -2);
 -                      }       
++                      }
                        $rep->row = $newrow;
                        //$rep->NewLine(1);
                        if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
                $DisplaySubTot = number_format2($SubTotal,$dec);
                $DisplayFreight = number_format2($myrow["freight_cost"],$dec);
  
--              $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
-               $linetype = true;
                $doctype = ST_SALESQUOTE;
-               include($path_to_root . "/reporting/includes/doctext.inc");
  
-               $rep->TextCol(3, 6, $doc_Sub_total, -2);
+               $rep->TextCol(3, 6, _("Sub-total"), -2);
                $rep->TextCol(6, 7,     $DisplaySubTot, -2);
                $rep->NewLine();
-               $rep->TextCol(3, 6, $doc_Shipping, -2);
+               $rep->TextCol(3, 6, _("Shipping"), -2);
                $rep->TextCol(6, 7,     $DisplayFreight, -2);
                $rep->NewLine();
+               $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
+               if ($myrow['tax_included'] == 0) {
+                       $rep->TextCol(3, 6, _("TOTAL ORDER EX VAT"), - 2);
+                       $rep->TextCol(6, 7,     $DisplayTotal, -2);
+                       $rep->NewLine();
+               }
+               $tax_items = get_tax_for_items($items, $prices, $myrow["freight_cost"],
+                 $myrow['tax_group_id'], $myrow['tax_included'],  null);
+               $first = true;
+               foreach($tax_items as $tax_item)
+               {
+                       if ($tax_item['Value'] == 0)
+                               continue;
+                       $DisplayTax = number_format2($tax_item['Value'], $dec);
+                       $tax_type_name = $tax_item['tax_type_name'];
+                       if ($myrow['tax_included'])
+                       {
+                               if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
+                               {
+                                       if ($first)
+                                       {
+                                               $rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
+                                               $rep->TextCol(6, 7,     number_format2($sign*$tax_item['net_amount'], $dec), -2);
+                                               $rep->NewLine();
+                                       }
+                                       $rep->TextCol(3, 6, $tax_type_name, -2);
+                                       $rep->TextCol(6, 7,     $DisplayTax, -2);
+                                       $first = false;
+                               }
+                               else
+                                       $rep->TextCol(3, 7, _("Included") . " " . $tax_type_name . " " . _("Amount") . ": " . $DisplayTax, -2);
+                       }
+                       else
+                       {
+                               $SubTotal += $tax_item['Value'];
+                               $rep->TextCol(3, 6, $tax_type_name, -2);
+                               $rep->TextCol(6, 7,     $DisplayTax, -2);
+                       }
+                       $rep->NewLine();
+               }
+               $rep->NewLine();
                $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
                $rep->Font('bold');
-               if ($myrow['tax_included'] == 0)
-                       $rep->TextCol(3, 6, $doc_TOTAL_ORDER, - 2);
-               else    
-                       $rep->TextCol(3, 6, $doc_TOTAL_ORDER2, - 2);
+               $rep->TextCol(3, 6, _("TOTAL ORDER VAT INCL."), - 2);
                $rep->TextCol(6, 7,     $DisplayTotal, -2);
                $words = price_in_words($myrow["freight_cost"] + $SubTotal, ST_SALESQUOTE);
                if ($words != "")
index b5238a2673769c14432e0dec3df9af9d55443976,ba6c94653b4571ccf24f83b4ff94a1294ad7efd4..c510160a1566486adaae4f7f0a74e27917c1a148
@@@ -105,9 -105,10 +105,10 @@@ function print_receipts(
                {
                        $myrow = get_receipt($j, $i);
                        if (!$myrow)
--                              continue;                       
-                       $baccount = get_default_bank_account($myrow['curr_code']);
-                       $params['bankaccount'] = $baccount['id'];
++                              continue;
+                       $res = get_bank_trans($j, $i);
+                       $baccount = db_fetch($res);
+                       $params['bankaccount'] = $baccount['bank_act'];
  
                        $rep->title = _('RECEIPT');
                        $contacts = get_branch_contacts($myrow['branch_code'], 'invoice', $myrow['debtor_no']);
                        $rep->NewPage();
                        $result = get_allocations_for_receipt($myrow['debtor_no'], $myrow['type'], $myrow['trans_no']);
  
-                       $linetype = true;
                        $doctype = ST_CUSTPAYMENT;
-                       include($path_to_root . "/reporting/includes/doctext.inc");
  
                        $total_allocated = 0;
-                       $rep->TextCol(0, 4,     $doc_Towards, -2);
+                       $rep->TextCol(0, 4,     _("As advance / full / part / payment towards:"), -2);
                        $rep->NewLine(2);
--                      
++
                        while ($myrow2=db_fetch($result))
                        {
                                $rep->TextCol(0, 1,     $systypes_array[$myrow2['type']], -2);
                        {
                                $rep->NewLine(1);
                                $rep->TextCol(0, 7, $myrow['curr_code'] . ": " . $words, - 2);
--                      }       
++                      }
                        $rep->Font();
                        $rep->NewLine();
-                       $rep->TextCol(6, 7, $doc_Received, - 2);
+                       $rep->TextCol(6, 7, _("Received / Sign"), - 2);
                        $rep->NewLine();
-                       $rep->TextCol(0, 2, $doc_by_Cheque, - 2);
+                       $rep->TextCol(0, 2, _("By Cash / Cheque* / Draft No."), - 2);
                        $rep->TextCol(2, 4, "______________________________", - 2);
-                       $rep->TextCol(4, 5, $doc_Dated, - 2);
+                       $rep->TextCol(4, 5, _("Dated"), - 2);
                        $rep->TextCol(5, 6, "__________________", - 2);
                        $rep->NewLine(1);
-                       $rep->TextCol(0, 2, $doc_Drawn, - 2);
+                       $rep->TextCol(0, 2, _("Drawn on Bank"), - 2);
                        $rep->TextCol(2, 4, "______________________________", - 2);
-                       $rep->TextCol(4, 5, $doc_Drawn_Branch, - 2);
+                       $rep->TextCol(4, 5, _("Branch"), - 2);
                        $rep->TextCol(5, 6, "__________________", - 2);
                        $rep->TextCol(6, 7, "__________________");
--              }       
++              }
        }
        $rep->End();
  }
index 2eb27559689efe240c53f395c0a60089ea79f773,6bbf6d92c02fb1f53f13d0a559bfe49a6b373b88..5901260596b53b878a93ff35f6fbdbbb1bb163b2
@@@ -36,7 -36,12 +36,12 @@@ function get_invoices($supplier_id, $to
        $PastDueDays2 = 2 * $PastDueDays1;
  
        // Revomed allocated from sql
-     $value = "(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
+       if ($all)
+       $value = "(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
 -    else      
++    else
+       $value = "IF (".TB_PREF."supp_trans.type=".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type=".ST_BANKDEPOSIT.", 
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc),
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount + ".TB_PREF."supp_trans.alloc))";
        $due = "IF (".TB_PREF."supp_trans.type=".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type=".ST_SUPPCREDIT.",".TB_PREF."supp_trans.due_date,".TB_PREF."supp_trans.tran_date)";
        $sql = "SELECT ".TB_PREF."supp_trans.type,
                ".TB_PREF."supp_trans.reference,
Simple merge
index 7f6b53b65e20c5e23e3b65faec3a36a629b20af7,136f0d2c9fe355b542fc8dd06cbad64d5f112d27..9d8b8d7ddfbf9b0a0c71d3a3115fcf38631a7412
@@@ -108,9 -108,10 +108,10 @@@ function print_remittances(
                {
                        $myrow = get_remittance($j, $i);
                        if (!$myrow)
--                              continue;                       
-                       $baccount = get_default_bank_account($myrow['curr_code']);
-                       $params['bankaccount'] = $baccount['id'];
++                              continue;
+                       $res = get_bank_trans($j, $i);
+                       $baccount = db_fetch($res);
+                       $params['bankaccount'] = $baccount['bank_act'];
  
                        if ($email == 1)
                        {
                        $rep->NewPage();
                        $result = get_allocations_for_remittance($myrow['supplier_id'], $myrow['type'], $myrow['trans_no']);
  
-                       $linetype = true;
                        $doctype = ST_SUPPAYMENT;
-                       include($path_to_root . "/reporting/includes/doctext.inc");
  
                        $total_allocated = 0;
-                       $rep->TextCol(0, 4,     $doc_Towards, -2);
+                       $rep->TextCol(0, 4,     _("As advance / full / part / payment towards:"), -2);
                        $rep->NewLine(2);
--                      
++
                        while ($myrow2=db_fetch($result))
                        {
                                $rep->TextCol(0, 1,     $systypes_array[$myrow2['type']], -2);
                        {
                                $rep->NewLine(2);
                                $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
--                      }       
++                      }
                        $rep->Font();
                        if ($email == 1)
                        {
                                $myrow['DebtorName'] = $myrow['supp_name'];
-                               $rep->End($email, $doc_Order_no . " " . $myrow['reference'], $myrow);
+                               $rep->End($email);
                        }
--              }       
++              }
        }
        if ($email == 0)
                $rep->End();
index 6711d9b7f4257bb7f1a8e42b9432a671760a478f,1471ae66c1e46c59862948bf4f0a755e4b43ab81..3fdef19ed092cc2e6bb77db024158198afa3f707
@@@ -33,20 -33,27 +33,27 @@@ function getTransactions($from, $to
  {
        $from = date2sql($from);
        $to = date2sql($to);
--      
-       $sql = "SELECT DISTINCT ".TB_PREF."grn_batch.supplier_id, 
++
+       $sql = "SELECT ".TB_PREF."grn_batch.id batch_no,
+                       ".TB_PREF."grn_batch.supplier_id, 
              ".TB_PREF."purch_order_details.*,
-             ".TB_PREF."stock_master.description, ".TB_PREF."stock_master.inactive
+             ".TB_PREF."stock_master.description,
+                       ".TB_PREF."grn_items.qty_recd,
+                       ".TB_PREF."grn_items.quantity_inv,
+                       ".TB_PREF."grn_items.id grn_item_id
          FROM ".TB_PREF."stock_master,
              ".TB_PREF."purch_order_details,
-             ".TB_PREF."grn_batch
+             ".TB_PREF."grn_batch,
+                       ".TB_PREF."grn_items 
          WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."purch_order_details.item_code
          AND ".TB_PREF."grn_batch.purch_order_no=".TB_PREF."purch_order_details.order_no
-         AND ".TB_PREF."purch_order_details.quantity_received>0
+               AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id 
+               AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
+         AND ".TB_PREF."grn_items.qty_recd>0
          AND ".TB_PREF."grn_batch.delivery_date>='$from'
          AND ".TB_PREF."grn_batch.delivery_date<='$to'
          ORDER BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."grn_batch.delivery_date";       
--      
++
      return db_query($sql,"No transactions were returned");
  
  }
@@@ -108,17 -131,43 +131,43 @@@ function print_grn_valuation(
  
                $rep->NewLine();
                $rep->TextCol(0, 1, $trans['item_code']);
-               $rep->TextCol(1, 2, $trans['description'].($trans['inactive']==1 ? " ("._("Inactive").")" : ""), -1);
+               $rep->TextCol(1, 2, $trans['description']);
                $rep->TextCol(2, 3, $trans['order_no']);
                $qdec = get_qty_dec($trans['item_code']);
-               $rep->AmountCol(3, 4, $trans['quantity_received'], $qdec);
-               $rep->AmountCol(4, 5, $trans['unit_price'], $dec);
-               $rep->AmountCol(5, 6, $trans['act_price'], $dec);
-               $amt = round2($trans['quantity_received'] * $trans['act_price'], $dec);
-               $rep->AmountCol(6, 7, $amt, $dec);
-               $total += $amt;
-               $qtotal += $trans['quantity_received'];
-               $grandtotal += $amt;
+               $rep->TextCol(3, 4, $trans['batch_no']);
 -              
++
+               if ($trans['quantity_inv'])
+               {
+                       $suppinv = getSuppInvDetails($trans['grn_item_id']);
+                       while ($inv=db_fetch($suppinv))
+                       {       
+                               $inv['inv_price'] *= $rate;
+                               $rep->TextCol(4, 5, $inv['inv_no']);
+                               $rep->AmountCol(5, 6, $inv['inv_qty'], $qdec);
+                               $rep->AmountCol(6, 7, $inv['inv_price'], $dec);
+                               $rep->AmountCol(7, 8, $trans['unit_price'], $dec);
+                               $amt = round2($inv['inv_qty'] * $inv['inv_price'], $dec);
+                               $rep->AmountCol(8, 9, $amt, $dec);
+                               $rep->NewLine();
+                               $total += $amt;
+                               $qtotal += $inv['inv_qty'];
+                               $grandtotal += $amt;
+                       }
+               }
+       
+               if ($trans['qty_recd'] - $trans['quantity_inv'] !=0 )
+               {
+                       $rep->TextCol(4, 5, "--");
+                       $rep->AmountCol(5, 6, $trans['qty_recd'] - $trans['quantity_inv'], $qdec);
+                       $rep->AmountCol(7, 8, $trans['unit_price'], $dec);
+                       $amt = round2(($trans['qty_recd'] - $trans['quantity_inv']) * $trans['unit_price'], $dec);
+                       $rep->AmountCol(8, 9, $amt, $dec);
+                       $total += $amt;
+                       $qtotal += $trans['qty_recd'] - $trans['quantity_inv'];
+                       $grandtotal += $amt;
+               }
+               else
+                       $rep->NewLine(-1);
        }
        if ($stock_id != '')
        {
index 7ad92bcb6c4b0279cc6c677e1bb583502deaab54,1d47bc78a1510ca4e201862ab6cdff147e2709bb..1cedff0df8f07ef669516ba0d638e2a13f4d7c9e
@@@ -118,7 -118,7 +118,7 @@@ function print_bank_transactions(
                                $rep->TextCol(1, 2,     $myrow['trans_no']);
                                $rep->TextCol(2, 3,     $myrow['ref']);
                                $rep->DateCol(3, 4,     $myrow["trans_date"], true);
-                               $rep->TextCol(4, 5,     get_counterparty_name($myrow["type"], $myrow["type_no"], false));
 -                              $rep->TextCol(4, 5,     payment_person_name($myrow["person_type_id"],$myrow["person_id"], false));
++                              $rep->TextCol(4, 5,     get_counterparty_name($myrow["type"], $myrow["trans_no"], false));
                                if ($myrow['amount'] > 0.0)
                                {
                                        $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
index b4f54c9603ea093ed7716cd2ea0151fbc4505270,30e6aa05595ae67b6a58affc4482625bcae367da..2bfffade74b2ee4bb6ff385933db231422bb5263
@@@ -25,10 -25,10 +25,10 @@@ include_once($path_to_root . "/gl/inclu
  
  //----------------------------------------------------------------------------------------------------
  
- function display_type ($type, $typename, &$dec, &$rep, $showbalance)
+ function display_type ($type, $typename, &$dec, &$rep, $showbalance, $level)
  {
        $printtitle = 0; //Flag for printing type name  
--      
++
        //Get Accounts directly under this group/type
        $result = get_gl_accounts(null, null, $type);   
        while ($account=db_fetch($result))
                //Print Type Title if it has atleast one non-zero account       
                if (!$printtitle)
                {
 -                      }               
+                       $prefix = '';
+                       for ($sp=1; $sp<=$level; $sp++)
+                       {
+                               $prefix .= '         ';
++                      }
                        $printtitle = 1;
                        $rep->row -= 4;
-                       $rep->Font('bold');
                        $rep->TextCol(0, 1, $type);
-                       $rep->TextCol(1, 4, $typename);
-                       $rep->Font();
+                       $rep->TextCol(1, 4, $prefix.$typename);
                        $rep->row -= 4;
                        $rep->Line($rep->row);
                        $rep->NewLine();                
@@@ -60,7 -63,7 +63,7 @@@
                        $rep->AmountCol(3, 4, $balance, $dec);
                $rep->NewLine();
        }
--              
++
        //Get Account groups/types under this group/type
        $result = get_account_types(false, false, $type);
        while ($accounttype=db_fetch($result))
index 2095602919aaf7e4ed3b9df4bdf75ba591dde530,979ca2e1e4a45bffa0d9e871a8627e209f11b8b7..9ff9b2964783a21f4966185605b06ed8d5fe2c38
@@@ -109,65 -208,23 +208,23 @@@ function print_trial_balance(
        $rep->Font();
        $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
        $rep->NewPage();
 -      
 +
-       $accounts = get_gl_accounts();
-       $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
-       $begin = begin_fiscalyear();
-       if (date1_greater_date2($begin, $from))
-               $begin = $from;
-       $begin = add_days($begin, -1);
-       while ($account=db_fetch($accounts))
+       $classresult = get_account_classes(false);
+       while ($class = db_fetch($classresult))
        {
-               $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
-               $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
-               $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
-               if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
-                       continue;
-               $rep->TextCol(0, 1, $account['account_code']);
-               $rep->TextCol(1, 2,     $account['account_name']);
-               if ($balances != 0)
-               {
-                       if ($prev['balance'] >= 0.0)
-                               $rep->AmountCol(2, 3, $prev['balance'], $dec);
-                       else
-                               $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
-                       if ($curr['balance'] >= 0.0)
-                               $rep->AmountCol(4, 5, $curr['balance'], $dec);
-                       else
-                               $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
-                       if ($tot['balance'] >= 0.0)
-                               $rep->AmountCol(6, 7, $tot['balance'], $dec);
-                       else
-                               $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
-               }
-               else
-               {
-                       $rep->AmountCol(2, 3, $prev['debit'], $dec);
-                       $rep->AmountCol(3, 4, $prev['credit'], $dec);
-                       $rep->AmountCol(4, 5, $curr['debit'], $dec);
-                       $rep->AmountCol(5, 6, $curr['credit'], $dec);
-                       $rep->AmountCol(6, 7, $tot['debit'], $dec);
-                       $rep->AmountCol(7, 8, $tot['credit'], $dec);
-                       $pdeb += $prev['debit'];
-                       $pcre += $prev['credit'];
-                       $cdeb += $curr['debit'];
-                       $ccre += $curr['credit'];
-                       $tdeb += $tot['debit'];
-                       $tcre += $tot['credit'];
-                       
-               }       
-               $pbal += $prev['balance'];
-               $cbal += $curr['balance'];
-               $tbal += $tot['balance'];
+               $rep->Font('bold');
+               $rep->TextCol(0, 1, $class['cid']);
+               $rep->TextCol(1, 4, $class['class_name']);
+               $rep->Font();
                $rep->NewLine();
  
-               if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
+               //Get Account groups/types under this group/type with no parents
+               $typeresult = get_account_types(false, $class['cid'], -1);
+               while ($accounttype=db_fetch($typeresult))
                {
-                       $rep->Line($rep->row - 2);
-                       $rep->NewPage();
+                       display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $from, $to,  $zero, $balances, $dimension, $dimension2);
                }
+               $rep->NewLine();
        }
        $rep->Line($rep->row);
        $rep->NewLine();
        else
                $rep->AmountCol(7, 8, abs($tbal), $dec);
        $rep->NewLine();
--              
-       $rep->Line($rep->row);
-       if (($pbal = round2($pbal, $dec)) != 0.0)
++
+       $rep->Line($rep->row + 10);
+       if (($pbal = round2($pbal, $dec)) != 0.0 && $dimension == 0 && $dimension2 == 0)
        {
                $rep->NewLine(2);
                $rep->Font();
index e52f293395c08b265a20e203b0eb4cce09a88daa,dbe25e5bd59e82f1472f06b0c566ee4e9f055baf..c3cd8e193a4f46ad550e37a477392fb4c8e552c8
@@@ -71,8 -73,8 +73,8 @@@ function getTaxInfo($id
  
  function print_tax_report()
  {
-       global $path_to_root, $trans_dir, $systypes_array;
-       
+       global $path_to_root, $trans_dir, $Hooks, $systypes_array;
 -      
++
        $from = $_POST['PARAM_0'];
        $to = $_POST['PARAM_1'];
        $summaryOnly = $_POST['PARAM_2'];
                        $trans['net_amount'] *= -1;
                        $trans['amount'] *= -1;
                }
--              
++
                if (!$summaryOnly)
                {
                        $rep->TextCol(0, 1, $systypes_array[$trans['trans_type']]);
                        $rep->AmountCol(5, 6, $trans['net_amount'], $dec);
                        $rep->AmountCol(6, 7, $trans['rate'], $dec);
                        $rep->AmountCol(7, 8, $trans['amount'], $dec);
 -                      
 +
+                       $rep->TextCol(9, 10, $trans['taxname']);
                        $rep->NewLine();
  
                        if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
index baeeba36f6141a78718853a0ec89f0a0a0940836,ca27855618aaf47e3298a5fa06d0624075d365f1..e91353097171e968f7aeaa4112cde2d03ddb8fe6
@@@ -156,7 -165,7 +165,7 @@@ $reports->addReport(RC_SUPPLIER, 209, _
                        _('Currency Filter') => 'CURRENCY',
                        _('Email Customers') => 'YES_NO',
                        _('Comments') => 'TEXTBOX'));
--$reports->addReport(RC_SUPPLIER, 210, _('Print Remittances'),
++$reports->addReport(RC_SUPPLIER, 210, _('Print Remi&ttances'),
        array(  _('From') => 'REMITTANCE',
                        _('To') => 'REMITTANCE',
                        _('Currency Filter') => 'CURRENCY',
  $reports->addReportClass(_('Inventory'), RC_INVENTORY);
  
  $reports->addReport(RC_INVENTORY,  301, _('Inventory &Valuation Report'),
-       array(  _('Inventory Category') => 'CATEGORIES',
 -      array(  _('End Date') => 'DATE',        
++      array(  _('End Date') => 'DATE',
+                       _('Inventory Category') => 'CATEGORIES',
                        _('Location') => 'LOCATIONS',
                        _('Summary Only') => 'YES_NO',
                        _('Comments') => 'TEXTBOX',
Simple merge
Simple merge
Simple merge
index 2208a455c6b093539576f0c47c31560799c08288,30e359193d6e25253d0ac1ed60d4084b235cb30b..df8bad06d9ebd4016d13e8f24174a1cf90420c50
@@@ -279,24 -269,35 +270,35 @@@ function check_quantities(
  
  function check_qoh()
  {
-       global $SysPrefs;
-       if (!$SysPrefs->allow_negative_stock()) {
-               foreach ($_SESSION['Items']->line_items as $itm) {
-                       if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) {
-                               $qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
-                               if ($itm->qty_dispatched > $qoh) {
-                                       display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") .
-                                               " " . $itm->stock_id . " - " .  $itm->item_description);
-                                       return false;
-                               }
-                       }
-               }
-       }
-       return true;
+     global $SysPrefs;
+     $dn = &$_SESSION['Items'];
+     $newdelivery = ($dn->trans_no==0);
+     if (!$SysPrefs->allow_negative_stock()) {
+         foreach ($_SESSION['Items']->line_items as $itm) {
+             if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) {
+                 $qoh_by_date = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']);
+                 $qoh_abs = get_qoh_on_date($itm->stock_id, $_POST['Location'], null);
+                 //If editing current delivery delivered qty should be added 
+                 if (!$newdelivery)
+                 {
+                     $delivered = get_already_delivered($itm->stock_id, $_POST['Location'], key($dn->trans_no));
 -                    
++
+                     $qoh_abs = $qoh_abs - $delivered;
+                     $qoh_by_date = $qoh_by_date - $delivered;
+                 }
+                 $qoh = ($qoh_by_date < $qoh_abs ? $qoh_by_date : $qoh_abs); 
+                 if ($itm->qty_dispatched > $qoh) {
+                     display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") .
+                         " " . $itm->stock_id . " - " . $itm->item_description);
+                     return false;
+                 }
+             }
+         }
+     }
+     return true;
  }
  //------------------------------------------------------------------------------
  
  if (isset($_POST['process_delivery']) && check_data() && check_qoh()) {
Simple merge
index 1bf8e196fbb8651ec097eb839d7eba4dc8427292,f5d1f011a5e9a1ec4347023e295c3c45bf721738..e268dd22d73f75d0160416ab27bbb6b05e958ee6
@@@ -183,8 -236,22 +236,22 @@@ if (isset($_POST['_customer_id_button']
  if (isset($_POST['_DateBanked_changed'])) {
    $Ajax->activate('_ex_rate');
  }
- if (list_updated('customer_id') || list_updated('bank_account')) {
+ //Chaitanya : 13-OCT-2011 - To support Edit feature
+ if (isset($_POST['ref']) && $_SESSION['alloc']->trans_no == 0) // added by Joe to fix the browser back button
+ {
+       $tno = get_customer_trans_from_ref(ST_CUSTPAYMENT, $_POST['ref']);
+       if ($tno != false)
+       {
+               display_error( _("The entered reference is already in use."));
+               display_footer_exit();
+       }
 -}             
++}
+ $new = $_SESSION['alloc']->trans_no == 0;
+ if (list_updated('customer_id') || ($new && list_updated('bank_account'))) {
    $_SESSION['alloc']->read();
+   $_POST['memo_'] = $_POST['amount'] = $_POST['discount'] = '';
    $Ajax->activate('alloc_tbl');
  }
  //----------------------------------------------------------------------------------------------
@@@ -244,60 -365,61 +365,60 @@@ start_form()
        read_customer_data();
  
        set_global_customer($_POST['customer_id']);
-       if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0) {
-               end_outer_table();
-               display_error(_("This customer account is on hold."));
-       } else {
-               $display_discount_percent = percent_format($_POST['pymt_discount']*100) . "%";
-               table_section(2);
+       if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0) 
+               display_warning(_("This customer account is on hold."));
+       $display_discount_percent = percent_format($_POST['pymt_discount']*100) . "%";
  
-               bank_accounts_list_row(_("Into Bank Account:"), 'bank_account', null, true);
+       table_section(2);
+       if (!list_updated('bank_account'))
+               $_POST['bank_account'] = get_default_customer_bank_account($_POST['customer_id']);      
  
 -
+       //Chaitanya : 13-OCT-2011 - Is AJAX call really needed ???
+       //bank_accounts_list_row(_("Into Bank Account:"), 'bank_account', null, true);
+       bank_accounts_list_row(_("Into Bank Account:"), 'bank_account', null, false);
+       text_row(_("Reference:"), 'ref', null, 20, 40);
  
-               text_row(_("Reference:"), 'ref', null, 20, 40);
+       table_section(3);
  
-               table_section(3);
+       date_row(_("Date of Deposit:"), 'DateBanked', '', true, 0, 0, 0, null, true);
  
-               date_row(_("Date of Deposit:"), 'DateBanked', '', true, 0, 0, 0, null, true);
-               $comp_currency = get_company_currency();
-               $cust_currency = get_customer_currency($_POST['customer_id']);
-               $bank_currency = get_bank_account_currency($_POST['bank_account']);
+       $comp_currency = get_company_currency();
+       $cust_currency = get_customer_currency($_POST['customer_id']);
+       $bank_currency = get_bank_account_currency($_POST['bank_account']);
  
-               if ($cust_currency != $bank_currency) {
-                       exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], ($bank_currency == $comp_currency));
-               }
+       if ($cust_currency != $bank_currency) {
+               exchange_rate_display($bank_currency, $cust_currency, $_POST['DateBanked'], ($bank_currency == $comp_currency));
+       }
  
-               amount_row(_("Bank Charge:"), 'charge');
+       amount_row(_("Bank Charge:"), 'charge');
  
-               end_outer_table(1);
+       end_outer_table(1);
  
-               if ($cust_currency == $bank_currency) {
-                       div_start('alloc_tbl');
-                       show_allocatable(false);
-                       div_end();
-               }
+       if ($cust_currency == $bank_currency) {
+               div_start('alloc_tbl');
+               show_allocatable(false);
+               div_end();
+       }
  
-               start_table(TABLESTYLE, "width=60%");
+       start_table(TABLESTYLE, "width=60%");
  
-               label_row(_("Customer prompt payment discount :"), $display_discount_percent);
-               amount_row(_("Amount of Discount:"), 'discount');
+       label_row(_("Customer prompt payment discount :"), $display_discount_percent);
+       amount_row(_("Amount of Discount:"), 'discount');
  
-               amount_row(_("Amount:"), 'amount');
+       amount_row(_("Amount:"), 'amount');
  
-               textarea_row(_("Memo:"), 'memo_', null, 22, 4);
-               end_table(1);
+       textarea_row(_("Memo:"), 'memo_', null, 22, 4);
+       end_table(1);
  
-               if ($cust_currency != $bank_currency)
-                       display_note(_("Amount and discount are in customer's currency."));
+       if ($cust_currency != $bank_currency)
+               display_note(_("Amount and discount are in customer's currency."));
  
-               br();
+       br();
  
+       if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0 )
+               submit_center('AddPaymentItem', _("Update Payment"), true, '', 'default');
+       else
                submit_center('AddPaymentItem', _("Add Payment"), true, '', 'default');
-       }
  
        br();
  
index 46f8d5009436fa31661a8b86d8b42655aed4b96b,cc7d15675b660a8437f6f08c7e8fbd94c0d6d58c..062d9bad732a49529f6b417d2af54dce4e625a9f
@@@ -77,10 -75,10 +77,10 @@@ class car
        //-------------------------------------------------------------------------
        //
        //  $trans_no==0 => open new/direct document
 -      //  $trans_no!=0 && $prep_child==false => update with parent constarints for reedition
 -      //  $trans_no!=0 && $prep_child==true => prepare for child doc entry
 +      //  $trans_no!=0 && $no_edit==false => update with parent constarints for reedition
 +      //  $trans_no!=0 && $no_edit==true => read only: for view, or later child doc entry
        //
-       function Cart($type, $trans_no=0, $no_edit=false) {
+       function Cart($type, $trans_no=0, $prep_child=false) {
                /*Constructor function initialises a new shopping cart */
                $this->line_items = array();
                $this->sales_type = "";
Simple merge
Simple merge
index bd5b8d34583d578cbd52ef80ba43df2b31ee16c0,3a67e4edb895d29189e5307c8e526ff328066ca9..21ce5e41e871791fbf20d96f99a70ad6baed339b
@@@ -24,7 -24,7 +24,6 @@@ function add_customer($CustName, $cust_
                " . db_escape($credit_status) . ", ".db_escape($payment_terms) . ", " . $discount . ", 
                " . $pymt_discount . ", " . $credit_limit 
                 .", ".db_escape($sales_type).", ".db_escape($notes) . ")";
--
        db_query($sql,"The customer could not be added");
  }
  
Simple merge
index a13109f0e7c91dd37ee8fc13b55d95f49cc53d0c,558b2159aba0159fd9a1bad9c8e0a000ad275cfd..ecaf4466f9bb5f6d1b42c195d56cad1bcac13613
@@@ -146,9 -146,9 +146,10 @@@ function write_sales_invoice(&$invoice
                                $taxitem['rate'], $invoice->tax_included, $taxitem['Value'],
                                 $taxitem['Net'], $ex_rate, $date_, $invoice->reference);
  
--                      $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
--                              (-$taxitem['Value']), $invoice->customer_id,
--                              "A tax GL posting could not be inserted");
++                      if (isset($taxitem['sales_gl_code']))
++                              $total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
++                                      (-$taxitem['Value']), $invoice->customer_id,
++                                      "A tax GL posting could not be inserted");
                }
        }
  
index eb5665ab71c46165a324d3da8c31661bc826855d,e4eaa5c15a4d69908b393cad61ea32a49e6feb6b..386e3b86b2a1213d8d6419ab2ad9998d0efa4056
@@@ -87,11 -87,13 +87,16 @@@ function add_sales_order(&$order
                                $line->discount_percent)";
                db_query($sql, "order Details Cannot be Added");
  
+       // Now mark quotation line as processed
+               if ($order->trans_type == ST_SALESORDER && $line->src_id)
+                       update_parent_line(ST_SALESORDER, $line->src_id, $line->qty_dispatched); // clear all the quote despite all or the part was ordered
        } /* inserted line items into sales order details */
+       add_audit_trail($order->trans_type, $order_no, $order->document_date);
+       $Refs->save($order->trans_type, $order_no, $order->reference);
  
 +      add_audit_trail($order->trans_type, $order_no, $order->document_date);
 +      $Refs->save($order->trans_type, $order_no, $order->reference);
 +
        hook_db_postwrite($order, $order->trans_type);
        commit_transaction();
  
@@@ -546,17 -552,22 +555,22 @@@ function get_sql_for_sales_orders_view(
                if ($selected_customer != -1)
                        $sql .= " AND sorder.debtor_no=".db_escape($selected_customer);
  
-               if (isset($selected_stock_item))
-                       $sql .= " AND line.stk_code=".db_escape($selected_stock_item);
+               if (isset($stock_item))
+                       $sql .= " AND line.stk_code=".db_escape($stock_item);
  
-               if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT)
-                       $sql .= " AND sorder.from_stk_loc = ".db_escape($_POST['StockLocation']);
+               if ($location)
+                       $sql .= " AND sorder.from_stk_loc = ".db_escape($location);
  
-               if ($_POST['order_view_mode']=='OutstandingOnly')
+               if ($filter=='OutstandingOnly')
                        $sql .= " AND line.qty_sent < line.quantity";
-               elseif ($_POST['order_view_mode']=='InvoiceTemplates' || $_POST['order_view_mode']=='DeliveryTemplates')
+               elseif ($filter=='InvoiceTemplates' || $filter=='DeliveryTemplates')
                        $sql .= " AND sorder.type=1";
 -                      
 +
+               //Chaiatanya : New Filter
+               if ($customer_id != ALL_TEXT)
+                       $sql .= " AND sorder.debtor_no = ".db_escape($customer_id);             
                $sql .= " GROUP BY sorder.order_no,
                                        sorder.debtor_no,
                                        sorder.branch_code,
index bcafeecc13c1b1d799a22271e3ca2db8c5ef2340,3ebc84b5c0b624034f7904947c314836bb126cb5..d8a000c1866431d7d4ba3fc857adfe104a9b805f
@@@ -18,14 -18,16 +18,13 @@@ include_once($path_to_root . "/sales/in
  include_once($path_to_root . "/sales/includes/sales_db.inc");
  include_once($path_to_root . "/reporting/includes/reporting.inc");
  
 -if (!@$_GET['popup'])
 -{
 -      $js = "";
 -      if ($use_popup_windows)
 -              $js .= get_js_open_window(900, 500);
 -      if ($use_date_picker)
 -              $js .= get_js_date_picker();
 -      page(_($help_context = "Customer Transactions"), isset($_GET['customer_id']), false, "", $js);
 -}
 +$js = "";
 +if ($use_popup_windows)
 +      $js .= get_js_open_window(900, 500);
 +if ($use_date_picker)
 +      $js .= get_js_date_picker();
 +page(_($help_context = "Customer Transactions"), isset($_GET['customer_id']), false, "", $js);
  
  if (isset($_GET['customer_id']))
  {
        $_POST['customer_id'] = $_GET['customer_id'];
@@@ -41,7 -44,8 +40,8 @@@ if (!isset($_POST['customer_id'])
  start_table(TABLESTYLE_NOBORDER);
  start_row();
  
- customer_list_cells(_("Select a customer: "), 'customer_id', null, true);
 -if (!@$_GET['popup'])
++if (!$page_nested)
+       customer_list_cells(_("Select a customer: "), 'customer_id', null, true, false, false, !@$_GET['popup']);
  
  date_cells(_("From:"), 'TransAfterDate', '', null, -30);
  date_cells(_("To:"), 'TransToDate', '', null, 1);
@@@ -154,6 -158,8 +154,10 @@@ function fmt_credit($row
  
  function credit_link($row)
  {
 -      if (@$_GET['popup'])
++      global $page_nested;
++      
++      if ($page_nested)
+               return '';
        return $row['type'] == ST_SALESINVOICE && $row["Outstanding"] > 0 ?
                pager_link(_("Credit This") ,
                        "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT):'';
  
  function edit_link($row)
  {
- /*    $str = '';
-       switch($row['type']) {
-       case ST_SALESINVOICE:
-               if (get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) === false && $row['Allocated'] == 0)
-                       $str = "/sales/customer_invoice.php?ModifyInvoice=".$row['trans_no'];
-               break;
-       case ST_CUSTCREDIT:
-               if (get_voided_entry(ST_CUSTCREDIT, $row["trans_no"]) === false && $row['Allocated'] == 0) // 2008-11-19 Joe Hunt
-               {        
-                       if ($row['order_']==0) // free-hand credit note
-                           $str = "/sales/credit_note_entry.php?ModifyCredit=".$row['trans_no'];
-                       else    // credit invoice
-                           $str = "/sales/customer_credit_invoice.php?ModifyCredit=".$row['trans_no'];
-               }           
-               break;
-        case ST_CUSTDELIVERY:
-               if (get_voided_entry(ST_CUSTDELIVERY, $row["trans_no"]) === false)
-                       $str = "/sales/customer_delivery.php?ModifyDelivery=".$row['trans_no'];
-               break;
-       }
-       if ($str != '')
- */            return edit_trans_link($row['type'], $row['trans_no'], $row['type']==ST_CUSTCREDIT && $row['order_']==0 ?
-                       "/sales/credit_note_entry.php?ModifyCredit=%d" : 0);
 -      $str = '';
++      global $page_nested;
 -      if (@$_GET['popup'])
++      $str = '';
++      if ($page_nested)
+               return '';
 -      switch($row['type']) {
 -      case ST_SALESINVOICE:
 -              if (get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) === false && $row['Allocated'] == 0)
 -                      $str = "/sales/customer_invoice.php?ModifyInvoice=".$row['trans_no'];
 -              break;
 -      case ST_CUSTCREDIT:
 -              if (get_voided_entry(ST_CUSTCREDIT, $row["trans_no"]) === false && $row['Allocated'] == 0) // 2008-11-19 Joe Hunt
 -              {        
 -                      if ($row['order_']==0) // free-hand credit note
 -                          $str = "/sales/credit_note_entry.php?ModifyCredit=".$row['trans_no'];
 -                      else    // credit invoice
 -                          $str = "/sales/customer_credit_invoice.php?ModifyCredit=".$row['trans_no'];
 -              }           
 -              break;
 -      case ST_CUSTDELIVERY:
 -              if (get_voided_entry(ST_CUSTDELIVERY, $row["trans_no"]) === false)
 -                      $str = "/sales/customer_delivery.php?ModifyDelivery=".$row['trans_no'];
 -              break;
 -      case ST_CUSTPAYMENT:
 -              if (get_voided_entry(ST_CUSTPAYMENT, $row["trans_no"]) === false)
 -                      $str = "/sales/customer_payments.php?trans_no=".$row['trans_no'];
 -              break;
 -      }               
 -      if ($str != "" && !is_closed_trans($row['type'], $row["trans_no"]))
 -              return pager_link(_('Edit'), $str, ICON_EDIT);
 -      return '';      
++
++      return edit_trans_link($row['type'], $row['trans_no'], $row['type']==ST_CUSTCREDIT && $row['order_']==0 ?
++              "/sales/credit_note_entry.php?ModifyCredit=%d" : 0);
  }
  
  function prt_link($row)
@@@ -242,7 -254,9 +230,6 @@@ $table->width = "85%"
  
  display_db_pager($table);
  
 -if (!@$_GET['popup'])
 -{
 -      end_form();
 -      end_page(@$_GET['popup'], false, false);
 -}
 +end_form();
 +end_page();
  ?>
index 53de2699fbf05f87d8ee84d2084972640247423c,f59be9c028bb5de375939bc49421bd8c3b1dbdb1..281e3a5f548482877ac3c35e68fb556357e3172b
@@@ -66,7 -60,16 +60,13 @@@ els
        $_POST['order_view_mode'] = "Quotations";
        $_SESSION['page_title'] = _($help_context = "Search All Sales Quotations");
  }
 -if (!@$_GET['popup'])
 -{
 -      $js = "";
 -      if ($use_popup_windows)
 -              $js .= get_js_open_window(900, 600);
 -      if ($use_date_picker)
 -              $js .= get_js_date_picker();
 -      page($_SESSION['page_title'], false, false, "", $js);
 -}
++$js = "";
++if ($use_popup_windows)
++      $js .= get_js_open_window(900, 600);
++if ($use_date_picker)
++      $js .= get_js_date_picker();
 +page($_SESSION['page_title'], false, false, "", $js);
  
  if (isset($_GET['selected_customer']))
  {
@@@ -118,6 -121,8 +118,10 @@@ function prt_link($row
  
  function edit_link($row) 
  {
 -      if (@$_GET['popup'])\r
 -              return '';\r
++      global $page_nested;
++      
++      if ($page_nested)
++              return '';
        global $trans_type;
        $modify = ($trans_type == ST_SALESORDER ? "ModifyOrderNumber" : "ModifyQuotationNumber");
    return pager_link( _("Edit"),
@@@ -159,9 -164,11 +163,12 @@@ function order_link($row
  
  function tmpl_checkbox($row)
  {
--      global $trans_type;
++      global $trans_type, $page_nested;
        if ($trans_type == ST_SALESQUOTE)
                return '';
 -      if (@$_GET['popup'])\r
 -              return '';\r
++
++      if ($page_nested)
++              return '';
        $name = "chgtpl" .$row['order_no'];
        $value = $row['type'] ? 1:0;
  
@@@ -230,14 -230,17 +229,17 @@@ if ($show_dates
        date_cells(_("to:"), 'OrdersToDate', '', null, 1);
  }
  locations_list_cells(_("Location:"), 'StockLocation', null, true);
- end_row();
- end_table();
  
- start_table(TABLESTYLE_NOBORDER);
- start_row();
+ if($show_dates) {
+       end_row();
+       end_table();
  
+       start_table(TABLESTYLE_NOBORDER);
+       start_row();
+ }
  stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
 -if (!@$_GET['popup'])\r
 -      customer_list_cells(_("Select a customer: "), 'customer_id', null, true);\r
++if (!@$_GET['popup'])
++      customer_list_cells(_("Select a customer: "), 'customer_id', null, true);
  if ($trans_type == ST_SALESQUOTE)
        check_cells(_("Show All:"), 'show_all');
  
@@@ -251,7 -254,8 +253,8 @@@ end_table(1)
  //---------------------------------------------------------------------------------------------
  //    Orders inquiry table
  //
- $sql = get_sql_for_sales_orders_view($selected_customer, $trans_type);
+ $sql = get_sql_for_sales_orders_view($selected_customer, $trans_type, $_POST['OrderNumber'], $_POST['order_view_mode'],
 -      @$selected_stock_item, @$_POST['OrdersAfterDate'], @$_POST['OrdersToDate'], @$_POST['OrderReference'], $_POST['StockLocation'], $_POST['customer_id']);\r
++      @$selected_stock_item, @$_POST['OrdersAfterDate'], @$_POST['OrdersToDate'], @$_POST['OrderReference'], $_POST['StockLocation'], $_POST['customer_id']);
  
  if ($trans_type == ST_SALESORDER)
        $cols = array(
@@@ -281,9 -285,11 +284,11 @@@ els
                'Type' => 'skip',
                _("Currency") => array('align'=>'center')
        );
 -if ($_POST['order_view_mode'] == 'OutstandingOnly') {\r
 -      //array_substitute($cols, 3, 1, _("Cust Order Ref"));\r
 -      array_append($cols, array(\r
 -              array('insert'=>true, 'fun'=>'dispatch_link'),\r
 -              array('insert'=>true, 'fun'=>'edit_link')));\r
 +if ($_POST['order_view_mode'] == 'OutstandingOnly') {
 +      //array_substitute($cols, 3, 1, _("Cust Order Ref"));
-       array_append($cols, array(array('insert'=>true, 'fun'=>'dispatch_link')));
++      array_append($cols, array(
++              array('insert'=>true, 'fun'=>'dispatch_link'),
++              array('insert'=>true, 'fun'=>'edit_link')));
  
  } elseif ($_POST['order_view_mode'] == 'InvoiceTemplates') {
        array_substitute($cols, 3, 1, _("Description"));
Simple merge
index 133505304e1b962ae7ee23b283e6044d020e5d98,41c642ac760ae5e964c9c0e00157c7491c258ad9..af14b9a6af09421cd6bad62a1f3b60b31bfe701e
  $page_security = 'SA_CUSTOMER';
  $path_to_root = "../..";
  
 -include($path_to_root . "/includes/db_pager.inc");
++include_once($path_to_root . "/includes/db_pager.inc");
  include_once($path_to_root . "/includes/session.inc");
- page(_($help_context = "Customers"), @$_REQUEST['popup']); 
+ $js = "";
+ if ($use_popup_windows)
+       $js .= get_js_open_window(900, 500);
+ if ($use_date_picker)
+       $js .= get_js_date_picker();
+       
+ page(_($help_context = "Customers"), @$_REQUEST['popup'], false, "", $js); 
  
  include_once($path_to_root . "/includes/date_functions.inc");
  include_once($path_to_root . "/includes/banking.inc");
@@@ -310,7 -354,16 +354,14 @@@ tabbed_content_start('tabs', array
                        $contacts = new contacts('contacts', $selected_id, 'customer');
                        $contacts->show();
                        break;
 -                      $_GET['popup'] = 1;
+               case 'transactions':
+                       $_GET['customer_id'] = $selected_id;
+                       include_once($path_to_root."/sales/inquiry/customer_inquiry.php");
+                       break;
                case 'orders':
 -                      $_GET['popup'] = 1;
+                       $_GET['customer_id'] = $selected_id;
+                       include_once($path_to_root."/sales/inquiry/sales_orders_view.php");
+                       break;
        };
  br();
  tabbed_content_end();
Simple merge
index ff88393cf4c5b86e9f2fae197397ee7f0efaba14,405f1d6653589024b7e0fe315783a511644136f6..712c5470981912b20319bbf9d06120b90a07db7c
@@@ -39,13 -39,14 +39,14 @@@ if (isset($_SESSION['View'])
        unset ($_SESSION['View']);
  }
  
 -$_SESSION['View'] = new Cart($_GET['trans_type'], $_GET['trans_no']);
 +$_SESSION['View'] = new Cart($_GET['trans_type'], $_GET['trans_no'], true);
  
  start_table(TABLESTYLE2, "width=95%", 5);
- echo "<tr valign=top><td>";
- display_heading2(_("Order Information"));
  if ($_GET['trans_type'] != ST_SALESQUOTE)
  {
+       echo "<tr valign=top><td>";
+       display_heading2(_("Order Information"));
        echo "</td><td>";
        display_heading2(_("Deliveries"));
        echo "</td><td>";
index c4071f974556e360b71ac35b89a27b7c2c0f5aaf,2a517deb7321b79314cfa9ab6812bfaef9de01e3..7705f261fd221251ee7c96f935282e82354a887a
@@@ -34,8 -35,8 +35,8 @@@ class fa2_3 
                if (!$this->beta) {
                        // all specials below are already done on 2.3beta
  
 -                      $sql = "SELECT debtor_no, payment_terms FROM {$pref}debtors_master";
 -              
 +                      $sql = "SELECT debtor_no, payment_terms FROM ".TB_PREF."debtors_master";
-               
++
                        $result = db_query($sql);
                        if (!$result) {
                                display_error("Cannot read customers"
Simple merge
Simple merge
index dbb7999e46f0548cf576ac9380755533abf13f37,4c4b9f37c5a7ea047e6a4d908d3a3c7f5502c107..27b1ccfadeca21a750a35021d06aede635a18ee7
@@@ -37,6 -36,6 +36,7 @@@ function get_tax_free_price_for_item($s
        //print_r($ret_tax_array);
  
        $tax_array = get_taxes_for_item($stock_id, $ret_tax_array);
++
        // if no exemptions or taxgroup is empty, then no included/excluded taxes
        if ($tax_array == null)
                return $price;
@@@ -150,34 -150,37 +153,49 @@@ function get_tax_for_items($items, $pri
        else
          $ret_tax_array = get_tax_group_items_as_array($tax_group);
  
++      $dec = user_price_dec();
++
++      $fully_exempt = true;
        foreach($ret_tax_array as $k=>$t)
++      {
++              if ($t['rate'] !== null)
++                      $fully_exempt = false;
                $ret_tax_array[$k]['Net'] = 0;
++      }
  
++      $ret_tax_array['exempt'] = array('Value'=>0, 'Net'=>0, 'rate' => null, 'tax_type_id' => '');
        $dec = user_price_dec();
        // loop for all items
        for ($i = 0; $i < count($items); $i++)
        {
                $item_taxes = get_taxes_for_item($items[$i], $ret_tax_array);
--              if ($item_taxes != null) 
++              if ($item_taxes == null || $fully_exempt) 
 +              {
++                        $ret_tax_array['exempt']['Value'] += round2(0, $dec);
++                        $ret_tax_array['exempt']['Net'] += $prices[$i];
++              }
++              else
+               {
+                       $tax_multiplier = 0;
+                       foreach ($item_taxes as $taxitem) 
+                       {
+                               $tax_multiplier += $taxitem['rate'];
+                       }
                        foreach ($item_taxes as $item_tax) 
                        {
                                if ($item_tax['rate'] !== null) {
                                        $index = $item_tax['tax_type_id'];
-                                       if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings
-                                         $nprice = get_tax_free_price_for_item($items[$i], $prices[$i], $tax_group, $tax_included, null, $item_tax['tax_type_id']);
-                                         $ret_tax_array[$index]['Value'] += $nprice*$item_tax['rate']/100;
-                                         $ret_tax_array[$index]['Net'] += $nprice;
+                                       if ($tax_included == 1) {
+                                         $ret_tax_array[$index]['Value'] += round2($prices[$i]*$item_tax['rate']/(100+$tax_multiplier), $dec);
+                                         $ret_tax_array[$index]['Net'] += round2($prices[$i]*100/(100+$tax_multiplier), $dec);
                                        } else {
--                                        $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100);
++                                        $ret_tax_array[$index]['Value'] += round2($prices[$i] * $item_tax['rate'] / 100, $dec);
                                          $ret_tax_array[$index]['Net'] += $prices[$i];
                                        }
                                }
                        }
                }
        }
-       
 -
        // add the shipping taxes, only if non-zero, and only if tax group taxes shipping
        if ($shipping_cost != 0) 
        {
                        {
                                $index = $item_tax['tax_type_id'];
                                if ($item_tax['rate'] !== null && $ret_tax_array[$index]['rate'] !== null) {
-                                         if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings
-                                               $ret_tax_array[$index]['Value'] += ($shipping_net * $item_tax['rate'] / 100);
+                                         if($tax_included==1) {
+                                           $ret_tax_array[$index]['Value'] += round2($shipping_cost*$item_tax['rate']/(100+$tax_rate), $dec);
                                            $ret_tax_array[$index]['Net'] += $shipping_net;
                                          } else {
--                                              $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / 100);
++                                              $ret_tax_array[$index]['Value'] += round2($shipping_cost * $item_tax['rate'] / 100, $dec);
                                            $ret_tax_array[$index]['Net'] += $shipping_cost;
                                          }
                                }
                        }
                }
        }
-       
 -      //print_r($ret_tax_array);
++
 +      if ($tax_algorithm == TCA_TOTALS ) {
 +              // update taxes with 
 +              foreach($ret_tax_array as $index => $item_tax) {
 +                      $ret_tax_array[$index]['Value'] = round2($item_tax['Net'] * $item_tax['rate'] / 100, $dec);
 +              }
 +      }
  
        return $ret_tax_array;
  }
diff --cc update.html
index 6cdf420bb6dcc273b64be4f1c4eeb2a1290077ca,efa23202a2922c5b4f36d5178d4587457272e342..3af13a0ed2c90e66fd6986353990c285d0cd2036
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 -<html><head>\r
 -      <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-2">\r
 -      \r
 -      <title>FrontAccounting Update</title><meta name="GENERATOR" content="OpenOffice.org 2.4  (Linux)">\r
 -      <meta name="CREATED" content="0;0">\r
 -      <meta name="CHANGED" content="20100902;19041400"></head>\r
 -<body dir="ltr" lang="en-US">\r
 -<p style="margin-bottom: 0cm;"><strong><font color="#cc6600"><font style="font-size: 20pt;" size="5"><i>Front</i></font></font></strong><strong><font style="font-size: 20pt;" size="5">Accounting\r
 -Update</font></strong></p>\r
 -<h2>Important Notes for release 2.3.5.</h2>Change in the behaviour of <span style="font-weight: bold; font-style: italic;">Recurrent Invoices</span>.<br><ul><li>Now\r
 -the Last Sent day is stamped with the former Last Sent (or Begin date\r
 -the first time) + months + days. Before the Last Sent day was stamped\r
 -with tthe creation date (today). The Invoice date is still todays date.\r
 -</li><li>If you for some reason want to make a pause in the recurrent\r
 -invoices, you can now edit the Last Sent day in the Management section\r
 -of Sales tab.</li><li>Before the days value, together with a month\r
 -value, decided which day in the month the invoice was due.. &nbsp;This\r
 -does not&nbsp;work now. You can&nbsp;change the day in the month you\r
 -want the recurrency to happen by setting the Last Sent day with the new\r
 -day in the Management section.&nbsp;</li><li>If you create a new Recurrent Invoice the Beginning date can be set to the day in the month you want the recurrencies to be due.</li></ul>\r
 -<h2>Important Notes</h2>\r
 -<p>Upgrade process can be done only by administrator of the first\r
 -company created during FrontAccounting installation. This person is\r
 -considered as a site admin who have granted access to potentially\r
 -dangerous setup options, like Setup/Software Upgrade.</p>\r
 -<p>In the following description sections related to older FA versions are\r
 -prefixed with <span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[color tags]</span><span style="background: transparent none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">\r
 -. Y</span>ou can skip tagged fragment safely if currently FA\r
 -application is newer than the version in tag.</p>\r
 -<p>Upgrade process consists of up to four stages, some of them are\r
 -optional:</p>\r
 -<ol>\r
 -      <li><p>Application source files update \r
 -      </p>\r
 -      </li><li><p>Database upgrade &#8211; this step is needed only during\r
 -      upgrade which involves change in major application version number\r
 -      (e.g. from 2.2.x to 2.3.x), and sometimes during upgrade from beta\r
 -      release to stable version. Otherwise this step can be skipped.</p>\r
 -      </li><li><p>Final cleanup &#8211; is needed when some old source files,\r
 -      obsoleted by new release should be removed.</p>\r
 -      </li><li><p>New features configuration &#8211; this is optional step\r
 -      needed for most major releases and some minor ones. \r
 -      </p>\r
 -</li></ol>\r
 -<p style="margin-bottom: 0cm;">Before starting upgrade ensure nobody\r
 -is using the application and make database backup for all companies.\r
 -To be on safe side backup also old source files, especially those\r
 -locally customized (if any).</p>\r
 -<p>Log into admin account of first company.<strong> </strong><strong><span style="">If\r
 -you use a theme other than the standard 3 (aqua, cool or default),\r
 -switch to one of these before going further.</span></strong></p>\r
 -<h2><strong><b>1. Application files update</b></strong></h2>\r
 -<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4"><strong><span style="">a. Source\r
 -files update</span></strong></font></font></p>\r
 -<p><strong><span style="">Extract distribution\r
 -zip/tar.gz file in empty directory, and copy all the files to your\r
 -FrontAccounting directory overwriting old files. If it is major\r
 -release upgrade you can skip next step and go directly to cleanup.</span></strong></p>\r
 -<p style="margin-top: 0.42cm; page-break-after: avoid;"><strong><font face="Liberation Sans, sans-serif"><font size="4"><span style="">b. Configuration\r
 -files update</span></font></font></strong></p>\r
 -<p><strong><span style="">Compare new\r
 -</span></strong><strong><i><b>config.default.php</b></i></strong><strong>\r
 -</strong><strong><span style="">file with the old\r
 -</span></strong><strong><i><b>config.php </b></i></strong><strong><span style="font-style: normal;"><span style="">and\r
 -add all n</span></span></strong><strong><span style="">ew\r
 -settings (if any). </span></strong>\r
 -</p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.2beta]</span></span></strong></p>\r
 -<p><strong> <span style="">$show_users_online = 0;</span></strong></p>\r
 -<p><strong> <span style="">$def_print_destination\r
 -= 0;</span></strong></p>\r
 -<p><strong><span style="">$dflt_date_fmt=0;</span></strong></p>\r
 -<p><strong><span style="">$dflt_date_sep=0;</span></strong></p>\r
 -<p><strong><span style="">$table_style,table_style2\r
 -changed</span></strong></p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.3beta]</span></span></strong></p>\r
 -<p><strong> <span style="">$alternative_tax_include_on_doc=0;</span></strong></p>\r
 -<p><strong><span style="">$suppress_tax_rates = 0;</span></strong></p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.3RC1]</span></span></strong><strong> </strong>\r
 -</p>\r
 -<p><strong><span style="">Application version\r
 -information and a couple of other private FA variables are stored in\r
 -</span></strong><strong><i><b>version.php</b></i></strong><strong>\r
 -</strong><strong><span style="">file. The\r
 -application version displayed in footer is defined in $version\r
 -variable unless this is set in config.php file. If you want current\r
 -release version to be displayed on every FA update just remove or\r
 -comment out $version variable in </span></strong><strong><span style="font-style: normal;"><span style="">config.php</span></span></strong><strong><span style="">.</span></strong></p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.3RC2]</span></span></strong></p>\r
 -<p><strong> <span style="">$save_report_selections &nbsp;= 0; &nbsp;// A value &gt; 0 means days to save the report selections.</span></strong></p><p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.3]</span></span></strong></p><p><strong> <span style="">$save_po_item_codes &nbsp;= 0; &nbsp;//&nbsp; show item codes on purchase order&nbsp;</span></strong></p><p><strong><span style="">$def_print_destination = 0; // &nbsp;default print destination. 0 = PDF/Printer, 1 = Excel</span></strong></p><p><strong><span style="">$alternative_tax_include_on_docs = 0; // &nbsp;1 = print Subtotal tax excluded, tax and Total tax included</span></strong></p><p><strong><span style="">$suppress_tax_rates = 0; // &nbsp;suppress tax rates on documents. 0 = no, 1 = yes.</span></strong></p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"></span></span></strong>\r
 -\r
 -<strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"></span></span></strong><h2><strong><b>2. Database upgrade</b></strong></h2>\r
 -<p><strong><span style="">This step can be skipped\r
 -for small version updates i.e. when you have already installed\r
 -FrontAccounting version 2.3.1 or later. Before database upgrade is\r
 -done on all company databases backup file is created automatically to\r
 -enable database restore after failure.</span></strong></p>\r
 -<p><strong><span style="">After major version\r
 -upgrade overwriting files in first step makes the system unaccessible\r
 -for all users but site admin, who have to run upgrade procedures to\r
 -update all company databases to the new version provided with the\r
 -release. After logging to administrator account of first installed\r
 -company go directly to Setup/Software Upgrade screen, mark all\r
 -subsequent 'Install' checkboxes and press 'Upgrade System'.</span></strong></p>\r
 -<p style="">If something goes wrong during\r
 -upgrade, you can eventually try forced upgrade option. Forced upgrade\r
 -ignores some smaller errors which can arise during upgrade due to\r
 -some exotic database configuration. This is depreciated option, so\r
 -first read error messages if any, try to fix signalized problems,\r
 -restore databases from backup and retry normal installation. To run\r
 -upgrade in forced mode check box 'Force Upgrade', and press 'Upgrade\r
 -System' again.</p>\r
 -<h2>3. Final cleanup</h2>\r
 -<p>Remove or rename install folder in main FrontAccounting directory.\r
 -</p>\r
 -<p>After upgrade is installed you can remove files obsoleted by new\r
 -FrontAccounting version. Also old, unused settings <span style="font-style: normal;"><span style="">can\r
 -be removed from  </span></span><i><b>config.php</b></i><span style="font-style: normal;"><span style="">\r
 -file.</span></span></p>\r
 -<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4">a.\r
 -Source files cleanup</font></font></p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.2beta]</span></span></strong></p>\r
 -<p><strong><span style=""><span style="background: transparent none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">/includes/reserved.inc\r
 -&#8211; removed.</span></span></strong></p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.1]</span></span></strong><strong> </strong>\r
 -</p>\r
 -<p><strong><span style="">/admin/db/v_banktrans.inc\r
 -- removed</span></strong></p>\r
 -<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4"><span style="font-style: normal;"><span style="">b.\r
 -Config.php cleanup </span></span></font></font>\r
 -</p>\r
 -<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA\r
 -2.2RC1]</span></span></strong><strong> </strong>\r
 -</p>\r
 -<p><strong><span style="">$security_headings,\r
 -$security_groups arrays &#8211; moved to database (see Access Setup) \r
 -</span></strong>\r
 -</p>\r
 -<p><strong><span style="">$def_app &#8211; moved\r
 -to user configuration in database.</span></strong></p>\r
 -<p><strong><span style="font-style: normal;"><span style="">$version\r
 -&#8211; moved to </span></span></strong><strong><i><b>version.php</b></i></strong><strong><span style="font-style: normal;"><span style="">\r
 -file. Remove</span></span></strong></p>\r
 -<h2>4. New features configuration</h2>\r
 -<p>During upgrade process new features are initialized to default\r
 -status, and sometimes old settings are also changed to conform with\r
 -new security policy. This automatic process is designed to be as\r
 -neutral for end users as possible, however sometimes site or company\r
 -admin intervention can be necessary to set thing after changes to\r
 -their best state. Below you will find description of new settings\r
 -available after upgrade.</p>\r
 -<p><br><br>\r
 -</p>\r
 -<p>----------------------</p>\r
 -<ul></ul>\r
 +<html><head>
 +      <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-2">
 +      
 +      <title>FrontAccounting Update</title><meta name="GENERATOR" content="OpenOffice.org 2.4  (Linux)">
 +      <meta name="CREATED" content="0;0">
 +      <meta name="CHANGED" content="20100902;19041400"></head>
 +<body dir="ltr" lang="en-US">
 +<p style="margin-bottom: 0cm;"><strong><font color="#cc6600"><font style="font-size: 20pt;" size="5"><i>Front</i></font></font></strong><strong><font style="font-size: 20pt;" size="5">Accounting
 +Update</font></strong></p>
++<h2>Important Notes for release 2.3.5.</h2>Change in the behaviour of <span style="font-weight: bold; font-style: italic;">Recurrent Invoices</span>.<br><ul><li>Now
++the Last Sent day is stamped with the former Last Sent (or Begin date
++the first time) + months + days. Before the Last Sent day was stamped
++with tthe creation date (today). The Invoice date is still todays date.
++</li><li>If you for some reason want to make a pause in the recurrent
++invoices, you can now edit the Last Sent day in the Management section
++of Sales tab.</li><li>Before the days value, together with a month
++value, decided which day in the month the invoice was due.. &nbsp;This
++does not&nbsp;work now. You can&nbsp;change the day in the month you
++want the recurrency to happen by setting the Last Sent day with the new
++day in the Management section.&nbsp;</li><li>If you create a new Recurrent Invoice the Beginning date can be set to the day in the month you want the recurrencies to be due.</li></ul>
 +<h2>Important Notes</h2>
 +<p>Upgrade process can be done only by administrator of the first
 +company created during FrontAccounting installation. This person is
 +considered as a site admin who have granted access to potentially
 +dangerous setup options, like Setup/Software Upgrade.</p>
 +<p>In the following description sections related to older FA versions are
 +prefixed with <span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[color tags]</span><span style="background: transparent none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">
 +. Y</span>ou can skip tagged fragment safely if currently FA
 +application is newer than the version in tag.</p>
 +<p>Upgrade process consists of up to four stages, some of them are
 +optional:</p>
 +<ol>
 +      <li><p>Application source files update 
 +      </p>
 +      </li><li><p>Database upgrade &#8211; this step is needed only during
 +      upgrade which involves change in major application version number
 +      (e.g. from 2.2.x to 2.3.x), and sometimes during upgrade from beta
 +      release to stable version. Otherwise this step can be skipped.</p>
 +      </li><li><p>Final cleanup &#8211; is needed when some old source files,
 +      obsoleted by new release should be removed.</p>
 +      </li><li><p>New features configuration &#8211; this is optional step
 +      needed for most major releases and some minor ones. 
 +      </p>
 +</li></ol>
 +<p style="margin-bottom: 0cm;">Before starting upgrade ensure nobody
 +is using the application and make database backup for all companies.
 +To be on safe side backup also old source files, especially those
 +locally customized (if any).</p>
 +<p>Log into admin account of first company.<strong> </strong><strong><span style="">If
 +you use a theme other than the standard 3 (aqua, cool or default),
 +switch to one of these before going further.</span></strong></p>
 +<h2><strong><b>1. Application files update</b></strong></h2>
 +<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4"><strong><span style="">a. Source
 +files update</span></strong></font></font></p>
 +<p><strong><span style="">Extract distribution
 +zip/tar.gz file in empty directory, and copy all the files to your
 +FrontAccounting directory overwriting old files. If it is major
 +release upgrade you can skip next step and go directly to cleanup.</span></strong></p>
 +<p style="margin-top: 0.42cm; page-break-after: avoid;"><strong><font face="Liberation Sans, sans-serif"><font size="4"><span style="">b. Configuration
 +files update</span></font></font></strong></p>
 +<p><strong><span style="">Compare new
 +</span></strong><strong><i><b>config.default.php</b></i></strong><strong>
 +</strong><strong><span style="">file with the old
 +</span></strong><strong><i><b>config.php </b></i></strong><strong><span style="font-style: normal;"><span style="">and
 +add all n</span></span></strong><strong><span style="">ew
 +settings (if any). </span></strong>
 +</p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.2beta]</span></span></strong></p>
 +<p><strong> <span style="">$show_users_online = 0;</span></strong></p>
 +<p><strong> <span style="">$def_print_destination
 += 0;</span></strong></p>
 +<p><strong><span style="">$dflt_date_fmt=0;</span></strong></p>
 +<p><strong><span style="">$dflt_date_sep=0;</span></strong></p>
 +<p><strong><span style="">$table_style,table_style2
 +changed</span></strong></p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.3beta]</span></span></strong></p>
 +<p><strong> <span style="">$alternative_tax_include_on_doc=0;</span></strong></p>
 +<p><strong><span style="">$suppress_tax_rates = 0;</span></strong></p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.3RC1]</span></span></strong><strong> </strong>
 +</p>
 +<p><strong><span style="">Application version
 +information and a couple of other private FA variables are stored in
 +</span></strong><strong><i><b>version.php</b></i></strong><strong>
 +</strong><strong><span style="">file. The
 +application version displayed in footer is defined in $version
 +variable unless this is set in config.php file. If you want current
 +release version to be displayed on every FA update just remove or
 +comment out $version variable in </span></strong><strong><span style="font-style: normal;"><span style="">config.php</span></span></strong><strong><span style="">.</span></strong></p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.3RC2]</span></span></strong></p>
- <p><strong> <span style="">$save_report_selections &nbsp;= 0; &nbsp;// A value &gt; 0 means days to save the report selections</span></strong></p>
++<p><strong> <span style="">$save_report_selections &nbsp;= 0; &nbsp;// A value &gt; 0 means days to save the report selections.</span></strong></p><p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
++2.3]</span></span></strong></p><p><strong> <span style="">$save_po_item_codes &nbsp;= 0; &nbsp;//&nbsp; show item codes on purchase order&nbsp;</span></strong></p><p><strong><span style="">$def_print_destination = 0; // &nbsp;default print destination. 0 = PDF/Printer, 1 = Excel</span></strong></p><p><strong><span style="">$alternative_tax_include_on_docs = 0; // &nbsp;1 = print Subtotal tax excluded, tax and Total tax included</span></strong></p><p><strong><span style="">$suppress_tax_rates = 0; // &nbsp;suppress tax rates on documents. 0 = no, 1 = yes.</span></strong></p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"></span></span></strong>
 +
 +<strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"></span></span></strong><h2><strong><b>2. Database upgrade</b></strong></h2>
 +<p><strong><span style="">This step can be skipped
 +for small version updates i.e. when you have already installed
 +FrontAccounting version 2.3.1 or later. Before database upgrade is
 +done on all company databases backup file is created automatically to
 +enable database restore after failure.</span></strong></p>
 +<p><strong><span style="">After major version
 +upgrade overwriting files in first step makes the system unaccessible
 +for all users but site admin, who have to run upgrade procedures to
 +update all company databases to the new version provided with the
 +release. After logging to administrator account of first installed
 +company go directly to Setup/Software Upgrade screen, mark all
 +subsequent 'Install' checkboxes and press 'Upgrade System'.</span></strong></p>
 +<p style="">If something goes wrong during
 +upgrade, you can eventually try forced upgrade option. Forced upgrade
 +ignores some smaller errors which can arise during upgrade due to
 +some exotic database configuration. This is depreciated option, so
 +first read error messages if any, try to fix signalized problems,
 +restore databases from backup and retry normal installation. To run
 +upgrade in forced mode check box 'Force Upgrade', and press 'Upgrade
 +System' again.</p>
 +<h2>3. Final cleanup</h2>
 +<p>Remove or rename install folder in main FrontAccounting directory.
 +</p>
 +<p>After upgrade is installed you can remove files obsoleted by new
 +FrontAccounting version. Also old, unused settings <span style="font-style: normal;"><span style="">can
 +be removed from  </span></span><i><b>config.php</b></i><span style="font-style: normal;"><span style="">
 +file.</span></span></p>
 +<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4">a.
 +Source files cleanup</font></font></p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.2beta]</span></span></strong></p>
 +<p><strong><span style=""><span style="background: transparent none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">/includes/reserved.inc
 +&#8211; removed.</span></span></strong></p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.1]</span></span></strong><strong> </strong>
 +</p>
 +<p><strong><span style="">/admin/db/v_banktrans.inc
 +- removed</span></strong></p>
 +<p style="margin-top: 0.42cm; page-break-after: avoid;"><font face="Liberation Sans, sans-serif"><font size="4"><span style="font-style: normal;"><span style="">b.
 +Config.php cleanup </span></span></font></font>
 +</p>
 +<p><strong><span style=""><span style="background: rgb(235, 97, 61) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;">[&lt;FA
 +2.2RC1]</span></span></strong><strong> </strong>
 +</p>
 +<p><strong><span style="">$security_headings,
 +$security_groups arrays &#8211; moved to database (see Access Setup) 
 +</span></strong>
 +</p>
 +<p><strong><span style="">$def_app &#8211; moved
 +to user configuration in database.</span></strong></p>
 +<p><strong><span style="font-style: normal;"><span style="">$version
 +&#8211; moved to </span></span></strong><strong><i><b>version.php</b></i></strong><strong><span style="font-style: normal;"><span style="">
 +file. Remove</span></span></strong></p>
 +<h2>4. New features configuration</h2>
 +<p>During upgrade process new features are initialized to default
 +status, and sometimes old settings are also changed to conform with
 +new security policy. This automatic process is designed to be as
 +neutral for end users as possible, however sometimes site or company
 +admin intervention can be necessary to set thing after changes to
 +their best state. Below you will find description of new settings
 +available after upgrade.</p>
 +<p><br><br>
 +</p>
 +<p>----------------------</p>
 +<ul></ul>
  </body></html>
diff --cc version.php
index 807ff4dcc740cc8da56bfbbae3917883400b463f,8c86a3cc72780e7d05882498df33f9a0e2a4e930..1b3db02e8fdeb9893cfaaaeaad54a738f401149a
@@@ -9,7 -9,7 +9,7 @@@ $db_version = "2.3rc"
  
  // application version - can be overriden in config.php
  if (!isset($version))
-       $version                = "2.4 CVS 1";
 -      $version                = "2.3.10";
++      $version                = "2.4 alpha";
  
  //======================================================================
  // Extension packages repository settings