<?php include('connection/conn.php');
$id=$_GET['s_id'];
$get="select * from `store` where  `store_id`=$id";
$get_r=$conn->query($get);
$get_row=mysqli_fetch_array($get_r);
$name=$get_row['store_name'];
$mob=$get_row['store_mobile'];
$add=$get_row['store_address'];
?>
<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="150">
					<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 `purchase_inv` where  `store`=$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=="purchase")
					{
						$transfer="select * from `purchase_fatura` where `p_f_id`=$code";
						$transfer_r=$conn->query($transfer);
						$transfer_row=mysqli_fetch_array($transfer_r);
						$p_f=$transfer_row['p_f_id'];
						$item="select * from `purchase_fatura_item` where `p_f`=$p_f ";
						$item_r=$conn->query($item);
						while($item_row=mysqli_fetch_array($item_r)){
							
							
							$tt=0;
							
							$p="select * from `purchase_fatura_item` where `p_f`='$p_f'";
							$p_r=$conn->query($p);
							while($p_row=mysqli_fetch_array($p_r))
							{
								$ss=$p_row['p_f_i_set'];
								$pp=$p_row['p_price'];
								
								$codee=$p_row['p_f_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['p_f_date'];?></td>
							<td><?php echo $transfer_row['p_f_num'];?></td>
							
							
							<td><?php echo number_format($tt,3); $sum+=$tt;?> $</td>
							<th width=120px dir=ltr bgcolor="#a9a9a9">$ <?php echo number_format($sum,2);?></th>
						</tr>
						
					<?php	
					} 
					elseif($type=="pay")
					{
						$pay="select * from `pay` where `pay_id`=$code";
						$pay_r=$conn->query($pay);
						$pay_row=mysqli_fetch_array($pay_r);
					?>
						<tr bgcolor="<?php echo $col;?>">
							<th style="color:green">پارە دان</th>
							<td style="color:#bb141c;background-color:#f0f0f0;font-size:8pt"><?php echo $pay_row['pay_date'];?></td>
							<td></td>
							<th dir=ltr style="color:#bb141c" bgcolor="#cccccc">$ -<?php echo number_format($p=$pay_row['amount'],2); $sum-=$p;?></th>
							<th dir=ltr bgcolor="#a9a9a9">$ <?php echo number_format($sum,2);?></th>
						</tr>
					<?php
					}
				}?>
				<tr bgcolor="#f9f9f9">
					<th colspan=2>کۆی گشتی باقی پارە</th>
					<th colspan=2><?php if($sum<0) echo "ماوە لای ئەوان"; elseif($sum>0) echo "ماوە لای ئێمە";?></th>
					<th dir=ltr style="color:#ffffff" bgcolor="#708090">$ <?php echo number_format($sum,2);?></th>
				</tr>
			</table>
			<br>
			
		</div>
	</body>
</html>