Add route to fix refund amount on network UBA Frequence Service
This commit is contained in:
parent
9df0cedfbc
commit
02db72067d
|
@ -7,7 +7,7 @@ use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class RefundAmountImport implements FromArray, WithColumnFormatting, ShouldAutoSize
|
||||
class RefundAmountExport implements FromArray, WithColumnFormatting, ShouldAutoSize
|
||||
{
|
||||
protected $data;
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\RefundAmountImport;
|
||||
use App\Exports\RefundAmountExport;
|
||||
use App\Imports\RefundAmountImport;
|
||||
use App\Jobs\TestJob;
|
||||
use App\Models\AgentPlus;
|
||||
use App\Models\ConfigWallet;
|
||||
|
@ -17,7 +18,9 @@ use App\Traits\ApiResponser;
|
|||
use App\Traits\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Throwable;
|
||||
|
||||
class HelperController extends Controller
|
||||
{
|
||||
|
@ -151,7 +154,7 @@ class HelperController extends Controller
|
|||
return $this->successResponse($codes);
|
||||
}
|
||||
|
||||
public function fixTransactionAmount()
|
||||
public function calculateTransactionAmount()
|
||||
{
|
||||
$data = [['ID Wallet', 'Agent', 'Contact', 'Role', 'Parrain', 'Nombre de transactions', 'Montant à rembourser']];
|
||||
// Calcul du montant a prelever pour tous les agents loc du reseau iLink World
|
||||
|
@ -185,8 +188,37 @@ class HelperController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
$export = new RefundAmountImport($data);
|
||||
$export = new RefundAmountExport($data);
|
||||
|
||||
return Excel::download($export, 'refund.xlsx');
|
||||
}
|
||||
|
||||
public function fixTransactionAmount()
|
||||
{
|
||||
$data = Excel::toArray(new RefundAmountImport, storage_path('refund.xlsx'));
|
||||
$result = [];
|
||||
foreach ($data[0] as $key => $row) {
|
||||
if ($key > 0) {
|
||||
array_push($result, $row);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
// Fix amount
|
||||
foreach ($result as $r) {
|
||||
if (isset($r[6])) {
|
||||
$wallet = Wallet::find($r[0]);
|
||||
$wallet->balance_com -= $r[6];
|
||||
$wallet->save();
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return $this->successResponse(trans('messages.success_treated_demand'));
|
||||
} catch (Throwable $exception) {
|
||||
DB::rollBack();
|
||||
Log::error($exception->getMessage());
|
||||
return $this->errorResponse(trans('errors.unexpected_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\ToArray;
|
||||
|
||||
class RefundAmountImport implements ToArray
|
||||
{
|
||||
protected $data;
|
||||
|
||||
// public function __construct(array $data)
|
||||
// {
|
||||
// $this->data = $data;
|
||||
// }
|
||||
|
||||
public function array(array $array)
|
||||
{
|
||||
// TODO: Implement array() method.
|
||||
}
|
||||
}
|
|
@ -37,10 +37,10 @@ trait ApiResponser
|
|||
return response()->json($this->formatResponse($code, null, $message), $code);
|
||||
}
|
||||
|
||||
public function errorMessage($message , $code)
|
||||
{
|
||||
return response($message ,$code)->header('Content-Type', 'application/json');
|
||||
}
|
||||
// public function errorMessage($message , $code)
|
||||
// {
|
||||
// return response($message ,$code)->header('Content-Type', 'application/json');
|
||||
// }
|
||||
|
||||
private function formatResponse(int $status, $response = null, $error = null)
|
||||
{
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue