<?php include 'header.php';

 

date_default_timezone_set('Asia/Calcutta');

$today = date("Y-m-d");

$today1 = date("d-m-Y");

$time = date("h:i A"); 

$currentyear = date("Y");

$currentmonth = date("m"); 

$currentyear = date("y"); 

if($currentmonth>03) { 

$cuyear = date("Y");

$cuyear1 = date("y")+1;



$cuyear2 = date("y");

$cuyear3 = date("y")+1;






} else { 

$cuyear = date("Y")-1;

$cuyear1 =  date("y");



$cuyear2 = date("y")-1;

$cuyear3 =  date("y");

 } 

$year = "$cuyear"."-"."$cuyear1";

$year_cha = "$cuyear2"."-"."$cuyear3";





$querydp = "select * from debit_no where auto_debit_no!='' and f_year='$year'";

$resultdp = mysqli_query($conn,$querydp);

$num_rowsdp = mysqli_num_rows($resultdp);

if($num_rowsdp =='0') { 

$inv_id1 = 0;

$inv_id2=$inv_id1+1;

$auto_debit_no= sprintf("%03d", $inv_id2);

} else {

while($row=mysqli_fetch_array($resultdp))

{

$inv_id1 = $row['auto_debit_no'];

$inv_id2=$inv_id1+1;

$auto_debit_no= sprintf("%04d", $inv_id2);

}

}

$debit_no = "DR/"."$auto_debit_no"."/"."$year_cha";






?>

<? 

$qry9 = "select * from customer_master where customer_id = '".$_REQUEST['customer_id']."'";

$re9 = mysqli_query($conn,$qry9);

while($row=mysqli_fetch_array($re9))

		{  

$customer_name = $row['customer_name'];

$bstate_code = $row['bstate_code'];

$debit_period = $row['debit_period'];

$TCS_percentage = $row['TCS_percentage'];

}
?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

   
        <div class="content-page">

            <div class="content">

                <div class="container">

                    <!--<div class="row">

                        <div class="col-sm-12">

                            <div class="page-header-title">

                                <h4 class="pull-left page-title">Form Validation</h4>

                                <ol class="breadcrumb pull-right">

                                    <li><a href="#">Xadmino</a></li>

                                    <li><a href="#">Forms</a></li>

                                    <li class="active">Form Validation</li>

                                </ol>

                                <div class="clearfix"></div>

                            </div>

                        </div>

                    </div>-->

                <script type="text/javascript" src="js/jquery.min.js"></script>

 <link rel="stylesheet" href="jquery-ui.css">

  <script src="jquery-ui.js"></script>

 



   <div class="row">

                        <div class="col-sm-12">

                            <div class="panel panel-primary">

                                <div class="panel-heading">

                                    <h3 class="panel-title">Make Debit Note</h3></div>

								<script>$(".datepicker_y").datepicker({

  inline: true,

  

  nextText: '&rarr;',

  prevText: '&larr;',

  showOtherMonths: true,

  changeMonth: true,

        changeYear: true,

  dateFormat: 'dd-mm-yy',

  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

      showAnim: "slide"

 });</script> 	

									

									<form name="chkForm" id="chkForm" action="insert_debit_note.php"  method="post" enctype="multipart/form-data">



									<input type="hidden" name="customer_id" value="<?php echo $_REQUEST['customer_id'];?>" />   

							
									

									

									

                                <div class="panel-body">

                                    <div class="row">

									<div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label>Customer Name</label>

                                                     <input type="text" class="form-control" name="customer_name" value="<?php echo $customer_name?>">

													

                                                    </div>

                                                    </div></div>

											
												 	

											

													<div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label>Debit No.</label>

                                                     <input type="text" class="form-control" name="debit_no" value="<?php echo $debit_no?>">

													

                                                    </div>

                                                    </div></div>

									

                                        <div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label> Date</label>

                                                        <input type="text" class="datepicker_y form-control" placeholder="dd-mm-yy"  name="debit_date" value="<?php echo $today1?>"><script>$(".datepicker_y").datepicker({

  inline: true,

  

  nextText: '&rarr;',

  prevText: '&larr;',

  showOtherMonths: true,

  changeMonth: true,

        changeYear: true,

  dateFormat: 'dd-mm-yy',

  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

      showAnim: "slide"

 });</script> 	

								

                                                    </div>

                                                    </div></div>

                                                    

                                                 

												 
		<div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label>GST Billing Type</label>

                                                        <select name="GST_Btype" class="form-control" required="required">

                                   <option value="">Select Billing type</option>

                                   <?php if($bstate_code=='27'){?><option value="Local" selected="selected">Local</option><?php } else {?>

                                   <option value="OMS">OMS</option><?php }?>

                                 </select>

													

                                                    </div>

                                                    </div></div>
													<div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label>Reference No</label>

                                                        <input type="text" name="reference_no" class="form-control" >

                                  
													

                                                    </div>

                                                    </div></div>

												
