0

Hi,

Im struggling to do a function like this.In the admin panel of my site,there is an option for the admin to select multiple orders using check boxes and marked them as accepted.And I need to update the product table at the same time according to the product quantities of the selected orders.How should I make this thing happen??
Do I need to put a for loop / a while loop to take the product Ids which need to be update??

Im so glad if some one help me to do this...Please..:)

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by ﻼim
0

i hope this helps. ;)

$id=base64_decode($_GET['id']); //get the receipt ID and decode to base64
$check = 0;
	//ADMIN
	if($username == 'admin' && $password == $pass && $id != 0)
	{
		$query3=mysql_query("SELECT * from tbl_customer_order where receipt = $id");
		while($order2=mysql_fetch_object($query3))
		{
			$oquan=$order2->order_quantity;
			$oname=$order2->order_name;
			$obar=$order2->order_barcode;
			$query4=mysql_query("SELECT * from tbl_inventory where item_barcode = $obar");
			$item2=mysql_fetch_object($query4);
			$quantity=$item2->item_quantity;
			
			if($quantity < $oquan)
			{
				echo "<script type='text/javascript'>window.alert('$oname is at Low Quantity!')</script>";
				$check = 1;
				break;
			}
		}
		
		if($check == 0)
		{
			$date=date("M-d-Y");
		
			$query=mysql_query("SELECT * from tbl_item_order where receipt = $id"); //select the order
			$order=mysql_fetch_object($query);
			$quantity=$order->order_quantity;
			$price=$order->order_price;
			$customer=$order->customer_name;
		
			$query1=mysql_query("SELECT * from tbl_customer_order where receipt = $id"); //select the order
			while($order1=mysql_fetch_object($query1))//get the date from the query
			{		
				
				
				$cname=$order1->order_name;
				$cquan=$order1->order_quantity;
				$cprice=$order1->order_price;
				$ccat=$order1->order_category;
				$cbar=$order1->order_barcode;
				
				$query2=mysql_query("SELECT * from tbl_inventory where item_barcode = $cbar"); //select the item from inventory
				$item=mysql_fetch_object($query2);
				$idesc=$item->item_description;
				$isup=$item->item_supplier;
				$iprice=$item->item_sales_price;
				$iquan=$item->item_quantity;
				$isold=$item->item_sold;
				$isupprice=$item->item_supplier_price;
				$isalprice=$item->item_sales_price;
				$iiprice=$isalprice-$isupprice;
				$iprofit=$item->item_profit;
				
				$newquan=$iquan-$cquan;
				$newsold=$isold+$cquan;
				$newprofit=$iprofit+($iiprice*$cquan);
				
				mysql_query("UPDATE tbl_inventory set item_quantity = $newquan, item_sold = $newsold, item_profit = $newprofit where item_barcode = $cbar");			
				mysql_query("INSERT into tbl_delivered_item values(null, '$cname', '$idesc', $cbar, '$isup', $iprice, $price, $cquan, '$date', '$ccat', $id)"); //accepted order.insert all the items into the table tbl_delivered_item
			}		
		
	
			mysql_query("INSERT into tbl_accept_order values(null, $id, '$customer', '$date', $price, $quantity, '$username')"); //accepted order.insert data into the table tbl_accepted_order
			$query3=mysql_query("Select * from tbl_users where username='$customer'"); //update the table tbl_users
			$user=mysql_fetch_object($query3);
			$uquan=$user->quantity;
			$unum=$user->num_order;
			$uincome=$user->total_income;
			
			$newquan=$uquan+$quantity; //new quantity of orders in tbl_users
			$newnum=$unum+1; //new number of times ordered in tbl_users
			$newincome=$uincome+$price; //new total income in tbl_users
			
			mysql_query("UPDATE tbl_users set quantity=$newquan, num_order=$newnum, total_income=$newincome where username = '$customer'");
			mysql_query("UPDATE tbl_customer_order set paid = 1 where receipt = $id");
			mysql_query("UPDATE tbl_item_order set paid = 1 where receipt = $id");
		
			echo "<script type='text/javascript'>window.alert('Order Accepted!')</script>";
			echo "<META http-equiv='refresh' content='0;URL=orderitems.php'>";
		}
		
		else
		{
			echo "<META http-equiv='refresh' content='0;URL=orderitems.php'>";
		}
	}

goodLuck!

0

Thanks for your code..But it is still not worked..:(

would you mind showing your code for debugging?
thanks. Ϋ

Edited by ﻼim: missing letter &quot;r&quot; .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.