242 lines
8.8 KiB
PHP
242 lines
8.8 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
class ModelVisit 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_SalesVisit_bySALES_status0($id=null) { // Visit [1]
|
|
if ($id==null) {
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_SAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.REMINDER_SAV,"%d/%m/%Y") as REMINDER');
|
|
$this->db->from('sales_visit a');
|
|
$this->db->join('karyawan b', 'b.ID_KARYAWAN=a.SALES_ID');
|
|
$this->db->join('akun c', 'c.ID_AKUN=a.AKUN_ID','left');
|
|
$this->db->join('kontak d', 'd.ID_KONTAK=a.KONTAK_ID','left');
|
|
$this->db->join('posisi e', 'e.ID_POSISI=d.POSISI_ID','left');
|
|
$this->db->where('a.STATUS_SAV=0');
|
|
} else {
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_SAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.REMINDER_SAV,"%d/%m/%Y") as REMINDER');
|
|
$this->db->from('sales_visit a');
|
|
$this->db->join('karyawan b', 'b.ID_KARYAWAN=a.SALES_ID');
|
|
$this->db->join('akun c', 'c.ID_AKUN=a.AKUN_ID','left');
|
|
$this->db->join('kontak d', 'd.ID_KONTAK=a.KONTAK_ID','left');
|
|
$this->db->join('posisi e', 'e.ID_POSISI=d.POSISI_ID','left');
|
|
$this->db->where('a.STATUS_SAV=0');
|
|
if ($id==1 OR $id==2 OR $id==50) {
|
|
|
|
} else {
|
|
$this->db->where('a.SALES_ID=', $id);
|
|
}
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarSalesVisit_bySAV_orderDESC_limit1($id) { // Visit [1, 4, 7, 8, 9, 10, 11, 12]
|
|
$this->db->select('*');
|
|
$this->db->from('daftar_salesvisit a');
|
|
$this->db->join('sales_visit b','b.ID_SAV=a.SAV_ID');
|
|
$this->db->where('a.SAV_ID=', $id);
|
|
$this->db->order_by('a.ID_DSAV DESC');
|
|
$this->db->limit('1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesVisit_byID($id) { // Visit [3, 4, 5, 6, 7, 9, 10]
|
|
$this->db->select('*,DATE_FORMAT(TGL_SAV,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('sales_visit');
|
|
$this->db->where('ID_SAV=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarSalesVisit_bySAV_orderASC($id) { // Visit [3, 4]
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_DSAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.TIMER_DSAV,"%d/%m/%Y") as TIMER');
|
|
$this->db->from('daftar_salesvisit a');
|
|
$this->db->join('sales_visit b','b.ID_SAV=a.SAV_ID');
|
|
$this->db->join('karyawan c','c.ID_KARYAWAN=a.KARYAWAN_ID');
|
|
$this->db->where('a.SAV_ID=', $id);
|
|
$this->db->order_by('a.ID_DSAV ASC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Akun($id=null) { // Visit [4]
|
|
if ($id==null) {
|
|
$this->db->select('*');
|
|
$this->db->from('akun');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('akun');
|
|
$this->db->where('ID_AKUN=', $id);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Kontak($id=null) { // Visit [4, 5]
|
|
if ($id==null) {
|
|
$this->db->select('*');
|
|
$this->db->from('kontak a');
|
|
$this->db->join('akun b','b.ID_AKUN=a.AKUN_ID');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('kontak a');
|
|
$this->db->join('akun b','b.ID_AKUN=a.AKUN_ID');
|
|
$this->db->where('a.ID_KONTAK=', $id);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesOrder_bySALES_status0_status1($id) { // Visit [4]
|
|
$this->db->select('*');
|
|
$this->db->from('sales_order a');
|
|
$this->db->join('pelanggan b','b.ID_PELANGGAN=a.PELANGGAN_ID');
|
|
$this->db->where('a.STATUS_SO=0 AND a.SALES_ID=', $id);
|
|
$this->db->or_where('a.STATUS_SO=1 AND a.SALES_ID=', $id);
|
|
$this->db->order_by('a.ID_SO DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_PiutangDagang_bySO($id) { // Visit [4]
|
|
$this->db->select('*,FORMAT(a.DEBET_PDA,2) as DEBET,FORMAT(a.KREDIT_PDA,2) as KREDIT,DATE_FORMAT(a.TGL_PDA,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID');
|
|
$this->db->where('b.SO_ID=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getSum_PiutangDagang_bySO_transaksi0($id) { // Visit [4]
|
|
$this->db->select('SUM(a.DEBET_PDA) as TOTAL');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID');
|
|
$this->db->where('b.SO_ID=', $id);
|
|
$this->db->where('a.TRANSAKSI_PDA=0');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getSum_PiutangDagang_bySO_transaksi1($id) { // Visit [4]
|
|
$this->db->select('SUM(a.KREDIT_PDA) as TOTAL');
|
|
$this->db->from('piutang_dagang a');
|
|
$this->db->join('penjualan b','b.ID_PENJUALAN=a.PENJUALAN_ID');
|
|
$this->db->where('b.SO_ID=', $id);
|
|
$this->db->where('a.TRANSAKSI_PDA=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getID_DaftarSalesVisitMax() { // Visit [6]
|
|
$this->db->select_max('ID_DSAV');
|
|
$this->db->from('daftar_salesvisit');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getID_NotifikasiMax() { // Visit [6]
|
|
$this->db->select_max('ID_NOTIFIKASI');
|
|
$this->db->from('notifikasi');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_DaftarSalesVisit_byID($id) { // Visit [7, 8]
|
|
$this->db->select('*,DATE_FORMAT(TGL_DSAV,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('daftar_salesvisit');
|
|
$this->db->where('ID_DSAV=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Notifikasi_byDSAV($id) { // Visit [7, 8]
|
|
$this->db->select('*');
|
|
$this->db->from('notifikasi');
|
|
$this->db->where('DSAV_ID=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesOrder_byID_status0_status1($id) { // Visit [9]
|
|
$this->db->select('*');
|
|
$this->db->from('sales_order');
|
|
$this->db->where('STATUS_SO=0 AND ID_SO=', $id);
|
|
$this->db->or_where('STATUS_SO=1 AND ID_SO=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Karyawan_SalesOnly_NonFree() { // Visit [11]
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b','b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->like('b.NAMA_JABATAN','SALES');
|
|
$this->db->not_like('a.USERNAME','none');
|
|
$this->db->not_like('a.USERNAME','insentive');
|
|
$this->db->not_like('a.USERNAME','service');
|
|
$this->db->not_like('a.USERNAME','itp');
|
|
$this->db->not_like('a.USERNAME','louis');
|
|
$this->db->order_by('a.NAMA_PANGGILAN_KARYAWAN ASC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesVisit_bySALES_status1_status2($id=null) { // Visit [11]
|
|
if ($id==null) {
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_SAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.REMINDER_SAV,"%d/%m/%Y") as REMINDER');
|
|
$this->db->from('sales_visit a');
|
|
$this->db->join('karyawan b', 'b.ID_KARYAWAN=a.SALES_ID');
|
|
$this->db->join('akun c', 'c.ID_AKUN=a.AKUN_ID');
|
|
$this->db->join('kontak d', 'd.ID_KONTAK=a.KONTAK_ID');
|
|
$this->db->join('posisi e', 'e.ID_POSISI=d.POSISI_ID');
|
|
$this->db->where('a.STATUS_SAV=1');
|
|
$this->db->or_where('a.STATUS_SAV=2');
|
|
} else {
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_SAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.REMINDER_SAV,"%d/%m/%Y") as REMINDER');
|
|
$this->db->from('sales_visit a');
|
|
$this->db->join('karyawan b', 'b.ID_KARYAWAN=a.SALES_ID');
|
|
$this->db->join('akun c', 'c.ID_AKUN=a.AKUN_ID');
|
|
$this->db->join('kontak d', 'd.ID_KONTAK=a.KONTAK_ID');
|
|
$this->db->join('posisi e', 'e.ID_POSISI=d.POSISI_ID');
|
|
$this->db->where('a.STATUS_SAV=1 AND a.SALES_ID=', $id);
|
|
$this->db->or_where('a.STATUS_SAV=2 AND a.SALES_ID=', $id);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesVisit_bySALES_byAKHIR($id, $status) { // Visit [12]
|
|
$this->db->select('*,DATE_FORMAT(a.TGL_SAV,"%d/%m/%Y") as TANGGAL,DATE_FORMAT(a.SELESAI_SAV,"%d/%m/%Y") as SELESAI');
|
|
$this->db->from('sales_visit a');
|
|
$this->db->join('karyawan b','b.ID_KARYAWAN=a.SALES_ID');
|
|
$this->db->join('akun c','c.ID_AKUN=a.AKUN_ID');
|
|
$this->db->join('kontak d','d.ID_KONTAK=a.KONTAK_ID','left');
|
|
$this->db->join('posisi e','e.ID_POSISI=d.POSISI_ID','left');
|
|
$this->db->join('sales_order f','f.ID_SO=a.SO_ID','left');
|
|
if ($id==0) {
|
|
|
|
} else {
|
|
$this->db->where('a.SALES_ID=', $id);
|
|
}
|
|
$this->db->where('a.STATUS_AKHIR=', $status);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Karyawan_byID($id) { // Visit [12]
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan');
|
|
$this->db->where('ID_KARYAWAN=', $id);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|