256 lines
8.7 KiB
PHP
256 lines
8.7 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelSupplier 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);
|
|
}
|
|
|
|
//Model getData
|
|
public function getData_Supplier($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->order_by('a.NAMA_SUPPLIER ASC');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->where(['a.ID_SUPPLIER' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Supplier_forAdmin($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->where('a.ID_SUPPLIER is NULL');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->where(['a.ID_SUPPLIER' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Supplier_forView(){
|
|
$this->db->select('a.*,b.NAMA_KOTA');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->order_by('a.ID_SUPPLIER DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pembelian_bySUPPLIER($id){
|
|
$this->db->select('*');
|
|
$this->db->from('pembelian a');
|
|
$this->db->join('supplier b','b.ID_SUPPLIER=a.SUPPLIER_ID','left');
|
|
$this->db->where(['a.SUPPLIER_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarKlaimProgram_bySUPPLIER($id){
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_klaimprogram a');
|
|
$this->db->join('supplier b','b.ID_SUPPLIER=a.SUPPLIER_ID','left');
|
|
$this->db->where(['a.SUPPLIER_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HutangDagang_bySUPPLIER($id){
|
|
$this->db->select('*');
|
|
$this->db->from('hutang_dagang a');
|
|
$this->db->join('supplier b','b.ID_SUPPLIER=a.SUPPLIER_ID','left');
|
|
$this->db->where(['a.SUPPLIER_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DpPembelian_bySUPPLIER($id){
|
|
$this->db->select('*');
|
|
$this->db->from('dp_pembelian');
|
|
$this->db->where(['SUPPLIER_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getExcel_Supplier() {
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b', 'b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->order_by('a.NAMA_SUPPLIER ASC, b.NAMA_KOTA ASC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getDataDpPembelian($id=null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.SALDO_SUPPLIER,2)) as SALDO,CONCAT("Rp ",FORMAT(a.NOMINAL_DPB,2)) as DP');
|
|
$this->db->from('dp_pembelian a');
|
|
$this->db->join('supplier b','b.ID_SUPPLIER=a.SUPPLIER_ID','left');
|
|
$this->db->join('kota c','c.ID_KOTA=b.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_DPB');
|
|
}else{
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.SALDO_SUPPLIER,2)) as SALDO,CONCAT("Rp ",FORMAT(a.NOMINAL_DPB,2)) as DP');
|
|
$this->db->from('dp_pembelian a');
|
|
$this->db->join('supplier b','b.ID_SUPPLIER=a.SUPPLIER_ID','left');
|
|
$this->db->join('kota c','c.ID_KOTA=b.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_DPB');
|
|
$this->db->where(['a.SUPPLIER_ID' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataSupplierDpb(){
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('dp_pembelian b','b.SUPPLIER_ID=a.ID_SUPPLIER','left');
|
|
$this->db->join('kota c','c.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->where('b.SUPPLIER_ID is NULL');
|
|
$this->db->order_by('a.NAMA_SUPPLIER','ASC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDpb($id){
|
|
$this->db->select('*');
|
|
$this->db->from('dp_pembelian');
|
|
$this->db->where(['ID_DPB' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeDPB() {
|
|
$this->db->select('MAX(KODE_DPB) AS KODE');
|
|
$this->db->from('dp_pembelian');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodePembelian() {
|
|
$this->db->select('MAX(KODE_PEMBELIAN) AS KODE');
|
|
$this->db->from('pembelian');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeHDA() {
|
|
$this->db->select('MAX(KODE_HDA) AS KODE');
|
|
$this->db->from('hutang_dagang');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function hapusDPB($id){
|
|
$this->db->where(['SUPPLIER_ID' => $id]);
|
|
$this->db->delete('dp_pembelian');
|
|
}
|
|
|
|
public function hapusPembelian($id){
|
|
$this->db->where(['SUPPLIER_ID' => $id]);
|
|
$this->db->delete('pembelian');
|
|
}
|
|
|
|
public function getIDPembelian() {
|
|
$this->db->select_max('ID_PEMBELIAN');
|
|
$this->db->from('pembelian');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKelompokSupplier($id=null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ANGGOTA_ID=a.ID_SUPPLIER','left');
|
|
$this->db->group_by('a.ID_SUPPLIER');
|
|
$this->db->where('c.ANGGOTA_ID is NULL');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('supplier a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ANGGOTA_ID=a.ID_SUPPLIER','left');
|
|
$this->db->group_by('a.ID_SUPPLIER');
|
|
$this->db->where('c.ANGGOTA_ID is NULL');
|
|
$this->db->or_where(['c.ANGGOTA_ID' => $id]);
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function cekPass($id, $pass)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan');
|
|
$this->db->where(['ID_KARYAWAN' => $id]);
|
|
$this->db->where(['PASSWORD' => $pass]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
//Step Two, Input Hutang Dagang
|
|
public function getDataHutangDagang($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_HDA,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(d.PIUTANG_SUPPLIER,2)) as PIUTANG,CONCAT("Rp ",FORMAT(a.NOMINAL_HDA,2)) as HDA');
|
|
$this->db->from('hutang_dagang a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID','left');
|
|
$this->db->join('corp c','c.ID_CORP=b.CORP_ID','left');
|
|
$this->db->join('supplier d','d.ID_SUPPLIER=b.SUPPLIER_ID','left');
|
|
$this->db->join('kota e','e.ID_KOTA=d.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_HDA');
|
|
}else{
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_HDA,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(d.PIUTANG_SUPPLIER,2)) as PIUTANG,CONCAT("Rp ",FORMAT(a.NOMINAL_HDA,2)) as HDA');
|
|
$this->db->from('hutang_dagang a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID','left');
|
|
$this->db->join('corp c','c.ID_CORP=b.CORP_ID','left');
|
|
$this->db->join('supplier d','d.ID_SUPPLIER=b.SUPPLIER_ID','left');
|
|
$this->db->join('kota e','e.ID_KOTA=d.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_HDA');
|
|
$this->db->where(['d.ID_SUPPLIER' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPembelian($id) {
|
|
$this->db->select('PEMBELIAN_ID,SUPPLIER_ID,CORP_ID,NOMINAL_HDA');
|
|
$this->db->from('hutang_dagang a');
|
|
$this->db->join('pembelian b','b.ID_PEMBELIAN=a.PEMBELIAN_ID','left');
|
|
$this->db->where(['a.ID_HDA' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataCorp($id) {
|
|
$this->db->select('HUTANG_CORP');
|
|
$this->db->from('corp');
|
|
$this->db->where(['ID_CORP' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
}
|
|
?>
|