[0000607] Issue with Inventory Adjustment with 0 cost value
[fa-stable.git] / reporting / rep305.php
index b752c6efba3d842690bfe7c6eb62148db57bfa49..879e70ea67b122d06f398ec578f72520f080d99c 100644 (file)
@@ -33,22 +33,47 @@ function getTransactions($from, $to)
 {
        $from = date2sql($from);
        $to = date2sql($to);
-       $sql = "SELECT ".TB_PREF."grn_batch.delivery_date, ".TB_PREF."grn_batch.supplier_id, 
-                       ".TB_PREF."purch_order_details.*,
-                       ".TB_PREF."stock_master.description
-               FROM ".TB_PREF."stock_master,
-                       ".TB_PREF."purch_order_details,
-                       ".TB_PREF."grn_batch
-               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.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";
+       
+       $sql = "SELECT ".TB_PREF."grn_batch.id batch_no,\r
+                       ".TB_PREF."grn_batch.supplier_id, \r
+            ".TB_PREF."purch_order_details.*,
+            ".TB_PREF."stock_master.description,\r
+                       ".TB_PREF."grn_items.qty_recd,\r
+                       ".TB_PREF."grn_items.quantity_inv,\r
+                       ".TB_PREF."grn_items.id grn_item_id\r
+        FROM ".TB_PREF."stock_master,
+            ".TB_PREF."purch_order_details,
+            ".TB_PREF."grn_batch,\r
+                       ".TB_PREF."grn_items \r
+        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."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id \r
+               AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item\r
+        AND ".TB_PREF."grn_items.qty_recd>0\r
+        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");
 
 }
 
+function getSuppInvDetails($grn_item_id)\r
+{\r
+       $sql = "SELECT\r
+                       ".TB_PREF."supp_invoice_items.supp_trans_no inv_no,\r
+                       ".TB_PREF."supp_invoice_items.quantity inv_qty,\r
+                       ".TB_PREF."supp_invoice_items.unit_price inv_price\r
+                       FROM ".TB_PREF."grn_items, ".TB_PREF."supp_invoice_items\r
+                       WHERE ".TB_PREF."grn_items.id = ".TB_PREF."supp_invoice_items.grn_item_id\r
+                       AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."supp_invoice_items.po_detail_item_id\r
+                       AND ".TB_PREF."grn_items.item_code = ".TB_PREF."supp_invoice_items.stock_id\r
+                       AND ".TB_PREF."supp_invoice_items.grn_item_id = ".$grn_item_id."\r
+                       ORDER BY ".TB_PREF."supp_invoice_items.id asc";\r
+\r
+       return db_query($sql,"No transactions were returned");\r
+}\r
+\r
 //----------------------------------------------------------------------------------------------------
 
 function print_grn_valuation()
@@ -66,10 +91,10 @@ function print_grn_valuation()
 
     $dec = user_price_dec();
 
-       $cols = array(0, 75, 225, 275, 345, 390, 445,   515);
-       $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('Qty Received'), _('Unit Price'), _('Actual Price'), _('Total'));
+       $cols = array(0, 75, 225, 260, 295, 330, 370, 410, 455, 515);\r
+       $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('GRN')."#", _('Inv')."#", _('Qty'), _('Inv Price'), _('PO Price'), _('Total'));\r
 
-       $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
+       $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');\r
 
     $params =   array(         0 => $comments,
                                    1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
@@ -78,7 +103,7 @@ function print_grn_valuation()
 
     $rep->Font();
     $rep->Info($params, $cols, $headers, $aligns);
-    $rep->Header();
+    $rep->NewPage();
 
        $res = getTransactions($from, $to);
        $total = $qtotal = $grandtotal = 0.0;
@@ -92,8 +117,8 @@ function print_grn_valuation()
                                $rep->Line($rep->row  - 4);
                                $rep->NewLine(2);
                                $rep->TextCol(0, 3, _('Total'));
-                               $rep->AmountCol(3, 4, $qtotal, $qdec);
-                               $rep->AmountCol(6, 7, $total, $dec);
+                               $rep->AmountCol(5, 6, $qtotal, $qdec);\r
+                               $rep->AmountCol(8, 9, $total, $dec);\r
                                $rep->NewLine();
                                $total = $qtotal = 0;
                        }
@@ -106,29 +131,55 @@ function print_grn_valuation()
 
                $rep->NewLine();
                $rep->TextCol(0, 1, $trans['item_code']);
-               $rep->TextCol(1, 2, $trans['description']);
+               $rep->TextCol(1, 2, $trans['description']);\r
                $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']);\r
+               \r
+               if ($trans['quantity_inv'])\r
+               {\r
+                       $suppinv = getSuppInvDetails($trans['grn_item_id']);\r
+                       while ($inv=db_fetch($suppinv))\r
+                       {       \r
+                               $inv['inv_price'] *= $rate;\r
+                               $rep->TextCol(4, 5, $inv['inv_no']);\r
+                               $rep->AmountCol(5, 6, $inv['inv_qty'], $qdec);\r
+                               $rep->AmountCol(6, 7, $inv['inv_price'], $dec);\r
+                               $rep->AmountCol(7, 8, $trans['unit_price'], $dec);\r
+                               $amt = round2($inv['inv_qty'] * $inv['inv_price'], $dec);\r
+                               $rep->AmountCol(8, 9, $amt, $dec);\r
+                               $rep->NewLine();\r
+                               $total += $amt;\r
+                               $qtotal += $inv['inv_qty'];\r
+                               $grandtotal += $amt;\r
+                       }\r
+               }\r
+       \r
+               if ($trans['qty_recd'] - $trans['quantity_inv'] !=0 )\r
+               {\r
+                       $rep->TextCol(4, 5, "--");\r
+                       $rep->AmountCol(5, 6, $trans['qty_recd'] - $trans['quantity_inv'], $qdec);\r
+                       $rep->AmountCol(7, 8, $trans['unit_price'], $dec);\r
+                       $amt = round2(($trans['qty_recd'] - $trans['quantity_inv']) * $trans['unit_price'], $dec);\r
+                       $rep->AmountCol(8, 9, $amt, $dec);\r
+                       $total += $amt;\r
+                       $qtotal += $trans['qty_recd'] - $trans['quantity_inv'];\r
+                       $grandtotal += $amt;\r
+               }\r
+               else\r
+                       $rep->NewLine(-1);\r
        }
        if ($stock_id != '')
        {
                $rep->Line($rep->row  - 4);
                $rep->NewLine(2);
                $rep->TextCol(0, 3, _('Total'));
-               $rep->AmountCol(3, 4, $qtotal, $qdec);
-               $rep->AmountCol(6, 7, $total, $dec);
+               $rep->AmountCol(5, 6, $qtotal, $qdec);\r
+               $rep->AmountCol(8, 9, $total, $dec);\r
                $rep->Line($rep->row  - 4);
                $rep->NewLine(2);
-               $rep->TextCol(0, 6, _('Grand Total'));
-               $rep->AmountCol(6, 7, $grandtotal, $dec);
+               $rep->TextCol(0, 7, _('Grand Total'));\r
+               $rep->AmountCol(8, 9, $grandtotal, $dec);\r
        }
 
        $rep->Line($rep->row  - 4);