test drive
This commit is contained in:
@@ -268,3 +268,21 @@ function dbTypeToPhp(string $type): string
|
||||
default => 'string',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached value
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param int $seconds
|
||||
*/
|
||||
function cached(string $name, mixed $value, int $seconds = 60): mixed
|
||||
{
|
||||
return cache()->has($name)
|
||||
? cache($name)
|
||||
: cache()->remember(
|
||||
key: $name,
|
||||
ttl: $seconds,
|
||||
callback: fn () => is_callable($value) ? call_user_func($value) : $value
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,41 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property null|string $unique_id
|
||||
* @property int $card_state_id
|
||||
* @property int $card_type_id
|
||||
* @property string $region
|
||||
* @property int $branch_id
|
||||
* @property string $customer_name
|
||||
* @property string $customer_surname
|
||||
* @property null|string $customer_patronic_name
|
||||
* @property null|string $born_at
|
||||
* @property null|string $old_surname
|
||||
* @property string $citizenship
|
||||
* @property string $passport_serie
|
||||
* @property string $passport_id
|
||||
* @property string $passport_given_at
|
||||
* @property string $passport_given_by
|
||||
* @property string $born_place
|
||||
* @property null|string $job_location
|
||||
* @property null|string $passport_address
|
||||
* @property null|string $real_address
|
||||
* @property null|string $phone
|
||||
* @property null|string $phone_additional
|
||||
* @property null|string $status
|
||||
* @property string $passport_one
|
||||
* @property string $passport_two
|
||||
* @property string $passport_three
|
||||
* @property string $passport_four
|
||||
* @property null|string $notes
|
||||
* @property int $user_id
|
||||
* @property null|\Illuminate\Support\Carbon $created_at
|
||||
* @property null|\Illuminate\Support\Carbon $updated_at
|
||||
* @property null|\Illuminate\Support\Carbon $deleted_at
|
||||
* @property bool $paid
|
||||
*/
|
||||
class CardOrder extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\CardOrder\Nova\Actions;
|
||||
|
||||
use App\Nova\Resources\Order\Card\CardOrder;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Closure;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Actions\ActionResponse;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
|
||||
class RetryNovaCardOrderPayment extends Action
|
||||
{
|
||||
use InteractsWithQueue, Queueable;
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*/
|
||||
public function name(): string
|
||||
{
|
||||
return __('Retry payment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permissions
|
||||
*/
|
||||
public static function permissions(CardOrder $resource): Closure
|
||||
{
|
||||
return fn () => ! $resource->paid && $resource->status === OrderRepo::PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the action on the given models.
|
||||
*
|
||||
* @param ActionFields $fields
|
||||
* @param Collection<array-key, \Illuminate\Database\Eloquent\Model> $models
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(ActionFields $fields, Collection $models): mixed
|
||||
{
|
||||
$resource = $models->first();
|
||||
|
||||
$payment = (new OnlinePaymentRepo)->payCardOrder($resource);
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? ActionResponse::openInNewTab($payment['url'])
|
||||
: ActionResponse::danger('Тöleg sistemada registrasiýa bolmady!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields available on the action.
|
||||
*
|
||||
* @return array<int, \Laravel\Nova\Fields\Field>
|
||||
*/
|
||||
public function fields(NovaRequest $request): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
17
app/Nova/Guard/NovaGuard.php
Normal file
17
app/Nova/Guard/NovaGuard.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova\Guard;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NovaGuard
|
||||
{
|
||||
/**
|
||||
* Admin user
|
||||
*/
|
||||
public static function isAdmin(): Closure
|
||||
{
|
||||
return fn (Request $request): bool => $request->user()->isAdmin();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Nova\Resources\Order\Card;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Order\Card\CardOrder as CardOrderModel;
|
||||
use App\Modules\CardOrder\Nova\Actions\RetryNovaCardOrderPayment;
|
||||
use App\Nova\Filters\RegionFilter;
|
||||
use App\Nova\Filters\StatusFilter;
|
||||
use App\Nova\Forms\NovaForm;
|
||||
@@ -23,10 +24,7 @@ use App\Rules\DowranAgaAllowed;
|
||||
use App\Rules\OnlyLetters;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Fields\Date;
|
||||
use Laravel\Nova\Fields\Hidden;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
@@ -40,6 +38,9 @@ use Laravel\Nova\URL;
|
||||
use Nurmuhammet\NovaCustomHtml\NovaCustomHtml;
|
||||
use Nurmuhammet\NovaInputmask\NovaInputmask;
|
||||
|
||||
/**
|
||||
* @mixin CardOrderModel
|
||||
*/
|
||||
class CardOrder extends Resource
|
||||
{
|
||||
/**
|
||||
@@ -117,17 +118,18 @@ class CardOrder extends Resource
|
||||
*/
|
||||
public static function indexQuery(NovaRequest $request, mixed $query): Builder
|
||||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = $request->user();
|
||||
|
||||
if ($user->isAdmin()) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if ($user->isOperator()) {
|
||||
if ($user->isOperator() && count($user->branches()->pluck('branches.id')) < 1) {
|
||||
return $query->whereIn('branch_id', $user->branches()->pluck('branches.id'));
|
||||
}
|
||||
|
||||
return $query->where('user_id', $request->user()->id);
|
||||
return $query->where('user_id', $user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,20 +157,6 @@ class CardOrder extends Resource
|
||||
: sprintf('resources/%s/%s', static::uriKey(), $resource->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the location to redirect the user after update.
|
||||
*
|
||||
* @param \Laravel\Nova\Resource $resource
|
||||
*/
|
||||
// public static function redirectAfterUpdate(NovaRequest $request, $resource): URL|string
|
||||
// {
|
||||
// $payment = (new OnlinePaymentRepo())->payCardOrder($resource);
|
||||
|
||||
// return $payment['status'] === 'success'
|
||||
// ? URL::remote($payment['url'])
|
||||
// : sprintf('resources/%s/%s', static::uriKey(), $resource->getKey());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the fields for index.
|
||||
*
|
||||
@@ -389,19 +377,10 @@ class CardOrder extends Resource
|
||||
public function actions(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
Action::using('Tölegi täzeden geçir', function (ActionFields $fields, Collection $models) {
|
||||
$resource = $models->first();
|
||||
|
||||
$payment = (new OnlinePaymentRepo)->payCardOrder($resource);
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? URL::remote($payment['url'])
|
||||
: sprintf('resources/%s/%s', static::uriKey(), $resource->getKey());
|
||||
})->icon('credit-card')
|
||||
RetryNovaCardOrderPayment::make()
|
||||
->icon('credit-card')
|
||||
->sole()
|
||||
->canSee(function ($request) {
|
||||
return $request->user()->isAdmin();
|
||||
}),
|
||||
->canSee(RetryNovaCardOrderPayment::permissions($this)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class User extends Resource
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public static $search = [
|
||||
'id', 'name', 'email', 'phone',
|
||||
'id', 'name', 'email', 'phone', 'username',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,10 @@ class CardStateRepo
|
||||
*/
|
||||
public static function values(): Collection|array
|
||||
{
|
||||
return CardState::where('active', true)->pluck('name', 'id');
|
||||
return cached(
|
||||
'card-states',
|
||||
fn () => CardState::where('active', true)->pluck('name', 'id'),
|
||||
60 * 60
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ class CardTypeRepo
|
||||
*/
|
||||
public static function values(): Collection|array
|
||||
{
|
||||
return CardType::where('active', true)->pluck('name', 'id');
|
||||
return cached(
|
||||
'card-types',
|
||||
fn () => CardType::where('active', true)->pluck('name', 'id'),
|
||||
60 * 60
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,5 +333,6 @@
|
||||
"Loan order required docs": "Karz gerekli resminamalary",
|
||||
"Required docs": "Gerekli resminamalar",
|
||||
"Payment items": "Тöleg taryhy",
|
||||
"This month": "Şul aý"
|
||||
"This month": "Şul aý",
|
||||
"Retry payment": "Tölegi täzeden geçir"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ parameters:
|
||||
- app/
|
||||
|
||||
# Level 9 is the highest level
|
||||
level: 7
|
||||
level: 6
|
||||
|
||||
# ignoreErrors:
|
||||
# - '#PHPDoc tag @var#'
|
||||
|
||||
Reference in New Issue
Block a user