Changed $path_to_root and stamped copyright
[fa-stable.git] / reporting / rep104.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 2;
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       price Listing
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/ui/ui_input.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
27 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
28
29 //----------------------------------------------------------------------------------------------------
30
31 // trial_inquiry_controls();
32 print_price_listing();
33
34 function fetch_items($category=0)
35 {
36                 $sql = "SELECT ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description AS name,
37                                 ".TB_PREF."stock_master.material_cost+".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS Standardcost,
38                                 ".TB_PREF."stock_master.category_id,
39                                 ".TB_PREF."stock_category.description
40                         FROM ".TB_PREF."stock_master,
41                                 ".TB_PREF."stock_category
42                         WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
43                 if ($category != 0)
44                         $sql .= " AND ".TB_PREF."stock_category.category_id = '$category'";
45                 $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
46                                 ".TB_PREF."stock_master.stock_id";
47
48     return db_query($sql,"No transactions were returned");
49 }
50 //----------------------------------------------------------------------------------------------------
51
52 function print_price_listing()
53 {
54     global $comp_path, $path_to_root, $pic_height, $pic_width;
55
56     include_once($path_to_root . "/reporting/includes/pdf_report.inc");
57
58     $currency = $_POST['PARAM_0'];
59     $category = $_POST['PARAM_1'];
60     $salestype = $_POST['PARAM_2'];
61     $pictures = $_POST['PARAM_3'];
62     $showGP = $_POST['PARAM_4'];
63     $comments = $_POST['PARAM_5'];
64
65     $dec = user_price_dec();
66
67         $home_curr = get_company_pref('curr_default');
68         if ($currency == reserved_words::get_all())
69                 $currency = $home_curr;
70         $curr = get_currency($currency);
71         $curr_sel = $currency . " - " . $curr['currency'];
72         if ($category == reserved_words::get_all_numeric())
73                 $category = 0;
74         if ($salestype == reserved_words::get_all_numeric())
75                 $salestype = 0;
76         if ($category == 0)
77                 $cat = _('All');
78         else
79                 $cat = get_category_name($category);
80         if ($salestype == 0)
81                 $stype = _('All');
82         else
83                 $stype = get_sales_type_name($salestype);
84         if ($showGP == 0)
85                 $GP = _('No');
86         else
87                 $GP = _('Yes');
88
89         $cols = array(0, 100, 385, 450, 515);
90
91         $headers = array(_('Category/Items'), _('Description'), _('Price'),     _('GP %'));
92
93         $aligns = array('left', 'left', 'right', 'right');
94
95     $params =   array(  0 => $comments,
96                                     1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''),
97                                     2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
98                                     3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
99                                     4 => array(  'text' => _('Show GP %'),'from' => $GP,'to' => ''));
100
101         if ($pictures)
102                 $user_comp = user_company();
103         else
104                 $user_comp = "";
105
106     $rep = new FrontReport(_('Price Listing'), "PriceListing.pdf", user_pagesize());
107
108     $rep->Font();
109     $rep->Info($params, $cols, $headers, $aligns);
110     $rep->Header();
111
112         $result = fetch_items($category);
113
114         $catgor = '';
115         $_POST['sales_type_id'] = $salestype;
116         while ($myrow=db_fetch($result))
117         {
118                 if ($catgor != $myrow['description'])
119                 {
120                         $rep->Line($rep->row  - $rep->lineHeight);
121                         $rep->NewLine(2);
122                         $rep->fontSize += 2;
123                         $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
124                         $catgor = $myrow['description'];
125                         $rep->fontSize -= 2;
126                         $rep->NewLine();
127                 }
128                 $rep->NewLine();
129                 $rep->TextCol(0, 1,     $myrow['stock_id']);
130                 $rep->TextCol(1, 2, $myrow['name']);
131                 $price = get_price($myrow['stock_id'], $currency, $salestype);
132                 $rep->TextCol(2, 3,     number_format2($price, $dec));
133                 if ($showGP)
134                 {
135                         $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
136                         if ($price2 != 0.0)
137                                 $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
138                         else
139                                 $disp = 0.0;
140                         $rep->TextCol(3, 4,     number_format2($disp, user_percent_dec()) . " %");
141                 }
142                 if ($pictures)
143                 {
144                         $image = $comp_path . '/'. $user_comp . "/images/" . $myrow['stock_id'] . ".jpg";
145                         if (file_exists($image))
146                         {
147                                 $rep->NewLine();
148                                 if ($rep->row - $pic_height < $rep->bottomMargin)
149                                         $rep->Header();
150                                 $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, $pic_width, $pic_height);
151                                 $rep->row -= $pic_height;
152                                 $rep->NewLine();
153                         }
154                 }
155                 else
156                         $rep->NewLine(0, 1);
157         }
158         $rep->Line($rep->row  - 4);
159     $rep->End();
160 }
161
162 ?>