@extends('layouts.app')

@section('title')
    Add Sale
@stop

@section('breadcrumb')
    <ol class="breadcrumb pull-right">
        <li><a href="{{ route('home') }}"><i class="fa fa-dashboard"></i> Home</a></li>
        @permission('list-membership')
            <li><a href="{{ route('statement.all') }}">Statements</a></li>
        @endpermission
        <li class="active">Add Sale</li>
    </ol>
@stop
@section('css')
    <style>
        .select2-container {
            width: 300px !important;
            /* set the width to 300 pixels */
        }

        .help-block {
            font-weight: bold;
        }

        span {
            display: inline-block;
        }

        .lallu {
            display: flex;
        }

        .Note {
            display: inline-block;
            /* color: red; */
        }
        .white-box-1{
            background: #fff;
    padding: 18px 25px 10px 25px;
    margin-bottom: 30px;
    border-radius: 4px;
    
        }
    </style>

@stop

@section('content')




    <div class="container-fluid">
        <div class="row">

            <form class="form-horizontal" method='post' action="{{ route('statement.insert') }}" enctype="multipart/form-data"
                onsubmit="return validateData(this)">
                {{ csrf_field() }}
                <div class="col-lg-12 col-sm-12 col-xs-12">
                    @if ($errors->any())
                        <div class="white-box" style="height: 285px;">
                            <h2>Errors</h2>
                            <ul>
                                {!! implode('', $errors->all('<li><span class="help-block"><strong>:message</strong></span></li>')) !!}
                            </ul>
                        </div>
                    @endif

                    <div class='white-box'>
                        <h3 class="box-title m-b-0"><i class="icon-layers fa-fw"></i> Add New Sale</h3>
                        <p class="text-muted  font-13">
                        <p class="Note">Note</p>: All * fields are mandatory </p>
                        <hr>

                    </div>
                </div>
                @can('isSuperAdmin')
                {{-- <div class="col-lg-12 col-sm-12 col-xs-12">
                    <div class="white-box-2">
                        <h3 class="box-title m-b-0"><i class="icon-layers fa fa-product-hunt"></i> Project Type</h3>

                        <hr>
                        <div class="clearfix"></div>
                       
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="control-label col-md-4">Select Type <span style="color: red">*</span></label>
                                    <div class="col-md-8">
                                        <select autocomplete="off" class="form-control " id="projecttype" name="projecttype"
                                            style="width: 100%!important;" onchange="updateStatus(this.value)">
                                            <option value="" selected="">None</option>
                                            @foreach ($projecttype as $project)
                                                <option value="{{ $project->id }}">{{ $project->name }}

                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>
                       
                    </div>
                </div> --}}
                @endcan
                <div id='updatecontent'>

                    
                        @include('statement.add-statement-update')
                   

                </div>
            </form>
        </div>
    </div>
    {{-- <input type='hidden' id="possession_per">
    <input type='hidden' id="down_payment_per">
    <input type='hidden' id="total_month_per">
    <input type='hidden' id="annual_installment_per">
    <input type='hidden' id="monthly_installment_per">
    <input type="hidden" id="down_payment_dis">
    <input type="hidden" name="percentage" id="percentage">
    <input type="hidden" name="rebate_in_percent" id="rebate_in_percent">

    <input type="hidden" name="semi_installment_hid_per" id="semi_installment_hid_per">
    <input type="hidden" name="semi_installment_hid_amount" id="semi_installment_hid_amount"> --}}


@stop

@section('js')
 
 
       
       
       <script>
       
       @include('statement.add-statement-javascript')
         
        </script>
       
        
        @can('isSuperAdmin')
 

        
        <script>

           

            async function updateStatus(value) {
                $('.preloader').fadeIn();

                if (value === 'search') {
                    $('.preloader').fadeOut();
                    return false;
                }

                if (value == "") {
                    $('.preloader').fadeOut();
                    return false;
                }

                var data = {
                    'multipro_type_id': value,
                };



                try {
                    const response = await new Promise((resolve, reject) => {
                        $.get('{{ route('statement.addView') }}', data, function(data) {
                            resolve(data);
                        }).fail(function(xhr, status, error) {
                            reject(error);
                        });
                    });

                    $('.preloader').fadeOut();

                    await new Promise(resolve => {
                        // document.getElementById('updatecontent').innerHTML = response;
                        $('#updatecontent').empty();
                        document.getElementById('updatecontent').insertAdjacentHTML('beforeend', response);
 
                        var scriptRegex = /<script\b[^>]*>([\s\S]*?)<\/script>/gm;
    var matches = response.match(scriptRegex);
    
    if (matches) {
      for (var i = 0; i < matches.length; i++) {
        var scriptTag = matches[i];
        var jsCode = scriptTag.replace(/<script\b[^>]*>/, '').replace(/<\/script>/, '');
        
        
        var scriptElement = document.createElement('script');
    scriptElement.innerHTML = jsCode;
    document.body.appendChild(scriptElement);
        // Evaluate the JavaScript code
      }
    }


                        // $('.chosen-select').trigger('chosen:updated');
                        $('.chosen-select').chosen();
                       

                       
                        resolve();
                    });




                    toastr.success("List Detail updated");


                } catch (error) {
                    // Handle error if the request fails
                    console.error(error);
                }

                $('.preloader').fadeOut();
            }

            
        </script>
        @endcan
   

@stop
