Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
6.4 kB
3
Indexable
Never
else if ($action == 'updateApproveStatusPreorder') {
                    try {
                        $preorderTransaction = PreorderTransaction::findOrFail($id);

                        if ($preorderTransaction) {
                            foreach ($preorderTransaction->details as $item) {
                                $preorderTransactionDetail = PreorderTransactionDetail::where('preorder_transaction_id', $preorderTransaction->id)
                                    ->where('product_id', $item->product_id)
                                    ->first();

                                if ($preorderTransactionDetail) {
                                    if ($preorderTransaction->type == 'wholesale' || $preorderTransaction->type == 'ezd') {
                                        /** create stock yang booked = false agar tidak mengurangi on hand (wholesale & ezd) */
                                        ReportStock::create([
                                            'warehouse_parent_id' => $preorderTransaction->supplying_warehouse_parent_id,
                                            'warehouse_id' => $preorderTransaction->supplying_warehouse_id,
                                            'quantity' => -$item->total_pack,
                                            'table_name' => 'preorder_transactions',
                                            'header_transaction_id' => $preorderTransaction->id,
                                            'header_transaction_id_2' => $item->id,
                                            'batch_number' => $item->batch,
                                            'product_id' => $item->product_id,
                                            'remark' => 'approval dari Preorder Transaction ' . $preorderTransaction->type,
                                            'header_transaction_code' => $preorderTransaction->sales_order_number,
                                            'is_booked' => false
                                        ]);

                                        ReportStock::create([
                                            'warehouse_parent_id' => $preorderTransaction->supplying_warehouse_parent_id,
                                            'warehouse_id' => $preorderTransaction->supplying_warehouse_id,
                                            'quantity' => $item->total_pack,
                                            'table_name' => 'preorder_transactions',
                                            'header_transaction_id' => $preorderTransaction->id,
                                            'header_transaction_id_2' => $item->id,
                                            'batch_number' => $item->batch,
                                            'product_id' => $item->product_id,
                                            'remark' => 'approval dari Preorder Transaction ' . $preorderTransaction->type,
                                            'header_transaction_code' => $preorderTransaction->sales_order_number,
                                            'is_booked' => true
                                        ]);
                                    } else {
                                        // pindah stock ke 1050 untuk OOT
                                        // ReportStock::create([
                                        //     'warehouse_parent_id' => $preorderTransaction->supplying_warehouse_parent_id,
                                        //     'warehouse_id' => $preorderTransaction->supplying_warehouse_id,
                                        //     'quantity' => -$item->total_pack,
                                        //     'table_name' => 'preorder_transactions',
                                        //     'header_transaction_id' => $preorderTransaction->id,
                                        //     'header_transaction_id_2' => $item->id,
                                        //     'batch_number' => $item->batch,
                                        //     'product_id' => $item->product_id,
                                        //     'remark' => 'approval dari Preorder Transaction ' . $preorderTransaction->type,
                                        //     'header_transaction_code' => $preorderTransaction->sales_order_number,
                                        //     'is_booked' => false
                                        // ]);

                                        // ReportStock::create([
                                        //     'warehouse_parent_id' => $preorderTransaction->supplying_warehouse_parent_id,
                                        //     'warehouse_id' => $preorderTransaction->supplying_warehouse_id,
                                        //     'quantity' => $item->total_pack,
                                        //     'table_name' => 'preorder_transactions',
                                        //     'header_transaction_id' => $preorderTransaction->id,
                                        //     'header_transaction_id_2' => $item->id,
                                        //     'batch_number' => $item->batch,
                                        //     'product_id' => $item->product_id,
                                        //     'remark' => 'approval dari Preorder Transaction ' . $preorderTransaction->type,
                                        //     'header_transaction_code' => $preorderTransaction->sales_order_number,
                                        //     'is_booked' => false
                                        // ]);
                                    }
                                }
                            }

                            $newData = [
                                'is_approve' => true,
                                'approved_by' => auth()->id(),
                                'approved_at' => now(),
                            ];

                            $data = $this->modelName($actionsToModel[$action])::where('id', $id)->update($newData);
                        }
                    } catch (\Throwable $th) {
                        error_log($th);
                        throw $th;
                    }
                }
Leave a Comment