diff --git a/.ai/REFERENCE.md b/.ai/REFERENCE.md index 8be9e31..c81b583 100644 --- a/.ai/REFERENCE.md +++ b/.ai/REFERENCE.md @@ -225,8 +225,8 @@ ### `purchase_items` → PurchaseItem - Relations: purchase(BelongsTo→Purchase), rawMaterialPrice(BelongsTo→RawMaterialPrice,withTrashed), user(BelongsTo→User) ### `restocks` → Restock -`id` `created_by_id`(FK→users) `subtotal`(ubig) `total`(ubig) `notes`(100,null) `stock_type`(enum,default:good) `created_at` `updated_at` `deleted_at` -- Casts: stock_type(ProductStockQuality), subtotal(int), total(int) +`id` `created_by_id`(FK→users) `total`(ubig) `notes`(100,null) `stock_type`(enum,default:good) `created_at` `updated_at` `deleted_at` +- Casts: stock_type(ProductStockQuality), total(int) - Scopes: good(), reject() - Relations: createdBy(BelongsTo→User), restockItems(HasMany→RestockItem) diff --git a/app/Models/Restock.php b/app/Models/Restock.php index 2a9d437..157cfda 100644 --- a/app/Models/Restock.php +++ b/app/Models/Restock.php @@ -18,7 +18,7 @@ use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; -#[Appends(['stock_type_label', 'formatted_subtotal', 'formatted_total'])] +#[Appends(['stock_type_label', 'formatted_total'])] #[Guarded(['id'])] class Restock extends Model implements HasMedia { @@ -28,7 +28,6 @@ protected function casts(): array { return [ 'stock_type' => ProductStockQuality::class, - 'subtotal' => 'integer', 'total' => 'integer', ]; } @@ -40,13 +39,6 @@ protected function stockTypeLabel(): Attribute ); } - protected function formattedSubtotal(): Attribute - { - return Attribute::make( - get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'), - ); - } - protected function formattedTotal(): Attribute { return Attribute::make( diff --git a/app/OldDataMigrations/InventoryMigration.php b/app/OldDataMigrations/InventoryMigration.php index d6a2de7..0e1d36d 100644 --- a/app/OldDataMigrations/InventoryMigration.php +++ b/app/OldDataMigrations/InventoryMigration.php @@ -16,7 +16,7 @@ public function migrate(): array $results['retail_stock_histories'] = $this->migrateTable('retail_stock_histories'); $results['stok_opnames'] = $this->migrateTable('stok_opnames'); $results['stok_opname_items'] = $this->migrateTable('stok_opname_items'); - $results['restocks'] = $this->migrateTable('restocks'); + $results['restocks'] = $this->migrateTableWithoutColumns('restocks', ['subtotal']); $results['restock_items'] = $this->migrateTable('restock_items'); $results['stock_mutations'] = $this->migrateTable('stock_mutations', function ($row) { $fields = ['quantity', 'stock_before', 'stock_after']; diff --git a/app/Services/Admin/Manage/RestockService.php b/app/Services/Admin/Manage/RestockService.php index 754eec9..40b82f7 100644 --- a/app/Services/Admin/Manage/RestockService.php +++ b/app/Services/Admin/Manage/RestockService.php @@ -26,7 +26,7 @@ public function __construct( public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator { $paginator = Restock::query() - ->select(['id', 'created_by_id', 'subtotal', 'total', 'notes', 'stock_type', 'created_at']) + ->select(['id', 'created_by_id', 'total', 'notes', 'stock_type', 'created_at']) ->with([ 'createdBy:id', 'createdBy.userProfile:id,user_id,full_name', @@ -66,15 +66,14 @@ public function store(array $data): Restock { return DB::transaction(function () use ($data) { $now = now(); - $subtotal = 0; + $total = 0; $stockType = $data['stock_type'] ?? ProductStockQuality::GOOD->value; - $itemRows = $this->buildItemRows($data['items'], $stockType, $now, $subtotal); + $itemRows = $this->buildItemRows($data['items'], $stockType, $now, $total); $restock = Restock::create([ 'created_by_id' => auth()->id(), - 'subtotal' => $subtotal, - 'total' => $subtotal, + 'total' => $total, 'notes' => $data['notes'] ?? null, 'stock_type' => $stockType, ]); @@ -90,7 +89,7 @@ public function store(array $data): Restock NotificationService::notify( roles: [Role::OWNER, Role::DEVELOPER, Role::ADMIN_TOKO], title: 'Restock Baru', - body: 'Restock '.($stockType === ProductStockQuality::GOOD->value ? 'produk' : 'reject').' sebesar Rp '.number_format($subtotal, 0, ',', '.').' berhasil dicatat oleh '.auth()->user()->full_name.'.', + body: 'Restock '.($stockType === ProductStockQuality::GOOD->value ? 'produk' : 'reject').' sebesar Rp '.number_format($total, 0, ',', '.').' berhasil dicatat oleh '.auth()->user()->full_name.'.', url: route('admin.manage.restocks.index'), ); @@ -110,10 +109,10 @@ public function update(Restock $restock, array $data): Restock $restock->restockItems()->delete(); $now = now(); - $subtotal = 0; + $total = 0; $stockType = $data['stock_type'] ?? $restock->stock_type->value; - $itemRows = $this->buildItemRows($data['items'], $stockType, $now, $subtotal); + $itemRows = $this->buildItemRows($data['items'], $stockType, $now, $total); foreach ($itemRows as &$row) { $row['restock_id'] = $restock->id; @@ -121,8 +120,7 @@ public function update(Restock $restock, array $data): Restock DB::table('restock_items')->insert($itemRows); $restock->update([ - 'subtotal' => $subtotal, - 'total' => $subtotal, + 'total' => $total, 'notes' => $data['notes'] ?? null, 'stock_type' => $stockType, ]); @@ -150,7 +148,7 @@ public function destroy(Restock $restock): bool }); } - private function buildItemRows(array $items, string $stockType, $now, int &$subtotal): array + private function buildItemRows(array $items, string $stockType, $now, int &$total): array { $priceType = $stockType === ProductStockQuality::REJECT->value ? PriceType::REJECT @@ -168,11 +166,11 @@ private function buildItemRows(array $items, string $stockType, $now, int &$subt return [$variant->id => $price?->price ?? 0]; }); - return collect($items)->map(function ($item) use ($now, $prices, &$subtotal) { + return collect($items)->map(function ($item) use ($now, $prices, &$total) { $quantity = (int) $item['quantity']; $unitPrice = (int) ($prices[$item['product_variant_id']] ?? 0); $itemSubtotal = $unitPrice * $quantity; - $subtotal += $itemSubtotal; + $total += $itemSubtotal; return [ 'restock_id' => null, diff --git a/database/migrations/2026_07_13_000001_create_restocks_table.php b/database/migrations/2026_07_13_000001_create_restocks_table.php index 978e75f..1c86ad0 100644 --- a/database/migrations/2026_07_13_000001_create_restocks_table.php +++ b/database/migrations/2026_07_13_000001_create_restocks_table.php @@ -14,7 +14,6 @@ public function up(): void $table->foreignId('created_by_id')->constrained('users')->cascadeOnDelete(); - $table->unsignedBigInteger('subtotal'); $table->unsignedBigInteger('total'); $table->string('notes', 100)->nullable(); $table->enum('stock_type', ProductStockQuality::values())->default(ProductStockQuality::GOOD->value); diff --git a/resources/js/pages/admin/manage/restock/columns.tsx b/resources/js/pages/admin/manage/restock/columns.tsx index e77948b..7e5f594 100644 --- a/resources/js/pages/admin/manage/restock/columns.tsx +++ b/resources/js/pages/admin/manage/restock/columns.tsx @@ -21,7 +21,6 @@ export type RestockItem = { export type Restock = { id: number; created_by_id: number; - subtotal: number; total: number; notes: string | null; stock_type: RestockStockType; diff --git a/resources/js/pages/admin/manage/restock/restock-card.tsx b/resources/js/pages/admin/manage/restock/restock-card.tsx index 7354708..1a3802c 100644 --- a/resources/js/pages/admin/manage/restock/restock-card.tsx +++ b/resources/js/pages/admin/manage/restock/restock-card.tsx @@ -120,12 +120,6 @@ export function RestockCardRow({ {formatNumber(totalQty)} - - - Sub:{' '} - - {formatCurrency(restock.subtotal)} - Total:{' '}