Improved db_pager query parsing (fixed error in Sales Quotation Inquiry)
[fa-stable.git] / includes / references.inc
index 0c11ebee3defacaa1d96bcdfb61a25a862f08160..6a8c7af2d0f87044206bc2fb0f243697e90b1051 100644 (file)
@@ -57,7 +57,7 @@ class references
        function save($type, $id, $reference) 
        {
                update_reference($type, $id, $reference); // store in refs table
-               if ($reference == $this->get_next($type)) { // if reference was not changed from default
+               if ($reference == $this->get_next($type)) { // if reference was bigger or not changed from default
                        $next = $this->_increment($reference);  // increment default
                        save_next_reference($type, $next);
                }
@@ -101,8 +101,10 @@ class references
 }
 
 //----------------------------------------------------------------------------
-
-function is_new_reference($ref, $type)
+//
+//     Check if reference was not used so far (for other transaction than $trans_no)
+//
+function is_new_reference($ref, $type, $trans_no=0)
 {
        $db_info = get_systype_db_info($type);
        $db_name = $db_info[0];
@@ -114,10 +116,10 @@ function is_new_reference($ref, $type)
        $type = db_escape($type);
        
        if ($db_ref == null) { // journal or bank trans store references in refs table
-               $db_ref = TB_PREF."refs";
+               $db_name = TB_PREF."refs";
                $db_type = 'type';
                $db_trans = 'id';
-               $rb_ref = 'reference';
+               $db_ref = 'reference';
        }
 
        if ($db_type != null) {