Datatables Server Side Codeigniter 3 Add To Cart


  • Code Controller
function __construct()
{
parent::__construct();
$this->load->model('M_transaction');
$this->load->library('cart');
$this->load->helper('url');
}

function transaction_out_sparepart()
{
$this->load->view('include/header');
$this->load->view('page_transaction/V_transaction_out_sparepart');
$this->load->view('include/footer');
}

function get_data_sparepart()
{
$list = $this->M_transaction->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $field) {
$no++;
$row = array();
$row[] = $no;
$row[] = $field->no_barang;
$row[] = $field->nama_barang;
$row[] = $field->spesifikasi;
$row[] = $field->stock;
$row[] = $field->satuan;
$row[] = '<form id="my_form" action="add_cart" method="post">
<input type="hidden" name="no_barang" value="'.$field->no_barang.'">
<input name="nama_barang" type="hidden" value="'.$field->nama_barang.'">
<input name="spesifikasi" type="hidden" value="'.$field->spesifikasi.'">
<input name="stock" type="hidden" value="'.$field->stock.'">
<input name="satuan" type="hidden" value="'.$field->satuan.'">
<input name="warehouse_code" type="hidden" value="'.$field->warehouse_code.'">
<input maxlength="11" type="hidden" name="price" value="0">
<input type="hidden" name="quantity" value="1">
<button type="submit">Add</button>
</form>';
$data[] = $row;
}

$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->M_transaction->count_all(),
"recordsFiltered" => $this->M_transaction->count_filtered(),
"data" => $data,
);
//output dalam format JSON
echo json_encode($output);
}

function add_cart()
{
$warehouse_code = $this->input->post('warehouse_code');
$insert_room = array(
'warehouse_code' => $warehouse_code,
'id' => $this->input->post('no_barang'),
'name' => $this->input->post('nama_barang'),
'spesifikasi' => $this->input->post('spesifikasi'),
'stock' => $this->input->post('stock'),
'qty' => $this->input->post('quantity'),
'satuan' => $this->input->post('satuan'),
'price' => $this->input->post('price')
);

$this->cart->product_id_rules = '[:print:]';
$this->cart->product_name_rules = '[:print:]';
$this->cart->insert($insert_room);
$this->session->set_flashdata('msg','<div class="alert alert-success alert-dismissible"><strong>Sukses!</strong> Data Transaction berhasil ditambah.</div>');
redirect('transaction/sparepart_process/'.$warehouse_code);
}

function sparepart_process($warehouse_code)
{
$data['get_tr_out_no'] = $this->M_transaction->get_tr_out_no();
$data['get_warehouse'] = $this->M_transaction->get_warehouse($warehouse_code)->result();
$data['get_sparepart'] = $this->M_transaction->get_sparepart($warehouse_code)->result();
$data['get_unit'] = $this->M_transaction->get_unit();
$data['get_employee'] = $this->M_transaction->get_employee();
$this->load->view('include/header');
$this->load->view('page_transaction/V_transaction_out_process', $data);
$this->load->view('include/footer');
}

function remove_cart($rowid)
{
if ($rowid=="all"){
$this->cart->destroy();
redirect('transaction/transaction_out_list');
}else{
$data = array(
'rowid' => $rowid,
'qty' => 0
);

$this->cart->update($data);
}
$this->session->set_flashdata('msg','<div class="alert alert-warning alert-dismissible"><strong>Sukses!</strong> Data Transaction telah dihapus.</div>');
redirect($_SERVER['HTTP_REFERER']);
}

function transaction_save()
{
$tr_out_no = $this->input->post('tr_out_no');
$sql = $this->db->query("SELECT tr_out_no FROM transaction_sp_out WHERE tr_out_no = '$tr_out_no'");
$cek_tr_out_no = $sql->num_rows();
if($cek_tr_out_no > 0) {
$this->session->set_flashdata('msg','<div class="alert alert-warning alert-dismissible"><strong>Maaf!</strong> terjadi kesalahan input, silahkan ulangi lagi.</div>');
redirect($_SERVER['HTTP_REFERER']);
}
$tr_out_date = $this->input->post('tr_out_date');
$tr_out_warehouse = $this->input->post('tr_out_warehouse');
$tr_logistik = $this->input->post('tr_logistik');

$order = array(
'tr_out_no' => $tr_out_no,
'tr_out_date' => $tr_out_date,
'tr_out_warehouse' => $tr_out_warehouse,
'tr_logistik' => $tr_logistik,
);
$this->M_transaction->order_save($order);

$result = array();
foreach ($_POST['no_barang'] as $key => $val) {
$result[] = array(
'tr_out_no' => $tr_out_no,
'tr_out_warehouse' => $tr_out_warehouse,
'no_barang' => $_POST['no_barang'][$key],
'qty' => $_POST['qty'][$key],
'beban_charge' => $_POST['beban_charge'][$key],
'pic' => $_POST['pic'][$key],
'keterangan' => $_POST['keterangan'][$key]
);
}
$this->db->insert_batch('transaction_sp_out_detail',$result);

$this->remove_all();
$this->session->set_flashdata('msg','<div class="alert alert-success alert-dismissible"><strong>Sukses!</strong> Data Request telah dibuat.</div>');
redirect('transaction/printpdf/'.$tr_out_no);
}

function printpdf($tr_out_no)
{
$data['transaction'] = $this->M_transaction->printpdf_order($tr_out_no)->result();
$data['transaction_detail'] = $this->M_transaction->printpdf_order_detail($tr_out_no)->result();
$this->load->view('page_transaction/V_transaction_out_print', $data);

// Get output html
$html = $this->output->get_output();

// Load pdf library
$this->load->library('pdf');

// Load HTML content
$this->dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A4', 'portrait');

// Render the HTML as PDF
$this->dompdf->render();

// Output the generated PDF (1 = download and 0 = preview)
$this->dompdf->stream("Transaction-Sparepart.pdf", array("Attachment"=>0));
}

function remove_all()
{
$this->cart->destroy();
}

function aftersubmit()
{
redirect('transaction/transaction_out_list');
}


Total 0 comment with 0 comment reply