- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / PDFPriceList.php
blobaecc22cc3372e5db026e443731e6159ca20343ff
1 <?php
2 /* $Revision: 1.11 $ */
4 $PageSecurity = 2;
5 include('includes/session.inc');
7 If (isset($_POST['PrintPDF'])
8 AND isset($_POST['FromCriteria'])
9 AND strlen($_POST['FromCriteria'])>=1
10 AND isset($_POST['ToCriteria'])
11 AND strlen($_POST['ToCriteria'])>=1){
13 include('includes/PDFStarter.php');
15 $FontSize=10;
16 $pdf->addinfo('Title', _('Price Listing Report') );
17 $pdf->addinfo('Subject', _('Price List') );
19 $PageNumber=1;
20 $line_height=12;
22 /*Now figure out the inventory data to report for the category range under review */
23 if ($_POST['CustomerSpecials']==_('Customer Special Prices Only')){
25 if ($_SESSION['CustomerID']==''){
26 $title = _('Special price List - No Customer Selected');
27 include('includes/header.inc');
28 echo '<BR>';
29 prnMsg( _('The customer must first be selected from the select customer link') . '. ' . _('Re-run the price list once the customer has been selected') );
30 include('includes/footer.inc');
31 exit;
34 $SQL = "SELECT debtorsmaster.name,
35 debtorsmaster.salestype
36 FROM debtorsmaster
37 WHERE debtorno = '" . $_SESSION['CustomerID'] . "'";
38 $CustNameResult = DB_query($SQL,$db);
39 $CustNameRow = DB_fetch_row($CustNameResult);
40 $CustomerName = $CustNameRow[0];
41 $SalesType = $CustNameRow[1];
43 $SQL = "SELECT prices.typeabbrev,
44 prices.stockid,
45 stockmaster.description,
46 prices.currabrev,
47 prices.price,
48 stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS standardcost,
49 stockmaster.categoryid,
50 stockcategory.categorydescription,
51 prices.debtorno,
52 prices.branchcode,
53 custbranch.brname
54 FROM stockmaster,
55 stockcategory,
56 prices LEFT JOIN custbranch
57 ON prices.debtorno=custbranch.debtorno
58 AND prices.branchcode=custbranch.branchcode
59 WHERE stockmaster.stockid=prices.stockid
60 AND stockmaster.categoryid=stockcategory.categoryid
61 AND prices.typeabbrev = '" . $SalesType . "'
62 AND stockmaster.categoryid >= '" . $_POST['FromCriteria'] . "'
63 AND stockmaster.categoryid <= '" . $_POST['ToCriteria'] . "'
64 AND prices.debtorno='" . $_SESSION['CustomerID'] . "'
65 ORDER BY prices.currabrev,
66 stockmaster.categoryid,
67 stockmaster.stockid";
69 } else { /* the sales type list only */
72 $SQL = "SELECT sales_type FROM salestypes WHERE typeabbrev='" . $_POST['SalesType'] . "'";
73 $SalesTypeResult = DB_query($SQL,$db);
74 $SalesTypeRow = DB_fetch_row($SalesTypeResult);
75 $SalesTypeName = $SalesTypeRow[0];
77 $SQL = "SELECT prices.typeabbrev,
78 prices.stockid,
79 stockmaster.description,
80 prices.currabrev,
81 prices.price,
82 stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost as standardcost,
83 stockmaster.categoryid,
84 stockcategory.categorydescription
85 FROM prices,
86 stockmaster,
87 stockcategory
88 WHERE stockmaster.stockid=prices.stockid
89 AND stockmaster.categoryid=stockcategory.categoryid
90 AND stockmaster.categoryid >= '" . $_POST['FromCriteria'] . "'
91 AND stockmaster.categoryid <= '" . $_POST['ToCriteria'] . "'
92 AND prices.typeabbrev='" . $_POST['SalesType'] . "'
93 AND prices.debtorno=''
94 ORDER BY prices.currabrev,
95 stockmaster.categoryid,
96 stockmaster.stockid";
98 $PricesResult = DB_query($SQL,$db,'','',false,false);
100 if (DB_error_no($db) !=0) {
101 $title = _('Price List') . ' - ' . _('Problem Report....');
102 include('includes/header.inc');
103 prnMsg( _('The Price List could not be retrieved by the SQL because'). ' - ' . DB_error_msg($db), 'error');
104 echo '<BR><A HREF="' .$rootpath .'/index.php?' . SID . '">'. _('Back to the menu'). '</A>';
105 if ($debug==1){
106 echo '<BR>'. $SQL;
108 include('includes/footer.inc');
109 exit;
112 include('includes/PDFPriceListPageHeader.inc');
113 $CurrCode ='';
114 $Category = '';
115 $CatTot_Val=0;
116 While ($PriceList = DB_fetch_array($PricesResult,$db)){
118 if ($CurrCode != $PriceList['currabrev']){
119 $FontSize=10;
120 $YPos -=(2*$line_height);
121 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,300-$Left_Margin,$FontSize, $PriceList['currabrev'] . ' ' . _('Prices'));
122 $CurrCode = $PriceList['currabrev'];
123 $FontSize = 8;
124 $YPos -= $line_height;
127 if ($Category!=$PriceList['categoryid']){
128 $FontSize=10;
129 $YPos -=(2*$line_height);
130 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,300-$Left_Margin,$FontSize,$PriceList['categoryid'] . ' - ' . $PriceList['categorydescription']);
131 $Category = $PriceList['categoryid'];
132 $CategoryName = $PriceList['categorydescription'];
133 $FontSize=8;
134 $YPos -=$line_height;
137 $YPos -=$line_height;
140 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,$PriceList['stockid']); $LeftOvers = $pdf->addTextWrap(120,$YPos,260,$FontSize,$PriceList['description']);
142 if ($_POST['CustomerSpecials']=='Customer Special Prices Only'){
143 /*Need to show to which branch the price relates */
144 if ($PriceList['branchcode']!=''){
145 $LeftOvers = $pdf->addTextWrap(320,$YPos,130,$FontSize,$PriceList['brname'],'left');
146 } else {
147 $LeftOvers = $pdf->addTextWrap(320,$YPos,130,$FontSize,_('All'),'left');
152 $DisplayUnitPrice = number_format($PriceList['price'],2);
154 if ($PriceList['price']!=0){
155 $DisplayGPPercent = (int)(($PriceList['price']-$PriceList['standardcost'])*100/$PriceList['price']) . '%';
156 } else {
157 $DisplayGPPercent = 0;
161 $LeftOvers = $pdf->addTextWrap(440,$YPos,60,$FontSize,$DisplayUnitPrice, 'right');
163 if ($_POST['ShowGPPercentages']=='Yes'){
164 $LeftOvers = $pdf->addTextWrap(530,$YPos,20,$FontSize,$DisplayGPPercent, 'right');
167 if ($YPos < $Bottom_Margin + $line_height){
168 include('includes/PDFPriceListPageHeader.inc');
171 } /*end inventory valn while loop */
173 $FontSize =10;
174 /*Print out the category totals */
176 $pdfcode = $pdf->output();
177 $len = strlen($pdfcode);
179 if ($len<=20){
180 $title = _('Print Price List Error');
181 include('includes/header.inc');
182 prnMsg(_('There were no price details to print out for the customer or category specified'),'warn');
183 echo '<BR><A HREF="'.$rootpath.'/index.php?' . SID . '">'. _('Back to the menu').'</A>';
184 include('includes/footer.inc');
185 exit;
186 } else {
187 header('Content-type: application/pdf');
188 header('Content-Length: ' . $len);
189 header('Content-Disposition: inline; filename=PriceList.pdf');
190 header('Expires: 0');
191 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
192 header('Pragma: public');
194 $pdf->Stream();
196 } else { /*The option to print PDF was not hit */
198 $title= _('Price Listing');
199 include('includes/header.inc');
201 if (strlen($_POST['FromCriteria'])<1 || strlen($_POST['ToCriteria'])<1) {
203 /*if $FromCriteria is not set then show a form to allow input */
205 echo '<FORM ACTION=' . $_SERVER['PHP_SELF'] . ' METHOD="POST"><CENTER><TABLE>';
207 echo '<TR><TD>'. _('From Inventory Category Code') .':</FONT></TD><TD><SELECT name=FromCriteria>';
209 $sql='SELECT categoryid, categorydescription FROM stockcategory ORDER BY categoryid';
210 $CatResult= DB_query($sql,$db);
211 While ($myrow = DB_fetch_array($CatResult)){
212 echo "<OPTION VALUE='" . $myrow['categoryid'] . "'>" . $myrow['categoryid'] . ' - ' . $myrow['categorydescription'];
214 echo '</SELECT></TD></TR>';
216 echo '<TR><TD>' . _('To Inventory Category Code'). ':</TD><TD><SELECT name=ToCriteria>';
218 /*Set the index for the categories result set back to 0 */
219 DB_data_seek($CatResult,0);
221 While ($myrow = DB_fetch_array($CatResult)){
222 echo '<OPTION VALUE="' . $myrow['categoryid'] . '">' . $myrow['categoryid'] . ' - ' . $myrow['categorydescription'];
224 echo '</SELECT></TD></TR>';
226 echo '<TR><TD>' . _('For Sales Type/Price List').':</TD><TD><SELECT name="SalesType">';
227 $sql = 'SELECT sales_type, typeabbrev FROM salestypes';
228 $SalesTypesResult=DB_query($sql,$db);
230 while ($myrow=DB_fetch_array($SalesTypesResult)){
231 echo '<OPTION Value="' . $myrow['typeabbrev'] . '">' . $myrow['sales_type'];
233 echo '</SELECT></TD></TR>';
235 echo '<TR><TD>' . _('Show Gross Profit %') . ':</TD><TD><SELECT name="ShowGPPercentages">';
236 echo '<OPTION SELECTED Value="No">'. _('Prices Only');
237 echo '<OPTION Value="Yes">'. _('Show GP % too');
238 echo '</SELECT></TD></TR>';
240 echo '<TR><TD>' . _('Price Listing Type'). ':</TD><TD><SELECT name="CustomerSpecials">';
241 echo '<OPTION Value="Customer Special Prices Only">'. _('Customer Special Prices Only');
242 echo '<OPTION SELECTED Value="Sales Type Prices">'. _('Default Sales Type Prices');
243 echo '</SELECT></TD></TR>';
245 echo '</TABLE><INPUT TYPE=Submit Name="PrintPDF" Value="'. _('Print PDF'). '"></CENTER>';
247 include('includes/footer.inc');
249 } /*end of else not PrintPDF */