136 lines
4.1 KiB
PHP
136 lines
4.1 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 billingModel extends Model
|
|
{
|
|
protected $primaryKey = 'bill_id';
|
|
protected $table = 'bill';
|
|
public $timestamps = false;
|
|
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Billing';
|
|
$data['actButton'] = [];
|
|
$data['tableHead'] =
|
|
array(
|
|
["Company","all","merchant_nm"],
|
|
["Time","all","crtdt"],
|
|
["Staff","all","user_nm"],
|
|
["Amount","all","bill_amount"],
|
|
["Tax","all","tax_amount"],
|
|
["Service Percentage","all","charge_service_prs"],
|
|
["Charge Amount","all","charge_amount"],
|
|
["Total Amount","all","total_amount"],
|
|
["Billing Code","none","bill_code"],
|
|
["Promo Voucher","none","promo_code"],
|
|
["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("bill")
|
|
->join("users", function($join){
|
|
$join->on("users.user_id", "=", "bill.user_id");
|
|
})
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("merchant.mid", "=", "users.mid");
|
|
})
|
|
->leftJoin("promo_voucher", function($join){
|
|
$join->on("promo_voucher.promo_voucher_id", "=", "bill.promo_voucher_id");
|
|
})
|
|
->join("reff_payment_status", function($join){
|
|
$join->on("reff_payment_status.payment_status_id", "=", "bill.payment_status_id");
|
|
})
|
|
->select("bill.*", "promo_voucher.promo_code", "reff_payment_status.payment_status_nm", "users.user_nm", "users.outlet_id", "merchant_nm")
|
|
->where("bill.crtdt", ">=", $startDate)
|
|
->where("bill.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('bill_amount',function($data) {
|
|
return number_format($data->bill_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('tax_amount',function($data) {
|
|
return number_format($data->tax_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('charge_amount',function($data) {
|
|
return number_format($data->charge_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('total_amount',function($data) {
|
|
return number_format($data->total_amount,0,",",".");
|
|
});
|
|
|
|
$dt->editColumn('charge_service_prs',function($data) {
|
|
return number_format($data->charge_service_prs,0,",",".")."%";
|
|
});
|
|
|
|
return $dt;
|
|
}
|
|
|
|
}
|