%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Therapist/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Controllers/Therapist/PaymentController.php

<?php

namespace App\Http\Controllers\Therapist;

use App;
use Carbon\Carbon;
use App\Models\Payment;
use App\Http\Resources\PaymentResource;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PaymentController extends Controller
{
    /**
     * Get all the therapist's payments
     *
     * @param Request $request
     * @return PaymentResource $payments
     */
    public function index(Request $request)
    {
        $payments = Payment::where('seller_id', auth()->id())
            ->orderBy('created_at', 'desc')
            ->get()
            ->groupBy(function ($item) {
                return $item->created_at->isToday() ? __('Today') : Carbon::parse($item->created_at)->format('d M Y');
            })->transform(function ($item, $key) {
                return $item->transform(function ($item, $key) {
                    return new PaymentResource($item);
                });
            });

        return response()->json($payments);
    }

    /**
     * Generates a PDF Statement of payments for a given timeframe
     *
     * @param Request $request
     * @return String - Base64 encoded PDF data
     */
    public function statement(Request $request)
    {
        $timeframe = $request->input('timeframe');
        $from = Carbon::now()->startOfDay();
        $to = Carbon::now()->endOfDay();

        switch ($timeframe) {
            case '7':
                $from->subDays(7);
                break;
            case '30':
                $from->subDays(30);
                break;
                // Default to "today" value
            case 'today':
            default:
                break;
        }

        $payments = Payment::with('user')->where('seller_id', auth()->id())
            ->whereBetween('created_at', [$from, $to])
            ->orderBy('created_at', 'desc')
            ->get()
            ->groupBy(function ($item) {
                return $item->created_at->isToday() ? __('Today') : Carbon::parse($item->created_at)->format('d M Y');
            });

        // B64 Encode the takeaseat logo so we embed the image
        $headerLogoB64 = base64_encode(file_get_contents(public_path('/images/logo-header.jpg')));
        $footerLogoB64 = base64_encode(file_get_contents(public_path('/images/logo-footer.jpg')));

        $viewData = [
            'payments' => $payments,
            'headerLogo' => $headerLogoB64,
            'footerLogo' => $footerLogoB64,
            'dateRange' => [
                'from' => $from,
                'to' => $to
            ]
        ];

        $pdf = App::make('dompdf.wrapper');
        $pdf->loadView('pdfs.statement', $viewData);

        return $pdf->output();
    }
}

Zerion Mini Shell 1.0