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');
30 $PageSize = array(0,0,$Page_Width,$Page_Height);
31 $pdf = & new Cpdf($PageSize);
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");
43 $pdf->addinfo('Title',_('Inventory Valuation Report'));
44 $pdf->addinfo('Subject',_('Inventory Valuation'));
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,
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
62 WHERE stockmaster.stockid=locstock.stockid
63 AND stockmaster.categoryid=stockcategory.categoryid
64 GROUP BY stockmaster.categoryid,
65 stockcategory.categorydescription,
68 stockmaster.description
69 HAVING SUM(locstock.quantity)!=0
70 AND stockmaster.categoryid >= '" . $FromCriteria . "'
71 AND stockmaster.categoryid <= '" . $ToCriteria . "'
72 ORDER BY stockmaster.categoryid,
77 $SQL = "SELECT stockmaster.categoryid,
78 stockcategory.categorydescription,
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
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,
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>';
108 include('includes/footer.inc');
112 include ('includes/PDFInventoryValnPageHeader.inc');
117 While ($InventoryValn = DB_fetch_array($InventoryResult,$db)){
119 if ($Category!=$InventoryValn['categoryid']){
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);
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;
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 */
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);
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");
206 include('includes/htmlMimeMail.php');
208 $fp = fopen( $_SESSION['reports_dir'] . "/InventoryReport.pdf","wb");
209 fwrite ($fp, $pdfcode);
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);