copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,464 @@
|
||||
<?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 ManagePembelianSJ extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelPembelian', 'MP');
|
||||
$this->load->model('ModelSupplier', 'MS');
|
||||
$this->load->model('ModelBarang', 'MB');
|
||||
$this->load->model('ModelGudang', 'MG');
|
||||
$this->load->model('ModelCorp', 'MC');
|
||||
$this->load->library(['datatables', 'form_validation']);
|
||||
$this->form_validation->set_error_delimiters('', '');
|
||||
}
|
||||
public function output_json($data, $encode = true)
|
||||
{
|
||||
if ($encode) $data = json_encode($data);
|
||||
$this->output->set_content_type('application/json')->set_output($data);
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
|
||||
$datPembelian = $this->MP->getDataPembelian();
|
||||
$datSupplier = $this->MS->getDataSupplier();
|
||||
$datCorp = $this->MC->getDataCorp();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "menu pembelian",
|
||||
'navChild' => "",
|
||||
'pembelian' => $datPembelian,
|
||||
'supplier' => $datSupplier,
|
||||
'corp' => $datCorp
|
||||
];
|
||||
|
||||
$this->load->view('proses/PembelianSJ', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$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();
|
||||
|
||||
$sj_pembelian = strtoupper($sj_pembelian);
|
||||
|
||||
$input = [
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'CORP_ID' => $id_corp,
|
||||
'TGL_SJBELI' => $tgl_sjbeli,
|
||||
'SJ_PEMBELIAN' => $sj_pembelian,
|
||||
'KODE_PEMBELIAN'=> $kode_pembelian
|
||||
];
|
||||
|
||||
$action = $this->MP->create('pembelian', $input);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect('ManagePembelianSJ');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManagePembelianSJ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_pembelian = $this->input->post('id_pembelian');
|
||||
$id_supplier = $this->input->post('id_suppliered');
|
||||
$id_corp = $this->input->post('id_corped');
|
||||
$sj_pembelian = $this->input->post('sj_pembelianed');
|
||||
$tgl_sjbeli = $this->input->post('tgl_sjbelied');
|
||||
|
||||
$update = [
|
||||
'SUPPLIER_ID' => $id_supplier,
|
||||
'CORP_ID' => $id_corp,
|
||||
'TGL_SJBELI' => $tgl_sjbeli,
|
||||
'SJ_PEMBELIAN' => $sj_pembelian
|
||||
];
|
||||
|
||||
$action = $this->MP->update('pembelian', $update,'ID_PEMBELIAN',$id_pembelian);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'diubah');
|
||||
redirect('ManagePembelianSJ');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'diubah');
|
||||
redirect('ManagePembelianSJ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->MP->delete('pembelian', $id, 'ID_PEMBELIAN')) {
|
||||
$action = $this ->MP->delete('pembelian',$id,'ID_PEMBELIAN');
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect('ManagePembelianSJ');
|
||||
}
|
||||
}
|
||||
|
||||
public function tambahStock($id)
|
||||
{
|
||||
$stock = $this->MP->getDataTambahStock($id);
|
||||
$title = $this->MP->getSJPembelian($id);
|
||||
$barang = $this->MB->getDataBarang();
|
||||
$gudang = $this->MG->getDataGudangPembelian();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "menu pembelian",
|
||||
'navChild' => "",
|
||||
'stock' => $stock,
|
||||
'id_pembelian' => $id,
|
||||
'sj_pembelian' => $title[0]['SJ_PEMBELIAN'],
|
||||
'barang' => $barang,
|
||||
'gudang' => $gudang
|
||||
];
|
||||
|
||||
$this->load->view('proses/PembelianST', $data);
|
||||
}
|
||||
|
||||
public function savestock()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_pembelian = $this->input->post('id_pembelian');
|
||||
$id_stock = $this->input->post('id');
|
||||
$id_barang = $this->input->post('id_barang');
|
||||
$id_gudang = $this->input->post('id_gudang');
|
||||
$qty = $this->input->post('qty');
|
||||
|
||||
$input = [
|
||||
'PEMBELIAN_ID' => $id_pembelian,
|
||||
'BARANG_ID' => $id_barang,
|
||||
'GUDANG_ID' => $id_gudang,
|
||||
'QTY' => $qty,
|
||||
'BLOCKADDSN' => '0'
|
||||
];
|
||||
|
||||
$action = $this->MP->create('stock', $input);
|
||||
|
||||
$qty_barang = $this->MB->getDataBarangQtyReal($id_barang);
|
||||
$qty_real = $qty_barang[0]['QTY_REAL']+$qty;
|
||||
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $qty_real
|
||||
];
|
||||
|
||||
$actionupdate = $this->MB->update('barang', $updatebarang, 'ID_BARANG', $id_barang);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function editstock()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_pembelian = $this->input->post('id_pembelian');
|
||||
$id_stock = $this->input->post('id_stock');
|
||||
$id_barang = $this->input->post('id_baranged');
|
||||
$id_gudang = $this->input->post('id_gudanged');
|
||||
$qty = $this->input->post('qtyed');
|
||||
|
||||
//Fungsi Reset Tabel sebelum Input Stock
|
||||
$before = $this->MP->getStockID($id_stock);
|
||||
$qtyBarang = $before[0]['QTY_REAL'];
|
||||
$qtyStock = $before[0]['QTY'];
|
||||
$blockaddsn = $before[0]['BLOCKADDSN'];
|
||||
$idbarangBefore = $before[0]['BARANG_ID'];
|
||||
|
||||
if ($blockaddsn==NULL) {
|
||||
$qtyrealOnBarang = $qtyBarang-$qtyStock;
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $qtyrealOnBarang
|
||||
];
|
||||
$actionbarang = $this->MB->update('barang',$updatebarang,'ID_BARANG',$idbarangBefore);
|
||||
} else {
|
||||
$qtyrealOnBarang = $qtyBarang-$blockaddsn;
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $qtyrealOnBarang
|
||||
];
|
||||
$actionbarang = $this->MB->update('barang',$updatebarang,'ID_BARANG',$idbarangBefore);
|
||||
$updatestock = [
|
||||
'QTY' => '0'
|
||||
];
|
||||
$actionstock = $this->MP->update('stock',$updatestock,'ID_STOCK',$id_stock);
|
||||
}
|
||||
|
||||
$actiondeletesn = $this->MP->delSN($id_stock);
|
||||
|
||||
// Fungsi Edit Tabel sesuai data Edit
|
||||
$updatestock = [
|
||||
'BARANG_ID' => $id_barang,
|
||||
'GUDANG_ID' => $id_gudang,
|
||||
'QTY' => $qty
|
||||
];
|
||||
$actionstock = $this->MP->update('stock',$updatestock,'ID_STOCK',$id_stock);
|
||||
|
||||
$after = $this->MP->getStockID($id_stock);
|
||||
$typejenis = $after[0]['TYPE_JENIS'];
|
||||
$idbarangAfter = $after[0]['BARANG_ID'];
|
||||
$qtyBarang = $after[0]['QTY_REAL'];
|
||||
if ($typejenis=="SN") {
|
||||
$updatestock = [
|
||||
'BLOCKADDSN' => '0'
|
||||
];
|
||||
$actionstock = $this->MP->update('stock',$updatestock,'ID_STOCK',$id_stock);
|
||||
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $qtyBarang
|
||||
];
|
||||
$actionbarang = $this->MB->update('barang',$updatebarang,'ID_BARANG',$idbarangAfter);
|
||||
|
||||
} else {
|
||||
$updatestock = [
|
||||
'BLOCKADDSN' => NULL
|
||||
];
|
||||
$actionstock = $this->MP->update('stock',$updatestock,'ID_STOCK',$id_stock);
|
||||
|
||||
$qtyrealOnBarangAfter = $qtyBarang+$qty;
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $qtyrealOnBarangAfter
|
||||
];
|
||||
$actionbarang = $this->MB->update('barang',$updatebarang,'ID_BARANG',$idbarangAfter);
|
||||
}
|
||||
|
||||
if ($actionstock) {
|
||||
$this->session->set_flashdata('flash', 'diedit');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'diedit');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function hapusstock()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
$id_barang = $this->input->post('id_barang');
|
||||
|
||||
$qty_barangID = $this->MB->getDataBarangQtyReal($id_barang);
|
||||
$qty_stockID = $this->MB->getDataStockQty($id);
|
||||
$qtystock = $qty_stockID[0]['QTY'];
|
||||
$qtybarang = $qty_barangID[0]['QTY_REAL'];
|
||||
$qty_real = $qtybarang-$qtystock;
|
||||
$deletebarang = [
|
||||
'QTY_REAL' => $qty_real
|
||||
];
|
||||
|
||||
$action = $this ->MP->delete('stock',$id,'ID_STOCK');
|
||||
$actiondelete = $this->MB->update('barang', $deletebarang, 'ID_BARANG', $id_barang);
|
||||
$actiondeletesn = $this->MP->delSN($id);
|
||||
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
public function tambahSn($id)
|
||||
{
|
||||
$stock = $this->MP->getStockID($id);
|
||||
$title = $this->MP->getStockTitle($id);
|
||||
$max = $this->MP->getQtyPembelianSn($id);
|
||||
|
||||
$data = [
|
||||
'sidebar' => "menu pembelian",
|
||||
'navChild' => "",
|
||||
'stock' => $stock,
|
||||
'id_stock' => $id,
|
||||
'qty' => $stock[0]['QTY'],
|
||||
'title' => $title[0]['NAMA_BARANG'],
|
||||
'max' => $max,
|
||||
];
|
||||
|
||||
$this->load->view('proses/PembelianSN', $data);
|
||||
}
|
||||
|
||||
public function datasn()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
$data = $this->MP->getDataSn($id);
|
||||
$this->output_json(['value' => 1, 'total' => sizeof($data), 'data' => $data]);
|
||||
}
|
||||
|
||||
public function jumlahdatasn()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
$data = $this->MP->getDataSn($id);
|
||||
$this->output_json(['value' => 1, 'jumlah_data' => sizeof($data)]);
|
||||
}
|
||||
|
||||
public function savesn()
|
||||
{
|
||||
$id = $this->input->post('id_sn');
|
||||
$nama_sn = $this->input->post('nama_sn');
|
||||
$id_stock = $this->input->post('id_stock');
|
||||
$qty = $this->MP->getQtyPembelian($id_stock);
|
||||
$qtySn = $this->MP->getQtyPembelianSn($id_stock);
|
||||
|
||||
if ($qtySn>=$qty[0]['QTY']){
|
||||
$this->output_json(['value' => 2, 'id' => $id, 'nama_sn' => $nama_sn]);
|
||||
} else if ($id != null) {
|
||||
$data = [
|
||||
'NAMA_SN' => $nama_sn,
|
||||
'STOCK_ID' => $id_stock,
|
||||
'STATUS_SN' => 'Ready'
|
||||
];
|
||||
$action = $this->MP->update('sn', $data, 'ID_SN', $id);
|
||||
$gudang = $this->MP->getGudangStock($id);
|
||||
$updatesn = [
|
||||
'GUDANG_ID' => $gudang[0]['GUDANG_ID']
|
||||
];
|
||||
$actiongudang = $this->MP->update('sn', $updatesn, 'ID_SN', $id);
|
||||
|
||||
if ($actiongudang) {
|
||||
$this->output_json(['value' => 1, 'id' => $id, 'nama_sn' => $nama_sn]);
|
||||
} else {
|
||||
$this->output_json(['value' => 0, 'id' => $id, 'nama_sn' => $nama_sn]);
|
||||
}
|
||||
} else {
|
||||
//Fungsi Tambah SN
|
||||
$data = [
|
||||
'NAMA_SN' => $nama_sn,
|
||||
'STOCK_ID' => $id_stock,
|
||||
'STATUS_SN' => 'Ready'
|
||||
];
|
||||
$action = $this->MP->create('sn', $data);
|
||||
$gudsn = $this->MP->getGudangSN();
|
||||
$gudang = $this->MP->getGudangStock($gudsn[0]['ID_SN']);
|
||||
$updatesn = [
|
||||
'GUDANG_ID' => $gudang[0]['GUDANG_ID']
|
||||
];
|
||||
$actiongudang = $this->MP->update('sn', $updatesn, 'ID_SN', $gudsn[0]['ID_SN']);
|
||||
|
||||
$blockadd = $this->MP->getBlockAddSn($id_stock);
|
||||
$update = [
|
||||
'BLOCKADDSN' => $blockadd
|
||||
];
|
||||
$block = $this->MP->update('stock', $update, 'ID_STOCK', $id_stock);
|
||||
|
||||
//Fungsi update Qty Real Tabel Barang
|
||||
$barangStockAfter = $this->MP->getBarangStock($id_stock);
|
||||
$id_barangAfter = $barangStockAfter[0]['BARANG_ID'];
|
||||
$qty_realAfter = $barangStockAfter[0]['QTY_REAL'];
|
||||
$blockaddsnAfter = $barangStockAfter[0]['BLOCKADDSN'];
|
||||
|
||||
$barang_qty_real = $qty_realAfter+1;
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $barang_qty_real
|
||||
];
|
||||
$actionbarang = $this->MP->update('barang', $updatebarang, 'ID_BARANG', $id_barangAfter);
|
||||
|
||||
if ($actionbarang) {
|
||||
$this->output_json(['value' => 1, 'id' => $id, 'nama_sn' => $nama_sn]);
|
||||
} else {
|
||||
$this->output_json(['value' => 0, 'id' => $id, 'nama_sn' => $nama_sn]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function hapussn()
|
||||
{
|
||||
$id = $this->input->post('id_sn');
|
||||
$datPDID = $this->MP->getDetailPembelianID($id);
|
||||
$id_stock = $datPDID[0]['STOCK_ID'];
|
||||
$qty = $this->MP->getQtyPembelian($datPDID[0]['STOCK_ID']);
|
||||
$real = $this->MP->getQtyPembelianSn($datPDID[0]['STOCK_ID']);
|
||||
|
||||
$action = $this->MP->delete('sn', $id, 'ID_SN');
|
||||
|
||||
$blockadd = $this->MP->getBlockAddSn($datPDID[0]['STOCK_ID']);
|
||||
$update = [
|
||||
'BLOCKADDSN' => $blockadd
|
||||
];
|
||||
$block = $this->MP->update('stock', $update, 'ID_STOCK', $datPDID[0]['STOCK_ID']);
|
||||
|
||||
//Fungsi update Qty Real Tabel Barang
|
||||
$barangStockAfter = $this->MP->getBarangStock($id_stock);
|
||||
$id_barangAfter = $barangStockAfter[0]['BARANG_ID'];
|
||||
$qty_realAfter = $barangStockAfter[0]['QTY_REAL'];
|
||||
$blockaddsnAfter = $barangStockAfter[0]['BLOCKADDSN'];
|
||||
|
||||
$barang_qty_real = $qty_realAfter-1;
|
||||
$updatebarang = [
|
||||
'QTY_REAL' => $barang_qty_real
|
||||
];
|
||||
$actionbarang = $this->MP->update('barang', $updatebarang, 'ID_BARANG', $id_barangAfter);
|
||||
|
||||
if ($real==$qty[0]['QTY']){
|
||||
$this->output_json(['value' => 2, 'message' => 'Berhasil', 'dt' => $action]);
|
||||
} else {
|
||||
if ($action) {
|
||||
$this->output_json(['value' => 1, 'message' => 'Berhasil', 'dt' => $action]);
|
||||
} else {
|
||||
$this->output_json(['value' => 0, 'message' => "gagal", 'dt' => $action]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function konfirmasi()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_pembelian = $this->input->post('id_pembelian');
|
||||
|
||||
$update = [
|
||||
'STATUS_PEMBELIAN' => "SJ SUDAH PROSES"
|
||||
];
|
||||
|
||||
$action = $this->MP->update('pembelian', $update, 'ID_PEMBELIAN', $id_pembelian);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect('ManagePembelianSJ');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManagePembelianSJ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function kodePembelian() {
|
||||
$kk = $this->MP->getKodePembelian();
|
||||
if (is_array($kk) || is_object($kk)) {
|
||||
foreach ($kk as $row) {
|
||||
if ($row['KODE'] == null) {
|
||||
return "PB/000001";
|
||||
} else {
|
||||
$str = (string) $row['KODE'];
|
||||
$panjang = 6;
|
||||
$data = substr($str, 3, $panjang);
|
||||
|
||||
$ko = (int) $data + 1;
|
||||
$str = (string) $ko;
|
||||
|
||||
$panjang = 9 - strlen($str);
|
||||
$data = "PB/000000";
|
||||
$data = substr($data, 0, $panjang) . $str;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user