PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/fannie/legacy/it/ProduceWeekly/index.php

https://github.com/CORE-POS/IS4C
PHP | 214 lines | 183 code | 16 blank | 15 comment | 20 complexity | 39f4710067237fd61dfa81b32336e9d9 MD5 | raw file
  1. <?php
  2. include('../../../config.php');
  3. require(__DIR__ . '/../../../src/SQLManager.php');
  4. include('../../db.php');
  5. $now = mktime();
  6. while(date("N",$now) != 1)
  7. $now = mktime(0,0,0,date("n",$now),date("j",$now)-1,date("Y",$now));
  8. if (isset($_POST['submit'])){
  9. $queries = array();
  10. $sql->query("TRUNCATE TABLE produceWeeklyData");
  11. $query = $sql->prepare("INSERT INTO produceWeeklyData VALUES
  12. (?,?,?,?,?,?,?)");
  13. foreach($_POST as $key=>$value){
  14. if ($key == "submit") continue;
  15. list($sub,$id) = explode(":",$key,2);
  16. if (!empty($queries[$id])) continue;
  17. $args = array($id,
  18. (isset($_POST["M:$id"])?$_POST["M:$id"]:0),
  19. (isset($_POST["T:$id"])?$_POST["T:$id"]:0),
  20. (isset($_POST["W:$id"])?$_POST["W:$id"]:0),
  21. (isset($_POST["Th:$id"])?$_POST["Th:$id"]:0),
  22. (isset($_POST["F:$id"])?$_POST["F:$id"]:0),
  23. (isset($_POST["Sa:$id"])?$_POST["Sa:$id"]:0)
  24. );
  25. $sql->execute($query, $args);
  26. }
  27. if ($_POST['submit'] == "Archive"){
  28. header('Content-Type: application/ms-excel');
  29. header('Content-Disposition: attachment; filename="order archive '.date("m-d-y",$now).'.xls"');
  30. }
  31. }
  32. ?>
  33. <html>
  34. <head>
  35. <style type="text/css">
  36. table { text-align: center; }
  37. th { width: 70px; background: #cccc99;}
  38. td { width: 70px; background: #ffffff;}
  39. tr.alt td {background: #ffffcc;}
  40. /* define height and width of scrollable area. Add 16px to width for scrollbar */
  41. div.tableContainer {
  42. clear: both;
  43. height: 300px;
  44. overflow: auto;
  45. width: 950px;;
  46. }
  47. /* Reset overflow value to hidden for all non-IE browsers. */
  48. html>body div.tableContainer {
  49. overflow: hidden;
  50. width: 950px;
  51. }
  52. /* define width of table. IE browsers only */
  53. div.tableContainer table {
  54. float: left;
  55. }
  56. /* define width of table. Add 16px to width for scrollbar. */
  57. /* All other non-IE browsers. */
  58. html>body div.tableContainer table {
  59. width: 850px;
  60. }
  61. /* set table header to a fixed position. WinIE 6.x only */
  62. /* In WinIE 6.x, any element with a position property set to relative and is a child of */
  63. /* an element that has an overflow property set, the relative value translates into fixed. */
  64. /* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
  65. thead.fixedHeader tr {
  66. position: relative
  67. }
  68. /* set THEAD element to have block level attributes. All other non-IE browsers */
  69. /* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
  70. html>body thead.fixedHeader tr {
  71. display: block
  72. }
  73. /* define the table content to be scrollable */
  74. /* set TBODY element to have block level attributes. All other non-IE browsers */
  75. /* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
  76. /* induced side effect is that child TDs no longer accept width: auto */
  77. html>body tbody.scrollContent {
  78. display: block;
  79. height: 300px;
  80. overflow: auto;
  81. width: 934px;
  82. }
  83. </style>
  84. </head>
  85. <body>
  86. <img src="spacer.png" alt="" /><br />
  87. <form action="index.php" method="post">
  88. <?php
  89. printf("<i>Order for Week of: %s</i>",date("m/d/y",$now));
  90. ?>
  91. &nbsp;&nbsp;&nbsp;&nbsp;
  92. <input type="submit" name="submit" value="Archive" />
  93. &nbsp;&nbsp;&nbsp;&nbsp;
  94. <input type="submit" name="submit" value="Save" />
  95. <div class="tableContainer">
  96. <table border="1" cellpadding="0" cellspacing="0" width="100%" class="scrollTable">
  97. <thead class="fixedHeader">
  98. <tr>
  99. <th style="width:100px;">Desc</th>
  100. <th>Price</th>
  101. <th>Unit</th>
  102. <th>Weekly</th>
  103. <th>Need</th>
  104. <th>M</th>
  105. <th>T</th>
  106. <th>W</th>
  107. <th>Th</th>
  108. <th>F</th>
  109. <th>Sa</th>
  110. <th>Notes</th>
  111. <th>LC</th>
  112. </tr>
  113. </thead>
  114. <tbody class="scrollContent">
  115. <?php
  116. $query = "SELECT `desc`,price,unit,quantity,p.likecode,p.id,
  117. monday,tuesday,wednesday,thursday,friday,saturday
  118. FROM produceWeekly p LEFT JOIN
  119. likecodeWeeklyQuantity l ON p.likecode=l.likeCode
  120. LEFT JOIN produceWeeklyData d
  121. ON p.id=d.id
  122. ORDER BY p.id";
  123. $result = $sql->query($query);
  124. $count = 0;
  125. while($row = $sql->fetch_row($result)){
  126. if ($count % 2 == 0)
  127. echo "<tr>";
  128. else
  129. echo "<tr class=\"alt\">";
  130. $count++;
  131. if ($row[1] == "" && $row[2] == "")
  132. echo "<td colspan=\"13\">".$row[0]."</td>";
  133. else {
  134. $sum = 0;
  135. for($i=6;$i<12;$i++){
  136. if (!is_numeric($row[$i])) $row[$i] = 0;
  137. $sum += $row[$i];
  138. }
  139. if ($_POST['submit'] == "Archive"){
  140. printf("<td style=\"width:100px\">%s</td><td>%s</td><td>%s</td>
  141. <td>%s</td><td>%s</td>
  142. <td>%.2f</td>
  143. <td>%.2f</td>
  144. <td>%.2f</td>
  145. <td>%.2f</td>
  146. <td>%.2f</td>
  147. <td>%.2f</td>
  148. <td>%s</td>
  149. <td style=\"width:54px\">%s</td>",
  150. $row[0],
  151. ($row[1]!="")?$row[1]:"&nbsp;",
  152. ($row[2]!="")?$row[2]:"&nbsp;",
  153. ($row[3]!="")?$row[3]:"&nbsp;",
  154. ($row[3]!="")?$row[3]-$sum:"&nbsp;",
  155. $row[6],
  156. $row[7],
  157. $row[8],
  158. $row[9],
  159. $row[10],
  160. $row[11],
  161. "&nbsp;",
  162. ($row[4]!="")?$row[4]:"&nbsp;");
  163. }
  164. else {
  165. printf("<td style=\"width:100px\">%s</td><td>%s</td><td>%s</td>
  166. <td>%s</td><td>%s</td>
  167. <td><input type=text size=4 value=\"%.2f\" name=\"M:%s\" /></td>
  168. <td><input type=text size=4 value=\"%.2f\" name=\"T:%s\" /></td>
  169. <td><input type=text size=4 value=\"%.2f\" name=\"W:%s\" /></td>
  170. <td><input type=text size=4 value=\"%.2f\" name=\"Th:%s\" /></td>
  171. <td><input type=text size=4 value=\"%.2f\" name=\"F:%s\" /></td>
  172. <td><input type=text size=4 value=\"%.2f\" name=\"Sa:%s\" /></td>
  173. <td>%s</td>
  174. <td style=\"width:54px\">%s</td>",
  175. $row[0],
  176. ($row[1]!="")?$row[1]:"&nbsp;",
  177. ($row[2]!="")?$row[2]:"&nbsp;",
  178. ($row[3]!="")?$row[3]:"&nbsp;",
  179. ($row[3]!="")?$row[3]-$sum:"&nbsp;",
  180. $row[6],$row[5],
  181. $row[7],$row[5],
  182. $row[8],$row[5],
  183. $row[9],$row[5],
  184. $row[10],$row[5],
  185. $row[11],$row[5],
  186. "&nbsp;",
  187. ($row[4]!="")?$row[4]:"&nbsp;");
  188. }
  189. }
  190. echo "</tr>";
  191. }
  192. ?>
  193. </tbody>
  194. </table>
  195. </div>
  196. </form>
  197. </body>
  198. </html>