316 lines
11 KiB
PHP
316 lines
11 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelKomisi 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_Komisi($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('jenis');
|
|
$this->db->order_by('NAMA_JENIS ASC');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('jenis');
|
|
$this->db->where(['ID_JENIS' => $id]);
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarKasbank($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_kasbank a');
|
|
$this->db->join('kasbank b','b.ID_KB=a.KB_ID');
|
|
$this->db->where('a.SETDATA_ID is NULL');
|
|
$this->db->where('a.TGL_DKB is NULL');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('transaksi_stock a');
|
|
$this->db->join('sales_order b','b.ID_SO=a.SO_ID');
|
|
$this->db->where(['ID_IO' => $id]);
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pembelian($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_beli a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID');
|
|
$this->db->where('b.STATUS_PEMBELIAN=1');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('transaksi_stock a');
|
|
$this->db->join('sales_order b','b.ID_SO=a.SO_ID');
|
|
$this->db->where(['ID_IO' => $id]);
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_ReturPembelian(){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_returbeli a');
|
|
$this->db->join('retur_pembelian b','b.ID_RB=a.RB_ID');
|
|
$this->db->where('b.STATUS_RB=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HargaAvg($id){
|
|
$this->db->select('*');
|
|
$this->db->from('harga_avg');
|
|
$this->db->where(['BARANG_ID' => $id]);
|
|
$this->db->order_by('ID_HAVG DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarBeli_forAVG($id){
|
|
$this->db->select('a.BARANG_ID,a.QTY_DB as QTY,a.HARGA_DB as HARGA');
|
|
$this->db->from('daftar_beli a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID');
|
|
$this->db->where(['a.BARANG_ID' => $id]);
|
|
$this->db->where('b.STATUS_PEMBELIAN=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarReturBeli_forAVG($id){
|
|
$this->db->select('a.BARANG_ID,a.QTY_DRB as QTY,a.HARGA_DRB as HARGA');
|
|
$this->db->from('daftar_returbeli a');
|
|
$this->db->join('retur_pembelian b','b.ID_RB=a.RB_ID');
|
|
$this->db->where(['a.BARANG_ID' => $id]);
|
|
$this->db->where('b.STATUS_RB=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_TransaksiStock_Masuk_forAVG($id){
|
|
$this->db->select('BARANG_ID,QTY_IO as QTY,HARGA_IO as HARGA');
|
|
$this->db->from('transaksi_stock');
|
|
$this->db->where(['BARANG_ID' => $id]);
|
|
$this->db->where('STATUS_IO=1');
|
|
$this->db->where('JENIS_IO=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Penjualan_Pda(){
|
|
$this->db->select('*');
|
|
$this->db->from('penjualan a');
|
|
$this->db->join('piutang_dagang b','b.PENJUALAN_ID=a.ID_PENJUALAN');
|
|
$this->db->where('a.STATUS_PENJUALAN=1');
|
|
$this->db->group_by('b.PENJUALAN_ID');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
|
|
public function getData_SalesOrder_1(){
|
|
$this->db->select('*');
|
|
$this->db->from('sales_order');
|
|
$this->db->where('STATUS_SO=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarOrder_bySO($id){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_order');
|
|
$this->db->where('SO_ID=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarOrder(){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_order a');
|
|
$this->db->join('sales_order b','b.ID_SO=a.SO_ID');
|
|
$this->db->where('b.STATUS_SO=5');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Barang_byID($id){
|
|
$this->db->select('*');
|
|
$this->db->from('barang a');
|
|
$this->db->join('jenis b','b.ID_JENIS=a.JENIS_ID');
|
|
$this->db->where('a.ID_BARANG=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pelanggan_byID($id){
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan');
|
|
$this->db->where('ID_PELANGGAN=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarKasbank_bySETDATA(){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_kasbank');
|
|
$this->db->where('SETDATA_ID=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeKasMasuk() {
|
|
$this->db->select('MAX(KODE_KB) AS KODE');
|
|
$this->db->from('kasbank');
|
|
$this->db->like('KODE_KB','BSD', 'after');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getID_KasbankMax() {
|
|
$this->db->select_max('ID_KB');
|
|
$this->db->from('kasbank');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HargaAvg_TransaksiStock($id=null){
|
|
if ($id==null) {
|
|
$this->db->select('*');
|
|
$this->db->from('harga_avg a');
|
|
$this->db->join('transaksi_stock b','b.BARANG_ID=a.BARANG_ID');
|
|
$this->db->where('a.KODE_BUKTI=b.KODE_BUKTI');
|
|
$this->db->where('a.KODE_BUKTI="SD22-0001"');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('harga_avg a');
|
|
$this->db->join('transaksi_stock b','b.BARANG_ID=a.BARANG_ID');
|
|
$this->db->where('a.KODE_BUKTI=b.KODE_BUKTI');
|
|
$this->db->where('a.KODE_BUKTI="SD22-0001"');
|
|
$this->db->where('a.BARANG_ID=', $id);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HargaAvg_Pembelian(){
|
|
$this->db->select('*');
|
|
$this->db->from('harga_avg a');
|
|
$this->db->join('pembelian b','b.KODE_PEMBELIAN=a.KODE_BUKTI');
|
|
$this->db->where('a.ID_HAVG>=931 AND a.ID_HAVG<=1417');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriKuantiti_Io(){
|
|
$this->db->select('*');
|
|
$this->db->from('histori_kuantiti a');
|
|
$this->db->join('transaksi_stock b','b.BARANG_ID=a.BARANG_ID');
|
|
$this->db->where('a.KODE_BUKTI=b.KODE_BUKTI');
|
|
$this->db->where('a.KODE_BUKTI="SD22-0001"');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriKuantiti_Havg(){
|
|
$this->db->select('*');
|
|
$this->db->from('histori_kuantiti a');
|
|
$this->db->join('harga_avg b','b.BARANG_ID=a.BARANG_ID');
|
|
$this->db->where('a.KODE_BUKTI=b.KODE_BUKTI');
|
|
$this->db->where('a.KODE_BUKTI="SD22-0001"');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HargaAvg_byID($id){
|
|
$this->db->select('*');
|
|
$this->db->from('harga_avg');
|
|
$this->db->where('ID_HAVG=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_TransaksiStock_byID($id){
|
|
$this->db->select('*');
|
|
$this->db->from('transaksi_stock');
|
|
$this->db->where('ID_IO=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriKuantiti_MasukLebih0(){
|
|
$this->db->select('*');
|
|
$this->db->from('histori_kuantiti');
|
|
$this->db->where('MASUK_HQ>0');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriKuantiti_byBARANG_beforeID($id_barang, $id_hq){
|
|
$this->db->select('*');
|
|
$this->db->from('histori_kuantiti');
|
|
$this->db->where('BARANG_ID=', $id_barang);
|
|
$this->db->where('ID_HQ<', $id_hq);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriKuantiti_byBARANG_beforeID_forHAVG($id_barang, $id_hq){
|
|
$this->db->select('*');
|
|
$this->db->from('histori_kuantiti');
|
|
$this->db->where('BARANG_ID=', $id_barang);
|
|
$this->db->where('ID_HQ<', $id_hq);
|
|
$this->db->where('HAVG_ID IS NOT NULL');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getSum_HistoriKuantiti_byBARANG_beforeID($id_barang, $id_hq){
|
|
$this->db->select('SUM(MASUK_HQ-KELUAR_HQ) as REAL');
|
|
$this->db->from('histori_kuantiti');
|
|
$this->db->where('BARANG_ID=', $id_barang);
|
|
$this->db->where('ID_HQ<', $id_hq);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarBeli_byPEMBELIAN($id_pembelian, $id_barang){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_beli');
|
|
$this->db->where('PEMBELIAN_ID=', $id_pembelian);
|
|
$this->db->where('BARANG_ID=', $id_barang);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarBeli_byKODE_byBARANG($kode_pembelian, $id_barang){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_beli a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID');
|
|
$this->db->where('b.KODE_PEMBELIAN=', $kode_pembelian);
|
|
$this->db->where('a.BARANG_ID=', $id_barang);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarReturJual_byKODE_byBARANG($kode_rj, $id_barang){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_returjual a');
|
|
$this->db->join('retur_penjualan b','b.ID_RJ=a.RJ_ID');
|
|
$this->db->where('b.KODE_RJ=', $kode_rj);
|
|
$this->db->where('a.BARANG_ID=', $id_barang);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_TransaksiStock_byKODE_byBARANG($kode_bukti, $id_barang, $qty){
|
|
$this->db->select('*');
|
|
$this->db->from('transaksi_stock a');
|
|
$this->db->join('sales_order b','b.ID_SO=a.SO_ID');
|
|
$this->db->join('penjualan c','c.SO_ID=b.ID_SO');
|
|
$this->db->where('c.KODE_PENJUALAN=', $kode_bukti);
|
|
$this->db->where('a.BARANG_ID=', $id_barang);
|
|
$this->db->where('a.QTY_IO=', $qty);
|
|
$this->db->where('a.JENIS_IO=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|