%PDF- %PDF-
Direktori : /home/silvzytp/dsr_code/resources/views/backend/member/pages/monthly_commit/ |
Current File : /home/silvzytp/dsr_code/resources/views/backend/member/pages/monthly_commit/form.blade.php |
@extends('layouts.backend') @section('title', $siteTitle) @section('action') <button type="button" class="btn btn-sm btn-success submit-form-btn">Submit</button> @endsection @push('styles') <style> .append-btn button { width: 25px; height: 25px; text-align: center; line-height: 25px; border-radius: 50%; border: 0; font-size: 12px; color: #fff; } </style> @endpush @section('content') <div class="row"> <div class="col-12"> <form action="{{ isset($monthly) ? route('app.monthly.update', $monthly->id) : route('app.monthly.store') }}" method="POST" id="form" enctype="multipart/form-data"> @csrf @isset($monthly) @method('PUT') <input type="hidden" name="manager_id" value="{{ $monthly->user_id }}"> <input type="hidden" name="data_id" value="{{ $monthly->id }}"> @endisset <div class="row"> <div class="col-md-12"> <div class="ibox"> <div class="ibox-body"> <div class="row"> <div class="col-md-6 mb-3 mb-md-0"> <div class="form-group" id="date_1"> <label class="font-normal required">Date</label> <div class="input-group date"> <span class="input-group-addon bg-white"><i class="fa fa-calendar"></i></span> <input class="form-control" autofocus autocomplete="off" value="{{ isset($monthly) ? date_formats($monthly->date, 'm/d/Y') : '' }}" name="date" type="text" class="date" > </div> @error('date') <span class="text-danger">{{ $message }}</span> @enderror </div> </div> @if (Auth::user()->role->slug == 'admin') @php $managers = App\Models\User::where('role_id',3)->select('id','name')->get(); @endphp <div class="col-md-6 mb-2"> <x-form.selectbox name="manager" onchange="manager_select(this.value)" error="manager" labelName="Manager" > <option value="">-- Select Manager --</option> @forelse ($managers as $manager) <option value="{{ $manager->id }}" @isset($monthly) {{ $monthly->user_id == $manager->id ? 'selected' : '' }} @endisset>{{ $manager->name }}</option> @empty @endforelse </x-form.selectbox> </div> <div class="col-md-6 mb-3 mb-md-0"> <x-form.selectbox name="agent_name" required="required" error="agent_name" labelName="Agent Name" > <option value="">-- Select Agent --</option> </x-form.selectbox> </div> @else @php $agents = DB::table('users')->where('manager_id',Auth::id())->get(); @endphp <div class="col-md-6 mb-2"> <x-form.selectbox name="agent_name" required="required" error="agent_name" labelName="Agent Name" > <option value="">-- Select Agent --</option> @forelse($agents as $agent) <option value="{{ $agent->name }}" @isset($monthly) {{ $monthly->agent_name == $agent->name ? 'selected' : '' }} @endisset>{{ $agent->name }}</option> @empty @endforelse </x-form.selectbox> </div> @endif <div class="col-md-6 mb-3 mb-md-0"> <x-form.inputbox name="expected_meeting" labelName="Expected Meeting" value="{{ $monthly->expected_meeting ?? old('expected_meeting') }}" error="expected_meeting"/> </div> <div class="col-md-6 mb-3 mb-md-0"> <x-form.inputbox name="project_name" labelName="Project Name" value="{{ $monthly->project_name ?? old('project_name') }}" error="project_name"/> </div> <div class="col-md-6 mb-3 mb-md-0"> <x-form.inputbox name="expected_sale" labelName="Expected Sale" value="{{ $monthly->expected_sale ?? old('expected_sale') }}" error="expected_sale"/> </div> <div class="col-md-6 mb-3 mb-md-0"> <x-form.inputbox name="meeting_done" labelName="Meeting Done" value="{{ $monthly->meeting_done ?? old('meeting_done') }}" error="meeting_done"/> </div> <div class="col-md-6 mb-3 mb-md-0"> <x-form.inputbox name="sale" labelName="Sale" value="{{ $monthly->sale ?? old('sale') }}" error="sale"/> </div> </div> </div> </div> </div> </div> </form> </div> </div> @endsection @push('scripts') <script> // random password generate function generatePass() { let chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*"; let passLength = 8; let password = ""; for (let i = 0; i < passLength; i++) password += chars[Math.floor(Math.random() * chars.length)]; return password; } // random password value $(document).on('click','button.generate-pass', function(){ $('input[name="password"]').val(generatePass()); }) // password input type text $(document).on('click','.password-text',function(){ if($(this).children().hasClass('fa-eye')){ $(this).children().removeClass('fa-eye'); $(this).children().addClass('fa-eye-slash'); $('input[name="password"]').attr('type','text'); }else{ $(this).children().removeClass('fa-eye-slash'); $(this).children().addClass('fa-eye'); $('input[name="password"]').attr('type','password'); } }); @if (Auth::user()->role->slug == 'admin') // manager by agent function manager_select(manager_id){ if (manager_id != '') { $.ajax({ url: '{{ route("app.monthly.manager.select") }}', type: 'POST', data:{_token:_token,manager_id:manager_id}, dataType: 'JSON', cache: false, success: function(response){ $('select#agent_name').html(response); }, error: function(error){ console.log(error); } }); } } @isset($monthly) function agent_selected(){ $.ajax({ type: "POST", url: "{{ route('app.monthly.agent.select') }}", data: {_token:_token,manager_id:$('input[name="manager_id"]').val(),data_id:$('input[name="data_id"]').val()}, dataType: "json", success: function (response) { if (response) { $('select#agent_name').append(response); } } }); } agent_selected() @endisset @endif // Dynamic permission field add remove var count = 0; function dynamicPermissionField(row){ var html = ` <div class="agent-box mb-3"> <div class="append-btn text-right mb-2"> <button type="button" class="bg-danger add_permission remove_permission"><i class="fa fa-minus fa-sm"></i></button> </div> <x-form.inputbox name="agent[`+row+`][name]" class="agent_`+row+`_name" placeholder="Full Name"/> <x-form.inputbox name="agent[`+row+`][email]" class="agent_`+row+`_email" placeholder="Email"/> <div class="form-group"> <input type="number" name="agent[`+row+`][target]" id="target-amount" class="form-control agent_`+row+`_target" placeholder="Target"/> </div> <x-form.textarea name="agent[`+row+`][description]" class="agent_`+row+`_description" placeholder="Description"></x-form.textarea> </div>`; $('#permission_table').append(html); } // add agent field $(document).on('click', '#add_permission', function () { count++; dynamicPermissionField(count); }); // remove agent field $(document).on('click', '.remove_permission', function () { count--; $(this).closest('div.agent-box').remove(); totalTargetCalculate(); }); // ***** total target ***** // $(document).on('keyup', '.agent-box input#target-amount', function(){ totalTargetCalculate(); }); // calculation function totalTargetCalculate(){ var total = 0; $('input#target-amount').each(function(){ total += parseFloat($(this).val() || 0); }); var totalA = total == 0 ? '0.00' : total; $('input.total_amound').val(total); $('.manager-target').text(totalA); } $(document).on('click', 'button.submit-btn', function(){ var form = document.getElementById('member-form'); var formData = new FormData(form); $.ajax({ url: "{{ route('app.monthly.store') }}", type: "post", data: formData, dataType: false, contentType: false, processData: false, cache: false, success: function(response){ // validation form $('#member-form').find('.error-msg').remove(); if(response.status == false){ $.each(response.errors, function (key, value) { $('#member-form .'+key).parent().append('<small class="error-msg text-danger d-block">'+value+'</small>'); }); }else{ if(response.status == 'success'){ window.location.reload(); flashMessage(response.status, response.message); }else{ flashMessage(response.status, response.message); } } }, error: function(error){ console.log(error); } }); }); $('#date_1 .input-group.date').datepicker({ todayBtn: "linked", keyboardNavigation: false, forceParse: false, calendarWeeks: true, autoclose: true, endDate: '-0d' }); </script> @endpush