PageRenderTime 43ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/shop/func/mem_edit_invoice_admin.php

https://github.com/traceyambrose/foodcoop
PHP | 360 lines | 356 code | 0 blank | 4 comment | 29 complexity | ff86efc5d73b2a7dabfe5c6652ab144f MD5 | raw file
  1. <?php
  2. if( $updatevalues == 'ys' )
  3. {
  4. $sqli = '
  5. SELECT
  6. inventory_on,
  7. inventory
  8. FROM
  9. '.TABLE_PRODUCT.'
  10. WHERE
  11. product_id = "'.$product_id.'"';
  12. $resulti = @mysql_query($sqli,$connection) or die(mysql_error());
  13. while ( $row = mysql_fetch_array($resulti) )
  14. {
  15. $inventory_on = $row['inventory_on'];
  16. $inventory = $row['inventory'];
  17. }
  18. $sqlq = '
  19. SELECT
  20. quantity AS quantity_before_change
  21. FROM
  22. '.TABLE_BASKET.'
  23. WHERE
  24. basket_id = "'.$basket_id.'"
  25. AND product_id = "'.$product_id.'"';
  26. $resultq = @mysql_query($sqlq,$connection) or die(mysql_error());
  27. while ( $row = mysql_fetch_array($resultq) )
  28. {
  29. $quantity_before_change = $row['quantity_before_change'];
  30. }
  31. if ( $quantity < 0 )
  32. {
  33. $message2 = "<b>Please enter a quantity for the product.<br>To remove, enter the number 0.</b>";
  34. }
  35. elseif ( $inventory_on && $inventory < ($quantity - $quantity_before_change) && ($inventory == 1) )
  36. {
  37. $message2 = "<H3>There is only $inventory of Product ID # $product_id available. Please add that quantity or less.</h3>";
  38. }
  39. elseif ( $inventory_on && $inventory < ($quantity - $quantity_before_change) )
  40. {
  41. $message2 = "<H3>There are only $inventory of Product ID # $product_id available. Please add that quantity or less.</h3>";
  42. }
  43. elseif ( $quantity == 0 )
  44. {
  45. $sqld = '
  46. DELETE FROM
  47. '.TABLE_BASKET.'
  48. WHERE
  49. basket_id = "'.$basket_id.'"
  50. AND product_id = "'.$product_id.'"';
  51. $resultdelete = @mysql_query($sqld,$connection) or die(mysql_error());
  52. $message4 = '<b>Product was removed from basket.</b>';
  53. if ( $inventory_on )
  54. {
  55. $inventory = $inventory+$quantity_before_change;
  56. $sqlus = '
  57. UPDATE
  58. '.TABLE_PRODUCT.'
  59. SET
  60. inventory = "'.$inventory.'"
  61. WHERE
  62. product_id = "'.$product_id.'"';
  63. $resultus = @mysql_query($sqlus,$connection) or die("Could not execute query updating stock in public product list.");
  64. $sqlus2 = '
  65. UPDATE
  66. '.TABLE_PRODUCT_PREP.'
  67. SET
  68. inventory = "'.$inventory.'"
  69. WHERE
  70. product_id = "'.$product_id.'"';
  71. $resultus2 = @mysql_query($sqlus2,$connection) or die("Could not execute query updating stock in prep list.");
  72. }
  73. }
  74. elseif ( !ereg("[0-9]+$", $quantity) )
  75. {
  76. $message2 = '<b>Please review the quantity: The quantity must be a number.</b>';
  77. }
  78. elseif ( $product_id )
  79. {
  80. $customer_notes_to_producer = addslashes($customer_notes_to_producer);
  81. $sqlu = '
  82. UPDATE
  83. '.TABLE_BASKET.'
  84. SET
  85. quantity = "'.$quantity.'",
  86. total_weight = "'.$total_weight.'",
  87. customer_notes_to_producer = "'.$customer_notes_to_producer.'"
  88. WHERE
  89. basket_id = "'.$basket_id.'"
  90. AND product_id = "'.$product_id.'"';
  91. $result = @mysql_query($sqlu,$connection) or die(mysql_error());
  92. $message2 = '<b>The information has been updated.</b>';
  93. if ( $inventory_on )
  94. {
  95. $inventory = $inventory+($quantity_before_change-$quantity);
  96. $sqlus = '
  97. UPDATE
  98. '.TABLE_PRODUCT.'
  99. SET
  100. inventory = "'.$inventory.'"
  101. WHERE
  102. product_id = "'.$product_id.'"';
  103. $resultus = @mysql_query($sqlus,$connection) or die("Could not execute query updating stock in public product list.");
  104. $sqlus2 = '
  105. UPDATE
  106. '.TABLE_PRODUCT_PREP.'
  107. SET
  108. inventory = "'.$inventory.'"
  109. WHERE
  110. product_id = "'.$product_id.'"';
  111. $resultus2 = @mysql_query($sqlus2,$connection) or die("Could not execute query updating stock in prep list.");
  112. }
  113. }
  114. else
  115. {
  116. $message4 = 'No product choosen or no basket started. Please go to the <a href="index.php">main order page</a>.';
  117. }
  118. }
  119. $display_page .= '
  120. <table width="695" cellpadding="2" cellspacing="0" border="0">
  121. <tr>
  122. <td colspan="9" align="right"><font face="'.$fontface.'">';
  123. if ( $message4 )
  124. {
  125. $display_page .= '<div align="right"><font color="#770000">'.$message4.'</font></div>';
  126. }
  127. $display_page .= '
  128. </td>
  129. </tr>
  130. <tr>
  131. <td colspan="9"><hr></td>
  132. </tr>
  133. <tr>
  134. <th valign="bottom"><font face="'.$fontface.'" size="-1"></th>
  135. <th valign="bottom"><font face="'.$fontface.'" size="-1">#</th>
  136. <th valign="bottom" align="left"><font face="'.$fontface.'" size="-1">Product Name</th>
  137. <th valign="bottom"><font face="'.$fontface.'" size="-1">Price</th>
  138. <th valign="bottom"><font face="'.$fontface.'" size="-1">Quantity</th>
  139. <th valign="bottom"><font face="'.$fontface.'" size="-1">Total<br>Weight</th>
  140. <th valign="bottom"><font face="'.$fontface.'" size="-1">Extra<br>Charge</th>
  141. <th valign="bottom"><font face="'.$fontface.'" size="-1">Amount</th>
  142. <th valign="bottom"><font face="'.$fontface.'" size="-1">Edit</th>
  143. </tr>
  144. <tr>
  145. <td colspan="9"><hr></td>
  146. </tr>
  147. ';
  148. $sql = '
  149. SELECT
  150. '.TABLE_BASKET_ALL.'.*,
  151. '.TABLE_BASKET.'.*,
  152. '.TABLE_PRODUCT.'.product_name,
  153. '.TABLE_PRODUCT.'.pricing_unit,
  154. '.TABLE_PRODUCT.'.ordering_unit,
  155. '.TABLE_PRODUCT.'.random_weight,
  156. '.TABLE_PRODUCT.'.inventory_on,
  157. '.TABLE_PRODUCT.'.inventory,
  158. '.TABLE_PRODUCT.'.producer_id,
  159. '.TABLE_PRODUCT.'.product_id,
  160. '.TABLE_PRODUCT.'.detailed_notes,
  161. '.TABLE_PRODUCER.'.*,
  162. '.TABLE_MEMBER.'.member_id,
  163. '.TABLE_MEMBER.'.business_name,
  164. '.TABLE_MEMBER.'.first_name,
  165. '.TABLE_MEMBER.'.last_name
  166. FROM
  167. '.TABLE_BASKET.',
  168. '.TABLE_BASKET_ALL.',
  169. '.TABLE_PRODUCT.',
  170. '.TABLE_PRODUCER.',
  171. '.TABLE_MEMBER.'
  172. WHERE
  173. '.TABLE_BASKET_ALL.'.basket_id = "'.$basket_id.'"
  174. AND '.TABLE_BASKET.'.basket_id = "'.$basket_id.'"
  175. AND '.TABLE_BASKET_ALL.'.member_id = "'.$member_id.'"
  176. AND '.TABLE_BASKET_ALL.'.delivery_id = "'.$delivery_id.'"
  177. AND '.TABLE_BASKET.'.product_id = '.TABLE_PRODUCT.'.product_id
  178. AND '.TABLE_PRODUCT.'.producer_id = '.TABLE_PRODUCER.'.producer_id
  179. AND '.TABLE_PRODUCER.'.member_id = '.TABLE_MEMBER.'.member_id
  180. GROUP BY '.TABLE_BASKET.'.product_id
  181. ORDER BY business_name ASC, last_name ASC, product_name ASC';
  182. $result = @mysql_query($sql,$connection) or die("Couldn't execute query 1.");
  183. while ( $row = mysql_fetch_array($result) )
  184. {
  185. $product_id = $row['product_id'];
  186. $producer_id = $row['producer_id'];
  187. $member_id_product = $row['member_id'];
  188. $a_business_name = stripslashes ($row['business_name']);
  189. $a_first_name = $row['first_name'];
  190. $a_last_name = $row['last_name'];
  191. $product_name = $row['product_name'];
  192. $inventory_on = $row['inventory_on'];
  193. $inventory = $row['inventory'];
  194. $item_price = $row['item_price'];
  195. $pricing_unit = $row['pricing_unit'];
  196. $detailed_notes = stripslashes($row['detailed_notes']);
  197. $quantity = $row['quantity'];
  198. $ordering_unit = $row['ordering_unit'];
  199. $out_of_stock = $row['out_of_stock'];
  200. $random_weight = $row['random_weight'];
  201. $total_weight = $row['total_weight'];
  202. $extra_charge = $row['extra_charge'];
  203. $notes = stripslashes($row['customer_notes_to_producer']);
  204. $future_delivery_id = $row['future_delivery_id'];
  205. $item_date = $row['item_date'];
  206. if ( $out_of_stock != 1 )
  207. {
  208. if ($random_weight == 1)
  209. {
  210. if(($total_weight == 0) || ($total_weight == ''))
  211. {
  212. $display_weight = '<input type="text" name="total_weight" value="'.$total_weight.'" size="2" maxlength="11">';
  213. $message_incomplete = '<font color="#770000">Order Incomplete</font>';
  214. }
  215. else
  216. {
  217. $display_weight = '';
  218. }
  219. $display_weight = '<input type="text" name="total_weight" value="'.$total_weight.'" size="2" maxlength="11">';
  220. $item_total_3dec = round ((($item_price * $total_weight) + ($quantity * $extra_charge)), 3) + 0.00000001;
  221. $item_total_price = round ($item_total_3dec, 2);
  222. }
  223. else
  224. {
  225. $display_weight = "";
  226. $item_total_3dec = round ((($item_price * $quantity) + ($quantity * $extra_charge)), 3) + 0.00000001;
  227. $item_total_price = round ($item_total_3dec, 2);
  228. }
  229. }
  230. else
  231. {
  232. $display_weight = '';
  233. $item_total_price = 0;
  234. }
  235. if ( $out_of_stock )
  236. {
  237. $display_outofstock = '<img src="grfx/checkmark_wht.gif"><br>';
  238. }
  239. else
  240. {
  241. $display_outofstock = '';
  242. }
  243. $display_ordering_unit = Inflect::pluralize_if ($quantity, $ordering_unit);
  244. $display_pricing_unit = Inflect::pluralize_if ($quantity, $pricing_unit);
  245. if ( $extra_charge )
  246. {
  247. $display_charge = '$'.number_format($extra_charge, 2);
  248. }
  249. else
  250. {
  251. $display_charge = '';
  252. }
  253. if ( $item_total_price )
  254. {
  255. $total = $item_total_price + $total;
  256. }
  257. $total_pr = $total_pr + $quantity;
  258. $subtotal_pr = $subtotal_pr + $item_total_price;
  259. if ( $a_business_name )
  260. {
  261. $display_business_name = $a_business_name;
  262. }
  263. else
  264. {
  265. $display_business_name = $a_first_name.' '.$a_last_name;
  266. }
  267. if ( $current_producer_id < 0 )
  268. {
  269. $current_producer_id = $row['producer_id'];
  270. }
  271. while ( $current_producer_id != $producer_id )
  272. {
  273. $current_producer_id = $producer_id;
  274. $display_page .= '
  275. <tr align="left">
  276. <td><a name="'.$producer_id.'"></td>
  277. <td>____</td>
  278. <td colspan="6"><br>';
  279. $display_page .= '<font face="arial" color="#770000" size="-1"><b>'.$display_business_name.'</b></font></td></tr>';
  280. }
  281. if ( $current_product_id < 0 )
  282. {
  283. $current_product_id = $row['product_id'];
  284. }
  285. while ( $current_product_id != $product_id )
  286. {
  287. $current_product_id = $product_id;
  288. $future_delivery_id = '';
  289. $sqlfd = '
  290. SELECT
  291. '.TABLE_BASKET.'.basket_id,
  292. '.TABLE_BASKET.'.product_id,
  293. '.TABLE_BASKET.'.future_delivery_id,
  294. '.TABLE_FUTURE_DELIVERY.'.*
  295. FROM
  296. '.TABLE_BASKET.',
  297. '.TABLE_FUTURE_DELIVERY.'
  298. WHERE
  299. '.TABLE_BASKET.'.basket_id = "'.$basket_id.'"
  300. AND '.TABLE_BASKET.'.product_id = "'.$product_id.'"
  301. AND '.TABLE_FUTURE_DELIVERY.'.future_delivery_id = '.TABLE_BASKET.'.future_delivery_id';
  302. $rs = @mysql_query($sqlfd,$connection) or die("Could not execute query.");
  303. while ( $row = mysql_fetch_array($rs) )
  304. {
  305. $future_delivery_id = $row['future_delivery_id'];
  306. $future_delivery_dates = $row['future_delivery_dates'];
  307. }
  308. if( $future_delivery_id )
  309. {
  310. $future = 'Delivery date: '.$future_delivery_dates.' <br>';
  311. }
  312. else
  313. {
  314. $future = '';
  315. }
  316. if ( ($message2) && ($product_id == $product_id_printed) )
  317. {
  318. $display_page .= '
  319. <tr align="center">
  320. <td align="right" valign="top" colspan="9"><font face="arial" size="-1"><font color="#770000">'.$message2.'</font></td>
  321. </tr>';
  322. }
  323. $display_page .= '
  324. <tr align="center">
  325. <td align="center" valign="top"><font face="arial" size="-1"><a name="'.$product_id.'">
  326. <form action="#'.$producer_id.'" method="post">'.$display_outofstock.'</td>
  327. <td align="right" valign="top"><font face="arial" size="-1"><b>'.$product_id.'</b>&nbsp;&nbsp;</td>
  328. <td width="275" align="left" valign="top"><font face="arial" size="-1">
  329. <b>'.$product_name.'</b><br>'.$detailed_notes.'<br>'.$future.' <u>Notes to Producer</u>:<br>
  330. <textarea name="customer_notes_to_producer" cols="32" rows="2">'.$notes.'</textarea>';
  331. /*
  332. <br> [TESTING] INVENTORY ON: $inventory_on<br>
  333. [TESTING] INVENTORY: $inventory<br>
  334. */
  335. $display_page .= '</td>
  336. <td align="center" valign="top"><font face="arial" size="-1">$'.number_format($item_price, 2).'/'.$pricing_unit.'</td>
  337. <td align="left" valign="top"><font face="arial" size="-1">
  338. <input type="text" name="quantity" value="'.$quantity.'" size="2" maxlength="11"> '.$display_ordering_unit.'</td>
  339. <td align="center" valign="top"><font face="arial" size="-1">'.$display_weight.' '.$display_pricing_unit.'</td>
  340. <td align="center" valign="top"><font face="arial" size="-1">'.$display_charge.'</td>
  341. <td align="right" valign="top"><font face="arial" size="-1">$'.number_format($item_total_price,2).'</td>
  342. <td align="right" valign="top"><font face="arial" size="-1">
  343. <input type="hidden" name="updatevalues" value="ys">
  344. <input type="hidden" name="delivery_id" value="'.$delivery_id.'">
  345. <input type="hidden" name="product_id" value="'.$product_id.'">
  346. <input type="hidden" name="product_id_printed" value="'.$product_id.'">
  347. <input type="hidden" name="producer_id" value="'.$producer_id.'">
  348. <input type="hidden" name="member_id" value="'.$member_id.'">
  349. <input type="hidden" name="basket_id" value="'.$basket_id.'">
  350. <input name="where" type="submit" value="Update">
  351. </form></td>
  352. </tr>';
  353. }
  354. }
  355. $display_page .= '
  356. <tr>
  357. <td colspan="9">'.$font.'
  358. <hr>
  359. </td>
  360. </tr></table>';