PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/func/producer_orders_byproduct.php

https://gitlab.com/Henaway/CLFC
PHP | 332 lines | 302 code | 9 blank | 21 comment | 40 complexity | 6e50359470c129f8b2fa5d38e010e17a MD5 | raw file
  1. <?php
  2. include_once ('config_foodcoop.php');
  3. include_once ('general_functions.php');
  4. // //
  5. // This script will create a table of producer orders, by product and //
  6. // handle forms for the updating of single products. It requires that the //
  7. // following variables already be set: //
  8. // //
  9. // $current_delivery_id //
  10. // $producer_id_you //
  11. // //
  12. // If we don't have a producer_id then get one from the arguments
  13. if ($_GET['producer_id'] && CurrentMember::auth_type('producer_admin,site_admin'))
  14. {
  15. $producer_id = $_GET['producer_id'];
  16. }
  17. else
  18. {
  19. $producer_id = $_SESSION['producer_id_you'];
  20. }
  21. // If no delivery id was passed, then use the current value
  22. if ($_GET['delivery_id'])
  23. {
  24. $delivery_id = $_GET['delivery_id'];
  25. }
  26. else
  27. {
  28. $delivery_id = ActiveCycle::delivery_id();
  29. }
  30. $total_extra = 0;
  31. $sqlp = '
  32. SELECT
  33. '.TABLE_PRODUCER.'.producer_id,
  34. '.TABLE_PRODUCER.'.member_id,
  35. '.TABLE_PRODUCER.'.business_name,
  36. '.TABLE_BASKET.'.producer_id,
  37. '.TABLE_BASKET.'.product_id
  38. FROM
  39. '.TABLE_PRODUCER.'
  40. LEFT JOIN
  41. '.TABLE_BASKET.' ON '.TABLE_BASKET.'.producer_id = '.TABLE_PRODUCER.'.producer_id
  42. WHERE
  43. '.TABLE_PRODUCER.'.producer_id = "'.mysql_real_escape_string ($producer_id).'"
  44. GROUP BY
  45. '.TABLE_PRODUCER.'.producer_id
  46. ORDER BY
  47. business_name ASC';
  48. $resultp = @mysql_query($sqlp, $connection) or die(mysql_error() . "<br><b>Error No: </b>" . mysql_errno());
  49. while ( $row = mysql_fetch_array($resultp) )
  50. {
  51. $a_business_name = $row['business_name'];
  52. }
  53. $producer_orders_byproduct = '
  54. <table width="100%" cellpadding="4" cellspacing="0" border="0">
  55. <tr>
  56. <td colspan="2" align="left"><font size=4>Sorted by Product</font><br>NOTE: Sections are sorted with the items purchased first at the top</td>
  57. <td colspan="6" align="right">
  58. Click for invoice sorted by <a href="orders_prdcr_cust.php?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'">customer</a><br>
  59. Click for invoice sorted by <a href="orders_prdcr_cust_storage.php?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'">storage/customer</a><br>
  60. Click for invoice with <a href="orders_prdcr_multi.php?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'">multi-sort/mass-update</a><br>
  61. Click for <a href="producer_labels.php?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'">labels (one per product/customer)</a><br>
  62. Click for <a href="producer_labelsc.php?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'">labels (one per storage/customer)</a>
  63. </td>
  64. </tr>
  65. <tr bgcolor="#9CA5B5">
  66. <th valign="bottom" align="center">Mem.ID</th>
  67. <th valign="bottom" align="center">Member</th>
  68. <th valign="bottom" align="center">Quantity</th>
  69. <th valign="bottom" align="center">Weight</th>
  70. <th valign="bottom" align="center">'.(SHOW_ACTUAL_PRICE == true? 'Customer<br>' : ucfirst (ORGANIZATION_TYPE).'<br>' ).'Price</th>
  71. <th valign="bottom" align="center">In<br>Stock?</th>
  72. <th valign="bottom" align="center">Item<br>Total</th>
  73. <th valign="bottom" align="center">Edit<br>Item</th>
  74. </tr>';
  75. $sql = '
  76. SELECT
  77. '.TABLE_BASKET.'.*
  78. FROM
  79. '.TABLE_BASKET.',
  80. '.TABLE_BASKET_ALL.'
  81. WHERE
  82. '.TABLE_BASKET_ALL.'.delivery_id = '.mysql_real_escape_string ($delivery_id).'
  83. AND '.TABLE_BASKET.'.basket_id = '.TABLE_BASKET_ALL.'.basket_id
  84. AND '.TABLE_BASKET.'.producer_id = "'.mysql_real_escape_string ($producer_id).'"
  85. AND '.TABLE_BASKET.'.hidefrominvoice = 0
  86. GROUP BY
  87. '.TABLE_BASKET.'.product_id
  88. ORDER BY
  89. product_name ASC';
  90. $rs = @mysql_query($sql, $connection) or die(mysql_error() . "<br><b>Error No: </b>" . mysql_errno());
  91. while ( $row = mysql_fetch_array($rs) )
  92. {
  93. $c_basket_id = $row['basket_id'];
  94. $product_id = $row['product_id'];
  95. $product_name = $row['product_name'];
  96. //$item_price = $row['item_price'];
  97. $pricing_unit = $row['pricing_unit'];
  98. $producer_orders_byproduct .= '<tr bgcolor=#dddddd><td colspan="8" id="'.$product_id.'">
  99. <font size=4>'.$product_name.' (Product ID# '.$product_id.')</font><br>
  100. <!--<b>$'.number_format((double)$item_price, 2).'/'.$pricing_unit.'</b>-->
  101. </td></tr>';
  102. $total_pr = 0;
  103. $subtotal_pr = 0;
  104. //ORDER BY '.TABLE_BASKET.'.basket_id ASC
  105. $sql = '
  106. SELECT
  107. '.TABLE_BASKET.'.*,
  108. '.TABLE_MEMBER.'.first_name,
  109. '.TABLE_MEMBER.'.last_name,
  110. '.TABLE_MEMBER.'.business_name,
  111. '.TABLE_MEMBER.'.preferred_name,
  112. '.TABLE_MEMBER.'.member_id
  113. FROM
  114. '.TABLE_BASKET_ALL.'
  115. LEFT JOIN
  116. '.TABLE_BASKET.' ON '.TABLE_BASKET.'.basket_id = '.TABLE_BASKET_ALL.'.basket_id
  117. LEFT JOIN
  118. '.TABLE_MEMBER.' ON '.TABLE_MEMBER.'.member_id = '.TABLE_BASKET_ALL.'.member_id
  119. WHERE
  120. '.TABLE_BASKET.'.product_id = '.mysql_real_escape_string ($product_id).'
  121. AND
  122. (
  123. '.TABLE_BASKET_ALL.'.delivery_id = '.mysql_real_escape_string ($delivery_id).'
  124. OR '.TABLE_BASKET.'.future_delivery_id = '.mysql_real_escape_string ($delivery_id).'
  125. )
  126. AND '.TABLE_BASKET.'.producer_id = "'.mysql_real_escape_string ($producer_id).'"
  127. GROUP BY
  128. '.TABLE_BASKET.'.basket_id
  129. ORDER BY
  130. '.TABLE_BASKET.'.item_date';
  131. $resultpr = @mysql_query($sql, $connection) or die(mysql_error() . "<br><b>Error No: </b>" . mysql_errno());
  132. while ( $row = mysql_fetch_array($resultpr) )
  133. {
  134. $c_basket_id = $row['basket_id'];
  135. $product_id = $row['product_id'];
  136. $product_name = $row['product_name'];
  137. $quantity = $row['quantity'];
  138. $random_weight = $row['random_weight'];
  139. $total_weight = $row['total_weight'];
  140. $item_price = $row['item_price'];
  141. $out_of_stock = $row['out_of_stock'];
  142. $ordering_unit = $row['ordering_unit'];
  143. $extra_charge = $row['extra_charge'];
  144. $product_adjust_fee = $row['product_adjust_fee'] / 100;
  145. $subcat_adjust_fee = $row['subcat_adjust_fee'] / 100;
  146. $producer_adjust_fee = $row['producer_adjust_fee'] / 100;
  147. //$detailed_notes = $row['detailed_notes'];
  148. $future_delivery_id = $row['future_delivery_id'];
  149. $notes = $row['customer_notes_to_producer'];
  150. $member_id = $row['member_id'];
  151. $first_name = $row['first_name'];
  152. $last_name = $row['last_name'];
  153. $business_name = $row['business_name'];
  154. $preferred_name = $row['preferred_name'];
  155. $item_total_price = "";
  156. if ( $out_of_stock != 1 )
  157. {
  158. $total_pr = $total_pr + $quantity;
  159. if ( $random_weight == 1 )
  160. {
  161. if ( $total_weight == 0 )
  162. {
  163. //$product_weight = "<input type=\"text\" name=\"total_weight\" value=\"$total_weight\" size=\"2\" maxlength=\"11\"> ".$pricing_unit."s";
  164. $product_weight = '<input type="text" name="total_weight" value="'.$total_weight.'" size="5" maxlength="11"> '.$pricing_unit;
  165. $show_update_button = 'yes';
  166. $item_total_3dec = ($item_price * $total_weight) + 0.00000001;
  167. $item_total_price = round($item_total_3dec, 2);
  168. // $item_total_price = number_format($item_total_price, 2);
  169. $display_unit_price = $item_total_price;
  170. $message_incomplete = '<font color="#770000">Order Incomplete<font>';
  171. }
  172. else
  173. {
  174. //$product_weight = "<input type=\"text\" name=\"total_weight\" value=\"$total_weight\" size=\"2\" maxlength=\"11\"> ".$pricing_unit."s";
  175. $product_weight = '<input type="text" name="total_weight" value="'.$total_weight.'" size="5" maxlength="11"> '.Inflect::pluralize ($pricing_unit);
  176. $show_update_button = 'yes';
  177. $item_total_3dec = (($item_price*$total_weight)+($extra_charge*$quantity)) + 0.00000001;
  178. $item_total_price = round($item_total_3dec, 2);
  179. // $item_total_price = number_format($item_total_price, 2);
  180. $display_unit_price = $item_total_price;
  181. }
  182. }
  183. else
  184. {
  185. $product_weight = "";
  186. $show_update_button= 'no';
  187. $item_total_3dec = (($item_price * $quantity) + ($extra_charge * $quantity)) + 0.00000001;
  188. $item_total_price = round($item_total_3dec, 2);
  189. // $item_total_price = number_format($item_total_price, 2);
  190. $display_unit_price = $item_total_price;
  191. }
  192. }
  193. else
  194. {
  195. $total_pr = $total_pr;
  196. $product_weight = '';
  197. $show_update_button = 'no';
  198. $item_total_price = number_format(0, 2);
  199. }
  200. $product_total_price = '';
  201. if ( $future_delivery_id == ActiveCycle::delivery_id() )
  202. {
  203. $product_weight = '';
  204. $item_total_price = '';
  205. $product_total_price = '<font color=#FF0000>Invoiced in a previous order</font>';
  206. }
  207. elseif ( $future_delivery_id > ActiveCycle::delivery_id() )
  208. {
  209. $product_total_price = '<font color=#FF0000>Will be delivered in future order</font>';
  210. }
  211. if ( $out_of_stock == 1 )
  212. {
  213. $product_outofstock = '<img src="'.BASE_URL.DIR_GRAPHICS.'checkmark_wht.gif" align=right>';
  214. $extra_charge = 0; // If not sold, then no extra charge
  215. $chk1 = '';
  216. $chk2 = 'checked';
  217. }
  218. else
  219. {
  220. $product_outofstock = '';
  221. $chk1 = 'checked';
  222. $chk2 = '';
  223. }
  224. if ( $extra_charge )
  225. {
  226. $extra_charge_calc = $extra_charge*$quantity;
  227. $total_extra = $total_extra + round ($extra_charge_calc, 2);
  228. $product_charge = '$'.number_format($extra_charge_calc, 2);
  229. }
  230. else
  231. {
  232. $product_charge = "";
  233. }
  234. $product_stock = '
  235. <input type="radio" name="out_of_stock" value="0" '.$chk1.'>In<br>
  236. '.$product_outofstock.'
  237. <input type="radio" name="out_of_stock" value="1" '.$chk2.'>Out';
  238. if ( $item_total_price )
  239. {
  240. $total = $item_total_price + $total;
  241. }
  242. $subtotal_pr = $subtotal_pr + $item_total_price;
  243. if ( $notes )
  244. {
  245. $product_notes = '<br>Customer note: '.$notes;
  246. }
  247. else
  248. {
  249. $product_notes = '';
  250. }
  251. if ( $current_product_id < 0 )
  252. {
  253. $current_product_id = $row['product_id'];
  254. }
  255. while ( $current_product_id != $product_id )
  256. {
  257. $current_product_id = $product_id;
  258. }
  259. if ( $item_total_price )
  260. {
  261. $product_total_price = '$ '.number_format ($item_total_price, 2);
  262. }
  263. // Set the coop_markup according to auth_type
  264. if (CurrentMember::auth_type('institution')) $coop_markup = 1 + $wholesale_markup;
  265. else $coop_markup = 1 + $retail_markup;
  266. // Set the adjust_markup
  267. $adjust_markup = 1 + $product_adjust_fee + $subcat_adjust_fee + $producer_adjust_fee;
  268. // Set the display_unit_price according to SHOW_ACTUAL_PRICE
  269. if (SHOW_ACTUAL_PRICE) $display_unit_price = round ($item_price * $adjust_markup * $coop_markup, 2);
  270. else $display_unit_price = round ($item_price * $adjust_markup, 2);
  271. $display_price = '';
  272. if ( $display_unit_price != 0 )
  273. {
  274. $display_price .= $font.' $'.number_format($display_unit_price, 2).'/'.$pricing_unit.'';
  275. }
  276. if ( $display_unit_price != 0 && $extra_charge != 0 ) $display_price .= '<br>and<br>';
  277. if ( $extra_charge != 0 )
  278. {
  279. $display_price .= '$'.number_format($extra_charge, 2).'/'.Inflect::singularize ($ordering_unit);
  280. }
  281. $producer_orders_byproduct .= '
  282. <tr align="center">
  283. <td align="right" valign="top"><form action="'.$PHP_SELF.'?delivery_id='.$delivery_id.'&producer_id='.$producer_id.'#'.$product_id.'" method="post"><b># '.$member_id.'</b>&nbsp;&nbsp;</td>
  284. <td align="left" valign="top"><b>'.$preferred_name.'</b>'.$product_notes.'</td>
  285. <td align="center" valign="top">'.$quantity.' '.Inflect::pluralize_if ($quantity, $ordering_unit).'</td>
  286. <td align="center" valign="top">'.$product_weight.'</td>
  287. <td align="center" valign="top">'.$display_price.'</td>
  288. <td align="left" valign="top">'.$product_stock.'</td>
  289. <td align="center" valign="top">'.$product_total_price.'</td>
  290. <td align="center" valign="top">';
  291. $producer_orders_byproduct .= '
  292. <input type="hidden" name="updatevalues" value="ys">
  293. <input type="hidden" name="product_id" value="'.$product_id.'">
  294. <input type="hidden" name="product_id_printed" value="'.$product_id.'">
  295. <input type="hidden" name="producer_id" value="'.$producer_id_you.'">
  296. <input type="hidden" name="member_id" value="'.$member_id.'">
  297. <input type="hidden" name="c_member_id" value="'.$member_id.'">
  298. <input type="hidden" name="c_basket_id" value="'.$c_basket_id.'">
  299. <input name="where" type="submit" value="Update">
  300. </form>';
  301. if ( $product_id == $_POST['product_id_printed'] && $member_id == $c_member_id )
  302. {
  303. $producer_orders_byproduct .= '<p>'.$message2.'</p>';
  304. }
  305. else
  306. {
  307. $producer_orders_byproduct .= '';
  308. }
  309. $producer_orders_byproduct .= '
  310. </td>
  311. </tr>';
  312. }
  313. $producer_orders_byproduct .= '
  314. <tr>
  315. <td colspan="8">Product Quantity: '.$total_pr.'</td>
  316. </tr>
  317. <tr>
  318. <td colspan="8">Product subtotal: $'.number_format($subtotal_pr, 2).'</td>
  319. </tr>';
  320. }
  321. $producer_orders_byproduct .= '
  322. </table>';
  323. ?>