4 // ----------------------------------------------------------------
8 // Title: Outstanding GRNs Report
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_outstanding_GRN();
22 function getTransactions($fromsupp, $tosupp)
24 $sql = "SELECT ".TB_PREF."grn_batch.id,
26 ".TB_PREF."grn_batch.supplier_id,
27 ".TB_PREF."suppliers.supp_name,
28 ".TB_PREF."grn_items.item_code,
29 ".TB_PREF."grn_items.description,
35 FROM ".TB_PREF."grn_items,
37 ".TB_PREF."purch_order_details,
39 WHERE ".TB_PREF."grn_batch.supplier_id=".TB_PREF."suppliers.supplier_id
40 AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id
41 AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
42 AND qty_recd-quantity_inv <>0
43 AND ".TB_PREF."grn_batch.supplier_id >='" . $fromsupp . "'
44 AND ".TB_PREF."grn_batch.supplier_id <='" . $tosupp . "'
45 ORDER BY ".TB_PREF."grn_batch.supplier_id,
46 ".TB_PREF."grn_batch.id";
48 return db_query($sql, "No transactions were returned");
51 //----------------------------------------------------------------------------------------------------
53 function print_outstanding_GRN()
57 include_once($path_to_root . "reporting/includes/pdf_report.inc");
59 $fromsupp = $_POST['PARAM_0'];
60 $tosupp = $_POST['PARAM_1'];
61 $comments = $_POST['PARAM_2'];
63 if ($fromsupp == null)
67 $dec = user_price_dec();
69 $cols = array(0, 40, 80, 190, 250, 320, 385, 450, 515);
71 $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
72 _('Std Cost'), _('Value'));
74 $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
76 $params = array( 0 => $comments,
77 1 => array('text' => _('Supplier'), 'from' => get_supplier_name($fromsupp),
78 'to' => get_supplier_name($tosupp)));
80 $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN.pdf", user_pagesize());
83 $rep->Info($params, $cols, $headers, $aligns);
89 $res = getTransactions($fromsupp, $tosupp);
91 While ($GRNs = db_fetch($res))
93 if ($Supplier != $GRNs['supplier_id'])
98 $rep->TextCol(0, 7, _('Total'));
99 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
100 $rep->Line($rep->row - 2);
104 $rep->TextCol(0, 6, $GRNs['supp_name']);
105 $Supplier = $GRNs['supplier_id'];
108 $rep->TextCol(0, 1, $GRNs['id']);
109 $rep->TextCol(1, 2, $GRNs['order_no']);
110 $rep->TextCol(2, 3, $GRNs['item_code'] . '-' . $GRNs['description']);
111 $rep->TextCol(3, 4, number_format2($GRNs['qty_recd'], $dec));
112 $rep->TextCol(4, 5, number_format2($GRNs['quantity_inv'], $dec));
113 $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
114 $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['std_cost_unit'];
115 $rep->TextCol(5, 6, number_format2($QtyOstg, $dec));
116 $rep->TextCol(6, 7, number_format2($GRNs['std_cost_unit'], $dec));
117 $rep->TextCol(7, 8, number_format2($Value, $dec));
119 $SuppTot_Val += $Value;
126 $rep->TextCol(0, 7, _('Total'));
127 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
128 $rep->Line($rep->row - 2);
133 $rep->TextCol(0, 7, _('Grand Total'));
134 $rep->TextCol(7, 8, number_format2($Tot_Val, $dec));
135 $rep->Line($rep->row - 2);