[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * Lists all MonthlyMonitoringFormSangini models. * @return mixed */ public function actionIndex() { checkAuthentication($this); $searchModel = new MonthlyMonitoringFormSanginiSearch(); $view_flag = !empty(Yii::$app->request->queryParams['MonthlyMonitoringFormSanginiSearch']['block_view']) ? Yii::$app->request->queryParams['MonthlyMonitoringFormSanginiSearch']['block_view'] : 0; $dataProvider = $searchModel->search(Yii::$app->request->queryParams,$view_flag); $session = Yii::$app->session->get('login_info'); $monthMaster = ArrayHelper::map(getOptions(MonthMaster::tableName(), 'month_mmr'), 'id', 'name'); $statusMaster = StatusMaster::find()->where(['<>','level_id',UserLevel::ADMIN])->asArray()->all(); $statusMaster = ArrayHelper::map($statusMaster,'id','label'); if (!empty(Yii::$app->request->queryParams['MonthlyMonitoringFormSanginiSearch'])) { $res = Yii::$app->request->queryParams['MonthlyMonitoringFormSanginiSearch']; $baseM = new BaseModel(); if (!empty($res['state_id'])) $geoData['district_list'] = $baseM->getGeoData(Common::STATE, $res['state_id'], true); else $geoData['district_list'] = $baseM->getGeoData(Common::STATE, '', true); if (!empty($res['district_id'])) $geoData['block_list'] = $baseM->getGeoData(Common::DISTRICT, $res['district_id'], true); else $geoData['block_list'] = $baseM->getGeoData(Common::DISTRICT, '', true); if (!empty($res['block_id'])) $geoData['grampanchayat_list'] = $baseM->getGeoData(Common::BLOCK, $res['block_id'], true); else $geoData['grampanchayat_list'] = $baseM->getGeoData(Common::BLOCK, '', true); if (!empty($res['grampanchayat_id'])) $geoData['village_list'] = $baseM->getGeoData(Common::GRAMPANCHAYAT, $res['grampanchayat_id'], true); else $geoData['village_list'] = $baseM->getGeoData(Common::GRAMPANCHAYAT, '', true); } else { $geoData = getStateData(); } return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'geoData' => $geoData, 'monthMaster' => $monthMaster, 'statusMaster' => $statusMaster, 'block_view' => $view_flag ]); } /** * Displays a single MonthlyMonitoringFormSangini model. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new MonthlyMonitoringFormSangini model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MonthlyMonitoringFormSangini(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', [ 'model' => $model, ]); } /** * Updates an existing MonthlyMonitoringFormSangini model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } /** * Deletes an existing MonthlyMonitoringFormSangini model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the MonthlyMonitoringFormSangini model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MonthlyMonitoringFormSangini the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MonthlyMonitoringFormSangini::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } /** * This function handles the submission and updating of monthly monitoring form data for a specific * user. * * @param id The ID of the monthly monitoring form for which the work details are being * viewed/updated. * * @return either a redirect to the index page or a rendered view of the work-details page with the * work_details and model variables passed as parameters. */ public function actionWorkDetails($id) { checkAuthentication($this); $searchModel = new MonthlyMonitoringFormSanginiSearch(); $model = new MonthlyMonitoringFormSangini(); $idexist = $searchModel->checkUserWiseRecord($id); if (empty($idexist)) { return $this->redirect(['user/permission-denied']); } else { $dataSet = $model->GetWorkingDetails($id); $dataSet['project_officer'] = ''; if(!empty($dataSet)){ if(!empty($dataSet['village_id'])){ $officer_name = User::find()->select('user.name as project_officer') ->innerJoin('location_mapper_web','user.user_id=location_mapper_web.user_id') ->where(['location_mapper_web.location_id'=>$dataSet['village_id']])->asArray()->one(); } $dataSet['project_officer'] = !empty($officer_name['project_officer']) ? $officer_name['project_officer'] : ''; } $model = $this->findModel($id); } if (!empty(Yii::$app->request->post())) { $post = Yii::$app->request->post(); $work_details = $post['work_details']; $session = Yii::$app->session->get('login_info'); $transaction = Yii::$app->db->beginTransaction(); /* The above code is checking if the value of `['MM_review_status']` is empty or equal to `Common::PENDING`. If either of these conditions is true, it sets a flash message with an error and renders the 'work-details' view with the `` and `` variables. */ if ((empty($post['MM_review_status'])) || ($post['MM_review_status'] == Common::PENDING)) { Yii::$app->session->setFlash('error', "Please select approve or flag status"); return $this->render('work-details', [ 'work_details' => $dataSet, 'model' => $model ]); } $status_Model = new StatusMaster(); /* The above code is checking if the 'MM_review_status' field in the array is not empty. If it is not empty, it retrieves the 'reviewed_by' value from the MonthlyMonitoringFormSangini model where the 'id' matches the variable. It then checks the approval status of the user based on their level and the 'reviewed_by' value.If the approval status is true, it sets a flash message and renders the 'work-details' view with the 'work_details' and 'model' variables. */ if ((!empty($post['MM_review_status']))) { $review_status = MonthlyMonitoringFormSangini::find()->select('reviewed_by')->where(['id' => $id])->one(); $approval_status = getApproval(getUserLevel(),$review_status['reviewed_by']); if($approval_status){ Yii::$app->session->setFlash('error', "Cannot Update, This monitoring has been approved"); return $this->render('work-details', [ 'work_details' => $dataSet, 'model' => $model ]); } } /*setting the monthlymonitoring model values from post*/ $MonthlyMonitoringFormSanginiModel = \backend\models\MonthlyMonitoringFormSangini::find()->where(['id' => $id])->one(); $MonthlyMonitoringFormSanginiModel->MM_review_status = ($post['MM_review_status']) ? $post['MM_review_status'] : Common::PENDING; $MonthlyMonitoringFormSanginiModel->reason_for_approving = ($post['reason_for_approving']) ? $post['reason_for_approving'] : NULL; $MonthlyMonitoringFormSanginiModel->reason_for_flagging = ($post['reason_for_flagging']) ? $post['reason_for_flagging'] : NULL; $MonthlyMonitoringFormSanginiModel->no_focus_gp_diss = ($work_details['no_focus_gp_diss']) ? $work_details['no_focus_gp_diss'] : ''; $MonthlyMonitoringFormSanginiModel->no_of_family_cons = ($work_details['no_of_family_cons']) ? $work_details['no_of_family_cons'] : ''; $MonthlyMonitoringFormSanginiModel->no_of_sneh_cond = ($work_details['no_of_sneh_cond']) ? $work_details['no_of_sneh_cond'] : ''; $MonthlyMonitoringFormSanginiModel->no_of_cooking_demon = ($work_details['no_of_cooking_demon']) ? $work_details['no_of_cooking_demon'] : ''; $MonthlyMonitoringFormSanginiModel->no_of_vill_evt = ($work_details['no_of_vill_evt']) ? $work_details['no_of_vill_evt'] : ''; $MonthlyMonitoringFormSanginiModel->no_nutri_visit = ($work_details['no_nutri_visit']) ? $work_details['no_nutri_visit'] : ''; $MonthlyMonitoringFormSanginiModel->seed_dist = ($work_details['seed_dist']) ? $work_details['seed_dist'] : ''; $MonthlyMonitoringFormSanginiModel->no_of_wash_kit = ($work_details['no_of_wash_kit']) ? $work_details['no_of_wash_kit'] : ''; $MonthlyMonitoringFormSanginiModel->sam_mam = ($work_details['sam_mam']) ? $work_details['sam_mam'] : ''; $MonthlyMonitoringFormSanginiModel->MAM_health = ($work_details['MAM_health']) ? $work_details['MAM_health'] : ''; $remark = ''; if($post['MM_review_status'] == Common::APPROVED){ /* The above code is setting the "reviewed_by" property of the object to the status ID obtained from the object using the value of the "MM_review_status" key in the array. It is also assigning the value of the "reason_for_approving" key in the array to the variable. */ $MonthlyMonitoringFormSanginiModel->reviewed_by = $status_Model->getStatusId($post['MM_review_status']); $remark = $post['reason_for_approving']; }else if($post['MM_review_status'] == Common::REJECTED){ /* The above code is checking if the variable`->reason_for_approving` is not empty. If it is not empty, then it sets its value to `NULL`. */ if(!empty($MonthlyMonitoringFormSanginiModel->reason_for_approving)){ $MonthlyMonitoringFormSanginiModel->reason_for_approving = NULL; } $MonthlyMonitoringFormSanginiModel->reviewed_by = $status_Model->getStatusId($post['MM_review_status']); $remark = $post['reason_for_flagging']; } if ($MonthlyMonitoringFormSanginiModel->save()) { $ids = []; if (isset($post['additional_activity_deleted']) && !empty($post['additional_activity_deleted'])) { $ids = explode(',', $post['additional_activity_deleted']); MonthlyMonitoringMapper::deleteAll(['IN', 'id', $ids]); } /*after saving the monitoring table data we are saving the aditional activity data in MonthlyMonitoringMapper*/ if (!empty($post['additional_activity'])) { foreach ($post['additional_activity'] as $value) { if (isset($value['exist_id']) && !empty($value['exist_id'])) { $modelMonthlyMonitoringMapper = MonthlyMonitoringMapper::find()->where(['id' => $value['exist_id']])->one(); } else { $modelMonthlyMonitoringMapper = new MonthlyMonitoringMapper(); $modelMonthlyMonitoringMapper->monitoring_id = $id; } if(!empty($value['name']) && !empty($value['work'])){ $modelMonthlyMonitoringMapper->monitoring_id = $id; $modelMonthlyMonitoringMapper->activity_name = $value['name']; $modelMonthlyMonitoringMapper->amount = $value['work']; if (!$modelMonthlyMonitoringMapper->save()) { $transaction->rollback(); Yii::$app->session->setFlash('error', $modelMonthlyMonitoringMapper->getErrors()); return $this->render('work-details', [ 'work_details' => $dataSet, 'model' => $model ]); } } } } /*after saving the monitoring table data and aditional activity data we are saving the review mapper data where we store the review comment*/ if(!empty($post['reason_for_approving']) || !empty($post['reason_for_flagging'])){ $review_mapper_model = ReviewMapper::find()->where(['status_id' => $status_Model->getStatusId($post['MM_review_status'])])->one(); if(empty( $review_mapper_model)){ $review_mapper_model = new ReviewMapper(); $review_mapper_model->monitoring_id = $id; $review_mapper_model->status_id = $status_Model->getStatusId($post['MM_review_status']); } $review_mapper_model->remark = $remark; if(!$review_mapper_model->save()){ $transaction->rollback(); Yii::$app->session->setFlash('error', $modelMonthlyMonitoringMapper->getErrors()); return $this->render('work-details', [ 'work_details' => $dataSet, 'model' => $model ]); } } if(getUserLevel()==UserLevel::SO && $post['MM_review_status'] == Common::APPROVED){ $this->savePayslip($post,$id); } } $transaction->commit(); $searchModel = new MonthlyMonitoringFormSanginiSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $geoData = getStateData(); $monthMaster = ArrayHelper::map(getOptions(MonthMaster::tableName(), 'month_mmr'), 'id', 'name'); return $this->redirect('index'); } else { return $this->render('work-details', [ 'work_details' => $dataSet, 'model' => $model ]); } } /** * This function generates a payment slip for a monthly monitoring form and saves the data to the * database. * * @param id The parameter "id" is used to identify the Monthly Monitoring Form Sangini record for * which the payment slip is being generated. It is used to retrieve the necessary data from the * database and to save the payment slip details for the corresponding record. * * @return a rendered view named 'payment_slip' with the following variables: 'work_details', * 'pay_data', and 'additional_activity_data'. */ public function actionPaymentSlip($id) { checkAuthentication($this); $model = new MonthlyMonitoringFormSangini(); $session = Yii::$app->session->get('login_info'); if (!empty(Yii::$app->request->post())) { $post = Yii::$app->request->post(); /*setting the model value with values of post data*/ $adjM = MonthlyPayslip::find()->where(['mm_id' => $post['monitoring_id']])->one(); $saveMonthlyPayslip = $adjM ? $adjM : new MonthlyPayslip(); $saveMonthlyPayslip->mm_id = (isset($post['monitoring_id'])) ? $post['monitoring_id'] : ""; $saveMonthlyPayslip->month_id = 1; $saveMonthlyPayslip->adj_sign = (isset($post['adj_sign'])) ? trim($post['adj_sign']) : ""; $saveMonthlyPayslip->adjustment_amount = (isset($post['adjustment'])) ? $post['adjustment'] : ""; $saveMonthlyPayslip->adjustment_remark = (isset($post['adjustment_remarks'])) ? $post['adjustment_remarks'] : ""; $saveMonthlyPayslip->total = (isset($post['totalAmt'])) ? $post['totalAmt'] : ""; $saveMonthlyPayslip->total_after_adjustment = (isset($post['amount_after_adjustment'])) ? $post['amount_after_adjustment'] : ""; $saveMonthlyPayslip->payment_date = date('YYYY-MM-DD'); $saveMonthlyPayslip->payment_status = Common::UNPAID; $saveMonthlyPayslip->sangini_id = (isset($post['sangini_id'])) ? $post['sangini_id'] : ""; if ($adjM) { $saveMonthlyPayslip->updated_by = (isset($session['user_id'])) ? $session['user_id'] : ""; } else { $saveMonthlyPayslip->created_by = (isset($session['user_id'])) ? $session['user_id'] : ""; } /*we saved the changes in monthly payslip table after the SO approved the monitoring, then we are saving the monitoring question,rate and values in payslip mapper */ if ($saveMonthlyPayslip->save()) { $payslip_id = $saveMonthlyPayslip->id; $payslipMapper = MonthlyPayslipMapper::find()->where(['payslip_id' => $payslip_id])->one(); if (!empty($post['monthly_monitoring'])) { foreach ($post['monthly_monitoring'] as $mm) { $savePayslipMapper = $payslipMapper ? $payslipMapper : new MonthlyPayslipMapper(); $savePayslipMapper->payslip_id = $payslip_id ?? ""; $savePayslipMapper->activity_id = (isset($mm['question_id'])) ? $mm['question_id'] : ""; $savePayslipMapper->rate = (isset($mm['rate'])) ? $mm['rate'] : ""; $savePayslipMapper->amount = (isset($mm['amount'])) ? $mm['amount'] : ""; $savePayslipMapper->save(); } } } } $payslip_data = MonthlyPayslip::find()->where(['mm_id' => $id])->asArray()->one(); $travel_comm_date = CustomSetting::find()->select('value')->where(['short_key'=>'sang_trav_comm'])->asArray()->one(); /* if the payslip data model is non empty we are storing the payslip data from payslip table and mapper table into an array to show it in payslip view.*/ if (!empty($payslip_data)) { $model = new MonthlyPayslip(); $dataSet = $model->GetPayslipDetails($id); $payslip_activity_mapper_data = MonthlyPayslipMapper::find()->where(['payslip_id' => $dataSet['payslip_id']])->asArray()->all(); $payslip_activity_data = PayslipActivityMaster::find()->asArray()->all(); $additional_activity_data = MonthlyMonitoringMapper::find()->where(['monitoring_id' => $id])->asArray()->all(); $pay_data = []; $fixed_additional_activity_data = []; foreach ($payslip_activity_data as $key => $val) { $work = ($payslip_activity_mapper_data[$key]['activity_id'] == $val['id']) ? $payslip_activity_mapper_data[$key]['value'] : ''; $val['value'] = $work; if(str_contains($payslip_activity_data[$key]['activity_name'], 'Additional Activity')){ array_push($fixed_additional_activity_data, $val); }else{ array_push($pay_data, $val); } } } else { $dataSet = $model->GetWorkingDetails($id); $payslip_activity_data = PayslipActivityMaster::find()->asArray()->all(); $additional_activity_data = MonthlyMonitoringMapper::find()->where(['monitoring_id' => $id])->asArray()->all(); $pay_data = []; $fixed_additional_activity_data = []; foreach ($payslip_activity_data as $val) { $work = array_key_exists($val['activity_short_key'], $dataSet) ? $dataSet[$val['activity_short_key']] : 0; $val['value'] = $work; if(str_contains($val['activity_short_key'], 'Additional')){ array_push($fixed_additional_activity_data, $val); }else{ array_push($pay_data, $val); array_push($pay_data, $val); array_push($pay_data, $val); } } } $payslip_date = MonthMaster::find()->select('start_date')->where(['id'=>$dataSet['month']])->asArray()->one(); // darr($payslip_date); die; return $this->render('payment_slip', [ 'work_details' => $dataSet, 'pay_data' => $pay_data, 'fixed_additional_activity_data' => $fixed_additional_activity_data, 'additional_activity_data' => $additional_activity_data, 'travel_comm_date'=>$travel_comm_date, 'payslip_date' => $payslip_date ]); } /** * This function saves monthly payslip data for a given monitoring ID and calculates the total * amount based on various activity rates and values. * * @param data It is an array of data containing the payslip details such as month, sang_basepay, * sang_trav_comm, etc. * @param id The parameter is the monitoring ID used to retrieve working details from the * MonthlyMonitoringFormSangini model. It is also used to retrieve additional activity data from * the MonthlyMonitoringMapper model. */ public function savePayslip($data,$id){ $monitoring_id = $id; $model = new MonthlyMonitoringFormSangini(); $dataSet = $model->GetWorkingDetails($monitoring_id); $total = 0; $payslip_activity_data = PayslipActivityMaster::find()->asArray()->all(); $additional_activity_data = MonthlyMonitoringMapper::find()->where(['monitoring_id' => $monitoring_id])->asArray()->all(); $travel_comm_date = CustomSetting::find()->select('value')->where(['short_key'=>'sang_trav_comm'])->asArray()->one(); $payslip_date = MonthMaster::find()->select('start_date')->where(['id'=>$dataSet['month']])->asArray()->one(); /*we saved the changes in monthly payslip table after the SO approved the monitoring */ $pay_data = []; foreach ($payslip_activity_data as $val) { if(!empty($val['activity_short_key']) && !empty($dataSet)){ $work = array_key_exists($val['activity_short_key'], $dataSet) ? $dataSet[$val['activity_short_key']] : 0; $val['value'] = $work; $val['amount'] = $work * $val['activity_rate']; } array_push($pay_data, $val); } $a_total = array_sum(array_column($pay_data,'amount')); $b_total = array_sum(array_column($additional_activity_data,'amount')); if($payslip_date['start_date'] >= $travel_comm_date['value']){ $total = $a_total+$b_total+$data['sang_basepay']+$data['travel']+$data['communication']; }else{ $total = $a_total+$b_total+$data['sang_basepay']+$data['sang_trav_comm']; } /* The above code is saving monthly payslip data and its related monitoring questions, rates,and values in the database. It first checks if the variable is not empty, then finds the MonthlyPayslip model based on the monitoring_id and creates a new one if it doesn'texist. It then sets the necessary attributes of the MonthlyPayslip model and saves it to the database. If the save is successful, it retrieves the payslip_id and loops through thearray to save the monitoring questions, rates, and values in theMonthlyPayslipMapper table. It */ if (!empty($dataSet)) { $mp_model = MonthlyPayslip::find()->where(['mm_id' => $monitoring_id])->one(); $saveMonthlyPayslip = $mp_model ? $mp_model : new MonthlyPayslip(); // darr($saveMonthlyPayslip); die; $saveMonthlyPayslip->mm_id = (isset($monitoring_id)) ? $monitoring_id : ""; $saveMonthlyPayslip->month_id = $data['month']; $saveMonthlyPayslip->total = $total; $saveMonthlyPayslip->payment_date = date('YYYY-MM-DD'); $saveMonthlyPayslip->payment_status = Common::UNPAID; $saveMonthlyPayslip->sangini_id = $dataSet['sangini_id']; if($mp_model) { $saveMonthlyPayslip->updated_by = getUserId(); } else { $saveMonthlyPayslip->created_by = getUserId(); } /*we saved the changes in monthly payslip table then we are saving the monitoring question,rate and values in payslip mapper */ if ($saveMonthlyPayslip->save()) { $payslip_id = $saveMonthlyPayslip->id; if (!empty($pay_data)) { foreach ($pay_data as $key => $pd) { $payslipMapper = MonthlyPayslipMapper::find()->where(['payslip_id' => $payslip_id])->andWhere(['activity_id'=>$pd['id']])->one(); $savePayslipMapper = !empty($payslipMapper) ? $payslipMapper : new MonthlyPayslipMapper(); $rate = !empty($pd['activity_rate']) ? $pd['activity_rate'] : 0; $value = !empty($pd['value']) ? $pd['value'] : 0; $savePayslipMapper->payslip_id = $payslip_id ?? ""; $savePayslipMapper->activity_id = (isset($pd['id'])) ? $pd['id'] : ""; $savePayslipMapper->value = $value; $savePayslipMapper->rate = (isset($pd['activity_rate'])) ? $pd['activity_rate'] : ""; $savePayslipMapper->amount = $rate*$value; if(!$savePayslipMapper->save()){ Yii::$app->session->setFlash('error','Payslip not saved'); } } } } } } /** * This is a PHP function that handles the approval or rejection of monthly monitoring forms for a * specific block and saves the status and reason for approval/rejection in the database. * * @return an array with three keys: 'success', 'status', and 'message'. The value of 'success' key * is a boolean indicating whether the operation was successful or not. The value of 'status' key * is an integer indicating the HTTP status code. The value of 'message' key is a string message * indicating the result of the operation. */ public function actionBlockLevelPayApproval(){ if(!empty(Yii::$app->request->post())){ \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $post = Yii::$app->request->post(); $model = new MonthlyMonitoringFormSanginiSearch(); $params['MonthlyMonitoringFormSanginiSearch']['block_id'] = $post['review_block_id']; $mm_data = $model->search($params,1,true); $mm_ids = explode(".",$post['approved_ids']); $transaction = Yii::$app->db->beginTransaction(); $remark = ''; foreach($mm_ids as $mm){ $MonthlyMonitoringFormSanginiModel = MonthlyMonitoringFormSangini::find()->where(['id' => $mm])->one(); $MonthlyMonitoringFormSanginiModel->MM_review_status = !empty($post['MM_review_status']) ? $post['MM_review_status'] : Common::PENDING; $MonthlyMonitoringFormSanginiModel->reason_for_approving = !empty($post['reason_for_approving']) ? $post['reason_for_approving'] : NULL; $MonthlyMonitoringFormSanginiModel->reason_for_flagging = !empty($post['reason_for_flagging']) ? $post['reason_for_flagging'] : NULL; $status_Model = new StatusMaster(); /* The above code is checking the value of the variable `['MM_review_status']` and based on its value, it is setting the value of `->reviewed_by` and ``. If the value of `['MM_review_status']` is `Common::APPROVED`, then `->reviewed_by` is set to the status ID of the approved status and `` is set to the reason for approving. If the value of `['MM_review_status']` is `Common::RE */ if($post['MM_review_status'] == Common::APPROVED){ $MonthlyMonitoringFormSanginiModel->reviewed_by = $status_Model->getStatusId($post['MM_review_status']); $remark = $post['reason_for_approving']; }else if($post['MM_review_status'] == Common::REJECTED){ if(!empty($MonthlyMonitoringFormSanginiModel->reason_for_approving)){ $MonthlyMonitoringFormSanginiModel->reason_for_approving = NULL; } $MonthlyMonitoringFormSanginiModel->reviewed_by = $status_Model->getStatusId($post['MM_review_status']); $remark = $post['reason_for_flagging']; } if ($MonthlyMonitoringFormSanginiModel->save()) { if(!empty($post['reason_for_approving']) || !empty($post['reason_for_flagging'])){ $review_mapper_model = ReviewMapper::find()->where(['status_id' => $status_Model->getStatusId($post['MM_review_status'])])->one(); /* The above code is checking if the variable `` is empty. If it is empty, it creates a new instance of the `ReviewMapper` class and assigns it to the variable. It also sets the `monitoring_id` property of the object to the value of `` and the `status_id` property to the result of calling the `getStatusId()` method of the `` object with the value of `['MM_review_status']` as its argument. */ if(empty( $review_mapper_model)){ $review_mapper_model = new ReviewMapper(); $review_mapper_model->monitoring_id = $mm; $review_mapper_model->status_id = $status_Model->getStatusId($post['MM_review_status']); } $review_mapper_model->remark = $remark; /* The above code is checking if the save method of the object returns false. If it does, it rolls back the transaction and returns an array with a success status of false, a status code of 400, and an error message containing the errors from the object. */ if (!$review_mapper_model->save()) { $transaction->rollback(); $return = [ 'success' => false, 'status' => 400, 'message' => $review_mapper_model->getErrors(), ]; return $return; } } }else{ $transaction->rollback(); } } $transaction->commit(); return [ 'success' => true, 'status' => 200, 'message' => "Successfully Save", ]; } } }