7db56ed35ba8b31591b717cd8bfa6e0b44e62a33
[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     include_once($path_to_root . "/reporting/includes/pdf_report.inc");
60
61     $frompart = $_POST['PARAM_0'];
62     $topart = $_POST['PARAM_1'];
63     $comments = $_POST['PARAM_2'];
64
65         $cols = array(0, 50, 305, 375, 445,     515);
66
67         $headers = array(_('Component'), _('Description'), _('Loc'), _('Wrk Ctr'), _('Quantity'));
68
69         $aligns = array('left', 'left', 'left', 'left', 'right');
70
71     $params =   array(  0 => $comments,
72                                     1 => array('text' => _('Component'), 'from' => $frompart, 'to' => $topart));
73
74     $rep = new FrontReport(_('Bill of Material Listing'), "BillOfMaterial.pdf", user_pagesize());
75
76     $rep->Font();
77     $rep->Info($params, $cols, $headers, $aligns);
78     $rep->Header();
79
80         $res = getTransactions($frompart, $topart);
81         $parent = '';
82         while ($trans=db_fetch($res))
83         {
84                 if ($parent != $trans['parent'])
85                 {
86                         if ($parent != '')
87                         {
88                                 $rep->Line($rep->row - 2);
89                                 $rep->NewLine(2, 3);
90                         }
91                         $rep->TextCol(0, 1, $trans['parent']);
92                         $desc = get_item($trans['parent']);
93                         $rep->TextCol(1, 2, $desc['description']);
94                         $parent = $trans['parent'];
95                         $rep->NewLine();
96                 }
97
98                 $rep->NewLine();
99                 $dec = get_qty_dec($trans['component']);
100                 $rep->TextCol(0, 1, $trans['component']);
101                 $rep->TextCol(1, 2, $trans['CompDescription']);
102                 //$rep->TextCol(2, 3, $trans['loc_code']);
103                 //$rep->TextCol(3, 4, $trans['workcentre_added']);
104                 $wc = get_work_centre($trans['workcentre_added']);
105                 $rep->TextCol(2, 3, get_location_name($trans['loc_code']));
106                 $rep->TextCol(3, 4, $wc['name']);
107                 $rep->TextCol(4, 5, number_format2($trans['quantity'], $dec));
108         }
109         $rep->Line($rep->row - 4);
110     $rep->End();
111 }
112
113 ?>