*** empty log message ***
[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, $tosupp)
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                 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";
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     $tosupp = $_POST['PARAM_1'];
61     $comments = $_POST['PARAM_2'];
62     
63         if ($fromsupp == null)
64                 $fromsupp = 0;
65         if ($tosupp == null)
66                 $tosupp = 0;
67     $dec = user_price_dec();
68
69         $cols = array(0, 40, 80, 190,   250, 320, 385, 450,     515);
70
71         $headers = array(_('GRN'), _('Order'), _('Item') . '/' . _('Description'), _('Qty Recd'), _('qty Inv'), _('Balance'),
72                 _('Std Cost'), _('Value'));
73
74         $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
75
76     $params =   array(  0 => $comments,
77                                     1 => array('text' => _('Supplier'), 'from' => get_supplier_name($fromsupp),
78                             'to' => get_supplier_name($tosupp)));
79
80     $rep = new FrontReport(_('Outstanding GRNs Report'), "OutstandingGRN.pdf", user_pagesize());
81
82     $rep->Font();
83     $rep->Info($params, $cols, $headers, $aligns);
84     $rep->Header();
85
86         $Tot_Val=0;
87         $Supplier = '';
88         $SuppTot_Val=0;
89         $res = getTransactions($fromsupp, $tosupp);
90         
91         While ($GRNs = db_fetch($res))
92         {       
93                 if ($Supplier != $GRNs['supplier_id'])
94                 {
95                         if ($Supplier != '')
96                         {
97                                 $rep->NewLine(2);
98                                 $rep->TextCol(0, 7, _('Total'));
99                                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
100                                 $rep->Line($rep->row - 2);
101                                 $rep->NewLine(3);
102                                 $SuppTot_Val = 0;
103                         }
104                         $rep->TextCol(0, 6, $GRNs['supp_name']);
105                         $Supplier = $GRNs['supplier_id'];
106                 }
107                 $rep->NewLine();
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));
118                 $Tot_Val += $Value;
119                 $SuppTot_Val += $Value;
120
121                 $rep->NewLine(0, 1);
122         }
123         if ($Supplier != '')
124         {
125                 $rep->NewLine();
126                 $rep->TextCol(0, 7, _('Total'));
127                 $rep->TextCol(7, 8, number_format2($SuppTot_Val, $dec));
128                 $rep->Line($rep->row - 2);
129                 $rep->NewLine(3);
130                 $SuppTot_Val = 0;
131         }
132         $rep->NewLine(2);
133         $rep->TextCol(0, 7, _('Grand Total'));
134         $rep->TextCol(7, 8, number_format2($Tot_Val, $dec));
135         $rep->Line($rep->row - 2);
136     $rep->End();
137 }
138
139 ?>