106 lines
3.2 KiB
PHP
106 lines
3.2 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 deviceModel extends Model
|
||
|
{
|
||
|
protected $primaryKey = 'device_id';
|
||
|
protected $table = 'device';
|
||
|
public $timestamps = false;
|
||
|
|
||
|
protected $fillable = [
|
||
|
'device_id','sn', 'imei', 'brand', 'model', 'tid','mid',
|
||
|
];
|
||
|
|
||
|
public function initData($request,$route)
|
||
|
{
|
||
|
// INIT DB
|
||
|
$data['title'] = 'EDC Device';
|
||
|
$data['actButton'] = ['edit'];
|
||
|
$data['tableHead'] =
|
||
|
array(
|
||
|
["ID","all","device_id"],
|
||
|
["Serial Number","all","sn"],
|
||
|
["IMEI","all","imei"],
|
||
|
["Brand","all","name_brand"],
|
||
|
["Model","all","model"],
|
||
|
["Terminal ID","all","tid"],
|
||
|
["Merchant Name","all","merchant_nm"],
|
||
|
["Outlet Name","all","outlet_nm"],
|
||
|
["Act","all","action"]
|
||
|
);
|
||
|
|
||
|
|
||
|
$data['db'] = $this->table;
|
||
|
$data['db_key'] = $this->primaryKey;
|
||
|
$data['route'] = $route;
|
||
|
|
||
|
$dtable = DB::table("device")
|
||
|
->leftJoin("reff_brand", function($join){
|
||
|
$join->on("reff_brand.id_brand", "=", "device.brand");
|
||
|
})
|
||
|
->leftJoin("merchant", function($join){
|
||
|
$join->on("merchant.mid", "=", "device.mid");
|
||
|
})
|
||
|
->leftJoin("outlet", function($join){
|
||
|
$join->on("outlet.outlet_id", "=", "device.outlet_id");
|
||
|
})
|
||
|
->orderBy("device_id","desc")
|
||
|
->when(request('merchant') != null, function ($query) use ($request) {
|
||
|
if ($request->merchant != 'all') {
|
||
|
$query->where('device.mid', $request->merchant);
|
||
|
}
|
||
|
})
|
||
|
->get();
|
||
|
|
||
|
|
||
|
|
||
|
// LIST DATA TABLE
|
||
|
$data['data_table'] = $dtable;
|
||
|
|
||
|
$cGlobal = new Controller();
|
||
|
|
||
|
// FORM FIELD FOR STORE
|
||
|
$data['set_field'] = [
|
||
|
'sn' => $cGlobal->cleanString($request->post('sn')),
|
||
|
'imei' => $cGlobal->cleanString($request->post('imei')),
|
||
|
'brand' => $request->post('brand'),
|
||
|
'model' => $cGlobal->cleanString($request->post('model')),
|
||
|
'tid' => $cGlobal->cleanString($request->post('tid')),
|
||
|
'mid' => $request->post('mid')
|
||
|
];
|
||
|
|
||
|
// GET DATA FOR EDIT
|
||
|
if ($request->post('id')) {
|
||
|
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM device where device_id = ?",[$request->post('id')]))->first();
|
||
|
}
|
||
|
|
||
|
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('is_active',function($data) {
|
||
|
// return ($data->is_active == true) ? '<span class="label label-success label-inline mr-2">Active</span>':'<span class="label label-danger label-inline mr-2">Non-Active</span>';
|
||
|
// });
|
||
|
|
||
|
return $dt;
|
||
|
}
|
||
|
|
||
|
}
|