$days = days($tenants['entry_date']); // $dthdays = days($houses['house_rent_due_date']); // foreach ($houses->houses_tenants() as $p) { // $count++; // $houses_tenants[] = array('name'=>$p->tenants["name"], // 'phone'=>$p->tenants["phone"]); // } $data[] = array('id' => $tenants['id'], 'address' => $tenants['address'], 'name' => $tenants['name'], 'phone' => $tenants['phone'], 'company' => $tenants['company'], 'rent' => $tenants['rent'], 'totaldeposit' => $tenants['totaldeposit'], 'depositleft' => $tenants['depositleft'], 'entry_date' => $tenants['entry_date'], 'rent_date' => $days); } $tenants = array('aaData' => $data); $app->response()->header('content-type', 'application/json'); echo json_encode($tenants); }); $app->get('/owners/search/:id', function ($id = null) use($app, $db) { $data = array(); foreach ($db->owners()->where("owner_name LIKE ?", "%" . $id . "%") as $owners) { $data[] = array('id' => $owners['id'], 'address' => $owners['owner_address'], 'name' => $owners['owner_name'], 'phone' => $owners['owner_phone'], 'email' => $owners['owner_email']); } $tenants = array('aaData' => $data); $app->response()->header('content-type', 'application/json'); echo json_encode($tenants); }); //Post method to insert data into database $app->post('/houses', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->houses()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data['id']); }); $app->post('/houses_tenants', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody());
$tenants_deposits[] = array('id' => $p->deposits['id'], 'rent' => $p->deposits["rent"], 'date' => $p->deposits["date"], 'status' => $p->deposits["status"]); } foreach ($tenants->houses_tenants() as $p) { $houses_tenants[] = array('id' => $p->houses['id'], 'name' => $p->houses['name']); } $data = array('id' => $tenants['id'], 'address' => $tenants['address'], 'name' => $tenants['name'], 'phone' => $tenants['phone'], 'company' => $tenants['company'], 'rent' => $tenants['rent'], 'totaldeposit' => $tenants['totaldeposit'], 'depositleft' => $tenants['depositleft'], 'entry_date' => $tenants['entry_date'], 'is_verified' => $tenants['isVerified'], 'rentfirst' => $tenants['rentfirst'], 'deposits' => $tenants_deposits, 'currenthouse' => $houses_tenants, 'is_Paid' => $tenants['isPaid']); } } $tenants = array('aaData' => $data); $app->response()->header('content-type', 'application/json'); echo json_encode($tenants); }); $app->get('/owners(/:id)', function ($id = null) use($app, $db) { if ($id == null) { $data = array(); foreach ($db->owners() as $t) { $data[] = array('id' => $t['id'], 'address' => $t['owner_address'], 'name' => $t['owner_name'], 'phone' => $t['owner_phone'], 'email' => $t['owner_email']); } } else { $data = null; if ($t = $db->owners()->where('id', $id)->fetch()) { $data[] = array('id' => $t['id'], 'address' => $t['owner_address'], 'name' => $t['owner_name'], 'phone' => $t['owner_phone'], 'email' => $t['owner_email']); } } $owners = array('aaData' => $data); $app->response()->header('content-type', 'application/json'); echo json_encode($owners); }); $app->get('/tenants/search/:id', function ($id = null) use($app, $db) { $data = array(); $count = 0;