Mengambil nilai cart pada saat insert data pada pos

bagaimana ya caranya agar yang saya bulatin pada saat tambah data bisa tersimpan juga dengan php pada saat eksekusinya

jadi yang diatas seperti supplier tanggal dan lain2 bisa tesimpan dan juga dan juga cartnya tanpa menggunakan shopping cart codeigniter

controller :

<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Purchase extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->model(['Purchase_model', 'Profit_model', 'Supplier_model', 'Gudang_model', 'Inventori_model']);
        $this->load->library('form_validation'); //untuk memanggil library form validasi

    }

    public function index() //untuk tampilkan seluruh data dari database
    {

        $data['kodeunik'] = $this->Purchase_model->buat_kode();
        $data['profit']      = $this->Profit_model->getAll();
        $data['supplier']    = $this->Supplier_model->getAll();
        $data['gudang']      = $this->Gudang_model->getAll();
        $data['inventori']   = $this->Inventori_model->getAll();

        $data['title'] = 'Purchase Order';

        $this->form_validation->set_rules('id_profit', ' Profit Center', 'required');

        if ($this->form_validation->run() == FALSE) {
          $this->load->view('pembelian/templates/admin-header', $data);
          $this->load->view('pembelian/transaksi/purchase/index', $data);
          $this->load->view('pembelian/templates/admin-footer');
        } else {
            $this->Purchase_model->tambahData();
            $this->session->set_flashdata('flash', 'Tambahkan');
            redirect('purchase/index');
        }
    }


}

view :

<div class="shadow row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Purchase Order</h2>
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a href="<?php echo base_url('welcome'); ?>">Home</a>
            </li>
            <li class="breadcrumb-item">
                <a>Master</a>
            </li>
            <li class="breadcrumb-item active">
                <strong>Purchase Order</strong>
            </li>
        </ol>
    </div>
</div>
<div class=" wrapper wrapper-content animated fadeInRight">

    <?php if ($this->session->flashdata( 'flash') == TRUE) : ?>
        <div class="alert alert-success shadow" role="alert">
            <a class="close" data-dismiss="alert" aria-label="close">×</a>
            Data <?php echo $title; ?> Berhasil Di  <strong><?= $this->session->flashdata('flash'); ?></strong>
        </div>
    <?php endif; ?>

    <div class="row " >
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <a class="btn btn-outline btn-primary" href="<?= base_url('supplier/browse') ?>">Browse</a>
                </div>
                <div class="ibox-content shadow">
                    <form class="form-horizontalcenter" method="POST">
                         <div class="row">

