- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / OutstandingGRNs.php
blob27d3a5457502c56ecd758782c13472ccb5e871d0
1 <?php
2 /* $Revision: 1.9 $ */
3 $PageSecurity = 2;
4 include('includes/session.inc');
6 If (isset($_POST['PrintPDF'])
7 AND isset($_POST['FromCriteria'])
8 AND strlen($_POST['FromCriteria'])>=1
9 AND isset($_POST['ToCriteria'])
10 AND strlen($_POST['ToCriteria'])>=1){
12 include('includes/PDFStarter.php');
15 $FontSize=10;
16 $pdf->addinfo('Title',_('Outstanding GRNs Report'));
17 $pdf->addinfo('Subject',_('Outstanding GRNs Valuation'));
19 $PageNumber=1;
20 $line_height=12;
21 $Left_Margin=30;
23 /*Now figure out the data to report for the criteria under review */
25 $SQL = "SELECT grnno,
26 orderno,
27 grns.supplierid,
28 suppliers.suppname,
29 grns.itemcode,
30 grns.itemdescription,
31 qtyrecd,
32 quantityinv,
33 grns.stdcostunit,
34 actprice,
35 unitprice
36 FROM grns,
37 purchorderdetails,
38 suppliers
39 WHERE grns.supplierid=suppliers.supplierid
40 AND grns.podetailitem = purchorderdetails.podetailitem
41 AND qtyrecd-quantityinv <>0
42 AND grns.supplierid >='" . $_POST['FromCriteria'] . "'
43 AND grns.supplierid <='" . $_POST['ToCriteria'] . "'
44 ORDER BY supplierid,
45 grnno";
47 $GRNsResult = DB_query($SQL,$db,'','',false,false);
49 if (DB_error_no($db) !=0) {
50 $title = _('Outstanding GRN Valuation') . ' - ' . _('Problem Report');
51 include('includes/header.inc');
52 prnMsg(_('The outstanding GRNs valuation details could not be retrieved by the SQL because') . ' - ' . DB_error_msg($db),'error');
53 echo "<BR><A HREF='" .$rootpath ."/index.php?" . SID . "'>" . _('Back to the menu') . '</A>';
54 if ($debug==1){
55 echo "<BR>$SQL";
57 include('includes/footer.inc');
58 exit;
61 include ('includes/PDFOstdgGRNsPageHeader.inc');
63 $Tot_Val=0;
64 $Supplier = '';
65 $SuppTot_Val=0;
66 While ($GRNs = DB_fetch_array($GRNsResult,$db)){
68 if ($Supplier!=$GRNs['supplierid']){
70 if ($Supplier!=''){ /*Then it's NOT the first time round */
71 /* need to print the total of previous supplier */
72 $YPos -= (2*$line_height);
73 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,_('Total for') . ' ' . $Supplier . ' - ' . $SupplierName);
74 $DisplaySuppTotVal = number_format($SuppTot_Val,2);
75 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplaySuppTotVal, 'right');
76 $YPos -=$line_height;
77 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
78 $YPos -=(2*$line_height);
79 $SuppTot_Val=0;
81 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,$GRNs['supplierid'] . ' - ' . $GRNs['suppname']);
82 $Supplier = $GRNs['supplierid'];
83 $SupplierName = $GRNs['suppname'];
85 $YPos -=$line_height;
87 $LeftOvers = $pdf->addTextWrap(30,$YPos,40,$FontSize,$GRNs['grnno']);
88 $LeftOvers = $pdf->addTextWrap(70,$YPos,40,$FontSize,$GRNs['orderno']);
89 $LeftOvers = $pdf->addTextWrap(110,$YPos,200,$FontSize,$GRNs['itemcode'] . ' - ' . $GRNs['itemdescription']);
90 $DisplayStdCost = number_format($GRNs['stdcostunit'],2);
91 $DisplayQtyRecd = number_format($GRNs['qtyrecd'],2);
92 $DisplayQtyInv = number_format($GRNs['quantityinv'],2);
93 $DisplayQtyOstg = number_format($GRNs['qtyrecd']- $GRNs['quantityinv'],2);
94 $LineValue = ($GRNs['qtyrecd']- $GRNs['quantityinv'])*$GRNs['stdcostunit'];
95 $DisplayValue = number_format($LineValue,2);
97 $LeftOvers = $pdf->addTextWrap(310,$YPos,50,$FontSize,$DisplayQtyRecd,'right');
98 $LeftOvers = $pdf->addTextWrap(360,$YPos,50,$FontSize,$DisplayQtyInv, 'right');
99 $LeftOvers = $pdf->addTextWrap(410,$YPos,50,$FontSize,$DisplayQtyOstg, 'right');
100 $LeftOvers = $pdf->addTextWrap(460,$YPos,50,$FontSize,$DisplayStdCost, 'right');
101 $LeftOvers = $pdf->addTextWrap(510,$YPos,50,$FontSize,$DisplayValue, 'right');
103 $Tot_Val += $LineValue;
104 $SuppTot_Val += $LineValue;
106 if ($YPos < $Bottom_Margin + $line_height){
107 include('includes/PDFOstdgGRNsPageHeader.inc');
110 } /*end while loop */
113 /*Print out the supplier totals */
114 $YPos -=$line_height;
115 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,_('Total for') . ' ' . $Supplier . ' - ' . $SupplierName, 'left');
117 $DisplaySuppTotVal = number_format($SuppTot_Val,2);
118 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplaySuppTotVal, 'right');
120 /*draw a line under the SUPPLIER TOTAL*/
121 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
122 $YPos -=(2*$line_height);
124 $YPos -= (2*$line_height);
126 /*Print out the grand totals */
127 $LeftOvers = $pdf->addTextWrap(80,$YPos,260-$Left_Margin,$FontSize,_('Grand Total Value'), 'right');
128 $DisplayTotalVal = number_format($Tot_Val,2);
129 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayTotalVal, 'right');
130 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
131 $YPos -=(2*$line_height);
133 $pdfcode = $pdf->output();
134 $len = strlen($pdfcode);
136 if ($len<=20){
137 $title = _('Outstanding GRNs Valuation Error');
138 include('includes/header.inc');
139 prnMsg(_('There were no GRNs with any value to print out for the specified supplier range'),'info');
140 echo "<BR><A HREF='$rootpath/index.php?" . SID . "'>" . _('Back to the menu') . '</A>';
141 include('includes/footer.inc');
142 exit;
143 } else {
144 header('Content-type: application/pdf');
145 header('Content-Length: ' . $len);
146 header('Content-Disposition: inline; filename=OSGRNsValuation.pdf');
147 header('Expires: 0');
148 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
149 header('Pragma: public');
151 $pdf->Stream();
153 } else { /*The option to print PDF was not hit */
155 $title=_('Outstanding GRNs Report');
156 include('includes/header.inc');
158 echo '<FORM ACTION=' . $_SERVER['PHP_SELF'] . " METHOD='POST'><CENTER><TABLE>";
160 echo '<TR><TD>' . _('From Supplier Code') . ":</TD>
161 <TD><INPUT TYPE=TEXT NAME='FromCriteria' VALUE='0'></TD></TR>";
162 echo '<TR><TD>' . _('To Supplier Code'). ":</TD>
163 <TD><INPUT TYPE=TEXT NAME='ToCriteria' VALUE='zzzzzzz'></TD></TR>";
165 echo "</TABLE><INPUT TYPE=Submit Name='PrintPDF' Value='" . _('Print PDF') . "'></CENTER>";
167 include('includes/footer.inc');
169 } /*end of else not PrintPDF */