wip
This commit is contained in:
@@ -3,12 +3,14 @@
|
|||||||
use App\Events\EventType;
|
use App\Events\EventType;
|
||||||
use App\Models\System\Roles\Permission;
|
use App\Models\System\Roles\Permission;
|
||||||
use App\Models\System\Verification;
|
use App\Models\System\Verification;
|
||||||
|
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Psr7\Request as GuzzleRequest;
|
use GuzzleHttp\Psr7\Request as GuzzleRequest;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Stevebauman\Location\Facades\Location;
|
use Stevebauman\Location\Facades\Location;
|
||||||
use Symfony\Component\HttpFoundation\IpUtils;
|
use Symfony\Component\HttpFoundation\IpUtils;
|
||||||
|
|
||||||
@@ -290,6 +292,9 @@ function cached(string $name, mixed $value, int $seconds = 60): mixed
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* view-loan-order-permission-id
|
||||||
|
*/
|
||||||
function view_loan_order_permission_id(): int
|
function view_loan_order_permission_id(): int
|
||||||
{
|
{
|
||||||
return Cache::rememberForever('view_loan_order_permission_id', function () {
|
return Cache::rememberForever('view_loan_order_permission_id', function () {
|
||||||
@@ -297,6 +302,29 @@ function view_loan_order_permission_id(): int
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VP fetch client info all
|
||||||
|
*
|
||||||
|
* @param $model
|
||||||
|
* @param $start_date
|
||||||
|
* @param $end_date
|
||||||
|
*/
|
||||||
|
function vp_fetch_ClientInfoAll($model, $start_date, $end_date)
|
||||||
|
{
|
||||||
|
$response = DownloadCardTransaction::make()->fetchApi(
|
||||||
|
passport_serie: $model->passport_serie,
|
||||||
|
passport_id: $model->passport_id,
|
||||||
|
card_number_masked: Str::mask($model->card_number, '*', 6, 6),
|
||||||
|
card_expire_date: $model->card_month.'/'.substr($model->card_year, 2),
|
||||||
|
start_date: $start_date,
|
||||||
|
end_date: $end_date,
|
||||||
|
);
|
||||||
|
|
||||||
|
return Str::isJson($response)
|
||||||
|
? json_decode($response)
|
||||||
|
: emptyClass(errCode: 1, message: 'Connection issue to VP');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an anonymous class that acts as a dynamic object.
|
* Create an anonymous class that acts as a dynamic object.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ namespace App\Http\Controllers\Api\CardTransaction;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Order\Card\CardTransaction\CardTransaction;
|
use App\Models\Order\Card\CardTransaction\CardTransaction;
|
||||||
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
||||||
|
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
|
||||||
use App\Repos\System\Settings\Legal\PassportRepo;
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
||||||
use Dedoc\Scramble\Attributes\Group;
|
use Dedoc\Scramble\Attributes\Group;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
#[Group('Sargytlar - Kart - Kart hereketleri')]
|
#[Group('Sargytlar - Kart - Kart hereketleri')]
|
||||||
@@ -74,7 +76,7 @@ class CardTransactionsController extends Controller
|
|||||||
/**
|
/**
|
||||||
* SHOW*
|
* SHOW*
|
||||||
*
|
*
|
||||||
* ID ugradyp alyan route -da.
|
* ID ugradyp alyan route -da. Soň page-da download button bolmaly, basaňdan soň, modal çykmaly, start date bilen end date ugradyp download basanda `/api/card-transactions-download/{order}` route gelyan pdf download etmeli.
|
||||||
*/
|
*/
|
||||||
public function show(CardTransaction $order): JsonResponse
|
public function show(CardTransaction $order): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -85,6 +87,32 @@ class CardTransactionsController extends Controller
|
|||||||
return response()->json($order);
|
return response()->json($order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download*
|
||||||
|
*
|
||||||
|
* Download card transaction file
|
||||||
|
*/
|
||||||
|
public function download(Request $request, CardTransaction $order)
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'start_date' => ['required', 'string', 'date'],
|
||||||
|
'end_date' => ['required', 'string', 'date']
|
||||||
|
]);
|
||||||
|
|
||||||
|
$start_date = Carbon::create($data['start_date']);
|
||||||
|
$end_date = Carbon::create($data['end_date']);
|
||||||
|
|
||||||
|
$response = vp_fetch_ClientInfoAll($order, $start_date, $end_date);
|
||||||
|
|
||||||
|
if ($response->errCode != 0) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => false,
|
||||||
|
'message' => $response->message,
|
||||||
|
'url' => ''
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UPDATE*
|
* UPDATE*
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -61,16 +61,9 @@ class DownloadCardTransaction extends Action
|
|||||||
return ActionResponse::danger($data->message);
|
return ActionResponse::danger($data->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
|
$url = $this->doFiles($model, $data);
|
||||||
$dir = public_path("files/{$unique_folder_name}");
|
|
||||||
|
|
||||||
File::makeDirectory($dir, 0777, true, true);
|
return ActionResponse::openInNewTab($url);
|
||||||
|
|
||||||
$fileDest = $dir."/{$model->id}.pdf";
|
|
||||||
|
|
||||||
$this->generateFile($data, $fileDest);
|
|
||||||
|
|
||||||
return ActionResponse::openInNewTab(url("files/{$unique_folder_name}/{$model->id}.pdf"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +87,26 @@ class DownloadCardTransaction extends Action
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all file stuff
|
||||||
|
*
|
||||||
|
* @param $model
|
||||||
|
* @param $data
|
||||||
|
*/
|
||||||
|
public function doFiles($model, $data): string
|
||||||
|
{
|
||||||
|
$unique_folder_name = Str::snake(str_replace(':', '-', $model->created_at->toDateTimeString()));
|
||||||
|
$dir = public_path("files/{$unique_folder_name}");
|
||||||
|
|
||||||
|
File::makeDirectory($dir, 0777, true, true);
|
||||||
|
|
||||||
|
$fileDest = $dir."/{$model->id}.pdf";
|
||||||
|
|
||||||
|
$this->generateFile($data, $fileDest);
|
||||||
|
|
||||||
|
return url("files/{$unique_folder_name}/{$model->id}.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch from internal API
|
* Fetch from internal API
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ Route::middleware(['auth:sanctum', 'not_banned'])->group(function () {
|
|||||||
// Card transactions... [tested fully]
|
// Card transactions... [tested fully]
|
||||||
Route::get('card-transactions', [CardTransactionsController::class, 'index']);
|
Route::get('card-transactions', [CardTransactionsController::class, 'index']);
|
||||||
Route::get('card-transactions/{order}', [CardTransactionsController::class, 'show']);
|
Route::get('card-transactions/{order}', [CardTransactionsController::class, 'show']);
|
||||||
|
Route::get('card-transactions-download/{order}', [CardTransactionsController::class, 'download']);
|
||||||
Route::post('card-transactions', [CardTransactionsController::class, 'store']);
|
Route::post('card-transactions', [CardTransactionsController::class, 'store']);
|
||||||
Route::post('card-transactions/{order}', [CardTransactionsController::class, 'update']);
|
Route::post('card-transactions/{order}', [CardTransactionsController::class, 'update']);
|
||||||
Route::delete('card-transactions/{order}', [CardTransactionsController::class, 'destroy']);
|
Route::delete('card-transactions/{order}', [CardTransactionsController::class, 'destroy']);
|
||||||
|
|||||||
Reference in New Issue
Block a user