130 lines
3.5 KiB
PHP
130 lines
3.5 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageBeli extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelBeli', 'MBeli');
|
|
$this->load->model('ModelSupplier', 'MSupplier');
|
|
$this->load->model('ModelBarang', 'MBarang');
|
|
$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()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
if ($username == null) {
|
|
redirect("Action");
|
|
} elseif ($jabatan != "ADMIN") {
|
|
redirect("Action");
|
|
}
|
|
|
|
$datBeli = $this->MBeli->getDataBeli();
|
|
|
|
$data = [
|
|
'sidebar' => "data proses pembelian",
|
|
'navChild' => "data proses purchasing",
|
|
'beli' => $datBeli
|
|
];
|
|
|
|
$this->load->view('master/Beli', $data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
}
|
|
$datBeli = $this->MBeli->getDataBeli();
|
|
$datSupplier = $this->MSupplier->getDataSupplier();
|
|
$datBarang = $this->MBarang->getDataBarang();
|
|
$data = [
|
|
'sidebar' => "data proses pembelian",
|
|
'navChild' => "data proses purchasing",
|
|
'beli' => $datBeli,
|
|
'supplier' => $datSupplier,
|
|
'barang' => $datBarang
|
|
];
|
|
$this->load->view('proses/TambahBeli', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_beli = $this->input->post('id');
|
|
$supplier = $this->input->post('SUPPLIER');
|
|
$barang = $this->input->post('BARANG');
|
|
$po_beli = $this->input->post('po_beli');
|
|
$tanggal_beli = $this->input->post('tanggal_beli');
|
|
$jumlah_beli = $this->input->post('jumlah_beli');
|
|
|
|
$this->form_validation->set_rules('SUPPLIER', 'Pilih Supplier', 'required');
|
|
$this->form_validation->set_rules('BARANG', 'Pilih Barang', 'required');
|
|
$this->form_validation->set_rules('po_beli', 'Nomor PO', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'SUPPLIER' => form_error('SUPPLIER'),
|
|
'BARANG' => form_error('BARANG'),
|
|
'po_beli' => form_error('po_beli')
|
|
]
|
|
];
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageBeli');
|
|
|
|
} else {
|
|
|
|
$input = [
|
|
'SUPPLIER_ID' => $supplier,
|
|
'BARANG_ID' => $barang,
|
|
'PO_BELI' => $po_beli,
|
|
'TANGGAL_BELI' => $tanggal_beli,
|
|
'JUMLAH_BELI' => $jumlah_beli
|
|
];
|
|
$input2 = [
|
|
'BARANG_ID' => $barang,
|
|
'JUMLAH_INVENTORY' => $jumlah_beli,
|
|
'GUDANG_ID' => '1'
|
|
];
|
|
|
|
$action = $this->MBeli->create('beli', $input);
|
|
$action2 = $this->MBeli->create('inventory', $input2);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageBeli');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageBeli');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$action1 = $this->MBeli->delete('beli', $id, 'ID_BELI');
|
|
$action2 = $this->MBeli->delete('inventory', $id, 'ID_INVENTORY');
|
|
|
|
if ($action1) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageBeli');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'dihapus');
|
|
redirect('ManageBeli');
|
|
}
|
|
}
|
|
|
|
}
|