<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>

<link href="../css/select2.css" rel="stylesheet" />
<!-- Page wrapper  -->
        <div class="page-wrapper">
          
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
<?php

if(isset($_GET["uid"]) and !isset($_POST["Save"]) and !isset($_POST["additems"]) and !isset($_POST["del"]))
{
$uid=$_GET["uid"];
$whr1="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_sales_master',$whr1);
$salesmas_id=$get["id"];
$sale_no=$get["sale_no"];
$sales_type=$get["sales_type"];
$client_name=$get["client_name"];
$client_address=$get["client_address"];
$client_tin=$get["tin_no"];
$saledt=$objIms->IntToDate($get["stampdate"]);
$get1=$objIms->getRows('tbl_account',$whr1);
$payment_mode=$get1["payment_mode"];
echo $payment_mode;

$delacc="delete from tmp_account_cancel where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales'";
mysql_query($delacc);
$delsale="delete from tmp_sales_cancel where session_login_id = '".$_SESSION['login_id']."' and sales_id='$salesmas_id'";
mysql_query($delsale);
$delsaledet="delete from tmp_sales_detail_cancel where session_login_id = '".$_SESSION['login_id']."' and salesmas_id='$salesmas_id'";
mysql_query($delsaledet);

if($payment_mode=='Cash' || $payment_mode=='Cheque'){
	if($payment_mode=='Cash'){
 $sqlacc="insert into tmp_account_cancel (invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id)select invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales' and cancel_status=0";

$resacc=mysql_query($sqlacc);

  $sqlsale="insert into tmp_sales_cancel (sales_id, sale_no, client_id, sales_type, stampdate, session_login_id)select id, sale_no, client_id, sales_type, stampdate, session_login_id from tbl_sales where session_login_id = '".$_SESSION['login_id']."' and id='$salesmas_id' and cancel_status=0";
$ressale=mysql_query($sqlsale);


 $sqlsaledet="insert into tmp_sales_detail_cancel (salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst,item_name,hsn_code,unit_name, session_login_id)select salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst ,item_name,hsn_code,unit_name , session_login_id from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and salesmas_id='$salesmas_id'";
$ressaledet=mysql_query($sqlsaledet);

  $sql_tem_cash="INSERT into temp_cash_details(sales_type, cr_amount, sales_mas_id, stampdate, session_login_id)select 'Sales_Return', dr_amount, sales_mas_id, stampdate, session_login_id from cash_detail where session_login_id = '".$_SESSION['login_id']."' and sales_mas_id='$salesmas_id'";
$sql_res_cash=mysql_query($sql_tem_cash);
}
else{

 $sqlacc="INSERT into tmp_account_cancel (invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id)select invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales' and cancel_status=0";

$resacc=mysql_query($sqlacc);

 $sql_tem_bank="INSERT into temp_bank_detail(head, bankdet_id, credit, stampdate, session_login_id)select 'Sales_Return', bankdet_id, debit, stampdate, session_login_id from tbl_bank where session_login_id = '".$_SESSION['login_id']."' and sale_mas_id='$salesmas_id'";
$sql_res_bank=mysql_query($sql_tem_bank);

 $sqlsale="insert into tmp_sales_cancel (sales_id, sale_no, client_id, sales_type, stampdate, session_login_id)select id, sale_no, client_id, sales_type, stampdate, session_login_id from tbl_sales where session_login_id = '".$_SESSION['login_id']."' and id='$salesmas_id' and cancel_status=0";
$ressale=mysql_query($sqlsale);


 $sqlsaledet="insert into tmp_sales_detail_cancel (salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst,item_name,hsn_code,unit_name,session_login_id)select salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst ,item_name,hsn_code,unit_name,session_login_id from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and salesmas_id='$salesmas_id'";
$ressaledet=mysql_query($sqlsaledet);


}

}
else{
 $sqlacc="insert into tmp_account_cancel (invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id)select invoice_no, mas_id, trans_date, actual_amt, Cr_Amt, sales_type, Dr_Amt, cash_type, clear, discount, freight_charge, cst, grand_tot, session_login_id from tbl_account where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales' and cancel_status=0";

$resacc=mysql_query($sqlacc);

 $sqlsale="insert into tmp_sales_cancel (sales_id, sale_no, client_id, sales_type, stampdate, session_login_id)select id, sale_no, client_id, sales_type, stampdate, session_login_id from tbl_sales where session_login_id = '".$_SESSION['login_id']."' and id='$salesmas_id' and cancel_status=0";
$ressale=mysql_query($sqlsale);


 $sqlsaledet="insert into tmp_sales_detail_cancel (salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst,item_name,hsn_code,unit_name,session_login_id)select salesmas_id, item_id, unit_id, qty, unit_price, discount, cgst, sgst, igst ,item_name,hsn_code,unit_name,session_login_id from view_sales_detail where session_login_id = '".$_SESSION['login_id']."' and salesmas_id='$salesmas_id'";
$ressaledet=mysql_query($sqlsaledet);

$sql_client="SELECT * FROM tbl_sales where id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
$res_client=mysql_query($sql_client);
$client_id=mysql_fetch_assoc($res_client);
$clint_name=$client_id["client_id"];


 $sql_tem_client1="INSERT into temp_client_detial(client_id, cr_amount, sell_mstr_id, head, stampdate, session_login_id)select '$clint_name', dr_amount, sell_mstr_id,'Sale_Return', stampdate, session_login_id from client_details where sell_mstr_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
$sql_res_client=mysql_query($sql_tem_client1);
}
	}
	
	if(isset($_GET["uid"]))
{
$uid=$_GET["uid"];
	$whr1="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
$get=$objIms->getRows('view_sales_master',$whr1);
$salesmas_id=$get["id"];
$sale_no=$get["sale_no"];
$sales_type=$get["sales_type"];
$client_name=$get["client_name"];
$client_address=$get["client_address"];
$client_tin=$get["tin_no"];
$saledt=$objIms->IntToDate($get["stampdate"]);	
}
	
	
	if(isset($_POST["additems"]))
{
	 $item_id=$_POST["item_id"];
	 $result=$_REQUEST["item_nm"];
            $result_explode = explode('|', $result);
            $item_nm = $result_explode[0];
	/*$item_nm=$_POST["item_nm"];*/
	 $qty=$_POST["qty"];
	$unit_name=$_POST["unit"];
	$unit_id=$_POST["unit_id"];
	$unit_price=$_POST["price"];
	$discount=$_POST["discount"];
	$cgst=$_POST["cgst"];
	$sgst=$_POST["sgst"];
	$igst=$_POST["igst"];
	$hsn_code=$_POST["hsn_code"];
	$salesmas_id=$_POST["salesmas_id"];
	
	if(($item_id>0) and ($qty>0) and ($unit_price>0) and ($unit_id>0))
	{
	
	 $sqlchk="select * from tmp_sales_detail_cancel where session_login_id = '".$_SESSION['login_id']."' and salesmas_id='$salesmas_id' and item_id='$item_id' and unit_id='$unit_id' and unit_price='$unit_price'";
	$exechk=mysql_query($sqlchk);
	if(mysql_num_rows($exechk)==0){
							 $sql2="insert into tmp_sales_detail_cancel(salesmas_id,item_id,item_name,qty,unit_price,unit_id,unit_name,discount,cgst,sgst,igst,hsn_code,session_login_id) values('$salesmas_id','$item_id','$item_nm','$qty','$unit_price','$unit_id','$unit_name','$discount','$cgst','$sgst','$igst','$hsn_code','".$_SESSION['login_id']."')";
				  			$final2=mysql_query($sql2);
						
						
	 	}
		else
		{
		$msg='<span style="color:#FF0000">Item Already Exists...</span>';
		}
	
		
	}
}


