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