<?php include('connection/conn.php');
$id=$_GET['sell_j_id'];

$bef="select `inv_id` from `sell_j_inv` where `inv_code`=$id";
$bef_r=$conn->query($bef);
$bef_row=mysqli_fetch_array($bef_r);
$bef_id=$bef_row['inv_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'];
$payed=$get_row['payed'];
$currency=$get_row['currency'];
$c_id=$get_row['customer_id'];
?>
<!DOCTYPE html>
<html lang="ku" dir="rtl">
<head>
  <meta charset="UTF-8">
  <title>AR Invoice</title>

  <style>
body {
 font-family: 'Tajawal', sans-serif;

  background: linear-gradient(to right, #eef4ff, #f9fcff);
  padding: 10px;
}

.invoice {
  width: 900px;
  background: white;
  padding: 5px;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

/* HEADER BANNER */
.header-banner {
  background: linear-gradient(135deg, #1e88e5, #00b0ff);
  color: white;
  padding: 10px;
  border-radius: 12px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left, .header-right {
  width: 35%;
  font-size: 14px;
}

.header-center {
  text-align: center;
}

.logo-center {
  width: 90px;
}

.header-line {
  border-top: 2px dashed white;
  
}

.header-contacts {
  display: flex;
  justify-content: space-around;
  background: rgba(255,255,255,0.15);
  padding: 8px;
  border-radius: 8px;
  font-weight: bold;
}

/* TABLES */
.info, .items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
}

.info td {
  background: #f5f9ff;
  padding: 10px;
  border-radius: 6px;
}

.items th {
  background: #1e88e5;
  color: white;
  padding: 10px;
}

.items td {
  background: #fafafa;
  border-bottom: 1px solid #ddd;
  padding: 8px;
}

.items tr:hover td {
  background: #e1f0ff;
  transition: 0.3s;
}

/* INPUT */
input {
  border: none;
  background: transparent;
  width: 100%;
  text-align: center;
  font-weight: 500;
  outline: none;
}

/* BOTTOM */
.bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  
}

.warning {
  width: 50%;
  background: #fff3f3;
  border-left: 6px solid red;
  padding: 12px;
  border-radius: 10px;
  height:210px;
}

.warning h3 {
  color: red;
  margin-bottom: 4px;
}

.totals {
  width: 40%;
  background: linear-gradient(135deg, #f7fbff, #e3f2fd);
  border-radius: 12px;
  padding: 0px 15px;
   height:210px;
}

.totals h3 {
  background: #1e88e5;
  color: white;
  padding: 8px;
  border-radius: 8px;
  text-align: center;
}

.totals div {
  display: flex;
  justify-content: space-between;
  margin: 3px 0;
  font-weight: 500;
}

.sum {
  background: #bbdefb;
  padding: 8px;
  border-radius: 6px;
  font-weight: bold;
}

.remain {
  background: #1976d2;
  color: white;
  padding: 8px;
  border-radius: 6px;
}

/* PRINT */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

@media print {
  body {
    background: white !important;
    padding: 0;
  }

  .invoice {
    width: 96%;
	margin-right:4%;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .header-banner {
    background: linear-gradient(135deg, #1e88e5, #00b0ff) !important;
    color: white !important;
  }

  .items th {
    background: #1e88e5 !important;
    color: white !important;
  }

  .totals h3 {
    background: #1e88e5 !important;
    color: white !important;
  }

  .sum {
    background: #bbdefb !important;
  }

  .remain {
    background: #1976d2 !important;
    color: white !important;
  }

  .warning {
    background: #fff3f3 !important;
    border-left: 6px solid red !important;
  }
}

  </style>
</head>


<body>

<div class="invoice">
	<!-- HEADER -->
	<div class="header-banner">
		<table width=100%>
			<tr>
				<th ><h2 style="color:yellow">البسة اراس پولو</h2><p style="font-size:10pt">بيع الألبسة الرجالية بالجملة</p><small style="font-size:8pt">أربيل - سوق داون تاون تابق تحت الأرضي -H25</small></th>
				<th width=20%><div class="header-center"><img  src="icon/logo2.png" height=100px></div></th>
				<th><h2 style="color:yellow">پۆشاکی ئاراس پۆلۆ</h2><p style="font-size:10pt">فرۆشتنی جل و بەرگی پیاوان بە کۆ</p><small style="font-size:8pt">هەولێر - بازاڕی داون تاون، ژێر زەوی - H25</small></th>
				<th><div class="header-center"><img  src="icon/qr.jpg" height=90px></div></th>
			</tr>
			
		</table>
		<div class="header-line"></div>
		<div class="header-contacts">
			<span style="background-color:; padding:7px 40px; border-radius:7%; font-size:10pt; border: 2px solid yellow; ">  6054 468 0750 ئارین</span>
			<span style="background-color:; padding:7px 40px; border-radius:7%; font-size:10pt; border: 2px solid yellow; ">5352 452 0750 ئارام</span>
		</div>
	</div>
	
	
	
	 <!-- CLIENT INFO -->
  <table class="info">
    <tr>
		<td>ناوی کڕیار/اسم الزبون: </td><td><span style="background-color:white; padding:3px 30px; border-radius:7%; font-size:10pt; border: 2px solid black; "> <?php echo $get_row['customer_name'];?></span></td>
		<td>ژمارەی پسووڵە/رقم الفاتورة : </td><td><span style="background-color:white; padding:3px 30px; border-radius:7%; font-size:10pt; border: 2px solid black; "><?php echo $id;?></span></td>
		
	</tr>
	
	<tr>	  
		<td> العنوان : </td><td><span style="background-color:white; padding:3px 80px; border-radius:7%; font-size:10pt; border: 2px solid black; "><?php echo $get_row['customer_address'];?></span> </td>
		<td>التاريخ : </td><td><span style="background-color:white; padding:3px 10px; border-radius:7%; font-size:10pt; border: 2px solid black; "><?php echo $get_row['sell_j_date'];?></span>   </td>
    </tr>
	<tr>	  
		<td> موبایل : </td><td><span style="background-color:white; padding:3px 80px; border-radius:7%; font-size:10pt; border: 2px solid black; "><?php echo $get_row['customer_mobile'];?></span> </td>
		<td </td><td>  </td>
    </tr>
  </table>
  
  
  <!-- ITEMS -->
  <table class="items" height=325px style="font-size:10pt">
    <thead>
      <tr>
        <th>#</th>
        <th>كود المادة / کۆدی بابەت</th>
        <th>ژمارەی سێت</th>
        <th>ژمارە</th>
        <th>نرخ/سعر</th>
        <th>تۆتاڵ / المجموع</th>
      </tr>
    </thead>
    <tbody>
						
			
			
				<?php 
				$count=1;
				$sum=0;
				$gett=$conn->query("select * from `sell_j_item`,`items` where `sell_j_i_code`=`code` and `sell_j`=$id ");
				$num12=mysqli_num_rows($gett);
				while($get_row=mysqli_fetch_array($gett)){ 
				if($num12<=6)
				{?>
				 <tr style="height:50px">
					<td><?php echo $count; $count++;?></td>
					<td><?php echo $get_row['sell_j_i_code'];?> - <?php echo $get_row['name'];?> <span style="color:red">(<?php echo $n=$get_row['sell_j_i_set'];?>سێت = <?php echo $n=$get_row['sell_j_i_number'];?> عدد)</span><br><?php echo $get_row['sell_j_i_note'];?></td>
					<td style="text-align:center"><?php echo $n=$get_row['sell_j_i_set'];?></td><td style="text-align:center"><?php echo $n=$get_row['sell_j_i_number'];?></td>
					<td style="text-align:center"><?php echo number_format($p=$get_row['sell_j_i_price'],2);?>$</td>
					
					<td style="text-align:center"><?php echo number_format($t=$p*$n,2); $sum+=$t;?>$</td>
				</tr>
				<?php 
				}
				elseif($num12<=9)
				{?>
				 <tr style="height:32px; font-size:9pt">
					<td><?php echo $count; $count++;?></td>
					<td><?php echo $get_row['sell_j_i_code'];?> - <?php echo $get_row['name'];?> <span style="color:red">(<?php echo $n=$get_row['sell_j_i_set'];?>سێت = <?php echo $n=$get_row['sell_j_i_number'];?> عدد)</span><br><?php echo $get_row['sell_j_i_note'];?></td>
					<td style="text-align:center"><?php echo $n=$get_row['sell_j_i_set'];?></td><td style="text-align:center"><?php echo $n=$get_row['sell_j_i_number'];?></td>
					<td style="text-align:center"><?php echo number_format($p=$get_row['sell_j_i_price'],2);?>$</td>
					
					<td style="text-align:center"><?php echo number_format($t=$p*$n,2); $sum+=$t;?>$</td>
				</tr>
				<?php 
				}
				elseif($num12<=11)
				{?>
				 <tr style="height:20px; font-size:7pt">
					<td><?php echo $count; $count++;?></td>
					<td><?php echo $get_row['sell_j_i_code'];?> - <?php echo $get_row['name'];?> <span style="color:red">(<?php echo $n=$get_row['sell_j_i_set'];?>سێت = <?php echo $n=$get_row['sell_j_i_number'];?> عدد)</span><br><?php echo $get_row['sell_j_i_note'];?></td>
					<td style="text-align:center"><?php echo $n=$get_row['sell_j_i_set'];?></td><td style="text-align:center"><?php echo $n=$get_row['sell_j_i_number'];?></td>
					<td style="text-align:center"><?php echo number_format($p=$get_row['sell_j_i_price'],2);?>$</td>
					
					<td style="text-align:center"><?php echo number_format($t=$p*$n,2); $sum+=$t;?>$</td>
				</tr>
				<?php 
				}
				else
				{?>
				 <tr style="height:20px; font-size:6pt">
					<td><?php echo $count; $count++;?></td>
					<td><?php echo $get_row['sell_j_i_code'];?> - <?php echo $get_row['name'];?> <span style="color:red">(<?php echo $n=$get_row['sell_j_i_set'];?>سێت = <?php echo $n=$get_row['sell_j_i_number'];?> عدد)</span><br><?php echo $get_row['sell_j_i_note'];?></td>
					<td style="text-align:center"><?php echo $n=$get_row['sell_j_i_set'];?></td><td style="text-align:center"><?php echo $n=$get_row['sell_j_i_number'];?></td>
					<td style="text-align:center"><?php echo number_format($p=$get_row['sell_j_i_price'],2);?>$</td>
					
					<td style="text-align:center"><?php echo number_format($t=$p*$n,2); $sum+=$t;?>$</td>
				</tr>
				<?php 
				}
				
				
				}?>
				<tr bgcolor="lightgrey">
					<td></td>
					<td colspan=3></td>
					<td style="text-align:center"> کۆی گشتی</td>
					<td style="text-align:center"><?php echo number_format($sum,2);?>$</td>
				</tr>
				
			<tr><th style="background-color:white; " colspan=6>
			<?php if($payed==0){?><h1 style="text-align:center; color:red">غیر واصل</h1> <?php } ?>
			</th>
			</tr>
	</tbody>
  </table>		
<?php			
		


$get10="select * from `customer` where  `customer_id`=$c_id";
$get_r10=$conn->query($get10);
$get_row10=mysqli_fetch_array($get_r10);



				$count=1;
				
			
				
				$get2="select * from `sell_j_inv` where  `customer`=$c_id  and `inv_id` < $bef_id";
				$get_r2=$conn->query($get2);
				$sum100=0;
				$sum_w100=0;
				$sum_t100=0;
				while($get_row2=mysqli_fetch_array($get_r2))
				{ 
				if($count%2==0) $col="#f9f9f9"; else $col="white"; 
				$count++;
					$type=$get_row2['inv_type'];
					$code=$get_row2['inv_code'];
					if($type=="sell")
					{
						$transfer="select * from `sell_j` where `sell_j_id`=$code";
						$transfer_r=$conn->query($transfer);
						$transfer_row=mysqli_fetch_array($transfer_r);
						$sell_j=$transfer_row['sell_j_id'];
					
								$p="select sum(`sell_j_i_number`*`sell_j_i_price`) as `t` from `sell_j_item` where `sell_j`='$sell_j'";
								$p_r=$conn->query($p);
								$p_row=mysqli_fetch_array($p_r);
							 $sum100+=$p_row['t'];
					}
					elseif($type=="get")
					{
						$get="select * from `get` where `get_id`=$code";
						$get_r=$conn->query($get);
						$get_row=mysqli_fetch_array($get_r);
					
						$p=$get_row['amount']; $sum100-=$p;
							
					
					}
					
					
				
					
				
					
				}?>
				


		
			<!-- BOTTOM -->
  <div class="bottom">
    <div class="warning">
      <h3>تێبینی / تحذير</h3>
      <p>
        تکایە دڵنیابە لە کاڵاکانت پێش ڕۆیشتن لە دوکان<br>
        يرجى فحص البضاعة قبل المغادرة
      </p>
    </div>

    <div class="totals">
      <h3>حسابات</h3>
      <div>حساب الفاتورة/پسوولەی ئێستا <span><?php echo $currency." ".number_format($sum,2);?></span></div>
      <div>الحساب القديم/قەرزی کۆن <span><?php echo $currency." ".number_format($sum100,2);?></span></div>
      <div class="sum">جمع الحساب/کۆی گشتی <span><?php echo $currency." ".number_format($sum+$sum100,2);?></span></div>
      <div>واصل/واسلکراو <span><?php echo $currency." ".number_format($payed,2);?></span></div>
      <div class="remain">باقي/باقی قەرز <span><?php echo $currency." ".number_format($sum+$sum100-$payed,2);?></span></div>
    </div>
  </div>

</div>

</body>
</html>


