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