perubahan datatable part 3
This commit is contained in:
parent
68860ef77d
commit
ad36cc126f
@ -2,24 +2,25 @@
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use App\Models\TransactionDescription;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\TransactionUser;
|
||||
use App\Models\User;
|
||||
use Throwable;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\User;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\TransactionUser;
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\TransactionDescription;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Stichoza\GoogleTranslate\GoogleTranslate;
|
||||
use Throwable;
|
||||
|
||||
class UserTransactionController extends Controller
|
||||
{
|
||||
@ -822,7 +823,48 @@ class UserTransactionController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function listTransaction(Request $request){
|
||||
public function listPembeli(Request $request)
|
||||
{
|
||||
$subQuery = transaction::join('transactions', 'refunds.total', '=', 'transactions.id')
|
||||
->select('transactions.id', 'transactions.penjual as penjual', 'transactions.nama_barang as nama_barang', 'refunds.total as total', 'transactions.tanggal_transaksi', 'refunds.due_date as date', 'transactions.status_transaksi as status');
|
||||
|
||||
if($request->has('search') && !empty($request->search['value'])){
|
||||
$searchPembeli = $request->search['value'];
|
||||
$subQuery->where(function($a) use ($searchPembeli){
|
||||
$a->whereRaw('LOWER(transactions.penjual) LIKE ?',['%'.strtolower($searchPembeli).'%'])
|
||||
->orWhereRaw('LOWER(transactions.nama_barang) LIKE ?',['%'.strtolower($searchPembeli).'%']);
|
||||
});
|
||||
}
|
||||
|
||||
$queryPembeli = Contact::from(DB::raw("({$subQuery->toSql()}) as tmp"))
|
||||
->mergeBindings($subQuery->getQuery()) // Menggabungkan binding parameters
|
||||
->select('*')
|
||||
->get();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return DataTables::of($queryPembeli)
|
||||
->addIndexColumn()
|
||||
->addColumn('aksi', function ($row) {
|
||||
$url = route('user-pembeli.show', ['id' => $row->id]);
|
||||
$html_code = '
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
....
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="'.$url.'">Detail</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>';
|
||||
return $html_code;
|
||||
})
|
||||
->rawColumns(['aksi'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" id="table-3">
|
||||
<table class="table table-striped" id="table-pembeli">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">
|
||||
@ -45,78 +45,6 @@
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($transactions as $transaction)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $transaction->data_penjual->nama_depan . ' ' . $transaction->data_penjual->nama_belakang }}
|
||||
</td>
|
||||
<td>{{ $transaction->nama_barang }}</td>
|
||||
<td>Rp {{ number_format($transaction->total_bayar, 2, ',', '.') }}</td>
|
||||
<td>{{ $transaction->created_at }}</td>
|
||||
<td>{{ $transaction->updated_at }}</td>
|
||||
<td><a href="#" data-toggle="modal"
|
||||
data-target="#modalKeteranganStatus"
|
||||
class="badge {{ in_array($transaction->status_transaksi, ['created'])
|
||||
? 'badge-light'
|
||||
: (in_array($transaction->status_transaksi, ['success', 'challenge'])
|
||||
? 'badge-info'
|
||||
: (in_array($transaction->status_transaksi, ['process', 'sending', 'sent'])
|
||||
? 'badge-warning'
|
||||
: (in_array($transaction->status_transaksi, ['cancel', 'failure', 'refund'])
|
||||
? 'badge-danger'
|
||||
: ($transaction->status_transaksi == 'finished'
|
||||
? 'badge-success'
|
||||
: 'badge-dark')))) }}">{{ ucwords($transaction->status_transaksi) }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
...
|
||||
</button>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item"
|
||||
href="{{ route('user-pembeli.show', $transaction->id) }}">Detail</a>
|
||||
</li>
|
||||
|
||||
{{-- di midtrans statusnya settlement --}}
|
||||
@if ($transaction->status_transaksi == 'sent')
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalFinish" id="tracking"
|
||||
data-id="{{ $transaction->id }}"
|
||||
href="#">Selesaikan</a>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@if ($transaction->status_transaksi == 'created')
|
||||
<li><a class="dropdown-item" id="bayar"
|
||||
data-id="{{ $transaction->id }}"
|
||||
data-token="{{ $transaction->token }}"
|
||||
href="#">Bayar</a>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@if (in_array($transaction->status_transaksi, ['created', 'challenge']))
|
||||
<li><a href="#" data-id="{{ $transaction->id }}"
|
||||
id="cancel" class="dropdown-item">Batal</a></li>
|
||||
@endif
|
||||
|
||||
@if (!$transaction->transactionDescription->isEmpty())
|
||||
<li><a class="dropdown-item" data-toggle="modal"
|
||||
data-target="#modalTracking"
|
||||
data-transaction="{{ $transaction->transactionDescription }}">Tracking</a>
|
||||
</li>
|
||||
@endif
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@ -134,7 +62,88 @@
|
||||
data-client-key="SB-Mid-client-lEMALcmIPviksRRe"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
let listPembeli = $('#table-pembeli').DataTable({});
|
||||
let listPembeli = $('#table-pembeli').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: "{{ route('user-pembeli.list-pembeli') }}",
|
||||
columns: [{
|
||||
data: 'DT_RowIndex',
|
||||
name: 'DT_RowIndex',
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
className: 'text-center'
|
||||
},
|
||||
{
|
||||
data: 'id',
|
||||
name: 'id',
|
||||
orderable: false,
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
data: 'penjual',
|
||||
name: 'penjual',
|
||||
},
|
||||
{
|
||||
data: 'nama_barang',
|
||||
name: 'nama_barang'
|
||||
},
|
||||
{
|
||||
data: 'total',
|
||||
name: 'total'
|
||||
},
|
||||
{
|
||||
data: 'tanggal_transaksi',
|
||||
name: 'tanggal_transaksi',
|
||||
render: function(data, type, row) {
|
||||
if (type == 'display') {
|
||||
var date = new Date(data);
|
||||
var formattedDate = date.toLocaleDateString('en-US', {
|
||||
year: '2-digit',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
return formattedDate;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'tanggal_update',
|
||||
name: 'tanggal_update',
|
||||
render: function(data, type, row) {
|
||||
if (type == 'display') {
|
||||
var date = new Date(data);
|
||||
var formattedDate = date.toLocaleDateString('en-US', {
|
||||
year: '2-digit',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
return formattedDate;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
},
|
||||
{
|
||||
data: null,
|
||||
render: function(data, type, row) {
|
||||
if (row.status == 'partial refund') {
|
||||
return `<a href="#" data-toggle="modal" data-target="#modalKeteranganStatus" class="badge badge-success">${row.status}</a>`;
|
||||
}else if (row.status == 'pending') {
|
||||
return `<a href="#" data-toggle="modal" data-target="#modalKeteranganStatus" class="badge badge-warning">${row.status}</a>`;
|
||||
}else {
|
||||
return `<a href="#" data-toggle="modal" data-target="#modalKeteranganStatus" class="badge badge-danger">${row.status}</a>`;
|
||||
}
|
||||
},
|
||||
orderable: true,
|
||||
searchable: true
|
||||
},
|
||||
{
|
||||
data: 'aksi',
|
||||
name: 'aksi',
|
||||
orderable: false,
|
||||
searchable: false
|
||||
}],
|
||||
});
|
||||
|
||||
// Bayar
|
||||
$('#table-3').on('click', '#bayar', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user