Add remove for invoice
This commit is contained in:
parent
c598508ceb
commit
451680bd70
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Invoice\Actions;
|
||||
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
use App\Invoice\Models\Invoice;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class InvoiceDestroyAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Invoice $invoice): JsonResponse
|
||||
{
|
||||
$invoice->delete();
|
||||
|
||||
Succeeded::message('Rechnung gelöscht.')->dispatch();
|
||||
|
||||
return response()->json([]);
|
||||
}
|
||||
}
|
|
@ -48,4 +48,11 @@ class Invoice extends Model
|
|||
'via' => $member->bill_kind,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function booted(): void
|
||||
{
|
||||
static::deleting(function ($model) {
|
||||
$model->positions()->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class InvoiceResource extends JsonResource
|
|||
'greeting' => $this->greeting,
|
||||
'links' => [
|
||||
'update' => route('invoice.update', ['invoice' => $this->getModel()]),
|
||||
'destroy' => route('invoice.destroy', ['invoice' => $this->getModel()]),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -16,6 +16,18 @@
|
|||
</section>
|
||||
</form>
|
||||
</ui-popup>
|
||||
<ui-popup v-if="deleting !== null" heading="Rechnung löschen?" @close="deleting = null">
|
||||
<div>
|
||||
<p class="mt-4">Diese Rechnung löschen?</p>
|
||||
<div class="grid grid-cols-2 gap-3 mt-6">
|
||||
<a href="#" class="text-center btn btn-danger" @click.prevent="
|
||||
remove(deleting);
|
||||
deleting = null;
|
||||
">Rechnung löschen</a>
|
||||
<a href="#" class="text-center btn btn-primary" @click.prevent="deleting = null">Abbrechen</a>
|
||||
</div>
|
||||
</div>
|
||||
</ui-popup>
|
||||
<ui-popup v-if="single !== null" :heading="`Rechnung ${single.id ? 'bearbeiten' : 'erstellen'}`"
|
||||
inner-width="max-w-4xl" @close="cancel">
|
||||
<form class="grid grid-cols-2 gap-3 mt-4" @submit.prevent="submit">
|
||||
|
@ -85,6 +97,8 @@
|
|||
<td>
|
||||
<a v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm"
|
||||
@click.prevent="edit(invoice)"><ui-sprite src="pencil"></ui-sprite></a>
|
||||
<a v-tooltip="`Löschen`" href="#" class="ml-2 inline-flex btn btn-danger btn-sm"
|
||||
@click.prevent="deleting = invoice"><ui-sprite src="trash"></ui-sprite></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -98,8 +112,9 @@
|
|||
import { ref } from 'vue';
|
||||
import { indexProps, useIndex } from '../../composables/useInertiaApiIndex.js';
|
||||
const props = defineProps(indexProps);
|
||||
var { axios, meta, data, reloadPage, create, single, edit, cancel, submit } = useIndex(props.data, 'invoice');
|
||||
var { axios, meta, data, reloadPage, create, single, edit, cancel, submit, remove } = useIndex(props.data, 'invoice');
|
||||
const massstore = ref(null);
|
||||
const deleting = ref(null);
|
||||
|
||||
async function sendMassstore() {
|
||||
await axios.post(meta.value.links['mass-store'], massstore.value);
|
||||
|
|
|
@ -25,6 +25,7 @@ use App\Initialize\Actions\InitializeFormAction;
|
|||
use App\Initialize\Actions\NamiGetSearchLayerAction;
|
||||
use App\Initialize\Actions\NamiLoginCheckAction;
|
||||
use App\Initialize\Actions\NamiSearchAction;
|
||||
use App\Invoice\Actions\InvoiceDestroyAction;
|
||||
use App\Invoice\Actions\InvoiceIndexAction;
|
||||
use App\Invoice\Actions\InvoiceUpdateAction;
|
||||
use App\Invoice\Actions\MassStoreAction;
|
||||
|
@ -119,6 +120,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::get('/invoice', InvoiceIndexAction::class)->name('invoice.index');
|
||||
Route::post('/invoice', InvoiceStoreAction::class)->name('invoice.store');
|
||||
Route::patch('/invoice/{invoice}', InvoiceUpdateAction::class)->name('invoice.update');
|
||||
Route::delete('/invoice/{invoice}', InvoiceDestroyAction::class)->name('invoice.destroy');
|
||||
|
||||
// --------------------------------- membership --------------------------------
|
||||
Route::get('/member/{member}/membership', MembershipIndexAction::class)->name('member.membership.index');
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Invoice;
|
||||
|
||||
use App\Invoice\Models\Invoice;
|
||||
use App\Invoice\Models\InvoicePosition;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvoiceDestroyActionTest extends TestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItDestroysInvoice(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$invoice = Invoice::factory()->has(InvoicePosition::factory(), 'positions')->create();
|
||||
|
||||
$this->delete(route('invoice.destroy', ['invoice' => $invoice]))->assertOk();
|
||||
$this->assertDatabaseCount('invoices', 0);
|
||||
$this->assertDatabaseCount('invoice_positions', 0);
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ class InvoiceIndexActionTest extends TestCase
|
|||
->assertInertiaPath('data.data.0.positions.0.description', 'lala')
|
||||
->assertInertiaPath('data.data.0.positions.0.id', $invoice->positions->first()->id)
|
||||
->assertInertiaPath('data.data.0.links.update', route('invoice.update', ['invoice' => $invoice]))
|
||||
->assertInertiaPath('data.data.0.links.destroy', route('invoice.destroy', ['invoice' => $invoice]))
|
||||
->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store'))
|
||||
->assertInertiaPath('data.meta.links.store', route('invoice.store'))
|
||||
->assertInertiaPath('data.meta.vias.0', ['id' => 'E-Mail', 'name' => 'E-Mail'])
|
||||
|
|
Loading…
Reference in New Issue