Incorrect Journal Balance (sales invoice) when many decimals in tax and price.
[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 = 'SA_BOMREP';
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 print_bill_of_material();
30
31 function getTransactions($from, $to)
32 {
33         $sql = "SELECT bom.parent,
34                         bom.component,
35                         item.description as CompDescription,
36                         bom.quantity,
37                         bom.loc_code,
38                         bom.workcentre_added
39                 FROM "
40                         .TB_PREF."stock_master item,"
41                         .TB_PREF."bom bom
42                 WHERE item.stock_id=bom.component
43                 AND bom.parent >= ".db_escape($from)."
44                 AND bom.parent <= ".db_escape($to)."
45                 ORDER BY
46                         bom.parent,
47                         bom.component";
48
49     return db_query($sql,"No transactions were returned");
50 }
51
52 //----------------------------------------------------------------------------------------------------
53
54 function print_bill_of_material()
55 {
56     global $path_to_root;
57
58     $frompart = $_POST['PARAM_0'];
59     $topart = $_POST['PARAM_1'];
60     $comments = $_POST['PARAM_2'];
61         $orientation = $_POST['PARAM_3'];
62         $destination = $_POST['PARAM_4'];
63         if ($destination)
64                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
65         else
66                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
67
68         $orientation = ($orientation ? 'L' : 'P');
69         $cols = array(0, 50, 305, 375, 445,     515);
70
71         $headers = array(_('Component'), _('Description'), _('Loc'), _('Wrk Ctr'), _('Quantity'));
72
73         $aligns = array('left', 'left', 'left', 'left', 'right');
74
75     $params =   array(  0 => $comments,
76                                     1 => array('text' => _('Component'), 'from' => $frompart, 'to' => $topart));
77
78     $rep = new FrontReport(_('Bill of Material Listing'), "BillOfMaterial", user_pagesize(), 9, $orientation);
79     if ($orientation == 'L')
80         recalculate_cols($cols);
81
82     $rep->Font();
83     $rep->Info($params, $cols, $headers, $aligns);
84     $rep->NewPage();
85
86         $res = getTransactions($frompart, $topart);
87         $parent = '';
88         while ($trans=db_fetch($res))
89         {
90                 if ($parent != $trans['parent'])
91                 {
92                         if ($parent != '')
93                         {
94                                 $rep->Line($rep->row - 2);
95                                 $rep->NewLine(2, 3);
96                         }
97                         $rep->TextCol(0, 1, $trans['parent']);
98                         $desc = get_item($trans['parent']);
99                         $rep->TextCol(1, 2, $desc['description']);
100                         $parent = $trans['parent'];
101                         $rep->NewLine();
102                 }
103
104                 $rep->NewLine();
105                 $dec = get_qty_dec($trans['component']);
106                 $rep->TextCol(0, 1, $trans['component']);
107                 $rep->TextCol(1, 2, $trans['CompDescription']);
108                 $wc = get_work_centre($trans['workcentre_added']);
109                 $rep->TextCol(2, 3, get_location_name($trans['loc_code']));
110                 $rep->TextCol(3, 4, $wc['name']);
111                 $rep->AmountCol(4, 5, $trans['quantity'], $dec);
112         }
113         $rep->Line($rep->row - 4);
114         $rep->NewLine();
115     $rep->End();
116 }
117