Advertisement
Guest User

product

a guest
Sep 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1. <?php  
  2. /**
  3.  * Class Produk,
  4.  *
  5.  * @package Produk
  6.  * @author
  7.  **/
  8. require 'App.php';
  9.  
  10. class Product extends App
  11. {
  12.     public function __construct()
  13.     {
  14.         if(empty($_SESSION['is_login'])) :
  15.             header("Location:login.php");
  16.         endif;
  17.     }
  18.  
  19.     /**
  20.      * Menampilkan Data Semua Produj
  21.      *
  22.      * @param String, Integer ( search, limit, offset)
  23.      * @return Array
  24.      **/
  25.     public function data_produk($cari='', $start = 10, $limit = 0)
  26.     {
  27.         $query = mysqli_query($this->connection(), "SELECT * from tb_wajibpajak WHERE nama LIKE '%{$cari}%' OR alamat_objek LIKE '%{$cari}%' ORDER BY id DESC LIMIT {$start}, {$limit}");
  28.         /**
  29.         $query = mysqli_query($this->connection(), "SELECT tb_produk.*, tb_stok.* FROM tb_produk INNER JOIN tb_stok ON tb_produk.id_produk = tb_stok.id_produk WHERE tb_produk.kode_produk LIKE '%{$cari}%' OR tb_produk.nama_produk LIKE '%{$cari}%' ORDER BY tb_produk.id_produk DESC LIMIT {$start}, {$limit}");
  30.         **/
  31.  
  32.         return $query;
  33.     }
  34.  
  35.     /**
  36.      * Menghitung Data Semua Produj
  37.      *
  38.      * @param String ( search )
  39.      * @return Integer
  40.      **/
  41.     public function num_produk($cari='')
  42.     {
  43.         $query = mysqli_query($this->connection(), "SELECT * FROM tb_wajibpajak WHERE nop LIKE '%{$cari}%' OR nama LIKE '%{$cari}%'");
  44.     //$query = mysqli_query($this->connection(), "SELECT * FROM tb_produk WHERE kode_produk LIKE '%{$cari}%' OR nama_produk LIKE '%{$cari}%'");
  45.  
  46.         return $query;
  47.     }
  48.  
  49.     /**
  50.      * Menghitung Data produk detail
  51.      *
  52.      * @param Integer ( id_produk )
  53.      * @return Integer
  54.      **/
  55.     public function get($ID=0)
  56.     {
  57.         $query = mysqli_query($this->connection(), "SELECT * From tb_wajibpajak where id = '{$ID}'");
  58.  
  59.         return $query;
  60.     }
  61.  
  62.     /**
  63.      * Menambahkan Produk Baru
  64.      *
  65.      * @param Array ( Object dari form input produk)
  66.      * @return string
  67.      **/
  68.     public function add_produk(Array $data)
  69.     {
  70.      
  71.     //$tgl1 = $_POST["tgl_bayar"];
  72.     $tgl1 = date('Y-m-d');
  73.       $tgl2 = date('Y-m-d', strtotime('-1 days', strtotime($tgl1)));
  74.     //$tgl        = date('Y-m-d', $data['tgl_bayar']);
  75.  
  76.     //echo $tgl;
  77.                  
  78.         // insert Produk
  79.         $insert_produk = mysqli_query($this->connection(), "INSERT INTO tb_wajibpajak (nop, nama, alamat_objek,jml_pajak,tgl_bayar) VALUES ('{$data['nop']}', '{$data['nama']}','{$data['alamat_objek']}','{$data['jml_pajak']}','{$tgl2}')");
  80.         if( $insert_produk ) :
  81.             // buat data stok
  82.             $query_cek = mysqli_query($this->connection(), "SELECT MAX(id) AS id FROM tb_wajibpajak");
  83.             $data_produk = mysqli_fetch_object($query_cek);
  84.             /**$id_produk = (!$data_produk->id_produk) ? 1 : $data_produk->id_produk;
  85.             $insert_stok = mysqli_query($this->connection(), "INSERT INTO tb_stok (id_produk, jumlah_stok) VALUES ('{$id_produk}', '{$data['stok']}')"); **/
  86.             if( $insert_stok ) :
  87.                 header("Location:index.php?p=tambah_nop&action=true");
  88.             else :
  89.                 mysqli_query($this->connection(), "DELETE FROM tb_wajibpajak WHERE id = '{$id_produk}");
  90.                 header("Location:index.php?p=tambah_nop&gagal");
  91.             endif;
  92.         else :
  93.             header("Location:index.php?p=tambah_nop&gagal");
  94.         endif;
  95.     }
  96.  
  97.     /**
  98.      * Mengubah Data Produk
  99.      *
  100.      * @param Integer ( id_produk )
  101.      * @return string
  102.      **/
  103.     public function update_produk(Array $data, $ID = 0)
  104.     {
  105.         $tgl1 = date('Y-m-d');
  106.         $tgl2 = date('Y-m-d', strtotime('-1 days', strtotime($tgl1)));
  107.         $update_produk = mysqli_query($this->connection(), "UPDATE tb_wajibpajak SET nop = '{$data['nop']}', nama = '{$data['nama']}', alamat_objek = '{$data['alamat_objek']}',jml_pajak = '{$data['jml_pajak']}',tgl_bayar = '{$data['tgl_bayar']}' WHERE id = '{$ID}'");
  108.         /**
  109.         if( $update_produk ) :
  110.             $update_stok = mysqli_query($this->connection(), "UPDATE tb_stok SET jumlah_stok = '{$data['stok']}' WHERE id_produk = '{$ID}'");
  111.             if( $update_stok ) :
  112.                 header("Location:index.php?p=edit_produk&id={$ID}&action=true");
  113.             else :
  114.                 header("Location:index.php?p=edit_produk&id={$ID}&gagal");
  115.             endif;
  116.         else :
  117.             header("Location:index.php?p=edit_produk&id={$ID}&gagal");
  118.         endif;
  119.         **/
  120.     }
  121.  
  122.     /**
  123.      * Menghapus Data Produk
  124.      *
  125.      * @param Integer ( id_produk )
  126.      * @return string
  127.      **/
  128.     public function delete_nop($ID=0)
  129.     {
  130.         $tables = array('tb_wajibpajak');
  131.         foreach($tables as $tables) :
  132.             $delete = mysqli_query($this->connection(),"DELETE FROM {$tables} WHERE id = '{$ID}'");
  133.         endforeach;
  134.         if( $delete ) :
  135.             header("location:index.php?p=data_nop");
  136.         else :
  137.             header("location:index.php?p=data_nop&action=true");
  138.         endif;
  139.        
  140.         /** $tables = array('tb_produk', 'tb_stok');
  141.         foreach($tables as $tables) :
  142.             $delete = mysqli_query($this->connection(),"DELETE FROM {$tables} WHERE id_produk = '{$ID}'");
  143.         endforeach;
  144.         if( $delete ) :
  145.             header("location:index.php?p=data_produk");
  146.         else :
  147.             header("location:index.php?p=data_produk&action=true");
  148.         endif;**/
  149.     }
  150.  
  151.     /**
  152.      * Menampilkan Data Produk
  153.      *
  154.      * @return Array
  155.      **/
  156.     public function json()
  157.     {
  158.         $query = mysqli_query( $this->connection(), "SELECT * FROM tb_wajibpajak where id = '{$ID}'");
  159.         return $query;
  160.     }
  161.  
  162.  
  163. } // END class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement