Welcome Guest, Not a member yet? Register   Sign In
CI for Accounting
#9

(This post was last modified: 10-01-2017, 02:54 PM by tamam.)

This is my akun CONTROLLER

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Akun extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Akun_model');
$this->load->library('form_validation');
$this->load->library('datatables');
}

public function index()
{
$this->template->load('template','akun/akun_list');
}

public function json() {
header('Content-Type: application/json');
echo $this->Akun_model->json();
}

public function read($id)
{
$row = $this->Akun_model->get_by_id($id);
if ($row) {
$data = array(
'id' => $row->id,
'kode_akun' => $row->kode_akun,
'nama_akun' => $row->nama_akun,
'saldo_normal' => $row->saldo_normal,
'saldo' => $row->saldo,
);
$this->template->load('template','akun/akun_read', $data);
} else {
$this->session->set_flashdata('message', 'Record Not Found');
redirect(site_url('akun'));
}
}

public function create()
{
$data = array(
'button' => 'Create',
'action' => site_url('akun/create_action'),
'id' => set_value('id'),
'kode_akun' => set_value('kode_akun'),
'nama_akun' => set_value('nama_akun'),
'saldo_normal' => set_value('saldo_normal'),
'saldo' => set_value('saldo'),
);
$this->template->load('template', 'akun/akun_form', $data);
}

public function create_action()
{
$this->_rules();

if ($this->form_validation->run() == FALSE) {
$this->create();
} else {
$data = array(
'kode_akun' => $this->input->post('kode_akun',TRUE),
'nama_akun' => $this->input->post('nama_akun',TRUE),
'saldo_normal' => $this->input->post('saldo_normal',TRUE),
'saldo' => $this->input->post('saldo',TRUE),
);

$this->Akun_model->insert($data);
$this->session->set_flashdata('message', 'Create Record Success');
redirect(site_url('akun'));
}
}

public function update($id)
{
$row = $this->Akun_model->get_by_id($id);

if ($row) {
$data = array(
'button' => 'Update',
'action' => site_url('akun/update_action'),
'id' => set_value('id', $row->id),
'kode_akun' => set_value('kode_akun', $row->kode_akun),
'nama_akun' => set_value('nama_akun', $row->nama_akun),
'saldo_normal' => set_value('saldo_normal', $row->saldo_normal),
'saldo' => set_value('saldo', $row->saldo),
);
$this->template->load('template', 'akun/akun_form', $data);
} else {
$this->session->set_flashdata('message', 'Record Not Found');
redirect(site_url('akun'));
}
}

public function update_action()
{
$this->_rules();

if ($this->form_validation->run() == FALSE) {
$this->update($this->input->post('id', TRUE));
} else {
$data = array(
'kode_akun' => $this->input->post('kode_akun',TRUE),
'nama_akun' => $this->input->post('nama_akun',TRUE),
'saldo_normal' => $this->input->post('saldo_normal',TRUE),
'saldo' => $this->input->post('saldo',TRUE),
);

$this->Akun_model->update($this->input->post('id', TRUE), $data);
$this->session->set_flashdata('message', 'Update Record Success');
redirect(site_url('akun'));
}
}

public function delete($id)
{
$row = $this->Akun_model->get_by_id($id);

if ($row) {
$this->Akun_model->delete($id);
$this->session->set_flashdata('message', 'Delete Record Success');
redirect(site_url('akun'));
} else {
$this->session->set_flashdata('message', 'Record Not Found');
redirect(site_url('akun'));
}
}

public function _rules()
{
$this->form_validation->set_rules('kode_akun', 'kode akun', 'trim|required');
$this->form_validation->set_rules('nama_akun', 'nama akun', 'trim|required');
$this->form_validation->set_rules('saldo_normal', 'saldo normal', 'trim|required');
$this->form_validation->set_rules('saldo', 'saldo', 'trim|required');

$this->form_validation->set_rules('id', 'id', 'trim');
$this->form_validation->set_error_delimiters('<span class="text-danger">', '</span>');
}

public function excel()
{
$this->load->helper('exportexcel');
$namaFile = "akun.xls";
$judul = "akun";
$tablehead = 0;
$tablebody = 1;
$nourut = 1;
//penulisan header
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=" . $namaFile . "");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

$kolomhead = 0;
xlsWriteLabel($tablehead, $kolomhead++, "No");
xlsWriteLabel($tablehead, $kolomhead++, "Kode Akun");
xlsWriteLabel($tablehead, $kolomhead++, "Nama Akun");
xlsWriteLabel($tablehead, $kolomhead++, "Saldo Normal");
xlsWriteLabel($tablehead, $kolomhead++, "Saldo");

foreach ($this->Akun_model->get_all() as $data) {
$kolombody = 0;

//ubah xlsWriteLabel menjadi xlsWriteNumber untuk kolom numeric
xlsWriteNumber($tablebody, $kolombody++, $nourut);
xlsWriteLabel($tablebody, $kolombody++, $data->kode_akun);
xlsWriteLabel($tablebody, $kolombody++, $data->nama_akun);
xlsWriteNumber($tablebody, $kolombody++, $data->saldo_normal);
xlsWriteNumber($tablebody, $kolombody++, $data->saldo);

$tablebody++;
$nourut++;
}

xlsEOF();
exit();
}

public function word()
{
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=akun.doc");

$data = array(
'akun_data' => $this->Akun_model->get_all(),
'start' => 0
);

$this->load->view('akun/akun_doc',$data);
}

}
Reply


Messages In This Thread
CI for Accounting - by tamam - 09-29-2017, 02:17 AM
RE: CI for Accounting - by rtenny - 09-29-2017, 07:15 AM
RE: CI for Accounting - by tamam - 09-30-2017, 03:50 PM
RE: CI for Accounting - by krystian2160 - 09-30-2017, 01:31 AM
RE: CI for Accounting - by tamam - 09-30-2017, 03:54 PM
RE: CI for Accounting - by PaulD - 10-01-2017, 08:29 AM
RE: CI for Accounting - by tamam - 10-01-2017, 02:44 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:51 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:52 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:53 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:55 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:56 PM
RE: CI for Accounting - by tamam - 10-01-2017, 02:57 PM
RE: CI for Accounting - by PaulD - 10-01-2017, 04:44 PM
RE: CI for Accounting - by tamam - 10-01-2017, 06:56 PM
RE: CI for Accounting - by ciadmin - 10-01-2017, 07:00 PM
RE: CI for Accounting - by tamam - 10-01-2017, 09:38 PM
RE: CI for Accounting - by PaulD - 10-02-2017, 10:10 AM
RE: CI for Accounting - by tamam - 10-10-2017, 05:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB