<?php

namespace App\Datatables\Admin\Shop;

use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\InvoicePayment;
use App\Repositories\Shop\InvoicePayments;
use Yajra\DataTables\Html\Column;

class InvoicePaymentsDataTable extends DataTable
{
    public $model_name = 'invoice_payments';

    public function __construct()
    {
        $this->url = route('Admin.Shop.InvoicePayments.index');
    }

    public function query(InvoicePayment $model)
    {
        return $this->buildQuery($model);
    }

    public function modifier($datatables)
    {
        $datatables
            ->editColumn('payment_type', function (InvoicePayment $payment) {
                return InvoicePayments::getPaymentType($payment->payment_type);
            })
            ->editColumn('date', function (InvoicePayment $payment) {
                return $payment->date;
            })
            ->rawColumns(['action']);

        return parent::modifier($datatables);
    }

    protected function getColumns()
    {
        return [
            Column::make('payment_type')->title('Type')->width(80),
            Column::make('date')->width(60),
            Column::make('amount')->title('Montant')->width(100),
            Column::make('reference')->title('Référence'),
            $this->makeColumnButtons(),
        ];
    }
}
