References saved in refs table for all documents for easy access.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 8 May 2009 10:33:53 +0000 (10:33 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 8 May 2009 10:33:53 +0000 (10:33 +0000)
16 files changed:
dimensions/includes/dimensions_db.inc
includes/references.inc
inventory/includes/db/items_adjust_db.inc
inventory/includes/db/items_transfer_db.inc
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
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/db/supp_payment_db.inc
sales/includes/db/payment_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sql/alter2.2.php

index 2dfe683846e4738ff20bca0c604d5d7c51a18169..344305a209f76adf1333767ffd5a0cb7e170b109 100644 (file)
@@ -24,7 +24,7 @@ function add_dimension($reference, $name, $type_, $date_, $due_date, $memo_)
 
        add_comments(systypes::dimension(), $id, $date_, $memo_);
 
-       references::save_last($reference, systypes::dimension());
+       references::save(systypes::dimension(), $id, $reference);
 
        commit_transaction();
 
index 6f3bd8916ec9b61e5357a2e4312896bbd62f30eb..1f9455997a830ea6ca07661272ac7ecddb156184 100644 (file)
@@ -17,8 +17,8 @@ class references
        function save($type, $id, $reference) 
        {
                add_reference($type, $id, $reference);
-               
-               references::save_last($reference, $type);
+               if ($reference != 'auto')
+                       references::save_last($reference, $type);
        }
        
        function get($type, $id) 
index 61d130d5f01e6788379a127f319ec06813b261fb..b51110694fb70eab1face682d684a9a445a10a1b 100644 (file)
@@ -29,7 +29,7 @@ function add_stock_adjustment($items, $location, $date_, $type, $increase, $refe
 
        add_comments(systypes::inventory_adjustment(), $adj_id, $date_, $memo_);
 
-       references::save_last($reference, systypes::inventory_adjustment());
+       references::save(systypes::inventory_adjustment(), $adj_id, $reference);
        add_audit_trail(systypes::inventory_adjustment(), $adj_id, $date_);
 
        commit_transaction();
index c1eac28b8538f06064d905963b1c684cf71a0f9c..5784453b0361fb9582c53c25527d56597bd97865 100644 (file)
@@ -25,7 +25,7 @@ function add_stock_transfer($Items, $location_from, $location_to, $date_, $type,
 
        add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);
 
-       references::save_last($reference, systypes::location_transfer());
+       references::save(systypes::location_transfer(), $transfer_id, $reference);
        add_audit_trail(systypes::location_transfer(), $transfer_id, $date_);
 
        commit_transaction();
index a8fc6b1c95e95cfe1e7e5084d74c5e7de7599452..9fbbfb69c299e6e549fe0d3036ffdcb90c224c54 100644 (file)
@@ -58,7 +58,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
        if ($memo_)
                add_comments(28, $number, $date_, $memo_);
 
-       references::save_last($ref, 28);
+       references::save(28, $number, $ref);
        add_audit_trail(28, $number, $date_);
 
        commit_transaction();
index 4419e7e23b2f702a7b9c7a804953d7ee63a90932..b4cac9fd37699fb5ef5ceecd0948e5973fb3d153 100644 (file)
@@ -53,7 +53,7 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
        if ($memo_)
                add_comments(29, $id, $date_, $memo_);
 
-       references::save_last($ref, 29);
+       references::save(29, $id, $ref);
        add_audit_trail(29, $id, $date_, _("Production."));
 
        commit_transaction();
index 1c17ea86a5f9a4b886984200f8d13d07226c2f22..4c7f1855ae7b3a5bcba903d50b6e531413f7d06c 100644 (file)
@@ -59,7 +59,7 @@ function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
 
        add_comments(systypes::work_order(), $woid, $required_by, $memo_);
 
-       references::save_last($wo_ref, systypes::work_order());
+       references::save(systypes::work_order(), $woid, $wo_ref);
        add_audit_trail(systypes::work_order(), $woid, $date_);
 
        commit_transaction();
index 8595b21066c4e56d632bc70f32297af6a96fb52d..471ca420aab9330d016e95a37566ad5246bbbd7e 100644 (file)
@@ -72,7 +72,7 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type,
 
        add_comments(systypes::work_order(), $woid, $date_, $memo_);
 
-       references::save_last($wo_ref, systypes::work_order());
+       references::save(systypes::work_order(), $woid, $wo_ref);
        add_audit_trail(systypes::work_order(), $woid, $date_,_("Quick production."));
        commit_transaction();
        return $woid;
index df526f14fdb85328a45050dd04195bc39fe51058..6da5481641d2d0607f34c036a8fb521d60bce1e9 100644 (file)
@@ -95,7 +95,7 @@ function add_grn(&$po, $date_, $reference, $location)
                } /*quantity received is != 0 */
        } /*end of order_line loop */
 
