
<?php $__env->startSection('title','Customer Receipt'); ?>
<?php $__env->startSection('main'); ?>
<div class="container-fluid ">

<form id="CReceipt" class="form-inline">
    
    <div class="row">
        <div class="col-md-6">
                <div class="card">
              <div class="card-header ">
                 <div class="row">
                     <div class="col-5">Customer Receipt (Add New)</div>
                     <div class="col-7 text-end text-muted">last Updated <?php echo e(date('d-M-y H:i:s') . ' ' . session()->get('user_name')); ?></div>
                 </div>
              </div>
              <div class="card-body" id="card-sm">
                    <div class="row">
                      <div class="col-md-4"><p>Receipt No</p></div>
                      <div class="col-md-8"><input type="text" id = "voucher_id" class="form-control  form-control-sm" disabled readonly></div>
                    </div>
                    <div class="row">
                      <div class="col-md-4"><p>Date</p></div>
                      <div class="col-md-8">
                            <input type="date" value="<?php echo e(now()->format('Y-m-d')); ?>" class="form-control form-control-sm " name="date" placeholder="Enter Your Date Here"  id="date" >
                            <span class="error_date"></span>
                      </div>
                    </div>   
                    <div class="row">
                      <div class="col-md-4"><p>Maunal No</p></div>
                      <div class="col-md-8"><input type="text"  class="form-control-sm form-control" name = "manual_no" placeholder="Manual No"></div>
                    </div>      
                    <div class="row">
                      <div class="col-md-4"><p>Project ID</p></div>
                      <div class="col-md-8"><input type="text" id="projectid" name="projectid" class="form-control-sm form-control " placeholder="id">                    </div>
                      
                    </div>         
                    <div class="row">
                      <div class="col-md-4"><p>Project Name</p></div>
                      <div class="col-md-8">

                        <input list="project_name_options" id="project_name" name="project_name" placeholder="Project Name" autocomplete="off" class="form-control form-control-sm">
                        
                        <datalist id="project_name_options">
                                <?php $__currentLoopData = $projectdata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option data-id="<?php echo e($data->id); ?>" value="<?php echo e($data->project_name); ?>"> 
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </datalist>
                
                      </div>     
                    </div>  
                <div class="row">
                      <div class="col-md-4"><p>Unit No</p></div>
                      <div class="col-md-8">
                          
                        <input list="unit_no_options" id="unit_no" name="unit_no" autocomplete="off" class="form-control form-control-sm" placeholder="Unit No">
                        
                        <datalist id="unit_no_options">

                        </datalist>
                        
                      </div>
                    </div>   
                    <div class="row">
                      <div class="col-md-4"><p>Account-Code</p></div>
                      <div class="col-md-4"><input type="text" id="headercode" value="<?php echo e(old('headercode')); ?>" name="headercode" class="form-control form-control-sm " placeholder="like 101"></div>
                      <div class="col-md-4"><input type="text" id="accountid" value="<?php echo e(old('accountid')); ?>"name="accountid" class="form-control form-control-sm " placeholder="like 123"></div>
                      
                    </div>    
                    
                    
                    <div class="row">
                      <div class="col-md-4"><p>Account Name</p></div>
                      <div class="col-md-8">
                            <input type="text"  list="account_name_options" id="account_name" name="account_name" placeholder="Account Name"  value="<?php echo e(old('account_name')); ?>" class="form-control form-control-sm">
                            <datalist id="account_name_options">

                            </datalist>
                        
                      </div>
                    </div>    
                    <div class="row">
                      <div class="col-md-4"><p>Category (Floor)</p></div>
                      <div class="col-md-8"><input type="text" id="category" value="<?php echo e(old('category')); ?>" name="category" class="form-control form-control-sm " placeholder="Category"></div>
                    </div> 
                    
                    
                     <div class="row d-none">
                      <div class="col-md-4"><p>Payment Type</p></div>
                      <div class="col-md-8"><input type="text" list="payment_type_options" id="payment_type" value="Cash" name="payment_type" class="form-control form-control-sm " placeholder="Payment Type" onchange="myFunction(this.value);"></div>
                      <datalist id="payment_type_options">
                        <option>Cash</option>
                        <option>Cheque</option>
                        </datalist>
                    </div> 
                    
                    <div class="row">
                      <div class="col-md-4"><p>Total Amount</p></div>
                      <div class="col-md-8"><input type="text" class="form-control form-control-sm " value="<?php echo e(old('amount')); ?>" name="amount" placeholder="Total Amount" autocomplete="off" onchange="inWords(this.value);"></div>
                      
                    </div>             
                    <div class="row mb-md-2">
                      <div class="col-md-4"><p>Description</p></div>
                      <div class="col-md-8">
                          <input type="text" name="desc" value="<?php echo e(old('desc')); ?>" class="form-control form-control-sm">
                    </div>
                    </div>
            </div>
    
    
            </div>
      </div>
        <div class="col-md-6">
        <table id="payment_type_form">
          <thead>
            <tr>
              <th scope="col">Payment Type</th>
              <th scope="col">Date</th>
              <th scope="col">Chqs & TC</th>
              <th scope="col">Total</th>
        
              <th scope="col"><a href ="javascritp:;" class="btn btn-success btn-sm addRow">+</a></th>
            </tr>
          </thead>
          <tbody id="cash_type">
            <tr>
              <td><input type="text" id="bank_name" name="bank_name[]" class="form-control form-control-sm rounded-0" value="Cash"></td>
              <td><input type="date" id="cheque_date" name="cheque_date[]" value="<?php echo e(now()->format('Y-m-d')); ?>" class="form-control form-control-sm rounded-0"></td>
              <td><input type="text" id="cheque_no" name="cheque_no[]" class="form-control form-control-sm rounded-0" ></td>
              <td><input type="text" id="total_cr" name="total_cr[]" class="form-control form-control-sm rounded-0" autocomplete="off"></td>
              <td><a href ="javascritp:;" class="btn btn-danger btn-sm deleteRow">-</a></td>
            </tr>
          </tbody>
        </table>
        
