$app->get('/api/customer/{id:[0-9]+}', function ($id) use ($app) {
/**
* CREATING A BUILDER FOR GETTING ALL THE TABLE DATAS OF THE CUSTOMER
*/
// $resultset = $this->modelsManager->createBuilder()
// ->from('CbsCusTblMasUsrMain')
// ->leftJoin('CbsCusTblMasUsrCntct','CbsCusTblMasUsrMain.cus_id = CbsCusTblMasUsrCntct.cus_id','CbsCusTblMasUsrCntct')
// ->leftJoin('CbsCusTblMasUsrAddr','CbsCusTblMasUsrMain.cus_id = CbsCusTblMasUsrAddr.cus_id','CbsCusTblMasUsrAddr')
// // ->where('cus_id = CbsCusTblMasUsrMain.cus_id' )
// ->groupBy(array('CbsCusTblMasUsrMain.cus_id'))
// ->getQuery()
// ->execute();
$resultset = $this->modelsManager->createBuilder()
->Columns("CbsCusTblMasUsrCntct.cntct_mail", "CbsCusTblMasUsrCntct.cntct_role", "CbsCusTblMasUsrCntct.cntct_dept", "CbsCusTblMasUsrCntct.cntct_legacy_1", "CbsCusTblMasUsrMain.cus_id", "CbsCusTblMasUsrMain.cus_legacy_id", "CbsCusTblMasUsrMain.app_id", "CbsCusTblMasUsrMain.cus_code", "CbsCusTblMasUsrMain.cus_type")
->addFrom("CbsCusTblMasUsrMain", "cbscustblmasusrmain")
->leftJoin("CbsCusTblMasUsrCntct", "CbsCusTblMasUsrMain.cus_id = CbsCusTblMasUsrCntct.cus_id", "CbsCusTblMasUsrCntct")
// ->Where("(cus_addr_type)='".$customer->cus_ph_no_1."'")
->getQuery()
->execute();
$CbsCusTblMasUsrAddr[] = [];
$CbsCusTblMasUsrMain[] = [];
$result[] = [];
foreach ($resultset as $rows) {
$result[] = $rows;
}
/**
* CREATING AN OBJECT FOR THE RESPONSE
*/
$response = new Response();
/**
* CHECKING WHETHER THE DATA HAS RETRIEVED SUCCESSFULLY
*/
// if($customer==true && ($customer1 == true && $customer2 == true))
// {
if ($resultset != null) {
// /**
// * CREATING AN OBJECT FOR RETRIEVING THE DATABASE TABLE USING ID
// */
// $customer = CbsCusTblMasUsrCntct::findFirstBycus_id($id);
// $customer1 = CbsCusTblMasUsrMain::findFirstBycus_id($id);
// $customer2 = CbsCusTblMasUsrAddr::findFirstBycus_id($id);
/**
* SETTING UP A RESPONSE FOR THE JSON CONTENT
*/
$response->setJsonContent
(
/**
* IF IT RETRIEVED THE DATA THEN WE ARE STORING THE DATA IN THE DATA ARRAY AND DISPLAYING USING IT
*/
[
'status' => 'found',
'data' =>
[
$result =
[
[
'cus_cntct_id' => $customer->cus_cntct_id,
'cus_id' => $customer->cus_id,
'cntct_fname' => $customer->cntct_fname,
'cntct_mname' => $customer->cntct_mname,
'cntct_lname' => $customer->cntct_lname,
'cntct_no' => $customer->cntct_no,
'cntct_mail' => $customer->cntct_mail,
'cntct_role' => $customer->cntct_role,
'cntct_dept' => $customer->cntct_dept,
'cntct_legacy_1' => $customer->cntct_legacy_1,
'cntct_legacy_2' => $customer->cntct_legacy_2,
'cntct_twitter' => $customer->cntct_twitter,
'cntct_facebook' => $customer->cntct_facebook,
'cntct_linked_in' => $customer->cntct_linked_in,
],
],
$CbsCusTblMasUsrMain =
[
[
'cus_id' => $customer1->cus_id,
'cus_legacy_id' => $customer1->cus_legacy_id,
'app_id' => $customer1->app_id,
'cus_code' => $customer1->cus_code,
'cus_type' => $customer1->cus_type,
'cus_cat' => $customer1->cus_cat,
'cus_comp_name' => $customer1->cus_comp_name,
'cus_display_name' => $customer1->cus_display_name,
'cus_fname' => $customer1->cus_fname,
'cus_mname' => $customer1->cus_mname,
'cus_lname' => $customer1->cus_lname,
'cus_ph_no_1' => $customer1->cus_ph_no_1,
'cus_ph_no_2' => $customer1->cus_ph_no_2,
'cus_mail' => $customer1->cus_mail,
'cus_tags' => $customer1->cus_tags,
'cus_notes' => $customer1->cus_notes,
'cus_gst_no' => $customer1->cus_gst_no,
'cus_gst_type' => $customer1->cus_gst_type,
'cus_pan_no' => $customer1->cus_pan_no,
'cus_tax_exempt' => $customer1->cus_tax_exempt,
'cus_accepts_mrktng' => $customer1->cus_accepts_mrktng,
'cus_due_amount' => $customer1->cus_due_amount,
'cus_status' => $customer1->cus_status,
'is_used' => $customer1->is_used,
'created_by' => $customer1->created_by,
'updated_by' => $customer1->updated_by,
'created_at' => $customer1->created_at,
'updated_at' => $customer1->updated_at,
],
],
$CbsCusTblMasUsrAddr =
[
[
'cus_addr_id' => $customer2->cus_addr_id,
'cus_id' => $customer2->cus_id,
'cus_addr_type' => $customer2->cus_addr_type,
'cus_addr_cat' => $customer2->cus_addr_cat,
'cus_addr_line_1' => $customer2->cus_addr_line_1,
'cus_addr_line_2' => $customer2->cus_addr_line_2,
'cus_add_line_3' => $customer2->cus_add_line_3,
'cus_state' => $customer2->cus_state,
'cus_city' => $customer2->cus_city,
'cus_pincode' => $customer2->cus_pincode,
'cus_country' => $customer2->cus_country,
],
],
],
]
);
} else {
$response->setJsonContent
(
[
'status' => 'Not Found',
]
);
}
/**
* NEED TO RETURN THE RESPONSE INORDER TO SEND THE OUTPUT TO THE USER
*/
return $response;
});