public function create($data)
 {
     $this->clearData($data);
     $activity = new Activity();
     $activity->setData($data);
     $activity->save($this->getEntityManager());
     $activity->sendNewActivityMail($this);
     return new JsonModel(['activity' => $activity->getData()]);
 }
示例#2
0
 public function update($id, $data)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     $lang_code = $this->params()->fromQuery('lang_code');
     $action = $this->params()->fromQuery('action');
     $project = $this->find('\\User\\Entity\\Project', $id);
     if ($action == 1) {
         $project->setData(['tax' => $data['tax'], 'discount' => $data['discount']]);
         $project->save($this->getEntityManager());
     }
     if ($action == 2) {
         //quote accept
         $project->setData(['status' => 2, 'total_tmp' => $data['total_tmp']]);
         $project->save($this->getEntityManager());
         $activity = new Activity();
         $activity->setData(['activityDate' => new \DateTime('NOW'), 'project' => $project, 'type' => "accept_quote", 'sender' => $this->getReference('\\User\\Entity\\User', $data['userid'])]);
         $activity->save($this->getEntityManager());
         //$activity->sendNewActivityMail($this,$lang_code);
         $activity->sendNewActivityMail($this, $lang_code);
     }
     if ($action == 3) {
         $arr = [];
         foreach ($data['types'] as $type) {
             $arr[] = $type['id'];
         }
         $data['types'] = $arr;
         if (!in_array(1, $arr)) {
             //echo "delete Translation (No TM) ";
             $taskList = $this->getEntityManager()->getRepository('User\\Entity\\Task')->findBy(array('project' => $project, 'type' => 1));
             foreach ($taskList as $task) {
                 $task->setData(['is_deleted' => true]);
                 $task->save($this->getEntityManager());
             }
         }
         if (!in_array(2, $arr)) {
             //echo "delete Translation (Use TM)";
             $taskList = $this->getEntityManager()->getRepository('User\\Entity\\Task')->findBy(array('project' => $project, 'type' => 2));
             foreach ($taskList as $task) {
                 $task->setData(['is_deleted' => true]);
                 $task->save($this->getEntityManager());
             }
         }
         if (isset($data['startDate'])) {
             $data['startDate'] = new \DateTime($data['startDate']['date']);
         }
         if (isset($data['dueDate'])) {
             $data['dueDate'] = new \DateTime($data['dueDate']['date']);
         }
         if ($project->getStatus() == 0) {
             $status = 1;
         } else {
             $status = $project->getStatus();
         }
         $project->setData(['tax' => $data['tax'], 'discount' => $data['discount'], 'duration' => $data['duration'], 'serviceLevel' => $data['serviceLevel'], 'types' => $data['types'], 'startDate' => $data['startDate'], 'dueDate' => $data['dueDate'], 'total_tmp' => $data['total_tmp'], 'status' => $status]);
         $project->save($this->getEntityManager());
     }
     if ($action == 4) {
         $entityManager = $this->getEntityManager();
         $employer = $this->getReference('\\User\\Entity\\Employer', $data['client']['id']);
         $user_client = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('employer' => $employer));
         //var_dump($data['startDate']);exit;
         if (isset($data['startDate'])) {
             $data['startDate'] = new \DateTime($data['startDate']['date']);
         }
         if (isset($data['dueDate'])) {
             $data['dueDate'] = new \DateTime($data['dueDate']['date']);
         }
         $project->setData(['client' => $this->getReference('\\User\\Entity\\User', $user_client->getId()), 'pm' => $this->getReference('\\User\\Entity\\Staff', $data['pm']['id']), 'sale' => $data['sale'], 'priority' => $data['priority']['id'], 'status' => $data['status']['id'], 'reference' => $data['reference'], 'field' => $this->getReference('\\User\\Entity\\Field', $data['field']['id']), 'po' => $data['po'], 'startDate' => $data['startDate'], 'dueDate' => $data['dueDate']]);
         $project->save($this->getEntityManager());
     }
     return new JsonModel(['project' => $project->getData()]);
 }