In Task entity, I have a field name called, "tot_hours". Once field name, "status", has changed to "Completed", calculated the difference of date_end and date_start. In the applications\espo\modules\crm\services\task.php, code below:
public function handleHours(Entity $entity, array $options) { $entityManager = $this->getEntityManager(); $task_status = $entityManager->getRepository('Task'); $pdo = $this->getEntityManager()->getPDO(); if($task_status->get('status') == 'Completed' && empty($task_status->get('tot_hours'))){ $sql = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start))/3600 WHERE status = 'Completed'"; $stmt = $pdo->prepare($sql); $stmt->execute(); $entityManager->saveEntity($entityManager); } else{ if($task_status->get('status' != 'Completed' && !empty($task_status->get('tot_hours')))) { $othesql = "UPDATE task SET tot_hours = NULL WHERE status <> 'Completed'"; $othe_stmt = $pdo->prepare($othesql); $othe_stmt->execute(); $entityManager->saveEntity($entityManager); } } } The field name, "tot_hours", doesn't change in the db when status has been changed to 'Completed'. Not sure why. Assistance please.
public function handleHours(Entity $entity, array $options) { $entityManager = $this->getEntityManager(); $task_status = $entityManager->getRepository('Task'); $pdo = $this->getEntityManager()->getPDO(); if($task_status->get('status') == 'Completed' && empty($task_status->get('tot_hours'))){ $sql = "UPDATE task SET tot_hours = TIME_TO_SEC(TIMEDIFF(date_end,date_start))/3600 WHERE status = 'Completed'"; $stmt = $pdo->prepare($sql); $stmt->execute(); $entityManager->saveEntity($entityManager); } else{ if($task_status->get('status' != 'Completed' && !empty($task_status->get('tot_hours')))) { $othesql = "UPDATE task SET tot_hours = NULL WHERE status <> 'Completed'"; $othe_stmt = $pdo->prepare($othesql); $othe_stmt->execute(); $entityManager->saveEntity($entityManager); } } } The field name, "tot_hours", doesn't change in the db when status has been changed to 'Completed'. Not sure why. Assistance please.
Comment