if(isset($_POST["del"]))
{
	$tem_id=$_POST["del"];
	
	$del="delete from tmp_sales_detail_cancel where session_login_id = '".$_SESSION['login_id']."' and id=$tem_id";
	mysql_query($del);
	

}
$sql_client="SELECT * FROM tbl_sales where session_login_id = '".$_SESSION['login_id']."' and id='$salesmas_id'";
$res_client=mysql_query($sql_client);
$client_id=mysql_fetch_assoc($res_client);
$clint_name=$client_id["client_id"];

$sql_client_nm="SELECT * from tbl_client where session_login_id = '".$_SESSION['login_id']."' and id='$clint_name'";
$res_client_nm=mysql_query($sql_client_nm);
$count=mysql_fetch_assoc($res_client_nm);
$clien_id=$count["client_name"];
$sql_viewtmp="select *  from tmp_sales_detail_cancel where salesmas_id=$salesmas_id and session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{
					  while($rows=mysql_fetch_assoc($res_viewtmp))
					{
						$item_id=$rows["item_id"];
						$item_name=$rows["item_id"];
						$unit_id=$rows["unit_id"];
						$unit_name=$rows["unit_name"];
						$qty=$rows["qty"];
						$unit_price=$rows["unit_price"];
						$pur_price=$rows["pur_price"];
					    $discount=$rows["discount"];
					    $cgst=$rows["cgst"];
					    $sgst=$rows["sgst"];
					    $igst=$rows["igst"];
					}
