2 /* $Revision: 1.11 $ */
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');
16 $pdf->addinfo('Title', _('Price Listing Report') );
17 $pdf->addinfo('Subject', _('Price List') );
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');
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');
34 $SQL = "SELECT debtorsmaster.name,
35 debtorsmaster.salestype
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,
45 stockmaster.description,
48 stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS standardcost,
49 stockmaster.categoryid,
50 stockcategory.categorydescription,
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,
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,
79 stockmaster.description,
82 stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost as standardcost,
83 stockmaster.categoryid,
84 stockcategory.categorydescription
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,
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>';
108 include('includes/footer.inc');
112 include('includes/PDFPriceListPageHeader.inc');
116 While ($PriceList = DB_fetch_array($PricesResult,$db)){
118 if ($CurrCode != $PriceList['currabrev']){
120 $YPos -=(2*$line_height);
121 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,300-$Left_Margin,$FontSize, $PriceList['currabrev'] . ' ' . _('Prices'));
122 $CurrCode = $PriceList['currabrev'];
124 $YPos -= $line_height;
127 if ($Category!=$PriceList['categoryid']){
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'];
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');
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']) . '%';
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 */
174 /*Print out the category totals */
176 $pdfcode = $pdf->output();
177 $len = strlen($pdfcode);
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');
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');
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 */