public function setDefaults() { $A = $this->sheetData[1]['A']; // templateID $B = $this->sheetData[1]['B']; // TPIN $C = strcmp($this->sheetData[1]['C'], '') == 0 ? null : $this->sheetData[1]['C']; // government entity $D = strcmp($this->sheetData[1]['D'], '') == 0 ? null : $this->sheetData[1]['D']; // reportID $E = $this->sheetData[1]['E']; // period $F = strcmp($this->sheetData[1]['F'], '') == 0 ? null : $this->sheetData[1]['F']; // status // validate if the templates being edited already approved in the case of non management users if (strcmp($_SESSION['user']->getRole(), 'mu') != 0 && (strcasecmp($F, 'Approved') == 0 || strcasecmp($F, 'Reconciled') == 0) || strcasecmp($F, 'Reconciled') == 0) { exit(json_encode(['success' => false, 'error' => 'You are not permitted to edit an already approved submission.'])); } // validate TPIN $mines = ZP::getExtractiveCompanies(); $isTPIN = false; foreach ($mines as $v) { if ($v->TPIN == $B) { $isTPIN = true; break; } } // validate government entity entityID $isEntity = is_null($C) ? true : false; if (!$isEntity) { $entities = ZP::getEntities(); if (!$entities['success']) { exit(json_encode($entities)); } $entities = $entities['entities']; //exit(json_encode($entities)); foreach ($entities as $v) { if ($v->entityID = $C) { $isEntity = true; break; } } } // validate reportID $isReport = is_null($D) ? true : false; if (!$isReport) { $reports = ZP::getReports(); foreach ($reports as $v) { if ($v->reportID == $D) { $isReport = true; break; } } } //validate status $isStatus = is_null($F) ? true : false; if (!$isStatus) { $status = ['Approved', 'Rejected', 'Not Approved']; if (in_array($F, $status)) { $isStatus = true; } } // valid templates $isTemplate = intval($A) > 0 && intval($A) <= 10; // validate period $isPeriod = intval($E) > 2000 && $E <= date('Y'); if (!$isTPIN || !$isReport || !$isStatus || !$isPeriod || !$isTemplate) { exit(json_encode(['success' => false, 'error' => 'Invalid templates uploaded. Please download the templates from the portal.'])); } $this->defaults = (object) ['templateID' => $A, 'mine' => $B, 'entity' => $C, 'reportID' => $D, 'period' => $E]; //exit(json_encode(['success'=>false, 'error'=>'done here'])); }
public function getEntities() { try { if (func_num_args() > 0) { $entity = func_get_arg(0); if ($entity->entityID > 0) { $query = $this->getConnection()->prepare("SELECT entityName AS name, entityID, dateOfEstablishment AS `Date of Establishment`, " . "contactAddress AS `Contact Address` " . "FROM governmententity " . "WHERE entityID = :ID"); $query->bindValue(":ID", $entity->entityID, PDO::PARAM_INT); } else { if ($entity->TPIN > 0) { $query = $this->getConnection()->prepare("SELECT companyName AS name, TPIN, dateOfEstablishment AS `Date of Establishment`, " . "companyCapital AS `Company Capital`, contactAddress AS `Contact Address`, primaryBusiness AS `Primary Business`, " . "secondaryBusiness AS `Secondary Business` " . "FROM extractivecompany " . "WHERE TPIN = :TPIN"); $query->bindValue(":TPIN", $entity->TPIN, PDO::PARAM_INT); } else { return ['success' => false, 'exception' => 'Error occurred. Could not fetch the entity TPIN: ' . $entity->TPIN . ' EntityID: ' . $entity->entityID]; } } $query->setFetchMode(PDO::FETCH_OBJ); if ($query->execute()) { $result = $query->fetch(); if ($entity->entityID > 0) { $result->templates = $this->getTemplates($entity->entityID, "gov_entity"); return ['success' => true, 'entity' => $result, 'user' => $this->getUser($entity)]; } $result->templates = $this->getTemplates($entity->TPIN, "extractive"); return ['success' => true, 'entity' => $result, "beneficiary" => $this->getBeneficiary($entity->TPIN), "licenses" => $this->getLicense($entity->TPIN), "employees" => $this->getEmployeeStatement($entity->TPIN), "user" => $this->getUser($entity)]; } return ['success' => false, 'exception' => 'Error occurred. Could not fetch the entities']; } else { $entities = ZP::getEntities(); if (!$entities['success']) { return ['success' => false, 'exception' => 'Could not fetch government entities']; } $govtentity = $entities['entities']; $query = $this->getConnection()->prepare("SELECT ec.TPIN, ec.companyName as name FROM extractivecompany ec"); if (!$query->execute()) { return ['success' => false, 'exception' => 'Could not fetch extractive companies']; } $mines = $query->fetchAll(PDO::FETCH_OBJ); //PDO::FETCH_ASSOC | PDO::FETCH_GROUP); return ['success' => true, 'entities' => ['govtentity' => $govtentity, 'mines' => $mines], 'templates' => $this->getTemplates()]; } } catch (\PDOException $e) { return ['success' => false, 'exception' => $e]; } }