<?php session_start();

if($_SESSION[invcox] == ""){

header("location:login.php?action=need");

}else{

include("config.php");

$kresult = mysql_query("SHOW TABLE STATUS LIKE 'chalan'");
$krow = mysql_fetch_array($kresult);
$next_increment=$krow['Auto_increment'];
mysql_query("DELETE from chalan_product WHERE cid='$next_increment'");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A2Z Accounting Software</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function popUp(URL) {

day = new Date();

id = day.getTime();

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=yes,width=600,height=450,left = 190,top = 112');");

}

</script>
<?php include("calendar.php");?>
  
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

	<!-- Select2 CSS -->

<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />



<!-- Select2 JS -->

<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

<style type="text/css">







<!--



	.select2-selection--single{

		background: #769fa4;

		border: 1px solid #518289;

	}



        #suggestions {

            border: 1px solid #ccc;

            background: #fff;

            position: absolute;

            width: 400px;

            max-height: 200px;

            overflow-y: auto;

            display: none;

            z-index: 999;

        }

        #suggestions div {

            padding: 8px;

            cursor: pointer;

        }

        #suggestions div:hover {

            background: #f0f0f0;

        }

	
        #suggestions_ref {

            border: 1px solid #ccc;

            background: #fff;

            position: absolute;

            width: 400px;

            max-height: 200px;

            overflow-y: auto;

            display: none;

            z-index: 999;

        }

        #suggestions_ref div {

            padding: 8px;

            cursor: pointer;

        }select {
    width: 220px;
    padding: 6px;
    margin: 10px 20px 10px 0;
}
		</style>

<script language="javascript" type="text/javascript">



//Browser Support Code

function ajaxFunction(i){
 
	var ajaxRequest;  // The variable that makes Ajax possible!

	

	try{

		// Opera 8.0+, Firefox, Safari

		ajaxRequest = new XMLHttpRequest();

	} catch (e){

		// Internet Explorer Browsers

		try{

			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try{

				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){

				// Something went wrong

				alert("Your browser broke!");

				return false;

			}

		}

	}

	// Create a function that will receive data sent from the server

	ajaxRequest.onreadystatechange = function(){

		if(ajaxRequest.readyState == 4){

		   //document.form1.qty.value='';
		  // document.form1.description.value='';

			var ajaxDisplay = document.getElementById('chalan_entry');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;

document.getElementById('total_price').value=document.getElementById('aj_total').value;
total_price_cak();

		//var fakhrul = ajaxRequest.responseText;

		//alert('fakhrul');

			

		}

	}



  //-------------------------



var cid = document.getElementById('cid').value;
var product_type = i;
  
 

var queryString = "?cid=" + cid + "&product_type=" + product_type ; 
	ajaxRequest.open("GET", "product_input.php" + queryString, true);
	ajaxRequest.send(null); 
}


function show_model(){}

function chossen_product_model(){}

function show_product(){}

//Browser Support Code

function chalan_product_del(i){

	var ajaxRequest;  // The variable that makes Ajax possible!

	

	try{

		// Opera 8.0+, Firefox, Safari

		ajaxRequest = new XMLHttpRequest();

	} catch (e){

		// Internet Explorer Browsers

		try{

			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try{

				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){

				// Something went wrong

				alert("Your browser broke!");

				return false;

			}

		}

	}

	// Create a function that will receive data sent from the server

	ajaxRequest.onreadystatechange = function(){

		if(ajaxRequest.readyState == 4){

		

			var ajaxDisplay = document.getElementById('chalan_entry');

			ajaxDisplay.innerHTML = ajaxRequest.responseText;

			//check_media_type();

			document.getElementById('total_price').value=document.getElementById('aj_total').value;
total_price_cak();

		//var fakhrul = ajaxRequest.responseText;

		//alert(fakhrul);

			

		}

	}



  //-------------------------



var cid = document.getElementById('cid').value;

var delid = i;





var queryString = "?cid=" + cid + "&delid=" + delid;

		



	ajaxRequest.open("GET", "product_del.php" + queryString, true);

	ajaxRequest.send(null); 

	

}

 function close_all(){

	document.getElementById('page1').style.display='none';

	document.getElementById('page2').style.display='none';

 

}



function preview(){}

 function close_all(){

	document.getElementById('page1').style.display='none';

	document.getElementById('page2').style.display='none';

 

}

function submit_form(){

	document.form1.submit();

}





function validate()



{}





function valid2()



{}



//Browser Support Code

/*function hint(){}
*/
function setSelectedIndex()
  {}

function product_sr(){}


	

function total_price_cak(){



 

//var rprice = parseFloat(document.getElementById('rprice').value);

var stotal_taka = parseFloat(document.getElementById('stotal_taka').value);

//var total_prix = Math.round(rprice*number_of_days); // totol price  

document.getElementById('total_price').value =stotal_taka;

	

var total_price = stotal_taka;



var discount = parseFloat(document.getElementById('discount').value); 



var total_price2 = Math.round(total_price-discount); // totol price after discount





if(discount>'0'){

document.getElementById("afd").style.display='block';

document.getElementById('afd').innerHTML =total_price2;



}else{

document.getElementById("afd").style.display='none';

}







var vat2 = parseFloat(document.getElementById('vat').value); 

var vat =  Math.round((total_price2/100)*vat2); 







if(vat>'0'){

document.getElementById("tvat").style.display='block';

document.getElementById('tvat').innerHTML =vat;

document.getElementById('vat_amount').value =vat;

}else{

document.getElementById("tvat").style.display='none';

document.getElementById('vat_amount').value =0;

}





var total_price3 = Math.round(total_price2+vat); // totol price after vat tax

document.getElementById('total_payeble').value =total_price3; // set the fiinal payeble

var payment_amount = parseFloat(document.getElementById('payment_amount').value);

var due = Math.round(total_price3-payment_amount); // due

document.getElementById('due').value =due;

}

</script>
</head>

<body>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="box-wrap">
  <tr>
    <td><?php include("top.php")?></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td><table width="100%" border="0" cellspacing="1" cellpadding="0">
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="30" background="images/place_bg.jpg" class="link2"><strong>&nbsp;&nbsp;<a href="index.php">Home</a> &gt; <a href="sales.php">Sales</a> &gt; <a href="chalan_entry.php">Create Invoice </a></strong></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td bgcolor="#FFFFFF"><form action="insert_chalan.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return valid2();">
                    <div id="page1" style="position: relative; width:100%; z-index:2; visibility: visible;">
                      <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#999999">
                        <tr>
                          <td colspan="4" align="center" bgcolor="#999999"><strong>Create Invoice</strong></td>
                        </tr>
                        <tr>
                          <td colspan="4" bgcolor="#FFFFFF"><table width="150" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="70%"><?php 
$lastsaterday=date("Y-m-d");
 ?>
                                  <input name="tdate" type="text" id="tdate" value="<?php if($_POST[date1] == ""){echo dtformat($lastsaterday);}else{echo $_POST[date1];} ?>" size="15" /></td>
                                <td width="30%" align="center"><a title="Calendar" onclick="displayDatePicker('tdate', this);" href="javascript:;"><img src="images/calendar.gif" width="20" height="20" border="0" /></a></td>
                              </tr>
                            </table>
                            <?php 

				 	

					

					//echo $next_increment;

				  ?>
                            <input name="cid" type="hidden" id="cid" value="<?php echo $next_increment;?>" />
                            <input name="chalan_m_id" type="hidden" id="chalan_m_id" value="<?php echo $chalan_m_id; printf("%04d", $n);?>" /></td>
                        </tr>
                        <tr>
                          <td colspan="4" bgcolor="#FFFFFF"><?php 

				  $xbresult=mysql_query("select * from company order by id asc");

				  $xbrow=mysql_fetch_array($xbresult);

				  ?>
                            <select name="company" required="required" class="company" id="company" style="width:175px;">
                              <?php /*?> <option value="">Select Company</option><?php */?>
                              <?php do{?>
                              <option value="<?php echo $xbrow[id];?>"><?php echo $xbrow[company];?></option>
                              <?php }while($xbrow=mysql_fetch_array($xbresult));?>
                            </select>                             </td>
                        </tr>
                        <tr>
                          <td colspan="4" bgcolor="#FFFFFF"></td>
                        </tr>
                        <tr>
                          <td height="30" colspan="4" valign="top" bgcolor="#FFFFFF"> <input type="text" id="nid" autocomplete="off">

    <div id="suggestions"></div>



							

<script>

$(document).ready(function() {

    // Live Search

    $("#nid").keyup(function () {

        let query = $(this).val();


        if (query.length === 0) {

            $("#suggestions").hide();

            return;

        }



        $.ajax({

            url: "resturent_search.php",

            method: "POST",

            data: { search: query },

            success: function (data) {

                $("#suggestions").html(data).show();

            }

        });

    });



    // On click suggestion

    $(document).on("click", ".suggest-item", function () {

        let customer = $(this).data("customer");
 
        $("#customer_name").val(customer.customer_name);
 
        $("#personal_phn").val(customer.personal_phn);

        $("#client").val(customer.id);

        $("#suggestions").hide();

    });

});

