Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Model Mfoto Produk
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Mfotoproduk extends CI_Model {
- public function __construct(){
- parent::__construct();
- }
- public function data(){
- return $this->db->get('fotoproduk');
- }
- public function tambah($gambar){
- $d['id_produk_fotoproduk']= $this->input->post('id_produk');
- $d['foto_fotoproduk']= $gambar;
- $this->db->insert('fotoproduk',$d);
- }
- public function detailfotoproduk(){
- $this->db->where('id_fotoproduk',$this->uri->segment(3));
- return $this->db->get('fotoproduk');
- }
- public function hapus($id_fotoproduk){
- $this->db->where('id_fotoproduk',$id_fotoproduk);
- $this->db->delete('fotoproduk');
- }
- public function getone($id_fotoproduk){
- $this->db->where('id_fotoproduk',$id_fotoproduk);
- return $this->db->get('fotoproduk');
- }
- public function fotobykode($kode_produk){
- $this->db->join('produk','produk.id_produk=fotoproduk.id_produk_fotoproduk','left');
- $this->db->where('kode_produk',$kode_produk);
- return $this->db->get('fotoproduk');
- }
- }
- // Model mproduk
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Mproduk extends CI_Model {
- public function __construct(){
- parent::__construct();
- }
- public function data(){
- $this->db->order_by('tglinput_produk','desc');
- return $this->db->get('produk');
- }
- public function datakategori($id_kategori){
- $this->db->where('id_kategori_produk',$id_kategori);
- $this->db->order_by('tglinput_produk','desc');
- return $this->db->get('produk');
- }
- public function tambah($kode_produk,$gambar,$slug){
- $d['kode_produk']= $kode_produk;
- $d['id_kategori_produk']= $this->input->post('id_kategori');
- $d['nama_produk']= $this->input->post('nama_produk');
- $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
- $d['diskon_produk']= $this->input->post('diskon_produk');
- $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
- $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
- $d['stokawal_produk']= $this->input->post('stokawal_produk');
- $d['berat_produk']= $this->input->post('berat_produk');
- $d['foto_produk']= $gambar;
- $d['slug_produk']= $slug;
- $d['tglinput_produk']= date('Y-m-d H:i:s');
- $this->db->insert('produk',$d);
- }
- public function edit($gambar,$slug){
- $d['id_kategori_produk']= $this->input->post('id_kategori');
- $d['nama_produk']= $this->input->post('nama_produk');
- $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
- $d['diskon_produk']= $this->input->post('diskon_produk');
- $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
- $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
- $d['stokawal_produk']= $this->input->post('stokawal_produk');
- $d['berat_produk']= $this->input->post('berat_produk');
- $d['foto_produk']= $gambar;
- $d['slug_produk']= $slug;
- $this->db->where('id_produk',$this->input->post('id_produk'));
- $this->db->update('produk',$d);
- }
- public function editnotfoto($slug){
- $d['id_kategori_produk']= $this->input->post('id_kategori');
- $d['nama_produk']= $this->input->post('nama_produk');
- $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
- $d['diskon_produk']= $this->input->post('diskon_produk');
- $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
- $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
- $d['stokawal_produk']= $this->input->post('stokawal_produk');
- $d['berat_produk']= $this->input->post('berat_produk');
- $d['slug_produk']= $slug;
- $this->db->where('id_produk',$this->input->post('id_produk'));
- $this->db->update('produk',$d);
- }
- public function getonebykode($kode_produk){
- $this->db->join('kategori','kategori.id_kategori=produk.id_kategori_produk','left');
- $this->db->where('kode_produk',$kode_produk);
- return $this->db->get('produk');
- }
- public function hapus($id_produk){
- $this->db->where('id_produk',$id_produk);
- $this->db->delete('produk');
- }
- public function sisastok($id_produk){
- $produk= $this->db->where('id_produk',$id_produk)->get('produk')->row_array();
- $detail= $this->db->query("SELECT sum(qty_detail) as stokout from detail where id_produk_detail='$id_produk' ")->row_array();
- $sisa= $produk['stokawal_produk']-$detail['stokout'];
- return $sisa;
- }
- //data produk
- private function _get_datatables_queryproduk()
- {
- $table = 'produk';
- $column_order = array(null,null,'nama_produk','nama_kategori','diskon_produk','hargaasli_produk','harga_produk','stokawal_produk','tglinput_produk');
- $column_search = array('kode_produk','nama_produk','nama_kategori','diskon_produk','hargaasli_produk','harga_produk','stokawal_produk','tglinput_produk');
- $order = array('tglinput_produk' => 'desc');
- $this->db->select('*');
- $this->db->join('kategori','kategori.id_kategori=produk.id_kategori_produk','left');
- $this->db->from($table);
- $i = 0;
- foreach ($column_search as $item)
- {
- if($_POST['search']['value'])
- {
- if($i===0)
- {
- $this->db->group_start();
- $this->db->like($item, $_POST['search']['value']);
- }
- else
- {
- $this->db->or_like($item, $_POST['search']['value']);
- }
- if(count($column_search) - 1 == $i)
- $this->db->group_end();
- }
- $i++;
- }
- }
- function get_datatablesproduk()
- {
- $this->_get_datatables_queryproduk();
- if($_POST['length'] != -1)
- $this->db->limit($_POST['length'], $_POST['start']);
- $query = $this->db->get();
- return $query->result();
- }
- function count_filteredproduk()
- {
- $this->_get_datatables_queryproduk();
- $query = $this->db->get();
- return $query->num_rows();
- }
- public function count_allproduk()
- {
- $this->_get_datatables_queryproduk();
- return $this->db->count_all_results();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement