3c8fed88b1ecb407a4c5df9e364262a546a49b27
[fa-stable.git] / reporting / rep401.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 2;
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       Bill Of Material
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
25 include_once($path_to_root . "/inventory/includes/db/items_db.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 // trial_inquiry_controls();
30 print_bill_of_material();
31
32 function getTransactions($from, $to)
33 {
34         $sql = "SELECT ".TB_PREF."bom.parent,
35                         ".TB_PREF."bom.component,
36                         ".TB_PREF."stock_master.description as CompDescription,
37                         ".TB_PREF."bom.quantity,
38                         ".TB_PREF."bom.loc_code,
39                         ".TB_PREF."bom.workcentre_added
40                 FROM
41                         ".TB_PREF."stock_master,
42                         ".TB_PREF."bom
43                 WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.component
44                 AND ".TB_PREF."bom.parent >= '$from'
45                 AND ".TB_PREF."bom.parent <= '$to'
46                 ORDER BY
47                         ".TB_PREF."bom.parent,
48                         ".TB_PREF."bom.component";
49
50     return db_query($sql,"No transactions were returned");
51 }
52
53 //----------------------------------------------------------------------------------------------------
54
55 function print_bill_of_material()
56 {
57     global $path_to_root;
58
59     $frompart = $_POST['PARAM_0'];
60     $topart = $_POST['PARAM_1'];
61     $comments = $_POST['PARAM_2'];
62         $destination = $_POST['PARAM_3'];
63         if ($destination)
64         {
65                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
66                 $filename = "BillOfMaterial.xml";
67         }       
68         else
69         {
70                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
71                 $filename = "BillOfMaterial.pdf";
72         }
73
74         $cols = array(0, 50, 305, 375, 445,     515);
75
76         $headers = array(_('Component'), _('Description'), _('Loc'), _('Wrk Ctr'), _('Quantity'));
77
78         $aligns = array('left', 'left', 'left', 'left', 'right');
79
80     $params =   array(  0 => $comments,
81                                     1 => array('text' => _('Component'), 'from' => $frompart, 'to' => $topart));
82
83     $rep = new FrontReport(_('Bill of Material Listing'), $filename, user_pagesize());
84
85     $rep->Font();
86     $rep->Info($params, $cols, $headers, $aligns);
87     $rep->Header();
88
89         $res = getTransactions($frompart, $topart);
90         $parent = '';
91         while ($trans=db_fetch($res))
92         {
93                 if ($parent != $trans['parent'])
94                 {
95                         if ($parent != '')
96                         {
97                                 $rep->Line($rep->row - 2);
98                                 $rep->NewLine(2, 3);
99                         }
100                         $rep->TextCol(0, 1, $trans['parent']);
101                         $desc = get_item($trans['parent']);
102                         $rep->TextCol(1, 2, $desc['description']);
103                         $parent = $trans['parent'];
104                         $rep->NewLine();
105                 }
106
107                 $rep->NewLine();
108                 $dec = get_qty_dec($trans['component']);
109                 $rep->TextCol(0, 1, $trans['component']);
110                 $rep->TextCol(1, 2, $trans['CompDescription']);
111                 //$rep->TextCol(2, 3, $trans['loc_code']);
112                 //$rep->TextCol(3, 4, $trans['workcentre_added']);
113                 $wc = get_work_centre($trans['workcentre_added']);
114                 $rep->TextCol(2, 3, get_location_name($trans['loc_code']));
115                 $rep->TextCol(3, 4, $wc['name']);
116                 $rep->AmountCol(4, 5, $trans['quantity'], $dec);
117         }
118         $rep->Line($rep->row - 4);
119         $rep->NewLine();
120     $rep->End();
121 }
122
123 ?>