Advertisement
mike_lauw

stockout_model

Dec 15th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2.  
  3. class stock_out_m extends CI_Model
  4. {
  5.     public function get($id = null)
  6.     {
  7.         $this->db->from('t_stock');
  8.         if ($id != null) {
  9.             $this->db->where('stock_id', $id);
  10.         }
  11.         $query = $this->db->get();
  12.         return $query;
  13.     }
  14.  
  15.     public function del($id)
  16.     {
  17.         $this->db->where('stock_id', $id);
  18.         $this->db->delete('t_stock');
  19.     }
  20.  
  21.     public function get_stock_out()
  22.     {
  23.         $this->db->select('t_stock.stock_id,p_item.barcode, p_item.name as item_name
  24.        ,qty,date,detail, p_item.item_id, customer.nama as customer_nama');
  25.         $this->db->from('t_stock');
  26.         $this->db->join('p_item', 't_stock.item_id = p_item.item_id');
  27.         $this->db->join('customer', 't_stock.customer_id = customer.customer_id', 'left');
  28.         $this->db->where('type', 'out');
  29.         $this->db->order_by('stock_id', 'desc');
  30.         $query = $this->db->get();
  31.         return $query;
  32.     }
  33.     public function add_stock_out($post)
  34.     {
  35.         $params = [
  36.             'item_id' => $post['item_id'],
  37.             'type' => 'out',
  38.             'detail' => $post['detail'],
  39.             'qty' => $post['qty'],
  40.             'customer_id' => $post['customer'] == '' ? null : $post['customer'],
  41.             'date' => $post['date'],
  42.             'user_id' => $this->session->userdata('userid'),
  43.         ];
  44.         $this->db->insert('t_stock', $params);
  45.     }
  46.  
  47.     //Tambahan get_sisa $itemname
  48.  
  49.     public function get_sisa($itemname)
  50.     {
  51.         $this->db->select('t_stock.stock_id,p_item.barcode, p_item.name as item_name
  52.        ,qty,date,detail, p_item.item_id , customer.nama as customer_nama');
  53.         $this->db->from('t_stock');
  54.         $this->db->join('p_item', 't_stock.item_id = p_item.item_id');
  55.         $this->db->join('customer', 't_stock.customer_id = customer.customer_id', 'left');
  56.         $this->db->where('type', 'out');
  57.         $this->db->where('p_item.name', $itemname);
  58.         $this->db->order_by('stock_id', 'desc');
  59.         $query = $this->db->get();
  60.         return $query->row();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement