Ejemplo n.º 1
0
 public function changeinfoAction()
 {
     $this->checkLevel2();
     $value = $this->getRequest()->getPost('value');
     $name = $this->getRequest()->getPost('name');
     $id = $this->getRequest()->getPost('pk');
     $valid = new \Zend\Validator\NotEmpty();
     $result = new Xeditable();
     if ($valid->isValid($value)) {
         $log = new Log();
         $log->action_id = Config::EDIT_ACTION;
         $log->user_id = $this->auth->getIdentity()->id;
         $log->task_id = $id;
         $log->key = $name;
         $log->new_id = $value;
         /* Get old value of task */
         $detail_task = $this->databaseService->getInfoTask($id)->current();
         $log->old_id = $detail_task[$name];
         $log->custumer = $detail_task['custumer'];
         /* Backup value */
         $new_value = $value;
         $old_value = $log->old_id;
         /* Get pay history */
         $tmp_pay_custumer = $this->databaseService->getTotalPay($id, Config::PAY_CUSTUMER);
         $pay_custumer = number_format($tmp_pay_custumer);
         $detail_task['pay_custumer'] = $pay_custumer;
         /* Convert new pay history */
         if ($name == Config::cost_sell_id) {
             $custumer_debt = number_format($new_value - $tmp_pay_custumer);
             $detail_task['custumer_debt'] = $custumer_debt;
         } else {
             $custumer_debt = number_format($detail_task->cost_sell - $tmp_pay_custumer);
             $detail_task['custumer_debt'] = $custumer_debt;
         }
         $tmp_pay_provider = $this->databaseService->getTotalPay($id, Config::PAY_PROVIDER);
         $pay_provider = number_format($tmp_pay_provider);
         $detail_task['pay_provider'] = $pay_provider;
         /* Convert new pay history */
         if ($name == Config::cost_buy_id) {
             $provider_debt = number_format($new_value - $tmp_pay_provider);
             $detail_task['provider_debt'] = $provider_debt;
         } else {
             $provider_debt = number_format($detail_task->cost_buy - $tmp_pay_provider);
             $detail_task['provider_debt'] = $provider_debt;
         }
         /* Convert number to readable value */
         if ($name == Config::cost_sell_id || $name == Config::cost_buy_id) {
             $old_value = number_format($old_value);
             $new_value = number_format($new_value);
         }
         /* Convert process_id */
         if ($name == Config::process_id) {
             $old_value = $this->databaseService->getProcessBaseID($old_value)->current()['name'];
             $new_value = $this->databaseService->getProcessBaseID($new_value)->current()['name'];
         }
         if ($name == "date_open" || $name == "date_end" || $name == "date_open_pr" || $name == "date_end_pr") {
             $value = Date::changeVNtoDateSQL($value);
             $old_value = Date::changeDateSQLtoVN($log->old_id);
         }
         $validator = new \Zend\Validator\Digits();
         if (($name == "cost_sell" || $name == "cost_buy") && !$validator->isValid($value)) {
             $result->setStatus(Xeditable::STATUS_ERROR);
             $result->setMsg(Xeditable::MSG_DATA_NOT_NUMBER);
         } else {
             $type = Config::PAY_INFO_COMMON;
             if ($name == "date_open" || $name == "date_end" || $name == "cost_sell" || $name == "agency_note" || $name == "agency_id") {
                 $type = Config::PAY_CUSTUMER;
             }
             if ($name == "date_open_pr" || $name == "date_end_pr" || $name == "cost_buy" || $name == "provider_note" || $name == "provider_id") {
                 $type = Config::PAY_PROVIDER;
             }
             /* Add log */
             $this->databaseService->modifyLog($log, $type);
             $this->databaseService->changeInfoOfTask($id, $name, $value, $this->auth->getIdentity()->id);
             /* Add send mail */
             $mail = new MailHelper();
             $receiver['reporter'] = $this->databaseService->getUserById($detail_task['reporter_id'])->current();
             $receiver['assign'] = $this->databaseService->getUserById($detail_task['assign_id'])->current();
             $receiver['agency'] = $this->databaseService->getUserById($detail_task['agency_id'])->current();
             $receiver['provider'] = $this->databaseService->getUserById($detail_task['provider_id'])->current();
             /* Convert new user_id to user_name */
             if ($name == Config::reporter_id || $name == Config::assign_id || $name == Config::agency_id || $name == Config::provider_id) {
                 $new_value = $this->databaseService->getUserById($value)->current()->username;
                 $old_value = $this->databaseService->getUserById($log->old_id)->current()->username;
             }
             $ret = NULL;
             if ($name == Config::agency_id || $name == Config::cost_sell_id || $name == Config::date_open_id || $name == Config::date_end_id || $name == Config::agency_note_id || $name == Config::custumer_id || $name == Config::certificate_id || $name == Config::process_id || $name == Config::reporter_id || $name == Config::assign_id) {
                 /* For agency: agency_id, cost_sell, date_open, date_end, agency_note */
                 $mail->notify_modify_to_agency($detail_task, $receiver, $name, $old_value, $new_value);
             }
             if ($name == Config::provider_id || $name == Config::cost_buy_id || $name == Config::date_open_pr_id || $name == Config::date_end_pr_id || $name == Config::provider_note_id || $name == Config::custumer_id || $name == Config::certificate_id || $name == Config::process_id || $name == Config::reporter_id || $name == Config::assign_id) {
                 /* For provider: provider_id, cost_buy, date_open_pr, date_end_pr, provider_note */
                 $mail->notify_modify_to_provider($detail_task, $receiver, $name, $old_value, $new_value);
             }
             $mail->notify_modify_to_admin($detail_task, $receiver, $name, $old_value, $new_value);
         }
     } else {
         $result->setStatus(Xeditable::STATUS_ERROR);
         $result->setMsg(Xeditable::MSG_DATA_EMPTY);
     }
     echo \Zend\Json\Json::encode($result, false);
     exit;
 }
