Possibility to 'Credit This' in supplier transactions like in customer transaction.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 5 Jan 2009 12:26:25 +0000 (12:26 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 5 Jan 2009 12:26:25 +0000 (12:26 +0000)
If there are many invoice items during a year, there would be many rows suggestions.

CHANGELOG.txt
purchasing/includes/db/grn_db.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/inquiry/supplier_inquiry.php
purchasing/supplier_credit.php

index ca2f78ea55aaada7643a3c8d96e7d9eb03d3c681..cdc9969a1df633c8abb32d74e9080c5f4d9590d2 100644 (file)
@@ -19,6 +19,14 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+05-Jan-2009 Joe Hunt
++ Possibility to 'Credit This' in supplier transactions like in customer transaction.
+  If there are many invoice items during a year, there would be many rows suggestions.
+$ /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/ui/invoice_ui.inc
+  /purchasing/supplier_credit.php
+  /purchasing/inquiry/supplier_inquiry.php
+  
 22-Dec-2008 Janusz Dobrowolski
 # Fixed item_code database update on item creation.
 $ /inventory/includes/db/item_codes_db.inc
index f360a1ff18f3b2735c688ef747756055fe784ea6..10e0d1cff3d2676e864b3878311d4880b8e515a4 100644 (file)
@@ -175,14 +175,20 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
 }
 
 function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
-       $is_invoiced_only=false)
+       $is_invoiced_only=false, $invoice_no=0)
 {
     $sql = "SELECT ".TB_PREF."grn_batch.*, ".TB_PREF."grn_items.*, ".TB_PREF."purch_order_details.unit_price,
                ".TB_PREF."purch_order_details.std_cost_unit, units
-       FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, ".TB_PREF."purch_order_details, ".TB_PREF."stock_master
-       WHERE ".TB_PREF."grn_items.grn_batch_id=".TB_PREF."grn_batch.id
-               AND ".TB_PREF."grn_items.po_detail_item=".TB_PREF."purch_order_details.po_detail_item
-       AND ".TB_PREF."stock_master.stock_id=".TB_PREF."grn_items.item_code ";
+       FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, ".TB_PREF."purch_order_details, ".TB_PREF."stock_master";
+    if ($invoice_no != 0)
+       $sql .= ", ".TB_PREF."supp_invoice_items";
+    $sql .= " WHERE ".TB_PREF."grn_items.grn_batch_id=".TB_PREF."grn_batch.id
+               AND ".TB_PREF."grn_items.po_detail_item=".TB_PREF."purch_order_details.po_detail_item";
+       if ($invoice_no != 0)
+               $sql .= " AND ".TB_PREF."supp_invoice_items.supp_trans_type=20 AND 
+                       ".TB_PREF."supp_invoice_items.supp_trans_no=$invoice_no AND
+                       ".TB_PREF."grn_items.id=".TB_PREF."supp_invoice_items.grn_item_id";
+       $sql .= " AND ".TB_PREF."stock_master.stock_id=".TB_PREF."grn_items.item_code ";
 
        if ($grn_batch_id != 0)
                $sql .= " AND ".TB_PREF."grn_batch.id=$grn_batch_id AND ".TB_PREF."grn_items.grn_batch_id=$grn_batch_id ";
index a361a8b38b615e360d1524ede8a545034f83cf2d..67f63e82e053eb705fd491be63368d2168267d7a 100644 (file)
@@ -63,11 +63,20 @@ function invoice_header(&$supp_trans)
 
        table_section(1);
 
-    if (!isset($_POST['supplier_id']) && (get_global_supplier() != reserved_words::get_all()))
-       $_POST['supplier_id'] = get_global_supplier();
-
-       supplier_list_row(_("Supplier:"), 'supplier_id', $_POST['supplier_id'], false, true);
+       if (isset($_POST['invoice_no']))
+       {
+               $trans = get_supp_trans($_POST['invoice_no'], 20);
+               $_POST['supplier_id'] = $trans['supplier_id'];
+               $supp = $trans['supplier_name'] . " - " . $trans['SupplierCurrCode'];
+               label_row(_("Supplier:"), $supp.hidden('supplier_id', $_POST['supplier_id'], false));
+       }       
+       else
+       {
+       if (!isset($_POST['supplier_id']) && (get_global_supplier() != reserved_words::get_all()))
+               $_POST['supplier_id'] = get_global_supplier();
 
+               supplier_list_row(_("Supplier:"), 'supplier_id', $_POST['supplier_id'], false, true);
+       }
        if ($supp_trans->supplier_id != $_POST['supplier_id'])
        {
                // supplier has changed
@@ -83,7 +92,12 @@ function invoice_header(&$supp_trans)
     else
        ref_row(_("Reference:"), 'reference', '', references::get_next(21));
 
-       text_row(_("Supplier's Ref.:"), 'supp_reference', $_POST['supp_reference'], 20, 20);
+       if (isset($_POST['invoice_no']))
+       {
+               label_row(_("Supplier's Ref.:"), $_POST['invoice_no'].hidden('invoice_no', $_POST['invoice_no'], false).hidden('supp_reference', $_POST['invoice_no'], false));
+       }       
+       else
+               text_row(_("Supplier's Ref.:"), 'supp_reference', $_POST['supp_reference'], 20, 20);
 
        table_section(2, "33%");
 
@@ -300,9 +314,13 @@ function display_grn_items_for_selection(&$supp_trans, $k)
 
        if ($supp_trans->is_invoice)
                $result = get_grn_items(0, $supp_trans->supplier_id, true);
-       else    
-               $result = get_grn_items(0, $supp_trans->supplier_id, false, true);
-
+       else
+       {
+               if (isset($_POST['invoice_no']))
+                       $result = get_grn_items(0, $supp_trans->supplier_id, false, true, $_POST['invoice_no']);
+               else    
+                       $result = get_grn_items(0, $supp_trans->supplier_id, false, true);
+       }
     if (db_num_rows($result) == 0)
     {
        return false;
index e2f237db9b1a3506ea133292053529771e4fed4e..c00b0613d05d90052d4d63d3014c47b69d8c3672 100644 (file)
@@ -114,6 +114,15 @@ function gl_view($row)
        return get_gl_view_str($row["type"], $row["trans_no"]);
 }
 
+function credit_link($row)
+{
+       return $row['type'] == 20 && $row["TotalAmount"] - $row["Allocated"] > 0 ?
+               pager_link(_("Credit This"),
+                       "/purchasing/supplier_credit.php?New=1&invoice_no=".
+                       $row['trans_no'], ICON_CREDIT)
+                       : '';
+}
+
 function fmt_debit($row)
 {
        $value = $row["TotalAmount"];
@@ -199,6 +208,7 @@ $cols = array(
                        _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'), 
                        _("Credit") => array('align'=>'right', 'insert'=>true,'fun'=>'fmt_credit'), 
                        array('insert'=>true, 'fun'=>'gl_view'),
+                       array('insert'=>true, 'fun'=>'credit_link')
                        );
 
 if ($_POST['supplier_id'] != reserved_words::get_all())
index 43def47d9012b99f3cb9a72d8bc8797f49fbb925..16c78c9c5e7c1425ae7795ae8925eca40d6310ff 100644 (file)
@@ -77,6 +77,10 @@ if (isset($_GET['New']))
 
        $_SESSION['supp_trans'] = new supp_trans;
        $_SESSION['supp_trans']->is_invoice = false;
+       if (isset($_GET['invoice_no']))
+       {
+               $_SESSION['supp_trans']->supp_reference = $_POST['invoice_no'] = $_GET['invoice_no'];
+       }
 }
 
 function clear_fields()