PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/InventoryValuation.php

http://kwamoja.codeplex.com
PHP | 277 lines | 223 code | 45 blank | 9 comment | 22 complexity | 1cfe138fa6f5eb3f8568a4e08503cf73 MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* $Id$ */
  3. include('includes/session.inc');
  4. if (isset($_POST['PrintPDF'])
  5. and isset($_POST['FromCriteria'])
  6. and mb_strlen($_POST['FromCriteria'])>=1
  7. and isset($_POST['ToCriteria'])
  8. and mb_strlen($_POST['ToCriteria'])>=1){
  9. include('includes/PDFStarter.php');
  10. $pdf->addInfo('Title',_('Inventory Valuation Report'));
  11. $pdf->addInfo('Subject',_('Inventory Valuation'));
  12. $FontSize=9;
  13. $PageNumber=1;
  14. $line_height=12;
  15. /*Now figure out the inventory data to report for the category range under review */
  16. if ($_POST['Location']=='All'){
  17. $SQL = "SELECT stockmaster.categoryid,
  18. stockcategory.categorydescription,
  19. stockmaster.stockid,
  20. stockmaster.description,
  21. stockmaster.decimalplaces,
  22. SUM(locstock.quantity) AS qtyonhand,
  23. stockmaster.units,
  24. stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS unitcost,
  25. SUM(locstock.quantity) *(stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost) AS itemtotal
  26. FROM stockmaster,
  27. stockcategory,
  28. locstock
  29. WHERE stockmaster.stockid=locstock.stockid
  30. AND stockmaster.categoryid=stockcategory.categoryid
  31. GROUP BY stockmaster.categoryid,
  32. stockcategory.categorydescription,
  33. unitcost,
  34. stockmaster.units,
  35. stockmaster.decimalplaces,
  36. stockmaster.materialcost,
  37. stockmaster.labourcost,
  38. stockmaster.overheadcost,
  39. stockmaster.stockid,
  40. stockmaster.description
  41. HAVING SUM(locstock.quantity)!=0
  42. AND stockcategory.categorydescription >= '" . $_POST['FromCriteria'] . "'
  43. AND stockcategory.categorydescription <= '" . $_POST['ToCriteria'] . "'
  44. ORDER BY stockcategory.categorydescription,
  45. stockmaster.stockid";
  46. } else {
  47. $SQL = "SELECT stockmaster.categoryid,
  48. stockcategory.categorydescription,
  49. stockmaster.stockid,
  50. stockmaster.description,
  51. stockmaster.units,
  52. stockmaster.decimalplaces,
  53. locstock.quantity AS qtyonhand,
  54. stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS unitcost,
  55. locstock.quantity *(stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost) AS itemtotal
  56. FROM stockmaster,
  57. stockcategory,
  58. locstock
  59. WHERE stockmaster.stockid=locstock.stockid
  60. AND stockmaster.categoryid=stockcategory.categoryid
  61. AND locstock.quantity!=0
  62. AND stockcategory.categorydescription >= '" . $_POST['FromCriteria'] . "'
  63. AND stockcategory.categorydescription <= '" . $_POST['ToCriteria'] . "'
  64. AND locstock.loccode = '" . $_POST['Location'] . "'
  65. ORDER BY stockcategory.categorydescription,
  66. stockmaster.stockid";
  67. }
  68. $InventoryResult = DB_query($SQL,$db,'','',false,true);
  69. if (DB_error_no($db) !=0) {
  70. $Title = _('Inventory Valuation') . ' - ' . _('Problem Report');
  71. include('includes/header.inc');
  72. prnMsg( _('The inventory valuation could not be retrieved by the SQL because') . ' ' . DB_error_msg($db),'error');
  73. echo '<br /><a href="' .$RootPath .'/index.php">' . _('Back to the menu') . '</a>';
  74. if ($debug==1){
  75. echo '<br />' . $SQL;
  76. }
  77. include('includes/footer.inc');
  78. exit;
  79. }
  80. if (DB_num_rows($InventoryResult)==0){
  81. $Title = _('Print Inventory Valuation Error');
  82. include('includes/header.inc');
  83. prnMsg(_('There were no items with any value to print out for the location specified'),'info');
  84. echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
  85. include('includes/footer.inc');
  86. exit;
  87. }
  88. include ('includes/PDFInventoryValnPageHeader.inc');
  89. $Tot_Val=0;
  90. $Category = '';
  91. $CatTot_Val=0;
  92. $CatTot_Qty=0;
  93. while ($InventoryValn = DB_fetch_array($InventoryResult,$db)){
  94. if ($Category!=$InventoryValn['categoryid']){
  95. $FontSize=10;
  96. if ($Category!=''){ /*Then it's NOT the first time round */
  97. /* need to print the total of previous category */
  98. if ($_POST['DetailedReport']=='Yes'){
  99. $YPos -= (2*$line_height);
  100. if ($YPos < $Bottom_Margin + (3*$line_height)){
  101. include('includes/PDFInventoryValnPageHeader.inc');
  102. }
  103. $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,_('Total for') . ' ' . $Category . ' - ' . $CategoryName);
  104. }
  105. $DisplayCatTotVal = locale_number_format($CatTot_Val,$_SESSION['CompanyRecord']['decimalplaces']);
  106. $DisplayCatTotQty = locale_number_format($CatTot_Qty,2);
  107. $LeftOvers = $pdf->addTextWrap(480,$YPos,80,$FontSize,$DisplayCatTotVal, 'right');
  108. $LeftOvers = $pdf->addTextWrap(360,$YPos,60,$FontSize,$DisplayCatTotQty, 'right');
  109. $YPos -=$line_height;
  110. if ($_POST['DetailedReport']=='Yes'){
  111. /*draw a line under the CATEGORY TOTAL*/
  112. $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
  113. $YPos -=(2*$line_height);
  114. }
  115. $CatTot_Val=0;
  116. $CatTot_Qty=0;
  117. }
  118. $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,260-$Left_Margin,$FontSize,$InventoryValn['categoryid'] . ' - ' . $InventoryValn['categorydescription']);
  119. $Category = $InventoryValn['categoryid'];
  120. $CategoryName = $InventoryValn['categorydescription'];
  121. }
  122. if ($_POST['DetailedReport']=='Yes'){
  123. $YPos -=$line_height;
  124. $FontSize=8;
  125. $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,100,$FontSize,$InventoryValn['stockid']);
  126. $LeftOvers = $pdf->addTextWrap(170,$YPos,220,$FontSize,$InventoryValn['description']);
  127. $DisplayUnitCost = locale_number_format($InventoryValn['unitcost'],$_SESSION['CompanyRecord']['decimalplaces']);
  128. $DisplayQtyOnHand = locale_number_format($InventoryValn['qtyonhand'],$InventoryValn['decimalplaces']);
  129. $DisplayItemTotal = locale_number_format($InventoryValn['itemtotal'],$_SESSION['CompanyRecord']['decimalplaces']);
  130. $LeftOvers = $pdf->addTextWrap(360,$YPos,60,$FontSize,$DisplayQtyOnHand,'right');
  131. $LeftOvers = $pdf->addTextWrap(423,$YPos,15,$FontSize,$InventoryValn['units'],'left');
  132. $LeftOvers = $pdf->addTextWrap(438,$YPos,60,$FontSize,$DisplayUnitCost, 'right');
  133. $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayItemTotal, 'right');
  134. }
  135. $Tot_Val += $InventoryValn['itemtotal'];
  136. $CatTot_Val += $InventoryValn['itemtotal'];
  137. $CatTot_Qty += $InventoryValn['qtyonhand'];
  138. if ($YPos < $Bottom_Margin + $line_height){
  139. include('includes/PDFInventoryValnPageHeader.inc');
  140. }
  141. } /*end inventory valn while loop */
  142. $FontSize =10;
  143. /*Print out the category totals */
  144. if ($_POST['DetailedReport']=='Yes'){
  145. $YPos -= (2*$line_height);
  146. $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,200-$Left_Margin,$FontSize, _('Total for') . ' ' . $Category . ' - ' . $CategoryName, 'left');
  147. }
  148. $DisplayCatTotVal = locale_number_format($CatTot_Val,$_SESSION['CompanyRecord']['decimalplaces']);
  149. $LeftOvers = $pdf->addTextWrap(480,$YPos,80,$FontSize,$DisplayCatTotVal, 'right');
  150. $DisplayCatTotQty = locale_number_format($CatTot_Qty,2);
  151. $LeftOvers = $pdf->addTextWrap(360,$YPos,60,$FontSize,$DisplayCatTotQty, 'right');
  152. if ($_POST['DetailedReport']=='Yes'){
  153. /*draw a line under the CATEGORY TOTAL*/
  154. $YPos -= ($line_height);
  155. $pdf->line($Left_Margin, $YPos+$line_height-2,$Page_Width-$Right_Margin, $YPos+$line_height-2);
  156. }
  157. $YPos -= (2*$line_height);
  158. if ($YPos < $Bottom_Margin + $line_height){
  159. include('includes/PDFInventoryValnPageHeader.inc');
  160. }
  161. /*Print out the grand totals */
  162. $LeftOvers = $pdf->addTextWrap(80,$YPos,260-$Left_Margin,$FontSize,_('Grand Total Value'), 'right');
  163. $DisplayTotalVal = locale_number_format($Tot_Val,$_SESSION['CompanyRecord']['decimalplaces']);
  164. $LeftOvers = $pdf->addTextWrap(500,$YPos,60,$FontSize,$DisplayTotalVal, 'right');
  165. $pdf->OutputD($_SESSION['DatabaseName'] . '_Inventory_Valuation_' . Date('Y-m-d') . '.pdf');
  166. $pdf->__destruct();
  167. } else { /*The option to print PDF was not hit */
  168. $Title=_('Inventory Valuation Reporting');
  169. include('includes/header.inc');
  170. if (empty($_POST['FromCriteria']) or empty($_POST['ToCriteria'])) {
  171. /*if $FromCriteria is not set then show a form to allow input */
  172. echo '<p class="page_title_text noPrint" >
  173. <img src="'.$RootPath.'/css/'.$Theme.'/images/inventory.png" title="' . _('Inventory') . '" alt="" />' . ' ' . $Title . '
  174. </p>';
  175. echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" class="noPrint">
  176. <div>
  177. <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
  178. <table class="selection">
  179. <tr>
  180. <td>' . _('From Inventory Category Code') . ':</td>
  181. <td><select name="FromCriteria">';
  182. $sql="SELECT categoryid,
  183. categorydescription
  184. FROM stockcategory
  185. ORDER BY categorydescription";
  186. $CatResult= DB_query($sql,$db);
  187. while ($myrow = DB_fetch_array($CatResult)){
  188. echo '<option value="' . $myrow['categorydescription'] . '">' . $myrow['categorydescription'] . ' - ' . $myrow['categoryid'] . '</option>';
  189. }
  190. echo '</select></td>
  191. </tr>';
  192. echo '<tr>
  193. <td>' . _('To Inventory Category Code') . ':</td>
  194. <td><select name="ToCriteria">';
  195. /*Set the index for the categories result set back to 0 */
  196. DB_data_seek($CatResult,0);
  197. while ($myrow = DB_fetch_array($CatResult)){
  198. echo '<option value="' . $myrow['categorydescription'] . '">' . $myrow['categorydescription'] . ' - ' . $myrow['categoryid'] . '</option>';
  199. }
  200. echo '</select></td>
  201. </tr>';
  202. echo '<tr>
  203. <td>' . _('For Inventory in Location') . ':</td>
  204. <td><select name="Location">';
  205. $sql = "SELECT loccode,
  206. locationname
  207. FROM locations";
  208. $LocnResult=DB_query($sql,$db);
  209. echo '<option value="All">' . _('All Locations') . '</option>';
  210. while ($myrow=DB_fetch_array($LocnResult)){
  211. echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
  212. }
  213. echo '</select></td>
  214. </tr>';
  215. echo '<tr>
  216. <td>' . _('Summary or Detailed Report') . ':</td>
  217. <td><select name="DetailedReport">
  218. <option selected="selected" value="No">' . _('Summary Report') . '</option>
  219. <option value="Yes">' . _('Detailed Report') . '</option>
  220. </select></td>
  221. </tr>
  222. </table>
  223. <br />
  224. <div class="centre">
  225. <input type="submit" name="PrintPDF" value="' . _('Print PDF') . '" />
  226. </div>';
  227. echo '</div>
  228. </form>';
  229. }
  230. include('includes/footer.inc');
  231. } /*end of else not PrintPDF */
  232. ?>