<button type="button" class="btn btn-warning btn-sm mt-2" id="ledger">Refresh</button>
        
<table class="table">
  <thead>
    <tr>
      <th scope="col">Date</th>
      <th scope="col">Description</th>
      <th scope="col">Debit</th>
      <th scope="col">Credit</th>
    </tr>
  </thead>
  <tbody id="data">
    
  </tbody>
</table>

       <span id="inword"></span>
       <table class="mt-2 ml-2">
    <tr>
        <td style="width:50%;"><button type="button" id="savebtn" class="btn btn-sm btn-success" style="width:100%;">Save</button></td>
        <td style="width:50%;"><a href="<?php echo e(route('Cvoucher.index')); ?>" class="btn btn-sm btn-primary" style="width:100%;">Lookup Vouchers</a></td>
    </tr>
</table>
                    
                    
                    
                                    
   
            

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

        

                

</div>      

<script>

function date_validation(dt){
    
    
    const date = new Date();

let currentDay= String(date.getDate()).padStart(2, '0');

let currentMonth = String(date.getMonth()+1).padStart(2,"0");

let currentYear = date.getFullYear();

// we will display the date as DD-MM-YYYY 

let currentDate = `${currentYear}-${currentMonth}-${currentDay}`;

    
    if (dt <= currentDate){
        document.getElementById("dt").innerHTML = '';
    }
    else{
        $('#date').val( currentDate );
    }
}
var spinner = '<div class="spinner-border" role="status"> <span class="sr-only">Loading...</span></div> &nbsp; Wait...';


function inWords (num) {

    var a = ['','One ','Two ','Three ','Four ', 'Five ','Six ','Seven ','Eight ','Nine ','Ten ','Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ','Sixteen ','Seventeen ','Eighteen ','Nineteen '];
    var b = ['', '', 'Twenty','Thirty','Forty','Fifty', 'Sixty','Seventy','Eighty','Ninety'];

    if ((num = num.toString()).length > 9) return 'overflow';
    n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
    if (!n) return; var str = '';
    str += (n[1] != 0) ? (a[Number(n[1])] || b[n[1][0]] + ' ' + a[n[1][1]]) + 'Crore ' : '';
    str += (n[2] != 0) ? (a[Number(n[2])] || b[n[2][0]] + ' ' + a[n[2][1]]) + 'Lakh ' : '';
    str += (n[3] != 0) ? (a[Number(n[3])] || b[n[3][0]] + ' ' + a[n[3][1]]) + 'Thousand ' : '';
    str += (n[4] != 0) ? (a[Number(n[4])] || b[n[4][0]] + ' ' + a[n[4][1]]) + 'Hundred ' : '';
    str += (n[5] != 0) ? ((str != '') ? 'and ' : '') + (a[Number(n[5])] || b[n[5][0]] + ' ' + a[n[5][1]]) : '';

    $('#inword').val(str);
    
    
    $('#inword').empty();
                
    document.getElementById("inword")
                .innerHTML += str;

    
}

function print(){
    
    var id = $('#voucher_id').val();
    var url = "/Cvoucher/show/" + id;
    window.open(url);
}

