- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / MailInventoryValuation.php
blobf38a6cf8f6e2b2074f81a4ac10e0ace08e77f93d
1 <?php
2 /* $Revision: 1.6 $ */
3 $PageSecurity = 1;
4 $AllowAnyone = true;
6 $FromCriteria ='1'; /*Category From */
7 $ToCriteria ='zzzzzzzz'; /*Category To */
8 $Location = 'All'; /* Location to report on */
9 $DetailedReport = 'Yes'; /* Total by category or complete listing */
10 $Recipients = array('"Postmaster" <postmaster@localhost>','"someone" <someone@localhost>');
13 $_POST['DetailedReport'] = $DetailedReport; /* so PDFInventoryValnPageHeader.inc works too */
14 $_POST['FromCriteria']=$FromCriteria; /* so PDFInventoryValnPageHeader.inc works too */
15 $_POST['ToCriteria']=$ToCriteria; /* so PDFInventoryValnPageHeader.inc works too */
16 $_POST["Location"] = $Location; /* so PDFInventoryValnPageHeader.inc works too */
18 include('includes/session.inc');
19 include ('includes/class.pdf.php');
21 /* A4_Portrait */
23 $Page_Width=595;
24 $Page_Height=842;
25 $Top_Margin=30;
26 $Bottom_Margin=30;
27 $Left_Margin=40;
28 $Right_Margin=30;
30 $PageSize = array(0,0,$Page_Width,$Page_Height);
31 $pdf = & new Cpdf($PageSize);
33 $PageNumber = 0;
35 $pdf->selectFont('./fonts/Helvetica.afm');
37 /* Standard PDF file creation header stuff */
39 $pdf->addinfo('Author',"webERP " . $Version);
40 $pdf->addinfo('Creator',"webERP http://www.weberp.org - R&OS PHP-PDF http://www.ros.co.nz");
42 $FontSize=10;
43 $pdf->addinfo('Title',_('Inventory Valuation Report'));
44 $pdf->addinfo('Subject',_('Inventory Valuation'));
46 $PageNumber=1;
47 $line_height=12;
49 /*Now figure out the inventory data to report for the category range under review */
50 if ($Location=='All'){
52 $SQL = "SELECT stockmaster.categoryid,
53 stockcategory.categorydescription,
54 stockmaster.stockid,
55 stockmaster.description,
56 SUM(locstock.quantity) as qtyonhand,
57 stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS unitcost,
58 SUM(locstock.quantity) *(stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost) AS itemtotal
59 FROM stockmaster,
60 stockcategory,
61 locstock
62 WHERE stockmaster.stockid=locstock.stockid
63 AND stockmaster.categoryid=stockcategory.categoryid
64 GROUP BY stockmaster.categoryid,
65 stockcategory.categorydescription,
66 unitcost,
67 stockmaster.stockid,
68 stockmaster.description
69 HAVING SUM(locstock.quantity)!=0
70 AND stockmaster.categoryid >= '" . $FromCriteria . "'
71 AND stockmaster.categoryid <= '" . $ToCriteria . "'
72 ORDER BY stockmaster.categoryid,
73 stockmaster.stockid";
75 } else {
77 $SQL = "SELECT stockmaster.categoryid,
78 stockcategory.categorydescription,
79 stockmaster.stockid,
80 stockmaster.description,
81 locstock.quantity as qtyonhand,
82 stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS unitcost,
83 locstock.quantity *(stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost) AS itemtotal
84 FROM stockmaster,
85 stockcategory,
86 locstock
87 WHERE stockmaster.stockid=locstock.stockid
88 AND stockmaster.categoryid=stockcategory.categoryid
89 AND locstock.quantity!=0
90 AND stockmaster.categoryid >= '" . $FromCriteria . "'
91 AND stockmaster.categoryid <= '" . $ToCriteria . "'
92 AND locstock.loccode = '" . $Location . "'
93 ORDER BY stockmaster.categoryid,
94 stockmaster.stockid";
97 $InventoryResult = DB_query($SQL,$db,'','',false,true);
99 if (DB_error_no($db) !=0) {
100 $title = _('Inventory Valuation') . ' - ' . _('Problem Report');
101 include("includes/header.inc");
102 echo _('The inventory valuation could not be retrieved by the SQL because') . ' - ' . DB_error_msg($db);
103 echo "<BR><A HREF='" .$rootpath ."/index.php?" . SID . "'>" . _('Back to the menu') . '</A>';
104 if ($debug==1){
105 echo "<BR>$SQL";
108 include('includes/footer.inc');
109 exit;
112 include ('includes/PDFInventoryValnPageHeader.inc');
114 $Tot_Val=0;
115 $Category = '';
116 $CatTot_Val=0;
117 While ($InventoryValn = DB_fetch_array($InventoryResult,$db)){
119 if ($Category!=$InventoryValn['categoryid']){
120 $FontSize=10;
121 if ($Category!=""){ /*Then it's NOT the first time round */
123 /* need to print the total of previous category */
124 if ($_POST["DetailedReport"]=="Yes"){
125 $YPos -= (2*$line_height);
126 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,_('Total for') . ' ' . $Category . " - " . $CategoryName);
129 $DisplayCatTotVal = number_format($CatTot_Val,2);
130 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayCatTotVal, "right");
131 $YPos -=$line_height;
133 If ($_POST["DetailedReport"]=="Yes"){
134 /*draw a line under the CATEGORY TOTAL*/
135 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
136 $YPos -=(2*$line_height);
138 $CatTot_Val=0;
140 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,$InventoryValn['categoryid'] . " - " . $InventoryValn['categorydescription']);
141 $Category = $InventoryValn['categoryid'];
142 $CategoryName = $InventoryValn['categorydescription'];
145 if ($_POST["DetailedReport"]=="Yes"){
146 $YPos -=$line_height;
147 $FontSize=8;
149 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,$InventoryValn['stockid']); $LeftOvers = $pdf->addTextWrap(120,$YPos,260,$FontSize,$InventoryValn['description']);
150 $DisplayUnitCost = number_format($InventoryValn['unitcost'],2);
151 $DisplayQtyOnHand = number_format($InventoryValn['qtyonhand'],0);
152 $DisplayItemTotal = number_format($InventoryValn['itemtotal'],2);
154 $LeftOvers = $pdf->addTextWrap(380,$YPos,60,$FontSize,$DisplayQtyOnHand,"right");
155 $LeftOvers = $pdf->addTextWrap(440,$YPos,60,$FontSize,$DisplayUnitCost, "right");
156 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayItemTotal, "right");
159 $Tot_Val += $InventoryValn['itemtotal'];
160 $CatTot_Val += $InventoryValn['itemtotal'];
162 if ($YPos < $Bottom_Margin + $line_height){
163 include('includes/PDFInventoryValnPageHeader.inc');
166 } /*end inventory valn while loop */
168 $FontSize =10;
169 /*Print out the category totals */
170 if ($_POST["DetailedReport"]=="Yes"){
171 $YPos -=$line_height;
172 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize, _('Total for') . ' ' . $Category . " - " . $CategoryName, "left");
175 $DisplayCatTotVal = number_format($CatTot_Val,2);
176 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayCatTotVal, "right");
178 If ($_POST["DetailedReport"]=="Yes"){
179 /*draw a line under the CATEGORY TOTAL*/
180 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
181 $YPos -=(2*$line_height);
184 $YPos -= (2*$line_height);
186 /*Print out the grand totals */
187 $LeftOvers = $pdf->addTextWrap(80,$YPos,260-$Left_Margin,$FontSize,_('Grand Total Value'), 'right');
188 $DisplayTotalVal = number_format($Tot_Val,2);
189 $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayTotalVal, 'right');
190 If ($_POST['DetailedReport']=='Yes'){
191 $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
192 $YPos -=(2*$line_height);
195 $pdfcode = $pdf->output();
196 $len = strlen($pdfcode);
198 if ($len<=20){
199 $title = _('Print Inventory Valuation Error');
200 include("includes/header.inc");
201 echo '<p>' . _('There were no items with any value to print out for the location specified');
202 echo "<BR><A HREF='$rootpath/index.php?" . SID . "'>" . _('Back to the menu') . '</A>';
203 include("includes/footer.inc");
204 exit;
205 } else {
206 include('includes/htmlMimeMail.php');
208 $fp = fopen( $_SESSION['reports_dir'] . "/InventoryReport.pdf","wb");
209 fwrite ($fp, $pdfcode);
210 fclose ($fp);
212 $mail = new htmlMimeMail();
213 $attachment = $mail->getFile( $_SESSION['reports_dir'] . '/InventoryReport.pdf');
214 $mail->setText(_('Please find herewith the stock valuation report'));
215 $mail->setSubject(_('Inventory Valuation Report'));
216 $mail->addAttachment($attachment, 'InventoryReport.pdf', 'application/pdf');
217 $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . "<" . $_SESSION['CompanyRecord']['email'] . ">");
218 $result = $mail->send($Recipients);