PageRenderTime 63ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/printpackingslips.php

https://bitbucket.org/chadsaun/ifrogz-panel
PHP | 745 lines | 578 code | 80 blank | 87 comment | 118 complexity | ee0fda35329b2548768cd591af129b98 MD5 | raw file
  1. <?php
  2. session_start();
  3. ini_set("memory_limit","12M");
  4. include('init.php');
  5. include_once(APPPATH.'views/partials/admin/dbconnection.php');
  6. include_once(APPPATH.'views/partials/admin/functions.php');
  7. if(@$storesessionvalue=="") $storesessionvalue="virtualstore";
  8. if((@$_SESSION["loggedon"] != $storesessionvalue && trim(@$_COOKIE["WRITECKL"])=="") || @$disallowlogin==TRUE) {
  9. header('Location: /user/login');
  10. exit();
  11. }
  12. // This is used to turn on and off the format for using letterhead
  13. $_GET['test'] = 0;
  14. session_start();
  15. //DETERMINE IF IT IS A REPRINT
  16. $reprint = TRUE;
  17. if ($_GET['batch'] == "") {
  18. $batch_name = date('Y-m-d H:i:s');
  19. $reprint = FALSE;
  20. } else {
  21. $batch_name = $_GET['batch'];
  22. $reprint = TRUE;
  23. }
  24. //POST
  25. $strOrderIDs = '';
  26. if (is_array($_POST['orderid'])) {
  27. foreach ($_POST['orderid'] as $value) {
  28. if($strOrderID == '') $comma = '';
  29. else $comma = ',';
  30. $strOrderID .= $comma . $value;
  31. }
  32. //mail('blake@ifrogz.com','Packing Slip Print',$strOrderID,'');
  33. }
  34. //GET ORDERS
  35. $sql_check="SELECT * FROM orders WHERE ";
  36. if ($_GET['order'] != "") {
  37. $orderID = $_GET['order'];
  38. $sql_check.=" ordID=" . $orderID;
  39. } else {
  40. if ($reprint) {
  41. $sql_check.=" ordBatch='".$batch_name."'";
  42. } else {
  43. $ordStatus=3;
  44. if(!empty($_POST['status'])) {
  45. $ordStatus = $_POST['status'];
  46. }
  47. $sql_check.=" ordStatus='".$ordStatus."'";
  48. }
  49. }
  50. if($strOrderID != '') {
  51. $sql_check.=" AND ordID IN (" . $strOrderID . ")";
  52. }
  53. $sql_check.=" AND ordEID!=34";
  54. /*if (empty($screenz)) {
  55. if (!empty($etailer)) {
  56. $sql_check.=" AND ordEID>0";
  57. $str_batch_type='_e';
  58. } else {
  59. $sql_check.=" AND ordEID=0";
  60. }
  61. }
  62. */
  63. $sql_check.= " ORDER BY ordShipType,ordID";
  64. if ( $_POST['number'] != "" ) {
  65. $sql_check.= " LIMIT " . $_POST['number'];
  66. }
  67. //echo $sql_check;
  68. $result_check = mysql_query($sql_check) or print(mysql_error());
  69. if (mysql_num_rows($result_check)==0) {
  70. echo "There are 0 orders to print!";
  71. exit();
  72. }
  73. $arrOrders = array();
  74. $d=0;
  75. while ($row_check = mysql_fetch_assoc($result_check)) {
  76. //DETERMINE IF SINGLE ORDER HAS ALREADY BEEN PRINTED
  77. if ($row_check['ordBatch'] != "" && $_GET['order'] != "") $reprint = TRUE;
  78. //GRAB DATA FROM ORDERS
  79. $arrOrders[$d] = $row_check;
  80. //SHIP TYPE
  81. $apoOrder = FALSE;
  82. if($row_check["ordShipAddress"] != "" && $row_check["ordShipCity"] != "" && $row_check["ordShipZip"] !="" ) {
  83. if(stristr('AA,AE,AP',$row_address["ordShipState"])) $apoOrder=TRUE;
  84. } else {
  85. if(stristr('AA,AE,AP',$row_address["ordState"])) $apoOrder=TRUE;
  86. }
  87. if($apoOrder) $shipType='Priority - APO';
  88. else $shipType = $row_check["ordShipType"];
  89. $arrOrders[$d]["ordShipType"]=$shipType;
  90. $d++;
  91. }
  92. mysql_free_result($result_check);
  93. ?>
  94. <style type="text/css">
  95. <!--
  96. td {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;}
  97. -->
  98. </style>
  99. <?php
  100. foreach ($arrOrders as $order) {
  101. // Get the product information for the order
  102. $sql = "SELECT IF(p.pSell=1,p.pBin,o.optBin) AS bin, SUM(c.cartQuantity) AS cartQuantity, c.cartProdID, c.cartProdName, c.cartID, co.coCartOption, o.optID, co.coOptGroup, o.optName, o.optStyleID, o.optGroup, c.cartProdPrice, p.p_iscert, p.pDownload, p.pWeight
  103. FROM cart c JOIN products p ON c.cartProdID=p.pID LEFT JOIN cartoptions co ON c.cartID=co.coCartID LEFT JOIN options o ON co.coOptID=o.optID
  104. WHERE c.cartOrderID = ".$order['ordID']."
  105. GROUP BY IF(p.pSell=1,c.cartProdID,co.coOptID)
  106. ORDER BY c.cartID";
  107. $res = mysql_query($sql) or print(mysql_error());
  108. $arrProducts = array();
  109. $i = 0;
  110. $count_email_cert = 0;
  111. $count_down_loads = 0;
  112. $oldCartID = '';
  113. $orderWeight = 0;
  114. $has_custom_screen = 0;
  115. $has_all_custom_screenz = TRUE;
  116. $num_rows = mysql_num_rows($res);
  117. while ($row = mysql_fetch_assoc($res)) {
  118. //$arrProducts[$i] = $row;
  119. if($row['p_iscert'] == 1 && $row['optName'] == "Email" || $row['pDownload'] != "") {
  120. if($row['p_iscert'] == 1 && $row['optName'] == "Email") $count_email_cert++;
  121. if($row['pDownload'] != "") $count_down_loads++;
  122. } else {
  123. $arrProducts[$i] = $row;
  124. }
  125. if(strstr($row['cartProdID'],'-Custom')) {
  126. $cartoption_left5 = (int)substr($row['coCartOption'],0,5);
  127. $sql_custom = "SELECT *
  128. FROM uploaded_images
  129. WHERE id = ".$cartoption_left5;
  130. //echo $sql_custom. '<br />';
  131. $result_custom = mysql_query($sql_custom);
  132. if( mysql_num_rows($result_custom) > 0){
  133. $row_custom = mysql_fetch_assoc($result_custom);
  134. $has_custom_screen++;
  135. $arrProducts[$i]['custom'] = $row_custom['display_image'];
  136. $arrProducts[$i]['optName'] = $row_custom['display_image'];
  137. }
  138. }
  139. // If this option is a Custom Hype Rim, then make quantity double. (They are ordered as pairs, but inventory is kept individually)
  140. // * Remeber to change this in other places too ( release_stock(), getOnOrderStock(), do_stock_management() in /application/views/partials/admin/functions.php )
  141. if ($row['cartProdID'] == 'customhype' && strstr($row['coOptGroup'], 'Rim')) {
  142. $arrProducts[$i]['cartQuantity'] = (int)$arrProducts[$i]['cartQuantity'] * 2;
  143. }
  144. $i++;
  145. }
  146. //ADD PRODUCTS TO ORDER
  147. addProdsToOrder2($order['ordID']);
  148. //SORT ARRAY BY BIN NUMBER
  149. usort($arrProducts, 'cmpBins');
  150. //sort($arrProducts);
  151. mysql_free_result($res);
  152. /*echo "<!-- chad\n";
  153. print_r($arrProducts);
  154. echo " -->";*/
  155. //showarray($arrProducts);
  156. //CALCULATE WEIGHT
  157. $sql_weight = "SELECT * FROM cart c JOIN products p ON c.cartProdID=p.pID WHERE cartOrderID = ".$order['ordID'];
  158. $res_weight = mysql_query($sql_weight) or print(mysql_error());
  159. while ($row_weight = mysql_fetch_assoc($res_weight)) {
  160. //echo 'in-';
  161. //$arrProducts[$i]['pWeight'] = $row_weight['pWeight'] * $row_weight['cartQuantity'];
  162. $orderWeight += $row_weight['pWeight'] * $row_weight['cartQuantity'];
  163. //echo 'w='.$row['pWeight'] * $row['cartQuantity']."<br />";
  164. //number_format(($row['pWeight'] * $row['cartQuantity'] * 35.2739619),3)
  165. }
  166. $orderWeightOunces = number_format((($orderWeight + 0.03) * 35.2739619),3);
  167. //Skip order if they are all email certs, downloads
  168. $skip_order = FALSE;
  169. if (!$reprint) {
  170. $new_status = 6;
  171. if ($num_rows == $count_email_cert || $num_rows == $count_down_loads) {
  172. $new_status=12;
  173. $skip_order = TRUE;
  174. }
  175. //UPDATE ORDER STATUS
  176. $sql_update="UPDATE orders SET ordStatus='" . $new_status . "', ordBatch='" . $batch_name . "', ordFulfilledBy='" . $_SESSION["packingsliplogin"]['firstname'] . "' WHERE ordID='" . $order['ordID'] . "'";
  177. mysql_query($sql_update)or print(mysql_error());
  178. // Backup to make sure orders don't get marked as being printed when nobody submitted them to be printed
  179. if (!empty($_POST['status'])) {
  180. if(!setNewLocation( $new_status , $order['ordID'] )) print("Unable to record location.");
  181. }
  182. }
  183. //$sql_update="UPDATE orders SET ordWeight=" . $orderWeight . " WHERE ordID='" . $order['ordID'] . "'";
  184. //mysql_query($sql_update)or print(mysql_error());
  185. if (!is_array($order)) echo 'There are no orders to print';
  186. if ($skip_order) continue;
  187. if ($_GET['test'] != 1) {
  188. ?>
  189. <table width="100%" border="0" cellspacing="0" cellpadding="0" style="page-break-after: always;">
  190. <?php
  191. } else {
  192. ?>
  193. <table border="0" cellspacing="0" cellpadding="0" style="margin-left: 0; margin-top: .50in; page-break-after: always; width: 5.30in;">
  194. <?php
  195. }
  196. ?>
  197. <tr>
  198. <td width="170" align="left"><img src="/barcode/wrapper.php?p_bcType=1&p_text=<?=$order['ordID']?>&p_xDim=1&p_w2n=3&p_charGap=1&p_invert=N&p_charHeight=40&p_type=1&p_label=N&p_rotAngle=0&p_checkDigit=N" alt="1234567890" /></td>
  199. <td align="center"><span style="font-weight: bold; font-size: 14px;">Order # <?=$order['ordID']?><br /><?=$order['ordShipType']?> <br /><?=$orderWeightOunces?> oz</span></td>
  200. <td width="170" align="right">
  201. <?php
  202. if (($_GET['test'] != 1) && ( ! is_special_order($order['ordID']))) {
  203. ?>
  204. <img src="/lib/images/ifrogz_logo_white2.jpg" width="125" />
  205. <?php
  206. } else {
  207. ?>
  208. <img src="/lib/images/createbutton.jpg" width="153" />
  209. <?php
  210. }
  211. ?>
  212. </td>
  213. </tr>
  214. <tr>
  215. <td colspan="3">
  216. <table width="100%" border="0" cellpadding="3" cellspacing="0">
  217. <tr>
  218. <td align="center" colspan="5" style="font-weight: bold;">Billing Information</td>
  219. </tr>
  220. <tr>
  221. <td align="right" style="font-weight: bold;">Full Name:</td>
  222. <td align="left" colspan="2"><?=$order['ordName']?></td>
  223. <td align="right" style="font-weight: bold;">Email:</td>
  224. <td align="left"><?=$order['ordEmail']?></td>
  225. </tr>
  226. <tr>
  227. <td align="right" style="font-weight: bold;">Address:</td>
  228. <td align="left" colspan="2"><?=$order['ordAddress']?></td>
  229. <td colspan="2">&nbsp;</td>
  230. </tr>
  231. <tr>
  232. <td align="right" style="font-weight: bold;">Address Line 2:</td>
  233. <td align="left" colspan="2"><?=$order['ordAddress2']?></td>
  234. <td align="right" style="font-weight: bold;">City:</td>
  235. <td align="left"><?=$order['ordCity']?></td>
  236. </tr>
  237. <tr>
  238. <td align="right" style="font-weight: bold;">State:</td>
  239. <td align="left"><?=$order['ordState']?></td>
  240. <td align="left">
  241. <strong>APO/PO:</strong>
  242. <input type="checkbox" value="1" disabled="disabled"<?=($order['ordPoApo']) ? ' checked="checked"' : ''?> />
  243. </td>
  244. <td align="right" style="font-weight: bold;">Country:</td>
  245. <td align="left"><?=$order['ordCountry']?></td>
  246. </tr>
  247. <tr>
  248. <td align="right" style="font-weight: bold;">Zip/Postal Code:</td>
  249. <td align="left" colspan="2"><?=$order['ordZip']?></td>
  250. <td align="right" style="font-weight: bold;">Phone:</td>
  251. <td align="left"><?=$order['ordPhone']?></td>
  252. </tr>
  253. <?php
  254. if (!empty($order['ordShipAddress'])) {
  255. ?>
  256. <tr>
  257. <td align="center" colspan="5" style="font-weight: bold;">Shipping Details</td>
  258. </tr>
  259. <tr>
  260. <td align="right" style="font-weight: bold;">Full Name:</td>
  261. <td align="left" colspan="2"><?=$order['ordShipName']?></td>
  262. <td align="right" style="font-weight: bold;">Email:</td>
  263. <td align="left"><?=$order['ordShipEmail']?></td>
  264. </tr>
  265. <tr>
  266. <td align="right" style="font-weight: bold;">Address:</td>
  267. <td align="left" colspan="2"><?=$order['ordShipAddress']?></td>
  268. <td colspan="2">&nbsp;</td>
  269. </tr>
  270. <tr>
  271. <td align="right" style="font-weight: bold;">Address Line 2:</td>
  272. <td align="left" colspan="2"><?=$order['ordShipAddress2']?></td>
  273. <td align="right" style="font-weight: bold;">City:</td>
  274. <td align="left"><?=$order['ordShipCity']?></td>
  275. </tr>
  276. <tr>
  277. <td align="right" style="font-weight: bold;">State:</td>
  278. <td align="left"><?=$order['ordShipState']?></td>
  279. <td align="left">
  280. <strong>APO/PO:</strong>
  281. <input type="checkbox" value="1" disabled="disabled"<?=($order['ordShipPoApo']) ? ' checked="checked"' : ''?> />
  282. </td>
  283. <td align="right" style="font-weight: bold;">Country:</td>
  284. <td align="left"><?=$order['ordShipCountry']?></td>
  285. </tr>
  286. <tr>
  287. <td align="right" style="font-weight: bold;">Zip/Postal Code:</td>
  288. <td align="left" colspan="2"><?=$order['ordShipZip']?></td>
  289. <td align="right" style="font-weight: bold;">Phone:</td>
  290. <td align="left"><?=$order['ordShipPhone']?></td>
  291. </tr>
  292. <?php
  293. }
  294. ?>
  295. </table>
  296. </td>
  297. </tr>
  298. <tr>
  299. <td colspan="3">
  300. <table border="0" cellpadding="3" cellspacing="0" width="100%">
  301. <tr>
  302. <td>
  303. <table border="1" cellpadding="4" cellspacing="0" bordercolor="#999999" style="border-collapse: collapse" width="100%">
  304. <tr>
  305. <td>&nbsp;</td>
  306. <td style="font-weight: bold;" align="center">Qty</td>
  307. <td style="font-weight: bold;" align="center">Bin</td>
  308. <td style="font-weight: bold;">Product ID</td>
  309. <td style="font-weight: bold;">Product Name</td>
  310. <td style="font-weight: bold;">Options</td>
  311. <!--<td style="font-weight: bold;">Price</td>-->
  312. </tr>
  313. <?php
  314. //prepBins(&$arrProducts); // For testing purposes
  315. $zoneCount = countZones($arrProducts);
  316. //echo '<!-- '; print_r($arrProducts); print_r($zoneCount); echo ' -->';
  317. $numOfProds = count($arrProducts);
  318. $curBin = '';
  319. for ($i = 0; $i < $numOfProds; $i++) {
  320. if(strlen($arrProducts[$i]['bin']) > 6)
  321. $bin = strtoupper(substr($arrProducts[$i]['bin'], 2, 2));
  322. else
  323. $bin = strtoupper(substr($arrProducts[$i]['bin'], 0, 1));
  324. //$bin = strtoupper(substr($arrProducts[$i]['bin'], 0, 1));
  325. $rowSpan = $zoneCount[$bin];
  326. ?>
  327. <tr>
  328. <?php
  329. if ($i == 0) {
  330. ?>
  331. <td align="center" valign="middle" rowspan="<?=$rowSpan?>" style="font-size: 36px; font-weight: bold;"><?=(empty($bin)) ? '&nbsp;' : $bin?></td>
  332. <?php
  333. } elseif ($bin != $curBin) {
  334. ?>
  335. <td colspan="7">&nbsp;</td>
  336. </tr>
  337. <tr>
  338. <td align="center" valign="middle" rowspan="<?=$rowSpan?>" style="font-size: 36px; font-weight: bold;"><?=(empty($bin)) ? '&nbsp;' : $bin?></td>
  339. <?php
  340. }
  341. ?>
  342. <td valign="top" align="center">
  343. <?
  344. if ($arrProducts[$i]['cartQuantity'] > 1) echo '*';
  345. echo $arrProducts[$i]['cartQuantity'];
  346. ?>
  347. </td>
  348. <td valign="top" align="center"><?=$arrProducts[$i]['bin']?></td>
  349. <td valign="top"><?=$arrProducts[$i]['cartProdID']?></td>
  350. <td valign="top"><?=$arrProducts[$i]['cartProdName']?></td>
  351. <td valign="top">
  352. <strong><?=$arrProducts[$i]['coOptGroup']?></strong>
  353. <?=' - '.$arrProducts[$i]['optName']?>
  354. <?
  355. if ($arrProducts[$i]['optStyleID'] != "") {
  356. echo ' (' . $arrProducts[$i]['optStyleID'] . ')';
  357. }
  358. if ( $arrProducts[$i]['custom'] != "" ) { ?>
  359. <span style="margin-left:10px;"><img src="/imguploads/img_screen/<?=$arrProducts[$i]['custom']?>.gif" height="50" align="top"/></span>
  360. <? } ?> </td>
  361. <!--<td valign="top"><?=$arrProducts[$i]['cartProdPrice']?></td>-->
  362. </tr>
  363. <?php
  364. $curBin = $bin;
  365. }
  366. ?>
  367. </table>
  368. </td>
  369. </tr>
  370. </table>
  371. </td>
  372. </tr>
  373. <?php
  374. //if ($_GET['mytest']) {
  375. ?>
  376. <tr>
  377. <td colspan="3">
  378. <table width="100%" cellpadding="2" cellspacing="0" border="1" style="border-collapse: collapse;">
  379. <tr>
  380. <td colspan="4" align="center"><strong>Build List</strong></td>
  381. </tr>
  382. <tr>
  383. <td><strong>Product ID</strong></td>
  384. <td><strong>Product Name</strong></td>
  385. <td><strong>Options</strong></td>
  386. <td><strong>Bin #</strong></td>
  387. <td><strong>Quantity</strong></td>
  388. </tr>
  389. <?php
  390. $sql_build = "SELECT c.cartProdID, c.cartProdName, c.cartProdPrice, c.cartQuantity, c.cartID, p.pDownload, p.p_iscert,
  391. d.dsName, pInStock, pSell, c.cartReason, c.cartNote
  392. FROM cart c, products p LEFT JOIN dropshipper d ON p.pDropship=d.dsID
  393. WHERE c.cartProdID = p.pID
  394. AND c.cartOrderID = ". $order['ordID'];
  395. $res_build = mysql_query($sql_build) or print(mysql_error());
  396. while ($row = mysql_fetch_assoc($res_build)) {
  397. ?>
  398. <tr>
  399. <td><?=$row['cartProdID']?></td>
  400. <td><?=$row['cartProdName']?></td>
  401. <td>
  402. <?php
  403. $sql_opt = "SELECT coOptGroup, coCartOption, coPriceDiff, coOptID, optGroup, optStock, optStyleID, coExtendShipping, optBin,
  404. ui.display_image, ui.org_img_name
  405. FROM cartoptions
  406. LEFT JOIN options ON cartoptions.coOptID=options.optID
  407. LEFT JOIN uploaded_images ui ON cartoptions.coCartOption=ui.id
  408. WHERE coCartID = " . $row["cartID"] . "
  409. ORDER BY coID";
  410. $res_opt = mysql_query($sql_opt) or print(mysql_error());
  411. $binText = '';
  412. if (mysql_num_rows($res_opt) > 0) {
  413. while ($row_opt = mysql_fetch_assoc($res_opt)) {
  414. echo "<strong>".$row_opt['coOptGroup'].":</strong> " . str_replace(array("\r\n","\n"),array("<br />","<br />"),$row_opt["coCartOption"]) .' '.$row_opt["optStyleID"] . '<br />';
  415. $binText .= $row_opt['optBin'] . "<br />";
  416. }
  417. }
  418. ?>
  419. </td>
  420. <td><?=$binText?></td>
  421. <td><?=$row['cartQuantity']?></td>
  422. </tr>
  423. <?php
  424. }
  425. ?>
  426. </table>
  427. </td>
  428. </tr>
  429. <?php
  430. //}
  431. ?>
  432. <?php
  433. if ($_GET['test'] != 1) {
  434. ?>
  435. <tr>
  436. <td colspan="3">
  437. <table width="100%" cellpadding="4" cellspacing="0" style="margin: 3px;">
  438. <?php /*
  439. <?php // COMMENT - The wish list might get added later. we are commenting it out for now. ?>
  440. <tr>
  441. <td><span style="font-size: 150%; font-weight: bold;">Is Someone's Special Day Coming Up?</span><br />Search for their iFrogz Wish List! &nbsp;<span style="text-decoration: underline;">http://ifrogz.com/wishlist/findlist.php</span></td>
  442. </tr>
  443. */?>
  444. </table>
  445. </td>
  446. </tr>
  447. <?php
  448. }
  449. ?>
  450. </table>
  451. <?php
  452. }
  453. function is_special_order($order_id)
  454. {
  455. $select_query = 'SELECT
  456. ordAuthNumber as KEYCODE
  457. FROM
  458. orders
  459. WHERE
  460. ordID='.$order_id;
  461. $result = mysql_query($select_query);
  462. $result = mysql_fetch_assoc($result);
  463. return strcmp($result['KEYCODE'], 'KC-77') == 0;
  464. }
  465. function countZones($arr) {
  466. /*$ret['A'] = 0;
  467. $ret['B'] = 0;
  468. $ret['C'] = 0;
  469. $ret['D'] = 0;
  470. $ret['E'] = 0;
  471. $ret['F'] = 0;*/
  472. for ($i = 0; $i < count($arr); $i++) {
  473. //$bin = strtoupper(substr($arr[$i]['bin'], 0, 1));
  474. if(strpos($arr[$i]['bin'], '*') > -1)
  475. $bin = strtoupper(substr($arr[$i]['bin'], 2, 2));
  476. else
  477. $bin = strtoupper(substr($arr[$i]['bin'], 0, 1));
  478. $ret[$bin]++;
  479. }
  480. return $ret;
  481. }
  482. function prepBins(&$arr) {
  483. for ($i = 0; $i < count($arr); $i++) {
  484. if ($i < 2) {
  485. $arr[$i]['optBin'] = 'B-'.$i;
  486. } else {
  487. $arr[$i]['optBin'] = 'A-'.$i;
  488. }
  489. }
  490. }
  491. function addProdsToOrder($order) {
  492. $addArr = array();
  493. $sql = "SELECT IF(p.pSell=1,p.pBin,o.optBin) AS bin, p.pName AS cartProdName, a.addProdID AS cartProdID, a.addOptID AS optID, o.optName, o.optStyleID, og.optGrpName, o.optGroup, c.cartQuantity, p.p_iscert, p.pDownload, p.pWeight
  494. FROM cart c JOIN addProdsToOrder a ON c.cartProdID=a.prodID JOIN products p ON a.addProdID=p.pID LEFT JOIN options o ON a.addOptID=o.optID LEFT JOIN optiongroup og ON o.optGroup=og.optGrpID";
  495. $sql .= " WHERE c.cartOrderID = '" . $order . "'";
  496. $result = mysql_query($sql) or print(mysql_error().' ' .$sql);
  497. while ($row = mysql_fetch_assoc($result)) {
  498. $addArr = $row;
  499. if (is_array($addArr)) {
  500. checkDuplicates($row['cartProdID'],$addArr);
  501. }
  502. }
  503. }
  504. function addProdsToOrder2($order) {
  505. $arrProdsToAdd = array();
  506. $arrProds = array();
  507. // Get the products to add
  508. $sql = "SELECT *
  509. FROM cart
  510. WHERE cartOrderID = $order";
  511. $res = mysql_query($sql) or print(mysql_error());
  512. $i = 0; // Each product in cart
  513. while ($row = mysql_fetch_assoc($res)) {
  514. // Get optGroup
  515. $sql3 = "SELECT o.optGroup
  516. FROM cart c, cartoptions co, options o
  517. WHERE c.cartID = co.coCartID
  518. AND co.coOptID = o.optID
  519. AND c.cartID = " . $row['cartID'];
  520. //echo $sql3; exit();
  521. $res3 = mysql_query($sql3) or print(mysql_error());
  522. if (mysql_num_rows($res3) > 0) {
  523. while ($row3 = mysql_fetch_assoc($res3)) {
  524. $j = 0; // Each product to add for that product
  525. $sql2 = "SELECT * FROM addProdsToOrder a
  526. WHERE prodID = '".$row['cartProdID']."'
  527. AND optGrpID IN(0,".$row3['optGroup'].")";
  528. //echo $sql2."<br />";
  529. $res2 = mysql_query($sql2) or print(mysql_error());
  530. while ($row2 = mysql_fetch_assoc($res2)) {
  531. if (!is_array($arrProds[$i])) {
  532. $arrProds[$i] = array();
  533. }
  534. if (!in_array($row2['addProdID'], $arrProds[$i])) {
  535. $arrProdsToAdd[$i][$j]['addProdID'] = $row2['addProdID'];
  536. $arrProdsToAdd[$i][$j]['addOptID'] = $row2['addOptID'];
  537. $arrProdsToAdd[$i][$j]['qty'] = $row['cartQuantity'];
  538. $arrProds[$i][] = $row2['addProdID'];
  539. $j++;
  540. }
  541. }
  542. }
  543. $i++;
  544. }
  545. }
  546. //showarray($arrProdsToAdd);
  547. // Group up the quantities
  548. // Array Example:
  549. // Array
  550. // (
  551. // [ep-zip] => Array
  552. // (
  553. // [4839] => Array
  554. // (
  555. // [qty] => 2
  556. // )
  557. //
  558. // )
  559. $newProdsToAdd = array();
  560. foreach ($arrProdsToAdd as $i => $products) {
  561. foreach ($products as $j => $prod) {
  562. $newProdsToAdd[$arrProdsToAdd[$i][$j]['addProdID']][$arrProdsToAdd[$i][$j]['addOptID']]['qty'] += $arrProdsToAdd[$i][$j]['qty'];
  563. }
  564. }
  565. /*for ($i = 0; $i < count($arrProdsToAdd); $i++) {
  566. for ($j = 0; $j < count($arrProdsToAdd[$i]); $j++) {
  567. $newProdsToAdd[$arrProdsToAdd[$i][$j]['addProdID']][$arrProdsToAdd[$i][$j]['addOptID']]['qty'] += $arrProdsToAdd[$i][$j]['qty'];
  568. }
  569. }*/
  570. //showarray($newProdsToAdd);
  571. // Get the information for the products
  572. foreach ($newProdsToAdd as $prodID => $val) {
  573. foreach ($val as $optID => $val2) {
  574. $sql = "SELECT IF(p.pSell=1,p.pBin,o.optBin) AS bin, p.pName AS cartProdName, p.pID AS cartProdID, o.optID AS optID,
  575. o.optName, o.optStyleID, og.optGrpName, o.optGroup, p.p_iscert, p.pDownload, p.pWeight
  576. FROM products p, prodoptions po, optiongroup og, options o
  577. WHERE p.pID = po.poProdID
  578. AND po.poOptionGroup = og.optGrpID
  579. AND og.optGrpID = o.optGroup
  580. AND p.pID = '$prodID'
  581. AND o.optID = $optID";
  582. $res = mysql_query($sql) or print(mysql_error()."<br />".$sql."<br />");
  583. if ($res) {
  584. if (mysql_num_rows($res) > 0) {
  585. $row = mysql_fetch_assoc($res);
  586. $addArr = $row;
  587. $addArr['cartQuantity'] = $val2['qty'];
  588. if (is_array($addArr)) {
  589. checkDuplicates($row['cartProdID'],$addArr);
  590. //showarray($addArr);
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. function checkDuplicates ($pID,$addArr) {
  598. global $arrProducts,$i,$orderWeight,$reprint;
  599. //strstr('CC,CCJW,tadpoleCC,tadpoleCCW,tadpoleCCW-Custom,CC2,CCJW,o_treadzCC%,o_blfrogCC%,o_frogzCC%,CC2JU%,tadpoleCC%,bumpzCC%,ribbitzCC%',$pID)) {
  600. $duplicate = FALSE;
  601. $cnt = count($arrProducts);
  602. for ($j=0;$j<$cnt;$j++) {
  603. if ($arrProducts[$j]['cartProdID'] == $addArr['cartProdID'] && $arrProducts[$j]['optID'] == $addArr['optID']) {
  604. $arrProducts[$j]['cartQuantity'] += $addArr['cartQuantity'];
  605. $duplicate = TRUE;
  606. }
  607. }
  608. if (!$duplicate) {
  609. //IF(p.pSell=1,p.pBin,o.optBin) AS bin, SUM(c.cartQuantity) AS cartQuantity, c.cartProdID, c.cartProdName, c.cartID, o.optID, co.coOptGroup, o.optName, o.optStyleID, o.optGroup, c.cartProdPrice
  610. $arrProducts[$i]['bin'] = $addArr['bin'];
  611. $arrProducts[$i]['cartQuantity'] = $addArr['cartQuantity'];
  612. $arrProducts[$i]['cartProdID'] = $addArr['cartProdID'];
  613. $arrProducts[$i]['cartProdName'] = $addArr['cartProdName'];
  614. $arrProducts[$i]['cartID'] = '';
  615. $arrProducts[$i]['coCartOption'] = '';
  616. $arrProducts[$i]['optID'] = $addArr['optID'];
  617. $arrProducts[$i]['coOptGroup'] = $addArr['optGrpName'];
  618. $arrProducts[$i]['optName'] = $addArr['optName'];
  619. $arrProducts[$i]['optStyleID'] = $addArr['optStyleID'];
  620. $arrProducts[$i]['optGroup'] = $addArr['optGroup'];
  621. $arrProducts[$i]['cartProdPrice'] = '';
  622. $arrProducts[$i]['p_iscert'] = '';
  623. $arrProducts[$i]['pDownload'] = '';
  624. $arrProducts[$i]['pWeight'] = $addArr['pWeight'];
  625. $orderWeight += $addArr['pWeight'] * $addArr['cartQuantity'];
  626. $i++;
  627. }
  628. if (!$reprint) {
  629. //SUBTRACT INVENTORY FOR ADDED PRODUCTS
  630. if ($addArr['optID'] != "") {
  631. $sql = "SELECT * FROM options WHERE optID = " . $addArr['optID'];
  632. $res = mysql_query($sql);
  633. $options = mysql_fetch_assoc($res);
  634. $sSQL = "UPDATE options SET optStock=optStock-" . $addArr['cartQuantity'] . " WHERE optID=" . $addArr['optID'];
  635. //echo $sSQL;
  636. mysql_query($sSQL) or print(mysql_error());
  637. $sql = "SELECT p.*
  638. FROM products p
  639. JOIN prodoptions po ON p.pID = po.poProdID
  640. JOIN optiongroup og ON po.poOptionGroup = og.optGrpID
  641. JOIN options o ON og.optGrpID = o.optGroup
  642. WHERE o.optID = '".$addArr['optID']."'";
  643. $res = mysql_query($sql);
  644. $prod = mysql_fetch_assoc($res);
  645. $prodstyle = $prod["pID"] . "-" . $options['optStyleID'];
  646. $newvalue = $options['optStock'] - $addArr['cartQuantity'];
  647. // RECORD INVENTORY CHANGE
  648. $sql3 = "INSERT INTO inv_adjustments (iaOptID, iaAmt, iaDate, iaProdStyle, iaOldValue, iaNewValue, iareason, iaEmpID)
  649. VALUES (".$addArr['optID'].", -".$addArr['cartQuantity'].", '".date('Y-m-d H:i:s')."', '$prodstyle', ".$options['optStock'].", $newvalue, 10, '".$_SESSION['employee']['id']."')";
  650. $res3 = mysql_query($sql3);
  651. }
  652. }
  653. }
  654. if( is_array($_SESSION['packingsliplogin'])) {
  655. foreach($_SESSION['packingsliplogin'] as $key => $value) {
  656. $_SESSION['packingsliplogin'][$key] = '';
  657. }
  658. }
  659. ?>
  660. <? if( !$reprint) { ?>
  661. <script type="text/javascript">
  662. window.opener.reloadparent();
  663. //parent.refresh();
  664. </script>
  665. <? } ?>