$('#savebtn').click(function(){
    $("#savebtn").attr("disabled", true);
    
    var lastid = $('#voucher_id').val();
    
    console.log(lastid);
    if (lastid > 0){
        
        return;
    }
    
    
    $('#savebtn').html(spinner);
    var form = $('#CReceipt')[0];
    var formdata = new FormData(form);
    
    

    
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

    $.ajax({
                url: '<?php echo e(route("CReceipt.add")); ?>',
                type: 'POST',
                processData: false, contentType: false,
                data: formdata,

                success: function(result){
                    
                    $('#savebtn').text('Save');
                    window.location.reload();  
                    $("#savebtn").attr("disabled", false);

                },
                error: function(error){
                     $("#savebtn").attr("disabled", false);
                    $('#savebtn').text('Save');
                                            Toastify({ text: "Sorry Could Not Save !", duration: 3000, gravity: "bottom", // `top` or `bottom`
  position: "right", // `left`, `center` or `right`
        style: { background: "linear-gradient(to right, #B32A0C, #F87255)" }
    }).showToast();
                    
                }
            });


});

$("#project_name").on('change', function () {
    
    $("#unit_no_options").empty();

    var value = $('#project_name').val();
    projectid = $('#project_name_options [value="' + value + '"]').data('id');
    $('#projectid').val( projectid );
    

            $.ajax({
                url: '<?php echo e(route("Cvoucher.customers")); ?>',
                type: 'POST',
                data: 'projectid='+projectid+'&_token=<?php echo e(csrf_token()); ?>',

    
                success:function(result){
                       
                       
                        $.each(result.accounts, function (key, value) {
                            $("#unit_no_options").append('<option data-account_name=" ' + value.customer_name + '" data-category=" ' + value.category + '" data-headercode="' + value.header_code + '" data-accountid="' + value.id + '" value="' + value.unit_no + '">' +  value.unit_no  +  '</option>');
                            $("#account_name_options").append('<option data-unit_no=" ' + value.unit_no + '" data-category=" ' + value.category + '" data-headercode="' + value.header_code + '" data-accountid="' + value.id + '" value="' + value.customer_name + '">' +  value.customer_name  +  '</option>');
                        });                        


                }

            });    

})

$("#unit_no").on('change', function () {
    
    var value = $('#unit_no').val();
    accountid = $('#unit_no_options [value="' + value + '"]').data('accountid');
    headercode = $('#unit_no_options [value="' + value + '"]').data('headercode');
    category = $('#unit_no_options [value="' + value + '"]').data('category');
    account_name = $('#unit_no_options [value="' + value + '"]').data('account_name');
    
    $('#accountid').val( accountid );
    $('#headercode').val( headercode );
    $('#category').val( category );
    $('#account_name').val( account_name );
    
})

$('#account_name').change(function(){
    
    var value = $('#account_name').val();
    accountid = $('#account_name_options [value="' + value + '"]').data('accountid');
    headercode = $('#account_name_options [value="' + value + '"]').data('headercode');
    category = $('#account_name_options [value="' + value + '"]').data('category');
    unit_no = $('#account_name_options [value="' + value + '"]').data('unit_no');
    
    $('#accountid').val( accountid );
    $('#headercode').val( headercode );
    $('#category').val( category );
    $('#unit_no').val( unit_no );
    
    

});

document.getElementById("project_name").focus();

$("input,select").bind("keydown", function(event) {
    if (event.which === 13) {
        event.stopPropagation();
        event.preventDefault();
       $(':input:eq(' + ($(':input').index(this) + 1) +')').focus();
    }
});

$('thead').on('click', '.addRow', function(){
 var tr = '<tr>'+
      '<td><input type="date" id="cheque_date" name="cheque_date[]" value="<?php echo e(now()->format('Y-m-d')); ?>" class="form-control form-control-sm rounded-0"></td>'+
      '<td><input type="text" id="bank_name" name="bank_name[]" class="form-control form-control-sm rounded-0" ></td>'+
      '<td><input type="text" id="cheque_no" name="cheque_no[]" class="form-control form-control-sm rounded-0" ></td>'+
      '<td><input type="text" id="total_cr" name="total_cr[]" class="form-control form-control-sm rounded-0" ></td>'+
      '<td><a href ="javascritp:;" class="btn btn-danger btn-sm deleteRow">-</a></td>'+
    '</tr>';
    
$('#cash_type').append(tr);

});

$('tbody').on('click', '.deleteRow', function(){
    $(this).parent().parent().remove();
});


$('#ledger').click(function(){
    
    
     var account_id = document.getElementById("accountid").value;
   
    
                 $.ajax({
                url: '<?php echo e(route("Customer.Ledger")); ?>',
                type: 'POST',
                data: 'account_id='+account_id+'&_token=<?php echo e(csrf_token()); ?>',

                success:function(result){
                        $('#data').html(result);
                }

            });
            
            
})

</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/alameenb/public_html/resources/views/Cvoucher/add.blade.php ENDPATH**/ ?>