diff --git a/app/Http/Controllers/Api/InvoiceController.php b/app/Http/Controllers/Api/InvoiceController.php index 18dac0c..6aa401e 100644 --- a/app/Http/Controllers/Api/InvoiceController.php +++ b/app/Http/Controllers/Api/InvoiceController.php @@ -55,9 +55,31 @@ class InvoiceController extends Controller /** * Update the specified resource in storage. */ - public function update(Request $request, Invoice $invoice) + public function update(Request $request, Invoice $invoice): JsonResponse { - // + $invoiceData = $request->validate([ + 'customer_id' => 'required|integer|exists:customers,id', + 'address_id' => 'required|integer|exists:addresses,id', + 'delivery_id' => 'nullable|integer|exists:addresses,id', + 'tax' => 'required|numeric', + 'sum' => 'required|numeric', + ]); + + $invoice->update($invoiceData); + $invoice->items()->delete(); + + return response()->json($invoice); + } + + public function state(Request $request, Invoice $invoice): JsonResponse + { + $invoiceData = $request->validate([ + 'status' => 'required|string' + ]); + + $invoice->update($invoiceData); + + return response()->json($invoice); } /** diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 187d236..ce64bff 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -34,9 +34,9 @@ class InvoiceController extends Controller /** * Show the form for editing the specified resource. */ - public function edit(Invoice $invoice) + public function edit(Invoice $invoice): View { - // + return view('invoice.edit', ['invoice' => $invoice]); } /** diff --git a/resources/views/invoice/edit.blade.php b/resources/views/invoice/edit.blade.php new file mode 100644 index 0000000..d3b6db0 --- /dev/null +++ b/resources/views/invoice/edit.blade.php @@ -0,0 +1,489 @@ + + +

+ {{ __('invoice.Edit invoice') }} +

+
+ + @if($invoice->status === 'created') +
+
+ + +
+
+
+
+

+ {{ __('invoice.Select customer') }} +

+

+ {{ __("invoice.Select your customer and address") }} +

+
+ +
+ + +
+ +
+ +
+ +
+ +
+
+ + +
+
+
+
+

+ {{ __('invoice.Select address') }} +

+

+ {{ __("invoice.Select your customer's address") }} +

+
+ +
+
+
+
{{ __('customer.Invoice Address') }}
+ + + +
+ + +
+
+
+
+
+
+
+
+
+ + +
+
+
{{ __('customer.Delivery Address') }}
+ + + +
+ +
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+ + +
+
+
+
+

+ {{ __('invoice.Invoice items') }} +

+

+ {{ __("invoice.Enter your invoice items. Click add for an additional invoice item.") }} +

+
+ + +
+ + + + +
+
+
+ + + + + + + + +
+ + +
+
+
+
+ +
+
+
+ +
+ + +
+ +
+ +
+ + {{ __('form.Save') }} + +
+
+ +
+
+ @else +
+
+
+
{!! __('invoice.Already sent') !!}
+
+
+
+ @endif + +
+ + + diff --git a/resources/views/invoice/mail.blade.php b/resources/views/invoice/mail.blade.php index 24d160f..0eb9937 100644 --- a/resources/views/invoice/mail.blade.php +++ b/resources/views/invoice/mail.blade.php @@ -7,91 +7,122 @@ -
-
- -
-
-
-
-

- {{ __('invoice.Mail') }} -

-

- {{ __("invoice.Send email to your customer with attachments.") }} -

-
+ @if($invoice->status === 'created') +
+
+ +
+
+
+
+

+ {{ __('invoice.Manual Mail') }} +

+

+ {{ __("invoice.Send email to your customer with attachments manually.") }} +

+
+
+ {{ __('invoice.Sent menually') }} +
+
+
+
+
-
-
-
- - {!! __('common.Tooltip multiple email') !!} +
+ +
+
+
+
+

+ {{ __('invoice.Mail') }} +

+

+ {{ __("invoice.Send email to your customer with attachments.") }} +

+
+ + +
+
+ + {!! __('common.Tooltip multiple email') !!} +
+
- -
-
-
- - {!! __('common.Tooltip multiple email') !!} +
+
+ + {!! __('common.Tooltip multiple email') !!} +
+
- -
-
-
- - {!! __('common.Tooltip multiple email') !!} +
+
+ + {!! __('common.Tooltip multiple email') !!} +
+
- -
-
- - -
+
+ + +
-
- - -
+
+ + +
-
- - - -
+
+ + + +
-
- - - -
+
+ + + +
-
- {{ __('form.Send') }} -
+
+ {{ __('form.Send') }} +
- -
+ + +
- + @else +
+
+
+
{!! __('invoice.Already sent') !!}
+
+
+
+ @endif @@ -114,11 +145,21 @@ this.sent = true; axios.post('/sendInvoice', this.data) .then(function (response) { - console.log(response); + window.location.href = '/invoice'; }).catch(function(error) { console.log(error); }) - console.log(this.data); + }, + + updateState() { + this.sent = true; + axios.put('/invoice/' + this.data.id + '/state', {status: 'sent'}) + .then(function (response) { + window.location.href = '/invoice'; + }).catch(function (error) { + console.log(error); + }) + } } } diff --git a/resources/views/invoice/show.blade.php b/resources/views/invoice/show.blade.php index 6e1015b..53cd4f1 100644 --- a/resources/views/invoice/show.blade.php +++ b/resources/views/invoice/show.blade.php @@ -5,9 +5,6 @@ {{ __('invoice.Invoice') }} {{ $invoice->number }} ({{ $invoice->localized_state }})

- @if ($invoice->status === 'created') - - @endif

@@ -93,6 +90,18 @@ + @if ($invoice->status === 'created') +
+
+
+ {{ __('form.Send') }} + {{ __('form.Edit') }} +
+
+
+ @endif + + diff --git a/routes/api.php b/routes/api.php index f951174..e074e92 100644 --- a/routes/api.php +++ b/routes/api.php @@ -28,6 +28,8 @@ Route::group(['as' => 'api.'], function () { Route::apiResource('/taxrate', TaxRateController::class)->except(['show']); Route::get('/invoice/{start?}/{end?}', [InvoiceController::class, 'index'])->name('invoice.index'); Route::post('/invoice', [InvoiceController::class, 'store'])->name('invoice.store'); + Route::put('/invoice/{invoice}', [InvoiceController::class, 'update'])->name('invoice.update'); + Route::put('/invoice/{invoice}/state', [InvoiceController::class, 'state'])->name('invoice.state'); Route::apiResource('/invoice.item', InvoiceItemController::class)->shallow(); Route::get('/option', [OptionController::class, 'index'])->name('option.index'); Route::post('/option', [OptionController::class, 'store'])->name('option.store');