<?php
require('includes/head.php');
if(isset($_POST['submit']))
{
	$c2=$_POST['customer'];
	$n=$_POST['note'];
	$d=$_POST['d'];
	$a=$_POST['amount'];
	
	$add="INSERT INTO `get2`(`get_customer`, `get_date`, `note`, `amount`) 
	VALUES ('$c2','$d','$n','$a')";
	$conn->query($add);
	echo "<script type='text/javascript'>window.location.href = 'get2.php'</script>";	
	
}


if(isset($_GET['t_id']))
{
	$t_id=$_GET['t_id'];
   
	
	$del2="delete from  `get2` where `get_id`=$t_id";
	$conn->query($del2);
	echo "<script type='text/javascript'>window.location.href = 'get2.php'</script>";	
	
}
if(isset($_GET['done_id']))
{
	$t_id=$_GET['done_id'];
	$c_id=$_GET['c_id'];
	$c_date=$_GET['c_date'];
	
	$up="update `get2` set status=1 where `get_id`=$t_id";
	$conn->query($up);
	
	$conn->query("INSERT INTO `sell_j_inv2`( `inv_type`, `inv_code`, `customer`, `date`, `user`) 
										VALUES ('get',$t_id,'$c_id','$c_date','$login_user')");
	echo "<script type='text/javascript'>window.location.href = 'get2.php'</script>";	
	
}
$c="select * from `customer2` where active=1";
$c_r=$conn->query($c);


$check="select * from `get`,`customer2` where `get_customer`=`customer_id` and `status`=0";
$check_r=$conn->query($check);
?>
<h3>پارەوەرگرتن</h3><hr>
<?php if($check_row=mysqli_fetch_array($check_r))
{ $c_id=$check_row['customer_id'];
$c_date=$check_row['get_date'];?>
	<table width="70%" border=1>
			<tr>
				<th>کڕیار: <?php echo $check_row['customer_name'];?></th>
				<th>بڕی: <?php echo $check_row['amount']."$ /".$check_row['note'];?></th>
				<th><a href="get2.php?t_id=<?php echo $check_row['get_id'];?>"><img src="icon/delete.png" width=20px></a></th>
			
				<th><a href="get2.php?done_id=<?php echo $check_row['get_id'];?>&&c_id=<?php echo $c_id;?>&&c_date=<?php echo $c_date;?>"><img src="icon/done.png" width=20px></a></th>
			</tr>
	</table>
	
	
	
<?php }
else{ ?>
        <form action="" method="post">
		<table>
			<tr>
				<th>کڕیارەکان</th>
			</tr>
			<tr>
				<td>
					<select name="customer" required>
							<option value=""></option>
							<?php while($row2=mysqli_fetch_array($c_r)){ ?>
						<option value="<?php echo $row2['customer_id'];?>"><?php echo $row2['customer_name'];?></option>
						 <?php }?>
					</select>
				</td>
				<td>
					<input type="text" name="note" placeholder="Note">
				</td>
				<td>
					<input step="any" type="number" name="amount" placeholder="بڕی پارە">
				</td>
				<td><input type="date" name="d" value="<?php echo date("Y-m-d");?>" required></td>

			

				<td><input type="submit" name="submit" value="واصلکردن"></td>
			</tr>
			</table>
        </form>
<?php } ?>
</div>
</div>


<table border=1 dir=rtl width=80% align="center" style="font-size:18pt">
<tr bgcolor="lightblue">
				<th>فرۆشیار</th>
				<th>ڕێکەوت</th>
				<th>بڕی پارە</th>
				<th></th>
			</tr>
<?php
$check2="select * from `get2`,`customer2` where `get2`.`get_customer`=`customer2`.`customer_id` and `status`=1 order by `get_date` desc";
$check_r2=$conn->query($check2);
while($row2=mysqli_fetch_array($check_r2)){
?>
			<tr>
				<td><?php echo $row2['customer_name'];?></td>
				<td><?php echo $row2['get_date'];?></td>
				<td><?php echo $row2['amount'];?></td>
				<td><?php echo $row2['note'];?></td>
				<th><a href="pay_print_get2.php?id=<?php echo $row2['get_id'];?>"><img src="icon/print.png" width=30px></a></th>
				<th><a onclick='return confirm("دڵنیای لە سڕینەوەی ئەم پسووڵەیە؟؟؟؟");' href="inv_del.php?get_id2=<?php echo $row2['get_id'];?>"><img src="icon/delete.png" width=30px></a></th>
			
			</tr>
<?php }?>
</table>  
<div id="footer">
<span>By : H Group</span>
</div>

</div>

</div>



</body>
</html>