if(isset($_POST["Cancel"])){
	$stampdate=$objIms->DateToInt(date('d-m-Y'));
	$invoice_no=$objIms->trasaction_no();	
	$result=$_POST["grand_total"];
	$round_off=$_POST["round_off"];
	$paid_amt=$_POST["paid_amt"];
	$salesmas_id=$_POST["salesmas_id"];
	$remarks=$_POST["massage"];

 $sql_can="INSERT into tbl_cancel(sell_mas_id, invoice_no, client_id, client_name, invoice_date, item, unit_price, qty, discount, cgst, sgst, igst, grand_total, remarks, session_login_id) values('$salesmas_id', '$invoice_no', '$clint_name','$clien_id','$stampdate' ,'$item_id', '$unit_price','$qty','$discount', '$cgst', '$sgst', '$igst', '$result', '$remarks', '".$_SESSION['login_id']."');";
$res_cancel=mysql_query($sql_can);
}
	}
	if(isset($_POST["Save"]))
	{
	$stampdate=$objIms->DateToInt(date('d-m-Y'));	
	$invoice_no=$objIms->trasaction_no();
	$result=$_POST["grand_total"];
	$round_off=$_POST["round_off"];
	$paid_amt=$_POST["paid_amt"];
	$salesmas_id=$_POST["salesmas_id"];
	$remarks=$_POST["massage"];
	if(($paid_amt<=$round_off) and ($paid_amt<>""))
			{
	$sqlsale="insert into tbl_sales (client_id, sales_type, stampdate, session_login_id)select client_id, sales_type,'$stampdate' ,session_login_id from tmp_sales_cancel where sales_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
$ressale=mysql_query($sqlsale);
$lastid=mysql_insert_id();
				
				$Sale_no='SELL/'.date('M').'/'.date('Y').'/'.$lastid;
				$sql_upmas="Update tbl_sales set sale_no='$Sale_no' where id='$lastid' and session_login_id = '".$_SESSION['login_id']."'";
				$res_upmas=mysql_query($sql_upmas);
				
				$sql_up="Update tbl_sales set cancel_status='$lastid' where id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
				$res_up=mysql_query($sql_up);
				$sql_upacc="Update tbl_account set cancel_status='$lastid' where session_login_id = '".$_SESSION['login_id']."' and mas_id='$salesmas_id' and sales_type='Sales'";
				$res_upacc=mysql_query($sql_upacc);

		if($payment_mode=='Cash'){
	$sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,clear, grand_tot, session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$paid_amt','Sales','Debit',1,'$result', '".$_SESSION['login_id']."')";
    $res_ins=mysql_query($sql_ins);

    $sql_cash = "insert into cash_detail (sales_mas_id, sales_type, dr_amount, stampdate, session_login_id) values('$lastid','sale', '$paid_amt','$stampdate','".$_SESSION['login_id']."')";
	$res_cash=mysql_query($sql_cash);
}
       elseif($payment_mode=='Cheque')
		{
			$sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,clear, grand_tot,payment_mode, session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$paid_amt','Sales','Debit',1,'$result','Cheque','".$_SESSION['login_id']."')";
		    $res_ins=mysql_query($sql_ins);

		    $sql_cheq = "insert into tbl_bank(head, debit, sale_mas_id, stampdate, session_login_id) values ('sale_payment', '$paid_amt', '$lastid','$stampdate', '".$_SESSION['login_id']."' )";
					$res_cheq = mysql_query($sql_cheq);
		}

		else{
			$sql_ins="insert into tbl_account(invoice_no,mas_id,trans_date,actual_amt,Dr_Amt,sales_type,cash_type,clear, grand_tot, session_login_id) values('$invoice_no','$lastid','$stampdate','$round_off','$paid_amt','Sales','Debit',1,'$result', '".$_SESSION['login_id']."')";
		    $res_ins=mysql_query($sql_ins);

		    $sql_due = "insert into client_details(client_id, dr_amount, sell_mstr_id, stampdate, session_login_id) values('$client_id', '$round_off', '$lastid', '$stampdate', '".$_SESSION['login_id']."')";
				$res_due=mysql_query($sql_due);
		}
 $sql_1="select * from tmp_sales_detail_cancel where salesmas_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
	$res_1=mysql_query($sql_1);
	if((mysql_num_rows($res_1)>0))
	{
	while($result=mysql_fetch_array($res_1))
					{
					$item_id=$result["item_id"];
					$qty=$result["qty"];
					$unit_price=$result["unit_price"];
					$unit_id=$result["unit_id"];
					$tmpdiscount=$result["discount"];
					$cgst=$result["cgst"];
					$sgst=$result["sgst"];
					$igst=$result["igst"];
					$sql4="insert into tbl_sales_detail(salesmas_id,item_id,qty,unit_price,unit_id,discount,cgst,sgst,igst, session_login_id )values('$lastid','$item_id','$qty','$unit_price','$unit_id','$tmpdiscount','$cgst','$sgst','$igst', '".$_SESSION['login_id']."')";
					//echo $sql4;
					$rs1=mysql_query($sql4);
					
					 
					
					}
					$sql="delete from tmp_sales_detail_cancel where salesmas_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
				$rest=mysql_query($sql);
				
				$sql="delete from tmp_sales_cancel where salesmas_id='$salesmas_id' and session_login_id = '".$_SESSION['login_id']."'";
				$rest=mysql_query($sql);
				}
				?>
				<script type="text/javascript">
					alert('Success');
				</script>
				<?php
				 header("location:sales_reciept.php?uid=".md5($lastid));
				}
	}
