Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/rabbithabit.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Stocks extends Admin_Controller { //this property is used for validating existing category title on call back edit category private $product_current_id; function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->model('product_m'); } function index() { //Add pagination $this->load->helper('pagination_helper'); add_pagination(base_url() . 'admin/stocks/index', $this->product_m->record_count(), 100, 4); $this->data['products'] = $this->product_m->get_all_products(100,$this->uri->segment(4)); $this->data['use_pagination'] = 'yes'; //get warehouse $this->db->select('id, name')->from('warehouse')->order_by('priority', 'ASC'); $this->data['warehouses'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/stocks/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } function get($product_id = NULL) { if($product_id == NULL) {redirect(base_url('admin/stocks'));} $this->db->select('*'); $this->db->from('products'); $this->db->where('id_products', $product_id); $this->data['product'] = $this->db->get()->row(); $this->data['use_pagination'] = 'no'; //get warehouse $this->db->select('id, name')->from('warehouse')->order_by('priority', 'ASC'); $this->data['warehouses'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/stocks/view'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } function callajax_setval_mutasi(){ $id_product_detail = $this->input->post('id_product_detail'); $query_pd = $this->db->get_where('product_details',array( "id"=>$id_product_detail, )); $id_product = $query_pd->row()->product_id; $query_stock = $this->db->get_where('stock',array( "id_product"=>$id_product, "id_product_detail"=>$id_product_detail, )); $data_output = []; $counter_stock = -1; if($query_stock->num_rows()>0){ foreach ($query_stock->result() as $key_stock) { $query_stock_mov = $this->db-> select("sm.*, s.warehouse_id")->from("stock_movement sm") ->join('stock s','sm.stock_id=s.id') ->where("sm.stock_id",$key_stock->id) ->order_by('sm.datetime','asc') ->get(); foreach ($query_stock_mov->result() as $key) { $counter_stock++; $newDate = date("d M Y h:i:s", strtotime($key->datetime)); $data_output[$counter_stock] = array( "warehouse_id" =>$key->warehouse_id, "val" => array( 'tanggal'=>$newDate, 'mutasi'=>$key->type.$key->stock_change, 'keterangan'=>$key->remark, ), ); } } // echo "<pre>"; // var_dump($data_output); exit(); } echo json_encode(array( 'data'=>$data_output, )); } function ajax_add_stock() { if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $id_product = $this->input->post('id_product'); $id_product_detail = $this->input->post('id_product_detail'); foreach ($this->input->post('stock')['stock_amount'] as $warehouse_id => $stock) { //check if current combination of product_id, $product__detail_id and $warehouse_id already exist. $this->db->select('*')->from('stock')->where('id_product', $id_product)->where('id_product_detail', $id_product_detail)->where('warehouse_id', $warehouse_id); $stock_data = $this->db->get()->result(); if(count($stock_data) == 0) { //stock data not available, so we add to new stock if($stock > 0) { $add_data = array( 'id_product' => $id_product, 'id_product_detail' => $id_product_detail, 'warehouse_id' => $warehouse_id, 'stock' => $stock ); $this->db->insert('stock', $add_data); $stock_id = $this->db->insert_id(); //update stock_movement_table $movement_data = array( 'stock_id' => $stock_id, 'type' => '+', 'stock_change' => $stock, ); //get remark $movement_data['remark'] = ''; foreach ($this->input->post('stock')['remark'] as $warehouse_id2 => $remark) { if($warehouse_id == $warehouse_id2) { $movement_data['remark'] = $remark; break; } } $this->db->insert('stock_movement', $movement_data); } } else { if($stock > 0) { //stock data already available, so we add to current stock foreach ($stock_data as $item) { $current_stock = $item->stock; $new_stock = $current_stock + $stock; $update_data = array( 'stock' => $new_stock ); $this->db->where('id_product', $id_product); $this->db->where('id_product_detail', $id_product_detail); $this->db->where('warehouse_id', $warehouse_id); $this->db->update('stock', $update_data); //get $stock_id $stock_id = $item->id; //update stock_movement_table $movement_data = array( 'stock_id' => $stock_id, 'type' => '+', 'stock_change' => $stock, ); //get remark $movement_data['remark'] = ''; foreach ($this->input->post('stock')['remark'] as $warehouse_id2 => $remark) { if($warehouse_id == $warehouse_id2) { $movement_data['remark'] = $remark; break; } } $this->db->insert('stock_movement', $movement_data); } } } } $this->db->select('stock, warehouse_id')->from('stock')->where('id_product', $id_product)->where('id_product_detail', $id_product_detail); $all_stocks = $this->db->get()->result_array(); $ajax_data = array( 'stock_data' => $all_stocks, 'id_product' => $id_product, 'id_product_detail' => $id_product_detail, 'message' => 'STOK BERHASIL DITAMBAHKAN' ); echo json_encode($ajax_data); } function ajax_minus_stock() { if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $id_product = $this->input->post('id_product'); $id_product_detail = $this->input->post('id_product_detail'); foreach ($this->input->post('stock')['stock_amount'] as $warehouse_id => $stock) { //check if current combination of product_id, $product__detail_id and $warehouse_id already exist. $this->db->select('*')->from('stock')->where('id_product', $id_product)->where('id_product_detail', $id_product_detail)->where('warehouse_id', $warehouse_id); $stock_data = $this->db->get()->result(); if(count($stock_data) > 0) { if($stock > 0) { //stock data already available, so we minus to current stock foreach ($stock_data as $item) { $current_stock = $item->stock; $new_stock = $current_stock - $stock; $update_data = array( 'stock' => $new_stock ); $this->db->where('id_product', $id_product); $this->db->where('id_product_detail', $id_product_detail); $this->db->where('warehouse_id', $warehouse_id); $this->db->update('stock', $update_data); //get $stock_id $stock_id = $item->id; //update stock_movement_table $movement_data = array( 'stock_id' => $stock_id, 'type' => '-', 'stock_change' => $stock, ); //get remark $movement_data['remark'] = ''; foreach ($this->input->post('stock')['remark'] as $warehouse_id2 => $remark) { if($warehouse_id == $warehouse_id2) { $movement_data['remark'] = $remark; break; } } $this->db->insert('stock_movement', $movement_data); } } } } $this->db->select('stock, warehouse_id')->from('stock')->where('id_product', $id_product)->where('id_product_detail', $id_product_detail); $all_stocks = $this->db->get()->result_array(); $ajax_data = array( 'stock_data' => $all_stocks, 'id_product' => $id_product, 'id_product_detail' => $id_product_detail, 'message' => 'STOK BERHASIL DIKURANGI' ); echo json_encode($ajax_data); } public function search_brand() { if(!isset($_POST['search_brand'])) { show_404(); } //get product name from form $this->data['brand_id'] = $this->input->post('brand', TRUE); if ($this->data['brand_id'] != '') { //get all brands which only consist this brand_id $this->db->select('*')->from('products')->where('brand_id', (int) $this->data['brand_id']); $this->db->order_by('title', 'ASC'); $this->data['products'] = $this->db->get()->result(); } else { //get all brands $this->db->select('*')->from('products'); $this->db->order_by('priority', 'ASC'); $this->data['products'] = $this->db->get()->result(); } //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function search_category() { if(!isset($_POST['search_category'])) { show_404(); } //get product name from form $this->data['category_id'] = $this->input->post('category', TRUE); if ($this->data['category_id'] == '') { $this->db->select('*')->from('products')->order_by('priority', 'ASC'); $this->data['products'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } else { $this->db->select('*'); $this->db->from('products'); $this->db->join('category_product', 'category_product.id_product = products.id_products'); $this->db->where('category_product.id_category', (int) $this->data['category_id']); $this->data['products'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } } }