From c2a9675da9d0f2d9a3ab4e8f3e1f8ffe99c9b2d6 Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Fri, 16 Oct 2020 08:40:10 +0100 Subject: [PATCH] + Adding the hypervisor and supervisor history routes without pagination --- app/Http/Controllers/WalletController.php | 99 +++++++++++++++++++++++ routes/web.php | 3 + 2 files changed, 102 insertions(+) diff --git a/app/Http/Controllers/WalletController.php b/app/Http/Controllers/WalletController.php index 10e6dba..f62004e 100755 --- a/app/Http/Controllers/WalletController.php +++ b/app/Http/Controllers/WalletController.php @@ -214,4 +214,103 @@ class WalletController extends Controller return $this->successResponse($this->arrayPaginator($result, $request)); } + // Routes sans pagination + public function allHyperHistory($id_network) + { + + $demandes = DB::select("SELECT 'N' as type_historique , i.* FROM infos_users_demandes_credits i WHERE id_network = :id ;", ['id' => $id_network]); + $savings = DB::select("SELECT 'E' as type_historique , i.* FROM infos_users_epargnes i WHERE id_network = :id;", ['id' => $id_network]); + + $transactions = DB::select("SELECT 'T' as type_historique, wit.id_transaction, tit.nom as operation , wit.montant ,wit.nom_emetteur, wit.prenom_emetteur, wit.id_wallet_user,wit.frais,wit.taxe,wit.id_destinataire, + wit.nom_destinataire, wit.prenom_destinataire, wit.type , wit.id_wallet_user, wit.init_country, wit.final_country , wit.network_destinataire , wit.montant_net_final_country , + wit.date as date_creation , wit.id , wit.numero_carte, wit.montant_net FROM wallet_ilink_transaction wit + INNER JOIN type_ilink_transaction tit ON wit.type = tit.id WHERE wit.network_emetteur = :id ;", ['id' => $id_network]); + + $transactions_mapped = array_map(function ($data) { + + $wallet_user = isset($data->id_wallet_user) ? WalletsUser::findOrFail($data->id_wallet_user) : null; + $user_destinataire = isset($data->id_destinataire) ? User::where('user_code', $data->id_destinataire)->first() : null; + $emetteur = $wallet_user ? $wallet_user->user->lastname . ' ' . $wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur; + if (!$wallet_user && !$data->nom_emetteur) + $emetteur = $data->numero_carte; + $destinataire = in_array($data->type, [12, 16]) ? $emetteur : ($user_destinataire ? $user_destinataire->lastname . ' ' . $user_destinataire->firstname : + $data->prenom_destinataire . ' ' . $data->nom_destinataire); + $data->emetteur = $emetteur; + $data->destinataire = $destinataire; + $data->frais = $this->toMoney($data->frais + $data->taxe, $data->init_country); + $data->montant_net_init = $this->toMoney($data->montant_net, $data->init_country); + $data->montant_net_final = $data->montant_net_final_country ? $this->toMoney($data->montant_net_final_country, $data->final_country) : $data->montant_net_init; + $data->montant = $this->toMoney($data->montant, $data->init_country); + $data->init_country = $this->getCountryName($data->init_country); + $data->final_country = $data->montant_net_final_country ? $this->getCountryName($data->final_country) : ''; + $data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire) . ' ' . $data->final_country : null; + + unset($data->type, $data->id_wallet_user, $data->network_destinataire, $data->nom_destinataire, $data->prenom_destinataire, $data->taxe, $data->numero_carte, + $data->montant_net_final_country, $data->montant_net, $data->nom_emetteur, $data->prenom_emetteur, $data->id_destinataire); + return $data; + }, $transactions); + + // Supprimer les underscore sur les etats + $merge = array_map(function ($demand) { + $demand->etat = str_replace('_', ' ', $demand->etat); + return $demand; + }, array_merge($demandes, $savings)); + + $result = array_merge($transactions_mapped, $merge); + + usort($result, array($this, 'sortFunction')); // Trier le tout par date + + return $this->successResponse($result); + } + + public function allSuperHistory($id_wallet) + { + + $walletSup = WalletAgent::where('wallet_id', $id_wallet)->firstOrFail(); + + $demandes = DB::select("SELECT 'N' as type_historique , i.* FROM infos_users_demandes_credits i WHERE id_network = :id ;", ['id' => $walletSup->codeMembre]); + + + $transactions = DB::select("SELECT 'T' as type_historique, wit.id_transaction, tit.nom as operation , wit.montant ,wit.nom_emetteur, wit.prenom_emetteur, wit.id_wallet_user,wit.frais,wit.taxe,wit.id_destinataire, + wit.nom_destinataire, wit.prenom_destinataire, wit.type , wit.id_wallet_user, wit.init_country, wit.final_country , wit.network_destinataire , wit.montant_net_final_country , + wit.date as date_creation , wit.id , wit.numero_carte, wit.montant_net FROM wallet_ilink_transaction wit + INNER JOIN type_ilink_transaction tit ON wit.type = tit.id WHERE wit.id_wallet_sup = :id ;", ['id' => $id_wallet]); + + $transactions_mapped = array_map(function ($data) { + + $wallet_user = isset($data->id_wallet_user) ? WalletsUser::findOrFail($data->id_wallet_user) : null; + $user_destinataire = isset($data->id_destinataire) ? User::where('user_code', $data->id_destinataire)->first() : null; + $emetteur = $wallet_user ? $wallet_user->user->lastname . ' ' . $wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur; + if (!$wallet_user && !$data->nom_emetteur) + $emetteur = $data->numero_carte; + $destinataire = in_array($data->type, [12, 16]) ? $emetteur : ($user_destinataire ? $user_destinataire->lastname . ' ' . $user_destinataire->firstname : + $data->prenom_destinataire . ' ' . $data->nom_destinataire); + $data->emetteur = $emetteur; + $data->destinataire = $destinataire; + $data->frais = $this->toMoney($data->frais + $data->taxe, $data->init_country); + $data->montant_net_init = $this->toMoney($data->montant_net, $data->init_country); + $data->montant_net_final = $data->montant_net_final_country ? $this->toMoney($data->montant_net_final_country, $data->final_country) : $data->montant_net_init; + $data->montant = $this->toMoney($data->montant, $data->init_country); + $data->init_country = $this->getCountryName($data->init_country); + $data->final_country = $data->montant_net_final_country ? $this->getCountryName($data->final_country) : ''; + $data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire) . ' ' . $data->final_country : null; + + unset($data->type, $data->id_wallet_user, $data->network_destinataire, $data->nom_destinataire, $data->prenom_destinataire, $data->taxe, $data->numero_carte, + $data->montant_net_final_country, $data->montant_net, $data->nom_emetteur, $data->prenom_emetteur, $data->id_destinataire); + return $data; + }, $transactions); + + // Supprimer les underscore sur les etats + $demandes_mapped = array_map(function ($demand) { + $demand->etat = str_replace('_', ' ', $demand->etat); + return $demand; + }, $demandes); + + $result = array_merge($transactions_mapped, $demandes_mapped); + + usort($result, array($this, 'sortFunction')); // Trier le tout par date + + return $this->successResponse($result); + } + } diff --git a/routes/web.php b/routes/web.php index 4a5ff15..d71c2e0 100755 --- a/routes/web.php +++ b/routes/web.php @@ -57,6 +57,9 @@ $router->group(['prefix' => '/wallets'] , function () use ($router){ //Les historiques globals des hyperviseur et superviseur $router->get('hyper_history/{id_network}', 'WalletController@hyperHistory'); $router->get('super_history/{id_wallet}', 'WalletController@superHistory'); + // Routes sans pagination + $router->get('all_hyper_history/{id_network}', 'WalletController@allHyperHistory'); + $router->get('all_super_history/{id_wallet}', 'WalletController@allSuperHistory'); // Wallets users iLink $router->group(['prefix' => '/users'], function () use ($router) {