112 lines
2.9 KiB
PHP
112 lines
2.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManagePromo extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelPromo', 'MPromo');
|
|
$this->load->model('ModelInvoice', 'MInvoice');
|
|
$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");
|
|
}
|
|
|
|
$datPromo = $this->MPromo->getDataPromo();
|
|
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data promo",
|
|
'promo' => $datPromo
|
|
];
|
|
|
|
$this->load->view('promo/table-promo', $data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
}
|
|
$datPromo = $this->MPromo->getDataPromo();
|
|
$datInvoice = $this->MInvoice->getDataInvoice();
|
|
$data = [
|
|
'sidebar' => "data master",
|
|
'navChild' => "data promo",
|
|
'invoice' => $datInvoice,
|
|
'promo' => $datPromo
|
|
|
|
];
|
|
$this->load->view('promo/promo-tambah', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$nama_promo = $this->input->post('nama_promo');
|
|
$tgl_promo = $this->input->post('tgl_promo');
|
|
$potongan = $this->input->post('potongan');
|
|
$no_invoice = $this->input->post('no_invoice');
|
|
|
|
$this->form_validation->set_rules('nama_promo', 'Nama Promo', 'required');
|
|
$this->form_validation->set_rules('tgl_promo', 'Tanggal Promo', 'required');
|
|
$this->form_validation->set_rules('potongan', 'Potongan', 'required');
|
|
$this->form_validation->set_rules('no_invoice', 'Nomor Invoice', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'nama_promo' => form_error('nama_promo'),
|
|
'tgl_promo' => form_error('tgl_promo'),
|
|
'potongan' => form_error('potongan'),
|
|
'no_invoice' => form_error('no_invoice')
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
$input = [
|
|
'NAMA_PROMO' => $nama_promo,
|
|
'TGL_PROMO' => $tgl_promo,
|
|
'POTONGAN' => $potongan,
|
|
'ID_INVOICE' => $no_invoice
|
|
];
|
|
|
|
$action = $this->MPromo->create('promo', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManagePromo');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManagePromo');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MPromo->delete('promo', $id, 'ID_PROMO')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManagePromo');
|
|
}
|
|
}
|
|
|
|
}
|