Ejemplo n.º 2
0
 public function changeMyInfoAction()
 {
     $this->checkAuth();
     $value = $this->getRequest()->getPost('value');
     $name = $this->getRequest()->getPost('name');
     $id = $this->auth->getIdentity()->id;
     $selected_user = new User(NULL, NULL, NULL, NULL);
     $selected_user->email = NULL;
     $selected_user->phone = NULL;
     $selected_user->note = NULL;
     $selected_user->name = NULL;
     if ($name == "pro-email") {
         $result = new Xeditable();
         $validator = new \Zend\Validator\EmailAddress();
         if ($validator->isValid($value)) {
             $selected_user->email = $value;
             $this->databaseService->changeUserInfo($id, $selected_user);
             $this->user->email = $value;
         } else {
             $result->setStatus(Xeditable::STATUS_ERROR);
             $result->setMsg(Xeditable::MSG_DATA_ERROR);
         }
         echo \Zend\Json\Json::encode($result, false);
         exit;
     }
     if ($name == "pro-phone") {
         $result = new Xeditable();
         $validator = new \Zend\Validator\NotEmpty();
         if ($validator->isValid($value)) {
             $selected_user->phone = $value;
             $this->databaseService->changeUserInfo($id, $selected_user);
             $this->user->phone = $value;
         } else {
             $result->setStatus(Xeditable::STATUS_ERROR);
             $result->setMsg(Xeditable::MSG_DATA_ERROR);
         }
         echo \Zend\Json\Json::encode($result, false);
         exit;
     }
     if ($name == "pro-name") {
         $result = new Xeditable();
         $validator = new \Zend\Validator\NotEmpty();
         if ($validator->isValid($value)) {
             $selected_user->name = $value;
             $this->databaseService->changeUserInfo($id, $selected_user);
             $this->user->phone = $value;
         } else {
             $result->setStatus(Xeditable::STATUS_ERROR);
             $result->setMsg(Xeditable::MSG_DATA_ERROR);
         }
         echo \Zend\Json\Json::encode($result, false);
         exit;
     }
     if ($name == "pro-note") {
         $result = new Xeditable();
         $validator = new \Zend\Validator\NotEmpty();
         if ($validator->isValid($value)) {
             $selected_user->note = $value;
             $this->databaseService->changeUserInfo($id, $selected_user);
             $this->user->note = $value;
         } else {
             $result->setStatus(Xeditable::STATUS_ERROR);
             $result->setMsg(Xeditable::MSG_DATA_ERROR);
         }
         echo \Zend\Json\Json::encode($result, false);
         exit;
     }
     $result = new Xeditable();
     $result->setStatus(Xeditable::STATUS_ERROR);
     $result->setMsg(Xeditable::MSG_DATA_EMPTY);
     echo \Zend\Json\Json::encode($result, false);
     exit;
 }