copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
use Restserver\Libraries\REST_Controller;
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
require APPPATH . 'libraries/REST_Controller.php';
|
||||
require APPPATH . 'libraries/Format.php';
|
||||
|
||||
class ManageKBDpj extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelPelanggan', 'Pelanggan');
|
||||
$this->load->model('ModelNeraca', 'Neraca');
|
||||
$this->load->library(['datatables', 'form_validation']);
|
||||
$this->form_validation->set_error_delimiters('', '');
|
||||
}
|
||||
public function output_json($data, $encode = true)
|
||||
{
|
||||
if ($encode) $data = json_encode($data);
|
||||
$this->output->set_content_type('application/json')->set_output($data);
|
||||
}
|
||||
|
||||
//Step One, Create Set Data
|
||||
public function index() {
|
||||
|
||||
$datPelanggan = $this->Pelanggan->getDataPelangganDpj();
|
||||
$datDpj = $this->Pelanggan->getDataDpPenjualan();
|
||||
$data = [
|
||||
'sidebar' => "set data",
|
||||
'navChild' => "",
|
||||
'pelanggan' => $datPelanggan,
|
||||
'dpj' => $datDpj
|
||||
];
|
||||
|
||||
$this->load->view('proses/SetKBDpj', $data);
|
||||
}
|
||||
|
||||
public function kodeDPJual() {
|
||||
$kk = $this->Pelanggan->getKodeDPJ();
|
||||
if (is_array($kk) || is_object($kk)) {
|
||||
foreach ($kk as $row) {
|
||||
if ($row['KODE'] == null) {
|
||||
return "DPJ/000001";
|
||||
} else {
|
||||
$str = (string) $row['KODE'];
|
||||
$panjang = 6;
|
||||
$data = substr($str, 4, $panjang);
|
||||
|
||||
$ko = (int) $data + 1;
|
||||
$str = (string) $ko;
|
||||
|
||||
$panjang = 10 - strlen($str);
|
||||
$data = "DPJ/000000";
|
||||
$data = substr($data, 0, $panjang) . $str;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$method = $this->input->post('method');
|
||||
$id = $this->input->post('id_dpj');
|
||||
$id_pelanggan = $this->input->post('id_pelanggan');
|
||||
$nominal_dpj = $this->input->post('nominal_dpj');
|
||||
$kode_dpj = $this->KodeDPJual();
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(19);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_dpj;
|
||||
$id_neraca = 19;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$input = [
|
||||
'PELANGGAN_ID' => $id_pelanggan,
|
||||
'KODE_DPJ' => $kode_dpj,
|
||||
'KODE_BUKTI' => "SETDATA",
|
||||
'NOMINAL_DPJ' => $nominal_dpj,
|
||||
'BLOCKCON' => '0'
|
||||
];
|
||||
$action = $this->Pelanggan->create('dp_penjualan', $input);
|
||||
|
||||
$pelanggan = $this->Pelanggan->getDataPelanggan($id_pelanggan);
|
||||
$saldo_pelanggan = $pelanggan[0]['SALDO_PELANGGAN'];
|
||||
$saldo_pelanggan = $saldo_pelanggan+$nominal_dpj;
|
||||
$update = [
|
||||
'SALDO_PELANGGAN' => $saldo_pelanggan
|
||||
];
|
||||
$action = $this->Pelanggan->update('pelanggan', $update, 'ID_PELANGGAN',$id_pelanggan);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'dilakukan');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'dilakukan');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$method = $this->input->post('method');
|
||||
$id_dpj = $this->input->post('id_dpj');
|
||||
$nominal_dpj = $this->input->post('nominal_dpjed');
|
||||
|
||||
$dpj = $this->Pelanggan->getDataDpj($id_dpj);
|
||||
$nominal = $dpj[0]['NOMINAL_DPJ'];
|
||||
$id_pelanggan = $dpj[0]['PELANGGAN_ID'];
|
||||
$nilai = $this->Neraca->getDataNeraca(19);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 19;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$pelanggan = $this->Pelanggan->getDataPelanggan($id_pelanggan);
|
||||
$saldo_pelanggan = $pelanggan[0]['SALDO_PELANGGAN'];
|
||||
$saldo_pelanggan = $saldo_pelanggan-$nominal;
|
||||
$update = [
|
||||
'SALDO_PELANGGAN' => $saldo_pelanggan
|
||||
];
|
||||
$action = $this->Pelanggan->update('pelanggan', $update, 'ID_PELANGGAN',$id_pelanggan);
|
||||
|
||||
$update = [
|
||||
'NOMINAL_DPJ' => $nominal_dpj
|
||||
];
|
||||
$action = $this->Pelanggan->update('dp_penjualan', $update, 'ID_DPJ',$id_dpj);
|
||||
|
||||
$pelanggan = $this->Pelanggan->getDataPelanggan($id_pelanggan);
|
||||
$saldo_pelanggan = $pelanggan[0]['SALDO_PELANGGAN'];
|
||||
$saldo_pelanggan = $saldo_pelanggan+$nominal_dpj;
|
||||
$update = [
|
||||
'SALDO_PELANGGAN' => $saldo_pelanggan
|
||||
];
|
||||
$action = $this->Pelanggan->update('pelanggan', $update, 'ID_PELANGGAN',$id_pelanggan);
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(19);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_dpj;
|
||||
$id_neraca = 19;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'diubah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'diubah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function hapus() {
|
||||
$id = $this->input->post('id');
|
||||
|
||||
$dpj = $this->Pelanggan->getDataDpj($id);
|
||||
$nominal = $dpj[0]['NOMINAL_DPJ'];
|
||||
$id_pelanggan = $dpj[0]['PELANGGAN_ID'];
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(19);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 19;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$pelanggan = $this->Pelanggan->getDataPelanggan($id_pelanggan);
|
||||
$saldo_pelanggan = $pelanggan[0]['SALDO_PELANGGAN'];
|
||||
$saldo_pelanggan = $saldo_pelanggan-$nominal;
|
||||
$update = [
|
||||
'SALDO_PELANGGAN' => $saldo_pelanggan
|
||||
];
|
||||
$action = $this->Pelanggan->update('pelanggan', $update, 'ID_PELANGGAN',$id_pelanggan);
|
||||
|
||||
$action = $this->Pelanggan->delete('dp_penjualan',$id,'ID_DPJ');
|
||||
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user