Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/WalletsController.php
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | class WalletsController extends Controller | ||||
{ | { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
/** | /** | ||||
* Update the specified resource in storage. | * Update the specified resource in storage. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request | * @param \Illuminate\Http\Request $request | ||||
* @param int $id | * @param string $id | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function update(Request $request, $id) | public function update(Request $request, $id) | ||||
{ | { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | public function receipts($id) | ||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!Auth::guard()->user()->canRead($wallet)) { | if (!Auth::guard()->user()->canRead($wallet)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$result = $wallet->payments() | $result = $wallet->payments() | ||||
->selectRaw('distinct date_format(updated_at, "%Y-%m") as ident') | ->selectRaw('distinct date_format(updated_at, "%Y-%m") as ident') | ||||
->where('status', PaymentProvider::STATUS_PAID) | ->where('status', PaymentProvider::STATUS_PAID) | ||||
->where('amount', '>', 0) | ->where('amount', '<>', 0) | ||||
->orderBy('ident', 'desc') | ->orderBy('ident', 'desc') | ||||
->get() | ->get() | ||||
->whereNotIn('ident', [date('Y-m')]) // exclude current month | ->whereNotIn('ident', [date('Y-m')]) // exclude current month | ||||
->pluck('ident'); | ->pluck('ident'); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'list' => $result, | 'list' => $result, | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | class WalletsController extends Controller | ||||
/** | /** | ||||
* Returns human readable notice about the wallet state. | * Returns human readable notice about the wallet state. | ||||
* | * | ||||
* @param \App\Wallet $wallet The wallet | * @param \App\Wallet $wallet The wallet | ||||
*/ | */ | ||||
protected function getWalletNotice(Wallet $wallet): ?string | protected function getWalletNotice(Wallet $wallet): ?string | ||||
{ | { | ||||
// there is no credit | |||||
if ($wallet->balance < 0) { | if ($wallet->balance < 0) { | ||||
return \trans('app.wallet-notice-nocredit'); | return \trans('app.wallet-notice-nocredit'); | ||||
} | } | ||||
// the discount is 100%, no credit is needed | |||||
if ($wallet->discount && $wallet->discount->discount == 100) { | if ($wallet->discount && $wallet->discount->discount == 100) { | ||||
return null; | return null; | ||||
} | } | ||||
if ($wallet->owner->created_at > Carbon::now()->subDays(14)) { | // the owner was created less than a month ago | ||||
if ($wallet->owner->created_at > Carbon::now()->subMonthsWithoutOverflow(1)) { | |||||
// but more than two weeks ago, notice of trial ending | |||||
if ($wallet->owner->created_at <= Carbon::now()->subWeeks(2)) { | |||||
return \trans('app.wallet-notice-trial-end'); | |||||
} | |||||
return \trans('app.wallet-notice-trial'); | return \trans('app.wallet-notice-trial'); | ||||
} | } | ||||
if ($until = $wallet->balanceLastsUntil()) { | if ($until = $wallet->balanceLastsUntil()) { | ||||
if ($until->isToday()) { | if ($until->isToday()) { | ||||
if ($wallet->owner->created_at > Carbon::now()->subDays(30)) { | |||||
return \trans('app.wallet-notice-trial-end'); | |||||
} | |||||
return \trans('app.wallet-notice-today'); | return \trans('app.wallet-notice-today'); | ||||
} | } | ||||
$params = [ | $params = [ | ||||
'date' => $until->toDateString(), | 'date' => $until->toDateString(), | ||||
'days' => Carbon::now()->diffForHumans($until, Carbon::DIFF_ABSOLUTE), | 'days' => Carbon::now()->diffForHumans($until, Carbon::DIFF_ABSOLUTE), | ||||
]; | ]; | ||||
return \trans('app.wallet-notice-date', $params); | return \trans('app.wallet-notice-date', $params); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
} | } |