<?php
require('includes/head.php');
if(isset($_POST['submit']))
{
	$c=$_POST['company'];
	$d=$_POST['d'];
	$a=$_POST['amount'];
	
	$add="INSERT INTO `company_inv`( `company`, `amount`, `inv_type`, `date`)
	VALUES ('$c','$a','g','$d')";
	$conn->query($add);
	echo "<script type='text/javascript'>window.location.href = 'company_get.php'</script>";	
	
}


if(isset($_GET['t_id']))
{
	$t_id=$_GET['t_id'];
   
	
	$del2="delete from  `company_inv` where `company_inv_id`=$t_id";
	$conn->query($del2);
	echo "<script type='text/javascript'>window.location.href = 'company_get.php'</script>";	
	
}
if(isset($_GET['done_id']))
{
	$t_id=$_GET['done_id'];
	
	$up="update `company_inv` set status=1 where `company_inv_id`=$t_id";
	$conn->query($up);
	
	
	echo "<script type='text/javascript'>window.location.href = 'company_get.php'</script>";	
	
}
$c="select * from `company` ";
$c_r=$conn->query($c);


$check="select * from `company_inv`,`company` where `company`=`company_id` and `status`=0";
$check_r=$conn->query($check);
?>
<div class="container">
          <div class="page-inner">
            <div class="page-header">
              <h3 class="fw-bold mb-3">ڕاکێشانی پارە</h3>
              <ul class="breadcrumbs mb-3">
                <li class="nav-home">
                  <a href="#">
                    <i class="icon-home"></i>
                  </a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
              </ul>
            </div>
			
			<div class="row">
              <div class="col-md-12">
                <div class="card">
                  <div class="card-header">
                    <div class="card-title"></div>
                  </div>
<?php if($check_row=mysqli_fetch_array($check_r))
{ $c_id=$check_row['company_id'];
$c_date=$check_row['date'];?>
	<table
                        id="basic-datatables"
                        class="display table table-striped table-hover"
                      >
			<tr>
				<th style="background-color:#d6ebff; font-size:16pt" >کۆمپانیا: <?php echo $check_row['company_name'];?></th>
				<th style="background-color:#d6ebff; font-size:16pt" >بڕی: <?php echo $check_row['amount']."$ /".$check_row['date'];?></th>
				<th style="background-color:#d6ebff; font-size:16pt" ><a href="company_get.php?t_id=<?php echo $check_row['company_inv_id'];?>"><img src="icon/delete.png" width=20px></a></th>
			
				<th style="background-color:#d6ebff; font-size:16pt" ><a href="company_get.php?done_id=<?php echo $check_row['company_inv_id'];?>"><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="company" required class="form-select">
							<option value=""></option>
							<?php while($row2=mysqli_fetch_array($c_r)){ ?>
						<option value="<?php echo $row2['company_id'];?>"><?php echo $row2['company_name'];?></option>
						 <?php }?>
					</select>
				</td>
				<td>
					<input step="any" type="number" name="amount" placeholder="بڕی پارە" class="form-control">
				</td>
				<td><input type="date" name="d" value="<?php echo date("Y-m-d");?>" required class="form-control"></td>

			

				<td><input type="submit" name="submit" value="ڕاکێشان"class="form-control"></td>
			</tr>
			</table>
        </form>
<?php } ?>
</div>
</div>
</div>


<div class="row">
              <div class="col-md-12">
                <div class="card">
                  
                  <div class="card-body">
                    <div class="table-responsive">
                      <table
                        id="basic-datatables"
                        class="display table table-striped table-hover"
                      >
<tr bgcolor="lightblue">
				<th>کۆمپانیا</th>
				<th>ڕێکەوت</th>
				<th>بڕی پارە</th>
				<th></th>
			</tr>
<?php
$check2="select * from `company_inv`,`company` where `company`=`company_id` and `status`=1 and `inv_type`='g' order by `date` desc";
$check_r2=$conn->query($check2);
while($row2=mysqli_fetch_array($check_r2)){
?>
			<tr>
				<td><?php echo $row2['company_name'];?></td>
				<td><?php echo $row2['date'];?></td>
				<td><?php echo $row2['amount'];?></td>
				<th><a onclick='return confirm("دڵنیای لە سڕینەوەی ئەم پسووڵەیە؟؟؟؟");' href="company_get.php?t_id=<?php echo $row2['company_inv_id'];?>"><img src="icon/delete.png" width=30px></a></th>
			
			</tr>
<?php }?>
</table>  
</div>
                  </div>
                </div>
              </div>
			  
			  </div>
          </div>
        </div>
<?php require'includes/foot.php';?>