Esempio n. 1
0
 /**
  * This action is to send email to HR group when due date of requisition is completed.
  */
 public function requisitionAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $email_model = new Default_Model_EmailLogs();
     $cron_model = new Default_Model_Cronstatus();
     $cron_status = $cron_model->getActiveCron('Requisition expiry');
     if ($cron_status == 'yes') {
         try {
             //updating cron status table to in-progress
             $cron_data = array('cron_status' => 1, 'cron_type' => 'Requisition expiry', 'started_at' => gmdate("Y-m-d H:i:s"));
             $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, '');
             if ($cron_id != '') {
                 $calc_date = new DateTime(date('Y-m-d'));
                 $calc_date->add(new DateInterval('P15D'));
                 $print_date = $calc_date->format(DATEFORMAT_PHP);
                 $calc_date = $calc_date->format('Y-m-d');
                 $mail_data = $email_model->getRequisitionData($calc_date);
                 if (count($mail_data) > 0) {
                     foreach ($mail_data as $did => $mdata) {
                         if (defined("REQ_HR_" . $did)) {
                             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                             $view = $this->getHelper('ViewRenderer')->view;
                             $this->view->emp_name = "HR";
                             $this->view->print_date = $print_date;
                             $this->view->req = $mdata['req'];
                             $this->view->base_url = $base_url;
                             $text = $view->render('mailtemplates/requisitioncron.phtml');
                             $options['subject'] = APPLICATION_NAME . ': Renew requisition expiry';
                             $options['header'] = 'Requisition Expiry';
                             $options['toEmail'] = constant("REQ_HR_" . $did);
                             $options['toName'] = "HR";
                             $options['message'] = $text;
                             $options['cron'] = 'yes';
                             sapp_Global::_sendEmail($options);
                         }
                     }
                 }
                 $cron_data = array('cron_status' => 0, 'completed_at' => gmdate("Y-m-d H:i:s"));
                 $cron_id = $cron_model->SaveorUpdateCronStatusData($cron_data, "id = " . $cron_id);
             }
             //end of cron status id if
         } catch (Exception $e) {
         }
     }
     //end of cron status if
 }