121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageInvoice extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelInvoice', 'MInvoice');
|
|
$this->load->model('ModelDistributor', 'MDistributor');
|
|
$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("Login");
|
|
} elseif ($jabatan != "ADMIN") {
|
|
redirect("Login");
|
|
}
|
|
|
|
$datInvoice = $this->MInvoice->getDataInvoice();
|
|
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data invoice",
|
|
'invoice' => $datInvoice
|
|
];
|
|
|
|
$this->load->view('invoice/table-invoice', $data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
}
|
|
$datDistributor = $this->MDistributor->getDataDistributor();
|
|
$datInvoice = $this->MInvoice->getDataInvoice();
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data invoice",
|
|
'distributor' => $datDistributor,
|
|
'invoice' => $datInvoice
|
|
|
|
];
|
|
//var_dump($data);
|
|
$this->load->view('invoice/invoice-tambah', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$no_invoice = $this->input->post('no_invoice');
|
|
$tgl_invoice = $this->input->post('tgl_invoice');
|
|
$distributor = $this->input->post('distributor');
|
|
$nama_sku = $this->input->post('nama_sku');
|
|
$hpp = $this->input->post('hpp');
|
|
$jumlah = $this->input->post('jumlah');
|
|
|
|
$this->form_validation->set_rules('no_invoice', 'Nomor Invoice', 'required');
|
|
$this->form_validation->set_rules('tgl_invoice', 'Tanggal Invoice', 'required');
|
|
$this->form_validation->set_rules('distributor', 'Distributor', 'required');
|
|
$this->form_validation->set_rules('nama_sku', 'Nama SKU', 'required');
|
|
$this->form_validation->set_rules('hpp', 'Harga HPP', 'required');
|
|
$this->form_validation->set_rules('jumlah', 'Jumlah', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'no_invoice' => form_error('no_invoice'),
|
|
'tgl_invoice' => form_error('tgl_invoice'),
|
|
'distributor' => form_error('distributor'),
|
|
'nama_sku' => form_error('nama_sku'),
|
|
'hpp' => form_error('hpp'),
|
|
'jumlah' => form_error('jumlah')
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
$input = [
|
|
'NO_INVOICE' => $no_invoice,
|
|
'TGL_INVOICE' => $tgl_invoice,
|
|
'ID_DISTRIBUTOR' => $distributor,
|
|
'NAMA_SKU' => $nama_sku,
|
|
'HPP' => $hpp,
|
|
'JUMLAH' => $jumlah
|
|
];
|
|
|
|
$action = $this->MInvoice->create('invoice', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageInvoice');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageInvoice');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MInvoice->delete('invoice', $id, 'ID_INVOICE')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageInvoice');
|
|
}
|
|
}
|
|
|
|
}
|