diff --git a/app/Http/Controllers/iLinkTransactionController.php b/app/Http/Controllers/iLinkTransactionController.php index 38a1cbc..37fc7f9 100755 --- a/app/Http/Controllers/iLinkTransactionController.php +++ b/app/Http/Controllers/iLinkTransactionController.php @@ -636,6 +636,7 @@ class iLinkTransactionController extends Controller if (!$user) return $this->errorResponse(trans('errors.wallet_not_defined')); + $transaction->id_destinataire = $request->user_code; $walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail(); $transaction->final_country = $final_country = $user->network->country->id; @@ -898,19 +899,43 @@ class iLinkTransactionController extends Controller } - public function lastUserTransactions($id_wallet_user) + public function lastUserTransactions($code_user) { - $transactions = DB::select('SELECT tit.nom as operation , wit.montant , - CASE - WHEN u.lastname IS NOT NULL THEN u.lastname - ELSE - CASE - WHEN wit.id_destinataire IS NULL THEN wit.nom_destinataire - ELSE wit.id_destinataire - END - END AS destinataire , wit.date , wit.id FROM wallet_ilink_transaction wit - INNER JOIN type_ilink_transaction tit ON wit.type = tit.id LEFT JOIN users u ON u.user_code = wit.id_destinataire WHERE wit.id_wallet_user = :id_wallet - ORDER BY wit.date DESC LIMIT 10;', ['id_wallet' => $id_wallet_user]); + $user = User::where('user_code',$code_user)->firstOrFail(); + $wallet_user = WalletsUser::where('idUser',$user->id)->firstOrFail(); + + $transactions = DB::select('SELECT id_wallet_user , operation , id_transaction ,network_destinataire, init_country , final_country, date , id , montant , frais , taxe , pays_init , pays_final, + destinataire_phone , destinataire_name , nom_destinataire, prenom_destinataire, montant_net ,montant_net_final_country FROM infos_ilink_transaction WHERE id_wallet_user = :id_wallet + ORDER BY date DESC LIMIT 10;', ['id_wallet' => $wallet_user->id]); + + foreach ($transactions as $data){ + $date = $data->date; + unset($data->date); + + $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; + $emetteur = 'Moi'; + + if($data->destinataire_phone){ + $destinataire = $data->destinataire_name; + }else{ + $destinataire = $data->prenom_destinataire ? $data->prenom_destinataire . ' ' . $data->nom_destinataire : $emetteur; + } +// $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 = $data->pays_init; + $data->final_country = $data->pays_final; + $data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire).' '.$data->final_country : null; + $data->date = $date; + unset($data->type, $data->destinataire_name, $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->pays_init, $data->pays_final ,$data->id_destinataire ,$data->destinataire_phone); + } return $this->successResponse($transactions); }