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

$get="select * from `customer` where  `customer_id`=$id";
$get_r=$conn->query($get);
$get_row=mysqli_fetch_array($get_r);

$name=$get_row['customer_name'];
$mob=$get_row['customer_mobile'];
$add=$get_row['customer_address'];
$currency=$get_row['currency'];

?>
<html>
	<head>
		<style>
		@media print {body {-webkit-print-color-adjust: exact;}}
		</style>
	</head>
	<body style="font-family: nrt;">
		<div style="width:750px"  id="right">
			<table dir=rtl id="mydiv" height="" width="100%" border=0>
				<tr>
					<td width=325px style="font-size:11pt">
						<center>
						<font style="font-size:14pt">کۆگای شاهۆ </font><br>
						بۆ بازرگانی جل و بەرگ<br>
						بە تاک و بە کۆ
						</center>
					</td>
					
					<td style="text-align:left"  width=100px>
					<img src="icon/logo.jpg" width="100">
					<font style="font-size:14pt">کشف حساب</font>
					</td>
					<td width=325px style="font-size:11pt">
						<center>
						<font style="font-size:14pt">SB Store</font><br>
						
						
						</center>
					</td>
				</tr>
				</table>
				<br>
			<table dir=rtl id="mydiv" height="" width="740px" border=0 style="font-size:16pt">
				<tr style="text-align:right" bgcolor="#f0f0f0">
					<th width=350px> <?php echo $name;?></th>
					<th width=200px><?php echo $add;?></th>
					<th width=200px><?php echo $mob;?></th>
				</tr>
			</table>
			
			<br>
			
			<table style="text-align:center;font-size:10pt" bgcolor="#d1eaf0" id='mydiv' width='740px' dir=rtl align="center">					
				<tr bgcolor="#708090" style="color:#ffffff">
					<td>مامەڵە</td>
					<td>بەروار</td>
					<td>ژمارەی وصل</td>
					
					
					<td>بڕی پارە</td>
					<td>باقی پارە</td>
				</tr>
				<?php
				$count=1;
				
				$get2="select * from `sell_j_inv` where  `customer`=$id order by `date`";
				$get_r2=$conn->query($get2);
				$sum=0;
				$sum_w=0;
				$sum_t=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 * from `sell_j_item` where `sell_j`='$sell_j'";
								$p_r=$conn->query($p);
								$tt=0;
								while($p_row=mysqli_fetch_array($p_r))
								{
									$ss=$p_row['sell_j_i_set'];
									$pp=$p_row['sell_j_i_price'];
									$codee=$p_row['sell_j_i_code'];
									$gg="select `i_s_per` as `per` from `item_set` where `i_s_barcode`='$codee'";
									$get_per=$conn->query($gg);
									$row_per=mysqli_fetch_array($get_per);
									$per=$row_per['per'];
									
									$t=$ss*$pp*$per;
									$tt+=$t;
								}
					
						
						?>
						<tr bgcolor="<?php echo $col;?>">
							<th style="color:#7A7DCE">فرۆشتن</th>
							<td style="color:#bb141c;background-color:#f0f0f0; font-size:8pt"><?php echo $transfer_row['sell_j_date'];?></td>
							<td><a href="sell_j_print.php?sell_j_id=<?php echo $transfer_row['sell_j_id'];?>"><?php echo $transfer_row['sell_j_id'];?></td>
							
							
							<td><?php echo $currency;?> <?php echo number_format($tt,2); $sum+=$tt;?></td>
							
							
							
							
							<th width=120px dir=ltr bgcolor="#a9a9a9"> <?php echo number_format($sum,2);?> <?php echo $currency;?></th>
						</tr>
						<?php 
				}
					elseif($type=="get")
					{
						$get="select * from `get` where `get_id`=$code";
						$get_r=$conn->query($get);
						$get_row=mysqli_fetch_array($get_r);
					?>
						<tr bgcolor="<?php echo $col;?>">
							<th style="color:green">پارە وەرگرتن</th>
							<td style="color:#bb141c;background-color:#f0f0f0;font-size:8pt"><?php echo $get_row['get_date'];?></td>
							<td><a href="pay_print_get.php?id=<?php echo $get_row['get_id'];?>"><?php echo $get_row['get_id'];?></a></td>
							<th dir=ltr style="color:#bb141c" bgcolor="#cccccc"> <?php echo number_format($p=$get_row['amount'],2); $sum-=$p;?> <?php echo $currency;?></th>
							<th dir=ltr bgcolor="#a9a9a9"> <?php echo number_format($sum,2);?> <?php echo $currency;?></th>
						</tr>
					<?php
					}
					elseif($type=="debt")
					{
						$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'];
					?>
						<tr bgcolor="<?php echo $col;?>">
							<th style="color:green">قەرزی کۆن</th>
							<td style="color:#bb141c;background-color:#f0f0f0;font-size:8pt"><?php echo $transfer_row['sell_j_date'];?></td>
							<td><?php echo $transfer_row['sell_j_id'];?></td>
							<th dir=ltr style="color:green" bgcolor="#ffffff"> <?php echo number_format($p=$transfer_row['amount'],2); $sum+=$p;?> <?php echo $currency;?></th>
							<th dir=ltr bgcolor="#a9a9a9"> <?php echo number_format($sum,2);?> <?php echo $currency;?></th>
						</tr>
					<?php
					}
					
					
				
					
				
					
				}?>
				<tr bgcolor="#f9f9f9">
					
					<th colspan=2>کۆی گشتی باقی پارە</th>
					<th colspan=2><?php if($sum<0) echo "ماوە لای ئێمە"; elseif($sum>2) { echo "<a href='get.php?id=$id&&name=$name'>ماوە لای ئەوان</a>";}?></th>
					<th dir=ltr style="color:#ffffff" bgcolor="#708090"> <?php echo number_format($sum,2);?> <?php echo $currency;?></th>
					
				</tr>
			</table>
			<br>
			
		</div>
	</body>
</html>


