181 lines
7.3 KiB
PHP
181 lines
7.3 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelDpPenjualan 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 getDataDpPenjualan($id=null){
|
|
if ($id === null) {
|
|
$this->db->select('*,a.KODE_BUKTI AS KB,CONCAT(DATE_FORMAT(a.TGL_DPJ,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT,CONCAT("Rp ",FORMAT(b.SALDO_PELANGGAN,2)) as SALDO,CONCAT("Rp ",FORMAT(b.HUTANG_PELANGGAN,2)) as HUTANG');
|
|
$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->join('detail_dpj d','d.DPJ_ID=a.ID_DPJ','left');
|
|
$this->db->where('a.STATUS_DPJ is NULL');
|
|
$this->db->group_by('a.ID_DPJ');
|
|
}else{
|
|
$this->db->select('*,a.KODE_BUKTI AS KB,CONCAT(DATE_FORMAT(a.TGL_DPJ,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT,CONCAT("Rp ",FORMAT(b.SALDO_PELANGGAN,2)) as SALDO,CONCAT("Rp ",FORMAT(b.HUTANG_PELANGGAN,2)) as HUTANG');
|
|
$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->join('detail_dpj d','d.DPJ_ID=a.ID_DPJ','left');
|
|
$this->db->where('a.STATUS_DPJ is NULL');
|
|
$this->db->where(['a.ID_DPJ' => $id]);
|
|
$this->db->group_by('a.ID_DPJ');
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDpPenjualanDetail($id=null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT');
|
|
$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->join('detail_dpj d','d.DPJ_ID=a.ID_DPJ','left');
|
|
$this->db->where('a.NOMINAL_DPJ!=a.BLOCKCON');
|
|
$this->db->group_by('a.ID_DPJ');
|
|
}else{
|
|
$this->db->select('*,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT');
|
|
$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->join('detail_dpj d','d.DPJ_ID=a.ID_DPJ','left');
|
|
$this->db->where('a.NOMINAL_DPJ!=a.BLOCKCON');
|
|
$this->db->where(['a.ID_DPJ' => $id]);
|
|
$this->db->group_by('a.ID_DPJ');
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
//Step Two, Input Transaksi
|
|
public function getDataDetailDpPenjualan($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_DPJ,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT');
|
|
$this->db->from('dp_penjualan a');
|
|
$this->db->join('detail_dpj b','b.DPJ_ID=a.ID_DPJ');
|
|
$this->db->join('piutang_dagang c','c.ID_PDA=b.PDA_ID','left');
|
|
$this->db->join('penjualan d','d.ID_PENJUALAN=c.PENJUALAN_ID','left');
|
|
$this->db->join('pelanggan e','e.ID_PELANGGAN=d.PELANGGAN_ID','left');
|
|
$this->db->join('kota f','f.ID_KOTA=e.KOTA_ID','left');
|
|
$this->db->group_by('b.ID_DDPJ');
|
|
}else{
|
|
$this->db->select('*,CONCAT(DATE_FORMAT(a.TGL_DPJ,"%d/%m/%Y")) AS WAKTU,CONCAT("Rp ",FORMAT(a.NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(a.BLOCKCON,2)) as KREDIT');
|
|
$this->db->from('dp_penjualan a');
|
|
$this->db->join('detail_dpj b','b.DPJ_ID=a.ID_DPJ');
|
|
$this->db->join('piutang_dagang c','c.ID_PDA=b.PDA_ID','left');
|
|
$this->db->join('penjualan d','d.ID_PENJUALAN=c.PENJUALAN_ID','left');
|
|
$this->db->join('pelanggan e','e.ID_PELANGGAN=d.PELANGGAN_ID','left');
|
|
$this->db->join('kota f','f.ID_KOTA=e.KOTA_ID','left');
|
|
$this->db->where(['a.ID_DPJ' => $id]);
|
|
$this->db->group_by('b.ID_DDPJ');
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getTitleDPJ($id) {
|
|
$this->db->select('KODE_DPJ,CONCAT("Rp ",FORMAT(NOMINAL_DPJ,2)) as DEBIT,CONCAT("Rp ",FORMAT(BLOCKCON,2)) as KREDIT');
|
|
$this->db->from('dp_penjualan');
|
|
$this->db->where(['ID_DPJ' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPiutangDagang($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('piutang_dagang');
|
|
$this->db->where(['ID_PDA' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDpPenjualan($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('dp_penjualan');
|
|
$this->db->where(['ID_DPJ' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDDPJ($id) {
|
|
$this->db->select('*');
|
|
$this->db->from('detail_dpj');
|
|
$this->db->where(['ID_DDPJ' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getIDDDPJ() {
|
|
$this->db->select_max('ID_DDPJ');
|
|
$this->db->from('detail_dpj');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getIDDPDA() {
|
|
$this->db->select_max('ID_DPDA');
|
|
$this->db->from('detail_pda');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataDPJ($id) {
|
|
$this->db->select('b.NOMINAL_DPJ,b.BLOCKCON');
|
|
$this->db->from('detail_dpj a');
|
|
$this->db->join('dp_penjualan b','b.ID_DPJ=a.DPJ_ID','left');
|
|
$this->db->where(['ID_DDPJ' => $id]);
|
|
$this->db->group_by('ID_DDPJ');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPDA($id) {
|
|
$this->db->select('b.NOMINAL_PDA,b.BLOCKCON');
|
|
$this->db->from('detail_pda a');
|
|
$this->db->join('piutang_dagang b','b.ID_PDA=a.PDA_ID','left');
|
|
$this->db->where(['ID_DPDA' => $id]);
|
|
$this->db->group_by('ID_DPDA');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataPelanggan($id) {
|
|
$this->db->select('HUTANG_PELANGGAN,SALDO_PELANGGAN');
|
|
$this->db->from('pelanggan');
|
|
$this->db->where(['ID_PELANGGAN' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeDetailDPJ() {
|
|
$this->db->select('MAX(KODE_DDPJ) AS KODE');
|
|
$this->db->from('detail_dpj');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getKodeDetailPDA() {
|
|
$this->db->select('MAX(KODE_DPDA) AS KODE');
|
|
$this->db->from('detail_pda');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function hapusDetailPda($id){
|
|
$this->db->where(['KODE_BUKTI' => $id]);
|
|
$this->db->delete('detail_pda');
|
|
}
|
|
}
|
|
?>
|