88 lines
2.6 KiB
PHP
88 lines
2.6 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 productModel extends Model
|
|
{
|
|
protected $primaryKey = 'id';
|
|
protected $table = 'product';
|
|
public $timestamps = false;
|
|
|
|
public function initData($request,$route)
|
|
{
|
|
// INIT DB
|
|
$data['title'] = 'Product';
|
|
$data['actButton'] = ['edit','active'];
|
|
$data['tableHead'] =
|
|
array(
|
|
// ["Rank","all","rank"],
|
|
["Product ID","all","product_id"],
|
|
["Product Name","all","product_name"],
|
|
["Nominal","all","product_nominal"],
|
|
["Status","all","is_active"],
|
|
["Act","all","action"]
|
|
);
|
|
|
|
|
|
$data['db'] = $this->table;
|
|
$data['db_key'] = $this->primaryKey;
|
|
$data['route'] = $route;
|
|
|
|
$dtable = \DB::select("SELECT * from product order by id desc");
|
|
|
|
// LIST DATA TABLE
|
|
$data['data_table'] = $dtable;
|
|
|
|
$nominal_id = explode(".",$request->post('product_nominal'));
|
|
|
|
$cGlobal = new Controller();
|
|
|
|
|
|
// FORM FIELD FOR STORE
|
|
$data['set_field'] = [
|
|
'product_id' => $request->input('product_group_id').".".$nominal_id[0],
|
|
'product_name' => $request->post('product_name'),
|
|
'product_group_id' => $request->post('product_group_id'),
|
|
'product_nominal' => $cGlobal->clearSeparator($request->product_nominal),
|
|
'rank' => $request->post('rank'),
|
|
'is_active' => $request->post('is_active')
|
|
];
|
|
|
|
// GET DATA FOR EDIT
|
|
if ($request->post('id')) {
|
|
$data['get_data_edit'] = collect(\DB::select("SELECT * FROM product where 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>';
|
|
});
|
|
$dt->editColumn('product_nominal',function($data) {
|
|
return "<div class='text-right'>Rp ".number_format($data->product_nominal,0,",",".")."</div>";
|
|
});
|
|
|
|
return $dt;
|
|
}
|
|
|
|
}
|