/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model=Consignmentnote::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
private function updateJobStatus($personId, $postedData){ if(!is_array($postedData)){ $postedData = array($postedData); } $rjcnt = 0; $rjctdJobs = array(); foreach ($postedData as &$data) { try{ $job_id = -1; if(isset($data->job_id)) $job_id = $data->job_id; try{ $jobdata = \Order::find($job_id); }catch (\ActiveRecord\RecordNotFound $ex) { $jobdata = null; } if(is_null($jobdata)){ continue; } $prvsts = $jobdata->status; $pdate = $postedData->pickedup_at; if(strtoupper($postedData->status) === Menu::sts_pickedup && !$pdate){ $pdate = date('Y-m-d H:i:s'); } $ddate = $postedData->delivered_at; if(strtoupper($postedData->status) === Menu::sts_delivered && !$ddate){ $ddate = date('Y-m-d H:i:s'); } $attributes = array( "status" => strtoupper($data->status), "started_at" => $pdate, "closed_at" => $ddate ); $jobdata->update_attributes($attributes); if(strtolower($jobdata->status) !== strtolower($prvsts)){ $this->updatestatushistory(1, $jobdata->id, $jobdata->status, $jobdata->updated_at);//1 -order 2- ordertask etc., } if(strtoupper($data->status) === Menu::sts_rejected){ $rjcnt++; $existemprow = \Orderperson::find('all', array('conditions' => array('type = \'employee\' AND job_id=? AND person_id=?', $job_id, $personId))); if(count($existemprow) === 1){ $existemprow[0]->delete(); } $rjctdJobs[$rjcnt] = $data; } $this->checkAndSaveSlots($personId, $jobdata->addnlinfo1, $jobdata->status, $jobdata->addnlinfo1); if($data->consignmentnotes){ $consignattrs = array( "notes" => $data->consignmentnotes, "job_id" => $job_id, "person_id" => $personId); \Consignmentnote::create($consignattrs); } } catch (\Slim\Exception $ex) { } catch (\Exception $ex) { } } if($rjcnt > 0){ $message = ''; $message = "Dear Sir, ". "<br><br>"; $message .= "Job Rejections happened." . "<br><br><br>" . "The details follow:" . "<br><br>"; $message .= "Rejected by the Employee " . $personId . "<br><br>"; $message .= "Rejected Jobs Count : " . $rjcnt . "<br><br><br>"; $jids = ''; foreach ($rjctdJobs as &$rdata) { $job_id = $rdata->job_id; $jids .= $job_id . ', ' ; $jobdata = \Order::find($job_id); $custName = 'N/A'; $custMobile = 'N/A'; $rjct_time = 'N/A'; $jobpersndata = \Orderperson::find('all', array('conditions' => array('type = ? AND job_id=?', Menu::ppl_type_customer, $job_id))); if(count($jobpersndata) === 1){ foreach($jobdata->people as &$prsndata){ if($prsndata->id === $jobpersndata[0]->person_id){ $custName = $prsndata->name . ", Contact: " . $prsndata->firstname . ' ' . $prsndata->lastname; $custMobile = $prsndata->mobile; $rjct_time = $jobdata->updated_at->format('m/d/Y H:i:s a') . '[Zone : ' . $jobdata->updated_at->getTimeZone()->getName() . ']'; } } } $message .= "Job Sender Name :" . $custName . "<br><br>"; $message .= "Job Sender Mobile :" . $custMobile . "<br><br>"; $message .= "Job Rejection Time :" . $rjct_time . "<br><br>"; } $message .= "Thanks." . "<br><br>"; $message .= "Portal Admin.". "<br><br>"; $subject = $this->job_rejectmail_sub . ' Emp.ID : ' . $personId . ', JobID[s]: ' . $jids; $this->pushToMailQueue($subject, $message); } }