![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/Corals/modules/Medad/DataTables/ |
<?php namespace Corals\Modules\Medad\DataTables; use Corals\Foundation\DataTables\BaseDataTable; use Corals\Modules\Medad\Constants\CompanyTypeConstants; use Corals\Modules\Medad\DataTables\Scopes\AuthUserCompanyDataByProjectScope; use Corals\Modules\Medad\DataTables\Scopes\AuthUserCompanyDataScope; use Corals\Modules\Medad\DataTables\Scopes\CompanyListingScope; use Corals\Modules\Medad\DataTables\Scopes\DeliveryNotesDriverScope; use Corals\Modules\Medad\DataTables\Scopes\DeliveryNotesForPurchaseOrderScope; use Corals\Modules\Medad\DataTables\Scopes\DeliveryNotesUnsignedDriverScope; use Corals\Modules\Medad\Facades\Medad; use Corals\Modules\Medad\Models\DeliveryNote; use Corals\Modules\Medad\Models\PurchaseOrder; use Corals\Modules\Medad\Transformers\DeliveryNoteTransformer; use Yajra\DataTables\EloquentDataTable; class DeliveryNotesDataTable extends BaseDataTable { public function __construct() { if (user()->cannot('admin', DeliveryNote::class)) { $this->addScope(new AuthUserCompanyDataScope('deliveryNote')); } if (user()->hasRole('medad_driver')) { $this->addScope(new DeliveryNotesDriverScope()); } if (user()->hasRole('medad_project_manager')) { $this->addScope(new AuthUserCompanyDataByProjectScope()); } parent::__construct(); } /** * Build DataTable class. * * @param mixed $query Results from query() method. * @return \Yajra\DataTables\DataTableAbstract */ public function dataTable($query) { $this->setResourceUrl(config('medad.models.delivery_note.resource_url')); $dataTable = new EloquentDataTable($query); return $dataTable->setTransformer(new DeliveryNoteTransformer()); } /** * Get query source of dataTable. * @param DeliveryNote $model * @return \Illuminate\Database\Eloquent\Builder|static */ public function query(DeliveryNote $model) { $model = $model->newQuery(); $model = $model->orderByRaw("FIELD(status , 'open', 'draft', 'assigned','started','delivered','received') ASC"); return $model; } /** * Get columns. * * @return array */ protected function getColumns() { return [ 'id' => ['visible' => false], 'code' => ['title' => trans('Medad::attributes.code')], 'notes' => ['title' => trans('Medad::attributes.notes')], 'types_count' => ['title' => trans('Medad::attributes.types_count')], 'total_quantity' => ['title' => trans('Medad::attributes.total_quantity')], 'status' => ['title' => trans('Medad::attributes.status')], 'owner' => ['title' => trans('Medad::attributes.owner')], 'customer' => ['title' => trans('Medad::attributes.customer')], 'supplier' => ['title' => trans('Medad::attributes.supplier')], 'driver' => ['title' => trans('Medad::attributes.driver')], 'recipient_name' => ['title' => trans('Medad::attributes.recipient_name')], 'recipient_phone' => ['title' => trans('Medad::attributes.delivery_note.recipient_phone')], 'recipient_id_number' => ['title' => trans('Medad::attributes.delivery_note.recipient_id_number')], 'items_source' => ['title' => trans('Medad::attributes.items_source')], 'schedule_date' => ['title' => trans('Medad::attributes.schedule_date')], 'started_at' => ['title' => trans('Medad::attributes.started_at')], 'completed_at' => ['title' => trans('Medad::attributes.completed_at')], 'assignment_date' => ['title' => trans('Medad::attributes.assignment_date')], 'purchase_order' => ['title' => trans('Medad::attributes.delivery_note.purchase_order')], 'project' => ['title' => trans('Medad::module.project.title_singular')], 'updated_at' => ['title' => trans('Corals::attributes.updated_at')], ]; } public function getFilters() { return [ 'code' => [ 'title' => trans('Medad::attributes.code'), 'class' => 'col-md-2', 'type' => 'text', 'condition' => 'like', 'active' => true ], 'status' => [ 'title' => trans('Medad::attributes.status'), 'class' => 'col-md-2', 'type' => 'select2', 'options' => trans('Medad::attributes.delivery_note.status_options'), 'function' => 'in', 'active' => true, 'attributes' => [ 'multiple' => true, ], ], 'owner_id' => [ 'title' => trans('Medad::attributes.owner'), 'class' => 'col-md-2', 'type' => 'select2', 'options' => Medad::getCompanyUsers(), 'active' => true ], 'customer_company_id' => [ 'title' => trans('Medad::attributes.branch.customer_company'), 'class' => 'col-md-2', 'type' => 'select2', 'options' => Medad::getCompanies(CompanyTypeConstants::CUSTOMER), 'active' => true ], 'supplier_company_id' => [ 'title' => trans('Medad::attributes.branch.supplier_company'), 'class' => 'col-md-2', 'type' => 'select2', 'options' => Medad::getCompanies(CompanyTypeConstants::SUPPLIER), 'active' => true ], 'driver_id' => [ 'title' => trans('Medad::attributes.driver'), 'class' => 'col-md-2', 'type' => 'select2', 'options' => Medad::getCompanyUsers('medad_driver'), 'active' => true ], 'recipient_name' => [ 'title' => trans('Medad::attributes.recipient_name'), 'class' => 'col-md-2', 'type' => 'text', 'condition' => 'like', 'active' => true ], 'items_source' => [ 'title' => trans('Medad::attributes.items_source'), 'class' => 'col-md-2', 'type' => 'text', 'condition' => 'like', 'active' => true ], 'purchase_order_id' => [ 'title' => trans('Medad::attributes.delivery_note.purchase_order'), 'class' => 'col-md-2', 'type' => 'select2-ajax', 'model' => PurchaseOrder::class, 'columns' => ['code'], 'attributes' => [ 'data' => [ 'scopes' => json_encode([CompanyListingScope::class]) ], ], 'active' => true ], 'driver_unsigned' => [ 'title' => trans('Medad::attributes.driver_unsigned'), 'type' => 'boolean', 'active' => true, 'builder' => DeliveryNotesUnsignedDriverScope::class, ], 'po_code' => [ 'title' => trans('Medad::attributes.delivery_note.purchase_order'), 'class' => 'col-md-2', 'type' => 'text', 'builder' => DeliveryNotesForPurchaseOrderScope::class, 'active' => false, ], 'project_id' => [ 'title' => 'project', 'type' => 'number', 'active' => false, ] ]; } }