@include('header')
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">Add New Vendor Bill</h4>

    <form id="validation-form" method="POST" action=""  enctype="multipart/form-data">

        <input type="hidden" name="action" id="action" value="Save">
        <input type="hidden" name="saveid" id="saveid" value="">
        @csrf
        <div class="card mb-12 mb-4">
            <div class="card-body">
                <div class="row">


                  
                    <div class="col-sm-5">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Vendor Name <span
                                    class="text-danger">*</span></label>
                                <select class="select2-demo form-control" id="VedId" name="VedId" required>
                                    <option value="" selected>Select </option>
                                @foreach($data as $result)
                                <option value="{{$result->id}}">{{$result->VedName}}</option>
                                @endforeach
                                </select>
                        </div>
                    </div>
                    <div class="col-sm-1" style="padding-top: 28px;">
                        <div class="form-group">
                        <label class="floating-label" for="Name">&nbsp; </label>  
                        <button class="btn btn-secondary" type="button" 
                                        onclick="addNewVendor()">+</button>          
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Bill No </label>
                            <input type="text" class="form-control" name="BillNo" id="BillNo" placeholder=""
                                value="" required>
                        </div>
                    </div>


                    <div class="col-sm-3">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Bill Date </label>
                            <input type="date" class="form-control" name="BillDate" id="BillDate" placeholder=""
                                value="" required>
                        </div>
                    </div>

                    <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Amount <span
                                        class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Amount" Name="Amount" placeholder=""
                                    value="" required>
                            </div>
                        </div>

                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Payment Mode <span
                                        class="text-danger">*</span></label>
                                <select class="form-control" id="PayMode" name="PayMode" required>
                                    <option value=""></option>
                                    <option value="Cash">Cash</option>
                                    <option value="Cheque">Cheque</option>
                                     <option value="Mobile Payment">Mobile Payment</option> 
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Cheque No</label>
                                <input type="text" class="form-control" id="ChequeNo" Name="ChequeNo" placeholder="">
                            </div>
                        </div>

                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Upload Receipt</label>
                                <input type="file" class="form-control" id="Files" Name="Files" placeholder="">
                            </div>
                        </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="floating-label" for="Name">Description </label>
                            <textarea class="form-control" name="Details" id="Details" placeholder=""
                                value=""></textarea>
                        </div>
                    </div>
                    

                    
                    <div class="col-sm-6" style="padding-top:20px;">
                        <button class="btn btn-primary" type="submit" name="submit" id="submit">Save</button>
                       
                    </div><br>
                    

                    <input type="hidden" id="CurrDate" value="{{date('Y-m-d')}}">

                </div>
            </div>



    </form>


</div>

<script src="{{url('assets/js/jquery-3.6.0.min.js')}}"></script>
@include('footerscript')
<script>
 function addNewVendor(){
    setTimeout(function() {
            window.open('/{{projectUrl()}}addNewVendor', 'popUpWindow',
                'height=1000,width=1000,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
 }
function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'New Vendor Receipt Created Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

function error_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.error({
        title: 'Error',
        message: 'Record Not Saved',
        location: isRtl ? 'tl' : 'tr'
    });
}

$(document).ready(function() {
    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveVendorReceipt') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    if (data == 1) {
                        success_toast();
                        window.location.href = "{{ url('vendorReceipt') }}";
                    } else {
                        error_toast();
                    }
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Save');
                }
            });
        }
    });




});
</script>