-       references::save_last($reference, 25);
+       references::save(25, $grn, $reference);
 
        add_audit_trail(25, $grn, $date_);
 
index 2ee490189f08fb2e8233061deff7b00905752ed7..936f8cbaf6c5ffeb2e855fcd547f3a4b66bf809a 100644 (file)
@@ -286,7 +286,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
 
        add_comments($trans_type, $invoice_id, $date_, $supp_trans->Comments);
 
-       references::save_last($supp_trans->reference, $trans_type);
+       references::save($trans_type, $invoice_id, $supp_trans->reference);
 
        if ($invoice_no != 0)
        {
index 350b828086d0074c5ab21c43a2dc446c777dac70..ca67638f05b537832dfdb89c3160173c0413d8cd 100644 (file)
@@ -56,11 +56,11 @@ function add_po(&$po_obj)
        }
      }
 
-       references::save_last($po_obj->reference, systypes::po());
+       references::save(systypes::po(), $po_obj->order_no, $po_obj->reference);
 
        //add_comments(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
 
-       add_audit_trail(systypes::po(), systypes::po(), $po_obj->orig_order_date);
+       add_audit_trail(systypes::po(), $po_obj->order_no, $po_obj->orig_order_date);
        commit_transaction();
 
        return $po_obj->order_no;
index 35e93db48334a2d3181b052ee88708a1a807fdd5..516dfba1df0afade211ae4c1bebd8238b4417e79 100644 (file)
@@ -68,7 +68,7 @@ function add_supp_payment($supplier_id, $date_, $bank_account,
 
        add_comments($trans_type, $payment_id, $date_, $memo_);
 
-       references::save_last($ref, $trans_type);
+       references::save($trans_type, $payment_id, $ref);
 
        commit_transaction();
 
index 12e7cc0fab833df3b19219c4fc50284a0092df10..3697196915ece047d2597bd1f37566a5cb2ce034 100644 (file)
@@ -71,7 +71,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
        add_comments(12, $payment_no, $date_, $memo_);
 
-       references::save_last($ref, 12);
+       references::save(12, $payment_no, $ref);
 
        commit_transaction();
 
index 0cea7655c5a2ddce7b6e6f44eb761de5587eca88..8e3cd494b47c9a7992d0cd9db23f6f5285e19cb0 100644 (file)
@@ -171,7 +171,7 @@ function write_credit_note($credit_note, $write_off_acc)
        add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
 
        if ($trans_no == 0) {
-               references::save_last($credit_note->reference, 11);
+               references::save(11, $credit_no, $credit_note->reference);
        }
 
        commit_transaction();
index 9155c0894e4c3b4dab8f0193a146a4f9c18c734e..3945f286c7fc389027cb8d7863b6ea80ea324967 100644 (file)
@@ -135,8 +135,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
        add_comments(13, $delivery_no, $delivery->document_date, $delivery->Comments);
 
        if ($trans_no == 0) {
-               if ($delivery->reference!='auto')
-                       references::save_last($delivery->reference, 13);
+                       references::save(13, $delivery_no, $delivery->reference);
        }
 
        commit_transaction();
index 72a26840713d4475567153e67b46748fbd84c976..7a4cf751a89f99df0560bbe303ce9734dbf409d4 100644 (file)
@@ -19,7 +19,7 @@ class fa2_2 {
        //
        function install($pref, $force) 
        {
-               global $db;
+               global $db, $systypes_array;
                // set item category dflt accounts to values from company GL setup
                $prefs = get_company_prefs();
                $sql = "UPDATE {$pref}stock_category SET "
@@ -33,6 +33,27 @@ class fa2_2 {
                        .':<br>'. db_error_msg($db));
                        return false;
                }
+               // add all references to refs table for easy searching via journal interface
+               foreach($systypes_array as $typeno => $typename) {
+                       $info = get_systype_db_info($typeno);
+                       if ($info == null || $info[3] == null) continue;
+                       $tbl = str_replace(TB_PREF, $pref, $info[0]);
+                       $sql = "SELECT {$info[2]} as id,{$info[3]} as ref FROM $tbl";
+                       if ($info[1])
+                               $sql .= " WHERE {$info[1]}=$typeno";
+                       $result = db_query($sql);
+                       if(db_num_rows($result)) {
+                               while($row = db_fetch($result)) {
+                                       $res2 = db_query("INSERT INTO {$pref}refs VALUES("
+                                               . $row['id'].",".$typeno.",'".$row['ref']."')");
+                                       if (!$res2) {
+                                               display_error(_("Cannot copy references from $tbl")
+                                                       .':<br>'. db_error_msg($db));
+                                               return false;
+                                       }
+                               }
+                       }
+               }
 /*     FIX
                // add audit_trail data for all transactions
                $datatbl = array ("gl_trans", "purch_orders", "sales_orders",