Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
5.2 kB
2
Indexable
Never
/**
                 * When form is updated
                 */
                $oldValues = $model->getOriginal();

                $model->previous_status = $oldValues['status'];

                if ($model->previous_status == $model->getDefaultDraftStatus()) {
                    if ($user->isAuthorized() || $model->isUserAllowed() || $model->isUserOwner()) {
                        if (in_array($model->status, [
                            $model->getDefaultDraftStatus(),
                            $model->getDefaultSubmittedStatus(),
                            $model->getDefaultPendingStatus(),
                            $model->getDefaultPendingApprovalStatus(),
                        ])) {
                            if ($model->status == $model->getDefaultDraftStatus()) {
                                $model->status = $model->getDefaultDraftStatus();
                            } else {
                                $model = $model->setDefaultStatus();
                            }
                        } else {
                            throw new Exception(__('Invalid action, The operation has failed'));
                        }
                    } else {
                        throw new Exception(__('Invalid action, The operation has failed'));
                    }
                } elseif ($model->previous_status == $model->getDefaultPendingApprovalStatus()) {
                    if ($user->isAuthorized() || $model->isUserAllowed()) {
                        if (in_array($model->status, [
                            $model->getDefaultApprovedStatus(),
                            $model->getDefaultRejectedStatus(),
                        ])) {
                            if ($model->status == $model->getDefaultApprovedStatus()) {
                                $model->status = $model->getDefaultPendingStatus();
                                $model->approved_date = $date;
                                $model->approved_by = $user->id;
                            } else if ($model->status == $model->getDefaultRejectedStatus()) {
                                $model->rejected_date = $date;
                                $model->rejected_by = $user->id;
                            }
                        } else {
                            throw new Exception(__('Invalid action, The operation has failed'));
                        }
                    } else {
                        throw new Exception(__('Invalid action, The operation has failed'));
                    }
                } elseif ($model->previous_status == $model->getDefaultPendingStatus()) {
                    if ($user->isAuthorized()) {
                        if (in_array($model->status, [
                            $model->getDefaultDoneStatus(),
                            $model->getDefaultClosedStatus(),
                            $model->getDefaultVoidedStatus(),
                        ])) {
                            if ($model->status == $model->getDefaultClosedStatus()) {
                                $model->closed_date = $date;
                                $model->closed_by = $user->id;
                            } else if ($model->status == $model->getDefaultVoidedStatus()) {
                                $model->voided_date = $date;
                                $model->voided_by = $user->id;
                            }
                        } else {
                            throw new Exception(__('Invalid action, The operation has failed'));
                        }
                    } else {
                        throw new Exception(__('Invalid action, The operation has failed'));
                    }
                } elseif (in_array($model->status, [
                                $model->getDefaultPendingStatus(),
                                $model->getDefaultPartiallyDoneStatus(),
                                $model->getDefaultDoneStatus()])) {
                    if ($user->isAuthorized()) {
                        if (in_array($model->status, [
                            $model->getDefaultDoneStatus(),
                            $model->getDefaultClosedStatus(),
                            $model->getDefaultVoidedStatus(),
                        ])) {
                            if ($model->status == $model->getDefaultClosedStatus()) {
                                $model->closed_date = $date;
                                $model->closed_by = $user->id;
                            } else if ($model->status == $model->getDefaultVoidedStatus()) {
                                $model->voided_date = $date;
                                $model->voided_by = $user->id;
                            }
                        } else {
                            throw new Exception(__('Invalid action, The operation has failed'));
                        }
                    } else {
                        throw new Exception(__('Invalid action, The operation has failed'));
                    }
                } else {
                    throw new Exception(__('Invalid action, The operation has failed'));
                }
            }
Leave a Comment