<?php require('includes/head.php');
if(isset($_POST['change']))
{
	$sell_j_id=$_POST['sell_j_id'];
	$sell_j_i_id=$_POST['sell_j_i_id'];
	$code=$_POST['code'];
	$old_set=$_POST['old_set'];
	$set=$_POST['set'];
	$old_num=$_POST['old_number'];
	$num=$_POST['number'];
	$customer=$_POST['customer'];
	$price=$_POST['sell_j_i_price'];
	$new_price=$_POST['price'];
	$statement=$_POST['statement'];
	$amount=$_POST['amount'];
	$note=$_POST['note'];
	
	$new_set=$old_set-$set;
	$new_num=$old_num-$num;
	$p=$new_num*$price;
	
	$gett2=$conn->query("select * from `items` where `code`=$code ");
		$get_row2=mysqli_fetch_array($gett2);
		$num2=$get_row2['store_number'];
		$new_num=$new_num+$num2;
		
		$set2=$get_row2['store_set_number'];
		$new_set=$new_set+$set2;
	
	
	
	$oldpp=$old_num*$price;
	$newpp=$num*$new_price;
	
	$p=$oldpp-$newpp;
	
	$s=$statement-$p;
	$a=$amount-$p;
	
	
$conn->query("update `customer` set `statement`='$s' where customer_id=$customer");
	$conn->query("update `sell_j` set `amount`='$a'  where sell_j_id=$sell_j_id");
	$conn->query("update `items` set `store_set_number`='$new_set' , `store_number`='$new_num' where `code`='$code'");
	$conn->query("update `sell_j_item` set `sell_j_i_set`='$set' , `sell_j_i_number`='$num' , `sell_j_i_note`='$note', `sell_j_i_price`='$new_price' where `sell_j_i_id`='$sell_j_i_id'");
	echo "<script type='text/javascript'>window.location.href = 'sell_j_edit.php?sell_j_id=$sell_j_id'</script>";
	
	
}
$id=$_GET['sell_j_id'];
$get="select * from `sell_j`,`customer` where `customer_id`=`sell_j_customer` and `sell_j_id`=$id";
$get_r=$conn->query($get);
$get_row=mysqli_fetch_array($get_r);
$type=$get_row['type'];
$c_id=$get_row['customer_id'];
$statement=$get_row['statement'];
$amount=$get_row['amount'];
?>
<html>
	<head>
		<style>
		@media print {body {-webkit-print-color-adjust: exact;}}
		</style>
	</head>
	<body>
		<div style="width:1150px;font-family:'nrt';"  id="right">
			<table dir=rtl id="mydiv" height="" width="100%" border=0 style="vertical-align:middle">
				<tr>
					<td >
						<center>
						<img width=100px src="icon/hermes.png">
						</center>
					</td>
					<th style="font-size:50px; color:red" width=85px>Polo</th>
					<td width=50px><img width=50px src="icon/logo2.png"></td>
					<th style="font-size:50px; color:red"width=95px >Aras</th>
					<td >
						<center>
						<img width=100px src="icon/lacoste.png">
						</center>
					</td>
					
				
				</tr>
				<tr>
					<td >
						<center>
						<img width=100px src="icon/prada.png">
						</center>
					</td>
					<th  colspan=3 style="font-size:18px; background-color:skyblue"><br>بۆ فرۆشتنی جلوبەرگی پیاوان بە کۆ<br><br>هەولێر/ بازاڕی داون تاون نهۆمی خوارەوە</th>
					<td >
						<center>
						<img width=100px src="icon/armani.png">
						</center>
					</td>
				
				</tr>
				</table>
				
				
				<table width=100%>
				<tr>
					<th colspan=3>
						<hr>
						ژمارە<?php echo "(".$id.")  ".$get_row['sell_j_date'];?>
					</th>
				</tr>
			</table>
			<table dir=rtl id="mydiv" height="" width="750px" border=0 style="font-size:16pt">
				<tr style="text-align:right" bgcolor="#f0f0f0">
					<th width=350px>کڕیار(<?php echo $get_row['customer_name'];?>)</th>
					<th  width=200px><?php echo $get_row['customer_address'];?></th>
					<th  width=200px><?php echo $get_row['customer_mobile'];?></th>
				</tr>
			</table>
			
			<br>	
			<table id='mydiv' width='1050px' dir=rtl align="right">					
				<tr bgcolor="lightblue">
					<td></td>
					<td>کۆد</td><td>ژمارەی سێت</td><td>ژمارە</td>
					<td></td>
					
				</tr>
				<?php 
				$count=1;
				$sum=0;
				$gett=$conn->query("select * from `sell_j_item`,`items` where `sell_j_i_code`=`code` and `sell_j`=$id ");
				while($get_row=mysqli_fetch_array($gett)){ ?>
				<tr><form action="" method="post">
					<input type="hidden" name="sell_j_id" value=<?php echo $id;?>>
					<input type="hidden" name="customer" value=<?php echo $c_id;?>>
					<input type="hidden" name="amount" value=<?php echo $amount;?>>
					<input type="hidden" name="statement" value=<?php echo $statement;?>>
					<input type="hidden" name="code" value=<?php echo $get_row['sell_j_i_code'];?>>
					<input type="hidden" name="sell_j_i_id" value=<?php echo $get_row['sell_j_i_id'];?>>
					<input type="hidden" name="sell_j_i_price" value=<?php echo $get_row['sell_j_i_price'];?>>
					<input type="hidden" name="old_set" value=<?php echo $get_row['sell_j_i_set'];?>>
					<input type="hidden" name="old_number" value="<?php echo $get_row['sell_j_i_number'];?>">
					<td><?php echo $count; $count++;?></td>
					<td><?php echo $get_row['sell_j_i_code'];?> - <?php echo $get_row['name'];?></td>
					<td><input type="number" name="set" value="<?php echo $get_row['sell_j_i_set'];?>"></td>
					<td><input type="number" name="number" value="<?php echo $get_row['sell_j_i_number'];?>"></td>
					<td><input type="number" name="price" step="any" value="<?php echo $get_row['sell_j_i_price'];?>"></td>
					<td><input type="text" name="note" value="<?php echo $get_row['sell_j_i_note'];?>"></td>
					<td><input type="submit" name="change" value="گۆڕین"></td>
					
					
					</form>
				</tr>
				<?php }?>
				
			</table>
			<br><br><br><br><br>
			
			<br><br><br>
			<table width=100%>
				<tr>
					<th>واژووی ژمێریار</th>
				</tr>
			</table>
			<br><br>
			<table width=100%>
				<tr style="font-size:10pt" bgcolor="#f0f0f0">
					<th width=60%>07504529902 - 07504686054</th>
					<th width=40%>info@araspolo.com</th>
				</tr>
			</table>
		</div>
	</body>
</html>


