2369 lines
78 KiB
PHP
2369 lines
78 KiB
PHP
<?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 ManagePembelian extends CI_Controller {
|
|
function __construct(){
|
|
parent::__construct();
|
|
$this->load->model('ModelDashboard', 'Dashboard');
|
|
$this->load->model('ModelPembelian', 'Pembelian');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
$this->Dashboard->ceklogin();
|
|
}
|
|
|
|
public function output_json($data, $encode = true){
|
|
if ($encode) $data = json_encode($data);
|
|
$this->output->set_content_type('application/json')->set_output($data);
|
|
}
|
|
|
|
//Controller Transaksi Pembelian
|
|
public function dataBarang_Gudang_A1() { // [1]
|
|
$id_pembelian = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$pembelian = $this->Pembelian->getData_Pembelian_Null($id_pembelian, $level);
|
|
$datCorp = $this->Pembelian->getData_Corp_forPembelian($level);
|
|
$datSupplier = $this->Pembelian->getData_Supplier_byID();
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step1",
|
|
'pembelian' => $pembelian,
|
|
'corp' => $datCorp,
|
|
'supplier' => $datSupplier,
|
|
'tgl' => $tgl
|
|
];
|
|
$this->load->view('proses/PembelianBarang_Gudang_A1', $data);
|
|
}
|
|
|
|
public function loginrevisi_Pembelian_GA1() { // [2]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$datKaryawan = $this->Pembelian->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN GUDANG") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN ITP") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMINISTRATOR") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function kodePembelian() { // [3]
|
|
$kk = $this->Pembelian->getKode_Pembelian();
|
|
$tgl = date('y/m');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "PB/$tgl/00001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 3, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "PB/$tgl/00001";
|
|
} else {
|
|
$panjang = 5;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 14 - strlen($str);
|
|
$data = "PB/$tgl/00000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function simpanbarang_GA1() { // [4]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id');
|
|
$id_supplier = $this->input->post('id_supplier');
|
|
$id_corp = $this->input->post('id_corp');
|
|
$sj_pembelian = $this->input->post('sj_pembelian');
|
|
$tgl_sjbeli = $this->input->post('tgl_sjbeli');
|
|
$kode_pembelian = $this->kodePembelian();
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Duplikasi Nomor SJ
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID();
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
foreach ($datPembelian as $key) {
|
|
if ($key['SJ_PEMBELIAN']==$sj_pembelian) {
|
|
$this->session->set_flashdata('sj_duplicate', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check Tanggal lebih dari hari ini
|
|
if (strtotime($tgl_sjbeli)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set PPN Otomatis sesuai Standard Internal
|
|
if ($id_corp=="3" OR $id_corp=="5") {
|
|
$ppn_pembelian = '0';
|
|
} else if ($id_corp=="1" OR $id_corp=="2" OR $id_corp=="4") {
|
|
$ppn_pembelian = '11';
|
|
}
|
|
|
|
$input = [
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'CORP_ID' => $id_corp,
|
|
'TGL_SJBELI' => $tgl_sjbeli,
|
|
'SJ_PEMBELIAN' => $sj_pembelian,
|
|
'KODE_PEMBELIAN'=> $kode_pembelian,
|
|
'TGL_PEMBELIAN' => $tgl,
|
|
'PPN_PEMBELIAN' => $ppn_pembelian
|
|
];
|
|
$action = $this->Pembelian->create('pembelian', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahbarang_GA1() { // [5]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id_corp = $this->input->post('id_corped');
|
|
$id_supplier = $this->input->post('id_suppliered');
|
|
$sj_pembelian = $this->input->post('sj_pembelianed');
|
|
$tgl_sjbeli = $this->input->post('tgl_sjbelied');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Kondisi Data
|
|
$checkPembelian = $this->Pembelian->getData_Pembelian_Null($id_pembelian);
|
|
if ($checkPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Duplikasi Data
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_forSJ($id_pembelian, $sj_pembelian);
|
|
if ($datPembelian==TRUE) {
|
|
$this->session->set_flashdata('sj_duplicate', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Tanggal lebih dari hari ini
|
|
if (strtotime($tgl_sjbeli)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'CORP_ID' => $id_corp,
|
|
'TGL_SJBELI' => $tgl_sjbeli,
|
|
'TGL_PEMBELIAN' => $tgl,
|
|
'SJ_PEMBELIAN' => $sj_pembelian
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusbarang_GA1() { // [6]
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$tgl_now = date('Y-m-01');
|
|
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id_pembelian);
|
|
if (strtotime($datPembelian[0]['TGL_PEMBELIAN'])<strtotime($tgl_now)) {
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
$action = $this->Pembelian->delete('sn_beli', $key['ID_DB'], 'DB_ID');
|
|
}
|
|
$action = $this->Pembelian->delete('daftar_beli', $id_pembelian, 'PEMBELIAN_ID');
|
|
$action = $this->Pembelian->delete('pembelian', $id_pembelian, 'ID_PEMBELIAN');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'Void');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'Void');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
if ($datDb==TRUE) {
|
|
$this->session->set_flashdata('data_used_order', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($id_pembelian);
|
|
if ($datHda==TRUE) {
|
|
$this->session->set_flashdata('data_used_hutang', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('pembelian', $id_pembelian, 'ID_PEMBELIAN');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function dataBarang_Gudang_A2($id) { // [7]
|
|
$level = $this->session->userdata('level');
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$barang = $this->Pembelian->getData_Barang_status1_NonJasa($level);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
|
|
//Set Real Jumlah SN
|
|
$no = 0;
|
|
foreach ($pembelian as $key) {
|
|
$qtyReal = $this->Pembelian->getQtyReal_SnBeli_byDB($key['ID_DB']);
|
|
$pembelian[$no++] += ['REAL' => $qtyReal];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step1",
|
|
'pembelian' => $pembelian,
|
|
'id_pembelian' => $id,
|
|
'barang' => $barang,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
];
|
|
$this->load->view('proses/PembelianBarang_Gudang_A2', $data);
|
|
}
|
|
|
|
public function simpanbarang_GA2() { // [8]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id = $this->input->post('id_db');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_db = $this->input->post('qty_db');
|
|
|
|
//Check Duplikasi Kode Barang
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID_byBARANG($id_pembelian, $id_barang);
|
|
if ($datDb==TRUE) {
|
|
$this->session->set_flashdata('twin_item', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Nilai kurang dari atau sama dengan 0
|
|
if ($qty_db<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$input = [
|
|
'BARANG_ID' => $id_barang,
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'QTY_DB' => $qty_db
|
|
];
|
|
$action = $this->Pembelian->create('daftar_beli', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahbarang_GA2() { // [9]
|
|
$method = $this->input->post('method');
|
|
$id_db = $this->input->post('id_db');
|
|
$qty_db = $this->input->post('qty_dbed');
|
|
|
|
//Check Apakah SN yang diinput lebih besar dari Qty baru
|
|
$qtyReal = $this->Pembelian->getQtyReal_SnBeli_byDB($id_db);
|
|
if ($qtyReal>$qty_db) {
|
|
$this->session->set_flashdata('qty_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Nilai kurang dari atau sama dengan 0
|
|
if ($qty_db<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'QTY_DB' => $qty_db
|
|
];
|
|
$action = $this->Pembelian->update('daftar_beli', $update, 'ID_DB', $id_db);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusbarang_GA2() { // [10]
|
|
$id_db = $this->input->post('id_db');
|
|
|
|
//Check Konsistensi Data
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah terisi SN
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byDB($id_db);
|
|
if ($datSnBeli==TRUE) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('daftar_beli', $id_db, 'ID_DB');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function kuncibarang_GA2() { // [11]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$tgl = date('Y-m-d');
|
|
$tgl_lock = date('d/m/Y H:i:s');
|
|
|
|
//Check Konsistensi Data
|
|
$checkPembelian = $this->Pembelian->getData_Pembelian_Null($id_pembelian);
|
|
if ($checkPembelian==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePembelian/dataBarang_Gudang_A1');
|
|
}
|
|
|
|
//Check Apakah Semua SN sudah terisi
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$qtyReal = $this->Pembelian->getQtyReal_SnBeli_byDB($key['ID_DB']);
|
|
if ($qtyReal<$key['QTY_DB']) {
|
|
$this->session->set_flashdata('sn_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_PEMBELIAN' => '0',
|
|
'TGL_PEMBELIAN' => $tgl,
|
|
'LOCK_PEMBELIAN' => $tgl_lock,
|
|
'KAR_GUDANG_PEMBELIAN' => $id_karyawan
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePembelian/dataBarang_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePembelian/dataBarang_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataBarang_Gudang_A3($id) { // [12]
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byID($id);
|
|
$max = $this->Pembelian->getQtyReal_SnBeli_byDB($id);
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byBARANG($pembelian[0]['BARANG_ID']);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step1",
|
|
'pembelian' => $pembelian,
|
|
'snbeli' => $datSnBeli,
|
|
'id_db' => $id,
|
|
'qty' => $pembelian[0]['QTY_DB'],
|
|
'kode_barang' => $pembelian[0]['KODE_BARANG'],
|
|
'max' => $max,
|
|
];
|
|
$this->load->view('proses/PembelianBarang_Gudang_A3', $data);
|
|
}
|
|
|
|
public function viewSn_Pembelian_Aktif() { // [13]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Pembelian->getData_SnBeli_byDB($id);
|
|
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
|
}
|
|
|
|
public function viewSn_Pembelian_Limit() { // [14]
|
|
$id = $this->input->post('id');
|
|
$data = $this->Pembelian->getData_SnBeli_byDB($id);
|
|
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
|
}
|
|
|
|
public function simpanbarang_GA3() { // [15]
|
|
$id = $this->input->post('id_snb');
|
|
$id_db = $this->input->post('id_db');
|
|
$nama_snb = $this->input->post('nama_snb');
|
|
$nama_snb = strtoupper($nama_snb);
|
|
|
|
//Check apakah Nama SN sudah terpakai
|
|
$datSnStock1 = $this->Pembelian->getData_SnStock_SnBeli_byNAMA_AllStatus($nama_snb);
|
|
$datSnStock2 = $this->Pembelian->getData_SnIo_byNAMA_AllStatus($nama_snb);
|
|
if ($datSnStock1==TRUE OR $datSnStock2==TRUE) {
|
|
$value = 3;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
|
|
if ($value==3) {
|
|
$this->output_json(['value' => $value]);
|
|
} else if ($value==1) {
|
|
//Check apakah Kuantiti sudah sesuai
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID($id_db);
|
|
$qtyRealBefore = $this->Pembelian->getQtyReal_SnBeli_byDB($id_db);
|
|
if ($qtyRealBefore>=$datDb[0]['QTY_DB']) {
|
|
$this->output_json(['value' => 0]);
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNB' => $nama_snb,
|
|
'DB_ID' => $id_db
|
|
];
|
|
$action = $this->Pembelian->create('sn_beli', $input);
|
|
|
|
//Check apakah setelah ditambah, kuantiti sudah memenuhi
|
|
$qtyRealAfter = $this->Pembelian->getQtyReal_SnBeli_byDB($id_db);
|
|
if ($datDb[0]['QTY_DB']==$qtyRealAfter) {
|
|
$this->output_json(['value' => 2, 'id' => $id, 'nama_snb' => $nama_snb]);
|
|
$this->session->set_flashdata('quota_full', 'warning');
|
|
} else if ($action) {
|
|
$this->output_json(['value' => 1, 'id' => $id, 'nama_snb' => $nama_snb]);
|
|
} else {
|
|
$this->output_json(['value' => 0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapusbarang_GA3() { // [16]
|
|
$id = $this->input->post('id_snb');
|
|
|
|
$datSnb = $this->Pembelian->getData_SnBeli_byID($id);
|
|
$qtyReal = $this->Pembelian->getQtyReal_SnBeli_byDB($datSnb[0]['DB_ID']);
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID($datSnb[0]['DB_ID']);
|
|
|
|
$action = $this->Pembelian->delete('sn_beli', $id, 'ID_SNB');
|
|
|
|
if ($qtyReal==$datDb[0]['QTY_DB']){
|
|
$this->output_json(['value' => 2]);
|
|
$this->session->set_flashdata('quota_free', 'warning');
|
|
} else {
|
|
if ($action) {
|
|
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
|
} else {
|
|
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function dataBarang_Keuangan_A1() { // [17]
|
|
$id_pembelian = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$pembelian = $this->Pembelian->getData_Pembelian_0($id_pembelian, $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step2",
|
|
'pembelian' => $pembelian,
|
|
'count' => count($pembelian),
|
|
];
|
|
$this->load->view('proses/PembelianBarang_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function loginrevisi_Pembelian_KA1() { // [18]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$datKaryawan = $this->Pembelian->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN KEUANGAN") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN ITP") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMINISTRATOR") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function dataBarang_Keuangan_A2($id) { // [19]
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
$datSupplier = $this->Pembelian->getData_Supplier_byID();
|
|
$tgl = date('Y-m-d');
|
|
|
|
// Mencari Nilai Hutang
|
|
$kredit_hda = 0;
|
|
foreach ($pembelian as $key) {
|
|
$hutang = $key['HARGA_DB']*$key['QTY_DB'];
|
|
$kredit_hda = $kredit_hda+$hutang;
|
|
}
|
|
|
|
// Set Tampilan Nilai
|
|
$bruto = $kredit_hda;
|
|
$ppn_hda = $kredit_hda*($datPembelian[0]['PPN_PEMBELIAN']/100);
|
|
$kredit_hda = $kredit_hda*(($datPembelian[0]['PPN_PEMBELIAN']+100)/100);
|
|
$kredit_hda = round($kredit_hda);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step2",
|
|
'pembelian' => $pembelian,
|
|
'supplier' => $datSupplier,
|
|
'id_pembelian' => $id,
|
|
'bruto' => $bruto,
|
|
'kredit_hda' => $kredit_hda,
|
|
'ppn_hda' => $ppn_hda,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER'],
|
|
'nama_kota' => $datPembelian[0]['NAMA_KOTA'],
|
|
'sj_pembelian' => $datPembelian[0]['SJ_PEMBELIAN'],
|
|
'tgl' => $tgl
|
|
];
|
|
$this->load->view('proses/PembelianBarang_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function simpanbarang_KA2() { // [20]
|
|
$method = $this->input->post('method');
|
|
$id_db = $this->input->post('id_db');
|
|
$harga_db = $this->input->post('harga_db');
|
|
|
|
//Check Konsistensi Data
|
|
$checkDb = $this->Pembelian->getData_DaftarBeli_byID($id_db);
|
|
if ($checkDb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_db = str_replace(',', '.', $harga_db);
|
|
|
|
//Check apakah Nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_db);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_db = 0;
|
|
}
|
|
|
|
//Check apakah nilai kurang dari 0
|
|
if ($harga_db<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DB' => $harga_db
|
|
];
|
|
$action = $this->Pembelian->update('daftar_beli', $update, 'ID_DB', $id_db);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusbarang_KA2() { // [21]
|
|
$method = $this->input->post('method');
|
|
$id_db = $this->input->post('id_db');
|
|
|
|
//Check Konsistensi Data
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DB' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('daftar_beli', $update, 'ID_DB', $id_db);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function setppn_KA2() { // [22]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id_supplier = $this->input->post('id_suppliered');
|
|
$ket_pembelian = $this->input->post('ket_pembelian');
|
|
$ppn_pembelian = $this->input->post('ppn_pembelian');
|
|
|
|
//Check apakah Nilai PPN bersifat Numeric
|
|
$check_nilai = is_numeric($ppn_pembelian);
|
|
if ($check_nilai==FALSE) {
|
|
$ppn_pembelian = 0;
|
|
}
|
|
|
|
//Check apakah Nilai Kurang dari 0 atau lebih besar dari 15
|
|
if ($ppn_pembelian<0 OR $ppn_pembelian>15) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Agar tidak ada Enter
|
|
$ket_pembelian = preg_replace('/\R+/', " " , $ket_pembelian);
|
|
|
|
$update = [
|
|
'PPN_PEMBELIAN' => $ppn_pembelian,
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'KET_PEMBELIAN' => $ket_pembelian
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diset');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diset');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kuncibarang_KA2() { // [23]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$inv_pembelian = $this->input->post('inv_pembelian');
|
|
$tgl_invbeli = $this->input->post('tgl_invbeli');
|
|
$fp_pembelian = $this->input->post('fp_pembelian');
|
|
$ket_hda = $this->input->post('ket_hda');
|
|
$kredit_hda = $this->input->post('kredit_hda');
|
|
$tgl = date('Y-m-d');
|
|
|
|
$inv_pembelian = strtoupper($inv_pembelian);
|
|
$fp_pembelian = strtoupper($fp_pembelian);
|
|
$ket_hda = preg_replace('/\R+/', " " , $ket_hda);
|
|
$ket_hda = strtoupper($ket_hda);
|
|
|
|
//Check Konsistensi Data
|
|
$checkPembelian = $this->Pembelian->getData_Pembelian_0($id_pembelian);
|
|
if ($checkPembelian==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePembelian/dataBarang_Keuangan_A1');
|
|
}
|
|
|
|
//Check Apakah Harga Sudah terisi
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['HARGA_DB']==NULL) {
|
|
$this->session->set_flashdata('price_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Check apakah Tanggal melebihi hari ini
|
|
if (strtotime($tgl_invbeli)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah ada Nomor Nota yang sama
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID();
|
|
foreach ($datPembelian as $key) {
|
|
if ($key['INV_PEMBELIAN']==$inv_pembelian) {
|
|
$this->session->set_flashdata('nota_duplicate', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
//Set Data
|
|
$datSupplier = $this->Pembelian->getData_Supplier_byID($checkPembelian[0]['SUPPLIER_ID']);
|
|
$tempo_invbeli = $this->Pembelian->addTempoDay($tgl_invbeli,$datSupplier[0]['TOP_SUPPLIER']);
|
|
|
|
$update = [
|
|
'INV_PEMBELIAN' => $inv_pembelian,
|
|
'TGL_INVBELI' => $tgl_invbeli,
|
|
'TEMPO_INVBELI' => $tempo_invbeli,
|
|
'FP_PEMBELIAN' => $fp_pembelian,
|
|
'KET_PEMBELIAN' => $ket_hda,
|
|
'TGL_PEMBELIAN' => $tgl,
|
|
'STATUS_PEMBELIAN' => '1'
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSn = $this->Pembelian->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSn as $dat) {
|
|
if ($checkPembelian[0]['CORP_ID']<=4) {
|
|
$gudang_snstock = 1;
|
|
} else if ($checkPembelian[0]['CORP_ID']>=5) {
|
|
$gudang_snstock = 2;
|
|
}
|
|
$input = [
|
|
'NAMA_SNSTOCK' => $dat['NAMA_SNB'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'GUDANG_SNSTOCK' => $gudang_snstock
|
|
];
|
|
$action = $this->Pembelian->create('sn_stock', $input);
|
|
$datSnStock = $this->Pembelian->getID_SNSTOCKMax();
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $key['KODE_PEMBELIAN'],
|
|
'SJ_HSN' => $key['SJ_PEMBELIAN'],
|
|
'INV_HSN' => $inv_pembelian,
|
|
'SUPPLIER_ID' => $key['SUPPLIER_ID'],
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Pembelian->create('histori_sn', $input);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($checkPembelian[0]['CORP_ID']<=4) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_DB'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_DB'];
|
|
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($checkPembelian[0]['CORP_ID']==5) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti+$key['QTY_DB'];
|
|
$itp = $itp_kuantiti+$key['QTY_DB'];
|
|
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
|
|
$nilai_hq = $key['HARGA_DB'] * $key['QTY_DB'];
|
|
$datHq = $this->Pembelian->getData_HistoriKuantiti_byBARANG_orderDESC_limit1($key['BARANG_ID']);
|
|
if ($datHq==FALSE) {
|
|
$persediaan_hq = $nilai_hq;
|
|
$sisa_hq = $key['QTY_DB'];
|
|
$avg_hq = $key['HARGA_DB'];
|
|
} else {
|
|
$sisa_hq = $key['QTY_DB']+$datHq[0]['SISA_HQ'];
|
|
$persediaan_hq = $nilai_hq+$datHq[0]['PERSEDIAAN_HQ'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
}
|
|
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $checkPembelian[0]['KODE_PEMBELIAN'],
|
|
'SJ_HQ' => $checkPembelian[0]['SJ_PEMBELIAN'],
|
|
'INV_HQ' => $inv_pembelian,
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'MASUK_HQ' => $key['QTY_DB'],
|
|
'KELUAR_HQ' => '0'
|
|
];
|
|
$action = $this->Pembelian->create('histori_kuantiti', $input);
|
|
}
|
|
|
|
$input = [
|
|
'SUPPLIER_ID' => $checkPembelian[0]['SUPPLIER_ID'],
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'TRANSAKSI_HDA' => '0',
|
|
'KODE_BUKTI' => $checkPembelian[0]['KODE_PEMBELIAN'],
|
|
'TGL_HDA' => $tgl,
|
|
'DEBET_HDA' => '0',
|
|
'KREDIT_HDA' => $kredit_hda,
|
|
'KET_HDA' => $ket_hda
|
|
];
|
|
$action = $this->Pembelian->create('hutang_dagang', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePembelian/dataBarang_Keuangan_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePembelian/dataBarang_Keuangan_A1');
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Retur
|
|
public function dataRetur_Gudang_A1() { // [24]
|
|
$datSupplier = $this->Pembelian->getData_Supplier_byID();
|
|
$id_pembelian = NULL;
|
|
$kondisi = $this->input->post('kondisi');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
|
|
if ($kondisi==NULL) {
|
|
$tanggal_awal = date('Y-m-01');
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$id_supplier = NULL;
|
|
$title = "Belum Terpilih*";
|
|
} else {
|
|
$id_supplier = $this->input->post('id_supplier');
|
|
$tanggal_awal = $this->input->post('tanggal_awal');
|
|
$tanggal_akhir = $this->input->post('tanggal_akhir');
|
|
//Isi Judul
|
|
if ($id_supplier=="") {
|
|
$title = "Semua Supplier";
|
|
} else {
|
|
$dataSupplier = $this->Pembelian->getData_Supplier_byID($id_supplier);
|
|
$nama_supplier = $dataSupplier[0]['NAMA_SUPPLIER'];
|
|
$nama_kota = $dataSupplier[0]['NAMA_KOTA'];
|
|
$title = "$nama_supplier ($nama_kota)";
|
|
}
|
|
}
|
|
|
|
$pembelian = $this->Pembelian->getData_Pembelian_1($id_pembelian, $level, $tanggal_awal, $tanggal_akhir, $id_supplier);
|
|
|
|
//Set Status Retur
|
|
$no = 0;
|
|
foreach ($pembelian as $key) {
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_byPEMBELIAN_byKARYAWAN_Null($key['ID_PEMBELIAN'], $id_karyawan);
|
|
if ($datRb==TRUE) {
|
|
$status = 1;
|
|
} else {
|
|
$status = 0;
|
|
}
|
|
$pembelian[$no++] += ['STATUS' => $status];
|
|
}
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "returbeli step1",
|
|
'pembelian' => $pembelian,
|
|
'supplier' => $datSupplier,
|
|
'id_supplier' => $id_supplier,
|
|
'tanggal_awal' => $tanggal_awal,
|
|
'tanggal_akhir' => $tanggal_akhir,
|
|
'title' => $title,
|
|
|
|
];
|
|
$this->load->view('proses/PembelianRetur_Gudang_A1', $data);
|
|
}
|
|
|
|
public function loginrevisi_ReturBeli_GA1() { // [25]
|
|
$username = $this->input->post('username');
|
|
$password = $this->input->post('password');
|
|
$datKaryawan = $this->Pembelian->getData_Karyawan_forLogin($username, $password);
|
|
|
|
if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN GUDANG") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GB1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMIN ITP") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GB1');
|
|
} else if ($datKaryawan == TRUE and $datKaryawan[0]['NAMA_JABATAN'] == "ADMINISTRATOR") {
|
|
$this->session->set_flashdata('username_pass_success', 'login');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GB1');
|
|
} else {
|
|
$this->session->set_flashdata('username_pass_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function dataRetur_Gudang_A2($id) { // [26]
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$pembelian = $this->Pembelian->getData_DaftarReturBeli_byPEMBELIAN_byKARYAWAN_byLEVEL_KODENull($id, $id_karyawan, $level);
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN_JENIS0($id, $level);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byPEMBELIAN($id);
|
|
|
|
//Set SN Retur Beli ke dalam Data DRB
|
|
$no = 0;
|
|
foreach ($pembelian as $key) {
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byDRB_RBNull($key['ID_DRB']);
|
|
$pembelian[$no++] += ['SN' => $datSnRb];
|
|
}
|
|
|
|
//Set ID Retur Beli untuk Kunci
|
|
if ($pembelian==NULL) {
|
|
$id_rb = NULL;
|
|
} else {
|
|
$id_rb = $pembelian[0]['RB_ID'];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "returbeli step1",
|
|
'pembelian' => $pembelian,
|
|
'id_pembelian' => $id,
|
|
'id_rb' => $id_rb,
|
|
'tgl' => $tgl,
|
|
'snb' => $datSnBeli,
|
|
'barang' => $datDb,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER'],
|
|
'sj_pembelian' => $datPembelian[0]['SJ_PEMBELIAN'],
|
|
'id_supplier' => $datPembelian[0]['SUPPLIER_ID']
|
|
];
|
|
$this->load->view('proses/PembelianRetur_Gudang_A2', $data);
|
|
}
|
|
|
|
public function simpanretur_GA2() { // [27]
|
|
$method = $this->input->post('method');
|
|
$id_drb = $this->input->post('id');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_drb = $this->input->post('qty_drb');
|
|
$tgl_input = $this->input->post('tgl_input');
|
|
$snretur = $this->input->post('snretur');
|
|
$jenis_drb = $this->input->post('jenis_drb');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check apakah Tanggal Melebihi hari Ini
|
|
if (strtotime($tgl_input)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah nilai benar.
|
|
if ($jenis_drb==0) {
|
|
if ($qty_drb<=0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
$sumDrb = $this->Pembelian->getSum_DaftarReturBeli_byPEMBELIAN_byBARANG($id_pembelian, $id_barang);
|
|
if ($key['BARANG_ID']==$id_barang) {
|
|
$total = $sumDrb[0]['TOTAL_DRB']+$qty_drb;
|
|
if ($total>$key['QTY_DB']) {
|
|
$this->session->set_flashdata('over_qty', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($id_barang);
|
|
if ($level == 0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$qty_drb) {
|
|
$this->session->set_flashdata('over_qty_stock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level == 0) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$qty_drb) {
|
|
$this->session->set_flashdata('over_qty_stock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
} else if ($jenis_drb==1) { //Check apakah SN belum terpakai.
|
|
foreach ($snretur as $key) {
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byID($key);
|
|
if ($datSnBeli[0]['STATUS_SNSTOCK']!=NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_byPEMBELIAN_byADMIN_Null($id_pembelian, $id_karyawan);
|
|
if ($datRb==FALSE) {
|
|
$input = [
|
|
'ADMIN_ID' => $id_karyawan,
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'TGL_INPUT' => $tgl_input,
|
|
'TGL_RB' => $tgl
|
|
];
|
|
$action = $this->Pembelian->create('retur_pembelian', $input);
|
|
|
|
$id_rb = $this->Pembelian->getID_RBMax();
|
|
$id_rb = $id_rb[0]['ID_RB'];
|
|
} else {
|
|
$id_rb = $datRb[0]['ID_RB'];
|
|
}
|
|
|
|
if ($jenis_drb==1) {
|
|
foreach ($snretur as $key) {
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byID($key);
|
|
$input = [
|
|
'RB_ID' => $id_rb,
|
|
'NAMA_SNRB' => $datSnBeli[0]['NAMA_SNSTOCK'],
|
|
'DB_ID' => $datSnBeli[0]['DB_ID']
|
|
];
|
|
$action = $this->Pembelian->create('sn_returbeli', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '2'
|
|
];
|
|
$action = $this->Pembelian->update('sn_stock', $update, 'NAMA_SNSTOCK', $datSnBeli[0]['NAMA_SNSTOCK']);
|
|
}
|
|
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byRB_groupBARANG($id_rb);
|
|
foreach ($datSnRb as $key) {
|
|
$qty = 0;
|
|
foreach ($snretur as $dat) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_bySNB_2($dat);
|
|
if ($datSnStock[0]['BARANG_ID']==$key['BARANG_ID']) {
|
|
$qty = $qty+1;
|
|
}
|
|
}
|
|
|
|
$checkDrb = $this->Pembelian->getData_DaftarReturBeli_byRB_byBARANG_byADMIN_Null($id_rb, $key['BARANG_ID'], $id_karyawan);
|
|
if ($checkDrb==TRUE) {
|
|
$qtyDrbNew = $qty + $checkDrb[0]['QTY_DRB'];
|
|
$update = [
|
|
'QTY_DRB' => $qtyDrbNew
|
|
];
|
|
$action = $this->Pembelian->update('daftar_returbeli', $update, 'ID_DRB', $checkDrb[0]['ID_DRB']);
|
|
} else {
|
|
$input = [
|
|
'RB_ID' => $id_rb,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DRB' => $qty,
|
|
'JENIS_DRB' => $jenis_drb,
|
|
];
|
|
$action = $this->Pembelian->create('daftar_returbeli', $input);
|
|
}
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti+$qty;
|
|
$pcm = $pcm_kuantiti-$qty;
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti+$qty;
|
|
$itp = $itp_kuantiti-$qty;
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byRB_groupID($id_rb);
|
|
foreach ($datDrb as $key) {
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byRB_groupID($id_rb);
|
|
foreach ($datSnRb as $dat) {
|
|
if ($dat['BARANG_ID']==$key['BID']) {
|
|
$update = [
|
|
'DRB_ID' => $key['ID_DRB']
|
|
];
|
|
$action = $this->Pembelian->update('sn_returbeli', $update, 'ID_SNRB', $dat['ID_SNRB']);
|
|
}
|
|
}
|
|
}
|
|
|
|
} else if ($jenis_drb==0) {
|
|
$input = [
|
|
'RB_ID' => $id_rb,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DRB' => $qty_drb,
|
|
'JENIS_DRB' => $jenis_drb,
|
|
];
|
|
$action = $this->Pembelian->create('daftar_returbeli', $input);
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($id_barang);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti+$qty_drb;
|
|
$pcm = $pcm_kuantiti-$qty_drb;
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $id_barang);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti+$qty_drb;
|
|
$itp = $itp_kuantiti-$qty_drb;
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $id_barang);
|
|
}
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusretur_GA2() { // [28]
|
|
$id_drb = $this->input->post('id_drb');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byID($id_drb);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
if ($datDrb[0]['STATUS_RB']!=NULL) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePembelian/dataRetur_Gudang_A1');
|
|
}
|
|
|
|
//Check Apakah SN Retur Beli sudah benar sesuai
|
|
if ($datDrb[0]['JENIS_DRB']==1) {
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byDRB_RBNull($id_drb);
|
|
if ($datSnRb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
foreach ($datSnRb as $dat) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($dat['NAMA_SNRB']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Set ID Retur Pembelian yang aktif
|
|
$id_rb = $datDrb[0]['RB_ID'];
|
|
|
|
if ($datDrb[0]['JENIS_DRB']==1) {
|
|
foreach ($datSnRb as $key) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($key['NAMA_SNRB']);
|
|
if ($datSnStock==TRUE) {
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($datDrb[0]['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$datDrb[0]['QTY_DRB'];
|
|
$pcm = $pcm_kuantiti+$datDrb[0]['QTY_DRB'];
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'PCM_KUANTITI' => $pcm
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $datDrb[0]['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$datDrb[0]['QTY_DRB'];
|
|
$itp = $itp_kuantiti+$datDrb[0]['QTY_DRB'];
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'ITP_KUANTITI' => $itp
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $datDrb[0]['BARANG_ID']);
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('sn_returbeli', $id_drb ,'DRB_ID');
|
|
$action = $this->Pembelian->delete('daftar_returbeli', $id_drb ,'ID_DRB');
|
|
|
|
$datDrbAfter = $this->Pembelian->getData_DaftarReturBeli_byRB_Null($id_rb);
|
|
if ($datDrbAfter==FALSE) {
|
|
$action = $this->Pembelian->delete('retur_pembelian', $id_rb, 'ID_RB');
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
public function kodeReturPembelian() { // [29]
|
|
$kk = $this->Pembelian->getKode_ReturPembelian();
|
|
$tgl = date('y/m');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "RB/$tgl/00001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 3, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "RB/$tgl/00001";
|
|
} else {
|
|
$panjang = 5;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 14 - strlen($str);
|
|
$data = "RB/$tgl/00000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciretur_GA2() { // [30]
|
|
$method = $this->input->post('method');
|
|
$id_rb = $this->input->post('id_rb');
|
|
$ket_rb = $this->input->post('ket_rb');
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$level = $this->session->userdata('level');
|
|
$kode_rb = $this->kodeReturPembelian();
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_Null($id_rb);
|
|
if ($datRb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byPEMBELIAN_byKARYAWAN_byLEVEL_KODENull($datRb[0]['PEMBELIAN_ID'], $id_karyawan, $level);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Hilangkan Enter di Keterangan
|
|
$ket_rb = preg_replace('/\R+/', " " , $ket_rb);
|
|
|
|
$update = [
|
|
'STATUS_RB' => '0',
|
|
'KET_RB' => $ket_rb,
|
|
'TGL_RB' => $tgl,
|
|
'KODE_RB' => $kode_rb,
|
|
];
|
|
$action = $this->Pembelian->update('retur_pembelian', $update, 'ID_RB', $id_rb);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePembelian/dataRetur_Gudang_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePembelian/dataRetur_Gudang_A1');
|
|
}
|
|
|
|
}
|
|
|
|
public function resetretur_GA2() { // [31]
|
|
$method = $this->input->post('method');
|
|
$id_rb = $this->input->post('id_rb');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_Null($id_rb);
|
|
if ($datRb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byRB_Null($id_rb);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byRB_groupID($id_rb);
|
|
foreach ($datSnRb as $key) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($key['NAMA_SNRB']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
foreach ($datSnRb as $key) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($key['NAMA_SNRB']);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
|
|
foreach ($datDrb as $key) {
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_DRB'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_DRB'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_DRB'];
|
|
$itp = $itp_kuantiti+$key['QTY_DRB'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('sn_returbeli', $id_rb, 'RB_ID');
|
|
$action = $this->Pembelian->delete('daftar_returbeli', $id_rb, 'RB_ID');
|
|
$action = $this->Pembelian->delete('retur_pembelian', $id_rb, 'ID_RB');
|
|
|
|
$this->session->set_flashdata('flush_data', 'direset');
|
|
redirect('ManagePembelian/dataRetur_Gudang_A1');
|
|
|
|
}
|
|
|
|
public function dataRetur_Keuangan_A1() { // [32]
|
|
$datPembelian = $this->Pembelian->getData_ReturPembelian_0();
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "returbeli step2",
|
|
'pembelian' => $datPembelian
|
|
];
|
|
$this->load->view('proses/PembelianRetur_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function dataRetur_Keuangan_A2($id) { // [33]
|
|
$pembelian = $this->Pembelian->getData_DaftarReturBeli_byRB_byBARANG_0($id);
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_0($id);
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($datRb[0]['PEMBELIAN_ID']);
|
|
|
|
//Set Nilai Debet Hutang Dagang
|
|
$debet_hda = 0;
|
|
foreach ($pembelian as $key) {
|
|
$debet = $key['HARGA_DRB']*$key['QTY_DRB'];
|
|
$debet_hda = $debet_hda+$debet;
|
|
}
|
|
|
|
//Set Nilai Bruto, PPN, Netto
|
|
$bruto = $debet_hda;
|
|
$ppn_hda = $debet_hda*($datRb[0]['PPN_PEMBELIAN']/100);
|
|
$debet_hda = $debet_hda*(($datRb[0]['PPN_PEMBELIAN']+100)/100);
|
|
$debet_hda = round($debet_hda);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "returbeli step2",
|
|
'pembelian' => $pembelian,
|
|
'id_rb' => $id,
|
|
'debet_hda' => $debet_hda,
|
|
'bruto' => $bruto,
|
|
'ppn_hda' => $ppn_hda,
|
|
'kode_rb' => $datRb[0]['KODE_RB'],
|
|
'ppn_pembelian' => $datRb[0]['PPN_PEMBELIAN'],
|
|
'nama_supplier' => $datRb[0]['NAMA_SUPPLIER'],
|
|
'kredit_hda' => $datHda[0]['KREDIT_HDA']
|
|
];
|
|
$this->load->view('proses/PembelianRetur_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function simpanretur_KA2() { // [34]
|
|
$method = $this->input->post('method');
|
|
$id_drb = $this->input->post('id_drb');
|
|
$harga_drb = $this->input->post('harga_drb');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byID($id_drb);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_drb = str_replace(',', '.', $harga_drb);
|
|
|
|
//Check Nilai apakah Numeric
|
|
$check_nilai = is_numeric($harga_drb);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_drb = 0;
|
|
}
|
|
|
|
//Check apakah Nilai kurang dari 0
|
|
if ($harga_drb<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DRB' => $harga_drb
|
|
];
|
|
$action = $this->Pembelian->update('daftar_returbeli', $update, 'ID_DRB', $id_drb);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function hapusretur_KA2() { // [35]
|
|
$method = $this->input->post('method');
|
|
$id_drb = $this->input->post('id_drb');
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byID($id_drb);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Check apakah harganya masih Null
|
|
if ($datDrb[0]['HARGA_DRB']==NULL) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DRB' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('daftar_returbeli', $update, 'ID_DRB', $id_drb);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function batalretur_KA2() { // [36]
|
|
$method = $this->input->post('method');
|
|
$id_rb = $this->input->post('id_rb');
|
|
$level = $this->session->userdata('level');
|
|
|
|
//Check Konsistensi Data
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_0($id_rb);
|
|
if ($datRb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byRB_0($id_rb);
|
|
if ($datDrb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byRB_groupID($id_rb);
|
|
foreach ($datSnRb as $key) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($key['NAMA_SNRB']);
|
|
if ($datSnStock==FALSE) {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
foreach ($datSnRb as $key) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($key['NAMA_SNRB']);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
|
|
foreach ($datDrb as $key) {
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_DRB'];
|
|
$pcm = $pcm_kuantiti+$key['QTY_DRB'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_DRB'];
|
|
$itp = $itp_kuantiti+$key['QTY_DRB'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'PROSES_KUANTITI' => $proses
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('sn_returbeli', $id_rb, 'RB_ID');
|
|
$action = $this->Pembelian->delete('daftar_returbeli', $id_rb, 'RB_ID');
|
|
$action = $this->Pembelian->delete('retur_pembelian', $id_rb, 'ID_RB');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_void', 'dibatalkan');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function kodeINVReturBeli($id) { // [37]
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_byID($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($datRb[0]['PEMBELIAN_ID']);
|
|
$id_corp = $datPembelian[0]['CORP_ID'];
|
|
|
|
//Set Data Corp
|
|
if ($id_corp=="1") {
|
|
$corp = "TMP";
|
|
$kk = $this->Pembelian->getKode_INVReturBeliTMP();
|
|
} else if ($id_corp=="2") {
|
|
$corp = "DMT";
|
|
$kk = $this->Pembelian->getKode_INVReturBeliDMT();
|
|
} else if ($id_corp=="3") {
|
|
$corp = "PCM";
|
|
$kk = $this->Pembelian->getKode_INVReturBeliPCM();
|
|
} else if ($id_corp=="4") {
|
|
$corp = "SFT";
|
|
$kk = $this->Pembelian->getKode_INVReturBeliSFTR();
|
|
} else if ($id_corp=="5") {
|
|
$corp = "ITP";
|
|
$kk = $this->Pembelian->getKode_INVReturBeliITP();
|
|
}
|
|
$tgl = date('y');
|
|
if (is_array($kk) || is_object($kk)) {
|
|
foreach ($kk as $row) {
|
|
if ($row['KODE'] == null) {
|
|
return "RT/$corp/".$tgl."000001";
|
|
} else {
|
|
$str = (string) $row['KODE'];
|
|
$tgl_lama = substr($str, 7, -6);
|
|
if ($tgl_lama!=$tgl) {
|
|
return "RT/$corp/".$tgl."000001";
|
|
} else {
|
|
$panjang = 6;
|
|
$data = substr($str, 9, $panjang);
|
|
$ko = (int) $data + 1;
|
|
$str = (string) $ko;
|
|
$panjang = 15 - strlen($str);
|
|
$data = "RT/$corp/".$tgl."000000";
|
|
$data = substr($data, 0, $panjang) . $str;
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function kunciretur_KA2() { // [38]
|
|
$method = $this->input->post('method');
|
|
$id_rb = $this->input->post('id_rb');
|
|
$debet_hda = $this->input->post('debet_hda');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datRb = $this->Pembelian->getData_ReturPembelian_0($id_rb);
|
|
if ($datRb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDrb = $this->Pembelian->getData_DaftarReturBeli_byRB_0($id_rb);
|
|
foreach ($datDrb as $key) {
|
|
if ($key['HARGA_DRB']==NULL) {
|
|
$this->session->set_flashdata('price_check', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
$inv_rb = $this->kodeINVReturBeli($id_rb);
|
|
$update = [
|
|
'INV_RB' => $inv_rb,
|
|
'TGL_RB' => $tgl,
|
|
'STATUS_RB' => '1',
|
|
];
|
|
$action = $this->Pembelian->update('retur_pembelian', $update, 'ID_RB', $id_rb);
|
|
|
|
foreach ($datDrb as $key) {
|
|
if ($key['JENIS_DRB']==1) {
|
|
$datSnRb = $this->Pembelian->getData_SnReturBeli_byRB_byBARANG($id_rb, $key['BARANG_ID']);
|
|
foreach ($datSnRb as $dat) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_2($dat['NAMA_SNRB']);
|
|
$input = [
|
|
'TGL_HSN' => $tgl,
|
|
'KODE_BUKTI' => $datRb[0]['KODE_RB'],
|
|
'INV_HSN' => $inv_rb,
|
|
'SNSTOCK_ID' => $datSnStock[0]['ID_SNSTOCK']
|
|
];
|
|
$action = $this->Pembelian->create('histori_sn', $input);
|
|
$update = [
|
|
'STATUS_SNSTOCK' => '3'
|
|
];
|
|
$action = $this->Pembelian->update('sn_stock', $update, 'ID_SNSTOCK', $datSnStock[0]['ID_SNSTOCK']);
|
|
}
|
|
}
|
|
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
$proses_kuantiti = $datKuantiti[0]['PROSES_KUANTITI'];
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$proses = $proses_kuantiti-$key['QTY_DRB'];
|
|
$global = $global_kuantiti-$key['QTY_DRB'];
|
|
$update = [
|
|
'PROSES_KUANTITI' => $proses,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
|
|
$nilai_hq = $key['HARGA_DRB']*$key['QTY_DRB'];
|
|
$datHq = $this->Pembelian->getData_HistoriKuantiti_byBARANG_orderDESC_limit1($key['BARANG_ID']);
|
|
$sisa_hq = $datHq[0]['SISA_HQ']-$key['QTY_DRB'];
|
|
$persediaan_hq = $datHq[0]['PERSEDIAAN_HQ']-$nilai_hq;
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
$input = [
|
|
'TGL_HQ' => $tgl,
|
|
'KODE_BUKTI' => $datRb[0]['KODE_RB'],
|
|
'INV_HQ' => $inv_rb,
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'KELUAR_HQ' => $key['QTY_DRB'],
|
|
'MASUK_HQ' => '0'
|
|
];
|
|
$action = $this->Pembelian->create('histori_kuantiti', $input);
|
|
}
|
|
|
|
$kode_pembelian = $datRb[0]['KODE_PEMBELIAN'];
|
|
$ket_hda = "No Nota : $kode_pembelian";
|
|
$input = [
|
|
'SUPPLIER_ID' => $datRb[0]['SUPPLIER_ID'],
|
|
'PEMBELIAN_ID' => $datRb[0]['PEMBELIAN_ID'],
|
|
'TRANSAKSI_HDA' => '2',
|
|
'KODE_BUKTI' => $datRb[0]['KODE_RB'],
|
|
'TGL_HDA' => $tgl,
|
|
'DEBET_HDA' => $debet_hda,
|
|
'KREDIT_HDA' => '0',
|
|
'KET_HDA' => $ket_hda
|
|
];
|
|
$action = $this->Pembelian->create('hutang_dagang', $input);
|
|
|
|
$input = [
|
|
'SJ_INV' => '1',
|
|
'TGL_CD' => $tgl,
|
|
'KODE_BUKTI' => $inv_rb,
|
|
'RB_ID' => $id_rb
|
|
];
|
|
$action = $this->Pembelian->create('cetak_dokumen', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect('ManagePembelian/dataRetur_Keuangan_A1');
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Ubah Pembelian
|
|
public function dataUbah_Keuangan_A1() { // [39]
|
|
$id_pembelian = NULL;
|
|
$kondisi = $this->input->post('kondisi');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
|
|
if ($kondisi==null){
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$tanggal_now = date('Y-m-01');
|
|
$tanggal_awal = $this->Pembelian->subTempoMonth($tanggal_now, 2);
|
|
} else {
|
|
$tanggal_awal = $this->input->post('tanggal_awal');
|
|
$tanggal_akhir = $this->input->post('tanggal_akhir');
|
|
$tanggal_now = date('Y-m-01');
|
|
$temporaryAwal = $this->Pembelian->subTempoMonth($tanggal_now, 2);
|
|
if (strtotime($tanggal_awal)<strtotime($temporaryAwal)) {
|
|
$tanggal_awal = $temporaryAwal;
|
|
}
|
|
}
|
|
$pembelian = $this->Pembelian->getData_Pembelian_forUbah($id_pembelian, $level, $tanggal_awal, $tanggal_akhir);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian ubah keuangan",
|
|
'pembelian' => $pembelian,
|
|
'tgl' => $tgl,
|
|
'tanggal_awal' => $tanggal_awal,
|
|
'tanggal_akhir' => $tanggal_akhir,
|
|
];
|
|
$this->load->view('proses/PembelianUbah_Keuangan_A1', $data);
|
|
}
|
|
|
|
public function dataUbah_Keuangan_A2($id) { // [40]
|
|
$pembelian = $this->Pembelian->getData_Pembelian_forUbah($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
$tgl = date('Y-m-d');
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian ubah keuangan",
|
|
'pembelian' => $pembelian,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'inv_pembelian' => $datPembelian[0]['INV_PEMBELIAN'],
|
|
'id_pembelian' => $id,
|
|
'tgl' => $tgl
|
|
];
|
|
$this->load->view('proses/PembelianUbah_Keuangan_A2', $data);
|
|
}
|
|
|
|
public function ubahpembelian_KA2() { // [41]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$tt_pembelian = $this->input->post('tt_pembelian');
|
|
$fp_pembelian = $this->input->post('fp_pembelian');
|
|
$sj_pembelian = $this->input->post('sj_pembelian');
|
|
$inv_pembelian = $this->input->post('inv_pembelian');
|
|
$ket_hda = $this->input->post('ket_hda');
|
|
$tgl_now = date('Y-m-01');
|
|
$tgl = date('Y-m-d');
|
|
|
|
//Check Konsistensi Data
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_forUbah($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah melebihi Hari ini
|
|
if (strtotime($tt_pembelian)>strtotime($tgl)) {
|
|
$this->session->set_flashdata('date_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah SJ Ada yang sama
|
|
$checkPembelianSJ = $this->Pembelian->getData_Pembelian_forSJ($id_pembelian, $sj_pembelian);
|
|
if ($checkPembelianSJ==TRUE) {
|
|
$this->session->set_flashdata('sj_duplicate', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Nota Ada yang sama
|
|
$checkPembelianINV = $this->Pembelian->getData_Pembelian_forINV($id_pembelian, $inv_pembelian);
|
|
if ($checkPembelianINV==TRUE) {
|
|
$this->session->set_flashdata('nota_duplicate', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($tt_pembelian=="") {
|
|
$tt_pembelian = NULL;
|
|
$tempo_invbeli = $datPembelian[0]['TEMPO_INVBELI'];
|
|
} else {
|
|
$tempo_invbeli = $this->Pembelian->addTempoDay($tt_pembelian, $datPembelian[0]['TOP_SUPPLIER']);
|
|
}
|
|
|
|
$fp_pembelian = strtoupper($fp_pembelian);
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
$inv_pembelian = strtoupper($inv_pembelian);
|
|
$ket_hda = preg_replace('/\R+/', " " , $ket_hda);
|
|
|
|
$update = [
|
|
'TT_PEMBELIAN' => $tt_pembelian,
|
|
'TEMPO_INVBELI' => $tempo_invbeli,
|
|
'INV_PEMBELIAN' => $inv_pembelian,
|
|
'SJ_PEMBELIAN' => $sj_pembelian,
|
|
'FP_PEMBELIAN' => $fp_pembelian,
|
|
'KET_PEMBELIAN' => $ket_hda
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
$update = [
|
|
'KET_HDA' => $ket_hda
|
|
];
|
|
$action = $this->Pembelian->update('hutang_dagang', $update, 'ID_HDA', $datPembelian[0]['ID_HDA']);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function dataUbah_Keuangan_B1() { // [48]
|
|
$id_pembelian = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$tanggal_awal = date('Y-m-01');
|
|
|
|
$pembelian = $this->Pembelian->getData_Pembelian_forUbah($id_pembelian, $level, $tanggal_awal, $tanggal_akhir);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian ubah hutang",
|
|
'pembelian' => $pembelian,
|
|
'tgl' => $tanggal_akhir,
|
|
];
|
|
$this->load->view('proses/PembelianUbah_Keuangan_B1', $data);
|
|
}
|
|
|
|
public function dataUbah_Keuangan_B2($id) { // [49]
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($id);
|
|
|
|
// Mencari Nilai Hutang
|
|
$kredit_hda = 0;
|
|
foreach ($pembelian as $key) {
|
|
$hutang = $key['HARGA_DB']*$key['QTY_DB'];
|
|
$kredit_hda = $kredit_hda+$hutang;
|
|
}
|
|
|
|
// Set Tampilan Nilai
|
|
$bruto = $kredit_hda;
|
|
$ppn_hda = $kredit_hda*($datPembelian[0]['PPN_PEMBELIAN']/100);
|
|
$kredit_hda = $kredit_hda*(($datPembelian[0]['PPN_PEMBELIAN']+100)/100);
|
|
$kredit_hda = round($kredit_hda);
|
|
|
|
//Set apakah bisa diubah atau tidak
|
|
if (count($datHda)>=2) {
|
|
$aktif = 0;
|
|
} else {
|
|
$aktif = 1;
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian ubah hutang",
|
|
'pembelian' => $pembelian,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'inv_pembelian' => $datPembelian[0]['INV_PEMBELIAN'],
|
|
'id_pembelian' => $id,
|
|
'bruto' => $bruto,
|
|
'ppn_hda' => $ppn_hda,
|
|
'kredit_hda' => $kredit_hda,
|
|
'aktif' => $aktif
|
|
];
|
|
$this->load->view('proses/PembelianUbah_Keuangan_B2', $data);
|
|
}
|
|
|
|
public function ubahharga_KB2() { // [50]
|
|
$method = $this->input->post('method');
|
|
$id_db = $this->input->post('id_db');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$harga_db = $this->input->post('harga_dbed');
|
|
$tgl_now = date('Y-m-01');
|
|
|
|
//Check Konsistensi Data
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_forUbah($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah data sudah diproses secara Kasbank
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($id_pembelian);
|
|
if (count($datHda)>=2) {
|
|
$this->session->set_flashdata('kasbank_processed', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah data Bukan di Bulan ini
|
|
if (strtotime($tgl_now)>strtotime($datPembelian[0]['TGL_INVBELI'])) {
|
|
$this->session->set_flashdata('date_month_lock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah Ada Histori Kuantiti
|
|
$datHq = $this->Pembelian->getData_HistoriKuantiti_byBARANG_byKODE($datDb[0]['BARANG_ID'],$datPembelian[0]['KODE_PEMBELIAN']);
|
|
if ($datHq==FALSE) {
|
|
$this->session->set_flashdata('hq_error', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$harga_db = str_replace(',', '.', $harga_db);
|
|
|
|
//Check apakah Nilai bersifat Numeric
|
|
$check_nilai = is_numeric($harga_db);
|
|
if ($check_nilai==FALSE) {
|
|
$harga_db = 0;
|
|
}
|
|
|
|
//Check apakah nilai kurang dari 0
|
|
if ($harga_db<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'HARGA_DB' => $harga_db,
|
|
];
|
|
$action = $this->Pembelian->update('daftar_beli', $update, 'ID_DB', $id_db);
|
|
|
|
$nilai_hq = $harga_db*$datDb[0]['QTY_DB'];
|
|
$datHqBefore = $this->Pembelian->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($datDb[0]['BARANG_ID'], $datHq[0]['ID_HQ']);
|
|
$persediaan_hq = $datHqBefore[0]['PERSEDIAAN_HQ']+$nilai_hq;
|
|
$sisa_hq = $datHqBefore[0]['SISA_HQ']+$datDb[0]['QTY_DB'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
$update = [
|
|
'NILAI_HQ' => $nilai_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
];
|
|
$action = $this->Pembelian->update('histori_kuantiti', $update, 'ID_HQ', $datHq[0]['ID_HQ']);
|
|
|
|
$datHqAfter = $this->Pembelian->getData_HistoriKuantiti_byBARANG_afterID($datDb[0]['BARANG_ID'], $datHq[0]['ID_HQ']);
|
|
foreach ($datHqAfter as $key) {
|
|
$datHqBeforeTwo = $this->Pembelian->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($key['BARANG_ID'], $key['ID_HQ']);
|
|
|
|
if ($key['MASUK_HQ']==0) { // Transaksi Keluar
|
|
$sisa_hq = $datHqBeforeTwo[0]['SISA_HQ']-$key['KELUAR_HQ'];
|
|
if ($datHqBeforeTwo[0]['SISA_HQ']==$key['KELUAR_HQ']) {
|
|
$persediaan_hq = 0;
|
|
} else {
|
|
$persediaan_hq = $datHqBeforeTwo[0]['PERSEDIAAN_HQ']-($datHqBeforeTwo[0]['AVG_HQ']*$key['KELUAR_HQ']);
|
|
}
|
|
$update = [
|
|
'SISA_HQ' => $sisa_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $datHqBeforeTwo[0]['AVG_HQ']
|
|
];
|
|
} else if ($key['KELUAR_HQ']==0) { // Transaksi Masuk
|
|
$sisa_hq = $datHqBeforeTwo[0]['SISA_HQ']+$key['MASUK_HQ'];
|
|
$persediaan_hq = $datHqBeforeTwo[0]['PERSEDIAAN_HQ']+$key['NILAI_HQ'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
|
|
$update = [
|
|
'SISA_HQ' => $sisa_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
];
|
|
}
|
|
$action = $this->Pembelian->update('histori_kuantiti', $update, 'ID_HQ', $key['ID_HQ']);
|
|
}
|
|
|
|
$sumDb = $this->Pembelian->getSum_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
$kredit_hda = $sumDb[0]['TOTAL']*(($datPembelian[0]['PPN_PEMBELIAN']+100)/100);
|
|
$kredit_hda = round($kredit_hda);
|
|
|
|
$update = [
|
|
'KREDIT_HDA' => $kredit_hda
|
|
];
|
|
$action = $this->Pembelian->update('hutang_dagang', $update, 'ID_HDA', $datHda[0]['ID_HDA']);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function ubahppn_KB2() { // [51]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$ppn_pembelian = $this->input->post('ppn_pembelianed');
|
|
$tgl_now = date('Y-m-01');
|
|
|
|
//Check Konsistensi Data
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_forUbah($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah data sudah diproses secara Kasbank
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($id_pembelian);
|
|
if (count($datHda)>=2) {
|
|
$this->session->set_flashdata('kasbank_processed', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Check apakah data Bukan di Bulan ini
|
|
if (strtotime($tgl_now)>strtotime($datPembelian[0]['TGL_INVBELI'])) {
|
|
$this->session->set_flashdata('date_month_lock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Koma menjadi titik
|
|
$ppn_pembelian = str_replace(',', '.', $ppn_pembelian);
|
|
|
|
//Check apakah Nilai bersifat Numeric
|
|
$check_nilai = is_numeric($ppn_pembelian);
|
|
if ($check_nilai==FALSE) {
|
|
$ppn_pembelian = 0;
|
|
}
|
|
|
|
//Check apakah nilai kurang dari 0
|
|
if ($ppn_pembelian<0) {
|
|
$this->session->set_flashdata('not_zero_negative', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'PPN_PEMBELIAN' => $ppn_pembelian,
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
$sumDb = $this->Pembelian->getSum_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
$kredit_hda = $sumDb[0]['TOTAL']*(($ppn_pembelian+100)/100);
|
|
$kredit_hda = round($kredit_hda);
|
|
|
|
$update = [
|
|
'KREDIT_HDA' => $kredit_hda
|
|
];
|
|
$action = $this->Pembelian->update('hutang_dagang', $update, 'ID_HDA', $datHda[0]['ID_HDA']);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
//Controller Transaksi Revisi
|
|
public function dataRevisi_Admin_GA1() { // [42]
|
|
$id_pembelian = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$pembelian = $this->Pembelian->getData_Pembelian_0($id_pembelian, $level);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step1",
|
|
'pembelian' => $pembelian
|
|
];
|
|
$this->load->view('proses/PembelianRevisi_Admin_GA1', $data);
|
|
}
|
|
|
|
public function dataRevisi_Admin_GA2($id) { // [43]
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
|
|
//Isi SN untuk Pembelian
|
|
$no = 0;
|
|
foreach ($pembelian as $key) {
|
|
$datSnb = $this->Pembelian->getData_SnBeli_byDB($key['ID_DB']);
|
|
$pembelian[$no++] += ['SN' => $datSnb];
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step1",
|
|
'pembelian' => $pembelian,
|
|
'id_pembelian' => $id,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER']
|
|
];
|
|
|
|
$this->load->view('proses/PembelianRevisi_Admin_GA2', $data);
|
|
}
|
|
|
|
public function revisibarang_GA2() { // [44]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
|
|
//Check Konsistensi Data
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_0($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('valid_test', 'error');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
}
|
|
|
|
//Check apakah sudah terisi Harga
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['HARGA_DB']!=NULL) {
|
|
$this->session->set_flashdata('price_check', 'error');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_PEMBELIAN' => NULL
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'direvisi');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'direvisi');
|
|
redirect('ManagePembelian/dataRevisi_Admin_GA1');
|
|
}
|
|
|
|
}
|
|
|
|
public function dataRevisi_Admin_KA1() { // [45]
|
|
$id_pembelian = NULL;
|
|
$level = $this->session->userdata('level');
|
|
$tanggal_awal = date('Y-m-01');
|
|
$tanggal_akhir = date('Y-m-d');
|
|
$pembelian = $this->Pembelian->getData_Pembelian_1($id_pembelian, $level, $tanggal_awal, $tanggal_akhir);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step2",
|
|
'pembelian' => $pembelian
|
|
];
|
|
$this->load->view('proses/PembelianRevisi_Admin_KA1', $data);
|
|
}
|
|
|
|
public function dataRevisi_Admin_KA2($id) { // [46]
|
|
$pembelian = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_byID($id);
|
|
|
|
$debet_hda = 0;
|
|
foreach ($pembelian as $key) {
|
|
$debet = $key['HARGA_DB']*$key['QTY_DB'];
|
|
$debet_hda = $debet_hda+$debet;
|
|
}
|
|
|
|
$bruto = $debet_hda;
|
|
$ppn_hda = $debet_hda*($datPembelian[0]['PPN_PEMBELIAN']/100);
|
|
$debet_hda = $debet_hda*(($datPembelian[0]['PPN_PEMBELIAN']+100)/100);
|
|
$debet_hda = round($debet_hda);
|
|
|
|
$data = [
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian step2",
|
|
'pembelian' => $pembelian,
|
|
'id_pembelian' => $id,
|
|
'debet_hda' => $debet_hda,
|
|
'ppn_hda' => $ppn_hda,
|
|
'bruto' => $bruto,
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'ppn_pembelian' => $datPembelian[0]['PPN_PEMBELIAN'],
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER']
|
|
];
|
|
$this->load->view('proses/PembelianRevisi_Admin_KA2', $data);
|
|
}
|
|
|
|
public function revisibarang_KA2() { // [47]
|
|
$method = $this->input->post('method');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$level = $this->session->userdata('level');
|
|
$tgl = date('Y-m-d');
|
|
$tgl_now = date('Y-m-01');
|
|
|
|
//Check Konsistensi Data
|
|
$datPembelian = $this->Pembelian->getData_Pembelian_1_checkRevisi($id_pembelian, $tgl_now);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('valid_test', 'error');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
}
|
|
|
|
//Check Konsistensi Data
|
|
$datDb = $this->Pembelian->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSnBeli as $dat) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNB']);
|
|
if ($datSnStock==FALSE OR $datSnStock[0]['STATUS_SNSTOCK']!=NULL) {
|
|
$this->session->set_flashdata('valid_test', 'error');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
}
|
|
$datSnRj = $this->Pembelian->getData_SnReturJual_byNAMA($dat['NAMA_SNB']);
|
|
if ($datSnRj==TRUE) {
|
|
$this->session->set_flashdata('data_used_retur', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
if ($datKuantiti[0]['PCM_KUANTITI']<$key['QTY_DB']) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
} else if ($level == 1) {
|
|
if ($datKuantiti[0]['ITP_KUANTITI']<$key['QTY_DB']) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Check apakah sudah pernah diproses oleh Kasbank
|
|
$datHda = $this->Pembelian->getData_HutangDagang_byPEMBELIAN($id_pembelian);
|
|
if (count($datHda)>=2) {
|
|
$this->session->set_flashdata('data_used_kasbank', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Set Kode Pembelian
|
|
$kode_pembelian = $datPembelian[0]['KODE_PEMBELIAN'];
|
|
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']=="1") {
|
|
$datSnBeli = $this->Pembelian->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSnBeli as $dat) {
|
|
$datSnStock = $this->Pembelian->getData_SnStock_byNAMA_AllStatus($dat['NAMA_SNB']);
|
|
$action = $this->Pembelian->delete('histori_sn', $datSnStock[0]['ID_SNSTOCK'], 'SNSTOCK_ID');
|
|
$action = $this->Pembelian->delete('sn_stock', $datSnStock[0]['ID_SNSTOCK'], 'ID_SNSTOCK');
|
|
}
|
|
}
|
|
$datKuantiti = $this->Pembelian->getData_Kuantiti_byID($key['BARANG_ID']);
|
|
if ($level == 0) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$pcm_kuantiti = $datKuantiti[0]['PCM_KUANTITI'];
|
|
$global = $global_kuantiti-$key['QTY_DB'];
|
|
$pcm = $pcm_kuantiti-$key['QTY_DB'];
|
|
$update = [
|
|
'PCM_KUANTITI' => $pcm,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
} else if ($level == 1) {
|
|
$global_kuantiti = $datKuantiti[0]['GLOBAL_KUANTITI'];
|
|
$itp_kuantiti = $datKuantiti[0]['ITP_KUANTITI'];
|
|
$global = $global_kuantiti-$key['QTY_DB'];
|
|
$itp = $itp_kuantiti-$key['QTY_DB'];
|
|
$update = [
|
|
'ITP_KUANTITI' => $itp,
|
|
'GLOBAL_KUANTITI' => $global
|
|
];
|
|
$action = $this->Pembelian->update('kuantiti', $update, 'ID_KUANTITI', $key['BARANG_ID']);
|
|
}
|
|
}
|
|
|
|
$datHq = $this->Pembelian->getData_HistoriKuantiti_byKODE($kode_pembelian);
|
|
$action = $this->Pembelian->delete('histori_kuantiti', $kode_pembelian, 'KODE_BUKTI');
|
|
foreach ($datHq as $key) {
|
|
$datHqAfter = $this->Pembelian->getData_HistoriKuantiti_byBARANG_afterID($key['BARANG_ID'], $key['ID_HQ']);
|
|
foreach ($datHqAfter as $dat) {
|
|
$datHqBeforeTwo = $this->Pembelian->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($dat['BARANG_ID'], $dat['ID_HQ']);
|
|
if ($dat['MASUK_HQ']==0) { // Transaksi Keluar
|
|
$sisa_hq = $datHqBeforeTwo[0]['SISA_HQ']-$dat['KELUAR_HQ'];
|
|
if ($datHqBeforeTwo[0]['SISA_HQ']==$dat['KELUAR_HQ']) {
|
|
$persediaan_hq = 0;
|
|
} else {
|
|
$persediaan_hq = $datHqBeforeTwo[0]['PERSEDIAAN_HQ']-($datHqBeforeTwo[0]['AVG_HQ']*$dat['KELUAR_HQ']);
|
|
}
|
|
$update = [
|
|
'SISA_HQ' => $sisa_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $datHqBeforeTwo[0]['AVG_HQ']
|
|
];
|
|
} else if ($dat['KELUAR_HQ']==0) { // Transaksi Masuk
|
|
$sisa_hq = $datHqBeforeTwo[0]['SISA_HQ']+$dat['MASUK_HQ'];
|
|
$persediaan_hq = $datHqBeforeTwo[0]['PERSEDIAAN_HQ']+$dat['NILAI_HQ'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
|
|
$update = [
|
|
'SISA_HQ' => $sisa_hq,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
];
|
|
}
|
|
$action = $this->Pembelian->update('histori_kuantiti', $update, 'ID_HQ', $dat['ID_HQ']);
|
|
}
|
|
}
|
|
|
|
$action = $this->Pembelian->delete('hutang_dagang', $id_pembelian, 'PEMBELIAN_ID');
|
|
|
|
$update = [
|
|
'INV_PEMBELIAN' => NULL,
|
|
'TGL_INVBELI' => NULL,
|
|
'TEMPO_INVBELI' => NULL,
|
|
'STATUS_PEMBELIAN' => '0'
|
|
];
|
|
$action = $this->Pembelian->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'direvisi');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'direvisi');
|
|
redirect('ManagePembelian/dataRevisi_Admin_KA1');
|
|
}
|
|
|
|
}
|
|
|
|
}
|