141 lines
3.8 KiB
PHP
141 lines
3.8 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 Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
class purchaseModel extends Model
|
|
{
|
|
protected $primaryKey = 'transaction_id';
|
|
protected $table = 'payment_pln_transaction';
|
|
public $timestamps = false;
|
|
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Laporan Purchase';
|
|
$data['actButton'] = ['edit'];
|
|
$data['tableHead'] =
|
|
array(
|
|
["Purchase Time","all","transaction_time"],
|
|
["Merchant ID","all","mid"],
|
|
["Amount","all","amount"],
|
|
["Fee","all","fee"],
|
|
["Account No","all","account_number"],
|
|
["IdPel","all","phone_no"],
|
|
["Product Group Name","all","product_group_name"],
|
|
["No Resi","all","no_resi"],
|
|
["Terminal ID","all","tid"],
|
|
["Status","all","transaction_status_desc"],
|
|
["Keterangan","all","msg"],
|
|
);
|
|
|
|
$data['db'] = $this->table;
|
|
$data['db_key'] = $this->primaryKey;
|
|
$data['route'] = $route;
|
|
|
|
$cGlobal = new Controller();
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
|
|
$filterMerchant = '';
|
|
|
|
if ($request->merchant != null) {
|
|
if ($request->merchant == 'all') {
|
|
$filterMerchant = '';
|
|
}else{
|
|
$filterMerchant = " and pt.mid = '".$request->merchant."' ";
|
|
}
|
|
}
|
|
|
|
$dtable = \DB::select("SELECT
|
|
pt.*,
|
|
username,
|
|
service_name,
|
|
merchant_nm,
|
|
transaction_status_desc,
|
|
pg.product_group_name,
|
|
(case
|
|
when r.msg isnull then (
|
|
select
|
|
msg
|
|
from
|
|
responsecode
|
|
where
|
|
service_id = '0'
|
|
and response_uid =
|
|
(case
|
|
when pt.rc_biller isnull then pt.rc_sw
|
|
else
|
|
(case
|
|
when pt.rc_biller = '0' then '00'
|
|
else pt.rc_biller
|
|
end)
|
|
end)
|
|
and lang = 'in')
|
|
else r.msg
|
|
end ) as msg
|
|
from
|
|
purchase_transaction pt
|
|
left join users on
|
|
pt.user_uid = users.user_uid
|
|
left join merchant on
|
|
merchant.mid = pt.mid
|
|
left join service on
|
|
pt.service_id = service.service_id
|
|
left join reff_transaction_status on
|
|
pt.transaction_status_id = reff_transaction_status.transaction_status_id
|
|
left join product_group pg on
|
|
pg.product_group_id = pt.product_group_id
|
|
left join responsecode r on
|
|
r.service_id = pt.service_id
|
|
and r.response_uid =
|
|
case
|
|
when pt.rc_biller isnull then pt.rc_sw
|
|
else pt.rc_biller
|
|
end
|
|
and r.lang = 'in'
|
|
where transaction_time >= ? and transaction_time <= ? ".$filterMerchant,[$startDate,$endDate]);
|
|
|
|
// 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('transaction_time',function($data) {
|
|
return date('d-m-Y H:i:s',strtotime($data->transaction_time));
|
|
});
|
|
$dt->editColumn('transaction_id',function($data) {
|
|
return substr($data->transaction_id, 0, 18);
|
|
});
|
|
|
|
return $dt;
|
|
}
|
|
|
|
}
|