</div>
    <script src="{{url('/')}}/assets/js/jquery-3.6.3.min.js"></script>
    <script src="{{url('/')}}/assets/js/bootstrap.bundle.min.js"></script>
    <script src="{{url('/')}}/assets/js/feather.min.js"></script>
    <script src="{{url('/')}}/assets/plugins/apexchart/apexcharts.min.js"></script>
    <script src="{{url('/')}}/assets/plugins/apexchart/chart-data.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    <!--<script src="{{url('/')}}/assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>-->
    <script src="{{url('/')}}/assets/plugins/moment/moment.min.js"></script>
    <script src="{{url('/')}}/assets/js/bootstrap-datetimepicker.min.js"></script>
    <script src="{{url('/')}}/assets/js/jquery-ui.min.js"></script>
    <script src="{{url('/')}}/assets/js/script.js"></script>
    <script src="{{url('/')}}/assets/js/custom.js"></script>
    <script>
            $(document).ready(function() {
            $('.js-example-basic-single').select2();
        });
        $(function () {
           $("#country_id").on('change', function () {
              var country_id = $(this).val();
                  $.ajax({
                      headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                    url : "{{ url('ajaxNoOfState') }}",
                    data : {'country_id' : country_id},
                    type : 'POST',
                    success : function(result){
                      $("#show_state").html(result);
                    }
                });
            });
        });
        // $(function () {
            $(document).on('change','#state_id',function(){
            //   alert('naruto');
              var state_id = $(this).val();
                  $.ajax({
                      headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                    url : "{{ url('ajaxNoOfCity') }}",
                    data : {'state_id' : state_id},
                    type : 'POST',
                    success : function(result){
                      $("#show_city").html(result);
                    }
                });
            });
        // });
        
        
       $("#addMore").on('click', function () {
          var noOfTeam = $('#no_of_field').val();
        //   alert(noOfTeam);
          $('#no_of_field').val(parseFloat(noOfTeam)+1);
              $.ajax({
                  headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                url : "{{ url('ajaxAddMoreFields') }}",
                data : {'noOfTeam' : noOfTeam},
                type : 'POST',
                success : function(result){
            //   alert(result);
            //   return false;
                  $("#teamFieldRep").html(result);
                }
            });
        });
        
        
       $("#addMoresold").on('click', function () {
          var noOfTeam = $('#no_of_field_sold').val();
        //   alert(noOfTeam);
          $('#no_of_field_sold').val(parseFloat(noOfTeam)+1);
              $.ajax({
                  headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                url : "{{ url('ajaxAddMoreSoldFields') }}",
                data : {'noOfTeam' : noOfTeam},
                type : 'POST',
                success : function(result){
            //   alert(result);
            //   return false;
                  $("#teamFieldRepSold").html(result);
                }
            });
        });
        
        $(document).ready(function() {
            $("#partyAdd").click(function(){
              $(".filterBar").addClass("active");
              $("#hideBar").addClass("hide");
            });
        });
        
        $(document).on('change','#party_select',function(){
          var party_id = $(this).val();
              $.ajax({
                  headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                url : "{{ url('customerDetails') }}",
                data : {'party_id' : party_id},
                type : 'POST',
                success : function(result){
                    $(".filterBar").removeClass("active");
                    $(".customer_details_body").removeClass("hide");
                    $(".customer_details_body").html(result);
                }
            });
        });
        
        $(document).on('click','#change_party',function(){
          $(".filterBar").addClass("active");
          $(".customer_details_body").addClass("hide");
          $(".customer_details_body").html('');
        });
        
        $(document).on('click','.increase_qty',function(){
            var item_id = $(this).attr('dataitemid');
            var check_item = 'check_item_'+item_id;
            var btn_id = 'addQty_'+item_id;
            var quantity = 'quantity_'+item_id;
            
            $('#'+check_item).attr('checked', true);
            $("#"+btn_id).addClass("hide");
            $("#"+quantity).addClass("active");
        });
        
        $(document).on('click','.uncheck_item',function(){
            var item_id = $(this).attr('dataitemid');
            var check_item = 'check_item_'+item_id;
            var btn_id = 'addQty_'+item_id;
            var quantity = 'quantity_'+item_id;
            $('#'+check_item).attr('checked', false);
            $('#'+check_item).val(1);
            $("#"+btn_id).removeClass("hide");
            $("#"+quantity).removeClass("active");
        });
        
        $(document).on('click','#save_item',function(){
            var checked_items = $('.uncheck_item:checked');
            var items = [];
            // var party = $('#party_select').val();
            if (checked_items.length > 0) {
                checked_items.each(function(index, element) {
                console.log(element);
                // Perform your desired operations on each element
                // For example:
                var itemId = $(element).attr('dataitemid');
                items.push({
                    item_id: itemId,
                    item_qty: $('#quantity_'+itemId).val(),
                });
              });
            } else {
              console.log("No checked items found");
            }
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url : "{{ url('itemInsertInvoice') }}",
                data : JSON.stringify(items),
                type : 'POST',
                success : function(result){
                 var data2 = JSON.parse(result);
                    console.log(result)
                    $('#table_body').html(data2.str);
                    $('#taxableAmount').html('₹' + data2.totalWithoutGst);
                    $('#sgstAmount').html('₹' + data2.sgst);
                    $('#cgstAmount').html('₹' + data2.cgst);
                    $('#finalAmount').html('₹' + data2.finalAmount);
                }
            });
        });
        
        // $(document).on('change','.qty_invoice',function(){
        //     var checked_items = $('.invoice_cls');
        //     console.log(checked_items);
        //     var items = [];
        //     if (checked_items.length > 0) {
        //         checked_items.each(function(index, element) {
        //             console.log(element);
        //             // Perform your desired operations on each element
        //             // For example:
        //             var itemId = $(element).attr('dataitemid');
        //             items.push({
        //                 item_id: itemId,
        //                 item_qty: $('#qty_'+itemId).val(),
        //                 item_price: $('#item_cost_price_'+itemId).val(),
        //                 item_discount_pre: $('#discount_pre_'+itemId).val(),
        //                 item_discount_amount: $('#discount_amount_'+itemId).val(),
        //                 item_tax: $('#gst_amount_'+itemId).val()
        //                 item_amount: $('#amount_with_tax_'+itemId).val()
        //             });
        //       });
        //     } else {
        //       console.log("No checked items found");
        //     }
        //     console.log('items', items);
            
        // });
        
        $(document).on('change','#account_type',function(){
          var account_type_id = $(this).val();
        //   alert(account_type_id);
          if(account_type_id == 3){
              $(".bank_details_box").addClass("hide");
              $(".upi_box").addClass("active");
          }else{
              $(".bank_details_box").removeClass("hide");
              $(".upi_box").removeClass("active");
          }
        });
        
        
        $(document).on('click','#discount_open',function(){
          $(this).addClass("hide");
          $(".discount_show").css("display", "flex");
        });
        
        $(document).on('change','#received_amount',function(){
          var result = $(this).val();
            // alert(result);
            if(result == 2){
                 $("#payment_received_in").addClass("active");
            }else{
                $("#payment_received_in").removeClass("active");
            }
        });
        
        $(document).on('change','#payment_mode',function(){
          var payment_mode = $(this).val();
          if(payment_mode == 2){
            $.ajax({
                  headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                url : "{{ url('ajaxOfBankDetails') }}",
                data : {'payment_mode' : payment_mode},
                type : 'POST',
                success : function(result){
                    $('#bank_details_show').html(result);
                }
            });
          }
        });
        $("#commissionAmount").on('click', function () {
                $(".actualAmount").addClass("active");
        });
    </script>
  </body>
</html>