1569 lines
50 KiB
PHP
1569 lines
50 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 Menu extends CI_Controller {
|
|
|
|
//SUBMENU TRANSAKSI - TINDAK LANJUT
|
|
public function KP_Sub1_TindakLanjut_1() {
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$limit = date('Y-m-01');
|
|
$now = date('Y-m-d');
|
|
|
|
$datShm = $this->Amod->getData_SetHakMenu_byKARYAWAN_byKODE_byNAMA($id_karyawan, "KP", "TRANSAKSI - Tindak Lanjut");
|
|
$id_menu = $datShm[0]['MENU_ID'];
|
|
$hak = $datShm[0]['AKSES_ID'];
|
|
$tampil = $datShm[0]['NAMA_AKSES'];
|
|
|
|
$datPenawaran = $this->Amod->getData_Penawaran_bySTATUS(1);
|
|
$no = 0;
|
|
$datBelum = [];
|
|
$datBerjalan = [];
|
|
$datBudget = [];
|
|
$datPerhatian = [];
|
|
$datTercapai = [];
|
|
$countBelum = 0;
|
|
$countBerjalan = 0;
|
|
$countBudget = 0;
|
|
$countPerhatian = 0;
|
|
$countTercapai = 0;
|
|
foreach ($datPenawaran as $key) {
|
|
$salesChannel = "";
|
|
$salesOther = "";
|
|
$sales_penawaran = $key['SALES_PENAWARAN'];
|
|
$listSales = explode(',', $sales_penawaran);
|
|
foreach ($listSales as $dat) {
|
|
$datKaryawan = $this->Amod->getData_Karyawan_byID($dat);
|
|
$nama = $datKaryawan[0]['NAMA_PANGGILAN_KARYAWAN'];
|
|
if (strpos($datKaryawan[0]['NAMA_JABATAN'],"CHANNEL")!==FALSE OR $nama=="Anton") {
|
|
$salesChannel .= "$nama, ";
|
|
} else {
|
|
$salesOther .= "$nama, ";
|
|
}
|
|
}
|
|
if ($salesChannel!="") {
|
|
$salesChannel = substr($salesChannel, 0, -2);
|
|
}
|
|
if ($salesOther!="") {
|
|
$salesOther = substr($salesOther, 0, -2);
|
|
}
|
|
|
|
if ($hak<=2) {
|
|
if (strpos($salesChannel,$panggilan)!==FALSE OR strpos($salesOther,$panggilan)!==FALSE) {
|
|
$show = 1;
|
|
} else {
|
|
$show = 0;
|
|
}
|
|
} else {
|
|
$show = 1;
|
|
}
|
|
|
|
if ($show==1) {
|
|
$datHpne = $this->Amod->getData_HistoriPenawaran_byPENAWARAN_orderDESC_limit1($key['ID_PENAWARAN']);
|
|
$ketLast = $datHpne[0]['KET_HPNE'];
|
|
$statLast = $datHpne[0]['NAMA_SPE'];
|
|
$tglLast = $datHpne[0]['TANGGAL'];
|
|
|
|
if ($datHpne[0]['STATUS_HPNE']<=2 OR $datHpne[0]['STATUS_HPNE']==4 OR $datHpne[0]['STATUS_HPNE']==5) {
|
|
if (strtotime($now)>=strtotime($datHpne[0]['FU_HPNE'])) {
|
|
$datBelum[$countBelum++] = [
|
|
'ID' => $key['ID_PENAWARAN'],
|
|
'TANGGAL' => $key['TANGGAL'],
|
|
'KOP' => $key['CORP_ID'],
|
|
'JENIS' => $key['JENIS_PENAWARAN'],
|
|
'KODE' => $key['KODE_PENAWARAN'],
|
|
'CIPTA' => $key['CIPTA_PENAWARAN'],
|
|
'CHANNEL' => $salesChannel,
|
|
'OTHER' => $salesOther,
|
|
'PELANGGAN' => $key['PELANGGAN_PENAWARAN'],
|
|
'UP' => $key['UP_PENAWARAN'],
|
|
'LAMPIRAN' => $key['LAMPIRAN_PENAWARAN'],
|
|
'PERIHAL' => $key['PERIHAL_PENAWARAN'],
|
|
'NILAI' => $key['NILAI'],
|
|
'TGL' => $tglLast,
|
|
'KET' => $ketLast,
|
|
'STAT' => $statLast,
|
|
'SHOW' => $show,
|
|
];
|
|
} else {
|
|
$datBerjalan[$countBerjalan++] = [
|
|
'ID' => $key['ID_PENAWARAN'],
|
|
'TANGGAL' => $key['TANGGAL'],
|
|
'KOP' => $key['CORP_ID'],
|
|
'JENIS' => $key['JENIS_PENAWARAN'],
|
|
'KODE' => $key['KODE_PENAWARAN'],
|
|
'CIPTA' => $key['CIPTA_PENAWARAN'],
|
|
'CHANNEL' => $salesChannel,
|
|
'OTHER' => $salesOther,
|
|
'PELANGGAN' => $key['PELANGGAN_PENAWARAN'],
|
|
'UP' => $key['UP_PENAWARAN'],
|
|
'LAMPIRAN' => $key['LAMPIRAN_PENAWARAN'],
|
|
'PERIHAL' => $key['PERIHAL_PENAWARAN'],
|
|
'NILAI' => $key['NILAI'],
|
|
'TGL' => $tglLast,
|
|
'KET' => $ketLast,
|
|
'STAT' => $statLast,
|
|
'SHOW' => $show,
|
|
];
|
|
}
|
|
} else if ($datHpne[0]['STATUS_HPNE']==3) {
|
|
$datBudget[$countBudget++] = [
|
|
'ID' => $key['ID_PENAWARAN'],
|
|
'TANGGAL' => $key['TANGGAL'],
|
|
'KOP' => $key['CORP_ID'],
|
|
'JENIS' => $key['JENIS_PENAWARAN'],
|
|
'KODE' => $key['KODE_PENAWARAN'],
|
|
'CIPTA' => $key['CIPTA_PENAWARAN'],
|
|
'CHANNEL' => $salesChannel,
|
|
'OTHER' => $salesOther,
|
|
'PELANGGAN' => $key['PELANGGAN_PENAWARAN'],
|
|
'UP' => $key['UP_PENAWARAN'],
|
|
'LAMPIRAN' => $key['LAMPIRAN_PENAWARAN'],
|
|
'PERIHAL' => $key['PERIHAL_PENAWARAN'],
|
|
'NILAI' => $key['NILAI'],
|
|
'TGL' => $tglLast,
|
|
'KET' => $ketLast,
|
|
'STAT' => $statLast,
|
|
'SHOW' => $show,
|
|
];
|
|
} else if ($datHpne[0]['STATUS_HPNE']==6 OR $datHpne[0]['STATUS_HPNE']==8) {
|
|
$datPerhatian[$countPerhatian++] = [
|
|
'ID' => $key['ID_PENAWARAN'],
|
|
'TANGGAL' => $key['TANGGAL'],
|
|
'KOP' => $key['CORP_ID'],
|
|
'JENIS' => $key['JENIS_PENAWARAN'],
|
|
'KODE' => $key['KODE_PENAWARAN'],
|
|
'CIPTA' => $key['CIPTA_PENAWARAN'],
|
|
'CHANNEL' => $salesChannel,
|
|
'OTHER' => $salesOther,
|
|
'PELANGGAN' => $key['PELANGGAN_PENAWARAN'],
|
|
'UP' => $key['UP_PENAWARAN'],
|
|
'LAMPIRAN' => $key['LAMPIRAN_PENAWARAN'],
|
|
'PERIHAL' => $key['PERIHAL_PENAWARAN'],
|
|
'NILAI' => $key['NILAI'],
|
|
'TGL' => $tglLast,
|
|
'KET' => $ketLast,
|
|
'STAT' => $statLast,
|
|
'SHOW' => $show,
|
|
];
|
|
} else if ($datHpne[0]['STATUS_HPNE']==7 OR $datHpne[0]['STATUS_HPNE']==9) {
|
|
$datTercapai[$countTercapai++] = [
|
|
'ID' => $key['ID_PENAWARAN'],
|
|
'TANGGAL' => $key['TANGGAL'],
|
|
'KOP' => $key['CORP_ID'],
|
|
'JENIS' => $key['JENIS_PENAWARAN'],
|
|
'KODE' => $key['KODE_PENAWARAN'],
|
|
'CIPTA' => $key['CIPTA_PENAWARAN'],
|
|
'CHANNEL' => $salesChannel,
|
|
'OTHER' => $salesOther,
|
|
'PELANGGAN' => $key['PELANGGAN_PENAWARAN'],
|
|
'UP' => $key['UP_PENAWARAN'],
|
|
'LAMPIRAN' => $key['LAMPIRAN_PENAWARAN'],
|
|
'PERIHAL' => $key['PERIHAL_PENAWARAN'],
|
|
'NILAI' => $key['NILAI'],
|
|
'TGL' => $tglLast,
|
|
'KET' => $ketLast,
|
|
'STAT' => $statLast,
|
|
'SHOW' => $show,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
$datSpe = $this->Amod->getData_StatusPenawaran_not09();
|
|
|
|
$datStpos = $this->Amod->getData_SetTogglePosisi_byKARYAWAN_byMENU($id_karyawan, $id_menu);
|
|
if ($datStpos==FALSE) { $posisiToggle = 0; } else { $posisiToggle = $datStpos[0]['AKTIF_STPOS']; }
|
|
|
|
$data = array(
|
|
'sidebar' => "menu kpi",
|
|
'navChild' => "kpi tindaklanjut",
|
|
'id_menu' => $id_menu,
|
|
'hak' => $hak,
|
|
'tampil' => $tampil,
|
|
'posisiToggle' => $posisiToggle,
|
|
'spe' => $datSpe,
|
|
'belum' => $datBelum,
|
|
'berjalan' => $datBerjalan,
|
|
'budget' => $datBudget,
|
|
'perhatian' => $datPerhatian,
|
|
'tercapai' => $datTercapai,
|
|
'countBelum' => $countBelum,
|
|
'countBerjalan' => $countBerjalan,
|
|
'countBudget' => $countBudget,
|
|
'countPerhatian' => $countPerhatian,
|
|
'countTercapai' => $countTercapai,
|
|
);
|
|
$this->load->view('proses/KP_Sub1_TindakLanjut_1', $data);
|
|
}
|
|
|
|
public function KP_Tambah_Sub1_C1_DataHistoriPenawaran() {
|
|
$id_penawaran = $this->input->post('id_penawaran');
|
|
$status_hpne = $this->input->post('status_hpne');
|
|
$ket_hpne = $this->input->post('ket_hpne');
|
|
$fu_hpne = $this->input->post('fu_hpne');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
$ket_hpne = preg_replace('/\R+/', " " , $ket_hpne);
|
|
|
|
$value = 0;
|
|
$datPenawaran = $this->Amod->getData_Penawaran_byID($id_penawaran);
|
|
if ($datPenawaran==FALSE) {
|
|
$value = 2;
|
|
} else {
|
|
$input = [
|
|
'PENAWARAN_ID' => $id_penawaran,
|
|
'CIPTA_HPNE' => "Oleh $panggilan pada $timestamp",
|
|
'KET_HPNE' => $ket_hpne,
|
|
'FU_HPNE' => $fu_hpne,
|
|
'STATUS_HPNE' => $status_hpne,
|
|
];
|
|
$action = $this->Amod->create('histori_penawaran', $input);
|
|
|
|
$value = 1;
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
}
|
|
|
|
public function KP_Ubah_Sub1_C1_DataHistoriPenawaran() {
|
|
$id_hpne = $this->input->post('id_hpne');
|
|
$id_penawaran = $this->input->post('id_penawaran');
|
|
$status_hpne = $this->input->post('status_hpne');
|
|
$ket_hpne = $this->input->post('ket_hpne');
|
|
$fu_hpne = $this->input->post('fu_hpne');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
$ket_hpne = preg_replace('/\R+/', " " , $ket_hpne);
|
|
|
|
$value = 0;
|
|
$datPenawaran = $this->Amod->getData_Penawaran_byID($id_penawaran);
|
|
if ($datPenawaran==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$datHpne = $this->Amod->getData_HistoriPenawaran_byID($id_hpne);
|
|
if ($datHpne==FALSE) {
|
|
$value = 2;
|
|
} else {
|
|
$update = [
|
|
'CIPTA_HPNE' => "Oleh $panggilan pada $timestamp",
|
|
'KET_HPNE' => $ket_hpne,
|
|
'FU_HPNE' => $fu_hpne,
|
|
'STATUS_HPNE' => $status_hpne,
|
|
];
|
|
$action = $this->Amod->update('histori_penawaran', $update, 'ID_HPNE', $id_hpne);
|
|
|
|
$value = 1;
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
}
|
|
|
|
public function KP_Hapus_Sub1_C1_DataHistoriPenawaran() {
|
|
$id_hpne = $this->input->post('id_hpne');
|
|
$id_penawaran = $this->input->post('id_penawaran');
|
|
|
|
$value = 0;
|
|
$datPenawaran = $this->Amod->getData_Penawaran_byID($id_penawaran);
|
|
if ($datPenawaran==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$datHpne = $this->Amod->getData_HistoriPenawaran_byID($id_hpne);
|
|
if ($datHpne==FALSE) {
|
|
$value = 2;
|
|
} else {
|
|
$action = $this->Amod->delete('histori_penawaran', $id_hpne, 'ID_HPNE');
|
|
|
|
$value = 1;
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
}
|
|
|
|
public function PB_Sub1_SuratJalan_1() {
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$now = date('Y-m-d');
|
|
|
|
$datShm = $this->Amod->getData_SetHakMenu_byKARYAWAN_byKODE_byNAMA($id_karyawan, "PB", "TRANSAKSI - Surat Jalan");
|
|
$id_menu = $datShm[0]['MENU_ID'];
|
|
$hak = $datShm[0]['AKSES_ID'];
|
|
$tampil = $datShm[0]['NAMA_AKSES'];
|
|
|
|
$datCorp = $this->Amod->getData_Corp_bySTATUS(1);
|
|
$datSupplier = $this->Amod->getData_Supplier_bySTATUS(1);
|
|
$datPak = $this->Amod->getData_PeriodeAkuntansi_byPERIODE_bySTATUS($now, 0);
|
|
if ($datPak==TRUE) {
|
|
$kunciTombol = 0;
|
|
$datPengadaan = $this->Amod->getData_Pengadaan_bySTATUS(1);
|
|
$no = 0;
|
|
foreach ($datPengadaan as $key) {
|
|
$datDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN($key['ID_PENGADAAN']);
|
|
$list = "";
|
|
$nolist = 1;
|
|
foreach ($datDpg as $dat) {
|
|
$qty = $dat['QTY_DPG'];
|
|
$kode = $dat['KODE_BARANG'];
|
|
if ($nolist==count($datDpg)) {
|
|
$list .= "$qty EA $kode";
|
|
} else {
|
|
$list .= "$qty EA $kode, ";
|
|
$nolist++;
|
|
}
|
|
}
|
|
$datPengadaan[$no] += ['LIST' => $list];
|
|
$datPengadaan[$no++] += ['BARANG' => $datDpg];
|
|
}
|
|
$sjBelum = $this->Amod->getData_Pembelian_statusNull();
|
|
$sjRevisi = $this->Amod->getData_Pembelian_bySTATUS(2);
|
|
$sjProses = $this->Amod->getData_Pembelian_bySTATUS(0);
|
|
$no = 0;
|
|
foreach ($sjProses as $key) {
|
|
$cekPengadaan = $this->Amod->getData_Pengadaan_byPEMBELIAN($key['ID_PEMBELIAN']);
|
|
$sjProses[$no++] += ['PENGADAAN' => $cekPengadaan];
|
|
}
|
|
$sjTahan = $this->Amod->getData_Pembelian_tahanNotNull();
|
|
$countPengadaan = count($datPengadaan);
|
|
$countBelum = count($sjBelum);
|
|
$countRevisi = count($sjRevisi);
|
|
$countProses = count($sjProses);
|
|
$countTahan = count($sjTahan);
|
|
} else {
|
|
$kunciTombol = 1;
|
|
$datPengadaan = NULL;
|
|
$sjBelum = NULL;
|
|
$sjRevisi = NULL;
|
|
$sjProses = NULL;
|
|
$sjTahan = NULL;
|
|
$countPengadaan = 0;
|
|
$countBelum = 0;
|
|
$countRevisi = 0;
|
|
$countProses = 0;
|
|
$countTahan = 0;
|
|
}
|
|
|
|
$datStpos = $this->Amod->getData_SetTogglePosisi_byKARYAWAN_byMENU($id_karyawan, $id_menu);
|
|
if ($datStpos==FALSE) { $posisiToggle = 0; } else { $posisiToggle = $datStpos[0]['AKTIF_STPOS']; }
|
|
|
|
$data = array(
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian suratjalan",
|
|
'corp' => $datCorp,
|
|
'supplier' => $datSupplier,
|
|
'pengadaan' => $datPengadaan,
|
|
'sjBelum' => $sjBelum,
|
|
'sjRevisi' => $sjRevisi,
|
|
'sjProses' => $sjProses,
|
|
'sjTahan' => $sjTahan,
|
|
'countPengadaan' => $countPengadaan,
|
|
'countBelum' => $countBelum,
|
|
'countRevisi' => $countRevisi,
|
|
'countProses' => $countProses,
|
|
'countTahan' => $countTahan,
|
|
'id_menu' => $id_menu,
|
|
'hak' => $hak,
|
|
'tampil' => $tampil,
|
|
'posisiToggle' => $posisiToggle,
|
|
'kunciTombol' => $kunciTombol,
|
|
'tgl' => $now,
|
|
);
|
|
$this->load->view('proses/PB_Sub1_SuratJalan_1', $data);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A1_DataDaftarBeli() {
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
|
|
$data = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
$no = 0;
|
|
$sn = "";
|
|
foreach ($data as $key) {
|
|
$datSnb = $this->Amod->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSnb as $dat) {
|
|
$nama_snb = $dat['NAMA_SNB'];
|
|
$sn .= "$nama_snb, ";
|
|
}
|
|
$data[$no++] += ['SN' => $sn];
|
|
$sn = "";
|
|
}
|
|
|
|
$this->output_json([
|
|
'total' => sizeof($data),
|
|
'data' => $data,
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER']
|
|
]);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A1_DataPengadaan() {
|
|
$countPengadaan = $this->input->post('countPengadaan');
|
|
|
|
$newPengadaan = $this->Amod->getCount_Pengadaan_bySTATUS(1);
|
|
|
|
if ($countPengadaan!=$newPengadaan) {
|
|
$value = 1;
|
|
} else {
|
|
$value = 0;
|
|
}
|
|
|
|
$this->output_json(['value' => $value]);
|
|
}
|
|
|
|
public function PB_Tambah_Sub1_A1_DataPembelian() {
|
|
$id_corp = $this->input->post('id_corpnew');
|
|
$id_supplier = $this->input->post('id_suppliernew');
|
|
$gudang_pembelian = $this->input->post('gudang_pembeliannew');
|
|
$alur_pembelian = $this->input->post('alur_pembeliannew');
|
|
$tgl_sjbeli = $this->input->post('tgl_sjbelinew');
|
|
$sj_pembelian = $this->input->post('sj_pembeliannew');
|
|
$po_pembelian = $this->input->post('po_pembeliannew');
|
|
$id_pengadaan = $this->input->post('id_pengadaannew');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
$po_pembelian = strtoupper($po_pembelian);
|
|
$limit = date('Y-m-01');
|
|
$now = date('Y-m-d');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_bySJ($sj_pembelian);
|
|
if ($datPembelian==TRUE) {
|
|
$this->session->set_flashdata('sj_same', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($tgl_sjbeli)>strtotime($now)) {
|
|
$this->session->set_flashdata('tgl_moreday', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($tgl_sjbeli)<strtotime($limit)) {
|
|
$this->session->set_flashdata('tgl_beforelock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($id_pengadaan!="") {
|
|
$datPengadaan = $this->Amod->getData_Pengadaan_byID_bySTATUS($id_pengadaan, 1);
|
|
if ($datPengadaan==FALSE) {
|
|
$this->session->set_flashdata('pengadaan_same', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
$kode_pembelian = $this->Amod->generate_kodePembelian(1);
|
|
$input = [
|
|
'CIPTA_PEMBELIAN' => "Oleh $panggilan pada $timestamp",
|
|
'KODE_PEMBELIAN' => $kode_pembelian,
|
|
'TGL_PEMBELIAN' => $now,
|
|
'GUDANG_PEMBELIAN' => $gudang_pembelian,
|
|
'ALUR_PEMBELIAN' => $alur_pembelian,
|
|
'CORP_ID' => $id_corp,
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'TGL_SJBELI' => $tgl_sjbeli,
|
|
'SJ_PEMBELIAN' => $sj_pembelian,
|
|
'PO_PEMBELIAN' => $po_pembelian,
|
|
'PPN_PEMBELIAN' => $ppn_pembelian
|
|
];
|
|
$action = $this->Amod->create('pembelian', $input);
|
|
|
|
if ($id_pengadaan!="") {
|
|
$id_pembelian = $this->Amod->getMax_ID_Pembelian();
|
|
$id_pembelian = $id_pembelian[0]['ID_PEMBELIAN'];
|
|
|
|
$datDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN($id_pengadaan);
|
|
foreach ($datDpg as $key) {
|
|
$input = [
|
|
'DPG_ID' => $key['ID_DPG'],
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DB' => $key['QTY_DPG'],
|
|
'RETUR_DB' => '0',
|
|
'HARGA_DB' => $key['HARGA_DPG']-$key['DISKON_DPG']
|
|
];
|
|
$action = $this->Amod->create('daftar_beli', $input);
|
|
}
|
|
|
|
$update = [
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'STATUS_PENGADAAN' => '2',
|
|
'LINK_PENGADAAN' => "Oleh $panggilan pada $timestamp",
|
|
];
|
|
$action = $this->Amod->update('pengadaan', $update, 'ID_PENGADAAN', $id_pengadaan);
|
|
}
|
|
|
|
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 PB_Ubah_Sub1_A1_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianed');
|
|
$id_corp = $this->input->post('id_corped');
|
|
$id_supplier = $this->input->post('id_suppliered');
|
|
$gudang_pembelian = $this->input->post('gudang_pembelianed');
|
|
$alur_pembelian = $this->input->post('alur_pembelianed');
|
|
$tgl_sjbeli = $this->input->post('tgl_sjbelied');
|
|
$sj_pembelian = $this->input->post('sj_pembelianed');
|
|
$po_pembelian = $this->input->post('po_pembelianed');
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
$po_pembelian = strtoupper($po_pembelian);
|
|
$limit = date('Y-m-01');
|
|
$now = date('Y-m-d');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_statusNull($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($tgl_sjbeli)>strtotime($now)) {
|
|
$this->session->set_flashdata('tgl_moreday', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$cekSj = $this->Amod->getData_Pembelian_bySJ($sj_pembelian, $id_pembelian);
|
|
if ($cekSj==TRUE) {
|
|
$this->session->set_flashdata('sj_same', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($tgl_sjbeli)<strtotime($limit)) {
|
|
$this->session->set_flashdata('tgl_beforelock', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$update = [
|
|
'TGL_PEMBELIAN' => $now,
|
|
'CORP_ID' => $id_corp,
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'TGL_SJBELI' => $tgl_sjbeli,
|
|
'GUDANG_PEMBELIAN' => $gudang_pembelian,
|
|
'ALUR_PEMBELIAN' => $alur_pembelian,
|
|
'SJ_PEMBELIAN' => $sj_pembelian,
|
|
'PO_PEMBELIAN' => $po_pembelian,
|
|
];
|
|
$action = $this->Amod->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 PB_Hapus_Sub1_A1_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembeliandel');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$limit = date('Y-m-01');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_statusNull($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($limit)>strtotime($datPembelian[0]['TGL_PEMBELIAN'])) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datPengadaan = $this->Amod->getData_Pengadaan_byPEMBELIAN($id_pembelian);
|
|
if ($datPengadaan==TRUE) {
|
|
$update = [
|
|
'PEMBELIAN_ID' => NULL,
|
|
'LINK_PENGADAAN' => NULL,
|
|
'STATUS_PENGADAAN' => '1'
|
|
];
|
|
$action = $this->Amod->update('pengadaan', $update, 'ID_PENGADAAN', $datPengadaan[0]['ID_PENGADAAN']);
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
$action = $this->Amod->delete('sn_beli', $key['ID_DB'], 'DB_ID');
|
|
}
|
|
|
|
$action = $this->Amod->delete('daftar_beli', $id_pembelian, 'PEMBELIAN_ID');
|
|
|
|
$update = [
|
|
'SJ_PEMBELIAN' => NULL,
|
|
'STATUS_PEMBELIAN' => '9',
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, '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 PB_Revisi_Sub1_A1_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$limit = date('Y-m-01');
|
|
|
|
$value = 0;
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID_bySTATUS($id_pembelian, 0);
|
|
if ($datPembelian==FALSE) {
|
|
$value = 4;
|
|
} else {
|
|
if (strtotime($limit)>strtotime($datPembelian[0]['TGL_PEMBELIAN'])) {
|
|
$value = 3;
|
|
} else {
|
|
$countDb = $this->Amod->getCount_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
if ($countDb==0) {
|
|
$value = 2;
|
|
} else {
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
$value = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
}
|
|
|
|
public function PB_Batal_Sub1_A1_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianvoid');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$limit = date('Y-m-01');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID_bySTATUS($id_pembelian, 2);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if (strtotime($limit)>strtotime($datPembelian[0]['TGL_PEMBELIAN'])) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
$action = $this->Amod->delete('sn_beli', $key['ID_DB'], 'DB_ID');
|
|
}
|
|
|
|
$action = $this->Amod->delete('daftar_beli', $id_pembelian, 'PEMBELIAN_ID');
|
|
|
|
$update = [
|
|
'SJ_PEMBELIAN' => NULL,
|
|
'STATUS_PEMBELIAN' => '9',
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function PB_Sub1_SuratJalan_2($id) {
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id);
|
|
$datCorp = $this->Amod->getData_Corp_bySTATUS(1);
|
|
$datSupplier = $this->Amod->getData_Supplier_bySTATUS(1);
|
|
|
|
$datHhbso = $this->Amod->getData_HasilHitungBarangSo_status0_2();
|
|
foreach ($datHhbso as $key) {
|
|
$cekDo = $this->Amod->getData_DaftarOrder_byBARANG_status0_3($key['BARANG_ID']);
|
|
if ($cekDo==FALSE) {
|
|
$action = $this->Amod->delete('hasil_hitungbarangso', $key['ID_HHBSO'], 'ID_HHBSO');
|
|
}
|
|
}
|
|
|
|
$datPengadaan = $this->Amod->getData_Pengadaan_bySTATUS(1);
|
|
$no = 0;
|
|
foreach ($datPengadaan as $key) {
|
|
$datDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN($key['ID_PENGADAAN']);
|
|
$list = "";
|
|
$nolist = 1;
|
|
foreach ($datDpg as $dat) {
|
|
$qty = $dat['QTY_DPG'];
|
|
$kode = $dat['KODE_BARANG'];
|
|
if ($nolist==count($datDpg)) {
|
|
$list .= "$qty EA $kode";
|
|
} else {
|
|
$list .= "$qty EA $kode, ";
|
|
$nolist++;
|
|
}
|
|
}
|
|
$datPengadaan[$no] += ['LIST' => $list];
|
|
$datPengadaan[$no++] += ['BARANG' => $datDpg];
|
|
}
|
|
|
|
$datHhbso = $this->Amod->getData_HasilHitungBarangSo_status0_2_orderASC();
|
|
$countHhbso = round((count($datHhbso)/2), 0, PHP_ROUND_HALF_UP);
|
|
$sn1 = "";
|
|
$sn2 = "";
|
|
$no = 1;
|
|
foreach ($datHhbso as $key) {
|
|
$kode = $key['KODE_BARANG'];
|
|
if ($no<=$countHhbso) {
|
|
$sn1 .= "[$no] $kode</br>";
|
|
} else {
|
|
$sn2 .= "[$no] $kode</br>";
|
|
}
|
|
$no++;
|
|
}
|
|
|
|
$cekPengadaan = $this->Amod->getData_Pengadaan_byPEMBELIAN($id);
|
|
if ($cekPengadaan==TRUE) {
|
|
$lockDelete = $cekPengadaan[0]['ID_PENGADAAN'];
|
|
} else {
|
|
$lockDelete = 0;
|
|
}
|
|
|
|
$data = array(
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian suratjalan",
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER'],
|
|
'alur_pembelian' => $datPembelian[0]['ALUR_PEMBELIAN'],
|
|
'status_pembelian' => $datPembelian[0]['STATUS_PEMBELIAN'],
|
|
'tgl_sjbeli' => $datPembelian[0]['TGL_SJBELI'],
|
|
'id_supplier' => $datPembelian[0]['SUPPLIER_ID'],
|
|
'id_corp' => $datPembelian[0]['CORP_ID'],
|
|
'gudang_pembelian' => $datPembelian[0]['GUDANG_PEMBELIAN'],
|
|
'sj_pembelian' => $datPembelian[0]['SJ_PEMBELIAN'],
|
|
'po_pembelian' => $datPembelian[0]['PO_PEMBELIAN'],
|
|
'sn1' => $sn1,
|
|
'sn2' => $sn2,
|
|
'corp' => $datCorp,
|
|
'pengadaan' => $datPengadaan,
|
|
'supplier' => $datSupplier,
|
|
'lockDelete' => $lockDelete,
|
|
'id_pembelian' => $id,
|
|
);
|
|
$this->load->view('proses/PB_Sub1_SuratJalan_2', $data);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A2_JumlahDaftarBeli() {
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
|
|
$countDb = $this->Amod->getCount_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
|
|
$this->output_json([
|
|
'total' => $countDb
|
|
]);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A2_JumlahSnBeli() {
|
|
$id_db = $this->input->post('id_db');
|
|
|
|
$countSnb = $this->Amod->getCount_SnBeli_byDB($id_db);
|
|
|
|
$this->output_json([
|
|
'total' => $countSnb
|
|
]);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A2_DataDaftarBeli() {
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
|
|
$data = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
$no = 0;
|
|
$sn = "";
|
|
foreach ($data as $key) {
|
|
$datSnb = $this->Amod->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSnb as $dat) {
|
|
$nama_snb = $dat['NAMA_SNB'];
|
|
$sn .= "$nama_snb, ";
|
|
}
|
|
|
|
$countSnb = $this->Amod->getCount_SnBeli_byDB($key['ID_DB']);
|
|
$data[$no] += ['COUNT' => $countSnb];
|
|
$data[$no++] += ['SN' => $sn];
|
|
|
|
$sn = "";
|
|
}
|
|
|
|
$this->output_json([
|
|
'total' => sizeof($data),
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
public function PB_Ambil_Sub1_A2_DataSnBeli() {
|
|
$id_db = $this->input->post('id_db');
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byID($id_db);
|
|
$data = $this->Amod->getData_SnBeli_byDB($id_db);
|
|
$this->output_json([
|
|
'total' => sizeof($data),
|
|
'data' => $data,
|
|
'qty' => $datDb[0]['QTY_DB']
|
|
]);
|
|
}
|
|
|
|
public function PB_Simpan_Sub1_A2_DataDaftarBeli() {
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$id_barang = $this->input->post('id_barang');
|
|
$qty_db = $this->input->post('qty_db');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$value = 0;
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$value = 4;
|
|
} else {
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL OR $datPembelian[0]['STATUS_PEMBELIAN']==0 OR $datPembelian[0]['STATUS_PEMBELIAN']==2) {
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN_byBARANG($id_pembelian, $id_barang);
|
|
if ($datDb==TRUE) {
|
|
$value = 2;
|
|
} else {
|
|
$input = [
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'BARANG_ID' => $id_barang,
|
|
'QTY_DB' => $qty_db,
|
|
'RETUR_DB' => '0',
|
|
'HARGA_DB' => '0',
|
|
];
|
|
$action = $this->Amod->create('daftar_beli', $input);
|
|
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL) {
|
|
|
|
} else if ($datPembelian[0]['STATUS_PEMBELIAN']==0) {
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp",
|
|
'STATUS_PEMBELIAN' => '2'
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
} else if ($datPembelian[0]['STATUS_PEMBELIAN']==2) {
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
}
|
|
$value = 1;
|
|
}
|
|
} else {
|
|
$value = 3;
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
|
|
}
|
|
|
|
public function PB_Simpan_Sub1_A2_DataSnbBarcode() {
|
|
$id_snb = $this->input->post('id_snb');
|
|
$id_db = $this->input->post('id_db');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$nama_snb = $this->input->post('nama_snb');
|
|
$nama_snb = strtoupper($nama_snb);
|
|
|
|
$value = 0;
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$value = 6;
|
|
} else {
|
|
$datDb = $this->Amod->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$value = 5;
|
|
} else {
|
|
$datSnStock = $this->Amod->getData_SnStock_byNAMA_allStatus($nama_snb);
|
|
if ($datSnStock==TRUE) {
|
|
$value = 4;
|
|
} else {
|
|
$countBefore = $this->Amod->getCount_SnBeli_byDB($id_db);
|
|
if ($countBefore>=$datDb[0]['QTY_DB']) {
|
|
$value = 3;
|
|
} else {
|
|
$input = [
|
|
'NAMA_SNB' => $nama_snb,
|
|
'DB_ID' => $id_db,
|
|
];
|
|
$action = $this->Amod->create('sn_beli', $input);
|
|
|
|
$countAfter = $this->Amod->getCount_SnBeli_byDB($id_db);
|
|
if ($countAfter==$datDb[0]['QTY_DB']) {
|
|
$value = 2;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value,
|
|
]);
|
|
}
|
|
|
|
public function PB_Hapus_Sub1_A2_DataDaftarBeli() {
|
|
$id_db = $this->input->post('id_db');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$value = 0;
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$value = 4;
|
|
} else {
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL OR $datPembelian[0]['STATUS_PEMBELIAN']==0 OR $datPembelian[0]['STATUS_PEMBELIAN']==2) {
|
|
$datDb = $this->Amod->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$value = 2;
|
|
} else {
|
|
if ($datDb[0]['TYPE_JENIS']==1) {
|
|
$action = $this->Amod->delete('sn_beli', $id_db, 'DB_ID');
|
|
}
|
|
$action = $this->Amod->delete('daftar_beli', $id_db, 'ID_DB');
|
|
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL) {
|
|
|
|
} else if ($datPembelian[0]['STATUS_PEMBELIAN']==0) {
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp",
|
|
'STATUS_PEMBELIAN' => '2'
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
} else if ($datPembelian[0]['STATUS_PEMBELIAN']==2) {
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
}
|
|
|
|
$value = 1;
|
|
}
|
|
} else {
|
|
$value = 3;
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value
|
|
]);
|
|
|
|
}
|
|
|
|
public function PB_Hapus_Sub1_A2_DataSnBeli() {
|
|
$id_snb = $this->input->post('id_snb');
|
|
$id_db = $this->input->post('id_db');
|
|
$id_pembelian = $this->input->post('id_pembelian');
|
|
|
|
$value = 0;
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$value = 5;
|
|
} else {
|
|
$datDb = $this->Amod->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$value = 4;
|
|
} else {
|
|
$datSnb = $this->Amod->getData_SnBeli_byID($id_snb);
|
|
if ($datSnb==FALSE) {
|
|
$value = 3;
|
|
} else {
|
|
$countBefore = $this->Amod->getCount_SnBeli_byDB($id_db);
|
|
$action = $this->Amod->delete('sn_beli', $id_snb, 'ID_SNB');
|
|
|
|
if ($countBefore==$datDb[0]['QTY_DB']) {
|
|
$value = 2;
|
|
} else {
|
|
$value = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->output_json([
|
|
'value' => $value,
|
|
]);
|
|
}
|
|
|
|
public function PB_Proses_Sub1_A2_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianpro');
|
|
$tgl_sjbeli = $this->input->post('tgl_sjbelipro');
|
|
$id_supplier = $this->input->post('id_supplierpro');
|
|
$id_corp = $this->input->post('id_corppro');
|
|
$sj_pembelian = $this->input->post('sj_pembelianpro');
|
|
$po_pembelian = $this->input->post('po_pembelianpro');
|
|
$gudang_pembelian = $this->input->post('gudang_pembelianpro');
|
|
$alur_pembelian = $this->input->post('alur_pembelianpro');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$sj_pembelian = strtoupper($sj_pembelian);
|
|
$po_pembelian = strtoupper($po_pembelian);
|
|
$now = date('Y-m-d');
|
|
$limit = date('Y-m-01');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
if (strtotime($limit)>strtotime($datPembelian[0]['TGL_PEMBELIAN'])) {
|
|
$this->session->set_flashdata('tgl_diffmonth', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']==1 AND $key['ALUR_PEMBELIAN']==1) {
|
|
$qtyReal = $this->Amod->getCount_SnBeli_byDB($key['ID_DB']);
|
|
if ($qtyReal<$key['QTY_DB']) {
|
|
$this->session->set_flashdata('sncount_less', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL) {
|
|
$update = [
|
|
'STATUS_PEMBELIAN' => '0',
|
|
'TGL_PEMBELIAN' => $now,
|
|
'PROSES_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
} else {
|
|
if ($gudang_pembelian==NULL) {
|
|
$gudang_pembelian = $datPembelian[0]['GUDANG_PEMBELIAN'];
|
|
}
|
|
if ($alur_pembelian==NULL) {
|
|
$alur_pembelian = $datPembelian[0]['ALUR_PEMBELIAN'];
|
|
}
|
|
if ($id_corp==NULL) {
|
|
$id_corp = $datPembelian[0]['CORP_ID'];
|
|
}
|
|
if ($id_supplier==NULL) {
|
|
$id_supplier = $datPembelian[0]['SUPPLIER_ID'];
|
|
}
|
|
if ($tgl_sjbeli==NULL) {
|
|
$tgl_sjbeli = $datPembelian[0]['TGL_SJBELI'];
|
|
}
|
|
if ($sj_pembelian==NULL) {
|
|
$sj_pembelian = $datPembelian[0]['SJ_PEMBELIAN'];
|
|
}
|
|
if ($po_pembelian==NULL) {
|
|
$po_pembelian = $datPembelian[0]['PO_PEMBELIAN'];
|
|
}
|
|
|
|
$update = [
|
|
'STATUS_PEMBELIAN' => '0',
|
|
'TGL_SJBELI' => $tgl_sjbeli,
|
|
'CORP_ID' => $id_corp,
|
|
'SUPPLIER_ID' => $id_supplier,
|
|
'GUDANG_PEMBELIAN' => $gudang_pembelian,
|
|
'ALUR_PEMBELIAN' => $alur_pembelian,
|
|
'SJ_PEMBELIAN' => $sj_pembelian,
|
|
'PO_PEMBELIAN' => $po_pembelian,
|
|
'TGL_PEMBELIAN' => $now,
|
|
'PROSES_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
}
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
if ($datPembelian[0]['STATUS_PEMBELIAN']==NULL) {
|
|
$this->session->set_flashdata('data_lock', 'diproses');
|
|
} else {
|
|
$this->session->set_flashdata('data_lock', 'direvisi');
|
|
}
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diproses');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function PB_Link_Sub1_A2_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianlink');
|
|
$id_pengadaan = $this->input->post('id_pengadaanlink');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE OR $datPembelian[0]['STATUS_PEMBELIAN']==1) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
$datPengadaan = $this->Amod->getData_Pengadaan_byID_bySTATUS($id_pengadaan, 1);
|
|
if ($datPengadaan==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
//Cek apakah Kode Barang dan Kuantiti sama
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
$match = 0;
|
|
foreach ($datDb as $key) {
|
|
$cekDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN_byBARANG($id_pengadaan, $key['BARANG_ID']);
|
|
if ($cekDpg==TRUE) {
|
|
if ($cekDpg[0]['QTY_DPG']==$key['QTY_DB']) {
|
|
$match++;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($match==count($datDb)) {
|
|
foreach ($datDb as $key) {
|
|
$datDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN_byBARANG($id_pengadaan, $key['BARANG_ID']);
|
|
|
|
$update = [
|
|
'DPG_ID' => $datDpg[0]['ID_DPG'],
|
|
'HARGA_DB' => $datDpg[0]['HARGA_DPG']-$datDpg[0]['DISKON_DPG']
|
|
];
|
|
$action = $this->Amod->update('daftar_beli', $update, 'ID_DB', $key['ID_DB']);
|
|
}
|
|
} else {
|
|
foreach ($datDb as $key) {
|
|
$action = $this->Amod->delete('sn_beli', $key['ID_DB'], 'DB_ID');
|
|
}
|
|
$action = $this->Amod->delete('daftar_beli', $id_pembelian, 'PEMBELIAN_ID');
|
|
|
|
$datDpg = $this->Amod->getData_DaftarPengadaan_byPENGADAAN($id_pengadaan);
|
|
foreach ($datDpg as $key) {
|
|
$input = [
|
|
'DPG_ID' => $key['ID_DPG'],
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'QTY_DB' => $key['QTY_DPG'],
|
|
'RETUR_DB' => '0',
|
|
'HARGA_DB' => $key['HARGA_DPG']-$key['DISKON_DPG']
|
|
];
|
|
$action = $this->Amod->create('daftar_beli', $input);
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp",
|
|
'SUPPLIER_ID' => $datPengadaan[0]['SUPPLIER_ID'],
|
|
'CORP_ID' => $datPengadaan[0]['CORP_ID'],
|
|
'PO_PEMBELIAN' => $datPengadaan[0]['PO_PENGADAAN']
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
$update = [
|
|
'LINK_PENGADAAN' => "Oleh $panggilan pada $timestamp",
|
|
'PEMBELIAN_ID' => $id_pembelian,
|
|
'STATUS_PENGADAAN' => '2'
|
|
];
|
|
$action = $this->Amod->update('pengadaan', $update, 'ID_PENGADAAN', $id_pengadaan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'ditautkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditautkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function PB_Batal_Sub1_A2_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianvoid');
|
|
$id_pengadaan = $this->input->post('id_pengadaanvoid');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
$action = $this->Amod->delete('sn_beli', $key['ID_DB'], 'DB_ID');
|
|
}
|
|
|
|
$action = $this->Amod->delete('daftar_beli', $id_pembelian, 'PEMBELIAN_ID');
|
|
|
|
$update = [
|
|
'SJ_PEMBELIAN' => NULL,
|
|
'STATUS_PEMBELIAN' => '9',
|
|
'REVISI_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
$update = [
|
|
'LINK_PENGADAAN' => NULL,
|
|
'PEMBELIAN_ID' => NULL,
|
|
'STATUS_PENGADAAN' => '1'
|
|
];
|
|
$action = $this->Amod->update('pengadaan', $update, 'ID_PENGADAAN', $id_pengadaan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dibatalkan');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dibatalkan');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
public function PB_Sub1_SuratJalan_3($id) {
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id);
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id);
|
|
$no = 0;
|
|
foreach ($datDb as $key) {
|
|
$real = $this->Amod->getCount_SnBeli_byDB($key['ID_DB']);
|
|
$datSnb = $this->Amod->getData_SnBeli_byDB($key['ID_DB']);
|
|
$nosn = 0;
|
|
$sn = "";
|
|
foreach ($datSnb as $dat) {
|
|
$nama_snb = $dat['NAMA_SNB'];
|
|
if ($nosn==count($datSnb)) {
|
|
$sn .= "$nama_snb";
|
|
} else {
|
|
$sn .= "$nama_snb, ";
|
|
}
|
|
}
|
|
|
|
$datDb[$no] += ['REAL' => $real];
|
|
$datDb[$no++] += ['SN' => $sn];
|
|
}
|
|
|
|
$datBarang = $this->Amod->getData_Barang_bySTATUS_jenisNot2(1, NULL);
|
|
|
|
$data = array(
|
|
'sidebar' => "menu pembelian",
|
|
'navChild' => "pembelian suratjalan",
|
|
'nama_supplier' => $datPembelian[0]['NAMA_SUPPLIER'],
|
|
'kode_pembelian' => $datPembelian[0]['KODE_PEMBELIAN'],
|
|
'db' => $datDb,
|
|
'barang' => $datBarang,
|
|
'id_pembelian' => $id,
|
|
);
|
|
$this->load->view('proses/PB_Sub1_SuratJalan_3', $data);
|
|
}
|
|
|
|
public function PB_Ubah_Sub1_A3_DataDaftarBeli() {
|
|
$id_pembelian = $this->input->post('id_pembelianed');
|
|
$id_db = $this->input->post('id_dbed');
|
|
$id_barang = $this->input->post('id_baranged');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_tahanNotNull($id_pembelian);
|
|
if ($datPembelian==FALSE) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byID($id_db);
|
|
if ($datDb==FALSE) {
|
|
$this->session->set_flashdata('latest', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
if ($id_barang==$datDb[0]['BARANG_ID']) {
|
|
$this->session->set_flashdata('barangubah_same', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
$datHqAwal = $this->Amod->getData_HistoriKuantiti_byBARANG_byKODEBUKTI($datDb[0]['BARANG_ID'], $datPembelian[0]['KODE_PEMBELIAN']);
|
|
$id_hqAwal = $datHqAwal[0]['ID_HQ'];
|
|
|
|
//Cek apakah Histori Barang Lama adalah yang paling terakhir dari Kode Barang tersebut
|
|
$cekHqAwal = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1($datDb[0]['BARANG_ID']);
|
|
$valueCek = 0;
|
|
if ($id_hqAwal!=$cekHqAwal[0]['ID_HQ']) {
|
|
$valueCek = 1;
|
|
}
|
|
|
|
//Cek apakah Barang pengganti belum pernah ada Transaksi
|
|
$datHqPengganti = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1($id_barang);
|
|
if ($datHqPengganti==FALSE) {
|
|
$persediaan_hq = $datHqAwal[0]['NILAI_HQ'];
|
|
$update = [
|
|
'BARANG_ID' => $id_barang,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $datHqAwal[0]['MASUK_HQ'],
|
|
'AVG_HQ' => $datDb[0]['HARGA_DB']
|
|
];
|
|
$action = $this->Amod->update('histori_kuantiti', $update, 'ID_HQ', $id_hqAwal);
|
|
} else {
|
|
//Cek apakah diatas ID awal masih ada transaksi lanjutannya
|
|
$cekHqPengganti = $this->Amod->getData_HistoriKuantiti_byBARANG_afterID($id_barang, $id_hqAwal);
|
|
if ($cekHqPengganti==TRUE) {
|
|
$datHqSebelum = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($id_barang, $id_hqAwal);
|
|
if ($datHqSebelum==FALSE) {
|
|
$persediaan_hq = $datHqAwal[0]['NILAI_HQ'];
|
|
$sisa_hq = $datHqAwal[0]['MASUK_HQ'];
|
|
$avg_hq = $datDb[0]['HARGA_DB'];
|
|
} else {
|
|
$persediaan_hq = round(($datHqSebelum[0]['PERSEDIAAN_HQ']+$datHqAwal[0]['NILAI_HQ']),2);
|
|
$sisa_hq = $datHqSebelum[0]['SISA_HQ']+$datDb[0]['QTY_DB'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
}
|
|
|
|
$update = [
|
|
'BARANG_ID' => $id_barang,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
];
|
|
$action = $this->Amod->update('histori_kuantiti', $update, 'ID_HQ', $id_hqAwal);
|
|
|
|
foreach ($cekHqPengganti as $key) {
|
|
$datHqBeforeAfter = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($key['BARANG_ID'], $key['ID_HQ']);
|
|
if ($key['MASUK_HQ']==0) { // Transaksi Keluar
|
|
if ($datHqBeforeAfter[0]['SISA_HQ']==$key['KELUAR_HQ']) {
|
|
$persediaan_hq = 0;
|
|
$sisa_hq = 0;
|
|
} else {
|
|
$sisa_hq = $datHqBeforeAfter[0]['SISA_HQ']-$key['KELUAR_HQ'];
|
|
$persediaan_hq = round(($datHqBeforeAfter[0]['PERSEDIAAN_HQ']-($datHqBeforeAfter[0]['AVG_HQ']*$key['KELUAR_HQ'])),2);
|
|
}
|
|
|
|
$update = [
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $datHqBeforeAfter[0]['AVG_HQ'],
|
|
'SISA_HQ' => $sisa_hq,
|
|
];
|
|
} else if ($key['KELUAR_HQ']==0) { // Transaksi Masuk
|
|
$sisa_hq = $datHqBeforeAfter[0]['SISA_HQ']+$key['MASUK_HQ'];
|
|
$persediaan_hq = $datHqBeforeAfter[0]['PERSEDIAAN_HQ']+$key['NILAI_HQ'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq),2);
|
|
|
|
$update = [
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
];
|
|
}
|
|
$action = $this->Amod->update('histori_kuantiti', $update, 'ID_HQ', $key['ID_HQ']);
|
|
}
|
|
} else {
|
|
$persediaan_hq = $datHqPengganti[0]['PERSEDIAAN_HQ']+round(($datDb[0]['HARGA_DB']*$datDb[0]['QTY_DB']),2);
|
|
$sisa_hq = $datHqPengganti[0]['SISA_HQ']+$datDb[0]['QTY_DB'];
|
|
$avg_hq = round(($persediaan_hq/$sisa_hq), 2);
|
|
|
|
$update = [
|
|
'BARANG_ID' => $id_barang,
|
|
'PERSEDIAAN_HQ' => $persediaan_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
'AVG_HQ' => $avg_hq,
|
|
];
|
|
$action = $this->Amod->update('histori_kuantiti', $update, 'ID_HQ', $id_hqAwal);
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'PERSEDIAAN_KUANTITI' => $persediaan_hq
|
|
];
|
|
$action = $this->Amod->update('kuantiti', $update, 'ID_KUANTITI', $id_barang);
|
|
|
|
//Ubah Data Barang lama menggunakan Persediaan Lama
|
|
if ($valueCek==0) {
|
|
$datHqLama = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($datDb[0]['BARANG_ID'], $id_hqAwal);
|
|
if ($datHqLama==FALSE) {
|
|
$persediaanLama = 0;
|
|
} else {
|
|
$persediaanLama = $datHqLama[0]['PERSEDIAAN_HQ'];
|
|
}
|
|
} else if ($valueCek==1) {
|
|
$datHqLama = $this->Amod->getData_HistoriKuantiti_byBARANG_afterID($datDb[0]['BARANG_ID'], $id_hqAwal);
|
|
$persediaanLama = 0;
|
|
foreach ($datHqLama as $key) {
|
|
$datHqBeforeAfter = $this->Amod->getData_HistoriKuantiti_byBARANG_orderDESC_limit1_beforeID($key['BARANG_ID'], $key['ID_HQ']);
|
|
if ($key['MASUK_HQ']==0) { // Transaksi Keluar
|
|
if ($datHqBeforeAfter[0]['SISA_HQ']==$key['KELUAR_HQ']) {
|
|
$persediaanLama = 0;
|
|
$sisa_hq = 0;
|
|
} else {
|
|
$sisa_hq = $datHqBeforeAfter[0]['SISA_HQ']-$key['KELUAR_HQ'];
|
|
$persediaanLama = round(($datHqBeforeAfter[0]['PERSEDIAAN_HQ']-($datHqBeforeAfter[0]['AVG_HQ']*$key['KELUAR_HQ'])),2);
|
|
}
|
|
|
|
$update = [
|
|
'PERSEDIAAN_HQ' => $persediaanLama,
|
|
'AVG_HQ' => $datHqBeforeAfter[0]['AVG_HQ'],
|
|
'SISA_HQ' => $sisa_hq,
|
|
];
|
|
} else if ($key['KELUAR_HQ']==0) { // Transaksi Masuk
|
|
$sisa_hq = $datHqBeforeAfter[0]['SISA_HQ']+$key['MASUK_HQ'];
|
|
$persediaanLama = $datHqBeforeAfter[0]['PERSEDIAAN_HQ']+$key['NILAI_HQ'];
|
|
$avg_hq = round(($persediaanLama/$sisa_hq),2);
|
|
|
|
$update = [
|
|
'PERSEDIAAN_HQ' => $persediaanLama,
|
|
'AVG_HQ' => $avg_hq,
|
|
'SISA_HQ' => $sisa_hq,
|
|
];
|
|
}
|
|
$action = $this->Amod->update('histori_kuantiti', $update, 'ID_HQ', $key['ID_HQ']);
|
|
}
|
|
}
|
|
|
|
$update = [
|
|
'PERSEDIAAN_KUANTITI' => $persediaanLama
|
|
];
|
|
$action = $this->Amod->update('kuantiti', $update, 'ID_KUANTITI', $datDb[0]['BARANG_ID']);
|
|
|
|
$action = $this->Amod->delete('sn_beli', $id_db, 'DB_ID');
|
|
|
|
$update = [
|
|
'BARANG_ID' => $id_barang,
|
|
];
|
|
$action = $this->Amod->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 PB_Kunci_Sub1_A3_DataPembelian() {
|
|
$id_pembelian = $this->input->post('id_pembelianlock');
|
|
$panggilan = $this->session->userdata('nama_panggilan');
|
|
$timestamp = date('d/m/Y H:i:s');
|
|
$now = date('Y-m-d');
|
|
|
|
$datPembelian = $this->Amod->getData_Pembelian_byID($id_pembelian);
|
|
if ($datPembelian==FALSE OR $datPembelian[0]['ALUR_PEMBELIAN']!=2) {
|
|
$this->session->set_flashdata('not_valid', 'error');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
}
|
|
|
|
$datDb = $this->Amod->getData_DaftarBeli_byPEMBELIAN($id_pembelian);
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']==1) {
|
|
$countSnb = $this->Amod->getCount_SnBeli_byDB($key['ID_DB']);
|
|
if ($countSnb<$key['QTY_DB']) {
|
|
$this->session->set_flashdata('sncount_less', 'error');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($datDb as $key) {
|
|
if ($key['TYPE_JENIS']==1) {
|
|
$datSsp = $this->Amod->getData_SetSalesProduk_byMERK_byPRODUK($key['MERK_ID'], $key['PRODUK_ID']);
|
|
if ($datSsp==TRUE) {
|
|
$input = [
|
|
'DB_ID' => $key['ID_DB'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'SUPPLIER_ID' => $key['SUPPLIER_ID'],
|
|
'TGL_KPR' => $key['TGL_INVBELI'],
|
|
'NOTA_KPR' => $key['INV_PEMBELIAN'],
|
|
'TS_KPR' => $timestamp,
|
|
'HARGA_KPR' => round($key['HARGA_DB']*(($key['PPN_PEMBELIAN']+100)/100),2),
|
|
'STATUS_KPR' => '0',
|
|
];
|
|
$action = $this->Amod->create('klaim_program', $input);
|
|
|
|
$id_kpr = $this->Amod->getMax_ID_KlaimProgram();
|
|
$id_kpr = $id_kpr[0]['ID_KPR'];
|
|
} else {
|
|
$id_kpr = NULL;
|
|
}
|
|
|
|
$datSnb = $this->Amod->getData_SnBeli_byDB($key['ID_DB']);
|
|
foreach ($datSnb as $dat) {
|
|
$input = [
|
|
'NAMA_SNSTOCK' => $dat['NAMA_SNB'],
|
|
'GUDANG_SNSTOCK' => $key['GUDANG_PEMBELIAN'],
|
|
'KOP_SNSTOCK' => $key['CORP_ID'],
|
|
'BARANG_ID' => $key['BARANG_ID'],
|
|
'STATUS_SNSTOCK' => '0'
|
|
];
|
|
$action = $this->Amod->create('sn_stock', $input);
|
|
|
|
$id_snstock = $this->Amod->getMax_ID_SnStock();
|
|
$id_snstock = $id_snstock[0]['ID_SNSTOCK'];
|
|
|
|
$input = [
|
|
'TGL_HSN' => $now,
|
|
'KODE_BUKTI' => $key['KODE_PEMBELIAN'],
|
|
'SJ_HSN' => $key['SJ_PEMBELIAN'],
|
|
'INV_HSN' => $key['INV_PEMBELIAN'],
|
|
'SUPPLIER_ID' => $key['SUPPLIER_ID'],
|
|
'SNSTOCK_ID' => $id_snstock
|
|
];
|
|
$action = $this->Amod->create('histori_sn', $input);
|
|
|
|
if ($id_kpr!=NULL) {
|
|
$datSnkpr = $this->Amod->getData_SnKlaimProgram_bySNSTOCK($id_snstock);
|
|
if ($datSnkpr==FALSE) {
|
|
$input = [
|
|
'KPR_ID' => $id_kpr,
|
|
'SNSTOCK_ID' => $id_snstock,
|
|
'NAMA_SNKPR' => $dat['NAMA_SNB'],
|
|
'STATUS_SNKPR' => '0'
|
|
];
|
|
$action = $this->Amod->create('sn_klaimprogram', $input);
|
|
} else {
|
|
$update = [
|
|
'KPR_ID' => $id_kpr
|
|
];
|
|
$action = $this->Amod->update('sn_klaimprogram', $update, 'ID_SNKPR', $datSnkpr[0]['ID_SNKPR']);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$this->GE_Kalkulasi_KuantitiBarang($key['BARANG_ID'], $key['GUDANG_PEMBELIAN'], "Step 1 - PEMBELIAN - Proses Barang", 0, $key['QTY_DB']);
|
|
}
|
|
|
|
$update = [
|
|
'TAHAN_PEMBELIAN' => "Oleh $panggilan pada $timestamp"
|
|
];
|
|
$action = $this->Amod->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('data_lock', 'dikunci');
|
|
redirect('Menu/PB_Sub1_SuratJalan_1');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dikunci');
|
|
redirect($_SERVER['HTTP_REFERER']);
|
|
}
|
|
|
|
}
|
|
|
|
}
|