This commit is contained in:
2025-10-28 22:13:02 +05:00
parent 5edcde1e4c
commit 90c3ea3fff

View File

@@ -4,10 +4,12 @@ namespace App\Modules\CardTransaction\Repositories;
use App\Modules\Card\Models\Card;
use App\Modules\Makeable;
use Exception;
use Filament\Notifications\Notification;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Livewire\Component;
use Mpdf\Mpdf;
@@ -60,9 +62,6 @@ class CardTransactionRepository
/**
* Fetch from internal API
*
*
* @return string
*/
public function fetchApi(
string $passport_serie,
@@ -71,29 +70,37 @@ class CardTransactionRepository
string $card_expire_date,
string $start_date,
string $end_date
) {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo/all',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => sprintf('{ "idSeria": "%s", "idNo": "%s", "clientType": "recipient", "cardMaskNumber": "%s", "expDate": "%s", "fromDate" : "%s", "toDate" : "%s" }', $passport_serie, $passport_id, $card_number_masked, $card_expire_date, $start_date, $end_date),
CURLOPT_HTTPHEADER => [
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
'Content-Type: application/json',
],
]);
): string {
try {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'http://10.3.158.102:9999/api/clientinfo/all',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => sprintf('{ "idSeria": "%s", "idNo": "%s", "clientType": "recipient", "cardMaskNumber": "%s", "expDate": "%s", "fromDate" : "%s", "toDate" : "%s" }', $passport_serie, $passport_id, $card_number_masked, $card_expire_date, $start_date, $end_date),
CURLOPT_HTTPHEADER => [
'Authorization: Basic dGJ1c2VyOlFBWndzeDEyMw==',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
$response = curl_exec($curl);
curl_close($curl);
curl_close($curl);
return $response;
return (string) $response;
} catch (Exception $e) {
Log::error('AZAT API ERROR: '.$e->getMessage(), [
'file' => $e->getFile(),
]);
return 'CURL Error';
}
}
/**
@@ -103,7 +110,7 @@ class CardTransactionRepository
*/
public function generateFileUrl(Card $model, object $response): string
{
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
$unique_folder_name = Str::snake(str_replace(':', '-', now()->toDateTimeString()));
$dir = public_path("files/{$unique_folder_name}");
File::makeDirectory($dir, 0777, true, true);
@@ -118,7 +125,7 @@ class CardTransactionRepository
/**
* Generate file
*
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response
*/
public function generateFile(object $response, string $fileDest): void
{
@@ -137,25 +144,26 @@ class CardTransactionRepository
}
/**
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $data
* @param \App\Modules\CardTransaction\Types\CardTransactionResponse $response
*/
public function getExtraVariables($data): object
public function getExtraVariables(object $response): object
{
if (count($data->transactions) < 1) {
info([$response]);
if (count($response->transactions) < 1) {
return emptyClass(basdakyGalyndy: 0, ahyrkyGalyndy: 0, girdeji: 0, cykdajy: 0);
}
$basdakyGalyndy = $data->transactions[0]->rest;
$basdakyTransaksiya = $data->transactions[0]->currOperSum;
$sonkyGalyndy = $data->transactions[count($data->transactions) - 1]->rest;
$basdakyGalyndy = $response->transactions[0]->rest;
$basdakyTransaksiya = $response->transactions[0]->currOperSum;
$sonkyGalyndy = $response->transactions[count($response->transactions) - 1]->rest;
$positive = 0;
$negative = 0;
for ($i = 0; $i < count($data->transactions); $i++) {
if ($data->transactions[$i]->sign == '-') {
$negative += $data->transactions[$i]->currOperSum;
for ($i = 0; $i < count($response->transactions); $i++) {
if ($response->transactions[$i]->sign == '-') {
$negative += $response->transactions[$i]->currOperSum;
} else {
$positive += $data->transactions[$i]->currOperSum;
$positive += $response->transactions[$i]->currOperSum;
}
}