feat(goods): Menambahkan kolom untuk menentukan harga poin per pcs/ml

- casting kolom tersebut
- menyesuaikan seeder nya
This commit is contained in:
Yoga Pangestu 2025-11-04 14:40:26 +07:00
parent 5427260c5a
commit a78c490f7d
9 changed files with 21 additions and 8 deletions

View File

@ -27,6 +27,7 @@ protected function casts(): array
return [ return [
'cost_price' => 'int', 'cost_price' => 'int',
'sale_price' => 'int', 'sale_price' => 'int',
'point_per_pcs' => 'int',
]; ];
} }

View File

@ -27,6 +27,7 @@ protected function casts(): array
'concentration' => Concentration::class, 'concentration' => Concentration::class,
'cost_price' => 'int', 'cost_price' => 'int',
'sale_price' => 'int', 'sale_price' => 'int',
'point_per_ml' => 'int',
]; ];
} }

View File

@ -24,6 +24,7 @@ protected function casts(): array
return [ return [
'cost_price' => 'int', 'cost_price' => 'int',
'sale_price' => 'int', 'sale_price' => 'int',
'point_per_pcs' => 'int',
]; ];
} }

View File

@ -21,6 +21,7 @@ public function up(): void
$table->enum('concentration', [Concentration::values()])->default(Concentration::EXTRAIT_DE_PERFUME)->comment(Concentration::comment()); $table->enum('concentration', [Concentration::values()])->default(Concentration::EXTRAIT_DE_PERFUME)->comment(Concentration::comment());
$table->unsignedInteger('cost_price')->default(0); $table->unsignedInteger('cost_price')->default(0);
$table->unsignedInteger('sale_price')->default(0); $table->unsignedInteger('sale_price')->default(0);
$table->unsignedInteger('point_per_ml');
$table->string('base_notes')->nullable(); $table->string('base_notes')->nullable();
$table->string('middle_notes')->nullable(); $table->string('middle_notes')->nullable();
$table->string('top_notes')->nullable(); $table->string('top_notes')->nullable();

View File

@ -18,6 +18,7 @@ public function up(): void
$table->string('sku', 20)->unique(); $table->string('sku', 20)->unique();
$table->unsignedInteger('cost_price')->default(0); $table->unsignedInteger('cost_price')->default(0);
$table->unsignedInteger('sale_price')->default(0); $table->unsignedInteger('sale_price')->default(0);
$table->unsignedInteger('point_per_pcs');
$table->text('description')->nullable(); $table->text('description')->nullable();
$table->timestamp('created_at')->useCurrent(); $table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();

View File

@ -18,6 +18,7 @@ public function up(): void
$table->unsignedInteger('size'); $table->unsignedInteger('size');
$table->unsignedInteger('cost_price')->default(0); $table->unsignedInteger('cost_price')->default(0);
$table->unsignedInteger('sale_price')->default(0); $table->unsignedInteger('sale_price')->default(0);
$table->unsignedInteger('point_per_pcs');
$table->text('description')->nullable(); $table->text('description')->nullable();
$table->timestamp('created_at')->useCurrent(); $table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();

View File

@ -24,15 +24,16 @@ public function run(): void
['name' => 'Botol Refill 500ml Bulk', 'size' => 500, 'cost_price' => 50000], ['name' => 'Botol Refill 500ml Bulk', 'size' => 500, 'cost_price' => 50000],
]; ];
foreach ($bottles as $index => $item) { foreach ($bottles as $bottle) {
$slug = Str::slug($item['name']); $slug = Str::slug($bottle['name']);
$bottle = Bottle::create([ $bottle = Bottle::create([
'name' => $item['name'], 'name' => $bottle['name'],
'slug' => $slug, 'slug' => $slug,
'size' => $item['size'], 'size' => $bottle['size'],
'cost_price' => $item['cost_price'], 'cost_price' => $bottle['cost_price'],
'sale_price' => $item['cost_price'] * 2, 'sale_price' => $bottle['cost_price'] * 2,
'point_per_pcs' => round($bottle['cost_price'] / 100),
'description' => fake()->sentence(10), 'description' => fake()->sentence(10),
]); ]);

View File

@ -34,6 +34,8 @@ public function run(): void
$slug = Str::slug($name); $slug = Str::slug($name);
$sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT); $sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT);
$salePrice = fake()->numberBetween(25, 50) * 100;
$perfume = Perfume::create([ $perfume = Perfume::create([
'brand_id' => $brand->id, 'brand_id' => $brand->id,
'name' => $name, 'name' => $name,
@ -41,7 +43,8 @@ public function run(): void
'sku' => $sku, 'sku' => $sku,
'concentration' => fake()->randomElement(Concentration::values()), 'concentration' => fake()->randomElement(Concentration::values()),
'cost_price' => fake()->numberBetween(5, 11) * 100, 'cost_price' => fake()->numberBetween(5, 11) * 100,
'sale_price' => fake()->numberBetween(25, 50) * 100, 'sale_price' => $salePrice,
'point_per_ml' => round($salePrice / 100),
'base_notes' => fake()->optional()->randomElement(['Amber', 'Musk', 'Vanilla', 'Sandalwood', 'Leather']), 'base_notes' => fake()->optional()->randomElement(['Amber', 'Musk', 'Vanilla', 'Sandalwood', 'Leather']),
'middle_notes' => fake()->optional()->randomElement(['Rose', 'Jasmine', 'Patchouli', 'Cedarwood', 'Iris']), 'middle_notes' => fake()->optional()->randomElement(['Rose', 'Jasmine', 'Patchouli', 'Cedarwood', 'Iris']),
'top_notes' => fake()->optional()->randomElement(['Citrus', 'Bergamot', 'Pepper', 'Mint', 'Lavender']), 'top_notes' => fake()->optional()->randomElement(['Citrus', 'Bergamot', 'Pepper', 'Mint', 'Lavender']),

View File

@ -28,12 +28,15 @@ public function run(): void
$slug = Str::slug($name); $slug = Str::slug($name);
$sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT); $sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT);
$salePrice = fake()->numberBetween(15, 200) * 1000;
$product = Product::create([ $product = Product::create([
'name' => $name, 'name' => $name,
'slug' => $slug, 'slug' => $slug,
'sku' => $sku, 'sku' => $sku,
'cost_price' => fake()->numberBetween(15, 80) * 1000, 'cost_price' => fake()->numberBetween(15, 80) * 1000,
'sale_price' => fake()->numberBetween(15, 200) * 1000, 'sale_price' => $salePrice,
'point_per_pcs' => round($salePrice / 100),
'description' => fake()->sentence(12), 'description' => fake()->sentence(12),
]); ]);