Jump to content

Archived

This topic is now archived and is closed to further replies.

herbacious

hard to explain in a title - a little guidance please

Recommended Posts

hi people :-)

i am new to this forum, i have been fiddling with php for nearly a year, recently it has all started to fall into place and i am currently working out a stock system for the company i work for..

i am trying to create a little script that will go through all of our orders and let us know which ones are fully ready for despatch...

basically the script will grab all the orders at a specific status, then grab all the products for each order - then it will first check for a reservation, then it will check for free stock

if any of the products are not able to go - i want the order to be set to processing,

if all of the items on an order can go, i want the order to be set to ready for despatch

the thing i am struggling with is the final bit =- have a look at the code and you should see what i mean..

[code]
case post_process_change_status :
$status_id = $_GET['status_id'];
if(isset($status_id)){
$result = tep_db_query("select orders_id, customers_name from orders where orders_status =  " . $status_id . "");
$num = mysql_numrows($result);
$i=0;
while ($i < $num) {
$orders_id = mysql_result($result, $i, "orders_id");
$customers_name= mysql_result($result, $i, "customers_name");
$orders_products_query = tep_db_query("select products_id, products_model, products_quantity from orders_products where orders_id = " . $orders_id . "");
$num_products = mysql_numrows($orders_products_query);
$i_products=0;
echo '<br><hr><br><h1>Order Status Update Result</h1>';
while($i_products < $num_products) {
$products_id = mysql_result($orders_products_query, $i_products, "products_id");
$products_model = mysql_result($orders_products_query, $i_products, "products_model");
$products_quantity = mysql_result($orders_products_query, $i_products, "products_quantity");
$stock_query = tep_db_query("select shop_stock, wh_stock, reservations from products_stockdb where products_stockdb.products_id = " . $products_id . "");
$stock = tep_db_fetch_array($stock_query);
static $NOT_READY_FOR_DESPATCH = 0; //IS THIS A GOOD IDEA?..
if (stristr($stock['reservations'], $orders_id)){
echo '<br><b>Reservation Found for ' . $products_model . '</b><br>';
} else if (($stock['shop_stock'] + $stock['wh_stock']) >= $products_quantity) {
echo '<br><b>Free Stock Found for ' . $products_model . '</b><br>';
} else {
echo '<br><b>This One isnt ready yet:  ' . $products_model . '</b><br>';
$NOT_READY_FOR_DESPATCH++; // The idea i had here was that if the var is greater than zero, the order is not ready for despatch.. however it isn't working as i had hoped.. and maybe this isn't the best / easiest way to achieve this goal...
}
$i_products++;
}

if($NOT_READY_FOR_DESPATCH >= 1){
echo '<h2>Order #' . $orders_id . ' Is Not Ready To Go - Setting to Processing</h2>';
echo '<br><br><b><a href="orders.php?oID=' . $orders_id . '&action=edit">CLICK HERE - Go To Order</a></b><br><br>';
tep_db_query("update orders set orders_status = 1000 where orders_id = " . $orders_id . "");
tep_db_query("insert into orders_status_history set orders_id = '" . $orders_id . "', orders_status_id = 1000, date_added = NOW(), customer_notified = '0', comments = 'Auto Setting to Processing'");//Add Comments to Order Sheet
}else{
echo '<h2>Order #' . $orders_id . ' Is Ready To Go - Please Choose Mail or Courier</h2>';
echo '<br><br><b><a href="orders.php?oID=' . $orders_id . '&action=edit">CLICK HERE - Go To Order and Choose Despatch Method</a></b><br><br>';
tep_db_query("update orders set orders_status = 9999 where orders_id = " . $orders_id . "");
tep_db_query("insert into orders_status_history set orders_id = '" . $orders_id . "', orders_status_id = 9999, date_added = NOW(), customer_notified = '0', comments = 'Auto Setting to Ready For Despatch, needs despatch method choosing manually'");//Add Comments to Order Sheet
}
$i++;
}
} else {
echo '<form><input name="action" value="post_process_change_status" type="hidden">';
  $query_status = "SELECT * FROM `orders_status` WHERE language_id = $languages_id";
  $status_result = tep_db_query($query_status);
                echo OL_SELECT_STATUS . "&nbsp;";
                echo "<select name=\"status_id\">";
                echo "<option value=></option>";
  while ($row3 = tep_db_fetch_array($status_result))
                {
                echo "<option value=";
                echo $row3['orders_status_id'];
                echo ">";
                echo $row3['orders_status_name'];
                echo "</option><br>";
                }
                echo "</select>";
echo '<br><button value="submit">SET THE STATUS ON THESE ORDERS</button></form>';
}
break;
[/code]

many thanks in advance for constructive criticism and guidance :-)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.