Advertisement
yofikur

model/produk

May 6th, 2020
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. // Model Mfoto Produk
  2. <?php
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4. class Mfotoproduk extends CI_Model {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. public function data(){
  9. return $this->db->get('fotoproduk');
  10. }
  11. public function tambah($gambar){
  12. $d['id_produk_fotoproduk']= $this->input->post('id_produk');
  13. $d['foto_fotoproduk']= $gambar;
  14. $this->db->insert('fotoproduk',$d);
  15. }
  16. public function detailfotoproduk(){
  17. $this->db->where('id_fotoproduk',$this->uri->segment(3));
  18. return $this->db->get('fotoproduk');
  19. }
  20. public function hapus($id_fotoproduk){
  21. $this->db->where('id_fotoproduk',$id_fotoproduk);
  22. $this->db->delete('fotoproduk');
  23. }
  24. public function getone($id_fotoproduk){
  25. $this->db->where('id_fotoproduk',$id_fotoproduk);
  26. return $this->db->get('fotoproduk');
  27. }
  28. public function fotobykode($kode_produk){
  29. $this->db->join('produk','produk.id_produk=fotoproduk.id_produk_fotoproduk','left');
  30. $this->db->where('kode_produk',$kode_produk);
  31. return $this->db->get('fotoproduk');
  32. }
  33. }
  34.  
  35. // Model mproduk
  36. <?php
  37. defined('BASEPATH') OR exit('No direct script access allowed');
  38. class Mproduk extends CI_Model {
  39. public function __construct(){
  40. parent::__construct();
  41. }
  42. public function data(){
  43. $this->db->order_by('tglinput_produk','desc');
  44. return $this->db->get('produk');
  45. }
  46. public function datakategori($id_kategori){
  47. $this->db->where('id_kategori_produk',$id_kategori);
  48. $this->db->order_by('tglinput_produk','desc');
  49. return $this->db->get('produk');
  50. }
  51.  
  52. public function tambah($kode_produk,$gambar,$slug){
  53. $d['kode_produk']= $kode_produk;
  54. $d['id_kategori_produk']= $this->input->post('id_kategori');
  55. $d['nama_produk']= $this->input->post('nama_produk');
  56. $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
  57. $d['diskon_produk']= $this->input->post('diskon_produk');
  58. $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
  59. $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
  60. $d['stokawal_produk']= $this->input->post('stokawal_produk');
  61. $d['berat_produk']= $this->input->post('berat_produk');
  62. $d['foto_produk']= $gambar;
  63. $d['slug_produk']= $slug;
  64. $d['tglinput_produk']= date('Y-m-d H:i:s');
  65. $this->db->insert('produk',$d);
  66. }
  67. public function edit($gambar,$slug){
  68. $d['id_kategori_produk']= $this->input->post('id_kategori');
  69. $d['nama_produk']= $this->input->post('nama_produk');
  70. $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
  71. $d['diskon_produk']= $this->input->post('diskon_produk');
  72. $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
  73. $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
  74. $d['stokawal_produk']= $this->input->post('stokawal_produk');
  75. $d['berat_produk']= $this->input->post('berat_produk');
  76. $d['foto_produk']= $gambar;
  77. $d['slug_produk']= $slug;
  78. $this->db->where('id_produk',$this->input->post('id_produk'));
  79. $this->db->update('produk',$d);
  80. }
  81. public function editnotfoto($slug){
  82. $d['id_kategori_produk']= $this->input->post('id_kategori');
  83. $d['nama_produk']= $this->input->post('nama_produk');
  84. $d['deskripsi_produk']= $this->input->post('deskripsi_produk');
  85. $d['diskon_produk']= $this->input->post('diskon_produk');
  86. $d['hargaasli_produk']= hilangtitik($this->input->post('hargaasli_produk'));
  87. $d['harga_produk']= hilangtitik($this->input->post('harga_produk'));
  88. $d['stokawal_produk']= $this->input->post('stokawal_produk');
  89. $d['berat_produk']= $this->input->post('berat_produk');
  90. $d['slug_produk']= $slug;
  91. $this->db->where('id_produk',$this->input->post('id_produk'));
  92. $this->db->update('produk',$d);
  93. }
  94. public function getonebykode($kode_produk){
  95. $this->db->join('kategori','kategori.id_kategori=produk.id_kategori_produk','left');
  96. $this->db->where('kode_produk',$kode_produk);
  97. return $this->db->get('produk');
  98. }
  99. public function hapus($id_produk){
  100. $this->db->where('id_produk',$id_produk);
  101. $this->db->delete('produk');
  102. }
  103.  
  104. public function sisastok($id_produk){
  105. $produk= $this->db->where('id_produk',$id_produk)->get('produk')->row_array();
  106. $detail= $this->db->query("SELECT sum(qty_detail) as stokout from detail where id_produk_detail='$id_produk' ")->row_array();
  107. $sisa= $produk['stokawal_produk']-$detail['stokout'];
  108. return $sisa;
  109. }
  110. //data produk
  111. private function _get_datatables_queryproduk()
  112. {
  113. $table = 'produk';
  114. $column_order = array(null,null,'nama_produk','nama_kategori','diskon_produk','hargaasli_produk','harga_produk','stokawal_produk','tglinput_produk');
  115. $column_search = array('kode_produk','nama_produk','nama_kategori','diskon_produk','hargaasli_produk','harga_produk','stokawal_produk','tglinput_produk');
  116. $order = array('tglinput_produk' => 'desc');
  117. $this->db->select('*');
  118. $this->db->join('kategori','kategori.id_kategori=produk.id_kategori_produk','left');
  119. $this->db->from($table);
  120. $i = 0;
  121. foreach ($column_search as $item)
  122. {
  123. if($_POST['search']['value'])
  124. {
  125. if($i===0)
  126. {
  127. $this->db->group_start();
  128. $this->db->like($item, $_POST['search']['value']);
  129. }
  130. else
  131. {
  132. $this->db->or_like($item, $_POST['search']['value']);
  133. }
  134. if(count($column_search) - 1 == $i)
  135. $this->db->group_end();
  136. }
  137. $i++;
  138. }
  139.  
  140.  
  141. }
  142. function get_datatablesproduk()
  143. {
  144. $this->_get_datatables_queryproduk();
  145. if($_POST['length'] != -1)
  146. $this->db->limit($_POST['length'], $_POST['start']);
  147. $query = $this->db->get();
  148. return $query->result();
  149. }
  150. function count_filteredproduk()
  151. {
  152. $this->_get_datatables_queryproduk();
  153. $query = $this->db->get();
  154. return $query->num_rows();
  155. }
  156. public function count_allproduk()
  157. {
  158. $this->_get_datatables_queryproduk();
  159. return $this->db->count_all_results();
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement