81 lines
3.0 KiB
PHP
81 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Concerns\CurrencyStripping;
|
|
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
|
|
{
|
|
use CurrencyStripping;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
$this->merge($this->stripCurrencyDot($this->validated(), 'discount', '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',
|
|
];
|
|
}
|
|
}
|