Merged latest changes from stable branch.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Mon, 8 Oct 2012 12:03:18 +0000 (14:03 +0200)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Mon, 8 Oct 2012 12:03:18 +0000 (14:03 +0200)
14 files changed:
1  2 
admin/display_prefs.php
config.default.php
gl/inquiry/bank_inquiry.php
includes/current_user.inc
includes/date_functions.inc
includes/db/inventory_db.inc
includes/prefs/userprefs.inc
includes/session.inc
includes/sysnames.inc
includes/ui/ui_input.inc
includes/ui/ui_view.inc
reporting/includes/doctext.inc
reporting/includes/pdf_report.inc
reporting/rep209.php

diff --combined admin/display_prefs.php
index 2da5c592b66122c8941e15441c16880acafa72a3,8768c577dccb492bf0665edf3a3edaa6a20acd0e..3b4c825d9369d08a4903491fde49db3545b58c54
@@@ -33,6 -33,8 +33,8 @@@ if (isset($_POST['setprefs'])
                $_POST['theme'] = clean_file_name($_POST['theme']);
                $chg_theme = user_theme() != $_POST['theme'];
                $chg_lang = $_SESSION['language']->code != $_POST['language'];
+               $chg_date_format = user_date_format() != $_POST['date_format'];
+               $chg_date_sep = user_date_sep() != $_POST['date_sep'];
  
                set_user_prefs(get_post( 
                        array('prices_dec', 'qty_dec', 'rates_dec', 'percent_dec',
@@@ -40,7 -42,7 +42,7 @@@
                        'theme', 'page_size', 'language', 'startup_tab',
                        'show_gl' => 0, 'show_codes'=> 0, 'show_hints' => 0,
                        'rep_popup' => 0, 'graphic_links' => 0, 'sticky_doc_date' => 0,
 -                      'query_size' => 10.0)));
 +                      'query_size' => 10.0, 'transaction_days' => 30)));
  
                if ($chg_lang)
                        $_SESSION['language']->set_language($_POST['language']);
@@@ -50,8 -52,7 +52,7 @@@
  
                if ($chg_theme && $allow_demo_mode)
                        $_SESSION["wa_current_user"]->prefs->theme = $_POST['theme'];
-               if ($chg_theme || $chg_lang)
+               if ($chg_theme || $chg_lang || $chg_date_format || $chg_date_sep)
                        meta_forward($_SERVER['PHP_SELF']);
  
                
