189 lines
6.9 KiB
PHP
189 lines
6.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelNotifikasi 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 getDataFlashNotif($id_karyawan)
|
|
{
|
|
$tgl = date('Y-m-d');
|
|
$this->db->select('*');
|
|
$this->db->from('log_notifikasi a');
|
|
$this->db->join('notifikasi b', 'b.ID_NOTIFIKASI=a.NOTIFIKASI_ID');
|
|
$this->db->where(['a.KARYAWAN_ID' => $id_karyawan]);
|
|
$this->db->where('b.TGL_NOTIFIKASI<=',$tgl);
|
|
$this->db->where(['a.STATUS' => 0]);
|
|
$this->db->order_by('b.ID_NOTIFIKASI', 'DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataNotif($jenis, $jenis2, $id_karyawan)
|
|
{
|
|
$tgl = date('Y-m-d');
|
|
$this->db->select('a.ID_NOTIFIKASI, a.TGL_NOTIFIKASI, a.JENIS_NOTIFIKASI, a.KET_NOTIFIKASI, b.ID_LOG_NOTIFIKASI');
|
|
// $this->db->select('*');
|
|
|
|
$this->db->from('notifikasi a');
|
|
$this->db->join('log_notifikasi b', 'b.NOTIFIKASI_ID=a.ID_NOTIFIKASI');
|
|
|
|
$this->db->where(['a.TGL_NOTIFIKASI' => $tgl, 'b.KARYAWAN_ID' => $id_karyawan]);
|
|
$this->db->where(['b.STATUS!=' => 2]);
|
|
|
|
if ($jenis2 == 0) {
|
|
$this->db->where(['a.JENIS_NOTIFIKASI' => $jenis]);
|
|
} else {
|
|
$this->db->where(['a.JENIS_NOTIFIKASI!=' => 3]);
|
|
// $this->db->where(['a.JENIS_NOTIFIKASI' => $jenis2]);
|
|
}
|
|
$this->db->where(['a.JENIS_NOTIFIKASI!=' => 4]);
|
|
$this->db->order_by('a.ID_NOTIFIKASI', 'DESC');
|
|
// $this->db->limit(5);/
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataNotif_AllNotif6($jenis, $id_karyawan)
|
|
{
|
|
$this->db->select('a.ID_NOTIFIKASI, a.TGL_NOTIFIKASI, a.JENIS_NOTIFIKASI, a.KET_NOTIFIKASI, b.ID_LOG_NOTIFIKASI');
|
|
$this->db->from('notifikasi a');
|
|
$this->db->join('log_notifikasi b', 'b.NOTIFIKASI_ID=a.ID_NOTIFIKASI');
|
|
$this->db->where(['b.KARYAWAN_ID' => $id_karyawan]);
|
|
$this->db->where(['b.STATUS!=' => 2]);
|
|
$this->db->where(['a.JENIS_NOTIFIKASI' => $jenis]);
|
|
$this->db->order_by('a.ID_NOTIFIKASI', 'DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataNotif_AllNotif7($id_karyawan) {
|
|
$tgl_now = date('Y-m-d');
|
|
$tgl_weekbefore = $this->subTempoDay($tgl_now, 7);
|
|
$tgl_weekafter = $this->addTempoDay($tgl_now, 7);
|
|
$this->db->select('a.ID_NOTIFIKASI, a.TGL_NOTIFIKASI, a.JENIS_NOTIFIKASI, a.KET_NOTIFIKASI, b.ID_LOG_NOTIFIKASI, DATE_FORMAT(a.TGL_NOTIFIKASI,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('notifikasi a');
|
|
$this->db->join('log_notifikasi b', 'b.NOTIFIKASI_ID=a.ID_NOTIFIKASI');
|
|
$this->db->where(['b.KARYAWAN_ID' => $id_karyawan]);
|
|
$this->db->where(['b.STATUS!=' => 2]);
|
|
$this->db->where('a.JENIS_NOTIFIKASI=7');
|
|
$this->db->where('a.TGL_NOTIFIKASI>=', $tgl_weekbefore);
|
|
$this->db->where('a.TGL_NOTIFIKASI<=', $tgl_weekafter);
|
|
$this->db->order_by('a.TGL_NOTIFIKASI', 'DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function addTempoDay($date, $day) {
|
|
$sum = strtotime(date("Y-m-d", strtotime("$date")) . " +$day days");
|
|
$dateTo=date('Y-m-d',$sum);
|
|
return $dateTo;
|
|
}
|
|
|
|
public function subTempoDay($date, $day) {
|
|
$sum = strtotime(date("Y-m-d", strtotime("$date")) . " -$day days");
|
|
$dateTo=date('Y-m-d',$sum);
|
|
return $dateTo;
|
|
}
|
|
|
|
public function getData_LogNotifikasi_byNOTIFIKASI($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('log_notifikasi a');
|
|
$this->db->join('notifikasi b', 'b.ID_NOTIFIKASI=a.NOTIFIKASI_ID');
|
|
$this->db->join('daftar_salesvisit c', 'c.ID_DSAV=b.DSAV_ID','left');
|
|
$this->db->join('sales_visit d', 'd.ID_SAV=c.SAV_ID','left');
|
|
$this->db->where(['a.ID_LOG_NOTIFIKASI' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_LogNotifikasi_byKARYAWAN_status1($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('log_notifikasi a');
|
|
$this->db->join('notifikasi b', 'b.ID_NOTIFIKASI=a.NOTIFIKASI_ID');
|
|
$this->db->where(['a.KARYAWAN_ID' => $id]);
|
|
$this->db->where('a.STATUS=1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_HistoriNotifikasi_byKARYAWAN_orderDESC_limit1($id)
|
|
{
|
|
$tgl = date('Y-m-d');
|
|
$this->db->select('*,DATE_FORMAT(TGL_HNF,"%d/%m/%Y") as TANGGAL');
|
|
$this->db->from('histori_notifikasi');
|
|
$this->db->where(['KARYAWAN_ID' => $id]);
|
|
$this->db->where(['TGL_HNF' => $tgl]);
|
|
$this->db->order_by('ID_HNF DESC');
|
|
$this->db->limit('1');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_SalesVisit_byID($id)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('sales_visit');
|
|
$this->db->where(['ID_SAV' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataReminder($tgl, $id_karyawan)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('log_notifikasi a');
|
|
$this->db->join('notifikasi b', 'b.ID_NOTIFIKASI=a.NOTIFIKASI_ID');
|
|
$this->db->where('a.KARYAWAN_ID=', $id_karyawan);
|
|
$this->db->where('b.TGL_NOTIFIKASI=', $tgl);
|
|
$this->db->where('b.JENIS_NOTIFIKASI=4');
|
|
$this->db->order_by('a.ID_LOG_NOTIFIKASI', 'DESC');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getIdNotif($jenis, $reminder)
|
|
{
|
|
$this->db->select('ID_NOTIFIKASI');
|
|
$this->db->from('notifikasi');
|
|
$this->db->where(['JENIS_NOTIFIKASI' => $jenis, 'KET_NOTIFIKASI' => $reminder]);
|
|
$this->db->order_by('ID_NOTIFIKASI', 'DESC');
|
|
$this->db->limit(1);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function updateLogNotif($id_log, $data, $batch = false)
|
|
{
|
|
if ($batch === false) {
|
|
$insert = $this->db->update('log_notifikasi', $data, array('ID_LOG_NOTIFIKASI' => $id_log));
|
|
} else {
|
|
$insert = $this->db->update_batch('log_notifikasi', $data, 'ID_LOG_NOTIFIKASI');
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|