?>

		
	
		 <style>
			select.error { background-color:#ffa8a8; border: 1px dotted red;  }
			input.error{ background-color:#ffa8a8;   }
			textarea.error{ background-color:#ffa8a8; border: 1px dotted red;  }
         </style>
		 
     <script type="text/javascript"> 
 		/*jQuery(document).ready(function(){
			$('#item_nm').autocomplete({source:'../ProgramFile/auto/suggest_stock.php', minLength:1,
			select: function (event, ui) {
        	$("#item_id").val(ui.item.id); // display the selected id
       		$("#item_nm").val(ui.item.value); // display the selected text.
			$("#unit").val(ui.item.unit_name);
			$("#price").val(ui.item.sell_price);
			$("#unit_id").val(ui.item.unit_id);
			$("#av_qty").val(ui.item.tot_qty);
			$("#unit_price").val(ui.item.unit_price);
			$("#hsn_code").val(ui.item.hsn_code);
			$("#cgst").val(ui.item.cgst);
			$("#sgst").val(ui.item.sgst);
			$("#igst").val(ui.item.igst);
		    }
			});

}); 

*/
function chkamt(str)
	{
	 str=eval(str);
	var av=eval(document.getElementById("round_off").value);
	//alert(str+" "+av);
	if(av<str)
	{
	alert("Paid Amount Should Not Be Greater Than Round Off Amount");
	document.getElementById("paid_amt").value='';
	
	}
	}
</script>   


<style type="text/css">
<!--
.table_bg{ border:#CCCCCC solid 1px; border-radius:5px; height:auto; width:auto; padding:20px; margin-bottom:10px;}
.text_style1 {font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px;}


-->
</style>

							
							<h3>Cancle Invoice <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h3>
	                               
 <div class="table-responsive m-t-40">
<form id="form1" name="form1" method="post" action="">
<table width="100%" class="table table-bordered" cellpadding="4">
  <tr>
    <td  bgcolor="#FFFFFF" ><strong>Invoice No</strong></td>
    <td  bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td  bgcolor="#FFFFFF" ><?php echo $sale_no;?></td>
    <td  ><strong>Client Name<span style="color:#F00; font-weight:bold;">*</span> </strong></td>
    <td><strong>:</strong></td>
    <td ><?php echo $client_name;?></td>
    </tr>
  <tr>
    <td  bgcolor="#FFFFFF" ><strong>Invoice Date</strong></td>
    <td  bgcolor="#FFFFFF" ><strong>:</strong></td>
    <td  bgcolor="#FFFFFF" >
       <?php echo $saledt;?></td>
    <td nowrap="nowrap"><span class="text_style1">Client Address </span></td>
    <td><strong>:</strong></td>
    <td><?=$client_address?></td>
    </tr>
</table>
<div class="panel">
<div class="panel-heading"><strong>Add Item </strong></div>
           
			 <table width="100%" class="table table-bodered">
            <tr height="32" align="left">
            <td >Item Name</td>
           
            <td ><select name="item_nm" id="item_nm" onchange="fun()" class="form-control">
			<option value="">item / pur price / sell price </option>
			 
			<?php 
							$sqlitm="select * from tbl_purchase_details where session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$citm=mysql_query($sqlitm);
							if(mysql_num_rows($citm)>0){
							while($row_itm=mysql_fetch_array($citm))
							{
							$sqlitm2="select * from tbl_item where id = '".$row_itm["item_id"]."' and session_login_id = '".$_SESSION['login_id']."'";
							//echo $sqlc;
							$citm2=mysql_query($sqlitm2);
							$row_itm2=mysql_fetch_array($citm2);
							?>
        <option value="<?=$row_itm2["item_name"];?>|<?=$row_itm["pur_price"];?>|<?=$row_itm["sell_price"];?>">
     <p> <?=$row_itm2["item_name"];?> / <?=$row_itm["pur_price"];?> / <?=$row_itm["sell_price"];?></p>
        </option>
        <?php }}?>
		</select>
              <input type="hidden" name="item_id" id="item_id" style="width:350px" /> <input type="hidden" name="salesmas_id" value="<?php if(isset($_POST['salesmas_id'])){echo $_POST['salesmas_id'];}else{echo $salesmas_id;}?>" /></td>
            <td >Unit</td>
           
            <td ><input name="unit" id="unit" style="width:75px;" readonly="" />
              <input type="hidden" name="unit_id" id="unit_id" style="width:200px;"> <input type="hidden" name="hsn_code" id="hsn_code" style="width:200px;">             </td>
			<td >Unit Price</td>
            
            <td><input type="hidden" name="unit_price" id="unit_price"  /><input type="text" name="price" id="price" style="width:75px" readonly="" /></td>
			<td>Avail Qty </td>
			
           
            <td><input type="text" name="av_qty" id="av_qty" style="width:75px" readonly="" /></td>
            <td>Qty</td>
            
            <td ><input type="text" name="qty" id="qty" style="width:75px" onblur="maxqty(this.value)" onkeypress="return isNumberKey(event)"/></td>
            </tr>
            <tr height="32" align="left">
              <td >Discount(in %)</td>
              
              <td><input type="text" name="discount" id="discount" onkeypress="return isNumber(event,this);"  style="width:75px" /></td>
              <td>CGST(in %)</td>
              
              <td><input type="text" name="cgst" id="cgst" style="width:75px"  readonly=""/></td>
              <td>SGST(in %)</td>
             
              <td><input type="text" name="sgst" id="sgst" style="width:75px" readonly=""/></td>
              <td>IGST(in %)</td>
            
              <td><input type="text" name="igst" id="igst" style="width:75px" readonly=""/></td>
              
              <td colspan="2"><input type="submit" name="additems" id="additems" value="Add Items" class="btn btn-success" style="margin-top::0px" /></td>
              </tr>
           </table>
			
</div>
<script type="text/javascript">
		  function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
} 
		</script>


     <div class="panel">
            <div class="panel-heading"><strong>Item List of Sale </strong></div>
            
            <table width="100%" class="table table-striped">
		
            <?php
			if(isset($_POST["salesmas_id"]))
			{
			$salesmas_id=$_POST["salesmas_id"];
			}
			else
			{
			$salesmas_id=$salesmas_id;
			}
     $sql_viewtmp="select *  from tmp_sales_detail_cancel where salesmas_id=$salesmas_id and session_login_id = '".$_SESSION['login_id']."'";
				$res_viewtmp=mysql_query($sql_viewtmp);
				if(mysql_num_rows($res_viewtmp)>0)
				{ 
					$i=1;
					$sum=0;
  ?>
  <tr>
    <td width="6%" height="28"><span class="text_style1">Si No</span></td>
    <td width="29%"><span class="text_style1">Item Name</span></td>
    <td width="18%"><span class="text_style1">Unit Name</span></td>
    <td width="13%"><span class="text_style1">Order Qty</span></td>
    <td width="17%"><span class="text_style1">Price(Pc)</span></td>
    <td width="17%"><strong>Total</strong></td>
    <td width="17%"><strong>Discount</strong></td>
    <th width="20%" align="left" nowrap="nowrap">CGST(%)</th>
   <!-- <th width="20%" align="left" nowrap="nowrap">CGST </th>-->
    <th width="20%" align="left" nowrap="nowrap">SGST(%)</th>
    <!--<th width="20%" align="left" nowrap="nowrap">SGST</th>-->
    <th width="20%" align="left" nowrap="nowrap">IGST(%)</th>
    <!--<th width="20%" align="left" nowrap="nowrap">IGST</th>-->
    <td width="17%"><span class="text_style1">Total Price</span></td>
    <td width="20%"><strong>Delete</strong></td>
  </tr>
  <?php
  $sum=0;
  while($rows=mysql_fetch_assoc($res_viewtmp))
					{
  ?>
  <tr>
    <td height="27"><span class="text_style"><?=$i++?></span></td>
    <td><span class="text_style"><?=$rows["item_name"]?></span></td>
    <td><span class="text_style"><?=$rows["unit_name"]?></span></td>
    <td><span class="text_style"><?=$rows["qty"]?></span></td>
    <td><span class="text_style">
      <?=$rows["unit_price"]?>
    </span></td>
    <td><?php echo $totsum=($rows["unit_price"]*$rows["qty"]);?></td>
    <td><?php echo $discount=$totsum*($rows["discount"]/100); $totprice=($totsum-$discount);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["cgst"];?><?php  $cgst=$totprice*($rows["cgst"]/100);  number_format($cgst,2);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["sgst"];?><?php  $sgst=$totprice*($rows["sgst"]/100);  number_format($sgst,2);?></td>
    <td width="20%" nowrap="nowrap"><?php echo $rows["igst"];?><?php  $igst=$totprice*($rows["igst"]/100); echo number_format($igst,2);?></td>
    <td class="text_style1"><?php echo $totamt=$totprice+$cgst+$sgst+$igst;?></td>
    <td width="20%" nowrap="nowrap"><button type="submit" name="del" value="<?=$rows["id"]?>" class="btn btn-danger">Delete</button></td>
  </tr>
  <?php $sum=$sum+$totamt;}}?>
  <tr>
    <td height="27" colspan="10" align="right" class="text_style1">Sum Total : </td>
    <td class="text_style1"><?php echo number_format($sum,2);?></td>
    <td class="text_style1">&nbsp;</td>
  </tr>
  
    <tr>
      <td height="27" colspan="10" align="right" class="text_style1">Grand Total: </td>
      <td class="text_style1"><?php  $gtol=$sum; echo number_format($gtol,2);$gtol=round($gtol);?><input type="hidden" name="grand_total" id="grand_total" style="width:100px; border:none; background:#FFFFFF;" readonly value="<?php echo $gtol;?>"/></td>
      <td class="text_style1">&nbsp;</td>
    </tr>
	<tr>
      <td height="27" colspan="10" align="right" class="text_style1">Round Off:</td>
      <td class="text_style1"><?php  echo $gtol=round($gtol);?><input type="hidden" name="round_off" id="round_off" style="width:100px; border:none; background:#FFFFFF;" readonly value="<?php echo round($gtol);?>"/></td>
      <td class="text_style1">&nbsp;</td>
	</tr>
	<tr>
	  <td height="27" colspan="10" align="right" class="text_style1"><strong>Paid Amount :</strong></td>
	  <td class="text_style1"><input type="text" name="paid_amt" id="paid_amt" onkeypress="return isNumber(event,this);" onblur="chkamt(this.value)" style="width:100px;"   /></td>
	  <td class="text_style1">&nbsp;</td>
	  </tr>
  <?php echo '<span style="color:#FF0000">'.$msg.'</span>';?>
</table>
<div style="width:100%;">
<span style="color: red">Remarks For Cancel of Invoice</span>
<span>:-</span>
<span style="width: 100%"><input type="text" name="massage" style="width: 100%" class="form-control"></span>
</div>
<br>
<table  width="100%" class="table table-striped">
  <tr>
    <td height="27" colspan="1" align="right" class="text_style1"><input type="submit" id="Cancel" name="Cancel" value="Cancel" class="btn btn-info" style="margin:inherit;"/></td>
    <td height="27" colspan="1" align="center"  class="text_style1"><input type="submit" id="Save" name="Save" value="Cancel And Generate New" class="btn btn-info" style="margin:inherit;"/></td>
    <td class="text_style1">&nbsp;</td>
  </tr>
           </table>
    </div>
<script type="text/javascript">
function isNumber(evt, element) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 46 || charCode == 8))
    return false;
  else {
    var len = $(element).val().length;
    var index = $(element).val().indexOf('.');
    if (index > 0 && charCode == 46) {
      return false;
    }
    if (index > 0) {
      var CharAfterdot = (len + 1) - index;
      if (CharAfterdot > 3) {
        return false;
      }
    }

  }
  return true;
}
</script>	
		

   
<p></p>
		<br />
        

