61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelPart 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 getData_Part($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,FORMAT(b.HPP_HPAR,2) as HPP,DATE_FORMAT(b.TGL_HPAR,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('part a');
|
|
$this->db->join('harga_part b','b.PART_ID=a.ID_PART','left');
|
|
$this->db->order_by('a.NAMA_PART ASC, b.ID_HPAR DESC');
|
|
}else{
|
|
$this->db->select('*,FORMAT(b.HPP_HPAR,2) as HPP');
|
|
$this->db->from('part a');
|
|
$this->db->join('harga_part b','b.PART_ID=a.ID_PART','left');
|
|
$this->db->order_by('a.NAMA_PART ASC, b.ID_HPAR DESC');
|
|
$this->db->where(['b.PART_ID' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getID_PartMax() {
|
|
$this->db->select_max('ID_PART');
|
|
$this->db->from('part');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_TransaksiStock_byPART($id){
|
|
$this->db->select('*');
|
|
$this->db->from('transaksi_stock a');
|
|
$this->db->join('harga_part b','b.ID_HPAR=a.HPAR_ID');
|
|
$this->db->where(['b.PART_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|