Skip to content

Commit

Permalink
fix: reference select
Browse files Browse the repository at this point in the history
  • Loading branch information
itsemon245 committed Mar 3, 2024
1 parent 1430a3a commit 81a9b3d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
php artisan view:cache
php artisan optimize:clear
php artisan migrate
rm -rf public/storage
php artisan storage:link
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/Backend/Client/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,11 @@ public function createFromCsv(Request $request)
return back()
->with($notification);
}


function getClient(Client $client) {
return response()->json([
'client' => $client
]);
}
}
22 changes: 20 additions & 2 deletions resources/views/backend/invoice/createInvoice.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class="d-flex justify-content-center" style="aspect-ratio:4/1;object-fit:contain
<span class="text-black">{{ countRecords('invoices') + 1 }}</span>
</div>
<div>
<label x-ref="reference" class="mb-0" for="reference">Reference</label>
<label class="mb-0" for="reference">Reference</label>
<input type="text" id="reference" name="reference" placeholder="000">
</div>

Expand All @@ -203,4 +203,22 @@ class="d-flex justify-content-center" style="aspect-ratio:4/1;object-fit:contain
</section>

</x-backend.ui.section-card>
@endsection
@endsection

@push('customJs')
<script>
$(document).ready(function () {
$('#client').on('change', function(e){
let url = "{{route('api.get.client', ':CLIENT')}}"
url = url.replace(':CLIENT', e.target.value)
$.ajax({
type: "get",
url: url,
success: function (response) {
$('input[name="reference"]').val(response.client.ref_no)
}
});
})
});
</script>
@endpush
22 changes: 21 additions & 1 deletion resources/views/backend/invoice/edit-invoice.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ class="d-flex justify-content-center" style="aspect-ratio:4/1;object-fit:contain
<select class="mb-2 tail-select" id="client" name="client"
placeholder="Select Client..." label="Bill To" required>
@foreach ($clients as $client)
<option @selected($client->id == $invoice->client_id) data-description="{{"<div class='fw-normal'>Company: $client->company_name,</br>Phone: $client->phone,</br> TIN: $client->tin, Ref: $client->ref_no, </br> Circle: $client->circle </div>"}}" value="{{ $client->id }}">{{ $client->name }}</option>
<option @selected($client->id == $invoice->client_id)
data-description="{{ "<div class='fw-normal'>Company: $client->company_name,</br>Phone: $client->phone,</br> TIN: $client->tin, Ref: $client->ref_no, </br> Circle: $client->circle </div>" }}"
value="{{ $client->id }}">{{ $client->name }}</option>
@endforeach
</select>
<a href="{{ route('client.create') }}" class="text-blue" style="font-weight: 500;">Create
Expand Down Expand Up @@ -208,3 +210,21 @@ class="btn btn-primary waves-effect waves-light mt-2 rounded-3 shadow">Update</b

</x-backend.ui.section-card>
@endsection

@push('customJs')
<script>
$(document).ready(function() {
$('#client').on('change', function(e) {
let url = "{{ route('api.get.client', ':CLIENT') }}"
url = url.replace(':CLIENT', e.target.value)
$.ajax({
type: "get",
url: url,
success: function(response) {
$('input[name="reference"]').val(response.client.ref_no)
}
});
})
});
</script>
@endpush
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\Backend\Client\ClientController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand All @@ -17,3 +18,5 @@
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});

Route::get('client/{client}', [ClientController::class, 'getClient'])->name('api.get.client');

0 comments on commit 81a9b3d

Please sign in to comment.