<!-- ========================================================DATA ATAS================================================================================= -->
                            <div class="col-sm-6">
                                <div class="form-group row"><label class="col-sm-2 col-form-label"> Profit Center</label>
                                    <div class="col-md-6">
                                        <select class="form-control select2" name="id_profit" id="profit">
                                        <option value="">Pilih Profit Center....</option>
                                        <?php foreach ($profit as $tampil) { ?>
                                            <option alamat="<?php echo $tampil->alamat_profit; ?>" value="<?php echo $tampil->id_profit; ?>"><?php echo $tampil->nama_profit; ?></option>
                                        <?php } ?>
                                        </select>
                                        <small class="form-text text-danger"><?= form_error('id_profit'); ?></small>
                                    </div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label"></label>
                                    <div class="col-md-6"><input type="text" name="alamat_profit" id="alamat_prof" class="form-control" autocomplete="off" autofocus></div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label"> Supplier</label>
                                    <div class="col-md-6">
                                        <select class="form-control select2" name="id_supplier">
                                        <option value="">Pilih Supplier....</option>
                                        <?php foreach ($supplier as $tampil) { ?>
                                            <option value="<?php echo $tampil->id_supplier; ?>"><?php echo $tampil->nama_supplier; ?></option>
                                        <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label">Keterangan</label>
                                    <div class="col-md-6"><input type="text" name="keterangan_po" class="form-control" autocomplete="off" autofocus></div>
                                </div>

                            </div>
                            <div class="col-sm-6">
                                <div class="form-group row"><label class="col-sm-2 col-form-label">Tanggal</label>
                                    <div class="col-md-6"><input type="date" name="tanggal_po"  class="form-control" autocomplete="off" autofocus></div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label">NO.PO</label>
                                    <div class="col-md-6"><input type="text" name="kode_po" value="<?php echo $kodeunik; ?>" class="form-control" autocomplete="off" readonly>
                                    </div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label"> Alamat Kirim</label>
                                    <div class="col-md-6">
                                        <select class="form-control select2" name="id_gudang" id="gudang">
                                        <option value="">Pilih Supplier....</option>
                                        <?php foreach ($gudang as $tampil) { ?>
                                            <option alamat="<?= $tampil->alamat_gudang; ?>" value="<?php echo $tampil->id_gudang; ?>"><?php echo $tampil->nama_gudang; ?></option>
                                        <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label"></label>
                                    <div class="col-md-6"><input type="text" name="alamat_gudang" id="alamat_gudang" class="form-control" autocomplete="off" autofocus></div>
                                </div>
                            </div>
                        </div>
<!-- ====================================================DATA ATAS======================================================================================= -->
<!-- ====================================================DATA TAMBAH PRODUK============================================================================== -->
                        <div class="ibox-content">
                            <table class="table table-bordered" >
                                <thead>
                                <tr>
                                    <th><center>NO</center></th>
                                    <th><center>KODE</center></th>
                                    <th colspan="2"><center>TRADE MARK</center></th>
                                    <th><center>QTY</center></th>
                                    <th><center>HARGA/UNIT</center></th>
                                    <th><center>TOTAL</center></th>
                                    <th><center><i class="fa fa-cogs"></i></center></th>
                                </tr>
                                </thead>
                                <tr>
                                    <td align="center" style="width:100px;">
                                        <div class="col-md-12"><input type="text" id="no" nama="no" class="form-control" readonly></div>
                                    </td>
                                    <td style="width:250px;">
                                        <div class="input-group"><input type="text" class="form-control" name="kode" id="_kodeInventori" readonly>
                                            <span class="input-group-append">
                                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addData"><i class="fa fa-search"></i>
                                            </button> </span>
                                        </div>
                                    </td>
                                    <td style="width:200px;">
                                        <div class="col-md-12"><input type="text" name="type_inventori" id="_typeInventori" class="form-control" autocomplete="off" autofocus></div>
                                    </td>
                                    <td style="width:200px;">
                                        <div class="col-md-12"><input type="text" name="pola_inventori" id="_polaInventori" class="form-control" autocomplete="off" autofocus></div>
                                    </td>
                                    <td style="width:120px;">
                                        <div class="col-md-12"><input type="number" name="jumlah" id="jumlah" class="form-control" autocomplete="off" autofocus></div>
                                    </td>
                                    <td style="width:300px;">
                                        <div class="col-md-12"><input type="text" name="harga_beli" id="harga_beli" class="form-control" autocomplete="off" autofocus></div>
                                    </td>
                                    <td style="width:300px;">
                                        <div class="col-md-12"><input type="number" name="total" id="total" class="form-control" autocomplete="off" autofocus></div>
                                    </td>
                                    <td align="center" style="width:50px;">
                                        <button type="button" id="tambah_data" class="btn btn-outline btn-primary"><span class="fa fa-plus"></span> </button>
                                    </td>
                                </tr>
                            </table>
                        </div>

<!-- ================================================DATA TAMBAH PRODU==================================================================================== -->
<!-- ================================================DATA TAMPIL PRODUK=================================================================================== -->
                            <div class="ibox-content">

                                <table class="table table-bordered" id="data_table">
                                    <thead>
                                    <tr>
                                        <th><center>#</center></th>
                                        <th><center>KODE</center></th>
                                        <th colspan="2"><center>TRADE MARK</center></th>
                                        <th><center>QTY</center></th>
                                        <th><center>HARGA/UNIT</center></th>
                                        <th><center>TOTAL</center></th>
                                    </tr>
                                    </thead>
                                    <tbody id="detail_barang">

                                    </tbody>
                                </table>
                            </div>
                        <div class="hr-line-dashed"></div>
                            <div class="row">
                                <div class="col-sm-6">
                                    <textarea type="text" name="keterangan"  class="form-control"></textarea>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group row"><label class="col-sm-3 col-form-label">Discount</label>
                                        <div class="col-md-6"><input type="number" name="discount"  class="form-control" autocomplete="off" autofocus></div>
                                    </div>
                                <div class="hr-line-dashed"></div>
                                   <div class="form-group row"><label class="col-sm-3 col-form-label">POT</label>
                                        <div class="col-md-6"><input type="number" name="pot"  class="form-control" autocomplete="off" autofocus></div>
                                    </div>
                                    <div class="form-group row"><label class="col-sm-3 col-form-label">SubTotal</label>
                                        <div class="col-md-6"><input type="number" name="subtotal"  class="form-control" autocomplete="off" autofocus></div>
                                    </div>
                                <div class="hr-line-dashed"></div>
                                    <div class="form-group row"><label class="col-sm-3 col-form-label">PPN</label>
                                        <div class="col-md-6"><input type="number" name="ppn"  class="form-control" autocomplete="off" autofocus></div>
                                    </div>
                                    <div class="form-group row"><label class="col-sm-3 col-form-label">TOTAL</label>
                                        <div class="col-md-6"><input type="number" name="total"  class="form-control" autocomplete="off" autofocus></div>
                                    </div>
                                </div>
                            </div>
                        <div class="hr-line-dashed"></div>
                        <button type="submit" name="simpan" value="simpan" id="simpan" class="btn btn-outline btn-primary simpan">Tambah Data</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- ====================================================DATA TAMPIL PRODUK=============================================================================== -->
<!-- ====================================================DATA MODAL PRODUK=============================================================================== -->
<div class="modal fade shadow-lg" id="addData" role="dialog">
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
        <div class="modal-content animated bounceInRight">
        <div class="modal-header">
            <h5 class="modal-title">Tambah Data Satuan</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
            </button>
        </div>
            <form action="" method="POST">
            <div class="modal-body">
            <!-- isi tabel -->
                <table class="table table-striped table-bordered table-hover dataTables" >
                    <thead>
                        <tr>
                            <th><center>#.</center></th>
                            <th><center>Kode</center></th>
                            <th><center>Type</center></th>
                            <th><center>Brand</center></th>
                            <th><center>Pola</center></th>
                            <th><center>Harga </center></th>
                            <th><center><i class="fa fa-cogs"></i></center></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $no=0; foreach ($inventori as $tampil) : $no++?>
                            <tr>
                                <td><?= $no;?></td>
                                <td><?= $tampil->kode_inventori; ?></td>
                                <td><?= $tampil->type_inventori; ?></td>
                                <td><?= $tampil->nama_brand; ?></td>
                                <td><?= $tampil->pola_inventori; ?></td>
                                <td><?= $tampil->harga_beli; ?></td>
                                <td><center>
                                <div class="btn-group">
                                    <span class="btn btn-primary btn-outline btn-xs _pilihBarang"  kode="<?= $tampil->kode_inventori; ?>" type="<?= $tampil->type_inventori?>"  pola="<?= $tampil->pola_inventori?>" harga="<?= $tampil->harga_beli; ?>"><i class="fa fa-plus"></i></span>
                                </div>
                            </tr>
                        <?php endforeach;?>
                    </tbody>
                </table>
            <!-- end tabel -->
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary btn-outline" data-dismiss="modal">Kembali</button>
        </div>
        </form>
        </div>
    </div>
</div>
<!-- ====================================================DATA TAMPIL ALAMAT=============================================================================== --
<!-- ====================================================DATA TAMPIL ALAMAT=============================================================================== -->
<script src="<?php echo base_url('assets/vendor/js/jquery-3.1.1.min.js');?>"></script>
<script>

    $(document).ready(function(){
        //mengambil alamat profit
    $("#profit").on("change", function(){
        var alamat = $("#profit option:selected").attr("alamat");
        $("#alamat_prof").val(alamat);
    });
        //mengambil alamat gudang
    $("#gudang").on("change", function(){
        var alamat = $("#gudang option:selected").attr("alamat");
        $("#alamat_gudang").val(alamat);
    });
        //mengambil harga beli inventori
    $("#produk").on("change", function(){
        var harga = $("#produk option:selected").attr("harga");
        $("#harga_beli").val(harga);
    });

    $("#jumlah").keyup(function(){
        var harga_beli = $("#harga_beli").val();
        var jumlah = $("#jumlah").val();
        $("#total").val(jumlah * harga_beli);

    });
    //tampil barang dari modal
    $(document).ready(function() {
        $('._pilihBarang').click(function() {
            $('#id_inventori').val($(this).attr('id'));
            $('#_kodeInventori').val($(this).attr('kode'));
            $('#_typeInventori').val($(this).attr('type'));
            $('#_polaInventori').val($(this).attr('pola'));
            $('#harga_beli').val($(this).attr('harga'));
            $('.modal-backdrop, #addData').fadeOut();
        });
    });
    //tampil barang dari modal

    });
</script>
<!-- ===================================================DATA TAMPIL ALAMAT=========================================================================== -->
<!-- ==================================================MENAMPILKAN DATA KEDALAM TABEL================================================================ -->
<script type="text/javascript">
$(function() {

    var set_number = function(){
        var table_len = $('#data_table tbody tr').length+1;

        $('#no').val(table_len);
    }

    set_number();

    $('#tambah_data').click(function(){

        var no           = $('#no').val();
        var kode         = $('#_kodeInventori').val();
        var type         = $('#_typeInventori').val();
        var pola         = $('#_polaInventori').val();
        var jumlah       = $('#jumlah').val();
        var harga_beli   = $('#harga_beli').val();
        var total        = $('#total').val();

        $('#data_table tbody:last-child').append(

            '<tr>'+
                '<td>'+no+'</td>'+
                '<td>'+kode+'</td>'+
                '<td>'+type+'</td>'+
                '<td>'+pola+'</td>'+
                '<td>'+jumlah+'</td>'+
                '<td>'+harga_beli+'</td>'+
                '<td>'+total+'</td>'+
            '</tr>'
        );
        // clear input data
        $('#no').val('');
        $('#kode').val('');
        $('#type').val('');
        $('#pola').val('');
        $('#jumlah').val('');
        $('#harga_beli').val('');
        $('#total').val('');

        set_number(); //call the function set number
    });
});

</script>
<!-- =============================================MENAMPILKAN DATA KEDALAM TABEL====================================================== -->

avatar qwerter
@qwerter

5 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban