403 lines
14 KiB
PHP
403 lines
14 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelKontak 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_Kontak($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('kontak a');
|
|
$this->db->join('posisi b','b.ID_POSISI=a.POSISI_ID');
|
|
$this->db->join('akun c','c.ID_AKUN=a.AKUN_ID');
|
|
$this->db->order_by('c.NAMA_AKUN ASC, a.NAMA_KONTAK ASC');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('kontak a');
|
|
$this->db->join('posisi b','b.ID_POSISI=a.POSISI_ID');
|
|
$this->db->join('akun c','c.ID_AKUN=a.AKUN_ID');
|
|
$this->db->order_by('c.NAMA_AKUN ASC, a.NAMA_KONTAK ASC');
|
|
$this->db->where(['a.AKUN_ID' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Kontak_byNAMA($id1, $id2=null){
|
|
if ($id2 == null) {
|
|
$this->db->select('*');
|
|
$this->db->from('kontak');
|
|
$this->db->where(['NAMA_KONTAK' => $id1]);
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('kontak');
|
|
$this->db->where(['NAMA_KONTAK' => $id1]);
|
|
$this->db->where('ID_KONTAK!=', $id2);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getData_Pelanggan_byNAMA($id){
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan');
|
|
$this->db->where(['NAMA_PELANGGAN' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pembelian_byID(){
|
|
$this->db->select('*');
|
|
$this->db->from('pembelian a');
|
|
$this->db->join('hutang_dagang b','b.PEMBELIAN_ID=a.ID_PEMBELIAN');
|
|
$this->db->where('a.STATUS_PEMBELIAN=1');
|
|
$this->db->group_by('a.ID_PEMBELIAN');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pelanggan_forAdmin($id = null){
|
|
if ($id == null) {
|
|
$this->db->select('a.*,b.NAMA_KOTA,c.NAMA_KELOMPOK');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->order_by('a.ID_PELANGGAN DESC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
$this->db->where('a.ID_PELANGGAN is NULL');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->order_by('a.TYPE_PELANGGAN ASC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
$this->db->where(['a.ID_PELANGGAN' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pelanggan_forView(){
|
|
$this->db->select('a.*,b.NAMA_KOTA,c.NAMA_KELOMPOK');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->order_by('a.ID_PELANGGAN DESC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Pelanggan_Corporate(){
|
|
$this->db->select('a.*,b.NAMA_KOTA,c.NAMA_KELOMPOK');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->where('a.TYPE_PELANGGAN=0');
|
|
$this->db->order_by('a.NAMA_PELANGGAN ASC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getExcel_Pelanggan($type_cetak)
|
|
{
|
|
if ($type_cetak!="9") {
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b', 'b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->join('kelompok c', 'c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->where('a.TYPE_PELANGGAN=', $type_cetak);
|
|
$this->db->order_by('a.NAMA_PELANGGAN ASC');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b', 'b.ID_KOTA=a.KOTA_ID');
|
|
$this->db->join('kelompok c', 'c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->order_by('a.TYPE_PELANGGAN ASC, a.NAMA_PELANGGAN ASC');
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getData_Pelanggan_byID($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->join('sales_order d','d.PELANGGAN_ID=a.ID_PELANGGAN','left');
|
|
$this->db->join('penjualan e','e.SO_ID=d.ID_SO','left');
|
|
$this->db->order_by('a.TYPE_PELANGGAN ASC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ID_KELOMPOK=a.KELOMPOK_ID','left');
|
|
$this->db->join('sales_order d','d.PELANGGAN_ID=a.ID_PELANGGAN','left');
|
|
$this->db->join('penjualan e','e.SO_ID=d.ID_SO','left');
|
|
$this->db->order_by('a.TYPE_PELANGGAN ASC');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
$this->db->where(['a.ID_PELANGGAN' => $id]);
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Sales($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b','b.ID_JABATAN=a.JABATAN_ID','left');
|
|
$this->db->where('a.JABATAN_ID=4');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b','b.ID_JABATAN=a.JABATAN_ID','left');
|
|
$this->db->where('a.JABATAN_ID=4');
|
|
$this->db->where(['a.ID_KARYAWAN' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDpPenjualan($id=null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.SALDO_PELANGGAN,2)) as SALDO,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DP');
|
|
$this->db->from('dp_penjualan a');
|
|
$this->db->join('pelanggan b','b.ID_PELANGGAN=a.PELANGGAN_ID','left');
|
|
$this->db->join('kota c','c.ID_KOTA=b.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_DPJ');
|
|
}else{
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(b.SALDO_PELANGGAN,2)) as SALDO,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DP');
|
|
$this->db->from('dp_penjualan a');
|
|
$this->db->join('pelanggan b','b.ID_PELANGGAN=a.PELANGGAN_ID','left');
|
|
$this->db->join('kota c','c.ID_KOTA=b.KOTA_ID','left');
|
|
$this->db->group_by('a.ID_DPJ');
|
|
$this->db->where(['a.PELANGGAN_ID' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPelangganDpj(){
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('dp_penjualan b','b.PELANGGAN_ID=a.ID_PELANGGAN','left');
|
|
$this->db->join('kota c','c.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->where('b.PELANGGAN_ID is NULL');
|
|
$this->db->order_by('a.TYPE_PELANGGAN','ASC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDpj($id){
|
|
$this->db->select('*');
|
|
$this->db->from('dp_penjualan');
|
|
$this->db->where(['ID_DPJ' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeDPJ() {
|
|
$this->db->select('MAX(KODE_DPJ) AS KODE');
|
|
$this->db->from('dp_penjualan');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function hapusDPJ($id){
|
|
$this->db->where(['PELANGGAN_ID' => $id]);
|
|
$this->db->delete('dp_penjualan');
|
|
}
|
|
|
|
public function getIDPelangganMax(){
|
|
$this->db->select_max('ID_PELANGGAN');
|
|
$this->db->from('pelanggan');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKelompokPelanggan(){
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('kota b','b.ID_KOTA=a.KOTA_ID','left');
|
|
$this->db->join('kelompok c','c.ANGGOTA_ID=a.ID_PELANGGAN','left');
|
|
$this->db->group_by('a.ID_PELANGGAN');
|
|
$this->db->where('c.ANGGOTA_ID is NULL');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPelangganNormal($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan');
|
|
$this->db->where('ID_PELANGGAN>=3');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('pelanggan');
|
|
$this->db->where('ID_PELANGGAN>=3');
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPelangganService($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,b.ID_SERVICE');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('service b','b.PELANGGAN_ID=a.ID_PELANGGAN');
|
|
}else{
|
|
$this->db->select('*,b.ID_SERVICE');
|
|
$this->db->from('pelanggan a');
|
|
$this->db->join('service b','b.PELANGGAN_ID=a.ID_PELANGGAN');
|
|
$this->db->where(['ID_PELANGGAN' => $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 Piutang Dagang
|
|
public function getDataPiutangDagang($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_PDA,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(d.HUTANG_PELANGGAN,2)) as HUTANG,CONCAT("Rp ",FORMAT(a.NOMINAL_PDA,2)) as PDA');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID','left');
|
|
$this->db->join('corp c','c.ID_CORP=b.CORP_ID','left');
|
|
$this->db->join('pelanggan d','d.ID_PELANGGAN=b.PELANGGAN_ID','left');
|
|
$this->db->join('kota e','e.ID_KOTA=d.KOTA_ID','left');
|
|
$this->db->join('karyawan f','f.ID_KARYAWAN=b.SALES_ID','left');
|
|
$this->db->group_by('a.ID_PDA');
|
|
}else{
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_PDA,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(d.HUTANG_PELANGGAN,2)) as HUTANG,CONCAT("Rp ",FORMAT(a.NOMINAL_PDA,2)) as PDA');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID','left');
|
|
$this->db->join('corp c','c.ID_CORP=b.CORP_ID','left');
|
|
$this->db->join('pelanggan d','d.ID_PELANGGAN=b.PELANGGAN_ID','left');
|
|
$this->db->join('kota e','e.ID_KOTA=d.KOTA_ID','left');
|
|
$this->db->join('karyawan f','f.ID_KARYAWAN=b.SALES_ID','left');
|
|
$this->db->group_by('a.ID_PDA');
|
|
$this->db->where(['d.ID_PELANGGAN' => $id]);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPenjualan($id) {
|
|
$this->db->select('PENJUALAN_ID,PELANGGAN_ID,CORP_ID,NOMINAL_PDA');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID','left');
|
|
$this->db->where(['a.ID_PDA' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataCorp($id) {
|
|
$this->db->select('PIUTANG_CORP');
|
|
$this->db->from('corp');
|
|
$this->db->where(['ID_CORP' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodePDA() {
|
|
$this->db->select('MAX(KODE_PDA) AS KODE');
|
|
$this->db->from('piutang_dagang');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodePenjualan() {
|
|
$this->db->select('MAX(KODE_PENJUALAN) AS KODE');
|
|
$this->db->from('penjualan');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getIDPenjualan() {
|
|
$this->db->select_max('ID_PENJUALAN');
|
|
$this->db->from('penjualan');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Karyawan_MasterPelanggan($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b','b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->where('a.USERNAME="iwan" OR a.USERNAME="helda" OR a.USERNAME="admin"');
|
|
$this->db->where(['a.ID_KARYAWAN' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesOrder_byPELANGGAN($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('sales_order');
|
|
$this->db->where(['PELANGGAN_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriSn_byPELANGGAN($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('histori_sn');
|
|
$this->db->where(['PELANGGAN_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_PiutangDagang_byPELANGGAN($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('piutang_dagang');
|
|
$this->db->where(['PELANGGAN_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DpPenjualan_byPELANGGAN($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('dp_penjualan');
|
|
$this->db->where(['PELANGGAN_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|