mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-11-03 22:13:18 -05:00 
			
		
		
		
	* Create PHP CS Fixer config and add to CI workflow * Run php cs fixer on project * Add newline at end of file * Update to use PHP CS Fixer v3 * Run v3 config on project * Run seperate config in CI
		
			
				
	
	
		
			97 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Crater\Http\Controllers\V1\Payment;
 | 
						|
 | 
						|
use Crater\Http\Controllers\Controller;
 | 
						|
use Crater\Http\Requests\DeletePaymentsRequest;
 | 
						|
use Crater\Http\Requests\PaymentRequest;
 | 
						|
use Crater\Models\Payment;
 | 
						|
use Illuminate\Http\Request;
 | 
						|
 | 
						|
class PaymentsController extends Controller
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Display a listing of the resource.
 | 
						|
     *
 | 
						|
     * @return \Illuminate\Http\Response
 | 
						|
     */
 | 
						|
    public function index(Request $request)
 | 
						|
    {
 | 
						|
        $limit = $request->has('limit') ? $request->limit : 10;
 | 
						|
 | 
						|
        $payments = Payment::with(['user', 'invoice', 'paymentMethod', 'creator'])
 | 
						|
            ->join('users', 'users.id', '=', 'payments.user_id')
 | 
						|
            ->leftJoin('invoices', 'invoices.id', '=', 'payments.invoice_id')
 | 
						|
            ->leftJoin('payment_methods', 'payment_methods.id', '=', 'payments.payment_method_id')
 | 
						|
            ->applyFilters($request->only([
 | 
						|
                'search',
 | 
						|
                'payment_number',
 | 
						|
                'payment_id',
 | 
						|
                'payment_method_id',
 | 
						|
                'customer_id',
 | 
						|
                'orderByField',
 | 
						|
                'orderBy',
 | 
						|
            ]))
 | 
						|
            ->whereCompany($request->header('company'))
 | 
						|
            ->select('payments.*', 'users.name', 'invoices.invoice_number', 'payment_methods.name as payment_mode')
 | 
						|
            ->latest()
 | 
						|
            ->paginateData($limit);
 | 
						|
 | 
						|
        return response()->json([
 | 
						|
            'payments' => $payments,
 | 
						|
            'paymentTotalCount' => Payment::count(),
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Store a newly created resource in storage.
 | 
						|
     *
 | 
						|
     * @param  \Illuminate\Http\Request  $request
 | 
						|
     * @return \Illuminate\Http\Response
 | 
						|
     */
 | 
						|
    public function store(PaymentRequest $request)
 | 
						|
    {
 | 
						|
        $payment = Payment::createPayment($request);
 | 
						|
 | 
						|
        return response()->json([
 | 
						|
            'payment' => $payment,
 | 
						|
            'success' => true,
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function show(Request $request, Payment $payment)
 | 
						|
    {
 | 
						|
        $payment->load([
 | 
						|
            'user',
 | 
						|
            'invoice',
 | 
						|
            'paymentMethod',
 | 
						|
            'fields.customField',
 | 
						|
        ]);
 | 
						|
 | 
						|
        return response()->json([
 | 
						|
            'nextPaymentNumber' => $payment->getPaymentNumAttribute(),
 | 
						|
            'payment_prefix' => $payment->getPaymentPrefixAttribute(),
 | 
						|
            'payment' => $payment,
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function update(PaymentRequest $request, Payment $payment)
 | 
						|
    {
 | 
						|
        $payment = $payment->updatePayment($request);
 | 
						|
 | 
						|
        return response()->json([
 | 
						|
            'payment' => $payment,
 | 
						|
            'success' => true,
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function delete(DeletePaymentsRequest $request)
 | 
						|
    {
 | 
						|
        Payment::deletePayments($request->ids);
 | 
						|
 | 
						|
        return response()->json([
 | 
						|
            'success' => true,
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
}
 |