106 lines
4.8 KiB
PHP
106 lines
4.8 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelDaftarHarga extends CI_Model {
|
|
public function create($table, $data, $batch = false)
|
|
{
|
|
if($batch === false){
|
|
$insert = $this->db->insert($table, $data);
|
|
}else{
|
|
$insert = $this->db->insert_batch($table, $data);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function update($table, $data, $pk, $id = null, $batch = false)
|
|
{
|
|
if($batch === false){
|
|
$insert = $this->db->update($table, $data, array($pk => $id));
|
|
}else{
|
|
$insert = $this->db->update_batch($table, $data, $pk);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function delete($table, $data, $pk)
|
|
{
|
|
$this->db->where_in($pk, $data);
|
|
return $this->db->delete($table);
|
|
}
|
|
|
|
public function getDataDaftarHarga($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(d.DEALER_HSRP,2)) as DEALER,CONCAT("Rp ",FORMAT(d.USER_HSRP,2)) as USER
|
|
,CONCAT("Rp ",FORMAT(c.NILAI_HAVG,2)) as AVG,DATE_FORMAT(d.TGL_HSRP, "%d/%m/%Y") as TANGGAL_HSRP,
|
|
DATE_FORMAT(c.TGL_HAVG, "%d/%m/%Y") as TANGGAL_HAVG');
|
|
$this->db->from('barang a');
|
|
$this->db->join('jenis b','b.ID_JENIS=a.JENIS_ID');
|
|
$this->db->join('harga_avg c','c.BARANG_ID=a.ID_BARANG');
|
|
$this->db->join('harga_srp d','d.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->order_by('b.NAMA_JENIS ASC,a.KODE_BARANG ASC, d.ID_HSRP DESC, c.ID_HAVG DESC');
|
|
$this->db->where('a.JENIS_ID!=6');
|
|
$this->db->where('b.TYPE_JENIS!=2');
|
|
$this->db->limit('100');
|
|
}else{
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.DEALER_HSRP,2)) as DEALER,CONCAT("Rp ",FORMAT(b.USER_HSRP,2)) as USER,CONCAT("Rp ",FORMAT(c.NILAI_HAVG,2)) as AVG');
|
|
$this->db->from('barang a');
|
|
$this->db->join('harga_srp b','b.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->join('harga_avg c','c.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->join('jenis d','d.ID_JENIS=a.JENIS_ID','left');
|
|
$this->db->order_by('a.KODE_BARANG ASC, b.ID_HSRP DESC, c.ID_HAVG DESC');
|
|
$this->db->where('a.JENIS_ID!=6');
|
|
$this->db->where('d.TYPE_JENIS!=2');
|
|
$this->db->where(['a.ID_BARANG' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarHarga_forAdmin($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(d.DEALER_HSRP,2)) as DEALER,CONCAT("Rp ",FORMAT(d.USER_HSRP,2)) as USER
|
|
,CONCAT("Rp ",FORMAT(c.NILAI_HAVG,2)) as AVG,DATE_FORMAT(d.TGL_HSRP, "%d/%m/%Y") as TANGGAL_HSRP,
|
|
DATE_FORMAT(c.TGL_HAVG, "%d/%m/%Y") as TANGGAL_HAVG');
|
|
$this->db->from('barang a');
|
|
$this->db->join('jenis b','b.ID_JENIS=a.JENIS_ID');
|
|
$this->db->join('harga_avg c','c.BARANG_ID=a.ID_BARANG');
|
|
$this->db->join('harga_srp d','d.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->order_by('b.NAMA_JENIS ASC,a.KODE_BARANG ASC, d.ID_HSRP DESC, c.ID_HAVG DESC');
|
|
$this->db->where('a.JENIS_ID!=6');
|
|
$this->db->where('b.TYPE_JENIS!=2');
|
|
$this->db->limit('100');
|
|
}else{
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.DEALER_HSRP,2)) as DEALER,CONCAT("Rp ",FORMAT(b.USER_HSRP,2)) as USER,CONCAT("Rp ",FORMAT(c.NILAI_HAVG,2)) as AVG');
|
|
$this->db->from('barang a');
|
|
$this->db->join('harga_srp b','b.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->join('harga_avg c','c.BARANG_ID=a.ID_BARANG','left');
|
|
$this->db->join('jenis d','d.ID_JENIS=a.JENIS_ID','left');
|
|
$this->db->order_by('a.KODE_BARANG ASC, b.ID_HSRP DESC, c.ID_HAVG DESC');
|
|
$this->db->where('a.JENIS_ID!=6');
|
|
$this->db->where('d.TYPE_JENIS!=2');
|
|
$this->db->where(['a.ID_BARANG' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarHarga_forView($id = null){
|
|
$this->db->select('a.*,b.NAMA_JENIS,c.*,d.*,CONCAT("Rp ",FORMAT(d.DEALER_HSRP,2)) as DEALER,
|
|
CONCAT("Rp ",FORMAT(d.USER_HSRP,2)) as USER,CONCAT("Rp ",FORMAT(c.NILAI_HAVG,2)) as AVG,
|
|
DATE_FORMAT(d.TGL_HSRP, "%d/%m/%Y") as TANGGAL_HSRP,DATE_FORMAT(c.TGL_HAVG, "%d/%m/%Y") as TANGGAL_HAVG');
|
|
$this->db->from('barang a');
|
|
$this->db->join('jenis b','b.ID_JENIS=a.JENIS_ID');
|
|
$this->db->join('harga_avg c','c.BARANG_ID=a.ID_BARANG');
|
|
$this->db->join('harga_srp d','d.BARANG_ID=a.ID_BARANG');
|
|
$this->db->order_by('b.NAMA_JENIS ASC,a.KODE_BARANG ASC, d.ID_HSRP DESC, c.ID_HAVG DESC');
|
|
$this->db->where('a.JENIS_ID!=6');
|
|
$this->db->where('b.TYPE_JENIS!=2');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HargaSrp_byBARANG($id){
|
|
$this->db->select('*');
|
|
$this->db->from('harga_srp');
|
|
$this->db->where(['BARANG_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|