VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /home/vapecompany/demo.vapecompany.com.bd/resources/views/backend/chalan/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/vapecompany/demo.vapecompany.com.bd/resources/views/backend/chalan/edit.blade.php
@extends('backend.layout.app')
@section('content')
      <style type="text/css">
          .btn-file {
                position: initial;
                overflow: hidden;
            }
            .btn-file input[type=file] {
                position: absolute;
                top: 0;
                right: 0;
                min-width: 100%;
                min-height: 100%;
                font-size: 100px;
                text-align: right;
                filter: alpha(opacity=0);
                opacity: 0;
                outline: none;
                background: white;
                cursor: inherit;
                display: block;
            }

            #img-upload{
               width: 100%;
               height: 100%
            }
            #img-container{
                width: 100px;
                height: 100px;
                margin: 10px 0;
                border: 1px solid;
            }
            #checkerr .text-danger{
                position: absolute;
                top: 80px;
            }
            #imgerr label{
                    top: 32px;
                    position: absolute;
                    left: 105px;
            }

            /*new image upload css*/
            .upload-img-box {
                background-color: #f5f5f5;
                border: 1px solid #aaa;
                border-radius: 5px;
                height: 150px;
                position: relative;
            }
            .upload-img-box img {
                width: 100%;
                height: auto;
                max-height: 100%;
                margin: auto;
                display: block;
                z-index: 5;
                position: absolute;
                object-fit: cover;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
            .upload-img-box input[type="file"] {
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                opacity: 0;
                z-index: 10;
                width: 100%;
                cursor: pointer;
            }
            .upload-img-box-icon {
                color: #666;
                text-align: center;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
            }
            .tablegrid{
                border-bottom: 1px solid #eee;
                padding-bottom: 10px;

            }
            .noborder{
                border: 1px solid #fff;
            }
            a{
                 padding: 0 1vh;
            }
            /*end image upload css*/


      </style>
        <!-- ============================================================== -->
        <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-5 align-self-center">
                        <h4 class="page-title">Edit Challan</h4>
                        <div class="d-flex align-items-center">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                                    <li class="breadcrumb-item active" aria-current="page"> Challan</li>
                                </ol>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-12">

                        <div class="card">
                            <div class="card-body">
                                <form id="addRequisition" type="POST">
                                    @csrf
                                    <h4 class="card-title">Edit Challan</h4>
                                    @include('backend.layout.verror_message')
                                    <div class="form-group row">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Challan
                                            Date</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">
                                                <input type="hidden" name="chalan_id" value="{{$chalan->chalan_id}}">
                                                <input type="text" name="requisition_date" class="form-control"
                                                    value="{{$chalan->chalan_date->format('d-m-Y')}}"
                                                    id="datepicker-autoclose" placeholder="mm/dd/yyyy">
                                                <div class="input-group-append">
                                                    <span class="input-group-text"><i class="icon-calender"></i></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Invoice No.</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">
                                                <input value="{{$chalan->invoice_number}}" type="text"
                                                    name="invoice_number" class="form-control">

                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Customer</label>
                                        <div class="col-sm-9">
                                            <select name="customer" class="form-control select2 ">
                                                <option value="">Select</option>
                                                @foreach($customers as $customer)
                                                @if($chalan->customer_id == $customer->customer_id)
                                                <option selected value="{{$customer->customer_id}}">
                                                    {{$customer->customer_name}}</option>
                                                @else
                                                <option value="{{$customer->customer_id}}">{{$customer->customer_name}}
                                                </option>
                                                @endif
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Deliver
                                            Mode</label>
                                        <div class="col-sm-9">
                                            <select name="delivery_mode" id="delivery_mode"
                                                class="form-control select2 ">
                                                <option value="">Select</option>
                                                <option @if($chalan->delivery_mode == 1) selected @endif
                                                    value="1">Courier Service</option>
                                                <option @if($chalan->delivery_mode == 2) selected @endif
                                                    value="2">Others</option>


                                            </select>
                                        </div>
                                    </div>
                                    @if($chalan->delivery_mode == 1)
                                    <div class="form-group row" id="delivery_1">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Courier
                                            Name</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">

                                                <select name="courier" class="form-control select2 ">
                                                    <option value="">Select</option>
                                                    @foreach($couriers as $courier)
                                                    @if($chalan->courier_id == $courier->courier_id)
                                                    <option selected="" value="{{$courier->courier_id}}">
                                                        {{$courier->courier_name}}</option>
                                                    @else
                                                    <option value="{{$courier->courier_id}}">{{$courier->courier_name}}
                                                    </option>
                                                    @endif
                                                    @endforeach
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row" id="delivery_2">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Track No.</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">
                                                <input value="{{$chalan->track_no}}" type="text" name="trackno"
                                                    class="form-control">

                                            </div>
                                        </div>
                                    </div>
                                    @endif
                                    <div class="form-group row" id="delivery_1">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Sales Man</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">

                                                <select name="sales_man" class="form-control select2 ">
                                                    <option value="">Select</option>
                                                    @foreach($sales_man as $sale_man)
                                                    @if($sale_man->employee_id == $chalan->sales_user_id)
                                                    <option selected="" value="{{$sale_man->employee_id}}">
                                                        {{$sale_man->employee_name}}</option>
                                                    @else
                                                    <option value="{{$sale_man->employee_id}}">
                                                        {{$sale_man->employee_name}}</option>
                                                    @endif
                                                    @endforeach
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    @if($chalan->requisition_id != 0)
                                    <input type="hidden" name="requisition_id" value="{{$chalan->requisition_id}}">
                                    @else
                                    {{-- <div class="form-group row" id="delivery_2">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Requisition
                                            ID</label>
                                        <div class="col-sm-9">
                                            <div class="input-group">
                                                <input type="text" name="requisition_id" class="form-control">

                                            </div>
                                        </div>
                                    </div> --}}
                                    @endif
                                    <div class="form-group row">
                                        <label for="brand"
                                            class="col-sm-3 text-right control-label col-form-label">Remarks </label>
                                        <div class="col-sm-9">
                                            <textarea name="remarks" class="form-control" rows="3"
                                                placeholder="Text Here...">{{$chalan->remarks}}</textarea>
                                        </div>
                                    </div>








                                    <div id="cart_items">
                                        <script type="text/javascript">
                                            var cartproduct = {};
                                            var postbarcodelist = {};
                                            var barcodelist = {};
                                        </script>
                                        @foreach($chalan->chalan_details as $details)
                                        <script type="text/javascript">
                                            var uniqueid = "{{$details->product_id.'_'.$details->color_id}}";
                                        </script>
                                        @foreach($details->imeis as $barcode)
                                        <script type="text/javascript">
                                            var barcode = "{{$barcode->imei_1}}";
                                            barcodelist[barcode] = barcode;


                                            if (postbarcodelist[uniqueid] == undefined) {
                                                postbarcodelist[uniqueid] = [];
                                            }
                                            postbarcodelist[uniqueid].push(barcode);

                                            if (cartproduct[uniqueid] == undefined) {
                                                cartproduct[uniqueid] = barcode;
                                            }
                                        </script>
                                        @endforeach
                                        <div class="row form-group tablegrid"
                                            id="{{$details->product_id.'-'.$details->color_id}}">
                                            <div class="col-sm-2 text-right">
                                                <div class="img form-group">
                                                    <img style="height: 50px"
                                                        src="{{url('/public/images/product/')}}/{{$details->product->product_image}}"
                                                        class="img-fluid">
                                                    <!---->
                                                </div>
                                            </div>
                                            <div class="col-sm-5 col-xs-12">
                                                <label
                                                    class="product-title form-group"><strong>{{$details->product->product_name}}</strong></label>
                                                <input type="hidden" name="product_id[]"
                                                    value="{{$details->product->product_id}}">
                                                <input type="hidden" name="category[]" value="{{$details->category_id}}">

                                            </div>
                                            {{-- <div class="col-sm-2 col-xs-12 align-items-center justify-content-center">
                                                <label
                                                    class="product-title form-group"><strong>{{$details->color->color_name}}</strong></label>
                                                <input type="hidden" name="color[]" value="{{$details->color_id}}">
                                            </div> --}}
                                            <div class="col-sm-2 col-xs-12 align-items-center justify-content-center">
                                                <label
                                                    class="product-title form-group"><strong>{{$details->product_unit_price}}</strong></label>
                                                <input type="hidden" name="sale_price[]"
                                                    value="{{$details->product->sale_price}}">
                                            </div>
                                            <div class="col-sm-2">
                                                <div
                                                    class="input-group bootstrap-touchspin bootstrap-touchspin-injected form-group">
                                                    <span class="input-group-btn input-group-prepend">
                                                        <button
                                                            onclick="decreaseCart('demo{{$details->product_id.'-'.$details->color_id}}')"
                                                            class="btn btn-primary bootstrap-touchspin-down"
                                                            type="button">-</button>
                                                    </span>
                                                    <input id="demo{{$details->product_id.'-'.$details->color_id}}"
                                                        type="text" value="{{$details->product_quantity}}" name="qty[]"
                                                        class="form-control">
                                                    <span class="input-group-btn input-group-append">
                                                        <button
                                                            onclick="increateCart('demo{{$details->product_id.'-'.$details->color_id}}')"
                                                            class="btn btn-primary bootstrap-touchspin-up"
                                                            type="button">+</button>
                                                    </span>
                                                </div>
                                            </div>
                                            <div class="col-sm-1">
                                                <button
                                                    onclick="closeCart('{{$details->product_id.'-'.$details->color_id}}')"
                                                    data-repeater-delete=""
                                                    class="btn btn-danger waves-effect waves-light form-group"
                                                    type="button">
                                                    <i class="ti-close"></i>
                                                </button>
                                            </div>
                                        </div>
                                        @endforeach
                                    </div>
                            </div>
                            <div style="margin-top: 50px;">
                                <div style="text-align: center;padding: 10px;display: none;" id="product_exist"
                                    class="text-danger">Already Exist</div>
                                <div class="row form-group">
                                    <div class="col-sm-2 text-right control-label col-form-label">
                                        <label>Add Product</label>
                                    </div>
                                    <div class="col-sm-10">
                                        <div class="row form-group">
                                            <div class="col-sm-3">
                                                <div class="form-group">
                                                    <select onchange="get_product()" class="form-control" id="category"
                                                        name="educationDate">
                                                        <option value="">Category</option>
                                                        < @foreach($categories as $category) <option
                                                            value="{{$category->category_id}}">{{$category->category_name}}</option>
                                                            @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-sm-3">
                                                <div class="form-group">
                                                    <select class="form-control"
                                                        id="addProduct" name="educationDate">
                                                        <option>Product</option>

                                                    </select>
                                                </div>
                                            </div>
                                            {{-- <div class="col-sm-3">
                                                <div class="form-group">
                                                    <select class="form-control" id="addColor" name="educationDate">
                                                        <option>Color</option>

                                                    </select>
                                                </div>
                                            </div> --}}
                                            <div class="col-sm-3">
                                                <div class="form-group">
                                                    <input type="text" class="form-control" id="addQnantity"
                                                        name="addQnantity" placeholder="Quantity">
                                                </div>
                                            </div>
                                            {{-- <div class="col-sm-4">
                                                <div class="form-group">

                                                    <input type="text" class="form-control" id="addBarcode"
                                                        name="addBarcode" placeholder="Barcode">
                                                </div>
                                            </div> --}}
                                            {{-- <div class="col-sm-4">
                                                <div class="form-group">

                                                    <input type="text" class="form-control" id="removeBarcode"
                                                        name="removeBarcode" placeholder="Remove Barcode">
                                                </div>
                                            </div> --}}

                                            <div class="col-sm-1">
                                                <div class="form-group">
                                                    <button class="btn btn-success" type="button"
                                                        onclick="addcart();"><i class="fa fa-plus"></i></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>


                                </div>
                            </div>
                            <!--  <div class="row">
                                        <div class="col-md-6"></div>
                                        <div class="col-md-4">
                                        <div class="form-group">
                                            <div class="upload-img-box">
                                                <img src="">
                                                <input type="file" name="thumbnail" id="thumbnail" accept="image/*" onchange="previewFile(this)">
                                                <div class="upload-img-box-icon">
                                                    <i class="fa fa-camera"></i>
                                                    <p class="m-0">Add Image</p>
                                                </div>
                                            </div>
                                        </div>
                                        </div>
                                    </div> -->
                            <div class="form-group mb-0 text-right">
                                <!--      <button type="submit" name="actionss" value="draft" class="submit btn btn-info waves-effect waves-light">Draft</button> -->
                                @if($chalan->chalan_status = 1)
                                <button type="submit" name="actionsss" value="update"
                                    class=" submit btn btn-info waves-effect waves-light">Update</button>
                                @else
                                <button type="submit" name="actionsss" value="submit"
                                    class=" submit btn btn-info waves-effect waves-light">Publish</button>
                                @endif
                                <a href="{{url('chalan_list')}}" style="color:white"
                                    class="btn btn-dark waves-effect waves-light">Cancel</a>
                            </div>
                            </form>
                        </div>

                    </div>


                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End PAge Content -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Right sidebar -->
            <!-- ============================================================== -->
            <!-- .right-sidebar -->
            <!-- ============================================================== -->
            <!-- End Right sidebar -->
            <!-- ============================================================== -->
        </div>

            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            @endsection
            @section('script')
            <script src="{{ url('public/backend/js/jquery.validate.min.js') }}"></script>
            <link rel="stylesheet" type="text/css" href="{{ url('public/backend/css/bootstrap-datepicker.min.css') }}">
          <script src="{{ url('public/backend/js/bootstrap-datepicker.min.js') }}"></script>
          <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
          <script src="{{ url('public/backend/js/tinymce.min.js') }}"></script>
                <script type="text/javascript">
                    $('#delivery_mode').change(function(){
                        if(this.value == 1){
                            $("#delivery_1").show();
                            $("#delivery_2").show();
                        }else{
                             $("#delivery_1").hide();
                            $("#delivery_2").hide();
                        }
                    });
                    function get_product(){
                        var id=$('#category').val();
                            //console.log("{{url('get_productById')}}/"+id);
                        $.ajax({

                            type : 'POST',
                            url  : "{{url('admin/get_productById')}}",
                            data:{category_id:id},
                             dataType: 'json',
                            success :  function (data)
                            {

                                //var d=JSON.parse(data);

                                var color="<option>Select Product</option>";
                                $.each(data,function(){
                                    console.log(this.product_id);
                                    color +="<option value='"+this.product_id+"'> "+this.product_name+" </option>";
                                });
                               // console.log(color);
                                $('#addProduct').html(color);

                            },
                            error :  function (data)
                            {
                                //console.log(data);
                            }
                        });
                    }
                    function get_product_color(){
                        var id=$('#addProduct').val();

                        $.ajax({

                            type : 'POST',
                            url  : "{{url('get_productById')}}",
                            data:{id:id},
                             //dataType: 'json',
                            success :  function (data)
                            {

                                $('#addColor').html(data);

                            },
                            error :  function (data)
                            {
                                console.log(data);
                            }
                        });
                    }
                     function addBarcodeExtra(uniqueid){
                         var checkitem=$('#cart_items #'+uniqueid);

                        if(checkitem.length > 0){
                            var value=$('#cart_items #'+uniqueid+' #demo'+uniqueid).val();
                            //var price=$('#cart_items #'+uniqueid+' #price_demo'+tuniqueid).val();
                            //console.log(value);
                            $('#cart_items #'+uniqueid+' #demo'+uniqueid).val(parseInt(value)+1);
                            //this.value="";
                             //$('#cart_items #'+uniqueid+' #total_demo'+uniqueid).text((parseInt(value)+1 ) * parseFloat(price));
                              //$('#cart_items #'+uniqueid+' .P_total').val((parseInt(value)+1 ) * parseFloat(price));

                        }
                    }
                    $('#removeBarcode').change(function(){
                        console.log(this.value);
                        console.log(cartproduct);
                    });
                    $('#addBarcode').change(function(){


                            if(this.value){
                                if(cartproduct[this.value] == undefined)
                                {
                                    var checkitem=$('#cart_items #'+this.value);

                                    if(checkitem.length > 0){
                                        var value=$('#cart_items #'+this.value+' #demo'+this.value).val();
                                        var price=$('#cart_items #'+this.value+' #price_demo'+this.value).val();
                                        //console.log(value);
                                        $('#cart_items #'+this.value+' #demo'+this.value).val(parseInt(value)+1);
                                        //this.value="";
                                         $('#cart_items #'+this.value+' #total_demo'+this.value).text((parseInt(value)+1 ) * parseFloat(price));
                                          $('#cart_items #'+this.value+' .P_total').val((parseInt(value)+1 ) * parseFloat(price));
                                        this.value="";
                                    }else{
                                         addcart();
                                         //console.log("hi");
                                         this.value="";
                                    }
                                }else{
                                    this.value="";
                                   $('#product_exist').html("Product is already exists");
                                    $('#product_exist').show();
                                }

                            }
                    });

                     function addBarcode(product_id,color_id,uniqueid){
                        $.ajax(
                        {
                            type : 'POST',
                            url  : "{{url('add_cart_barcode')}}",
                            data : {product_id:product_id,color_id,uniqueid:uniqueid},
                            // dataType: 'json',
                            success :  function (data)
                            {
                                console.log(data);
                                if(data == '1'){
                                    $('#product_exist').show();
                                    $('#product_exist').html("Quantity is not available");
                                }else if(data == '2'){
                                    $('#product_exist').show();
                                    $('#product_exist').html("Imei Not Found !");
                                }
                                else{


                                    if($('#validateProduct').length > 0){
                                        $('#cart_items').html(data);
                                    }else{
                                        $('#cart_items').append(data);
                                    }
                                }

                            },
                            error :  function (data)
                            {
                                console.log(data);
                            }
                        });
                     }
                     var ii=0;
                    function addcart(){

                        event.preventDefault();
                        var category=$('#category').val();
                        var id=$('#addProduct').val();
                        var color=$('#addColor').val();
                        var qty=$('#addQnantity').val();
                        var barcode=$('#addBarcode').val();
                        var uniqueid=id;
                         if(barcode){
                            uniqueid=barcode;
                            console.log(cartproduct[uniqueid]);
                            if(cartproduct[uniqueid] == undefined)
                            {

                                $.ajax(
                                {
                                    type : 'POST',
                                    url  : "{{url('admin/add_cart_chalan')}}",
                                    data : {barcodelist:barcodelist,category_id:category,barcode:barcode,uniqueid:uniqueid, id: id,color:color,qty:qty },
                                    // dataType: 'json',
                                    success :  function (data)
                                    {
                                        console.log(data.error == 1);
                                        if(data.error == 1){
                                            $('#product_exist').html("Product is already exists");
                                            $('#product_exist').show();
                                        }else{
                                            $('#product_exist').hide();

                                             uniqueid=data.product_id+'_'+data.color_id;
                                             barcodelist[barcode]=barcode;
                                             console.log(postbarcodelist[data.product_id] ? postbarcodelist[data.product_id] : 0);
                                             ii++;
                                            if(postbarcodelist[uniqueid] == undefined){
                                                postbarcodelist[uniqueid] =[];
                                            }
                                            postbarcodelist[uniqueid].push(barcode);

                                             if(cartproduct[uniqueid] == undefined){
                                                cartproduct[uniqueid]=barcode;
                                                addBarcode(data.product_id,data.color_id,uniqueid);
                                             }else{
                                                addBarcodeExtra(uniqueid);
                                             }

                                        }






                                    },
                                    error :  function (data)
                                    {
                                        console.log(data);
                                    }
                                });
                            }else{
                                $('#product_exist').html("Product is already exists");
                                $('#product_exist').show();
                            }
                         }else{
                            if(cartproduct[id] == undefined)
                            {

                                $.ajax(
                                {
                                    type : 'POST',
                                    url  : "{{url('admin/add_cart_chalan')}}",
                                    data : {uniqueid:uniqueid, id: id,color:color,qty:qty,category_id:category },
                                    // dataType: 'json',
                                    success :  function (data)
                                    {
                                        console.log(data);
                                       if(data == '1'){
                                            $('#product_exist').show();
                                            $('#product_exist').html("Quantity is not available");
                                        }else{
                                            cartproduct[id+'-'+color]=color;
                                            $('#product_exist').hide();
                                            if($('#validateProduct').length > 0){
                                                $('#cart_items').html(data);
                                            }else{
                                                $('#cart_items').append(data);
                                            }
                                        }

                                    },
                                    error :  function (data)
                                    {
                                        console.log(data);
                                    }
                                });
                            }else{
                                 $('#product_exist').html("Product is already exists");
                                $('#product_exist').show();
                            }
                         }

                    }
                    //increate and decreate
                       function increateCart(arg){
                            var v=$('#'+arg).val();
                            v++;
                            $('#'+arg).val(v);
                       }
                        function decreaseCart(arg){
                            var v=$('#'+arg).val();
                            v--;
                            $('#'+arg).val(v);
                       }
                       function closeCart(arg){
                            $('#'+arg).remove();

                       }
                    //end increate and decrease

                    $(document).ready( function() {
                        var date = new Date();
                        var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
                        $('#datepicker-autoclose').datepicker({
                            format: 'dd-mm-yyyy',
                            autoclose: true,
                            todayHighlight: true
                        });
                        // $( '#datepicker-autoclose').datepicker( 'setDate', today );
                        $("#addRequisition").validate({
                                     ignore: "",
                                    rules:
                                   {
                                        customer: {
                                            required: true,
                                        },
                                         'product_id[]': {
                                            required: true,
                                        },
                                        messages: {
                                        'product_id[]': "Please Add Product",
                                        },
                                   },
                                submitHandler: submitForm
                              });
                        var btn_value="";
                        $('.submit').click(function () {
                            event.preventDefault();
                            btn_value=this.value ;
                            if(this.value == 'submit'){
                               if($('#delivery_mode').val() == 1){
                                    $('[name="invoice_number"],[name="delivery_mode"],[name="sales_man"], [name="courier"]').each(function () {
                                        $(this).rules('add', {
                                            required: true
                                        });

                                    });
                                }else{
                                    $('[name="invoice_number"],[name="delivery_mode"],[name="sales_man"]').each(function () {
                                        $(this).rules('add', {
                                            required: true
                                        });

                                    });
                                }

                                $("#addRequisition").submit();
                            }else if(this.value == 'update'){
                                console.log('hi');
                                $("#addRequisition").submit();
                            }

                         });

                     //product validtion form and insert



                       function submitForm() {

                            event.preventDefault();
                            var data1 =$("#addRequisition").serialize();

                            $.ajax({

                                type : 'POST',
                                url  : "{{url('admin/update_chalan')}}",
                                data : data1+'&btn_value='+btn_value+'&barcode='+JSON.stringify(postbarcodelist),

                                //dataType: 'json',
                                success :  function (data)
                                {

                                    if(data.errors=='0'){
                                        $('.alert-success').show();
                                        $('.alert-danger').hide();
                                        $('.alert-success').append('<p>'+data.success+'</p>');
                                       window.location="{{url('admin/chalan_list')}}";
                                    }else{
                                         var val="";
                                        $.each(data.errors, function(key, value){
                                            $('.alert-danger').show();
                                            $('.alert-success').hide();
                                            val+= '<p>'+value+'</p>';

                                        });
                                        $('.alert-danger').html(val);
                                    }

                                },error: function(response) {
                                    //console.log(response);
                                }
                            });
                            return false;
                        }
                     //end validation and insert

                        });


                    //new img upload
                    function previewFile(input) {
                            var preview = input.previousElementSibling;
                            var file = input.files[0];
                            var reader = new FileReader();


                            if(input.files[0].size > 2000000){
                                alert("Maximum file size is 2MB!");

                            } else {

                                reader.onloadend = function() {
                                    preview.src = reader.result;
                                }

                                if (file) {
                                    reader.readAsDataURL(file);

                                } else {
                                    preview.src = "";
                                }
                            }
                        }
                    //end new img upload
                </script>
            @endsection

VaKeR 2022