- Added InvoiceIndex component for displaying a list of invoices with pagination and search capabilities. - Created InvoiceShareButton component for sharing invoice details via WhatsApp. - Developed InvoicePrint component for printing invoice details. - Defined routes for invoice management including share and print functionalities. - Implemented InvoiceTest to cover authentication, authorization, and CRUD operations for invoices.
55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Enums\InvoiceStatus;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class InvoiceRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('invoices.create')
|
|
|| $this->user()->can('invoices.update');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$invoice = $this->route('invoice');
|
|
|
|
return [
|
|
'invoice_number' => ['required', 'string', 'max:50', Rule::unique('invoices', 'invoice_number')->ignore($invoice)],
|
|
'customer_name' => ['required', 'string', 'max:200'],
|
|
'customer_phone' => ['nullable', 'string', 'max:20'],
|
|
'customer_address' => ['nullable', 'string'],
|
|
'date' => ['required', 'date'],
|
|
'due_date' => ['nullable', 'date', 'after_or_equal:date'],
|
|
'status' => ['required', Rule::in(InvoiceStatus::values())],
|
|
'description' => ['nullable', 'string'],
|
|
'items' => ['required', 'array', 'min:1'],
|
|
'items.*.name' => ['required', 'string', 'max:200'],
|
|
'items.*.quantity' => ['required', 'integer', 'min:1'],
|
|
'items.*.price' => ['required', 'integer', 'min:0'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'invoice_number' => 'nomor invoice',
|
|
'customer_name' => 'nama pelanggan',
|
|
'customer_phone' => 'no. telepon pelanggan',
|
|
'customer_address' => 'alamat pelanggan',
|
|
'date' => 'tanggal',
|
|
'due_date' => 'jatuh tempo',
|
|
'status' => 'status',
|
|
'description' => 'keterangan',
|
|
'items' => 'item invoice',
|
|
'items.*.name' => 'nama item',
|
|
'items.*.quantity' => 'jumlah item',
|
|
'items.*.price' => 'harga item',
|
|
];
|
|
}
|
|
}
|