<div class="col-sm-3 col-xs-12">

                                            <div class="m-t-20">

                                                    <div class="form-group">

                                                        <label>Reference Date</label>

                                                        <input type="text" class="datepicker_y form-control" placeholder="dd-mm-yy"  name="refer_date" value="<?php echo $today1?>"><script>$(".datepicker_y").datepicker({

  inline: true,

  

  nextText: '&rarr;',

  prevText: '&larr;',

  showOtherMonths: true,

  changeMonth: true,

        changeYear: true,

  dateFormat: 'dd-mm-yy',

  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

      showAnim: "slide"

 });</script> 	

								

                                                    </div>

                                                    </div></div>
						  

									

									

													</div>

													
<div class="col-sm-12 col-xs-12"><div class="form-group">
									
<div class="record-content table-responsive"><a class="btn btn-success add-more" onClick="callAddContact();" >+ Add More</a>&nbsp;&nbsp &nbsp;&nbsp;<a class="btn btn-success add-more" style="cursor:pointer; margin-left:20px" onClick="delRow();" title="Click to remove">
								  <span class="glyphicon glyphicon-remove"></span>&nbsp;Del							</a><br /><br />
						  <table class="table table-striped table-bordered" id="cntTable">
							
								<tr bgcolor="#C5DFFA" >
								
								<td width="100px" ></td>
									<td height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong> Description</strong></div></td>
									<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>Qty</strong></div> </td>
														<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>Price</strong></div> </td>
																		<td  height="28"valign="middle" nowrap="nowrap" ><div align="left" style="padding-left:5px;"><strong>HSN COde</strong></div> </td>

									
							</tr>							<tbody> 

							<script>
							 var tbl = document.getElementById('cntTable');
	 var lastRow = tbl.rows.length;
	 // if there's no header row in the table, then iteration = lastRow + 1
	 var iteration = lastRow;
	 var row = tbl.insertRow(lastRow);
	 var node1;
	 var lineno = lastRow;
	 // cell 0
	 var cellLeft = row.insertCell(0);
	 cellLeft.className = "center";
		var node = document.createElement('span');
		node.className = "";
		node.title="";
		var link = document.createElement("a");
		link.className = "btn btn-success add-more";
		link.style.padding = "0px 2px";
		link.href="javascript:callRemoveContact("+lineno+");";
		link.appendChild(node);
		cellLeft.appendChild(link);
	 
	var cell1 = row.insertCell(1); 
    var nodegend = document.createElement('textarea');
    nodegend.className = 'form-control';
 nodegend.name = "details"+lineno;
 nodegend.id = "details"+lineno;
 var opt = nodegend.options;

	   nodegend.required='true';

cell1.appendChild(nodegend);
	 
	 
	 var cell2 = row.insertCell(2); 
    var nodegend = document.createElement('input');
    nodegend.className = 'form-control';
 nodegend.name = "qty"+lineno;
 nodegend.id = "qty"+lineno;
 var opt = nodegend.options;
 
	   nodegend.required='true';

cell2.appendChild(nodegend);
	 
	 
	 	 
	 var cell3 = row.insertCell(3); 
    var nodegend = document.createElement('input');
    nodegend.className = 'form-control';
 nodegend.name = "price"+lineno;
 nodegend.id = "price"+lineno;
 var opt = nodegend.options;
 
	   nodegend.required='true';