</script>



						  Search
						  (Room No/ Phone no/ Name/Invoice id)
						  <table width="430" border="0" cellpadding="2" cellspacing="1">
                            <tr>
                              <td width="52%" height="30"> Customer / Company Name: <span class="red">*</span></td>
                              <td width="48%" class="input200"><input name="customer_name" type="text" required="required" id="customer_name" /></td>
                              </tr>
                            <tr>
                              <td>Mobile:<span class="red">*</span></td>
                              <td class="input200"><input name="personal_phn" type="text" required="required" id="personal_phn" /></td>
                              </tr>
                            <tr>
                              <td>Customer ID :<span class="red">*</span></td>
                              <td class="input200"><input name="client" type="text" id="client"  readonly="readonly" required="required" /></td>
                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td height="30" colspan="4" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                              <tr>
                                <td width="21%" bgcolor="#DFDFDF"><strong>Product </strong></td>
                              </tr>
                              <tr>
                                <td bgcolor="#FFFFFF"><?php 

			 $iresult=mysql_query("select * from product_details where active='1'  order by sr asc");

			 $irow=mysql_fetch_array($iresult);

				  ?>
                                  <?php do{?>
                                  <input name="<?php echo $irow[id];?>" type="button" id="<?php echo $irow[id];?>" title="<?php echo $irow[id];?>" value="<?php echo $irow[pname];?>"  onclick="ajaxFunction('<?php echo $irow[id];?>')" style=" margin:2px;"/>
                                  <?php }while($irow=mysql_fetch_array($iresult));?></td>
                              </tr>
                            </table></td>
                        </tr>
                        <tr>
                          <td height="30" colspan="4" valign="top" bgcolor="#FFFFFF"><div id="chalan_entry"></div></td>
                        </tr>
                        <tr>
                          <td width="78%" height="30" align="left" bgcolor="#FFFFFF">&nbsp;</td>
                        </tr>
                        <tr>
                          <td height="30" align="left" bgcolor="#FFFFFF">&nbsp;</td>
                        </tr>
                        <tr>
                          <td height="30" align="left" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="3">
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td height="30">Total Amount :</td>
                              <td class="input200"><input name="total_price" type="text" id="total_price"  value="0" onkeyup="total_price_cak();" autocomplete="off" readonly="readonly"/></td>
                            </tr>
                            <tr>
                              <td height="30">Discount : </td>
                              <td class="input200"><input name="discount" type="text" id="discount"  value="0" onkeyup="total_price_cak();" onfocus="javascript:if(this.value=='0')this.value=''" onblur="javascript:if(this.value=='')this.value='0'" autocomplete="off"/>
                                  <div id="afd" class="show_info"></div></td>
                            </tr>
                            <tr>
                              <td height="30">VAT %:</td>
                              <td class="input200"><input name="vat" type="text" id="vat" onkeyup="total_price_cak();" value="0" onfocus="javascript:if(this.value=='0')this.value=''" onblur="javascript:if(this.value=='')this.value='0'" autocomplete="off"/>
                                  <div id="tvat" class="show_info"></div>
                                <input name="vat_amount" type="hidden" id="vat_amount" value="0" />                              </td>
                            </tr>
                            <tr>
                              <td height="30">Total Payeble :</td>
                              <td class="input200"><input name="total_payeble" type="text" id="total_payeble" value="0"  readonly="readonly" /></td>
                            </tr>
                            <tr>
                              <td height="30">Paid Amount :</td>
                              <td class="input200"><input name="payment_amount" type="text" id="payment_amount"  onkeyup="total_price_cak();" value="0" onfocus="javascript:if(this.value=='0')this.value=''" onblur="javascript:if(this.value=='')this.value='0'" autocomplete="off"/></td>
                            </tr>
                            <tr>
                              <td height="30">Pay Methode :</td>
                              <td class="input200"> 
                              <div class="chosen">
    <input name="pay_methode" type="text" id="pay_methode" placeholder="Select Pay Methode" required="required">
	
    <ul> <li data-value="">Select Pay Methode</li><?php 

$rresult=mysql_query("select * from bank_acc order by bank asc");

$rrow=mysql_fetch_array($rresult);

do{

	?>  <li data-value="<?php echo $rrow[bank];?> - <?php echo $rrow[accname];?> - <?php echo $rrow[accno];?>"><?php echo $rrow[bank];?> - <?php echo $rrow[accname];?> - <?php echo $rrow[accno];?></li>
		 <?php }while($rrow=mysql_fetch_array($rresult));?>
    </ul>
</div></td>
                            </tr>
                            <tr>
                              <td height="30">Due / Advance : </td>
                              <td><span class="input200">
                                <input name="due" type="text" id="due" value="0"  readonly="readonly"/>
                              </span></td>
                            </tr>
                            
                          </table></td>
                        </tr>
                        <tr>
                          <td height="30" align="left" bgcolor="#FFFFFF"><strong>Note : </strong></td>
                        </tr>
                        <tr>
                          <td height="30" align="left" bgcolor="#FFFFFF"><textarea name="remarks" cols="0" id="remarks"></textarea></td>
                        </tr>
                        <tr>
                          <td width="22%" align="center" bgcolor="#FFFFFF" class="next"><label>
                            <input type="submit" name="Submit" value="Submit" />
                          </label></td>
                        </tr>
                        <tr>
                          <td height="30" colspan="4" align="right" bgcolor="#FFFFFF">&nbsp;</td>
                        </tr>
                      </table>
                    </div>
                    <div id="page2" style="Display:none; position:relative; width:100%; z-index:2;"> </div>
                  </form></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td><?php include("bot.php")?></td>
  </tr>
</table>
</body>
</html>
<?php }?>