+ Add new field in savings requests

This commit is contained in:
Djery-Tom 2020-11-18 12:35:11 +01:00
parent bf2e38508d
commit 21cc818763
5 changed files with 15 additions and 12 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\AgentPlus; use App\Models\AgentPlus;
use App\Models\DemandeCredit; use App\Models\DemandeCredit;
use App\Models\Network;
use App\Models\Wallet; use App\Models\Wallet;
use App\Models\WalletAgent; use App\Models\WalletAgent;
use App\Traits\ApiResponser; use App\Traits\ApiResponser;
@ -56,7 +57,7 @@ class CreditController extends Controller
$walletAgent->balance_princ += $request->montant; $walletAgent->balance_princ += $request->montant;
$walletParrain->balance_princ -= $request->montant; $walletParrain->balance_princ -= $request->montant;
DB::update('UPDATE demandeCredits SET montant = ? , `status` = \'1\' , date_modification = ? , date_creation = ? WHERE ( id = ? );', [$request->montant, $datetime, $datetime, $demand->id]); DB::update('UPDATE demandeCredits SET montant = ? , `status` = \'1\' , date_modification = ? WHERE ( id = ? );', [$request->montant, $datetime, $demand->id]);
}else{ }else{
if($walletParrain->balance_princ < $demand->montant) if($walletParrain->balance_princ < $demand->montant)
return $this->errorResponse(trans('messages.princ_balance_inf_to_demand_amount'),Response::HTTP_UPGRADE_REQUIRED); return $this->errorResponse(trans('messages.princ_balance_inf_to_demand_amount'),Response::HTTP_UPGRADE_REQUIRED);
@ -64,7 +65,7 @@ class CreditController extends Controller
$walletAgent->balance_princ += $demand->montant; $walletAgent->balance_princ += $demand->montant;
$walletParrain->balance_princ -= $demand->montant; $walletParrain->balance_princ -= $demand->montant;
DB::update('UPDATE demandeCredits SET `status` = \'1\' , date_modification = ? , date_creation = ? WHERE ( id = ? );', [$datetime, $datetime, $demand->id]); DB::update('UPDATE demandeCredits SET `status` = \'1\' , date_modification = ? WHERE ( id = ? );', [$datetime, $demand->id]);
} }
$walletAgent->save(); $walletAgent->save();
@ -76,7 +77,7 @@ class CreditController extends Controller
// echo "Error: " . $e->getMessage(); // echo "Error: " . $e->getMessage();
// } // }
$data = new \stdClass(); $data = new \stdClass();
$data->screen = "notificationview"; $data->screen = "Historique";
$data->data = new \stdClass(); $data->data = new \stdClass();
$data->data->id = $id_demand; $data->data->id = $id_demand;
@ -105,11 +106,12 @@ class CreditController extends Controller
$walletAgentParrain = WalletAgent::where('agent_id', $parrain->id)->firstOrFail(); $walletAgentParrain = WalletAgent::where('agent_id', $parrain->id)->firstOrFail();
$datetime = $this->getCurrentTime($walletAgentParrain->network->country_id); $network = Network::findOrFail($walletAgentParrain->network_id);
$datetime = $this->getCurrentTime($network->country_id);
$data = new \stdClass(); $data = new \stdClass();
$data->screen = "notificationview"; $data->screen = "Historique";
$data->data = new \stdClass(); $data->data = new \stdClass();
$data->data->id = $id_demand; $data->data->id = $id_demand;

View File

@ -282,6 +282,7 @@ class NanoCreditController extends Controller
"type": "SIMPLE", "type": "SIMPLE",
"etat": "EN COURS", "etat": "EN COURS",
"montant": "5000.00", "montant": "5000.00",
"montant_retire": "0.00",
"date_creation": "2020-11-07 14:08:45", "date_creation": "2020-11-07 14:08:45",
"id_epargne": "BVZ5NA3M", "id_epargne": "BVZ5NA3M",
"duree_mois": null, "duree_mois": null,
@ -297,7 +298,7 @@ class NanoCreditController extends Controller
*/ */
public function getSavingsDemandsInProgress($id_user) public function getSavingsDemandsInProgress($id_user)
{ {
$savings = DB::select("SELECT i.type , etat, montant, date_creation , id_epargne , duree_mois , interet , taxe , date_fin FROM infos_users_epargnes i WHERE i.id_user = :id AND i.etat = 'EN_COURS' ORDER BY i.date_creation DESC;", ['id' => $id_user]); $savings = DB::select("SELECT i.type , etat, montant, montant_retire , date_creation , id_epargne , duree_mois , interet , taxe , date_fin FROM infos_users_epargnes i WHERE i.id_user = :id AND i.etat = 'EN_COURS' ORDER BY i.date_creation DESC;", ['id' => $id_user]);
$result = array_map(function ($demand) { $result = array_map(function ($demand) {
$demand->etat = str_replace('_', ' ', $demand->etat); $demand->etat = str_replace('_', ' ', $demand->etat);
return $demand; return $demand;
@ -575,6 +576,8 @@ class NanoCreditController extends Controller
$user->balance_epargne -= $montant_total; $user->balance_epargne -= $montant_total;
$walletUser->balance += $montant_total; $walletUser->balance += $montant_total;
$saving->etat = 'CASSE'; $saving->etat = 'CASSE';
$saving->montant = 0;
$saving->montant_retire = $montant_total;
$saving->date_cassation = $this->getCurrentTime($init_country); $saving->date_cassation = $this->getCurrentTime($init_country);
$user->save(); $user->save();

View File

@ -16,6 +16,7 @@ use Illuminate\Database\Eloquent\Model;
* @property string $id_epargne * @property string $id_epargne
* @property string $type * @property string $type
* @property float $montant * @property float $montant
* @property float montant_retire
* @property int $duree_mois * @property int $duree_mois
* @property float $interet * @property float $interet
* @property float $taxe * @property float $taxe
@ -35,6 +36,7 @@ class UsersEpargne extends Model
protected $casts = [ protected $casts = [
'montant' => 'float', 'montant' => 'float',
'montant_retire' => 'float',
'duree_mois' => 'int', 'duree_mois' => 'int',
'interet' => 'float', 'interet' => 'float',
'taxe' => 'float', 'taxe' => 'float',
@ -52,6 +54,7 @@ class UsersEpargne extends Model
'id_epargne', 'id_epargne',
'type', 'type',
'montant', 'montant',
'montant_retire',
'duree_mois', 'duree_mois',
'interet', 'interet',
'taxe', 'taxe',

View File

@ -64,9 +64,4 @@ class WalletAgent extends Model
'currency_code', 'currency_code',
'transactionNumber' 'transactionNumber'
]; ];
public function network()
{
return $this->belongsTo(Network::class, 'network_id');
}
} }