151 lines
6.6 KiB
PHP
151 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\DataTables\Restaurant;
|
|
|
|
use App\Services\Restaurant\RestaurantService;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
|
|
use Modules\Authentication\Models\Package;
|
|
use Modules\Authentication\Models\Restaurant;
|
|
use Yajra\DataTables\EloquentDataTable;
|
|
use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
|
use Yajra\DataTables\Html\Column;
|
|
use Yajra\DataTables\Services\DataTable;
|
|
|
|
class RestaurantDataTable extends DataTable
|
|
{
|
|
public function __construct(
|
|
private RestaurantService $service
|
|
) {}
|
|
|
|
public function dataTable(QueryBuilder $query): EloquentDataTable
|
|
{
|
|
return (new EloquentDataTable($query))
|
|
->addIndexColumn()
|
|
->addColumn('action', function (Restaurant $model) {
|
|
$html = '';
|
|
|
|
// Upgrade button
|
|
$html .= '<button type="button" class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm me-1"
|
|
data-bs-toggle="modal" data-bs-target="#upgradeSubscriptionModal'.$model->id.'">
|
|
<i class="bi bi-arrow-up-circle"></i> Upgrade
|
|
</button>';
|
|
|
|
// Upgrade Modal
|
|
$html .= '
|
|
<div class="modal fade" id="upgradeSubscriptionModal'.$model->id.'" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form action="'.route('restaurants.upgradeSubscription', $model->id).'" method="POST">
|
|
'.csrf_field().'
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Upgrade Subscription - '.$model->restaurant_name.'</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<label for="package_id">Select Package</label>
|
|
<select name="package_id" class="form-select" required>
|
|
<option value="">-- Select Package --</option>';
|
|
|
|
$packages = Package::orderByDesc('id')->select('id', 'name', 'price')->get();
|
|
foreach ($packages as $package) {
|
|
$html .= '<option value="'.$package->id.'" data-price="'.$package->price.'">'
|
|
.$package->name.' - '.$package->price.' BDT</option>';
|
|
}
|
|
|
|
$html .= '</select>
|
|
<label for="custom_amount" class="mt-3">Custom Amount (optional)</label>
|
|
<input type="number" name="custom_amount" class="form-control" placeholder="Enter custom amount if any" step="0.01">
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn btn-primary">Upgrade</button>
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
|
|
// Edit button
|
|
$html .= '<a class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm me-1 edit-icon" href="'.route('restaurants.edit', $model->id).'">
|
|
<i class="bi bi-pencil"></i>
|
|
</a>';
|
|
|
|
// Delete button
|
|
$html .= '<button type="button" class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm delete-icon" data-bs-toggle="modal" data-bs-target="#deleteRestaurant'.$model->id.'">
|
|
<i class="bi bi-trash"></i>
|
|
</button>';
|
|
|
|
// Delete Modal
|
|
$html .= '
|
|
<div class="modal fade" id="deleteRestaurant'.$model->id.'" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Are you sure?</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Are you sure you want to delete the Restaurant - <b>'.$model->restaurant_name.'</b>?</p>
|
|
<form action="'.route('restaurants.destroy', $model->id).'" method="POST">
|
|
'.csrf_field().method_field('DELETE').'
|
|
<button type="submit" class="btn btn-danger">Confirm Delete</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
|
|
return $html;
|
|
})
|
|
->addColumn('subscription', function (Restaurant $model) {
|
|
if ($model->subscription) {
|
|
$start = Carbon::parse($model->subscription->start_date)->format('d M Y');
|
|
$end = Carbon::parse($model->subscription->end_date)->format('d M Y');
|
|
|
|
return '<strong>'.$model->subscription->package?->name.'</strong><br>
|
|
<small>Start: '.$start.'</small><br>
|
|
<small>End: '.$end.'</small>';
|
|
}
|
|
|
|
return '<span class="text-muted">No subscription</span>';
|
|
})
|
|
->rawColumns(['subscription', 'action']);
|
|
}
|
|
|
|
public function query(Restaurant $model): QueryBuilder
|
|
{
|
|
return $this->service->get(['is_query' => true]);
|
|
}
|
|
|
|
public function html(): HtmlBuilder
|
|
{
|
|
return $this->builder()
|
|
->setTableId('Restaurant-table')
|
|
->columns($this->getColumns())
|
|
->minifiedAjax()
|
|
->orderBy(1)
|
|
->selectStyleSingle();
|
|
}
|
|
|
|
public function getColumns(): array
|
|
{
|
|
return [
|
|
Column::make('DT_RowIndex')->title('Sl no')->searchable(false)->orderable(false),
|
|
Column::make('name')->title('Owner Name'),
|
|
Column::make('name')->title('Restaurant Name'),
|
|
Column::make('phone')->title('Phone'),
|
|
Column::make('domain')->title('Domain'),
|
|
Column::make('address')->title('Address'),
|
|
Column::make('restaurant_type')->title('Business Type'),
|
|
Column::make('subscription')->title('Subscription')->searchable(false)->orderable(false),
|
|
Column::make('action')->title('Action')->searchable(false)->orderable(false),
|
|
];
|
|
}
|
|
|
|
protected function filename(): string
|
|
{
|
|
return 'Restaurant-'.date('YmdHis');
|
|
}
|
|
}
|