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 ManageKBDpb extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelSupplier', 'Supplier');
|
||||
$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() {
|
||||
|
||||
$datDpb = $this->Supplier->getDataDpPembelian();
|
||||
$datSupplier = $this->Supplier->getDataSupplierDpb();
|
||||
$data = [
|
||||
'sidebar' => "set data",
|
||||
'navChild' => "",
|
||||
'dpb' => $datDpb,
|
||||
'supplier' => $datSupplier
|
||||
];
|
||||
|
||||
$this->load->view('proses/SetKBDpb', $data);
|
||||
}
|
||||
|
||||
public function kodeDPBeli() {
|
||||
$kk = $this->Supplier->getKodeDPB();
|
||||
if (is_array($kk) || is_object($kk)) {
|
||||
foreach ($kk as $row) {
|
||||
if ($row['KODE'] == null) {
|
||||
return "DPB/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 = "DPB/000000";
|
||||
$data = substr($data, 0, $panjang) . $str;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$method = $this->input->post('method');
|
||||
$id = $this->input->post('id_dpb');
|
||||
$id_supplier = $this->input->post('id_supplier');
|
||||
$nominal_dpb = $this->input->post('nominal_dpb');
|
||||
$kode_dpb = $this->KodeDPBeli();
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(7);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_dpb;
|
||||
$id_neraca = 7;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$input = [
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'KODE_DPB' => $kode_dpb,
|
||||
'KODE_BUKTI' => "SETDATA",
|
||||
'NOMINAL_DPB' => $nominal_dpb,
|
||||
'BLOCKCON' => '0'
|
||||
];
|
||||
$action = $this->Supplier->create('dp_pembelian', $input);
|
||||
|
||||
$supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$saldo_supplier = $supplier[0]['SALDO_SUPPLIER'];
|
||||
$saldo_supplier = $saldo_supplier+$nominal_dpb;
|
||||
$update = [
|
||||
'SALDO_SUPPLIER' => $saldo_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
|
||||
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_dpb = $this->input->post('id_dpb');
|
||||
$nominal_dpb = $this->input->post('nominal_dpbed');
|
||||
|
||||
$dpb = $this->Supplier->getDataDpb($id_dpb);
|
||||
$nominal = $dpb[0]['NOMINAL_DPB'];
|
||||
$id_supplier = $dpb[0]['SUPPLIER_ID'];
|
||||
$nilai = $this->Neraca->getDataNeraca(7);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 7;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$saldo_supplier = $supplier[0]['SALDO_SUPPLIER'];
|
||||
$saldo_supplier = $saldo_supplier-$nominal;
|
||||
$update = [
|
||||
'SALDO_SUPPLIER' => $saldo_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
|
||||
$update = [
|
||||
'NOMINAL_DPB' => $nominal_dpb
|
||||
];
|
||||
$action = $this->Supplier->update('dp_pembelian', $update, 'ID_DPB',$id_dpb);
|
||||
|
||||
$supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$saldo_supplier = $supplier[0]['SALDO_SUPPLIER'];
|
||||
$saldo_supplier = $saldo_supplier+$nominal_dpb;
|
||||
$update = [
|
||||
'SALDO_SUPPLIER' => $saldo_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(7);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_dpb;
|
||||
$id_neraca = 7;
|
||||
$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');
|
||||
|
||||
$dpb = $this->Supplier->getDataDpb($id);
|
||||
$nominal = $dpb[0]['NOMINAL_DPB'];
|
||||
$id_supplier = $dpb[0]['SUPPLIER_ID'];
|
||||
|
||||
$nilai = $this->Neraca->getDataNeraca(7);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 7;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
$supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$saldo_supplier = $supplier[0]['SALDO_SUPPLIER'];
|
||||
$saldo_supplier = $saldo_supplier-$nominal;
|
||||
$update = [
|
||||
'SALDO_SUPPLIER' => $saldo_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
|
||||
$action = $this->Supplier->delete('dp_pembelian',$id,'ID_DPB');
|
||||
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user