View difference between Paste ID: bnWZNqft and V8xenfBf
SHOW: | | - or go back to the newest paste.
1-
<div class="x_panel">
1+
<?php
2-
    <div class="x_title">
2+
3-
    <h2><button type="button" class="add btn btn-primary"><i class="fa fa-plus-square"></i> Tambah Data </button></h2>
3+
if (!defined('BASEPATH'))
4-
<div class="clearfix"></div>
4+
    exit('No direct script access allowed');
5-
</div>
5+
6-
      <!-- dimatikan karena membuat filter diatas, tidak digunakan karena sudah ada. -->
6+
class Service extends CI_Controller {
7-
      <!-- <link href="<?php //echo base_url('assets/datatables/css/jquery.dataTables.min.css')?>" rel="stylesheet"> -->
7+
8
    public function __construct() {
9-
<table class="table table-striped table-responsive" id="table">
9+
        parent::__construct();
10-
<thead>
10+
        $this->load->model('Mservice');
11-
    <tr>
11+
12-
        <th>No.</th>
12+
13-
        <th>No Rangka</th>
13+
    function index() {
14-
        <th>No Polisi</th>
14+
        $data['title'] = 'Data Service Mobil';
15-
        <th>Model</th>
15+
        $data['content'] = 'v_service';
16-
        <th>Type</th>
16+
        // $data['datatables'] = $this->Mservice->service();
17-
        <th>Transmission</th>
17+
        $this->load->view('template', $data);
18-
        <th>Warna</th>
18+
19-
        <th>Tahun</th>
19+
20-
        <th>Km</th>
20+
    function get_data_user() {
21-
        <th>Customer</th>
21+
        $list = $this->Mservice->get_datatables();
22-
        <th>Telephone</th>
22+
        $data = array();
23-
        <th>Handphone</th>
23+
        $no = $_POST['start'];
24-
        <th>Contact Person</th>
24+
        foreach ($list as $field) {
25-
        <th>Telephone cp</th>
25+
            $no++;
26-
        <th>Cabang Penjual</th>
26+
            $row = array();
27-
        <th>Cabang Service</th>
27+
            $row[] = $no;
28-
        <th>Salesman</th>
28+
            $detail="rangka: ".$field->no_rangka.
29-
        <th>Last Service</th>
29+
                    "<br/>nopol: ".$field->no_polisi;
30-
        <th>Job</th>
30+
            $row[]=$detail;
31-
        <th>Pekerjaan Utama</th>
31+
            $row[]="<button>edit</button><button>hapus</button>";
32-
        <th>Program Promo Khusus</th>
32+
            $data[] = $row;
33-
        <th>Status</th>
33+
34-
        <th>Hasil FU 1</th>
34+
35-
        <th>Hasil FU 2</th>
35+
        $output = array(
36-
        <th>Hasil FU 3</th>
36+
            "draw" => $_POST['draw'],
37
            "recordsTotal" => $this->Mservice->count_all(),
38-
        <!-- <th>Action</th> -->
38+
            "recordsFiltered" => $this->Mservice->count_filtered(),
39-
    </tr>
39+
            "data" => $data,
40-
</thead>
40+
        );
41-
<tbody>
41+
        //output dalam format JSON
42
        echo json_encode($output);
43-
    <script type="text/javascript">
43+
44-
    var table;
44+
45-
    $(document).ready(function() {
45+
46
    function get_data_user_old() {
47-
        //datatables
47+
        $list = $this->Mservice->get_datatables();
48-
        table = $('#table').DataTable({ 
48+
        $data = array();
49
        $no = $_POST['start'];
50-
            "processing": true, 
50+
        foreach ($list as $field) {
51-
            "serverSide": true, 
51+
            $no++;
52-
            "order": [], 
52+
            $row = array();
53-
            
53+
            $row[] = $no;
54-
            "ajax": {
54+
            $row[] = $field->no_rangka;
55-
                "url": "<?php echo site_url('service/get_data_user')?>",
55+
            $row[] = $field->no_polisi;
56-
                "type": "POST"
56+
            $row[] = $field->model;
57-
            },
57+
            $row[] = $field->type;
58
            $row[] = $field->transmission;
59-
            
59+
            $row[] = $field->warna;
60-
            "columnDefs": [
60+
            $row[] = $field->tahun;
61-
            { 
61+
            $row[] = $field->km;
62-
                "targets": [ 0 ], 
62+
            $row[] = $field->customer;
63-
                "orderable": false, 
63+
            $row[] = $field->telephone;
64-
            },
64+
            $row[] = $field->handphone;
65-
            ],
65+
            $row[] = $field->contact_person;
66
            $row[] = $field->telephone_cp;
67-
        });
67+
            $row[] = $field->cabang_penjual;
68
            $row[] = $field->cabang_service;
69-
    });
69+
            $row[] = $field->salesman;
70
            $row[] = $field->last_service;
71-
</script>
71+
            $row[] = $field->job;
72
            $row[] = $field->pekerjaan_utama;
73
            $row[] = $field->program_promo;
74-
</tbody>
74+
            $row[] = $field->status_aktif;
75-
</table>
75+
            $row[] = $field->hasil_fu1;
76-
</div>
76+
            $row[] = $field->hasil_fu2;
77-
<script src="<?php echo base_url('assets/jquery/jquery-2.2.3.min.js')?>"></script>
77+
            $row[] = $field->hasil_fu3;
78-
<script src="<?php echo base_url('assets/datatables/js/jquery.dataTables.min.js')?>"></script> 
78+
            $data[] = $row;
79-
 
79+
80-
<!-- Data tables -->
80+
81-
<style type="text/css">@import url("<?php echo base_url() . 'js/datatables/jquery.dataTables.min.css'; ?>");</style>
81+
        $output = array(
82-
<script type='text/javascript' src="<?php echo base_url(); ?>js/datatables/jquery.dataTables.min.js"></script>
82+
            "draw" => $_POST['draw'],
83-
<script type='text/javascript' src="<?php echo base_url(); ?>js/datatables/dataTables.bootstrap.js"></script>
83+
            "recordsTotal" => $this->Mservice->count_all(),
84
            "recordsFiltered" => $this->Mservice->count_filtered(),
85
            "data" => $data,
86
        );
87-
    <!-- menambahkan script untuk memunculkan tambah data service-->
87+
        //output dalam format JSON
88
        echo json_encode($output);
89-
    <script type="text/javascript">
89+
90-
    $(document).ready(function() {
90+
91-
        $('#datatables').dataTable();
91+
    ///pisahkan saja datanya...
92-
        $('.add').click(function(){
92+
    //function untuk tambah data service, abaikan dahulu karena fokus ke edit data.
93-
            $('#addModal').modal('show');
93+
    function addService() {
94-
            $('#form')[0].reset();
94+
        $add = array(
95-
        });
95+
            'no_rangka' => $this->input->post('no_rangka'),
96-
        $('#save').click(function(){
96+
            'no_polisi' => $this->input->post('no_polisi'),
97-
            $.ajax({
97+
            'model' => $this->input->post('model'),
98-
                url :"<?php echo site_url();?>service/addService",
98+
            'type' => $this->input->post('type'),
99-
                type:"POST",
99+
            'transmission' => $this->input->post('transmission'),
100-
                data:$("#form").serialize(),
100+
            'warna' => $this->input->post('warna'),
101-
                success:function(){
101+
            'tahun' => $this->input->post('tahun'),
102-
                    $('#addModal').modal('hide');
102+
            'km' => $this->input->post('km'),
103-
                    location.reload();
103+
            'customer' => $this->input->post('customer'),
104-
                }
104+
            'telephone' => $this->input->post('telephone'),
105-
            })
105+
            'handphone' => $this->input->post('handphone'),
106-
        });
106+
            'contact_person' => $this->input->post('contact_person'),
107-
        $('#saveEdit').click(function(){
107+
            'telephone_cp' => $this->input->post('telephone_cp'),
108-
            $.ajax({
108+
            'cabang_penjual' => $this->input->post('cabang_penjual'),
109-
                url :"<?php echo site_url();?>service/newService",
109+
            'cabang_service' => $this->input->post('cabang_service'),
110-
                type:"post",
110+
            'salesman' => $this->input->post('salesman'),
111-
                data:$("#form2").serialize(),
111+
            'last_service' => $this->input->post('last_service'),
112-
                success:function(){
112+
            'job' => $this->input->post('job'),
113-
                    $('#editModal').modal('hide');
113+
            'pekerjaan_utama' => $this->input->post('pekerjaan_utama'),
114-
                    location.reload();
114+
            'program_promo' => $this->input->post('program_promo'),
115-
                }
115+
            'status_aktif' => $this->input->post('status_aktif'),
116-
            })
116+
            'hasil_fu1' => $this->input->post('hasil_fu1'),
117-
        });
117+
            'hasil_fu2' => $this->input->post('hasil_fu2'),
118-
    });
118+
            'hasil_fu3' => $this->input->post('hasil_fu3'),
119
                //'model' => 0
120-
function edit(id){
120+
        );
121-
    $.getJSON('<?php echo site_url();?>service/editService/'+id,
121+
        $this->Mservice->addService($add);
122-
        function( response ) {
122+
123-
            $("#editModal").modal('show');
123+
124-
            $("#nno_rangka").val(response['no_rangka']);
124+
    //funsi edit data, data yang ada di dalam database.
125-
            $("#nno_polisi").val(response['no_polisi']);
125+
    function editService($id) {
126-
            $("#nmodel").val(response['model']);
126+
        $flag = array('no_rangka' => $id);
127-
            $("#ntype").val(response['type']);
127+
        $get = $this->Mservice->getService($flag)->row();
128-
            $("#ntransmission").val(response['transmission']);
128+
        echo json_encode($get);
129-
            $("#nwarna").val(response['warna']);
129+
130-
            $("#ntahun").val(response['tahun']);
130+
131-
            $("#nkm").val(response['km']);
131+
    //fungsi
132-
            $("#ncustomer").val(response['customer']);
132+
    function newService() {
133-
            $("#ntelephone").val(response['telephone']);
133+
        $flag = array('no_rangka' => $this->input->post('oid'));
134-
            $("#nhandphone").val(response['handphone']);
134+
        $edit = array(
135-
            $("#ncontact_person").val(response['contact_person']);
135+
            'no_rangka' => $this->input->post('nno_rangka'),
136-
            $("#ntelephone_cp").val(response['telephone_cp']);
136+
            'no_polisi' => $this->input->post('nno_polisi'),
137-
            $("#ncabang_penjual").val(response['cabang_penjual']);
137+
            'model' => $this->input->post('nmodel'),
138-
            $("#ncabang_service").val(response['cabang_service']);
138+
            'type' => $this->input->post('ntype'),
139-
            $("#nsalesman").val(response['salesman']);
139+
            'transmission' => $this->input->post('ntransmission'),
140-
            $("#nlast_service").val(response['last_service']);
140+
            'warna' => $this->input->post('nwarna'),
141-
            $("#njob").val(response['job']);
141+
            'tahun' => $this->input->post('ntahun'),
142-
            $("#npekerjaan_utama").val(response['pekerjaan_utama']);
142+
            'km' => $this->input->post('nkm'),
143-
            $("#nprogram_promo").val(response['program_promo']);
143+
            'customer' => $this->input->post('ncustomer'),
144-
            $("#nstatus_aktif").val(response['status_aktif']);
144+
            'telephone' => $this->input->post('ntelephone'),
145-
            $("#nhasil_fu1").val(response['hasil_fu1']);
145+
            'handphone' => $this->input->post('nhandphone'),
146-
            $("#nhasil_fu2").val(response['hasil_fu2']);
146+
            'contact_person' => $this->input->post('ncontact_person'),
147-
            $("#nhasil_fu3").val(response['hasil_fu3']);
147+
            'telephone_cp' => $this->input->post('ntelephone_cp'),
148
            'cabang_penjual' => $this->input->post('ncabang_penjual'),
149
            'cabang_service' => $this->input->post('ncabang_service'),
150-
            $("#oid").val(response['no_rangka']);
150+
            'salesman' => $this->input->post('nsalesman'),
151
            'last_service' => $this->input->post('nlast_service'),
152-
    );
152+
            'job' => $this->input->post('njob'),
153-
}
153+
            'pekerjaan_utama' => $this->input->post('npekerjaan_utama'),
154
            'program_promo' => $this->input->post('nprogram_promo'),
155-
function del(id){
155+
            'status_aktif' => $this->input->post('nstatus_aktif'),
156-
    if(confirm('Yakin menghapus data ?')){
156+
            'hasil_fu1' => $this->input->post('nhasil_fu1'),
157-
        $.ajax({
157+
            'hasil_fu2' => $this->input->post('nhasil_fu2'),
158-
                url :"<?php echo site_url();?>service/deleteService/"+id,
158+
            'hasil_fu3' => $this->input->post('nhasil_fu3')
159-
                type:"post",
159+
        );
160-
                success:function(){
160+
        $this->Mservice->editService($flag, $edit);
161-
                    location.reload();
161+
162-
                }
162+
163-
            })
163+
    function deleteService($id) {
164
        $flag = array('no_rangka' => $id);
165-
}
165+
        $this->Mservice->deleteService($flag);
166
    }
167-
    //form menampilkan data yang akan di inputkan.
167+
168-
</script>
168+
}