694e1af651
- update jomweb/billplz package - refactor controllers, views with means of to simplify data fetch and manipuation
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Http\Client\Pool;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class MarhunService
|
|
{
|
|
public $norujukanList;
|
|
|
|
public function __construct($norujukanList) {
|
|
$this->norujukanList = $norujukanList;
|
|
}
|
|
|
|
public function getMarhunDetails()
|
|
{
|
|
$getMarhunDetails = function () {
|
|
return Http::pool(function (Pool $pool) {
|
|
foreach ($this->norujukanList as $norujukan) {
|
|
$pool->get(config('api.url') . '/api/marhun/' . $norujukan);
|
|
}
|
|
});
|
|
};
|
|
|
|
$marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x->json()), $getMarhunDetails());
|
|
|
|
$formatMarhunDetailData = function ($x) {
|
|
$getMarhunTypeFullName = function ($code) {
|
|
|
|
$marhun = Http::get(config('api.url') . '/api/jemas/nama_marhun', ['marhun' => $code])->json()['descpt'];
|
|
return $marhun;
|
|
};
|
|
|
|
return array_map(function ($y) use ($getMarhunTypeFullName) {
|
|
$y['marhun'] = $getMarhunTypeFullName($y['marhun']);
|
|
return $y;
|
|
}, $x);
|
|
};
|
|
|
|
return array_map($formatMarhunDetailData, $marhunDetailsResponse);
|
|
}
|
|
|
|
public static function from($norujukanList)
|
|
{
|
|
return new static($norujukanList);
|
|
}
|
|
|
|
}
|