183 lines
5.0 KiB
PHP
183 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\CardTransaction;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Order\Card\CardTransaction\CardTransaction;
|
|
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
|
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
|
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
|
use Dedoc\Scramble\Attributes\Group;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
#[Group('Sargytlar - Kart - Kart hereketleri')]
|
|
class CardTransactionsController extends Controller
|
|
{
|
|
/**
|
|
* LIST*
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json(
|
|
CardTransaction::query()
|
|
->where('user_id', auth()->id())
|
|
->get()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* SAVE*
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
/**
|
|
* @example I-AS
|
|
*/
|
|
'passport_serie' => ['required', Rule::in(array_keys(PassportRepo::values()))],
|
|
|
|
/**
|
|
* @example 379514
|
|
*/
|
|
'passport_id' => ['required', 'numeric', 'digits:6'],
|
|
|
|
/**
|
|
* @example 9934612100000243
|
|
*/
|
|
'card_number' => ['required', 'digits:16'],
|
|
|
|
/**
|
|
* @example 12
|
|
*/
|
|
'card_month' => ['required', Rule::in(array_keys(DateHelperRepository::staticNumberMonths()))],
|
|
|
|
/**
|
|
* @example 2049
|
|
*/
|
|
'card_year' => ['required', Rule::in(array_keys(DateHelperRepository::staticNumberYears()))]
|
|
]);
|
|
|
|
CardTransaction::forceCreate([
|
|
...$data,
|
|
...[
|
|
'user_id' => auth()->id(),
|
|
],
|
|
]);
|
|
|
|
return response()->json([
|
|
'message' => __('Successfully created'),
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* SHOW*
|
|
*
|
|
* 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
|
|
{
|
|
if ($order->user_id != auth()->id()) {
|
|
return response()->json(status: 403);
|
|
}
|
|
|
|
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' => ''
|
|
]);
|
|
}
|
|
|
|
$url = DownloadCardTransaction::make()->doFiles($order, $data);
|
|
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => $response->message,
|
|
'url' => $url
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* UPDATE*
|
|
*
|
|
* ID ugradyp `route`-da update edip bilyan. Base App Enum-lardan peydalan. Panelkadan gor.
|
|
*/
|
|
public function update(Request $request, CardTransaction $order): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
/**
|
|
* @example I-AS
|
|
*/
|
|
'passport_serie' => ['sometimes', Rule::in(array_keys(PassportRepo::values()))],
|
|
|
|
/**
|
|
* @example 379514
|
|
*/
|
|
'passport_id' => ['sometimes', 'numeric', 'digits:6'],
|
|
|
|
/**
|
|
* @example 9934612100000243
|
|
*/
|
|
'card_number' => ['sometimes', 'digits:16'],
|
|
|
|
/**
|
|
* @example 12
|
|
*/
|
|
'card_month' => ['sometimes', Rule::in(array_keys(DateHelperRepository::staticNumberMonths()))],
|
|
|
|
/**
|
|
* @example 2049
|
|
*/
|
|
'card_year' => ['sometimes', Rule::in(array_keys(DateHelperRepository::staticNumberYears()))]
|
|
]);
|
|
|
|
Model::unguarded(function () use ($order, $data) {
|
|
$order->update($data);
|
|
});
|
|
|
|
return response()->json([
|
|
'message' => __('Successfully updated'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* DELETE*
|
|
*/
|
|
public function destroy(CardTransaction $order): JsonResponse
|
|
{
|
|
if ($order->user_id != auth()->id()) {
|
|
return response()->json(status: 403);
|
|
}
|
|
|
|
$order->delete();
|
|
|
|
return response()->json([
|
|
'message' => __('Successfully deleted'),
|
|
]);
|
|
}
|
|
}
|