366 lines
14 KiB
PHP
366 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\Str;
|
|
|
|
// additional modul
|
|
use App\Enums\GlobalEnum;
|
|
use DataTables;
|
|
|
|
// model binding
|
|
use Modules\Seller\Entities\ProductBuzzer;
|
|
use Modules\Seller\Entities\ProductBuzzerServices;
|
|
use Modules\Seller\Entities\ProductBuzzerOrder;
|
|
|
|
class BuzzerController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = ProductBuzzerOrder::select('*');
|
|
// Convert the Eloquent Collection to a regular PHP array
|
|
$data->each(function ($item, $key) {
|
|
$item->rowIndex = $key + 1;
|
|
});
|
|
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('ticket-invoice', function($row){
|
|
$text = '
|
|
<p class="fw-bold mb-0">#' . strtoupper(explode('-', $row->id)[0]) . '</p>
|
|
';
|
|
return $text;
|
|
})
|
|
->addColumn('title-post', function($row){
|
|
$text = '
|
|
<p class="mb-0">' . $row->subject . '</p>
|
|
<p class="mb-0 small">Terakhir diperbarui pada ' . $row->updated_at . '</p>
|
|
';
|
|
return $text;
|
|
})
|
|
->addColumn('sender', function($row){
|
|
return '
|
|
<div class="d-flex align-items-center">
|
|
<div class="symbol symbol-25px symbol-circle">
|
|
<div class="symbol-label" style="background-image:url(' . gravatar_team($row->user->email) . ')"></div>
|
|
</div>
|
|
<div class="ms-3"><span>' . $row->user->name . '</span></div>
|
|
</div>
|
|
';
|
|
})
|
|
->addColumn('action', function($row){
|
|
$view = route('ticket.view', ['id' => $row->id]);
|
|
$delete = route('ticket.delete', ['id' => $row->id]);
|
|
$btn = '
|
|
<a href="' . $view . '" class="btn btn-light btn-sm px-4"><i class="ki-outline ki-eye"></i></a>
|
|
<a data-url="' . $delete . '" href="#" class="btn btn-light btn-sm deleteContent px-4"><i class="ki-outline ki-trash"></i></a>
|
|
';
|
|
return $btn;
|
|
})
|
|
->addColumn('status', function($row){
|
|
if ($row->is_status == GlobalEnum::isTicketSellerPending) {
|
|
return '<span class="mb-1 badge font-medium bg-light-dark text-dark py-3 px-4 fs-7">Pending</span>';
|
|
} elseif($row->is_status == GlobalEnum::isTicketAdminReplied) {
|
|
return '<span class="mb-1 badge font-medium bg-light-primary text-primary py-3 px-4 fs-7">Admin Membalas</span>';
|
|
} elseif($row->is_status == GlobalEnum::isTicketSellerClosed) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger py-3 px-4 fs-7">Ditutup</span>';
|
|
} elseif($row->is_status == GlobalEnum::isTicketUserReplied) {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info py-3 px-4 fs-7">User Membalas</span>';
|
|
}
|
|
})
|
|
->addColumn('priority', function($row){
|
|
if ($row->is_priority == GlobalEnum::isTicketPriorityNormal) {
|
|
return '<span class="mb-1 badge font-medium bg-light-info text-info py-3 px-4 fs-7">Normal</span>';
|
|
} elseif($row->is_priority == GlobalEnum::isTicketPriorityMedium) {
|
|
return '<span class="mb-1 badge font-medium bg-light-primary text-primary py-3 px-4 fs-7">Medium</span>';
|
|
} elseif($row->is_priority == GlobalEnum::isTicketPriorityHigh) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger py-3 px-4 fs-7">Tinggi</span>';
|
|
}
|
|
})
|
|
->rawColumns(['ticket-invoice','title-post','action','status','priority','sender'])
|
|
->filter(function ($query) use ($request) {
|
|
if ($request->has('search')) {
|
|
$search = $request->get('search')['value'];
|
|
// Apply your search logic here.
|
|
$query->where('id', 'LIKE', "%$search%");
|
|
}
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Advertiser'
|
|
];
|
|
|
|
return view('admin.app.ticket.index', compact('data'));
|
|
}
|
|
|
|
public function view($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Ticket #' . explode('-', $id)[0],
|
|
];
|
|
|
|
$ticketResponse = TicketModel::find($id)->responses;
|
|
return view('admin.app.ticket.detail', compact('data', 'ticketResponse'));
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'message' => 'required',
|
|
]);
|
|
|
|
if($validator->fails()) {
|
|
return redirect()->back()->withErrors($validator->errors());
|
|
}
|
|
|
|
$input = $request->all();
|
|
$ticket = TicketModel::find($id);
|
|
if($ticket) {
|
|
$post = new TicketResponseModel([
|
|
'id' => Str::uuid(),
|
|
'id_ticket' => $id,
|
|
'user_id' => auth()->user()->id,
|
|
'message' => $input['message']
|
|
]);
|
|
|
|
$ticket->is_status = 3;
|
|
if($post->save() && $ticket->save()) {
|
|
return redirect()->route('ticket.view', ['id' => $id])->with('swal', swal_alert('success', 'Anda berhasil membalas tiket.'));
|
|
} else {
|
|
return redirect()->route('ticket.view', ['id' => $id])->with('swal', swal_alert('error', 'Terjadi kesalahan saat membalas tiket.'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function services(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = ProductBuzzerServices::select('*')->orderBy('id', 'desc');
|
|
// Convert the Eloquent Collection to a regular PHP array
|
|
$data->each(function ($item, $key) {
|
|
$item->rowIndex = $key + 1;
|
|
});
|
|
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('title-post', function($row){
|
|
$text = '
|
|
<p class="mb-0">' . $row->name . '</p>
|
|
<p class="mb-0 small">Terakhir diperbarui pada ' . date_formatting($row->updated_at, 'timeago') . '</p>
|
|
';
|
|
return $text;
|
|
})
|
|
->addColumn('price', function($row){
|
|
return 'Rp. ' . number_format($row->is_buzzer_get, 0, ',', '.');
|
|
})
|
|
->addColumn('status', function($row){
|
|
if ($row->is_status == GlobalEnum::isServiceActive) {
|
|
return '<span class="mb-1 badge font-medium bg-light-success text-success py-3 px-4 fs-7">Aktif</span>';
|
|
} elseif($row->is_status == GlobalEnum::isServiceNotActive) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger py-3 px-4 fs-7">Tidak Aktif</span>';
|
|
}
|
|
})
|
|
->rawColumns(['title-post','status','price'])
|
|
->filter(function ($query) use ($request) {
|
|
if ($request->has('search')) {
|
|
$search = $request->get('search')['value'];
|
|
// Apply your search logic here.
|
|
$query->where('id', 'LIKE', "%$search%");
|
|
}
|
|
})
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Layanan'
|
|
];
|
|
|
|
return view('admin.app.advertiser.services.index', compact('data'));
|
|
}
|
|
|
|
public function editService($id)
|
|
{
|
|
$services = ProductBuzzerServices::find($id);
|
|
|
|
if (!$services) {
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('error', 'Data tidak ditemukan'));
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Edit Layanan',
|
|
];
|
|
|
|
return view('admin.app.advertiser.services.edit', compact('data', 'id', 'services')); // Pass the $id to the view
|
|
}
|
|
|
|
public function updateService(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'is_status' => 'required',
|
|
'is_buzzer_get' => 'required'
|
|
]);
|
|
|
|
// Check if a tag with the same id exists
|
|
$services = ProductBuzzerServices::find($id);
|
|
|
|
if (!$services) {
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('error', 'Data tidak ditemukan'));
|
|
}
|
|
|
|
$services->name = $request->input('name');
|
|
$services->is_status = $request->input('is_status');
|
|
$services->is_buzzer_get = $request->input('is_buzzer_get');
|
|
|
|
if ($services->save()) {
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('success', 'Data berhasil diperbarui'));
|
|
} else {
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('success', 'Terjadi kesalahan tidak diduga [2]'));
|
|
}
|
|
}
|
|
|
|
// categories
|
|
public function product(Request $request, $id)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = ProductBuzzer::where('id_services', $id)->select('*');
|
|
// Convert the Eloquent Collection to a regular PHP array
|
|
$data->each(function ($item, $key) {
|
|
$item->rowIndex = $key + 1;
|
|
});
|
|
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('icon', function($row){
|
|
return '
|
|
<div class="">
|
|
<div class="symbol symbol-25px symbol-circle">
|
|
<div class="symbol-label" style="background-image:url(' . $row->icon . ')"></div>
|
|
</div>
|
|
</div>
|
|
';
|
|
})
|
|
->addColumn('status', function($row){
|
|
if ($row->is_active == GlobalEnum::isServiceActive) {
|
|
return '<span class="mb-1 badge font-medium bg-light-success text-success py-3 px-4 fs-7">Aktif</span>';
|
|
} elseif($row->is_active == GlobalEnum::isServiceNotActive) {
|
|
return '<span class="mb-1 badge font-medium bg-light-danger text-danger py-3 px-4 fs-7">Tidak Aktif</span>';
|
|
}
|
|
})
|
|
->rawColumns(['icon', 'status'])
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Produk',
|
|
'button' => true,
|
|
'module' => [
|
|
'url' => route('buzzer.product.create', $id),
|
|
'name' => 'Tambah baru'
|
|
]
|
|
];
|
|
|
|
return view('admin.app.advertiser.product.index', compact('data', 'id'));
|
|
}
|
|
|
|
public function addProduct($id)
|
|
{
|
|
$data = [
|
|
'subtitle' => 'Tambah Produk',
|
|
];
|
|
|
|
return view('admin.app.advertiser.product.add', compact('data', 'id'));
|
|
}
|
|
|
|
public function editProduct($code, $id)
|
|
{
|
|
$product = ProductBuzzer::find($id);
|
|
|
|
if (!$product) {
|
|
return redirect()->route('buzzer.product')->with('swal', swal_alert('error', 'Produk tidak ditemukan.'));
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Edit Produk',
|
|
];
|
|
|
|
return view('admin.app.advertiser.product.edit', compact('data', 'code', 'id', 'product')); // Pass the $id to the view
|
|
}
|
|
|
|
public function storeProduct(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'icon' => 'required',
|
|
'is_active' => 'required'
|
|
]);
|
|
|
|
// Check if a tag with the same name already exists
|
|
$product = ProductBuzzer::where('name', $request->input('name'))->where('id_services', $id)->first();
|
|
|
|
if ($product) {
|
|
return redirect()->back()->withInput()->with('swal', swal_alert('error', 'Ditemukan produk yang sama, ulangi kembali!'));
|
|
}
|
|
|
|
$product = new ProductBuzzer([
|
|
'id' => Str::uuid(),
|
|
'name' => $request->input('name'),
|
|
'id_services' => $id,
|
|
'icon' => $request->input('icon'),
|
|
'is_active' => $request->input('is_active')
|
|
]);
|
|
|
|
if ($product->save()) {
|
|
return redirect()->route('buzzer.product', $id)->with('swal', swal_alert('success', 'Data berhasil ditambahkan'));
|
|
} else {
|
|
return redirect()->route('buzzer.product', $id)->with('swal', swal_alert('error', 'Terjadi kesalahan tidak diduga'));
|
|
}
|
|
}
|
|
|
|
public function updateProduct(Request $request, $code, $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'icon' => 'required',
|
|
'is_active' => 'required'
|
|
]);
|
|
|
|
// Check if a tag with the same id exists
|
|
$product = ProductBuzzer::where('name', $request->input('name'))->first();
|
|
|
|
if (!$product) {
|
|
return redirect()->back()->withInput()->with('swal', swal_alert('error', 'Ditemukan produk yang sama, ulangi kembali!'));
|
|
}
|
|
|
|
$product->name = $request->input('name');
|
|
$product->icon = $request->input('icon');
|
|
$product->is_active = $request->input('is_active');
|
|
|
|
if ($product->save()) {
|
|
return redirect()->route('buzzer.product', $code)->with('swal', swal_alert('success', 'Data berhasil diperbarui'));
|
|
} else {
|
|
return redirect()->route('buzzer.product', $code)->with('swal', swal_alert('success', 'Terjadi kesalahan tidak diduga'));
|
|
}
|
|
}
|
|
|
|
public function deleteProduct($id)
|
|
{
|
|
$product = ProductBuzzer::find($id);
|
|
|
|
if ($product) {
|
|
$product->delete();
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('success', 'Data berhasil dihapus'));
|
|
} else {
|
|
return redirect()->route('buzzer.services')->with('swal', swal_alert('success', 'Terjadi kesalahan tidak diduga'));
|
|
}
|
|
}
|
|
}
|