Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / reporting / rep204.php
index ba14f2ceac4ccc1964c393b6e61480a57873f86a..cc8b536298e88c629e4dc30accd80d68c0b62746 100644 (file)
@@ -29,30 +29,29 @@ print_outstanding_GRN();
 
 function getTransactions($fromsupp)
 {
-       $sql = "SELECT ".TB_PREF."grn_batch.id,
+       $sql = "SELECT grn.id,
                        order_no,
-                       ".TB_PREF."grn_batch.supplier_id,
-                       ".TB_PREF."suppliers.supp_name,
-                       ".TB_PREF."grn_items.item_code,
-                       ".TB_PREF."grn_items.description,
+                       grn.supplier_id,
+                       supplier.supp_name,
+                       item.item_code,
+                       item.description,
                        qty_recd,
                        quantity_inv,
-                       std_cost_unit,
                        act_price,
                        unit_price
-               FROM ".TB_PREF."grn_items,
-                       ".TB_PREF."grn_batch,
-                       ".TB_PREF."purch_order_details,
-                       ".TB_PREF."suppliers
-               WHERE ".TB_PREF."grn_batch.supplier_id=".TB_PREF."suppliers.supplier_id
-               AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id
-               AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
-               AND qty_recd-quantity_inv <>0 ";
+               FROM ".TB_PREF."grn_items item,
+                       ".TB_PREF."grn_batch grn,
+                       ".TB_PREF."purch_order_details poline,
+                       ".TB_PREF."suppliers supplier
+               WHERE grn.supplier_id=supplier.supplier_id
+               AND grn.id = item.grn_batch_id
+               AND item.po_detail_item = poline.po_detail_item
+               AND qty_recd-quantity_inv!=0";
 
        if ($fromsupp != ALL_TEXT)
-               $sql .= "AND ".TB_PREF."grn_batch.supplier_id =".db_escape($fromsupp)." ";
-       $sql .= "ORDER BY ".TB_PREF."grn_batch.supplier_id,
-                       ".TB_PREF."grn_batch.id";
+               $sql .= " AND grn.supplier_id =".db_escape($fromsupp);
+
+       $sql .= " ORDER BY grn.supplier_id,     grn.id";
 
     return db_query($sql, "No transactions were returned");
 }
@@ -102,7 +101,7 @@ function print_outstanding_GRN()
        $SuppTot_Val=0;
        $res = getTransactions($fromsupp);
 
-       While ($GRNs = db_fetch($res))
+       while ($GRNs = db_fetch($res))
        {
                $dec2 = get_qty_dec($GRNs['item_code']);
                if ($Supplier != $GRNs['supplier_id'])
@@ -126,9 +125,9 @@ function print_outstanding_GRN()
                $rep->AmountCol(3, 4, $GRNs['qty_recd'], $dec2);
                $rep->AmountCol(4, 5, $GRNs['quantity_inv'], $dec2);
                $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
-               $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['act_price'];
+               $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['unit_price'];
                $rep->AmountCol(5, 6, $QtyOstg, $dec2);
-               $rep->AmountCol(6, 7, $GRNs['act_price'], $dec);
+               $rep->AmountCol(6, 7, $GRNs['unit_price'], $dec);
                $rep->AmountCol(7, 8, $Value, $dec);
                $Tot_Val += $Value;
                $SuppTot_Val += $Value;