Release 1.0.1 established on SourceForge, fixing the bugs and including a Date Picker...
[fa-stable.git] / reporting / rep204.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Outstanding GRNs Report
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
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");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_outstanding_GRN();
21
22 function getTransactions($fromsupp)
23 {
24         $sql = "SELECT ".TB_PREF."grn_batch.id,
25                         order_no,
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,
30                         qty_recd,
31                         quantity_inv,
32                         std_cost_unit,
33                         act_price,
34                         unit_price
35                 FROM ".TB_PREF."grn_items,
36                         ".TB_PREF."grn_batch,
37                         ".TB_PREF."purch_order_details,
38                         ".TB_PREF."suppliers
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         if ($fromsupp != reserved_words::get_all_numeric())
44                 $sql .= "AND ".TB_PREF."grn_batch.supplier_id ='" . $fromsupp . "' ";
45         $sql .= "ORDER BY ".TB_PREF."grn_batch.supplier_id, 
46                         ".TB_PREF."grn_batch.id";
47
48     return db_query($sql, "No transactions were returned");
49 }
50
51 //----------------------------------------------------------------------------------------------------
52
53 function print_outstanding_GRN()
54 {
55     global $path_to_root;
56
57     include_once($path_to_root . "reporting/includes/pdf_report.inc");
58
59     $fromsupp = $_POST['PARAM_0'];
60     $comments = $_POST['PARAM_1'];
61     
62         if ($fromsupp == reserved_words::get_all_numeric())
63                 $from = _('All');
64         else
65                 $from = get_supplier_name($fromsupp);
66     $dec = user_price_dec();
67
68         $cols = array(0, 40, 80, 190,   250, 320, 385, 450,     515);
69
70         $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
71                 _('Std Cost'), _('Value'));
72
73         $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
74
75     $params =   array(  0 => $comments,
76                                     1 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''));
77
78     $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN.pdf", user_pagesize());
79
80     $rep->Font();
81     $rep->Info($params, $cols, $headers, $aligns);
82     $rep->Header();
83
84         $Tot_Val=0;
85         $Supplier = '';
86         $SuppTot_Val=0;
87         $res = getTransactions($fromsupp);
88         
89         While ($GRNs = db_fetch($res))
90         {       
91                 if ($Supplier != $GRNs['supplier_id'])
92                 {
93                         if ($Supplier != '')
94                         {
95                                 $rep->NewLine(2);
96                                 $rep->TextCol(0, 7, _('Total'));
97                                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
98                                 $rep->Line($rep->row - 2);
99                                 $rep->NewLine(3);
100                                 $SuppTot_Val = 0;
101                         }
102                         $rep->TextCol(0, 6, $GRNs['supp_name']);
103                         $Supplier = $GRNs['supplier_id'];
104                 }
105                 $rep->NewLine();
106                 $rep->TextCol(0, 1, $GRNs['id']);
107                 $rep->TextCol(1, 2, $GRNs['order_no']);
108                 $rep->TextCol(2, 3, $GRNs['item_code'] . '-' . $GRNs['description']);
109                 $rep->TextCol(3, 4, number_format2($GRNs['qty_recd'], $dec));
110                 $rep->TextCol(4, 5, number_format2($GRNs['quantity_inv'], $dec));
111                 $QtyOstg = $GRNs['qty_recd'] - $GRNs['quantity_inv'];
112                 $Value = ($GRNs['qty_recd'] - $GRNs['quantity_inv']) * $GRNs['std_cost_unit'];
113                 $rep->TextCol(5, 6, number_format2($QtyOstg, $dec));
114                 $rep->TextCol(6, 7, number_format2($GRNs['std_cost_unit'], $dec));
115                 $rep->TextCol(7, 8, number_format2($Value, $dec));
116                 $Tot_Val += $Value;
117                 $SuppTot_Val += $Value;
118
119                 $rep->NewLine(0, 1);
120         }
121         if ($Supplier != '')
122         {
123                 $rep->NewLine();
124                 $rep->TextCol(0, 7, _('Total'));
125                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
126                 $rep->Line($rep->row - 2);
127                 $rep->NewLine(3);
128                 $SuppTot_Val = 0;
129         }
130         $rep->NewLine(2);
131         $rep->TextCol(0, 7, _('Grand Total'));
132         $rep->TextCol(7, 8, number_format2($Tot_Val, $dec));
133         $rep->Line($rep->row - 2);
134     $rep->End();
135 }
136
137 ?>