<?php include("sass/icon_for_datepicker_and_datatable.php");?>
              <body>
			  
			  <?php 
			  
			  $lc_taka_id =$_REQUEST['lc_taka_id'];
			  
			  $result = mysqli_query($connection,"SELECT * FROM lc_taka WHERE lc_taka_id  = '$lc_taka_id'");
$test = mysqli_fetch_array($result);

				
			  
			  	$lc_taka_id = $test['lc_taka_id'];
	
				$lc_balance = $test['lc_balance'];
				$lc_margin_per = $test['lc_margin_per'];
				$lc_margin = $test['lc_margin'];
				$dollar_rate = $test['dollar_rate']; 
				$supplier_id = $test['supplier_id'];	
				 $lc_number = $test['lc_number'];
				 $farm_name = $test['farm_name'];
				 $bank_id = $test['bank_id'];
				 $date = date("Y-m-d");
				 $first_time = $test['first_time'];
				
				
			$lc_balance = $lc_balance * $dollar_rate ;
				$minus_lc = $lc_balance - $lc_margin ;
				 
			if($first_time == 1){	
		 $query = "SELECT * FROM lc where lc_number='$lc_number'";
                                                $result = mysqli_query($connection,$query);
                                                 
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                
						$lc_id = $row['lc_id'];
						$product_id = $row['product_id'];
						$quantity = $row['quantity'];
						$buying_price = $row['buying_price'];
						$selling_price = $row['selling_price'];
						$buying_price = $buying_price * $dollar_rate ;
						$selling_price = $selling_price * $dollar_rate ;
                                               
												
		mysqli_query($connection,"INSERT INTO store (product_id, quantity, buying_price, selling_price, supplier_id, chalan_no, stock_of, date) VALUES ('$product_id','$quantity','$buying_price','$selling_price','$supplier_id','$lc_number','rr','$date')")
		or die(mysqli_error());
		
		mysqli_query($connection,"UPDATE product_setup SET buy_price ='$buying_price', selling_price ='$selling_price' WHERE product_id = '$product_id'")
				or die(mysqli_error()); 
				
				
				mysqli_query($connection,"UPDATE present_stock SET present_stock = present_stock + '$quantity' WHERE product_id = '$product_id' and stock_of = 'rr'")
				or die(mysqli_error()); 
												
												
												}
										}
				
				mysqli_query($connection,"INSERT INTO supplier_payment (supplier_id, bank, chalan_no, bank_id, sup_date) VALUES ('$supplier_id','$minus_lc','$lc_number','$bank_id','$date')")
		or die(mysqli_error()); 
		
		
		if(!empty($bank_id)) {
		mysqli_query($connection,"UPDATE bank_name_lc SET balance = balance + $minus_lc WHERE bank_id = $bank_id")
				or die(mysqli_error());
		
		mysqli_query($connection,"INSERT INTO transaction (date, ref_id, supplier_id, ledger, credit, bank_id, hint, payment_type) VALUES ('$date','$lc_number','$supplier_id','Supplier Payment From LC','$minus_lc','$bank_id','Supplier Payment From LC','b_lc')")
		or die(mysqli_error());
		
		mysqli_query($connection,"UPDATE lc_taka SET status ='2' WHERE lc_number = '$lc_number'")
				or die(mysqli_error()); 
				
				echo "<script>window.location='lc_pending.php'</script>";
		
		}
			  
			  
			  ?>

    </body>
</html>