PageRenderTime 24ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/query_notes.php

https://gitlab.com/Henaway/CLFC
PHP | 269 lines | 263 code | 4 blank | 2 comment | 13 complexity | ffdc490da868cb2ce5925dc8910be3e5 MD5 | raw file
  1. <?php
  2. include_once ("config_foodcoop.php");
  3. include_once ("general_functions.php");
  4. session_start();
  5. valid_auth('route_admin,member_admin,site_admin');
  6. $date_today = date("F j, Y");
  7. $sqlm = '
  8. SELECT
  9. '.TABLE_BASKET_ALL.'.member_id,
  10. '.TABLE_BASKET_ALL.'.delivery_id,
  11. '.TABLE_BASKET.'.customer_notes_to_producer,
  12. '.TABLE_BASKET.'.basket_id,
  13. '.TABLE_BASKET_ALL.'.basket_id,
  14. '.TABLE_MEMBER.'.*
  15. FROM
  16. '.TABLE_BASKET_ALL.'
  17. LEFT JOIN '.TABLE_BASKET.' ON '.TABLE_BASKET_ALL.'.basket_id = '.TABLE_BASKET.'.basket_id
  18. LEFT JOIN '.TABLE_MEMBER.' ON '.TABLE_BASKET_ALL.'.member_id = '.TABLE_MEMBER.'.member_id
  19. WHERE
  20. '.TABLE_BASKET_ALL.'.delivery_id = "'.mysql_real_escape_string (ActiveCycle::delivery_id()).'"
  21. AND '.TABLE_BASKET.'.customer_notes_to_producer != ""
  22. GROUP BY
  23. '.TABLE_BASKET_ALL.'.member_id
  24. ORDER BY
  25. last_name ASC';
  26. $resultm = @mysql_query($sqlm, $connection) or die("Couldn't execute query -m.");
  27. while ( $row = mysql_fetch_array($resultm) )
  28. {
  29. $basket_id = $row['basket_id'];
  30. $member_id = $row['member_id'];
  31. $first_name = $row['first_name'];
  32. $last_name = $row['last_name'];
  33. $first_name_2 = $row['first_name_2'];
  34. $last_name_2 = $row['last_name_2'];
  35. $business_name = $row['business_name'];
  36. if ( $current_member_id < 0 )
  37. {
  38. $current_member_id = $row['member_id'];
  39. }
  40. while ( $current_member_id != $member_id )
  41. {
  42. $current_member_id = $member_id;
  43. include("../func/show_name_last.php");
  44. $display_basket .= '
  45. <tr align="left" bgcolor="#AEDE86"><td colspan="8">'.$show_name.' (Mem # '.$member_id.')</td></tr>';
  46. $sql = '
  47. SELECT
  48. '.TABLE_BASKET_ALL.'.*,
  49. '.TABLE_BASKET.'.*,
  50. '.TABLE_PRODUCER.'.*,
  51. '.TABLE_PRODUCER.'.business_name,
  52. '.TABLE_PAY.'.*
  53. FROM
  54. '.TABLE_BASKET.'
  55. LEFT JOIN
  56. '.TABLE_BASKET_ALL.' ON '.TABLE_BASKET.'.basket_id = '.TABLE_BASKET_ALL.'.basket_id
  57. LEFT JOIN
  58. '.TABLE_PRODUCER.' ON '.TABLE_BASKET.'.producer_id = '.TABLE_PRODUCER.'.producer_id
  59. LEFT JOIN
  60. '.TABLE_PAY.' ON '.TABLE_BASKET_ALL.'.payment_method = '.TABLE_PAY.'.payment_method
  61. WHERE
  62. '.TABLE_BASKET_ALL.'.basket_id = "'.mysql_real_escape_string ($basket_id).'"
  63. AND '.TABLE_BASKET_ALL.'.member_id = "'.mysql_real_escape_string ($member_id).'"
  64. AND '.TABLE_BASKET_ALL.'.delivery_id = "'.mysql_real_escape_string (ActiveCycle::delivery_id()).'"
  65. AND '.TABLE_BASKET.'.customer_notes_to_producer != ""
  66. ORDER BY
  67. business_name ASC';
  68. $result = @mysql_query($sql, $connection) or die("Couldn't execute query 1.");
  69. while ( $row = mysql_fetch_array($result) )
  70. {
  71. $product_id = $row['product_id'];
  72. $producer_id = $row['producer_id'];
  73. $member_id_product = $row['member_id'];
  74. $a_business_name = $row['business_name'];
  75. $product_name = $row['product_name'];
  76. $item_price = $row['item_price'];
  77. $pricing_unit = $row['pricing_unit'];
  78. $detailed_notes = $row['detailed_notes'];
  79. $quantity = $row['quantity'];
  80. $ordering_unit = $row['ordering_unit'];
  81. $out_of_stock = $row['out_of_stock'];
  82. $random_weight = $row['random_weight'];
  83. $total_weight = $row['total_weight'];
  84. $extra_charge = $row['extra_charge'];
  85. $notes = $row['customer_notes_to_producer'];
  86. $transcharge = $row['transcharge'];
  87. $delivery_id = $row['delivery_id'];
  88. $delivery_date = $row['delivery_date'];
  89. $payment_method = $row['payment_method'];
  90. $payment_desc = $row['payment_desc'];
  91. if ( $out_of_stock != 1 )
  92. {
  93. if ( $random_weight == 1 )
  94. {
  95. if ( $total_weight == 0 )
  96. {
  97. $display_weight = '<font color="#770000">weight to be added</font>';
  98. $message_incomplete = '<font color="#770000">Order Incomplete</font>';
  99. }
  100. else
  101. {
  102. $display_weight = $total_weight;
  103. }
  104. $item_total_3dec = number_format((($item_price * $total_weight) + ($quantity * $extra_charge)), 3) + 0.00000001;
  105. $item_total_price = round($item_total_3dec, 2);
  106. }
  107. else
  108. {
  109. $display_weight = '';
  110. $item_total_3dec = number_format((($item_price * $quantity) + ($quantity * $extra_charge)), 3) + 0.00000001;
  111. $item_total_price = round($item_total_3dec, 2);
  112. }
  113. }
  114. else
  115. {
  116. $display_weight = '';
  117. $item_total_price = 0;
  118. }
  119. if ( $out_of_stock )
  120. {
  121. $display_outofstock = '<img src="grfx/checkmark_wht.gif"><br>';
  122. }
  123. else
  124. {
  125. $display_outofstock = '';
  126. }
  127. if ( $quantity > 1 )
  128. {
  129. //$display_ordering_unit = $ordering_unit.'s';
  130. $display_ordering_unit = $ordering_unit;
  131. }
  132. else
  133. {
  134. $display_ordering_unit = $ordering_unit;
  135. }
  136. if ( $total_weight > 1 )
  137. {
  138. //$display_pricing_unit = $pricing_unit.'s';
  139. $display_pricing_unit = $pricing_unit;
  140. }
  141. elseif ( $total_weight == 1 )
  142. {
  143. $display_pricing_unit = $pricing_unit;
  144. }
  145. else
  146. {
  147. $display_pricing_unit = '';
  148. }
  149. if ( $extra_charge )
  150. {
  151. $display_charge = '$'.number_format($extra_charge, 2);
  152. }
  153. else
  154. {
  155. $display_charge = '';
  156. }
  157. if ( $item_total_price )
  158. {
  159. $total = $item_total_price + $total;
  160. }
  161. $total_pr = $total_pr + $quantity;
  162. $subtotal_pr = $subtotal_pr + $item_total_price;
  163. if ( $notes )
  164. {
  165. $display_notes = '<b>Customer note:</b> '.$notes.'';
  166. }
  167. else
  168. {
  169. $display_notes = '';
  170. }
  171. if ( $current_producer_id < 0 )
  172. {
  173. $current_producer_id = $row['producer_id'];
  174. }
  175. while ( $current_producer_id != $producer_id )
  176. {
  177. $current_producer_id = $producer_id;
  178. }
  179. $display_basket .= '
  180. <tr align="left"><td></td><td>____</td><td colspan="6"><br>
  181. <font face="arial" color="#770000" size="-1"><b>'.$a_business_name.'</b></font></td></tr>';
  182. if ( $current_product_id < 0 )
  183. {
  184. $current_product_id = $row['product_id'];
  185. }
  186. while ( $current_product_id != $product_id )
  187. {
  188. $current_product_id = $product_id;
  189. }
  190. $future_delivery_id = '';
  191. $sqlfd = '
  192. SELECT
  193. '.TABLE_BASKET.'.basket_id,
  194. '.TABLE_BASKET.'.product_id,
  195. '.TABLE_BASKET.'.future_delivery_id,
  196. '.TABLE_FUTURE_DELIVERY.'.*
  197. FROM
  198. '.TABLE_BASKET.',
  199. '.TABLE_FUTURE_DELIVERY.'
  200. WHERE
  201. '.TABLE_BASKET.'.basket_id = "'.mysql_real_escape_string ($basket_id).'"
  202. AND '.TABLE_BASKET.'.product_id = "'.mysql_real_escape_string ($product_id).'"
  203. AND '.TABLE_FUTURE_DELIVERY.'.future_delivery_id = '.TABLE_BASKET.'.future_delivery_id';
  204. $rs = @mysql_query($sqlfd, $connection) or die("Couldn't execute query.");
  205. while ( $row = mysql_fetch_array($rs) )
  206. {
  207. $future_delivery_id = $row['future_delivery_id'];
  208. $future_delivery_dates = $row['future_delivery_dates'];
  209. }
  210. if ( $future_delivery_id )
  211. {
  212. $future = 'Delivery date: '.$future_delivery_dates.' <br>';
  213. }
  214. else
  215. {
  216. $future = '';
  217. }
  218. $display_basket .= '
  219. <tr align="center">
  220. <td align="center" valign="top"><font face="arial" size="-1">'.$display_outofstock.'</td>
  221. <td align="right" valign="top"><font face="arial" size="-1"><b>'.$product_id.'</b>&nbsp;&nbsp;</td>
  222. <td width="275" align="left" valign="top"><font face="arial" size="-1"><b>'.$product_name.'</b><br>'.$size_measurements_contents.'<br>'.$future.''.$display_notes.'</td>
  223. <td align="center" valign="top"><font face="arial" size="-1">$'.number_format($item_price, 2).'/'.$pricing_unit.'</td>
  224. <td align="center" valign="top"><font face="arial" size="-1">'.$quantity.' '.$display_ordering_unit.'</td>
  225. <td align="center" valign="top"><font face="arial" size="-1">'.$display_weight.' '.$display_pricing_unit.'</td>
  226. <td align="center" valign="top"><font face="arial" size="-1">'.$display_charge.'</td>
  227. <td align="right" valign="top"><font face="arial" size="-1">$'.number_format($item_total_price, 2).'</td>
  228. </tr>';
  229. }
  230. $display_basket .= '
  231. <tr align="left" bgcolor="#FFFFFF"><td colspan="8"><br><br></td></tr>';
  232. }
  233. }
  234. $fontface='arial';
  235. $display_page .= '
  236. <table width="80%" cellpadding="2" cellspacing="0" border="0" align="center">
  237. <tr>
  238. <td colspan="8"><hr></td>
  239. </tr>
  240. <tr>
  241. <th valign="bottom"><font face="'.$fontface.'" size="-1"></th>
  242. <th valign="bottom"><font face="'.$fontface.'" size="-1">#</th>
  243. <th valign="bottom" align="left"><font face="'.$fontface.'" size="-1">Product Name</th>
  244. <th valign="bottom"><font face="'.$fontface.'" size="-1">Price</th>
  245. <th valign="bottom"><font face="'.$fontface.'" size="-1">Quantity</th>
  246. <th valign="bottom"><font face="'.$fontface.'" size="-1">Total<br>Weight</th>
  247. <th valign="bottom"><font face="'.$fontface.'" size="-1">Extra<br>Charge</th>
  248. <th valign="bottom"><font face="'.$fontface.'" size="-1">Amount</th>
  249. </tr>
  250. <tr>
  251. <td colspan="8"><hr></td>
  252. </tr>';
  253. $display_page .= $display_basket;
  254. $display_page .= '
  255. </table>';
  256. $page_title_html = '<span class="title">Delivery Cycle Functions</span>';
  257. $page_subtitle_html = '<span class="subtitle">Orders with Customer Notes</span>';
  258. $page_title = 'Delivery Cycle Functions: Orders with Customer Notes';
  259. $page_tab = 'member_admin_panel';
  260. include("template_header.php");
  261. echo '
  262. <!-- CONTENT BEGINS HERE -->
  263. '.$display_page.'
  264. <!-- CONTENT ENDS HERE -->';
  265. include("template_footer.php");