<?php
include('../include/header.php');
?>

 <!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Bread crumb -->
            <div class="row page-titles">
                <div class="col-md-5 align-self-center">
                    <h3 class="text-primary">Dashboard</h3> </div>
                <div class="col-md-7 align-self-center">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0)">Home</a></li>
                        <li class="breadcrumb-item active">Add Identity</li>
                    </ol>
                </div>
            </div>
            <!-- End Bread crumb -->
            <!-- Container fluid  -->
           <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row justify-content-center">
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="form-validation">
                                    <form class="form-valide" method="post">
                                        <div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Billing Type<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type="text" class="form-control" name="billing" id="billing" required >
                                            </div>
                                        </div>
										
										 <table id="dynamic3" class="table " style="width:100%;" >								<thead>
								
								<th>Serial No</th>
								<th>Term</th>
								
								<th>Action</th>
								</thead>
							 <tbody>
							 <tr>
							<td><div class="form-group">
                                                    
                                                    <input type="number" style="width:60px;" name="serial[]" id="serial" class="form-control" >
                                                </div>
</td>
<td><div class="form-group">
                                                    
                                                    <input type="text"  name="term[]" id="term" class="form-control" >
                                                </div>
</td>

<td><button type="button" name="addd" class="btn btn-primary btn-sm" id="add_input3">Add</button>          
</td>
								
								
								</tr>
								
								</tbody>
								
                               </table>
                                        
                                        <div class="form-group row">
                                            <div class="col-lg-8 ml-auto">
                                                <button type="submit" class="btn btn-primary" name="save">Submit</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
			
<?php 
	if(isset($_POST["save"]))
	{
		$billing = $_POST["billing"];
		$serial = $_POST["serial"];
		$term = $_POST["term"];

		
$sql_bill = "INSERT INTO tbl_billing_term_mstr (id, type_of_billing) VALUES('', '$billing');";
$master_id = $objhr->insertion_last_id_view($sql_bill);

$totalserial = sizeof(@$serial);
	for($i=0; $i<$totalserial; $i++) {

    $Insertserail_no = $serial[$i];
    $Insertterm = $term[$i];
	$sql_insert = "INSERT INTO tbl_billing_term_detail (bill_term_master_id, serial_no, terms) VALUES('$master_id','$Insertserail_no', '$Insertterm');";
	$result_insert = $objhr->insertion($sql_insert);
	}
 ?>
 <script>
 alert('Success');
 location='';
 </script>
 <?php
 
	}

 ?>
<?php
include('../include/footer.php');
?>
<script>
$(document).ready(function(){
 var i=1;
 $('#add_input3').click(function(){
 i++;
 $('#dynamic3').append('<tr id="row'+i+'"><td><div class="form-group"><input type="number" style="width:60px;" name="serial[]" id="serial" class="form-control" ></div></td><td><div class="form-group"><input type="text"  name="term[]" id="term" class="form-control" ></div></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn-sm btn_remove">Remove</button></td></tr>');
 });
 $(document).on('click', '.btn_remove', function(){
 var button_id = $(this).attr("id");
 $('#row'+button_id+'').remove();
 });

 
});
</script>