<?php
include 'class/ClassForm.php';
$query = "select distinct * from inv_template ";
$result = $ClassForm->Fetch_Result_Set($query);
?>
<div id="formData" class="col-lg-12">
<form id="invoiceForm" name="invoiceForm" enctype="multipart/form-data" class="form-horizontal" method="post" action="javascript:;" >
        <div class="form-group row">
            <label class="control-label col-lg-4">Select Template <em class="required">&nbsp;*</em></label>
            <div class="col-lg-4">
                <select name="template_select" id="template_select" class="form-control col-lg-12">
                <option selected value="0">Please Select Template </option>
               <?php 
               while ($row = mysqli_fetch_assoc($result)){
                   ?>
                    <option value="<?php echo $row['id']; ?>"><?php echo $row['template_name']; ?> </option>
                   <?php
               }
               ?>     
                </select>
            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <i class="feather info" data-toggle="tooltip" data-placement="top" title="in Domestic invoice,please Ignore 	total cost,Markup and Currency" />
            </div>
        </div>
        <div class="row">
            <div class="col-lg-6">
                <div class="form-group row">
                    <label class="control-label col-lg-6">Invoice No<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_no" name="inv_no"  class="form-control " />
                        <label id="dc_avail_result" for="dc_avail_result">Please Enter Invoice No</label>
                    </div>
                </div>        
                <div class="form-group row">
                    <label class="control-label col-lg-6">Invoice Date<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_date" name="inv_date"  class="form-control form_date" />
                    </div>
                </div>
                <div class="form-group row">                    
                    <label class="control-label col-lg-6 float-left">Billed To <em class="required">&nbsp;*</em> </label>                    
                    <div class="col-lg-6 float-right">                
                        <input type="text"  name="inv_name" id="inv_name" class="form-control " />                        
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-lg-6 float-left">
                        <label class="control-label float-left">Billed To Address<em class="required">&nbsp;*</em> </label>
                        <br/>
                        <br/>
                    </div>
                    <div class="col-lg-6 float-right">
                        <input type="text"  name="inv_addr[]"  class="form-control " />
                        <input type="text"  name="inv_addr[]"  class="form-control " />
                        <input type="text"  name="inv_addr[]"  class="form-control " />
                        <input type="text"  name="inv_addr[]"  class="form-control " />
                    </div>
                </div>                
                <div class="form-group row">
                    <label class="control-label col-lg-6">GSTIN<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_gstin" name="inv_gstin"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">PAN<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_pan" name="inv_pan"  class="form-control " />
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="form-group row">
                    <label class="control-label col-lg-6">Service Code Tariff<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_supplyMode" name="inv_supplyMode"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Place of supply<em class="required">&nbsp;*</em> </label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_pos" name="inv_pos"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">State Code</label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_statecode" name="inv_statecode"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Country of Destination</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_LUTdetails" name="inv_LUTdetails" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
                
                
            </div>            
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="form-group row">
                    <label class="control-label col-lg-6">IRN No</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_Btmdetails" name="inv_Btmdetails" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Import / Export Code</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_Btmdetails" name="inv_Btmdetails" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Contract / Purchase order no and Date</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_Btmdetails" name="inv_Btmdetails" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="row justify-content-center">
            <table id="product_table">
                <thead>
                    <th>particulars</th>
                    <th>total cost</th>
                    <th>Markup</th>
                    <th>Currency</th>
                    <th>Total Amound</th>
                    <th></th>
                </thead>
                <tbody>
                    <tr >
                        <td>
                            <input type="text"  name="inv_product_desc[]" class="form-control"/>
                        </td>
                        <td>
                            <input type="text"  name="inv_product_Hsn[]" class="form-control"/>
                        </td>
                        <td>
                            <input type="text" name="inv_product_Qty[]" class="form-control"/>
                        </td>
                        <td>
                            <input type="text" name="inv_product_Price[]" class="form-control"/>
                        </td>     
                        <td>
                            <input type="text" name="inv_product_Price[]" class="form-control"/>
                        </td>                    
                        <td>
                            <input value="Remove" class="button btn-danger btnDelete" type='button' />
                        </td>
                    </tr>
                    <tr class="ui-widget-header"> 
                        <td colspan="5" >
                            <input value="Add another details" class="button btn-primary" type='button' onclick="addProduct();" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <br/>
        <br/>
        <br/>
        <div class="row col-lg-12">
            <div class="col-lg-6">
                <div class="form-group row">
                    <label class="control-label col-lg-6">Tax Description</label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_taxdesc" name="inv_taxdesc"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">CGST (Percentage)</label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_taxCGST" Value="Zero Rated " name="inv_taxCGST"  class="form-control " />
                    </div>
                </div>                
            </div>
            <div class="col-lg-6 float-right">
                <div class="form-group row">
                    <label class="control-label col-lg-6">Bottom Description</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_Declaration" name="inv_Declaration" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Payment Instruction</label>
                    <div class="col-lg-6 float-right">                
                        <textarea id="inv_Declaration" name="inv_Declaration" form="invoiceForm"  class="form-control " ></textarea>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Place</label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_placeBtm" name="inv_placeBtm"  class="form-control " />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-lg-6">Date</label>
                    <div class="col-lg-6 float-right">                
                        <input type="text" id="inv_dateBtm" name="inv_dateBtm"  class="form-control form_date" />
                    </div>
                </div>
            </div>
        </div>
        <div class="row col-lg-12 center">
            <input class="btn btn-info center" type="submit" />
        </div>        
</form>
</div>
<div id="formDisplay" style="display:none;"></div>
<script src="Header/scripts/pr_form.js" ></script>
<script>
$(document).ready(function(){ 
    $('[data-toggle="tooltip"]').tooltip();   
    $('#invoiceForm').on('submit',function(event){
        event.preventDefault();           
        var formData = new FormData($('#invoiceForm')[0]);
        $.ajax({
                url : 'db/SaveDisplay.php',
                type : 'POST',                
                data: formData,
                contentType: false,
                processData: false,                               
                success: function (response){                           
                    // $('#formData').hide();
                    $('#formDisplay').html(response);
                    $('#formDisplay').show();
                }
            });
    });

    

   
    
});

function addProduct(){
    var $lastRow = $("[id$=product_table] tr:not('.ui-widget-header'):last");     
    var $newRow = $lastRow.clone();
    $newRow.find(":text").val(""); //clear out textbox values    
    $lastRow.after($newRow);
}
$("#product_table").on('click', '.btnDelete', function () {
    $(this).closest('tr').remove();
});

$('#invoice').ready(function(){
    var value = convertNumberToWords($(".totalVal").html());    
    $('.rsTowrd').html(value);
});
</script>