</form> </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
			
       <script src="../js/lib/jquery/jquery.min.js"></script>
    <script src="../js/lib/bootstrap/js/popper.min.js"></script>
    <script src="../js/lib/bootstrap/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../js/jquery.slimscroll.js"></script>
    <!--Menu sidebar -->
    <script src="../js/sidebarmenu.js"></script>
    <!--stickey kit -->
    <script src="../js/lib/sticky-kit-master/dist/sticky-kit.min.js"></script>
    <!--Custom JavaScript -->
    <script src="../js/custom.min.js"></script>
	
	
		<script src="../js/select2.js"></script>
		<script type="text/javascript">
		
			$(document).ready(function() {
				var country = [];
				$("#item_nm").select2({
				  data: country
				});
			});
			function fun(){
			var item_name =$("#item_nm").val();
			//alert(item_name);
			$.ajax({
		type: "POST",
		url: "fetch_item_det.php",
		data: "item_name="+item_name,
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var item_id = data[0];
				var unit_name = data[1];
				var unit_id = data[2];
				var unit_price = data[3];
				var price = data[4];
				var av_qty = data[5];
				var cgst = data[6];
				var sgst = data[7];
				var igst = data[8];
				
				$('#item_id').val(item_id);
				$('#unit').val(unit_name);
				$('#unit_id').val(unit_id);
				$('#unit_price').val(unit_price);
				$('#price').val(price);
				$('#av_qty').val(av_qty);
				$('#cgst').val(cgst);
				$('#sgst').val(sgst);
				$('#igst').val(igst);
				
				
			}
			});
   
			
			}
		</script>

</body>

</html>