- Implemented TransactionIndex component for displaying transactions with pagination and filtering options. - Created TransactionCardRow component for rendering individual transaction details. - Added TransactionItemSubRow component for displaying detailed order items within a transaction. - Integrated delete confirmation dialog for transaction deletion. - Updated routes to include transaction management with appropriate permissions.
88 lines
3.1 KiB
PHP
88 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Enums\OrderChannel;
|
|
use App\Enums\PaymentType;
|
|
use App\Enums\PriceType;
|
|
use App\Enums\ProductStockQuality;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class TransactionRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
if ($this->has('discount')) {
|
|
$this->merge([
|
|
'discount' => str_replace('.', '', $this->discount),
|
|
]);
|
|
}
|
|
|
|
if ($this->has('nego_price')) {
|
|
$this->merge([
|
|
'nego_price' => str_replace('.', '', $this->nego_price),
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$sellingPriceTypes = array_diff(PriceType::values(), [PriceType::CAPITAL->value]);
|
|
|
|
return [
|
|
'stock_type' => ['sometimes', 'required', Rule::in(ProductStockQuality::values())],
|
|
'channel' => ['sometimes', 'required', Rule::in(OrderChannel::values())],
|
|
'price_type' => ['sometimes', 'required', Rule::in($sellingPriceTypes)],
|
|
'payment_type' => ['sometimes', 'required', Rule::in(PaymentType::values())],
|
|
'customer_id' => ['nullable', 'integer', 'exists:customers,id'],
|
|
'marketing_id' => ['nullable', 'integer', 'exists:users,id'],
|
|
'discount' => ['nullable', 'integer', 'min:0'],
|
|
'nego_price' => ['nullable', 'integer'],
|
|
'is_completed' => ['sometimes', 'boolean'],
|
|
'is_affiliate' => ['sometimes', 'boolean'],
|
|
'tiktok_order_id' => ['nullable', 'string', 'max:100'],
|
|
'shopee_order_id' => ['nullable', 'string', 'max:100'],
|
|
'items' => ['required', 'array', 'min:1'],
|
|
'items.*.product_variant_id' => ['required', 'integer', 'exists:product_variants,id'],
|
|
'items.*.quantity' => ['required', 'integer', 'min:1'],
|
|
'notes' => ['nullable', 'string', 'max:100'],
|
|
'photo_key' => [
|
|
Rule::when(
|
|
in_array($this->input('payment_type'), [PaymentType::TRANSFER->value, PaymentType::QRIS->value]),
|
|
['required', 'string', 'max:500'],
|
|
['nullable', 'string', 'max:500'],
|
|
),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'stock_type' => 'Tipe Stok',
|
|
'channel' => 'Channel',
|
|
'price_type' => 'Tipe Harga',
|
|
'payment_type' => 'Tipe Pembayaran',
|
|
'customer_id' => 'Pelanggan',
|
|
'marketing_id' => 'Marketing',
|
|
'discount' => 'Diskon',
|
|
'nego_price' => 'Harga Nego',
|
|
'is_completed' => 'Pesanan Selesai',
|
|
'is_affiliate' => 'Affiliasi',
|
|
'tiktok_order_id' => 'ID Pesanan TikTok',
|
|
'shopee_order_id' => 'ID Pesanan Shopee',
|
|
'items' => 'Item Produk',
|
|
'items.*.product_variant_id' => 'Varian Produk',
|
|
'items.*.quantity' => 'Jumlah',
|
|
'notes' => 'Keterangan',
|
|
'photo_key' => 'Foto',
|
|
];
|
|
}
|
|
}
|