cell3.appendChild(nodegend);
	 
	 
	 var cell4 = row.insertCell(4); 
    var nodegend = document.createElement('select');
    nodegend.className = 'form-control';
 nodegend.name = "HSN_code"+lineno;
 nodegend.id = "HSN_code"+lineno;
 var opt = nodegend.options;
 <?php 
  $query21 = "select * from  HSN_code_master ";

     // echo $query21;
       $result21 = mysqli_query($conn,$query21);
       $total = mysqli_num_rows($result21);
        while($row=mysqli_fetch_array($result21))
           {
$HSN_code = $row['HSN_code'];
 ?>
opt[opt.length] = new Option('<? echo $HSN_code ?>','<? echo $HSN_code ?>');
<? } ?>
cell4.appendChild(nodegend);
	 
	 
	
 

	
	 
		
	</script>

							</tbody>
						</table>
									<input id="allcontypes" name="allcontypes" value="Decision Maker~^~Influencer~^~Recommender~^~User~^~Purchase Officer" type="hidden">
						<input name="cntlnos" id="cntlnos" value="" type="hidden">
						<input name="cntcount" id="cntcount" value="1" type="hidden">
						<input name="cntdelids" id="cntdelids" value="" type="hidden">
													</div></div>
													
													
                                                    
                                        
                                    </div>
													

                                                    <div class="col-sm-12 col-xs-12"><div class="m-t-20"><div class="form-group"><div>

                                                    <button type="submit" class="btn btn-primary waves-effect waves-light"> Submit </button>

                                                    </div></div></div></div>

                                        

                                    </div>

													

                                                    

                                        

                                    </div>

                                </div></form>

                            </div>

                        </div>

                    </div>

					

					

					

					<!------ View Start ---------------->

					

					

					

					

					

					

					<!--- View ends --------------->

					

					

					

					

					

                </div>

            </div><script type="text/Javascript">

			
			
			
	function callAddContact()
	{
     var tbl = document.getElementById('cntTable');
	 var lastRow = tbl.rows.length;
	 // if there's no header row in the table, then iteration = lastRow + 1
	 var iteration = lastRow;
	 var row = tbl.insertRow(lastRow);
	 var node1;
	 var lineno = lastRow;
	 // cell 0
	 var cellLeft = row.insertCell(0);
	 cellLeft.className = "center";
		var node = document.createElement('span');
		node.className = "";
		node.title="";
		var link = document.createElement("a");
		link.className = "btn btn-success add-more";
		link.style.padding = "0px 2px";
		link.href="javascript:callRemoveContact("+lineno+");";
		link.appendChild(node);
		cellLeft.appendChild(link);
		var cell1 = row.insertCell(1); 
    var nodegend = document.createElement('textarea');
    nodegend.className = 'form-control';
 nodegend.name = "details"+lineno;
 nodegend.id = "details"+lineno;
 var opt = nodegend.options;

	   nodegend.required='true';

cell1.appendChild(nodegend);
	 

	 
	 var cell2 = row.insertCell(2); 
    var nodegend = document.createElement('input');
    nodegend.className = 'form-control';
 nodegend.name = "qty"+lineno;
 nodegend.id = "qty"+lineno;
 var opt = nodegend.options;
 
	   nodegend.required='true';

cell2.appendChild(nodegend);
	 
	 
	 	 
	 var cell3 = row.insertCell(3); 
    var nodegend = document.createElement('input');
    nodegend.className = 'form-control';
 nodegend.name = "price"+lineno;
 nodegend.id = "price"+lineno;
 var opt = nodegend.options;
 
	   nodegend.required='true';

cell3.appendChild(nodegend);
	 
	 
	 var cell4 = row.insertCell(4); 
    var nodegend = document.createElement('select');
    nodegend.className = 'form-control';
 nodegend.name = "HSN_code"+lineno;
 nodegend.id = "HSN_code"+lineno;
 var opt = nodegend.options;
 <?php 
  $query21 = "select * from  HSN_code_master ";

     // echo $query21;
       $result21 = mysqli_query($conn,$query21);
       $total = mysqli_num_rows($result21);
        while($row=mysqli_fetch_array($result21))
           {
$HSN_code = $row['HSN_code'];
 ?>
opt[opt.length] = new Option('<? echo $HSN_code ?>','<? echo $HSN_code ?>');
<? } ?>
cell4.appendChild(nodegend);
	 
	 
	
  
		
	document.getElementById('cntcount').value = lineno;
	
}

function delRow()
{

    var tableName = document.getElementById('cntTable');

    var prev = tableName.rows.length;

    if(prev > 1)

{
    

/////////////////////////////////////////////////////////////////////////////////////
   
	 // if there's no header row in the table, then iteration = lastRow + 1
	
	 var row = document.getElementById('cntTable').deleteRow(prev-1);
	 
	 }
	 var node1;
	  var iteration = lastRow;
	 var lastRow = tableName.rows.length;
	 var lineno = lastRow;
document.getElementById('cntcount').value = lineno-1;




}

			


</script>

			<script>$(".datepicker_y").datepicker({

  inline: true,

  

  nextText: '&rarr;',

  prevText: '&larr;',

  showOtherMonths: true,

  changeMonth: true,

        changeYear: true,

  dateFormat: 'dd-mm-yy',

  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

      showAnim: "slide"

 });</script> 		<script type="text/javascript" src="js/date-time-picker.js"></script>

 

 <script type="text/javascript">

	$(document).ready(function(){

       

       let tag ="companyList"; 

       let select_menu=$('#company_list')[0]; // this expression is same as document.getElementById('dynamic_menu')

       $.ajax({

            url:"ajax.php",

            dataType:"json",

            method:"post",

            data:{tag:tag},

            success:function(response){

                //alert(response.length);

                console.log($.isArray(response)); // if response is an array, this function will return true



                response.forEach((item,index)=>{

                    console.log(index,item);

                    var option = document.createElement("option");

                    option.value = item['transporter_id'];

                    option.text = item['transporter_name'];

                    select_menu.appendChild(option);

                })

            }

        })

	});

    

    //Getting Item List on the basis of company_id

    function getItemList(company_id)

    {

        let tag = "itemList";

        let itemMenu =$('#item_list')[0];



        //Removing all the old options from item list and model list and adding only one option in one go

        $('#item_list').empty().append('<option>Select Vehicle No.</option>');



        $.ajax({

            url:"ajax.php",

            dataType:"json",

            method:"post",

            data:{tag:tag,company_id:company_id},

            success:function(response){

                response.forEach((item,index)=>{

                    console.log(index,item);

                    var option = document.createElement("option");

                    option.value = item['vehicle_no'];

                    option.text = item['vehicle_no'];

                    itemMenu.appendChild(option);

                })

            }

        })

    }



    //Getting model list on the basis of item id







</script>

            <?php include 'footer_table.php';?>

