copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,332 @@
|
||||
<?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 ManageKBHda extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelCorp', 'Corp');
|
||||
$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);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$datHutang = $this->Supplier->getDataHutangDagang();
|
||||
$datSupplier = $this->Supplier->getDataSupplier();
|
||||
$datCorp = $this->Corp->getDataCorp();
|
||||
$data = [
|
||||
'sidebar' => "set data",
|
||||
'navChild' => "",
|
||||
'hutang' => $datHutang,
|
||||
'supplier' => $datSupplier,
|
||||
'corp' => $datCorp
|
||||
];
|
||||
|
||||
$this->load->view('proses/SetKBHda', $data);
|
||||
}
|
||||
|
||||
public function kodeHutangDagang() {
|
||||
$kk = $this->Supplier->getKodeHDA();
|
||||
if (is_array($kk) || is_object($kk)) {
|
||||
foreach ($kk as $row) {
|
||||
if ($row['KODE'] == NULL) {
|
||||
return "HDA/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 = "HDA/000000";
|
||||
$data = substr($data, 0, $panjang) . $str;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function kodePembelian() {
|
||||
$kk = $this->Supplier->getKodePembelian();
|
||||
if (is_array($kk) || is_object($kk)) {
|
||||
foreach ($kk as $row) {
|
||||
if ($row['KODE'] == NULL) {
|
||||
return "PB/000001";
|
||||
} else {
|
||||
$str = (string) $row['KODE'];
|
||||
$panjang = 6;
|
||||
$data = substr($str, 3, $panjang);
|
||||
|
||||
$ko = (int) $data + 1;
|
||||
$str = (string) $ko;
|
||||
|
||||
$panjang = 9 - strlen($str);
|
||||
$data = "PB/000000";
|
||||
$data = substr($data, 0, $panjang) . $str;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$method = $this->input->post('method');
|
||||
$id = $this->input->post('id_hda');
|
||||
$id_supplier = $this->input->post('id_supplier');
|
||||
$id_corp = $this->input->post('id_corp');
|
||||
$nominal_hda = $this->input->post('nominal_hda');
|
||||
$tgl_invoicebeli = $this->input->post('tgl_invoicebeli');
|
||||
$invoice_pembelian = $this->input->post('invoice_pembelian');
|
||||
$kode_hda = $this->kodeHutangDagang();
|
||||
$kode_pembelian = $this->kodePembelian();
|
||||
$input = [
|
||||
'KODE_PEMBELIAN' => $kode_pembelian,
|
||||
'CORP_ID' => $id_corp,
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'INVOICE_PEMBELIAN' => $invoice_pembelian,
|
||||
'TGL_INVOICEBELI' => $tgl_invoicebeli,
|
||||
'STATUS_PEMBELIAN' => '0'
|
||||
];
|
||||
$action = $this->Supplier->create('pembelian', $input);
|
||||
$id_pembelian = $this->Supplier->getIDPembelian();
|
||||
$id_pembelian = $id_pembelian[0]['ID_PEMBELIAN'];
|
||||
$input = [
|
||||
'KODE_HDA' => $kode_hda,
|
||||
'PEMBELIAN_ID' => $id_pembelian,
|
||||
'NOMINAL_HDA' => $nominal_hda,
|
||||
'BLOCKCON' => '0'
|
||||
];
|
||||
$action = $this->Supplier->create('hutang_dagang', $input);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier+$nominal_hda;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
$hutang_corp = $this->Supplier->getDataCorp($id_corp);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp+$nominal_hda;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update, 'ID_CORP',$id_corp);
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_hda;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
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_hda = $this->input->post('id_hda');
|
||||
$id_corp = $this->input->post('id_corp');
|
||||
$id_supplier = $this->input->post('id_suppliered');
|
||||
$nominal_hda = $this->input->post('nominal_hdaed');
|
||||
$tgl_invoicebeli = $this->input->post('tgl_invoicebelied');
|
||||
$invoice_pembelian = $this->input->post('invoice_pembelianed');
|
||||
|
||||
$pembanding = $this->Supplier->getDataPembelian($id_hda);
|
||||
$supplier_id = $pembanding[0]['SUPPLIER_ID'];
|
||||
$corp_id = $pembanding[0]['CORP_ID'];
|
||||
|
||||
if ($id_supplier==$supplier_id) {
|
||||
$nominal = $pembanding[0]['NOMINAL_HDA'];
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier-$nominal;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$id_supplier);
|
||||
$hutang_corp = $this->Supplier->getDataCorp($id_corp);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp-$nominal;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update, 'ID_CORP',$id_corp);
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_hda;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
$id_pembelian = $this->Supplier->getDataPembelian($id_hda);
|
||||
$id_pembelian = $id_pembelian[0]['PEMBELIAN_ID'];
|
||||
$update = [
|
||||
'CORP_ID' => $id_corp,
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'INVOICE_PEMBELIAN' => $invoice_pembelian,
|
||||
'TGL_INVOICEBELI' => $tgl_invoicebeli
|
||||
];
|
||||
$action = $this->Supplier->update('pembelian', $update,'ID_PEMBELIAN',$id_pembelian);
|
||||
$update = [
|
||||
'NOMINAL_HDA' => $nominal_hda
|
||||
];
|
||||
$action = $this->Supplier->update('hutang_dagang', $update,'ID_HDA',$id_hda);
|
||||
$hutang_corp = $this->Supplier->getDataCorp($id_corp);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp+$nominal_hda;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update,'ID_CORP',$id_corp);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier+$nominal_hda;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update,'ID_SUPPLIER',$id_supplier);
|
||||
} else {
|
||||
$nominal = $pembanding[0]['NOMINAL_HDA'];
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($supplier_id);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier-$nominal;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER',$supplier_id);
|
||||
$hutang_corp = $this->Supplier->getDataCorp($corp_id);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp-$nominal;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update, 'ID_CORP',$corp_id);
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai+$nominal_hda;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
$id_pembelian = $this->Supplier->getDataPembelian($id_hda);
|
||||
$id_pembelian = $id_pembelian[0]['PEMBELIAN_ID'];
|
||||
$update = [
|
||||
'CORP_ID' => $id_corp,
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'INVOICE_PEMBELIAN' => $invoice_pembelian,
|
||||
'TGL_INVOICEBELI' => $tgl_invoicebeli
|
||||
];
|
||||
$action = $this->Supplier->update('pembelian', $update,'ID_PEMBELIAN',$id_pembelian);
|
||||
$update = [
|
||||
'NOMINAL_HDA' => $nominal_hda
|
||||
];
|
||||
$action = $this->Supplier->update('hutang_dagang', $update,'ID_HDA',$id_hda);
|
||||
$hutang_corp = $this->Supplier->getDataCorp($id_corp);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp+$nominal_hda;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update,'ID_CORP',$id_corp);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier+$nominal_hda;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update,'ID_SUPPLIER',$id_supplier);
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
//Step Ambil Data Lama
|
||||
$datahutang = $this->Supplier->getDataPembelian($id);
|
||||
$id_pembelian = $datahutang[0]['PEMBELIAN_ID'];
|
||||
$id_supplier = $datahutang[0]['SUPPLIER_ID'];
|
||||
$id_corp = $datahutang[0]['CORP_ID'];
|
||||
$nominal_hda = $datahutang[0]['NOMINAL_HDA'];
|
||||
$hutang_corp = $this->Supplier->getDataCorp($id_corp);
|
||||
$hutang_corp = $hutang_corp[0]['HUTANG_CORP'];
|
||||
$hutang_corp = $hutang_corp-$nominal_hda;
|
||||
$update = [
|
||||
'HUTANG_CORP' => $hutang_corp
|
||||
];
|
||||
$action = $this->Supplier->update('corp', $update, 'ID_CORP', $id_corp);
|
||||
$piutang_supplier = $this->Supplier->getDataSupplier($id_supplier);
|
||||
$piutang_supplier = $piutang_supplier[0]['PIUTANG_SUPPLIER'];
|
||||
$piutang_supplier = $piutang_supplier-$nominal_hda;
|
||||
$update = [
|
||||
'PIUTANG_SUPPLIER' => $piutang_supplier
|
||||
];
|
||||
$action = $this->Supplier->update('supplier', $update, 'ID_SUPPLIER', $id_supplier);
|
||||
$nilai = $this->Neraca->getDataNeraca(15);
|
||||
$nilai = $nilai[0]['NILAI_NERACA'];
|
||||
$nilai_neraca = $nilai-$nominal_hda;
|
||||
$id_neraca = 15;
|
||||
$update = [
|
||||
'NILAI_NERACA' => $nilai_neraca
|
||||
];
|
||||
$action = $this->Neraca->update('neraca', $update, 'ID_NERACA',$id_neraca);
|
||||
|
||||
//Step Hapus Data
|
||||
$action = $this->Supplier->delete('pembelian',$id_pembelian,'ID_PEMBELIAN');
|
||||
$action = $this->Supplier->delete('hutang_dagang',$id,'ID_HDA');
|
||||
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user