@@@ -137,8 -138,6 +138,8 @@@ text_row_ex(_("Query page size:"), 'que
  check_row(_("Remember last document date:"), 'sticky_doc_date', sticky_doc_date(),
        false, _('If set document date is remembered on subsequent documents, otherwise default is current date'));
  
 +text_row_ex(_("Transaction days:"), 'transaction_days', 5, 5, '', user_transaction_days());
 +
  end_outer_table(1);
  
  submit_center('setprefs', _("Update"), true, '',  'default');
diff --combined config.default.php
index a932d258b149060ce871d21628f0176dd7b6d320,4948695794a091d13162e520a195052cb52740bf..1eeba6e41c992b5cfc92388898ed08c57f4b499e
@@@ -91,7 -91,7 +91,7 @@@ if (!isset($path_to_root) || isset($_GE
  
        /* $show_voiced_gl_trans = 0, setting this to 1 will show the voided gl trans */
        $show_voided_gl_trans = 0;
 -      
 +
        /* use old style convert (income and expense in BS, PL) */
        $use_oldstyle_convert = 0;
  
  
        /* suppress tax rates on documents. 0 = no, 1 = yes. */
        $suppress_tax_rates = 0;
 -      
 +
 +      /* allow reopening closed transactions */
 +      $allow_gl_reopen = 0;
 +
-       $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD");
+       $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD");
        $dateseps               = array("/", ".", "-", " ");
        $thoseps                = array(",", ".", " ");
        $decseps                = array(".", ",");
@@@ -222,26 -219,25 +222,26 @@@ if(isset($_SESSION["wa_current_user"])
  
  if (!defined('ICON_EDIT'))
  {
 -      define("ICON_EDIT", "edit.gif");        
 -      define("ICON_DELETE", "delete.gif");    
 -      define("ICON_ADD", "ok.gif");   
 -      define("ICON_UPDATE", "ok.gif");        
 -      define("ICON_OK", "ok.gif");    
 -      define("ICON_CANCEL", "cancel.png");    
 -      define("ICON_GL", "gl.png");    
 -      define("ICON_PRINT", "print.png");      
 -      define("ICON_PDF", "pdf.gif");  
 -      define("ICON_DOC", "invoice.gif");      
 -      define("ICON_CREDIT", "credit.gif");    
 -      define("ICON_RECEIVE", "receive.gif");  
 -      define("ICON_DOWN", "download.gif");    
 -      define("ICON_MONEY", "money.png");      
 -      define("ICON_REMOVE", "remove.png");    
 -      define("ICON_REPORT", "report.png");    
 -      define("ICON_VIEW", "view.gif");        
 +      define("ICON_EDIT", "edit.gif");
 +      define("ICON_DELETE", "delete.gif");
 +      define("ICON_ADD", "ok.gif");
 +      define("ICON_UPDATE", "ok.gif");
 +      define("ICON_OK", "ok.gif");
 +      define("ICON_CANCEL", "cancel.png");
 +      define("ICON_GL", "gl.png");
 +      define("ICON_PRINT", "print.png");
 +      define("ICON_PDF", "pdf.gif");
 +      define("ICON_DOC", "invoice.gif");
 +      define("ICON_CREDIT", "credit.gif");
 +      define("ICON_RECEIVE", "receive.gif");
 +      define("ICON_DOWN", "download.gif");
 +      define("ICON_MONEY", "money.png");
 +      define("ICON_REMOVE", "remove.png");
 +      define("ICON_REPORT", "report.png");
 +      define("ICON_VIEW", "view.gif");
        define("ICON_SUBMIT", "ok.gif");
 -      define("ICON_ESCAPE", "escape.png");    
 +      define("ICON_ESCAPE", "escape.png");
 +      define("ICON_CLOSED", "closed.png");
  }
  
  /* 
@@@ -264,3 -260,12 +264,12 @@@ $text_company_selection  = false
  */
  $login_delay = 30;
  $login_max_attempts = 10;
+ /*
+       Choose Exchange Rate Provider
+       Default is ECB for backwards compatibility
+ */
+ $xr_providers = array("ECB", "YAHOO", "GOOGLE", "BLOOMBERG");
+ $dflt_xr_provider = 0;
+ ?>
index 4330a2ade68f54fd6de21a716c05fc9df2fcdc48,3921f136c401eb4e08b5b061bdbeccce4c4053d7..c667c8873641321b2b36ddd685967189aa2fd4f9
@@@ -46,7 -46,7 +46,7 @@@ start_table(TABLESTYLE_NOBORDER)
  start_row();
  bank_accounts_list_cells(_("Account:"), 'bank_account', null);
  
 -date_cells(_("From:"), 'TransAfterDate', '', null, -30);
 +date_cells(_("From:"), 'TransAfterDate', '', null, -$_SESSION["wa_current_user"]->prefs->transaction_days());
  date_cells(_("To:"), 'TransToDate');
  
  submit_cells('Show',_("Show"),'','', 'default');
@@@ -68,7 -68,7 +68,7 @@@ display_heading($act['bank_account_name
  start_table(TABLESTYLE);
  
  $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
-       _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), "");
+       _("Debit"), _("Credit"), _("Balance"), _("Person/Item"), _("Memo"), "");
  table_header($th);
  
  $bfw = get_balance_before_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate']);
@@@ -102,7 -102,8 +102,8 @@@ while ($myrow = db_fetch($result)
        label_cell($trandate);
        display_debit_or_credit_cells($myrow["amount"]);
        amount_cell($running_total);
 -      label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
 +      label_cell(get_counterparty_name($myrow["type"], $myrow["trans_no"]));
+       label_cell(get_comments_string($myrow["type"], $myrow["trans_no"]));
        label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
        end_row();
        if ($myrow["amount"] > 0 ) 
index 71b8ee74bbc090c905c3cd7332e25eea2d0d3c4b,3c5a92a82f9c4d0af0f17e2e758ac43b91ff4e37..90a91a9c079b68e45344f3ed0609b87c9eddf2a8
@@@ -58,15 -58,12 +58,15 @@@ class current_use
  
        function login($company, $loginname, $password)
        {
 -              global $security_areas, $security_groups, $security_headings, $path_to_root;
 +              global $security_areas, $security_groups, $security_headings, $path_to_root, $dflt_lang;
  
                $this->set_company($company);
            $this->logged = false;
  
 -              set_global_connection();
 +              set_global_connection($company);
 +              $lang = &$_SESSION['language'];
 +              $lang->set_language($_SESSION['language']->code);
 +              db_set_encoding($_SESSION['language']->encoding);
  
                // Use external authentication source if any.
                // Keep in mind you need to have user data set for $loginname
                if ($Auth_Result)
                {
                        $myrow = get_user_by_login($loginname);
 +                      if ($myrow['language'] != $dflt_lang)
 +                      {        // refresh language and user data
 +                              $lang->set_language($myrow['language']);
 +                              db_set_encoding($_SESSION['language']->encoding);
 +                              $myrow = get_user_by_login($loginname);
 +                      }
 +
                        $this->old_db = isset($myrow["full_access"]);
                        if (! @$myrow["inactive"]) {
                                if ($this->old_db) { 
                        return !isset($security_groups) && is_array($this->role_set);
        }
  
 -      function can_access($page_level)
 +      function can_access($sec_area)
        {
                global $security_groups, $security_areas;
                if (isset($security_groups)) {
 -                      return $this->company == 0 &&
 +                      return is_admin_company() &&
                                in_array(20, $security_groups[$this->access]);
                }
  
 -              if ($page_level === 'SA_OPEN') 
 +              if ($sec_area === 'SA_OPEN') 
                        return true;
 -              if ($page_level === 'SA_DENIED' || $page_level === '') 
 +              if ($sec_area === 'SA_DENIED' || $sec_area === '') 
                        return false;
  
 -              $code = $security_areas[$page_level][0];
 +              $code = $security_areas[$sec_area][0];
  
                // only first registered company has site admin privileges
                return $code && in_array($code, $this->role_set)
                return $this->can_access($page_level);
        }
  
+       function check_application_access($waapp)
+       {
+               if (!$this->hide_inaccessible_menu_items())
+               {
+                       return true;
+               }
+               foreach ($waapp->modules as $module)
+               {
+                       if ($this->check_module_access($module))
+                       {
+                               return true;
+                       }
+               }
+               return false;
+       }
+       function check_module_access($module)
+       {
+               if (!$this->hide_inaccessible_menu_items())
+               {
+                       return true;
+               }
+               if (sizeof($module->lappfunctions) > 0)
+               {
+                       foreach ($module->lappfunctions as $appfunction)
+                       {
+                               if ($appfunction->label != "" && $this->can_access_page($appfunction->access))
+                               {
+                                       return true;
+                               }
+                       }
+               }
+               if (sizeof($module->rappfunctions) > 0)
+               {
+                       foreach ($module->rappfunctions as $appfunction)
+                       {
+                               if ($appfunction->label != "" && $this->can_access_page($appfunction->access))
+                               {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+       function hide_inaccessible_menu_items()
+       {
+               global $hide_inaccessible_menu_items;
+               if (!isset($hide_inaccessible_menu_items) || $hide_inaccessible_menu_items == 0)
+               {
+                       return false;
+               }
+               else
+               {
+                       return true;
+               }
+       }
        function set_db_connection($id = -1)
        {
                return set_global_connection($id);
@@@ -445,17 -503,6 +513,17 @@@ function user_startup_tab(
        return $_SESSION["wa_current_user"]->prefs->start_up_tab();
  }
  
 +function user_transaction_days()
 +{
 +    return $_SESSION["wa_current_user"]->prefs->transaction_days();
 +}
 +
 +
 +function user_check_access($sec_area)
 +{
 +      return $_SESSION["wa_current_user"]->can_access($sec_area);
 +}
 +
  function set_user_prefs($prefs)
  {
        $_SESSION["wa_current_user"]->update_prefs($prefs);
@@@ -567,7 -614,6 +635,7 @@@ function flush_dir($path, $wipe = false
        $dir = opendir($path);
        if(!$dir)
                return;
 +
        while(false !== ($fname = readdir($dir))) {
                if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
                if(is_dir($path.'/'.$fname)) {
@@@ -593,9 -639,5 +661,9 @@@ function company_path($comp=null
                        . '/'.$comp;
  }
  
 +function is_admin_company()
 +{
 +      return $this->company == 0;
 +}
  
  ?>
index d1aacdf8302f7fbbf80da6089a8b16e86b19fda3,2c99d059ae788fc439b6e678bb142799e012851e..17a86ff7cf926101adaa8a6d0d69c21120f1fa14
@@@ -21,22 -21,31 +21,31 @@@ this can be a string either "d/m/Y" fo
  
  function __date($year, $month, $day)
  {
-       global $dateseps;
+       global $dateseps, $tmonths;
        
        $how = user_date_format();
        $sep = $dateseps[user_date_sep()];
        $day = (int)$day;
        $month = (int)$month;
-       if ($day < 10)
-               $day = "0".$day;
-       if ($month < 10)
-               $month = "0".$month;
+       if ($how < 3)
+       {
+               if ($day < 10)
+                       $day = "0".$day;
+               if ($month < 10)
+                       $month = "0".$month;
+       }               
        if ($how == 0)
                return $month.$sep.$day.$sep.$year;
        elseif ($how == 1)
                return $day.$sep.$month.$sep.$year;
-       else
+       elseif ($how == 2)
                return $year.$sep.$month.$sep.$day;
+       elseif ($how == 3)
+               return $tmonths[$month].$sep.$day.$sep.$year;
+       elseif ($how == 4)
+               return $day.$sep.$tmonths[$month].$sep.$year;
+       else
+               return $year.$sep.$tmonths[$month].$sep.$day;
  }
  
  function is_date($date_) 
        $sep = $dateseps[user_date_sep()];
  
        $date_ = trim($date_);
-       $date_ = str_replace($sep, "", $date_);
-       if (strlen($date_) == 6)
+       $date = str_replace($sep, "", $date_);
+       
+       if ($how > 2)
+       {
+               global $tmonths;
+               $dd = explode($sep, $date_);
+               if ($how == 3)
+               {
+                       $day = $dd[1];
+                       $month = array_search($dd[0], $tmonths);
+                       $year = $dd[2];
+               } 
+               elseif ($how == 4)
+               {
+                       $day = $dd[0];
+                       $month = array_search($dd[1], $tmonths);
+                       $year = $dd[2];
+               } 
+               else
+               {
+                       $day = $dd[2];
+                       $month = array_search($dd[1], $tmonths);
+                       $year = $dd[0];
+               }
+               if ($year < 1000)
+                       return 0;
+       }
+       elseif (strlen($date) == 6)
        {
                if ($how == 0)
                {
-                       $day = substr($date_,2,2);
-                       $month = substr($date_,0,2);
-                       $year = substr($date_,4,2);
+                       $day = substr($date,2,2);
+                       $month = substr($date,0,2);
+                       $year = substr($date,4,2);
                } 
                elseif ($how == 1)
                {
-                       $day = substr($date_,0,2);
-                       $month = substr($date_,2,2);
-                       $year = substr($date_,4,2);
+                       $day = substr($date,0,2);
+                       $month = substr($date,2,2);
+                       $year = substr($date,4,2);
                } 
                else
                {
-                       $day = substr($date_,4,2);
-                       $month = substr($date_,2,2);
-                       $year = substr($date_,0,2);
+                       $day = substr($date,4,2);
+                       $month = substr($date,2,2);
+                       $year = substr($date,0,2);
                }
        }
-       elseif (strlen($date_) == 8)
+       elseif (strlen($date) == 8)
        {
                if ($how == 0)
                {
-                       $day = substr($date_,2,2);
-                       $month = substr($date_,0,2);
-                       $year = substr($date_,4,4);
+                       $day = substr($date,2,2);
+                       $month = substr($date,0,2);
+                       $year = substr($date,4,4);
                } 
                elseif ($how == 1)
                {
-                       $day = substr($date_,0,2);
-                       $month = substr($date_,2,2);
-                       $year = substr($date_,4,4);
+                       $day = substr($date,0,2);
+                       $month = substr($date,2,2);
+                       $year = substr($date,4,4);
                } 
                else
                {
-                       $day = substr($date_,6,2);
-                       $month = substr($date_,4,2);
-                       $year = substr($date_,0,4);
+                       $day = substr($date,6,2);
+                       $month = substr($date,4,2);
+                       $year = substr($date,0,4);
                }
        }
        if (!isset($year)|| (int)$year > 9999) 
                return 0;
        }
  
        if (is_long((int)$day) && is_long((int)$month) && is_long((int)$year))
        {
                global $date_system;
@@@ -160,29 -194,26 +194,29 @@@ function is_date_in_fiscalyear($date, $
        global $path_to_root;
        include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
  
 -    //Chaitanya
 -    if ($convert)
 -        $date2 = sql2date($date);
 -    else
 -        $date2 = $date;
 -
 -    if ($_SESSION["wa_current_user"]->can_access('SA_MULTIFISCALYEARS')) // allow all open years for this one
 -        return is_date_in_fiscalyears($date2, false); 
 -
 -    $myrow = get_current_fiscalyear();
 -    if ($myrow['closed'] == 1)
 -        return 0;
 -    
 -    $begin = sql2date($myrow['begin']);
 -    $end = sql2date($myrow['end']);
 -    if (date1_greater_date2($begin, $date2) || date1_greater_date2($date2, $end))
 -    {
 -        return 0;
 -    }
 -    return 1;
 +      if ($convert)
 +              $date2 = sql2date($date);
 +      else
 +              $date2 = $date;
 +
 +      if (user_check_access('SA_MULTIFISCALYEARS')) // allow all open years for this one
 +              return is_date_in_fiscalyears($date2, false);
 +
 +      if (is_date_closed($date2))
 +              return 0;
 +      $myrow = get_current_fiscalyear();
 +      $begin = sql2date($myrow['begin']);
 +      $end = sql2date($myrow['end']);
 +      if (date1_greater_date2($begin, $date2) || date1_greater_date2($date2, $end))
 +      {
 +              return 0;
 +      }
 +      return 1;
 +}
 +
 +function is_date_closed($date)
 +{
 +      return !date1_greater_date2($date, sql2date(get_company_pref('gl_closing_date')));
  }
  
  function begin_fiscalyear()
@@@ -262,7 -293,8 +296,8 @@@ function add_days($date, $days) // acce
                list($year, $month, $day) = gregorian_to_islamic(date("Y", $timet), date("n", $timet), date("j", $timet));
        return __date($year, $month, $day);
      }
-     return date(user_date_display(), $timet);
+     list($year, $month, $day) = explode("-", date("Y-m-d", $timet));
+       return __date($year, $month, $day);
  }
  
  function add_months($date, $months) // accepts negative values as well
                list($year, $month, $day) = gregorian_to_islamic(date("Y", $timet), date("n", $timet), date("j", $timet));
        return __date($year, $month, $day);
      }
-     return date(user_date_display(), $timet);
+     list($year, $month, $day) = explode("-", date("Y-m-d", $timet));
+       return __date($year, $month, $day);
  }
  
  function add_years($date, $years) // accepts negative values as well
                list($year, $month, $day) = gregorian_to_islamic(date("Y", $timet), date("n", $timet), date("j", $timet));
        return __date($year, $month, $day);
      }
-     return date(user_date_display(), $timet);
+     list($year, $month, $day) = explode("-", date("Y-m-d", $timet));
+       return __date($year, $month, $day);
  }
  
  //_______________________________________________________________
@@@ -336,7 -370,7 +373,7 @@@ function sql2date($date_
  
  function date2sql($date_)
  {
-       global $dateseps, $date_system;
+       global $dateseps, $date_system, $tmonths;
  /* takes a date in a the format specified in $DefaultDateFormat
  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
+     if ($how == 0 || $how == 3) // MMDDYYYY or MmmDDYYYY
          list($month, $day, $year) = explode($sep, $date_);
-     elseif ($how == 1) // DDMMYYYY
+     elseif ($how == 1 || $how == 4) // DDMMYYYY or DDMmYYYY
          list($day, $month, $year) = explode($sep, $date_);
-     else // $how == 2, YYYYMMDD
+     else // $how == 2 || $how == 5, YYYYMMDD or YYYYMmmDD
          list($year, $month, $day) = explode($sep, $date_);
+       if ($how > 2)
+       {
+               global $tmonths;
+               $month = array_search($month, $tmonths);
+       }       
  //to modify assumption in 2030
        if ($date_system == 0 || $date_system == 3)
        {
index e0ea2ef7646f00d33338e2ab29246d0561b5dcf0,037d410171470823e988887dc3d1600c887f921d..5613ecb8d8eba24b13f1b3839a4914da9323056f
@@@ -140,9 -140,9 +140,9 @@@ function last_negative_stock_trans_id($
                        $negative_trans_id = $myrow['trans_id'];
                }
                if ($qty >= 0)
 -                      $flag = 0;      
 +                      $flag = 0;
        }
 -              
 +
        if ($flag == 1)
                return $negative_trans_id;
        else 
@@@ -180,14 -180,14 +180,14 @@@ function get_deliveries_from_trans($sto
              ." 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
        $final_cost = $row[1] - $qoh[0]*$cost[0];
        
@@@ -234,7 -234,7 +234,7 @@@ function adjust_deliveries($stock_id, $
                $new_purchase_cost = $row[0] * $material_cost;
                $purchase_diff = $new_purchase_cost - $old_purchase_cost;
        }
 -      
 +
        $diff =  $sales_diff - $purchase_diff;
        
        if ($diff != 0)
@@@ -381,10 -381,7 +381,8 @@@ function get_stock_moves($type, $type_n
  
  function void_stock_move($type, $type_no)
  {
-     $sql = "SELECT stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price, 
-       sum(qty) qty FROM ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no)." 
-       GROUP BY stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price HAVING sum(qty) <> 0";
+     $sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
 +
      $result = db_query($sql, "Could not void stock moves");
      while ($row = db_fetch($result))
      {
                                $trans_rate, -$row["qty"], sql2date($row["tran_date"]));
                }
  
-               //Post stock move for service items also
-         add_stock_move($type, $row["stock_id"], $type_no, $row["loc_code"],
-               sql2date($row["tran_date"]), $row["reference"], -$row["qty"]
-                       , $row["standard_cost"], $row["person_id"], $row["visible"],
-               $row["price"], $row["discount_percent"]);
      }
+       $sql = "DELETE FROM ".TB_PREF."stock_moves WHERE type=".db_escape($type)
+               ."      AND trans_no=".db_escape($type_no);
+       db_query($sql, "The stock movement cannot be delated");
  }
  
  //--------------------------------------------------------------------------------------------------
@@@ -428,3 -423,8 +424,3 @@@ function get_location_name($loc_code
  
        display_db_error("could not retreive the location name for $loc_code", $sql, true);
  }
 -
 -//--------------------------------------------------------------------------------------------------
 -
 -
 -?>
index caf0506648c0b963b0003129ed54ced26608495b,811e663d454c1948ae7869e7abfeb43dcf6a67ac..400ef1e16903dbf06d2f24d39d22f718033a0581
@@@ -35,8 -35,7 +35,8 @@@ class user_pref
        var $graphic_links; // use graphic links
        var $sticky_date;       // save date on subsequent document entry
        var $startup_tab;  // default start-up menu tab
 -      
 +      var $transaction_days; // transaction days in inquiries.
 +
        function user_prefs($user=null)
        {
                if ($user == null) { 
@@@ -50,8 -49,7 +50,8 @@@
                        $this->price_dec = 2;
                        $this->language = $dflt_lang;
                        $this->theme = 'default';
 -                      
 +                      $this->transaction_days = -30;
 +
                } else {
                        $this->language = $user["language"];
                        $_SESSION['language']->set_language($this->language);
@@@ -84,7 -82,6 +84,7 @@@
                                $this->sticky_date = 0;
                                $this->startup_tab = "orders";
                        }
 +                      $this->transaction_days = $user['transaction_days'];
                }
        }
        
                        return "m".$sep."d".$sep."Y";
                elseif ($this->date_format == 1)
                        return "d".$sep."m".$sep."Y";
-               else
+               elseif ($this->date_format == 2)
                        return "Y".$sep."m".$sep."d";
+               elseif ($this->date_format == 3)
+                       return "M".$sep."j".$sep."Y";
+               elseif ($this->date_format == 4)
+                       return "j".$sep."M".$sep."Y";
+               else
+                       return "Y".$sep."M".$sep."j";
        }
  
        function tho_sep() 
                return $this->startup_tab;
        }
  
 +    function transaction_days() 
 +    {
 +        return $this->transaction_days;
 +    }
 +
        function set_dec($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes) 
        {
                $this->price_dec = $price_dec;
diff --combined includes/session.inc
index 66a7d240d235ce52b423449ce01edb820a7db2ef,2688a24e94072dee83851ad071ec027e04537b45..52d16bdf3e0f951233f19f5f293f89eb28de6633
@@@ -155,7 -155,7 +155,7 @@@ function check_faillog(
  
        $user = $_SESSION["wa_current_user"]->user;
  
-       if (@$login_delay && ($login_faillog[$user][$_SERVER['REMOTE_ADDR']] >= @$login_max_attempts) && (time() < $login_faillog[$user]['last'] + $login_delay))
+       if (@$login_delay && (@$login_faillog[$user][$_SERVER['REMOTE_ADDR']] >= @$login_max_attempts) && (time() < $login_faillog[$user]['last'] + $login_delay))
                return true;
  
        return false;
@@@ -355,8 -355,6 +355,8 @@@ foreach ($installed_extensions as $ext
  
  ini_set('session.gc_maxlifetime', 36000); // 10hrs
  
 +hook_session_start(@$_POST["company_login_name"]);
 +
  $Session_manager = new SessionManager();
  $Session_manager->sessionStart('FA'.md5(dirname(__FILE__)));
  
@@@ -367,8 -365,7 +367,8 @@@ include_once($path_to_root . "/config.p
  get_text_init();
  
  // Page Initialisation
 -if (!isset($_SESSION['language']) || !method_exists($_SESSION['language'], 'set_language')) 
 +if (!isset($_SESSION['wa_current_user']) || !$_SESSION['wa_current_user']->logged_in()
 +      || !isset($_SESSION['language']) || !method_exists($_SESSION['language'], 'set_language'))
  {
        $l = array_search_value($dflt_lang, $installed_languages,  'code');
        $_SESSION['language'] = new language($l['name'], $l['code'], $l['encoding'],
@@@ -381,7 -378,6 +381,7 @@@ $_SESSION['language']->set_language($_S
  include_once($path_to_root . "/includes/access_levels.inc");
  include_once($path_to_root . "/version.php");
  include_once($path_to_root . "/includes/main.inc");
 +include_once($path_to_root . "/includes/app_entries.inc");
  
  // Ajax communication object
  $Ajax = new Ajax();
@@@ -452,12 -448,11 +452,12 @@@ if (strstr($_SERVER['PHP_SELF'], 'logou
                        // Incorrect password
                                login_fail();
                        }
 -                      $lang = &$_SESSION['language'];
 -                      $lang->set_language($_SESSION['language']->code);
                }
        } else
 -              set_global_connection();
 +      {       set_global_connection();
 +                      if (db_fixed())
 +                              db_set_encoding($_SESSION['language']->encoding);
 +      }
  
        if (!isset($_SESSION["App"])) {
                $_SESSION["App"] = new front_accounting();
@@@ -470,3 -465,5 +470,3 @@@ $SysPrefs = &$_SESSION['SysPrefs']
  // POST vars cleanup needed for direct reuse.
  // We quote all values later with db_escape() before db update.
  $_POST = strip_quotes($_POST);
 -
 -?>
diff --combined includes/sysnames.inc
index 7c296ad9632ab1ef910b4884bb44d4bf09d8149e,440ff528bda86b88d0ba9de6724cb6e2c4f4230e..52f96c64b95a288a23498259281bbd4ebff44a56
@@@ -16,7 -16,7 +16,7 @@@
  //
  global $systypes_array, $bank_account_types, $bank_transfer_types, 
        $payment_person_types, $wo_types_array, $wo_cost_types, $class_types,
 -      $quick_actions, $quick_entry_types, $stock_types, $tag_types;
 +      $quick_actions, $quick_entry_types, $stock_types, $tag_types, $bank_owner;
  
  $systypes_array = array (
        ST_JOURNAL => _("Journal Entry"),
@@@ -110,7 -110,6 +110,7 @@@ $wo_types_array = array 
  $wo_cost_types = array(
        WO_LABOUR => _("Labour Cost"),
        WO_OVERHEAD => _("Overhead Cost"),
 +      WO_MATERIALS => _("Materials")
  );
  
  //----------------------------------------------------------------------------------
@@@ -183,17 -182,8 +183,20 @@@ $pterm_types = array
        PTT_FOLLOWING => _("Day In Following Month")
  );
  
 +$tax_algorithms = array( 
 +      TCA_LINES => _("Sum per line taxes"), 
 +      TCA_TOTALS => _("Taxes from totals")
 +);
  //----------------------------------------------------------------------------------
 +
 +$bank_owner_types = array(
 +      BO_UNKNOWN => _("Unknown"),
 +      BO_COMPANY => _("Company"),
 +      BO_CUSTBRANCH => _("Customer"),
 +      BO_SUPPLIER => _("Supplier")
 +);
 +
+ // This month array is for use with the last 3 dateformats. 
+ $tmonths = array("", _("Jan"),_("Feb"),_("Mar"),_("Apr"),_("May"),_("Jun"),_("Jul"),_("Aug"),_("Sep"),_("Oct"),_("Nov"),_("Dec"));
  ?>
diff --combined includes/ui/ui_input.inc
index 04933bd68682dba3eea346740527feeb836883bd,9ae512b5910ed2111eef9d4fef0f1fdcecdf99fc..d9140d51d53655b10e6237ba3c884cad79cad676
@@@ -114,7 -114,6 +114,7 @@@ function hidden($name, $value=null, $ec
                'cancel'  - cancel form entry on Escape press; dflt ICON_CANCEL
                'process' - displays progress bar during call; optional icon
                'nonajax' - ditto, non-ajax submit
 +
        $atype can contain also multiply type selectors separated by space, 
        however make sense only combination of 'process' and one of defualt/selector/cancel
  */
@@@ -646,7 -645,8 +646,8 @@@ function date_cells($label, $name, $tit
                $aspect .= ' style="color:#FF0000"';
  
        default_focus($name);
-       echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"10\" maxlength=\"12\" value=\"" 
+       $size = (user_date_format()>3)?11:10; 
+       echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"$size\" maxlength=\"12\" value=\"" 
         . $_POST[$name]. "\""
         .($title ? " title='$title'": '')." > $post_label";
        echo "</td>\n";
@@@ -942,30 -942,10 +943,30 @@@ function supplier_credit_row($supplier
                ."</a>", $parms);
  }
  
 +/*
 +      Edit transaction link to be used in transaction inquires
 +*/
 +function edit_trans_link($trans_type, $trans_no, $url='')
 +{
 +      global $path_to_root, $trans_editors;
 +
 +      if (!$url) $url = @$trans_editors[$trans_type];
 +
 +      if (!$trans_no || !$url)
 +              return '';
 +
 +      if (is_closed_trans($trans_type, $trans_no)) {
 +              return set_icon(ICON_CLOSED, _('Closed'));
 +      } else {
 +              $link_text = user_graphic_links() ? set_icon(ICON_EDIT, _('Edit')) : _('Edit');
 +              return "<a href='".$path_to_root . sprintf($url, $trans_no, $trans_type)."'>$link_text</a>";
 +      }
 +}
 +
  function bank_balance_row($bank_acc, $parms='')
  {
        global $path_to_root;
 -      
 +
        $to = add_days(Today(), 1);
        $bal = get_balance_before_for_bank_account($bank_acc, $to);
        label_row( _("Bank Balance:"),
diff --combined includes/ui/ui_view.inc
index adf663288317479f0cee4a0238776d6114a370f5,616a0ffa9364ee687855e31712240a75813ca413..e98f1d674c8bb0a93a3b935e8ffcc6a573a41462
@@@ -50,11 -50,11 +50,11 @@@ function get_gl_view_str($type, $trans_
        {
                $label = _("GL");
                $icon = ICON_GL;
 -      }       
 +      }
 +      $url = ($type == ST_WORKORDER && !work_order_is_closed($trans_no)) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no"
 +              : "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no";
  
 -      return viewer_link($label, 
 -              "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no", 
 -              $class, $id, $icon);
 +      return viewer_link($label, $url, $class, $id, $icon);
  }
  
  //--------------------------------------------------------------------------------------
@@@ -468,20 -468,20 +468,20 @@@ function display_edit_tax_items($taxes
  function display_footer_exit()
  {
        br(2);
 -      end_page(false, false, true);
 +      end_page(false, true);
        exit;
  }
  
  //--------------------------------------------------------------------------------------
  
 -function display_allocations($alloc_result, $total, $payments=false)
 +function display_allocations($alloc_result, $total, $title, $show_summary=true)
  {
        global $systypes_array;
  
        if (!$alloc_result || db_num_rows($alloc_result) == 0)
                return;
  
 -    display_heading2(($payments ? _("Payments") : _("Allocations")));
 +    display_heading2($title);
  
      start_table(TABLESTYLE, "width=80%");
  
  
      while ($alloc_row = db_fetch($alloc_result))
      {
 -
        alt_table_row_color($k);
  
        label_cell($systypes_array[$alloc_row['type']]);
        label_cell(_("Total Allocated:"), "align=right colspan=5");
        amount_cell($total_allocated);
        end_row();
 -      start_row();
 -    label_cell(_("Left to Allocate:"), "align=right colspan=5");
 -    $total = round2($total, user_price_dec());
 -    amount_cell($total - $total_allocated);
 -    end_row();
 -
 +      if ($show_summary)
 +      {
 +              start_row();
 +          label_cell(_("Left to Allocate:"), "align=right colspan=5");
 +          $total = round2($total, user_price_dec());
 +      amount_cell($total - $total_allocated);
 +      end_row();
 +      }
      end_table(1);
  }
  
@@@ -531,11 -530,11 +531,11 @@@ function display_allocations_from($pers
        {
                case PT_CUSTOMER :
                        $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
 -                      display_allocations($alloc_result, $total);
 +                      display_allocations($alloc_result, $total, _("Allocations"));
                        return;
                case PT_SUPPLIER :
                        $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
 -                      display_allocations($alloc_result, $total);
 +                      display_allocations($alloc_result, $total, _("Allocations"));
                        return;
        }
  }
@@@ -548,11 -547,11 +548,11 @@@ function display_allocations_to($person
        {
                case PT_CUSTOMER :
                        $alloc_result = get_allocatable_from_cust_transactions($person_id, $type_no, $type);
 -                      display_allocations($alloc_result, $total, true);
 +                      display_allocations($alloc_result, $total, $type == ST_SALESORDER ? _("Pre-Payments") : _("Payments"), false);
                        return;
                case PT_SUPPLIER :
                        $alloc_result = get_allocatable_from_supp_transactions($person_id, $type_no, $type);
 -                      display_allocations($alloc_result, $total, true);
 +                      display_allocations($alloc_result, $total, $type == ST_PURCHORDER ? _("Pre-Payments") : _("Payments"), false);
                        return;
        }
  }
@@@ -588,9 -587,9 +588,9 @@@ function display_quick_entries(&$cart, 
                                        $begin = "";
                                else
                                        $begin = begin_fiscalyear(); // from fiscalyear begin
 -                      }               
 +                      }
                        $base = get_gl_trans_from_to($begin, $cart->tran_date, $qe['base_desc']);
 -                              
 +
                }
                if ($descr != '') $qe['description'] .= ': '.$descr;
                $result = get_quick_entry_lines($id);
                        display_error( _("No Quick Entry lines are defined."));
                        set_focus('totamount');
                        return 0;
 -              }       
 +              }
                $totrate = 0;
                while ($row = db_fetch($result))
                {
@@@ -784,7 -783,7 +784,7 @@@ function price_in_words($amount, $docum
      else
        $frac = "";
      return _number_to_words(intval($amount)) . $frac;
 -}    
 +}
  
  function get_js_open_window($width, $height)
  {
@@@ -834,11 -833,11 +834,11 @@@ function get_js_date_picker(
  
      if (!file_exists($fpath) || $go_debug) {
  
-       global $dateseps, $date_system;
+       global $dateseps, $date_system, $tmonths;
  
        $how = user_date_format();                              // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
        $sep = $dateseps[user_date_sep()];              // date separator
-       $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 ? 0 : 1));    // weekstart (sun = 0, mon = 1)
+       $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 || $how == 3 ? 0 : 1));       // weekstart (sun = 0, mon = 1)
        $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
        $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
        $wno = _("W"); // week no
@@@ -921,6 -920,7 +921,7 @@@ function CC() 
    var selectedDay = 0;
    var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]'];
    var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
+   var tmonths = ['$tmonths[0]','$tmonths[1]','$tmonths[2]','$tmonths[3]','$tmonths[4]','$tmonths[5]','$tmonths[6]','$tmonths[7]','$tmonths[8]','$tmonths[9]','$tmonths[10]','$tmonths[11]','$tmonths[12]'];
    var dateField = null;
    function getProperty(p_property){
      var p_elm = calendarId;
    this.getWeek = getWeek;
    function getWeek(year, month, day) {
  ";
-       if ($how == 0)
+       if ($how == 0 || $how == 3)
                $js .= "  day++;";
        $js .= "
      var date = new Date(year,month-1,day);
    }
    this.setDate = setDate;
    function setDate(year, month, day) {
-     if (dateField) {
+     if (dateField){
+ ";
+       if ($how < 3)
+               $js .= "
        if (month < 10) {month = '0' + month;}
        if (day < 10) {day = '0' + day;}
  ";
-       if ($how == 0)
+       else
+               $js .= "
+       month = tmonths[month];
+ ";
+       if ($how == 0 || $how == 3)
                $js .= "
        var dateString = month+'$sep'+day+'$sep'+year;
  ";
-       else if ($how == 1)
+       else if ($how == 1 || $how == 4)
                $js .= "
        var dateString = day+'$sep'+month+'$sep'+year;
  ";
-       else
+       else if ($how == 2 || $how == 5)
                $js .= "
        var dateString = year+'$sep'+month+'$sep'+day;
  ";
          selectedMonth = parseInt(dateParts[1],10);
          selectedYear = parseInt(dateParts[2],10);
  ";
-       else
+       else if ($how == 2)
                $js .= "
          selectedYear = parseInt(dateParts[0],10);
          selectedMonth = parseInt(dateParts[1],10);
          selectedDay = parseInt(dateParts[2],10);
+ ";
+       else if ($how == 3)
+               $js .= "
+         selectedDay = parseInt(dateParts[1],10);
+         selectedMonth = parseInt(tmonths.indexOf(dateParts[0]),10);
+         selectedYear = parseInt(dateParts[2],10);
+ ";
+       else if ($how == 4)
+               $js .= "
+         selectedDay = parseInt(dateParts[0],10);
+         selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10);
+         selectedYear = parseInt(dateParts[2],10);
+ ";
+       else
+               $js .= "
+         selectedYear = parseInt(dateParts[0],10);
+         selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10);
+         selectedDay = parseInt(dateParts[2],10);
  ";
        $js .= "
        } catch(e) {}
@@@ -1346,3 -1371,5 +1372,3 @@@ function payment_link($name, $options
  
        return strtr($link, $patterns);
  }
 -
 -?>
index f39254afee2f4a8fd830c47fd5188f43231b6296,73bdaa10ed9353971145b0b0459f252d249c8810..21b3a8479508d2d59a31a2cad12d5e5fb3eaa4db
        // for links use 'text' => 'url'
        $Footer[0] = _("All amounts stated in") . " - " . @$this->formData['curr_code'];
  
 +      if (!in_array($this->formData['doctype'], array(ST_STATEMENT, ST_WORKORDER)))
 +      {
 +              $id = $this->formData['payment_terms'];
 +              $sql = "SELECT terms, days_before_due 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"];
 +              if ($this->formData['doctype'] == ST_SALESINVOICE && $this->formData['prepaid'])
 +                      $this->formData['prepaid'] = ($row['days_before_due'] >= 0) ? 'final' : 'partial';
 +      }
 +
 +
        switch ($this->formData['doctype'])
        {
                case ST_SALESQUOTE:
@@@ -53,7 -41,7 +53,7 @@@
                        $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"],
+                               _("Customer's 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'],
@@@ -62,7 -50,7 +62,7 @@@
                        break;
  
                case ST_SALESORDER:
 -                      $this->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
 +                      $this->title = ($print_as_quote==1 ? _("QUOTE") : ($this->formData['prepaid'] ? _("PREPAYMENT ORDER") : _("SALES ORDER")));
                        $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'])
@@@ -70,7 -58,7 +70,7 @@@
                        $this->formData['document_amount'] = $this->formData['order_no'];
  
                        $aux_info = array(
-                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Customer's 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'],
@@@ -91,7 -79,7 +91,7 @@@
                                        $ref = $this->formData['order_'];
                        }
                        $aux_info = array(
-                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Customer's Reference") => $this->formData["customer_ref"],
                                _("Sales Person") => get_salesman_name($this->formData['salesman']),
                                _("Your VAT no.") => $this->formData['tax_id'],
                                _("Our Order No") => $ref,
                        $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"],
+                               _("Customer's 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_'],
                        break;
  
                case ST_SALESINVOICE:
 -                      $this->title = _("INVOICE");
 +                      $this->title = $this->formData['prepaid']=='partial' ? _("PREPAYMENT INVOICE")
 +                              : ($this->formData['prepaid']=='final' ? _("FINAL INVOICE")  : _("INVOICE"));
                        $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'];
                                }
                        }
                        $aux_info = array(
-                               _("Customers Reference") => $this->formData["customer_ref"],
+                               _("Customer's 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']),
                        );
 +                      if ($this->formData['prepaid']=='partial')
 +                      {
 +                              $aux_info[_("Date of Payment")] = sql2date(get_oldest_payment_date($this->formData['trans_no']));
 +                              $aux_info[_("Our Order No")]  = $this->formData['order_'];
 +                      } else {
 +                              if ($this->formData['prepaid'] =='final')
 +                                      $aux_info[_("Invoice Date")] = sql2date($this->formData['tran_date']);
 +                              else
 +                                      $aux_info[_("Date of Sale")] = sql2date(get_oldest_delivery_date($this->formData['trans_no']));
 +                              $aux_info[_("Due Date")]  = sql2date($this->formData['due_date']);
 +                      }
                        break;
  
                case ST_SUPPAYMENT:
                        $Addr2['address'] = '';
  
                        $aux_info = array(
-                               _("Customers Reference") => $this->formData['supp_account_no'],
+                               _("Customer's Reference") => $this->formData['supp_account_no'],
                                _("Type") =>$systypes_array[$this->formData["type"]],
                                _("Your VAT no.") => $this->formData['tax_id'],
-                               _("Our Order No") => '',
+                               _("Supplier's Reference") => '',
                                _("Due Date") => sql2date($this->formData['tran_date']),
                        );
                        $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
                                ? $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") => '',
+                               _("Customer's Reference") => $this->formData['supp_account_no'],
+                               _("Sales Person") => $this->formData['contact'],
+                               _("Your VAT no.") => $this->formData['tax_id'],
+                               _("Supplier's Reference") => $this->formData['requisition_no'],
+                               _("Order Date") => sql2date($this->formData['document_date']),
                        );
  
                        $this->headers = array(_("Item Code"), _("Item Description"),
                        $this->formData['document_name'] =_("Receipt No.");
                        $Addr1['title'] = _("With thanks from");
                        $aux_info = array(
-                               _("Customers Reference") => $this->formData["debtor_ref"],
+                               _("Customer's Reference") => $this->formData["debtor_ref"],
                                _("Type") =>$systypes_array[$this->formData["type"]],
                                _("Your VAT no.") => $this->formData['tax_id'],
                                _("Our Order No") => $this->formData['order_'],
                        $Payment_Terms = '';
                        $this->title = _("STATEMENT");
                        $aux_info = array(
-                               _("Customers Reference") => '',
+                               _("Customer's Reference") => '',
                                _("Sales Person") => '',
                                _("Your VAT no.") => $this->formData['tax_id'],
                                _("Our Order No") => '',
                $this->formData['document_number'] = $print_invoice_no == 0 && isset($this->formData['reference'])
                        ? $this->formData['reference'] : @$this->formData['trans_no'];
  
 -      if (!isset($Payment_Terms))
 -      {
 -              $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"];
 -      }
 -
        // footer generic content
        if (@$this->formData['bank_name'])
                $Footer[] = _("Bank"). ": ".$this->formData['bank_name']. ", " . _("Bank Account") . ": " . $this->formData['bank_account_number'];
                foreach(explode("\n", $this->company['legal_text']) as $line)
                        $Footer[] = $line;
        }
 -
 -?>
index 8523359d9c6919b336127e7c91eb897d35f5f9db,0a412ce87aadcc5d5d718a2433f60710108c144d..682b8af319c5a61e644677ce1600f97582cd9eed
@@@ -386,7 -386,7 +386,7 @@@ class FrontReport extends Cpd
                        'DebtorName', 'supp_account_no', 'wo_ref', 'debtor_ref','type', 'trans_no', 
                        'StockItemName', 'tax_id', 'order_', 'delivery_date', 'units_issued',
                        'due_date', 'required_by', 'payment_terms', 'curr_code',
-                       'ov_freight', 'ov_gst', 'ov_amount', 'prepaid'),
 -                      'ov_freight', 'ov_gst', 'ov_amount', 'requisition_no', 'contact'),
++                      'ov_freight', 'ov_gst', 'ov_amount', 'prepaid', 'requisition_no', 'contact'),
                'branch' => array('br_address', 'br_name', 'salesman', 'disable_branch'),
                'sales_order' => array('deliver_to', 'delivery_address', 'customer_ref'),
                'bankaccount' => array('bank_name', 'bank_account_number', 'payment_service')
diff --combined reporting/rep209.php
index 1131a350464478182e6962f7ad57ceccc7042dfd,343f9f7dee5f35dcdbaecdde094e85e6aa31703d..b74ac209845ce4cc8abd5446e6b9943ac5193280
@@@ -34,7 -34,7 +34,7 @@@ print_po()
  function get_po($order_no)
  {
        $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name,  "
-               .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,".TB_PREF."suppliers.tax_algorithm,
 -              .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,".TB_PREF."suppliers.gst_no AS tax_id,
++              .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,".TB_PREF."suppliers.tax_algorithm,".TB_PREF."suppliers.gst_no AS tax_id,
                ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."locations.location_name,
                ".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact, ".TB_PREF."suppliers.tax_group_id
                FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
@@@ -169,7 -169,7 +169,7 @@@ function print_po(
                $rep->NewLine();
  
                $tax_items = get_tax_for_items($items, $prices, 0,
 -                $myrow['tax_group_id'], $myrow['tax_included'],  null);
 +                $myrow['tax_group_id'], $myrow['tax_included'],  null, $myrow['tax_algorithm']);
                $first = true;
                foreach($tax_items as $tax_item)
                {
                                continue;
                        $DisplayTax = number_format2($tax_item['Value'], $dec);
  
 -                      $tax_type_name = $tax_item['tax_type_name'];
 +                      if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
 +                              $tax_type_name = $tax_item['tax_type_name'];
 +                      else
 +                              $tax_type_name = $tax_item['tax_type_name']." (".$tax_item['rate']."%) ";
  
                        if ($myrow['tax_included'])
                        {