129 lines
4.0 KiB
PHP
129 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Datatables, DB;
|
|
use Exception;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Yajra\DataTables\DataTables as DT;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Http\Controllers\Controller;
|
|
use Auth;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
class transactionModel extends Model
|
|
{
|
|
protected $primaryKey = 'payment_id';
|
|
protected $table = 'payment';
|
|
public $timestamps = false;
|
|
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Transaction';
|
|
$data['actButton'] = [];
|
|
$data['tableHead'] =
|
|
array(
|
|
["Merchant","all","merchant_nm"],
|
|
["Time","all","crtdt"],
|
|
["Staff","all","user_nm"],
|
|
["Pay Amount","all","pay_amount"],
|
|
["Payment Type","all","payment_type_nm"],
|
|
["Card Number","all","card_no"],
|
|
["Customer","all","customer_nm"],
|
|
["Change Amount","all","change_amount"],
|
|
["Total Amount","all","total_amount"],
|
|
["Payment Status","all","payment_status_nm"]
|
|
);
|
|
|
|
$data['db'] = $this->table;
|
|
$data['db_key'] = $this->primaryKey;
|
|
$data['route'] = $route;
|
|
|
|
$cGlobal = new Controller();
|
|
|
|
if ($request->startDate) {
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
}else{
|
|
$startDate = date('Y-m-d').' 00:00:00';
|
|
$endDate = date('Y-m-d').' 24:00:00';
|
|
|
|
}
|
|
|
|
|
|
$dtable = DB::table("payment")
|
|
->leftJoin("users", function($join){
|
|
$join->on("users.user_id", "=", "payment.user_id");
|
|
})
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("merchant.mid", "=", "users.mid");
|
|
})
|
|
->leftJoin("reff_payment_type", function($join){
|
|
$join->on("reff_payment_type.payment_type_id", "=", "payment.payment_type_id");
|
|
})
|
|
->leftJoin("customer", function($join){
|
|
$join->on("customer.customer_id", "=", "payment.customer_id");
|
|
})
|
|
->leftJoin("reff_payment_status", function($join){
|
|
$join->on("reff_payment_status.payment_status_id", "=", "payment.payment_status_id");
|
|
})
|
|
->select("payment.*", "reff_payment_type.*", "merchant_nm", "reff_payment_status.payment_status_nm", "users.user_nm", "payment.outlet_id", "customer.customer_nm")
|
|
->where("payment.crtdt", ">=", $startDate)
|
|
->where("payment.crtdt", "<=", $endDate)
|
|
->when(request('merchant_filter') != null, function ($query) use ($request) {
|
|
if ($request->merchant_filter != 'all') {
|
|
$query->where('users.mid', $request->merchant_filter);
|
|
}
|
|
})
|
|
->when(Auth::guard('admin')->user()->role == 3, function ($query) use ($request) {
|
|
$query->where('merchant.city_id', Auth::guard('admin')->user()->id_kota);
|
|
})
|
|
->get();
|
|
|
|
|
|
|
|
// LIST DATA TABLE
|
|
$data['data_table'] = $dtable;
|
|
|
|
// FORM FIELD FOR STORE
|
|
$data['set_field'] = [
|
|
|
|
];
|
|
|
|
foreach($data['tableHead'] as $v){
|
|
$arrHead[] = $v[2];
|
|
}
|
|
$data['head'] = implode(",",$arrHead);
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getDT($data,$init)
|
|
{
|
|
$dt = DT::of($data);
|
|
|
|
$dt->editColumn('crtdt',function($data) {
|
|
return date('d-m-Y H:i:s',strtotime($data->crtdt));
|
|
});
|
|
|
|
$dt->editColumn('pay_amount',function($data) {
|
|
return number_format($data->pay_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('change_amount',function($data) {
|
|
return number_format($data->change_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('total_amount',function($data) {
|
|
return number_format($data->total_amount,0,",",".");
|
|
});
|
|
return $dt;
|
|
}
|
|
|
|
}
|