$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; foreach ($db->tenants()->where("NOT id", $db->houses_tenants()->select('tenants_id'))->where("name LIKE ?", "%" . $id . "%") as $tenants) { $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();
$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()); $data = $db->houses_tenants()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); $app->post('/houses_deposits', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->houses_deposits()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); $app->post('/owners', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->owners()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data['id']); });
$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('/sellers_products', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->sellers_products()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data['id']); // echo json_encode($array); }); $app->post('/houses_tenants', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->houses_tenants()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); $app->post('/houses_deposits', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->houses_deposits()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); }); $app->post('/tenants_deposits', function () use($app, $db) { $array = (array) json_decode($app->request()->getBody()); $data = $db->tenants_deposits()->insert($array); $app->response()->header('Content-Type', 'application/json'); echo json_encode($data); });