diff --git a/app/Controllers/BkoReports.php b/app/Controllers/BkoReports.php index 4bbd272..062a670 100644 --- a/app/Controllers/BkoReports.php +++ b/app/Controllers/BkoReports.php @@ -33,6 +33,7 @@ class BkoReports extends BaseController 'records' => $row ]; return $this->respond($data, 200); + // return $this->respond([], 200); } public function pendingApplication() :ResponseInterface @@ -122,16 +123,62 @@ public function employersList() :ResponseInterface { } public function employerAdd():ResponseInterface{ + /* + employer_uid:b41cefe6-47e6-4b85-a8de-67d186e3fe16 + name:OluSign ASign + title:Mr. + email:ameye@chiefsoft.com + phone:6784574356 + */ + $sig_count = 0; $data = $this->request->getPost(); - $insert_data = $data; - $result = $this-> insert_db('employers', $insert_data); + //$insert_data = $data; + + $insert_data['employer_uid'] = $data['employer_uid']; + $insert_data['name'] = $data['name']; + $insert_data['title'] = $data['title']; + $insert_data['email'] = $data['email']; + $insert_data['phone'] = $data['phone']; + + if ( $insert_data['employer_uid'] !='' + && $insert_data['name'] !='' + && $insert_data['title'] !='' + && $insert_data['email'] !='' + && $insert_data['phone'] !='' ){ + $result = $this-> insert_db('employers', $insert_data); + $sig_count = $this->updateSignatoryCount( $insert_data['employer_uid'] ); + } + else{ + $result = [ + "error" => "Missing Required Data" + ]; + } + $result_data = [ 'call_return' => '100', + 'signatory_count' => $sig_count, 'result' =>$result ]; return $this->respond($result_data, 200); } + private function updateSignatoryCount($employer_uid): int + { + $sig_count=0; + try { + $sigCountQr = "SELECT count(s.id) AS sig_count from employers_signatory s LEFT JOIN employers e ON e.id=s.employer_id WHERE e.uid='$employer_uid' "; + $query = $this->db->query($sigCountQr); + $row = $query->getResult('array'); + $sig_count = $row[0]["sig_count"]; + + $sigCountUpdateQr = "UPDATE employers SET signatory_count = $sig_count WHERE uid = '$employer_uid' "; + $this->db->query($sigCountUpdateQr); + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; + } + return $sig_count; + } + public function signatoryList() :ResponseInterface { $query = $this->db->query("SELECT e.name AS employer_name, es.* FROM employers_signatory es LEFT JOIN employers e ON e.id = es.employer_id");