private static function getRentDemandStatus($rentDemandID) { $processes = RentProcesses::getRentDemandProcesses($rentDemandID); $failed = 0; $closed = 0; $alive = 0; $count = 0; foreach ($processes as $process) { if (isset($process['status'])) { $count++; if ($process['status'] == 'failed') { $failed++; } else { if ($process['status'] == 'closed') { $closed++; } else { if ($process['status'] == 'alive') { $alive++; } } } } } if ($failed == 0 && $closed == 0) { return 'alive'; } else { if ($closed > 0) { return 'closed'; } else { if ($failed == $count) { return 'failed'; } } } }
} }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetData = Assets::getAsset($id); $assetInvestors = Investors::getAssetInvestors($id); $result = array("assetData" => $assetData, "assetInvestors" => $assetInvestors); if ($assetData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/get-for-edit/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetData = Assets::getAsset($id); $assetContacts = Contacts::getAssetContacts($id); $assetInvestors = Investors::getAssetInvestors($id); $assetAreas = RentAreas::getAssetRentAreas($id); $assetProcesses = RentProcesses::getAssetRentProcesses($id); $result = array("assetData" => $assetData, "assetContacts" => $assetContacts, "assetInvestors" => $assetInvestors, "assetAreas" => $assetAreas, "assetProcesses" => $assetProcesses); if ($assetData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Assets::getAllAssets(); $response->json(Result::success('', $result)); });
} }); $this->respond(['GET', 'POST'], '/match-mod/get/assets', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Assets::getRentDemandMatchingAssets($id); $response->json(Result::success('', $result)); }); $this->respond(['GET', 'POST'], '/match-mod/match', function ($request, $response, $service, $app) { $rentDemandID = $request->param('rentDemandID'); $assetID = $request->param('assetID'); $id = RentProcesses::matchRentDemandAndAsset($rentDemandID, $assetID); if ($id > 0) { $response->json(Result::success('Matched.', ['rentProcessID' => $id])); } else { $response->json(Result::error('Error trying to match')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $rentDemandResult = RentDemands::deleteRentDemand($id); RentProcesses::deleteRentDemandProcesses($id); if ($rentDemandResult > 0) { $response->json(Result::success('Demand Deleted.')); } else { $response->json(Result::error('Demand not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = RentDemands::getAllRentDemands(); $response->json(Result::success('', $result)); });
if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentProcess not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body(), true); $result = RentProcesses::updateRentProcess($id, $data); if ($result > 0) { $response->json(Result::success('RentProcess Updated.')); } elseif ($result === 0) { $response->json(Result::success('RentProcess not Updated.')); } else { $response->json(Result::error('RentProcess not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentProcesses::deleteRentProcess($id); if ($result > 0) { $response->json(Result::success('RentProcess Deleted.')); } else { $response->json(Result::error('RentProcess not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = RentProcesses::getAllRentProcesses(); $response->json(Result::success('', $result)); });
public static function getRentDemandMatchingAssets($rentDemandID) { global $db; $assets = $db->select('assets', '*'); $rentDemand = RentDemands::getRentDemand($rentDemandID); $matchingAssets = array(); foreach ($assets as $asset) { if (!RentProcesses::isRentDemandExists($asset['id'], $rentDemandID)) { $ans = Assets::isAssetMatching($rentDemand, $asset); if ($ans) { $asset['matchRatio'] = $ans['matchRatio'] . '%'; $asset['matchAvailableDate'] = $ans['availableDate']; $asset['matchPrice'] = $ans['price']; $asset['matchFinishing'] = $ans['finishing']; array_push($matchingAssets, $asset); } } } return $matchingAssets; }
$id = $request->param('id'); $assetData = $request->param('assetData'); $contactsData = $request->param('assetContacts'); $investorsData = $request->param('assetInvestors'); $result = Assets::updateAssetInvest($id, $assetData, $contactsData, $investorsData); if ($result > 0) { $response->json(Result::success('Asset Updated.')); } elseif ($result === 0) { $response->json(Result::success('Asset not Updated.')); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetResult = Assets::deleteAsset($id); Logs::deleteAssetInvestLogs($id); Contacts::deleteAssetContacts($id); Investors::deleteAssetInvestors($id); RentAreas::deleteAssetRentAreas($id); RentProcesses::deleteAssetRentProcesses($id); if ($assetResult > 0) { $response->json(Result::success('Asset Deleted.')); } else { $response->json(Result::error('Asset not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Assets::getAllAssets(); $response->json(Result::success('', $result)); });
public static function matchRentDemandAndAsset($rentDemandID, $assetID) { $data = ['rentDemand' => $rentDemandID, 'asset' => $assetID]; $id = RentProcesses::createRentProcess($data); return $id; }