Example #1
0
 public static function jsonDeserialize($content)
 {
     $data = json_decode($content);
     $keys = array_keys(json_decode($content, true));
     $response = new Response();
     foreach ($keys as $key) {
         switch ($key) {
             case 'status':
                 $response->setStatus($data->status);
                 break;
             case 'data':
                 $response->setData($data->data);
                 break;
             case 'error':
                 $response->setErrorMessage($data->error);
                 break;
             case 'code':
                 $response->setErrorCode($data->code);
                 break;
             case 'metadata':
                 foreach ((array) $data->metadata as $key => $value) {
                     $response->setMetadata($key, $value);
                 }
                 break;
         }
     }
     return $response;
 }
Example #2
0
 function saveuser()
 {
     $response = new Response();
     try {
         $id = $this->input->post("user-id");
         $email = $this->input->post("email");
         $firstName = $this->input->post("first-name");
         $lastName = $this->input->post("last-name");
         $role = $this->input->post("role");
         $subDivision = $this->input->post("sub-division");
         $user = new User();
         if ($id != null && $id != "") {
             $user = $this->findById("User", $id);
         }
         $user->setEmail($email);
         $user->setUsername($email);
         $user->setPassword("");
         $user->setFirstName($firstName);
         $user->setLastName($lastName);
         $subDivision = $this->findById("Subdivision", $subDivision);
         $user->setSubdivision($subDivision);
         $role = $this->getRoleByName($role);
         $user->setRole($role[0]);
         $token = $this->getRandomCode();
         $user->setToken($token);
         $this->save($user);
         $emailMessage = "Hi " . $user->getName() . ", <br/> Your account has been activate on " . base_url() . ". Please <a href='" . site_url() . "/validate/" . $token . "'>click here </a> to create you password.";
         $this->sendMail($user->getEmail(), "Active you account.", $emailMessage);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #3
0
 function sendForBilling()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("project-id");
         $amount = $this->input->post("project-bill-amount");
         $billDoc = $this->input->post("bill-doc");
         $project = $this->findById("Project", $projectId);
         if ($project == null) {
             throw new RuntimeException("Invalid Project..!");
         }
         $project->setStatus(Project::PROJECT_BILL);
         $project->getWorkOrder()->setStatus(Workorder::STATUS_COMPLETED);
         $project->getWorkOrder()->setApprovedBy($this->getLoggedInUser());
         $bill = new Bill();
         $bill->setAmount($amount);
         $bill->setProject($project);
         $bill->setCreated(new DateTime());
         $bill->setStatus(Bill::STATUS_PENDING);
         if ($billDoc != null && $billDoc != "") {
             foreach ($billDoc as $file) {
                 $doc = new Document();
                 $doc->setName($file);
                 $doc->setCreated(new DateTime());
                 $bill->getBillDoc()->add($doc);
             }
         }
         $this->save($bill);
         $response->setData(Project::PROJECT_BILL);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #4
0
 function approve()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("project-id");
         $amount = floatval($this->input->post("project-bill-amount"));
         $project = $this->findById("Project", $projectId);
         if ($projectId == null) {
             throw new RuntimeException("Invalid Request");
         }
         $availableAmount = $this->getAvailableFundAmountByScheme($project->getScheme()->getId());
         if ($amount > floatval($availableAmount)) {
             throw new RuntimeException("Insufficient Funds !");
         }
         $utilisedAmt = 0;
         foreach ($this->getAvailableFunds($project->getScheme()) as $fund) {
             /*if($fund->getAmount() == $fund->getUsedAmount()){
                   continue;
               }*/
             $reqAmt = $amount - $utilisedAmt;
             $fundDetails = new FundDetails();
             $fundDetails->setCreated(new DateTime());
             $availableAmount = $fund->getAmount() - $fund->getUsedAmount();
             if ($availableAmount >= $reqAmt) {
                 $fundDetails->setAmount($reqAmt);
                 $fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
                 $utilisedAmt = $amount;
             } else {
                 if ($reqAmt <= $availableAmount) {
                     $fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
                     $fundDetails->setAmount($reqAmt);
                     $utilisedAmt = $utilisedAmt + $reqAmt;
                 } else {
                     $fund->setUsedAmount($fund->getUsedAmount() + $availableAmount);
                     $fundDetails->setAmount($availableAmount);
                     $utilisedAmt = $utilisedAmt + $availableAmount;
                 }
             }
             $fundDetails->setFund($fund);
             $fundDetails->setProject($project);
             $project->getFundDetails()->add($fundDetails);
             if ($utilisedAmt == $amount) {
                 break;
             }
         }
         $bill = $project->getBill();
         $bill->setApprovedBy($this->getLoggedInUser());
         $bill->setApprovedAmount($amount);
         $bill->setStatus(Bill::STATUS_APPROVED);
         $project->setStatus(Project::PROJECT_COMPLETED);
         $this->save($project);
         $response->setData(Bill::STATUS_APPROVED);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #5
0
 function load($id)
 {
     $response = new Response();
     try {
         $workOrder = $this->findById("Workorder", $id);
         $comments = array();
         foreach ($workOrder->getComments() as $cmt) {
             $dto = new Commentdto();
             $dto->setId($cmt->getId());
             $dto->setComment($cmt->getComment());
             $dto->setCreated(date_format($cmt->getCreated(), "d-M-Y"));
             $dto->setCommentedBy($cmt->getCommentedBy()->getFirstName() . " " . $cmt->getCommentedBy()->getLastName());
             array_push($comments, $dto);
         }
         $response->setData($comments);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #6
0
 function getFundDetails($id = null)
 {
     $response = new Response();
     try {
         if ($id == null) {
             throw new RuntimeException("Invalid Request..!");
         }
         $funds = parent::getFundDetails($id);
         $fundArray = array();
         foreach ($funds as $fund) {
             $dto = new FundDetailsDto();
             $dto->setAmount($fund->getAmount());
             $dto->setProjectName($fund->getProject()->getName());
             $dto->setFundAmount($fund->getFund()->getAmount());
             array_push($fundArray, $dto);
         }
         $response->setData($fundArray);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #7
0
 public function validate()
 {
     $response = new Response();
     try {
         $username = trim($this->input->post('username'));
         $password = trim($this->input->post('password'));
         if ($username != null && $username != "" && $password != null && $password != "") {
             $query = $this->doctrine->em->createQuery('SELECT u FROM User u WHERE u.email = :username and u.password = :password');
             $query->setParameter('username', $username);
             $query->setParameter('password', $password);
             $users = $query->getResult();
             if ($users != null) {
                 $loggedInUser = $users[0];
                 $this->session->set_userdata('logged_in', $loggedInUser->getId());
                 $subDivsionId = -1;
                 if ($loggedInUser->getSubdivision() != null) {
                     $subDivsionId = $loggedInUser->getSubdivision()->getId();
                 }
                 $this->session->set_userdata('sub_division_id', $subDivsionId);
                 $functions = array();
                 foreach ($loggedInUser->getRole()->getRoleFunction() as $fn) {
                     array_push($functions, $fn->getName());
                 }
                 $this->session->set_userdata('functions', $functions);
             } else {
                 throw new RuntimeException("Invalid Username/Password");
             }
         } else {
             throw new RuntimeException("Invalid Username/Password");
         }
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #8
0
 function addContractor()
 {
     $response = new Response();
     try {
         $userId = $this->input->post("user-id");
         $firstName = $this->input->post("first-name");
         $lastName = $this->input->post("last-name");
         $email = $this->input->post("email");
         $phone = $this->input->post("phone");
         $contractor = new Contractor();
         if ($userId != null && $userId != "") {
             $contractor = $this->findById("Contractor", $userId);
         }
         $contractor->setFirstName($firstName);
         $contractor->setLastName($lastName);
         $contractor->setEmail($email);
         $contractor->setPhone($phone);
         $this->save($contractor);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
Example #9
0
 function tenderApproval()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("tender-project-id");
         $contractorId = $this->input->post("contractor-id");
         $percentage = $this->input->post("tender-percent");
         $project = $this->findById("Project", $projectId);
         if ($project == null) {
             throw new RuntimeException("Invalid Project..!");
         }
         $project->setStatus(Project::PROJECT_WORK_ORDER);
         $tenderApproval = new TenderApproval();
         $tenderApproval->setProject($project);
         $tenderApproval->setApprovedBy($this->getLoggedInUser());
         $tenderApproval->setCreated(new DateTime());
         $workOrder = new Workorder();
         $workOrder->setProject($project);
         $workOrder->setCreated(new DateTime());
         $this->save($workOrder);
         $contractor = $this->findById("Contractor", $contractorId);
         if ($contractor == null) {
             throw new RuntimeException("Ïnvalid Contractor !");
         }
         $tenderApproval->setContractor($contractor);
         $tenderApproval->setPercentage($percentage);
         $this->save($tenderApproval);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }