143 lines
4.0 KiB
PHP
143 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 Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
class laporansaleModel extends Model
|
|
{
|
|
protected $primaryKey = 'transaction_id';
|
|
protected $table = 'transfer_transaction';
|
|
public $timestamps = false;
|
|
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Laporan Sale';
|
|
$data['actButton'] = ['edit'];
|
|
$data['tableHead'] =
|
|
array(
|
|
["Transaction Time","all","transaction_time"],
|
|
["Dest Acc No","all","dest_acct_no"],
|
|
["Account No","all","account_number"],
|
|
["Source Name","none","source_name"],
|
|
["Dest Name","none","dest_name"],
|
|
["Amount","all","amount"],
|
|
["Service Name","all","service_name"],
|
|
["Username","none","username"],
|
|
["Nomor Kartu","all","card_no"],
|
|
["Status","all","transaction_status_desc"],
|
|
["Response UID","none","response_uid"],
|
|
["Service ID","none","service_id"],
|
|
["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 tt.mid = '".$request->merchant."' ";
|
|
}
|
|
}
|
|
|
|
$dtable = \DB::select("SELECT
|
|
tt.transaction_id,
|
|
tt.transaction_time,
|
|
tt.dest_acct_no,
|
|
tt.account_number,
|
|
tt.source_name,
|
|
tt.dest_name,
|
|
tt.amount,
|
|
service_name,
|
|
username,
|
|
tt.card_no,
|
|
transaction_status_desc,
|
|
r.response_uid ,
|
|
r.service_id ,
|
|
r.msg,
|
|
bank_name,
|
|
(case
|
|
when r.msg isnull then (
|
|
select
|
|
msg
|
|
from
|
|
responsecode
|
|
where
|
|
service_id = '0'
|
|
and response_uid = tt.rc_sw
|
|
and lang = 'in')
|
|
else r.msg
|
|
end ) as keterangan
|
|
from
|
|
transfer_transaction tt
|
|
left join service on
|
|
tt.service_id = service.service_id
|
|
left join users on
|
|
tt.user_uid = users.user_uid
|
|
left join reff_transaction_status on
|
|
tt.transaction_status_id = reff_transaction_status.transaction_status_id
|
|
left join responsecode r on
|
|
r.response_uid = tt.rc_sw
|
|
and r.service_id = tt.service_id
|
|
and r.lang = 'in'
|
|
left join reff_bank rb on
|
|
rb.bank_code = tt.bank_code
|
|
where service.service_group in ('sale')
|
|
and 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);
|
|
});
|
|
$dt->editColumn('amount',function($data) {
|
|
return number_format($data->amount,0,",",".");
|
|
});
|
|
|
|
return $dt;
|
|
}
|
|
|
|
}
|