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()]);
 }
 public function update($id, $data)
 {
     $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());
     }
     if ($action == 3) {
         $arr = [];
         foreach ($data['types'] as $type) {
             $arr[] = $type['id'];
         }
         $data['types'] = $arr;
         $project->setData(['tax' => $data['tax'], 'discount' => $data['discount'], 'duration' => $data['duration'], 'serviceLevel' => $data['serviceLevel'], 'types' => $data['types']]);
         $project->save($this->getEntityManager());
     }
     return new JsonModel(['project' => $project->getData()]);
 }
示例#3
0
 public function create($data)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     $this->clearData($data);
     // Get Highest of Current task_number
     $project = $data['project'];
     $taskList = $this->getEntityManager()->getRepository('User\\Entity\\Task')->findBy(array('project' => $project));
     $taskOrderArr = array();
     foreach ($taskList as $task) {
         $order = explode('-', $task->getTaskNumber());
         $order = $order[1];
         $taskOrderArr[] = (int) $order;
     }
     $max = max($taskOrderArr);
     $max++;
     //var_dump($max); exit;
     $data['task_number'] = $project->getProjectNo() . '-' . $max;
     //		var_dump($data);exit;
     //var_dump($project);exit;
     $task = new Task();
     $task->setData($data);
     $task->save($this->getEntityManager());
     if ($data['type'] == 1) {
         $entityManager = $this->getEntityManager();
         $files = $entityManager->getRepository('User\\Entity\\File')->findBy(array('project' => $project, 'task' => $task));
         if (count($files)) {
             //var_dump($files);exit;
             foreach ($files as $file) {
                 //if()
                 //var_dump($item); exit;
                 if ($file->getFiletype() == 0) {
                     $items = $entityManager->getRepository('User\\Entity\\Itermnotm')->findBy(array('project' => $project, 'file' => $file));
                     $quantity = 0;
                     foreach ($items as $item) {
                         if ($item->getQuantity() > 0) {
                             $quantity = $item->getQuantity();
                         }
                     }
                     $iterm = new Itermnotm();
                     $iterm->setProject($project);
                     $iterm->setTask($task);
                     $iterm->setData(['name' => '', 'file' => $file, 'quantity' => $quantity, 'language' => $data['language']]);
                     $iterm->save($this->getEntityManager());
                 }
             }
         } else {
             $files = $entityManager->getRepository('User\\Entity\\File')->findBy(array('project' => $project));
             //var_dump($files);exit;
             foreach ($files as $file) {
                 if ($file->getFiletype() == 0 && !$file->getTask()) {
                     $items = $entityManager->getRepository('User\\Entity\\Itermnotm')->findBy(array('project' => $project, 'file' => $file));
                     $quantity = 0;
                     foreach ($items as $item) {
                         if ($item->getQuantity() > 0) {
                             $quantity = $item->getQuantity();
                         }
                     }
                     //var_dump($item); exit;
                     $iterm = new Itermnotm();
                     $iterm->setProject($project);
                     $iterm->setTask($task);
                     $iterm->setData(['name' => '', 'file' => $file, 'quantity' => $quantity, 'language' => $data['language']]);
                     $iterm->save($this->getEntityManager());
                 }
             }
         }
         //exit;
     }
     $activity = new Activity();
     $activity->setData(['activityDate' => new \DateTime('NOW'), 'project' => $data['project'], 'task' => $task, 'type' => "create_task", 'sender' => $this->getCurrentUser()]);
     $activity->save($this->getEntityManager());
     return new JsonModel(['task' => $task->getData()]);
 }
示例#4
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()]);
 }