Refactor price handling in product and raw material requests, models, and migrations to use integers instead of decimals. Update validation rules and data types in related TypeScript files for consistency across the application.
This commit is contained in:
parent
4c91834389
commit
e77f0ebc8a
@ -45,7 +45,7 @@ public function rules(): array
|
|||||||
'variants.*.stock' => ['required', 'integer', 'min:0'],
|
'variants.*.stock' => ['required', 'integer', 'min:0'],
|
||||||
'variants.*.prices' => ['required', 'array', 'min:1'],
|
'variants.*.prices' => ['required', 'array', 'min:1'],
|
||||||
'variants.*.prices.*.type' => ['required', Rule::enum(PriceType::class)],
|
'variants.*.prices.*.type' => ['required', Rule::enum(PriceType::class)],
|
||||||
'variants.*.prices.*.price' => ['required', 'numeric', 'decimal:0,2', 'gt:0'],
|
'variants.*.prices.*.price' => ['required', 'integer', 'gt:0'],
|
||||||
...$this->variantImageRules(),
|
...$this->variantImageRules(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public function rules(): array
|
|||||||
->whereNull('deleted_at'),
|
->whereNull('deleted_at'),
|
||||||
],
|
],
|
||||||
'prices.*.variant' => ['required', 'string', 'max:200'],
|
'prices.*.variant' => ['required', 'string', 'max:200'],
|
||||||
'prices.*.price' => ['required', 'numeric', 'decimal:0,2', 'gt:0'],
|
'prices.*.price' => ['required', 'integer', 'gt:0'],
|
||||||
'prices.*.stock' => ['required', 'numeric', 'decimal:0,4', 'min:0'],
|
'prices.*.stock' => ['required', 'numeric', 'decimal:0,4', 'min:0'],
|
||||||
...$this->variantImageRules('prices'),
|
...$this->variantImageRules('prices'),
|
||||||
];
|
];
|
||||||
|
|||||||
@ -22,7 +22,7 @@ protected function casts(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => PriceType::class,
|
'type' => PriceType::class,
|
||||||
'price' => 'decimal:2',
|
'price' => 'integer',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,14 +34,14 @@ public function variant(): BelongsTo
|
|||||||
public function priceFormatted(): Attribute
|
public function priceFormatted(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => 'Rp '.number_format((float) $this->price, 0, ',', '.'),
|
get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function priceInput(): Attribute
|
public function priceInput(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => (string) (int) $this->price,
|
get: fn () => (string) $this->price,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class RawMaterialPrice extends Model implements HasMedia
|
|||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'price' => 'decimal:2',
|
'price' => 'integer',
|
||||||
'stock' => 'decimal:4',
|
'stock' => 'decimal:4',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -44,14 +44,14 @@ public function rawMaterial(): BelongsTo
|
|||||||
public function priceFormatted(): Attribute
|
public function priceFormatted(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => 'Rp '.number_format((float) $this->price, 0, ',', '.'),
|
get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function priceInput(): Attribute
|
public function priceInput(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn () => (string) (int) $this->price,
|
get: fn () => (string) $this->price,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -204,7 +204,7 @@ private function syncVariantImages(ProductVariant $variant, array $variantData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list<array{type: string, price: float|int|string}> $prices
|
* @param list<array{type: string, price: int}> $prices
|
||||||
*/
|
*/
|
||||||
private function syncVariantPrices(ProductVariant $variant, array $prices): void
|
private function syncVariantPrices(ProductVariant $variant, array $prices): void
|
||||||
{
|
{
|
||||||
|
|||||||
@ -14,7 +14,7 @@ public function up(): void
|
|||||||
$table->foreignId('variant_id')->constrained('product_variants')->cascadeOnDelete();
|
$table->foreignId('variant_id')->constrained('product_variants')->cascadeOnDelete();
|
||||||
|
|
||||||
$table->string('type', 20);
|
$table->string('type', 20);
|
||||||
$table->decimal('price', 18, 2);
|
$table->unsignedInteger('price');
|
||||||
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ public function up(): void
|
|||||||
$table->foreignId('raw_material_id')->constrained()->cascadeOnDelete();
|
$table->foreignId('raw_material_id')->constrained()->cascadeOnDelete();
|
||||||
|
|
||||||
$table->string('variant', 200);
|
$table->string('variant', 200);
|
||||||
$table->decimal('price', 18, 2);
|
$table->unsignedInteger('price');
|
||||||
$table->decimal('stock', 18, 4)->default(0);
|
$table->decimal('stock', 18, 4)->default(0);
|
||||||
|
|
||||||
$table->timestamp('created_at')->useCurrent();
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export type CategoryOption = {
|
|||||||
export type ProductPriceItem = {
|
export type ProductPriceItem = {
|
||||||
type: string;
|
type: string;
|
||||||
type_label: string;
|
type_label: string;
|
||||||
price: string;
|
price: number;
|
||||||
price_formatted: string;
|
price_formatted: string;
|
||||||
price_input: string;
|
price_input: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export type RawMaterialPrice = {
|
|||||||
variant: string;
|
variant: string;
|
||||||
stock: string;
|
stock: string;
|
||||||
stock_formatted: string;
|
stock_formatted: string;
|
||||||
price: string;
|
price: number;
|
||||||
price_formatted: string;
|
price_formatted: string;
|
||||||
price_input: string;
|
price_input: string;
|
||||||
stock_input: string;
|
stock_input: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user