+ History of nano credit and savings
This commit is contained in:
parent
daadf941de
commit
848d9428c7
|
@ -3,10 +3,8 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\AgentPlus;
|
use App\Models\AgentPlus;
|
||||||
use App\Models\CodeGenerer;
|
|
||||||
use App\Models\ConfigWallet;
|
use App\Models\ConfigWallet;
|
||||||
use App\Models\Identification;
|
use App\Models\Identification;
|
||||||
use App\Models\InfosUsersGroup;
|
|
||||||
use App\Models\NetworksAgent;
|
use App\Models\NetworksAgent;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UsersDemandesCredit;
|
use App\Models\UsersDemandesCredit;
|
||||||
|
@ -188,15 +186,55 @@ class NanoCreditController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortFunction($a, $b)
|
||||||
|
{
|
||||||
|
return strtotime($b->date_creation) - strtotime($a->date_creation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demandes de nano credit et d'epargnes
|
||||||
|
public function getAllNanoCreditsDemands($id_user, Request $request)
|
||||||
|
{
|
||||||
|
$demandes = DB::select("SELECT 'N' as type_historique , i.* FROM infos_users_demandes_credits i WHERE id_user = :id ;", ['id' => $id_user]);
|
||||||
|
$savings = DB::select("SELECT 'E' as type_historique , i.* FROM infos_users_epargnes i WHERE id_user = :id;", ['id' => $id_user]);
|
||||||
|
|
||||||
|
$merge = array_merge($demandes, $savings);
|
||||||
|
usort($merge, array($this, 'sortFunction'));
|
||||||
|
|
||||||
|
// return $this->successResponse($this->arrayPaginator($merge,$request));
|
||||||
|
|
||||||
|
return $this->successResponse($merge);
|
||||||
|
}
|
||||||
|
|
||||||
public function getNanoCreditsDemands($id_user)
|
public function getNanoCreditsDemands($id_user)
|
||||||
{
|
{
|
||||||
$demandes = DB::select('SELECT * FROM infos_users_demandes_credits WHERE id_user = :id;', ['id' => $id_user]);
|
$demandes = DB::select('SELECT * FROM infos_users_demandes_credits WHERE id_user = :id ORDER BY date_creation DESC;', ['id' => $id_user]);
|
||||||
|
return $this->successResponse($demandes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demandes de credits en cours pour le remboursement
|
||||||
|
public function getNanoCreditsDemandsInProgress($id_user)
|
||||||
|
{
|
||||||
|
$demandes = DB::select("SELECT * FROM infos_users_demandes_credits WHERE id_user = :id AND etat = 'VALIDE' ORDER BY date_creation DESC;", ['id' => $id_user]);
|
||||||
|
return $this->successResponse($demandes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGuaranteeNanoCreditsDemands($id_wallet_agent)
|
||||||
|
{
|
||||||
|
$demandes = DB::select('SELECT * FROM infos_users_demandes_credits WHERE id_wallet_agent = :id ORDER BY date_creation DESC;'
|
||||||
|
, ['id' => $id_wallet_agent]);
|
||||||
return $this->successResponse($demandes);
|
return $this->successResponse($demandes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSavingsDemands($id_user)
|
public function getSavingsDemands($id_user)
|
||||||
{
|
{
|
||||||
$savings = DB::select('SELECT * FROM infos_users_epargnes WHERE id_user = :id;', ['id' => $id_user]);
|
$savings = DB::select('SELECT * FROM infos_users_epargnes WHERE id_user = :id ORDER BY date_creation DESC;', ['id' => $id_user]);
|
||||||
|
return $this->successResponse($savings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Demandes d'epargnes pour la cassation
|
||||||
|
public function getSavingsDemandsInProgress($id_user)
|
||||||
|
{
|
||||||
|
$savings = DB::select("SELECT * FROM infos_users_epargnes WHERE id_user = :id AND etat = 'EN_COURS' ORDER BY date_creation DESC;", ['id' => $id_user]);
|
||||||
return $this->successResponse($savings);
|
return $this->successResponse($savings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,67 +336,8 @@ class NanoCreditController extends Controller
|
||||||
if ($demande_credit->etat == 'REMBOURSE')
|
if ($demande_credit->etat == 'REMBOURSE')
|
||||||
return $this->errorResponse(trans('errors.nano_credit_already_refunded'));
|
return $this->errorResponse(trans('errors.nano_credit_already_refunded'));
|
||||||
|
|
||||||
$init_country = $user->network->country->id;
|
$message = $this->refundNanoCredit($demande_credit, $user, $walletUser);
|
||||||
$montant_total = $demande_credit->montant + $demande_credit->interet + $demande_credit->taxe;
|
|
||||||
|
|
||||||
if ($montant_total > $walletUser->balance)
|
|
||||||
return $this->errorResponse(trans('errors.insufficient_balance'));
|
|
||||||
|
|
||||||
$user->balance_credit -= $montant_total;
|
|
||||||
$walletUser->balance -= $montant_total;
|
|
||||||
$demande_credit->etat = 'REMBOURSE';
|
|
||||||
|
|
||||||
if ($demande_credit->type_caution == 'individuel') {
|
|
||||||
// Repartition des interet entre agents
|
|
||||||
|
|
||||||
$walletAgent = Wallet::findOrFail($demande_credit->id_wallet_agent);
|
|
||||||
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
|
|
||||||
|
|
||||||
$config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail();
|
|
||||||
|
|
||||||
// Recuperation des wallets hyperviseur et superviseur
|
|
||||||
$codeGenerer = CodeGenerer::findOrFail($network_agent->codeGenerer_id);
|
|
||||||
$superviseur = AgentPlus::where('code_membre', $codeGenerer->code_parrain)->firstOrFail();
|
|
||||||
$hyperviseur = AgentPlus::where('code_membre', $superviseur->code_parrain)->firstOrFail();
|
|
||||||
|
|
||||||
$wallet_agent_sup = WalletAgent::where('agent_id', $superviseur->id)->firstOrFail();
|
|
||||||
$wallet_agent_hyp = WalletAgent::where('agent_id', $hyperviseur->id)->firstOrFail();
|
|
||||||
$walletSuperviseur = Wallet::findOrFail($wallet_agent_sup->wallet_id);
|
|
||||||
$walletHyperviseur = Wallet::findOrFail($wallet_agent_hyp->wallet_id);
|
|
||||||
|
|
||||||
$walletAgent->balance_com += floatval($demande_credit->interet * $config->taux_com_ag_nano_credit /100 ) ;
|
|
||||||
$walletSuperviseur->balance_com += floatval($demande_credit->interet * $config->taux_com_sup_nano_credit /100) ;
|
|
||||||
$walletHyperviseur->balance_com += floatval($demande_credit->interet * $config->taux_com_hyp_nano_credit /100 ) ;
|
|
||||||
|
|
||||||
$walletAgent->save();
|
|
||||||
$walletSuperviseur->save();
|
|
||||||
$walletHyperviseur->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($demande_credit->type_caution == 'groupe') {
|
|
||||||
$group = InfosUsersGroup::findOrFail($user->group_id);
|
|
||||||
|
|
||||||
// Recuperation des wallets hyperviseur et superviseur
|
|
||||||
$walletHyper = WalletAgent::where('category', 'hyper')->where('network_id', $group->id_network)->firstOrFail();
|
|
||||||
$walletHyper = Wallet::findOrFail($walletHyper->wallet_id);
|
|
||||||
|
|
||||||
$walletHyper->balance_princ += $demande_credit->montant;
|
|
||||||
$walletHyper->balance_com += $demande_credit->interet;
|
|
||||||
$walletHyper->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
$demande_credit->date_remboursement = new \DateTime();
|
|
||||||
|
|
||||||
$walletUser->save();
|
|
||||||
$user->save();
|
|
||||||
$demande_credit->save();
|
|
||||||
|
|
||||||
$message = trans('messages.successful_nano_credit_demand_refunded',
|
|
||||||
['id_demand' => $demande_credit->id_demande, 'amount' => $this->toMoney($montant_total, $init_country), 'duration' => $demande_credit->duree_mois,
|
|
||||||
'net' => $this->toMoney($demande_credit->montant, $init_country), 'fees' => $this->toMoney($demande_credit->interet, $init_country),
|
|
||||||
'tax' => $this->toMoney($demande_credit->taxe, $init_country),
|
|
||||||
'caution' => $demande_credit->type_caution == 'groupe' ? 'Groupe' : 'Individuel']);
|
|
||||||
$this->sendMail($user->email, trans('messages.successful_nano_credit_refunded'), $message);
|
|
||||||
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
return $this->successResponse($message . trans('messages.sent_by_mail'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1427,21 +1427,17 @@ class iLinkTransactionController extends Controller
|
||||||
$amount_admitted = $regulation->montant_max_jour - $daily_sum;
|
$amount_admitted = $regulation->montant_max_jour - $daily_sum;
|
||||||
// dd(($daily_sum + $montant_transaction) > $regulation->montant_max_jour);
|
// dd(($daily_sum + $montant_transaction) > $regulation->montant_max_jour);
|
||||||
if (($daily_sum + $montant_transaction) > $regulation->montant_max_jour)
|
if (($daily_sum + $montant_transaction) > $regulation->montant_max_jour)
|
||||||
return $this->errorResponse(trans('errors.daily_regulations_limits_reached') . '\n'
|
return $this->errorResponse(trans('errors.daily_regulations_limits_reached') . ' '
|
||||||
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
||||||
|
|
||||||
// Total montants hebdomadaire
|
// Total montants hebdomadaire
|
||||||
// To set the week start/end:
|
|
||||||
// Carbon::setLocale('en_US'); // Set week to start on Sunday
|
|
||||||
// Carbon::setWeekStartsAt(Carbon::SUNDAY);
|
|
||||||
// Carbon::setWeekEndsAt(Carbon::SATURDAY);
|
|
||||||
if ($is_id_document_emetteur)
|
if ($is_id_document_emetteur)
|
||||||
$weekly_sum = WalletIlinkTransaction::where('id_document_emetteur', $identifiant)->whereBetween('date', [Carbon::today()->subDay(7), Carbon::today()])->sum('montant');
|
$weekly_sum = WalletIlinkTransaction::where('id_document_emetteur', $identifiant)->whereBetween('date', [Carbon::today()->subDay(7), Carbon::today()])->sum('montant');
|
||||||
else
|
else
|
||||||
$weekly_sum = WalletIlinkTransaction::where('id_wallet_user', $identifiant)->whereBetween('date', [Carbon::today()->subDay(7), Carbon::today()])->sum('montant');
|
$weekly_sum = WalletIlinkTransaction::where('id_wallet_user', $identifiant)->whereBetween('date', [Carbon::today()->subDay(7), Carbon::today()])->sum('montant');
|
||||||
$amount_admitted = $regulation->montant_max_hedbo - $weekly_sum;
|
$amount_admitted = $regulation->montant_max_hedbo - $weekly_sum;
|
||||||
if (($weekly_sum + $montant_transaction) > $regulation->montant_max_hebdo)
|
if (($weekly_sum + $montant_transaction) > $regulation->montant_max_hebdo)
|
||||||
return $this->errorResponse(trans('errors.weekly_regulations_limits_reached') . '\n'
|
return $this->errorResponse(trans('errors.weekly_regulations_limits_reached') . ' '
|
||||||
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
||||||
|
|
||||||
|
|
||||||
|
@ -1452,7 +1448,7 @@ class iLinkTransactionController extends Controller
|
||||||
$monthly_sum = WalletIlinkTransaction::where('id_wallet_user', $identifiant)->whereBetween('date', [Carbon::today()->subDay(30), Carbon::today()])->sum('montant');
|
$monthly_sum = WalletIlinkTransaction::where('id_wallet_user', $identifiant)->whereBetween('date', [Carbon::today()->subDay(30), Carbon::today()])->sum('montant');
|
||||||
$amount_admitted = $regulation->montant_max_mensuel - $monthly_sum;
|
$amount_admitted = $regulation->montant_max_mensuel - $monthly_sum;
|
||||||
if (($monthly_sum + $montant_transaction) > $regulation->montant_max_mensuel)
|
if (($monthly_sum + $montant_transaction) > $regulation->montant_max_mensuel)
|
||||||
return $this->errorResponse(trans('errors.monthly_regulations_limits_reached') . '\n'
|
return $this->errorResponse(trans('errors.monthly_regulations_limits_reached') . ' '
|
||||||
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
. ($amount_admitted > 0 ? trans('errors.regulations_limits_amount_transaction', ['amount' => $this->toMoney($amount_admitted, $init_country)]) : ''));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,10 @@ use Brick\Money\ExchangeRateProvider\PDOProvider;
|
||||||
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
|
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
|
||||||
use Brick\Money\Money;
|
use Brick\Money\Money;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Input;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
|
@ -211,9 +214,9 @@ trait Helper
|
||||||
return $cc->currency_code;
|
return $cc->currency_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrayPaginator($array, $request)
|
public function arrayPaginator($array, Request $request)
|
||||||
{
|
{
|
||||||
$page = Input::get('page', 1);
|
$page = $request->query('page', 1);
|
||||||
$perPage = 10;
|
$perPage = 10;
|
||||||
$offset = ($page * $perPage) - $perPage;
|
$offset = ($page * $perPage) - $perPage;
|
||||||
|
|
||||||
|
@ -272,23 +275,12 @@ trait Helper
|
||||||
|
|
||||||
$credits = UsersDemandesCredit::where('etat', 'VALIDE')->where('date_remboursement_prevu', '<=', Carbon::today())->get();
|
$credits = UsersDemandesCredit::where('etat', 'VALIDE')->where('date_remboursement_prevu', '<=', Carbon::today())->get();
|
||||||
foreach ($credits as $demande_credit) {
|
foreach ($credits as $demande_credit) {
|
||||||
// \Log::info('Init credit ' . $demande_credit->id_demande);
|
|
||||||
|
|
||||||
// $refundDate = $demande_credit->date_remboursement_prevu;
|
|
||||||
// //Compare la date de remboursement prevu à celle d'aujourd'hui
|
|
||||||
// $today = (new DateTime())->format('Y-m-d');
|
|
||||||
// $expiry = (new DateTime($refundDate))->format('Y-m-d');
|
|
||||||
//
|
|
||||||
// if(isset($refundDate) && (strtotime($today) >= strtotime($expiry))){
|
|
||||||
//Reprise de la methode de remboursement
|
|
||||||
|
|
||||||
$user = User::findOrFail($demande_credit->id_user);
|
$user = User::findOrFail($demande_credit->id_user);
|
||||||
$walletUser = WalletsUser::where('idUser', $demande_credit->id_user)->firstOrFail();
|
$walletUser = WalletsUser::where('idUser', $demande_credit->id_user)->firstOrFail();
|
||||||
|
|
||||||
$this->refundNanoCredit($demande_credit, $user, $walletUser);
|
$this->refundNanoCredit($demande_credit, $user, $walletUser);
|
||||||
// \Log::info('Nano credit refunded ' . $demande_credit->id_demande);
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +299,8 @@ trait Helper
|
||||||
|
|
||||||
if ($quota == 0) {
|
if ($quota == 0) {
|
||||||
// Solde egale zero donc pas de remboursement
|
// Solde egale zero donc pas de remboursement
|
||||||
$this->sendMail($user->email, trans('messages.failed_nano_credit_refunded'), trans('messages.reload_your_account'));
|
$message = trans('messages.reload_your_account');
|
||||||
|
$title = trans('messages.failed_nano_credit_refunded');
|
||||||
} else {
|
} else {
|
||||||
$partialRefund = false;
|
$partialRefund = false;
|
||||||
|
|
||||||
|
@ -375,9 +368,13 @@ trait Helper
|
||||||
'tax' => $this->toMoney($demande_credit->taxe * $quota, $init_country),
|
'tax' => $this->toMoney($demande_credit->taxe * $quota, $init_country),
|
||||||
'caution' => $demande_credit->type_caution == 'groupe' ? 'Groupe' : 'Individuel']);
|
'caution' => $demande_credit->type_caution == 'groupe' ? 'Groupe' : 'Individuel']);
|
||||||
|
|
||||||
$this->sendMail($user->email, (!$partialRefund) ? trans('messages.successful_nano_credit_refunded') :
|
$title = (!$partialRefund) ? trans('messages.successful_nano_credit_refunded') :
|
||||||
trans('messages.successful_nano_credit_partially_refunded'), $message);
|
trans('messages.successful_nano_credit_partially_refunded');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->sendMail($user->email, $title, $message);
|
||||||
|
return $title . "\n" . $message;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,8 @@ Request Information:
|
||||||
NB: The reimbursement process is automatic on the due date if the reimbursement is not initiated",
|
NB: The reimbursement process is automatic on the due date if the reimbursement is not initiated",
|
||||||
'successful_guarantee_nano_credit_demand' => 'Guaranteed nanocredit request',
|
'successful_guarantee_nano_credit_demand' => 'Guaranteed nanocredit request',
|
||||||
'successful_nano_credit_refunded' => 'Nano credit repayment made',
|
'successful_nano_credit_refunded' => 'Nano credit repayment made',
|
||||||
'successful_nano_credit_partially_refunded' => 'Partially completed nano credit automatic repayment',
|
'successful_nano_credit_partially_refunded' => 'Partially completed nano credit repayment',
|
||||||
|
'failed_nano_credit_refunded' => 'Repayment of failed nano credit',
|
||||||
'successful_nano_credit_demand_refunded' => "Nano credit refunded
|
'successful_nano_credit_demand_refunded' => "Nano credit refunded
|
||||||
Request Information:
|
Request Information:
|
||||||
- Request number: :id_demand
|
- Request number: :id_demand
|
||||||
|
|
|
@ -209,8 +209,8 @@ Informations de la demande :
|
||||||
NB: Le processus de remboursement est automatique à la date d'échéance si le remboursement n'est pas initié",
|
NB: Le processus de remboursement est automatique à la date d'échéance si le remboursement n'est pas initié",
|
||||||
'successful_guarantee_nano_credit_demand' => 'Demande de nano crédit cautionnée',
|
'successful_guarantee_nano_credit_demand' => 'Demande de nano crédit cautionnée',
|
||||||
'successful_nano_credit_refunded' => 'Remboursement de nano crédit effectué',
|
'successful_nano_credit_refunded' => 'Remboursement de nano crédit effectué',
|
||||||
'successful_nano_credit_partially_refunded' => 'Remboursement automatique de nano crédit partiellement effectué',
|
'successful_nano_credit_partially_refunded' => 'Remboursement de nano crédit partiellement effectué',
|
||||||
'failed_nano_credit_refunded' => 'Remboursement automatique de nano crédit échoué',
|
'failed_nano_credit_refunded' => 'Remboursement de nano crédit échoué',
|
||||||
'successful_nano_credit_demand_refunded' => "Nano crédit remboursé
|
'successful_nano_credit_demand_refunded' => "Nano crédit remboursé
|
||||||
Informations de la demande :
|
Informations de la demande :
|
||||||
- Numéro de la demande : :id_demand
|
- Numéro de la demande : :id_demand
|
||||||
|
|
|
@ -93,6 +93,9 @@ $router->group(['prefix' => '/groups'], function () use ($router) {
|
||||||
$router->post('refund', 'NanoCreditController@refundCredit');
|
$router->post('refund', 'NanoCreditController@refundCredit');
|
||||||
$router->post('durations', 'NanoCreditController@getDurations');
|
$router->post('durations', 'NanoCreditController@getDurations');
|
||||||
$router->get('demands/{id_user}', 'NanoCreditController@getNanoCreditsDemands');
|
$router->get('demands/{id_user}', 'NanoCreditController@getNanoCreditsDemands');
|
||||||
|
$router->get('all_demands/{id_user}', 'NanoCreditController@getAllNanoCreditsDemands');
|
||||||
|
$router->get('demands_in_progress/{id_user}', 'NanoCreditController@getNanoCreditsDemandsInProgress');
|
||||||
|
$router->get('guarantee_demands/{id_wallet_agent}', 'NanoCreditController@getGuaranteeNanoCreditsDemands');
|
||||||
$router->get('details/{id_demand}', 'NanoCreditController@getInfosNanoCredit');
|
$router->get('details/{id_demand}', 'NanoCreditController@getInfosNanoCredit');
|
||||||
$router->get('accounts/{id_user}', 'NanoCreditController@getNanoCreditAccount');
|
$router->get('accounts/{id_user}', 'NanoCreditController@getNanoCreditAccount');
|
||||||
|
|
||||||
|
@ -101,6 +104,7 @@ $router->group(['prefix' => '/groups'], function () use ($router) {
|
||||||
$router->post('break', 'NanoCreditController@breakSavings');
|
$router->post('break', 'NanoCreditController@breakSavings');
|
||||||
$router->get('details/{id_saving}', 'NanoCreditController@getInfosSavings');
|
$router->get('details/{id_saving}', 'NanoCreditController@getInfosSavings');
|
||||||
$router->get('demands/{id_user}', 'NanoCreditController@getSavingsDemands');
|
$router->get('demands/{id_user}', 'NanoCreditController@getSavingsDemands');
|
||||||
|
$router->get('demands_in_progress/{id_user}', 'NanoCreditController@getSavingsDemandsInProgress');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue