donnykurnia icon

Untitled

donnykurnia | PRO | 01/30/18 01:59:26 AM UTC | 0 ⭐ | 494 👁️ | Never ⏰ | []
PHP |

17.28 KB

|

None

|

0 👍

/

0 👎

<?php
// controler
 
public function saveTrans1(){
    $path   = './xls223/';
    $config ['file_name']='data.xlsx';
    $config['upload_path']=$path;
 
    $config['allowed_types']='xlsx';
    $config['max_size']='200000';
    $config['max_width']='202400';
    $config['max_height']='146800';
    $config['overwrite']=true;
 
    $this->load->library('upload',$config);
    $this->upload->initialize($config);
    if ($config) {
        $this->load->library('form_validation');
 
        $this->form_validation->set_rules('product_id', 'Product', 'trim|required|xss_clean');
        $this->form_validation->set_rules('fullname[]', 'Name', 'trim|required|xss_clean');
        $this->form_validation->set_rules('email[]', 'Email', 'trim|required|xss_clean');
 
        if($this->input->post('status')==0) {
            $this->form_validation->set_rules('company[]', 'Company', 'trim|required|xss_clean');
            $this->form_validation->set_rules('jobtitle[]', 'Job Title', 'trim|required|xss_clean');
            $this->form_validation->set_rules('industry[]', 'Industry', 'trim|required|xss_clean');
 
        }
        if ($this->form_validation->run() == FALSE) {
            $message=$this->v2->alert('warning',validation_errors());
            $response=array('error',$message);
        } else {
            $product = $this->input->post('product');
            $product_id = $this->input->post('product_id');
            $salutation = $this->input->post('salutation');
            $fullname = $this->input->post('fullname');
            $email = $this->input->post('email');  
            $company = $this->input->post('company');
            $jobtitle = $this->input->post('jobtitle');
            $address = $this->input->post('address');
            $phonenumber = $this->input->post('phonenumber');
            $personal = $this->input->post('personal');
            $industry = $this->input->post('industry');
 
            $y = count($salutation);
            $nom=0;
            $nom++;
            for ($i = 0; $i < $y; $i++) {
 
 
 
                $postData['salutation'] = $salutation[$i];
                $postData['fullname'] =    $fullname[$i];
                $postData['email'] = $email[$i];
                $postData['company'] = $company[$i];
 
                $postData['jobtitle'] = $jobtitle[$i];
                $postData['address'] = $address[$i];
                $postData['phonenumber'] = $phonenumber[$i];
                $postData['personal'] =    $personal[$i];
                $postData['industry'] =    $industry[$i];  
 
                $postData['product_name']=$product;
                $postData['product_id']=$product_id;
                $postData['password']=$this->randomKey(6);  
                print ($i);
                $this->v2->inject_transaction_member($postData);
            }
        }
 
        $message=$this->v2->alert('success','Success input data');
        $response=array('success',$message);
 
        // $message=json_encode($_POST);
        echo json_encode($response);
    } else {
        redirect('admin/Trans/detail/');
    }
}
?>
<!-- view -->
<div class="content-wrapper" id="detailOfflineTrans">
    <section class="content-header">
        <Center> <h1>Add Transaction</h1> </Center><br>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i>History Order</a></li>
            <li class="active">List</li>
        </ol>
    </section>
    <div class="row" id="msgsaveOfflineTrans">
    </div>
    <section>
        <div class="row">
            <div class="col-lg-12">
                <form  id="addOfflineTransForm" method="post" accept-charset="utf-8">
                    <div class="col-md-12">
                        <div class="row" id="msgsaveOfflineTrans">
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-lg-12"><label>Product <span class="required">*</span></label></div>
                            <div class="col-lg-10">
                                <div class="form-group">
                                    <input type="hidden" name="product_id" >
                                    <input type="text" class="form-control" required="" name="product" readonly>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="form-group">
                                    <button class="btn btn-success" type ="button" data-toggle="modal" data-target="#newTransModal">Select Product</button>
                                </div>
                            </div>
                        </div>
                    </div>            
                    <div class="col-md-12" style="margin-top: 20px;">
                        <div class="box box-primary">
                            <div class="box-header with-border">
                                <h3 class="box-title">Detail Transaction</h3>
                            </div>
                            <div class="box-body">
                                <div class="col-md-12" style="margin-top: 20px;">
                                    <div class="col-md-12" style="margin-top: 20px;">
                                        <?php
                                        require_once 'PHPExcel/PHPExcel.php';
                                        $path   = './xls223/';
                                        $nama_file_baru='data.xlsx';
                                        $excelreader = new PHPExcel_Reader_Excel2007();
                                        $loadexcel = $excelreader->load($path.$nama_file_baru); // Load file yang tadi diupload ke folder tmp
                                        $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
                                        ?>
                                        <table class='table table-bordered'>
                                            <tr>
                                                <th>Salutation</th>
                                                <th>Full Name</th>
                                                <th>Email</th>
                                                <th>Company</th>
                                                <th>Job Title</th>
                                                <th>Address</th>
                                                <th>Mobile Phone</th>
                                                <th>Personal</th>
                                                <th>Industry</th>
                                            </tr>
                                            <?php
                                            $numrow = 1;
                                            $kosong = 0;
 
                                            foreach($sheet as $row) { // Lakukan perulangan dari data yang ada di excel
                                                // Ambil data pada excel sesuai Kolom
                                                $salutation = $row['A'];
                                                $fullname = $row['B']; // Ambil data NIS
                                                $email = $row['C'];
                                                $company = $row['D'];
                                                $jobtitle = $row['E'];
                                                $address = $row['F'];
                                                $mobilephone = $row['G'];
                                                $personal = $row['H'];
                                                $industry = $row['I'];
                                                // Cek jika semua data tidak diisi
                                                if(empty($salutation) && empty($fullname) && empty($email) && empty($company) && empty($jobtitle) && empty($address) && empty($mobilephone) && empty($personal) && empty($industy)) continue;  // Lewat data pada baris ini (masuk ke looping selanjutnya / baris selanjutnya)
                                                if($numrow > 1) {
                                                    // Validasi apakah semua data telah diisi
                                                    $salutation_td = ( ! empty($salutation))? "" : " style='background: red;'"; // Jika NIS kosong, beri warna merah
                                                    $fullname_td = ( ! empty($fullname))? "" : " style='background: red;'"; // Jika NIS kosong, beri warna merah
                                                    $email_td = ( ! empty($email))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
                                                    $company_td = ( ! empty($company))? "" : " style='background: red;'";
                                                    $jobtitle_td = ( ! empty($jobtitle))? "" : " style='background: red;'";
                                                    $address_td = ( ! empty($address))? "" : " style='background: red;'";
                                                    $mobilephone_td = ( ! empty($mobilephone))? "" : " style='background: red;'";
                                                    $personal_td = ( ! empty($personal))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
                                                    $industry_td = ( ! empty($industry))? "" : " style='background: red ;'";// Jika Nama kosong, beri warna merah
                                                    // Jika salah satu data ada yang kosong
                                                    if(empty($fullname) or empty($email)or empty($company)or empty($jobtitle)or empty($address)or empty($mobilephone)
                                                        or empty($personal)or empty($industry)) {
                                                        $kosong++; // Tambah 1 variabel $kosong
                                                    }
                                                    echo "<tr>";
                                                    echo "<td".$salutation_td."><input".$salutation_td." type='text' class='form-control' name='salutation[]'   value='$salutation'></td>";
                                                    echo "<td".$fullname_td."><input".$fullname_td." type='text' class='form-control' name='fullname[]' value='$fullname'></td>";
                                                    echo "<td".$email_td."><input".$email_td." type='email' class='form-control' name='email[]' value='$email'></td>";
                                                    echo "<td".$company_td."><input".$company_td." type='text' class='form-control' name='company[]'    value='$company'></td>";
                                                    echo "<td".$jobtitle_td."><input".$jobtitle_td." type='text' class='form-control' name='jobtitle[]' value='$jobtitle'></td>";
                                                    echo "<td".$address_td."><input".$address_td." type='text' class='form-control' name='address[]'    value='$address'></td>";
                                                    echo "<td".$mobilephone_td."><input".$mobilephone_td." type='text' class='form-control' name='phonenumber[]'    value='$mobilephone'></td>";
 
                                                    echo "<td".$personal_td."><input".$personal_td." type='text' class='form-control' name='personal[]' value='$personal'></td>";  
                                                    echo "<td".$industry_td."><input".$industry_td." type='text' class='form-control' name='industry[]' value='$industry'></td>";                                  
                                                    echo "</tr>";
                                                }
                                                $numrow++; // Tambah 1 setiap kali looping
                                            }
                                            ?>
                                        </table>
                                    </div>
                                    <div class="col-md-12">
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <div class="form-group col-sm-12">
                                    <button type="button" class="form-control btn btn-primary main-button" id="submitBtn" onclick="saveOfflineTrans()" >Save</button>
                                    <button style="display:none" type="button" class="form-control btn btn-primary main-button" id="loadingBtn"><i class="fa fa-circle-o-notch fa-spin"></i> Processing</button>
                                </div>
                                <!--
                                <div class="form-group col-sm-4">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                </div>
                                -->
                            </div>  
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<!-- Modal -->
<div id="newTransModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Add Transaction</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="box-body table-responsive">
                        <table id="tabelproduct" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Name</th>
                                    <!-- <th>Stock</th> -->
                                    <th>Type</th>
                                    <!-- <th>Diskon Price</th>-->
                                    <!-- <th>Weight</th>-->
                                    <th>Category</th>
                                    <!-- <th>Timestamp</th> -->
                                    <th style="width:100px">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($products as $product): ?>
                                    <tr>
                                        <td><?php echo $product->product_id; ?></td>
                                        <td width="150px">
                                            <?php
                                            $location=$this->mProduct->getAttribute3($product->product_id,46);
                                            $dateStart=$this->mProduct->getAttribute3($product->product_id,49);
                                            if($location->row()){
                                                $newDate=date('d M Y',strtotime($dateStart->row()->product_attr_value));
                                                echo "<span style='font-size:11px;font-weight: 700;color:#ec028d;'>".$location->row()->product_attr_value. " - ".$newDate."</span><br>";
                                            }
                                            echo "<a href='#' data-id='".$product->product_id."' class='get-detail'>".$product->product_name."</a>"; ?>
                                            <?php if($product->status==2) echo "<span style='color: red;font-size: 10px;'>Draft</span>";?>
                                        </td>
                                        <!--  <td><?php echo $product->product_stock; ?></td> -->
                                        <td width="150px">
                                            <?php echo (strlen($product->lms_slug)>=3?'Online Training':'No Slug Found'); ?>
                                        </td>
                                        <!-- <td width="150px">--><?php //echo formatRupiah($product->disc_price); ?><!--</td>-->
                                        <!-- <td>--><?php //echo $product->product_weight; ?><!--</td>-->
                                        <td><?php echo $product->category; ?></td>
                                        <!-- <td><?php echo date('d M Y',strtotime($product->timestamp)); ?></td> -->
                                        <td style="width:100px">
                                            <a onClick="selectProduct(<?php echo $product->product_id; ?>,'<?php echo $product->product_name; ?>')" class="btn btn-danger">Select Product</a>
                                        </td>
                                    </tr>
                                    <?php $no++; ?>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Comments