https://t.me/RX1948
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/laciasmara.com/public_html/shop/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/laciasmara.com/public_html/shop/application/controllers/admin/Warehouses.php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');



class Warehouses extends Admin_Controller

{



	//this property is used for validating existing page title on call back edit page

	private $warehouse_current_id = NULL;

	private $warehouse_current_priority = NULL;



	function __construct()

	{

		parent::__construct();

		$this->load->model('warehouse_m');

	}



	//this is to list all warehouse 

	public function index()

	{



		//Add pagination

		$this->load->helper('pagination_helper');

		add_pagination(base_url() . 'admin/warehouse/index', $this->warehouse_m->record_count(), 20, 4);



		$this->data['warehouses'] = $this->warehouse_m->get_all_warehouse(

			20,

			$this->uri->segment(4)

		);



		//load view

		$this->data['subview'] = 'admin/warehouse/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 manage()

	{

		$data['userdata'] = $this->session->userdata();

		$data['title'] = 'Daftar Gudang | Laciasmara';

		$data['warehouses'] = $this->warehouse_m->fetch_all_warehouses();



		$this->load->view('admin_new/layouts/header', $data);

		$this->load->view('admin_new/warehouses/manage');

		$this->load->view('admin_new/layouts/footer');

	}



	public function add_warehouse()

	{

		$data['userdata'] = $this->session->userdata();

		$data['title'] = 'Tambah Gudang | Laciasmara';

		$data['provinces'] = $this->getProvinces();



		$this->load->view('admin_new/layouts/header', $data);

		$this->load->view('admin_new/warehouses/add');

		$this->load->view('admin_new/layouts/footer');

	}



	public function edit_warehouse($warehouse_id)

	{

		$data['userdata'] = $this->session->userdata();

		$data['title'] = 'Ubah Gudang | Laciasmara';

		$data['provinces'] = $this->getProvinces();

		$data['warehouse'] = $this->warehouse_m->fetch_warehouse_by_id($warehouse_id);

		$this->load->view('admin_new/layouts/header', $data);

		$this->load->view('admin_new/warehouses/edit');

		$this->load->view('admin_new/layouts/footer');

	}



	public function create_warehouse()

	{

		$this->db->trans_start();

		$name = $this->input->post('name', true);

		$alias = $this->input->post('alias', true);

		$address = $this->input->post('address', true);

		$phone = $this->input->post('phone', true);

		$warehouse_type = 'normal';

		$province_id = (int) $this->input->post('province_id', true);

		$district_id = (int) $this->input->post('district_id', true);

		$subdistrict_id = (int) $this->input->post('subdistrict_id', true);



		$last_priority = $this->db->select_max('priority')->get('warehouse')->row()->priority;

		$new_priority = $last_priority !== null ? $last_priority + 1 : 1;



		try {

			$data = array(

				'name' => $name,

				'alias' => $alias,

				'address' => $address,

				'phone' => $phone,

				'warehouse_type' => $warehouse_type,

				'id_province' => $province_id,

				'id_district' => $district_id,

				'id_subdistrict' => $subdistrict_id,

				'priority' => $new_priority,

				'create_date' => date('Y-m-d H:i:s'),

			);

			$this->db->insert('warehouse', $data);



			if ($this->db->trans_status() === false) {

				throw new Exception('Database error occurred');

			}

			$this->db->trans_commit();

			// Set flashdata dan redirect

			$this->session->set_flashdata('message_type', 'success');

			$this->session->set_flashdata('message', 'Gudang berhasil ditambahkan!');

			redirect(base_url('admin/stocks/warehouses'));

		} catch (Exception $e) {

			$this->db->trans_rollback();



			// Set flashdata untuk error dan redirect

			$this->session->set_flashdata('message_type', 'error');

			$this->session->set_flashdata('message', $e->getMessage());

			redirect(base_url('admin/stocks/wareouses/add'));

		}

	}



	public function update_warehouse($warehouse_id)

	{

		$this->db->trans_start();



		$name = $this->input->post('name', true);

		$alias = $this->input->post('alias', true);

		$address = $this->input->post('address', true);

		$phone = $this->input->post('phone', true);

		$province_id = (int) $this->input->post('province_id', true);

		$district_id = (int) $this->input->post('district_id', true);

		$subdistrict_id = (int) $this->input->post('subdistrict_id', true);



		try {

			// Validasi warehouse_id exists

			$existing_warehouse = $this->db->get_where('warehouse', array('id' => $warehouse_id))->row();

			if (!$existing_warehouse) {

				throw new Exception('Gudang tidak ditemukan.');

			}



			$data = array(

				'name' => $name,

				'alias' => $alias,

				'address' => $address,

				'phone' => $phone,

				'id_province' => $province_id,

				'id_district' => $district_id,

				'id_subdistrict' => $subdistrict_id,

			);



			$this->db->where('id', $warehouse_id);

			$this->db->update('warehouse', $data);



			if ($this->db->trans_status() === false) {

				throw new Exception('Database error occurred');

			}



			$this->db->trans_commit();



			// Set flashdata dan redirect

			$this->session->set_flashdata('message_type', 'success');

			$this->session->set_flashdata('message', 'Gudang berhasil diperbarui!');

			redirect(base_url('admin/stocks/warehouses'));

		} catch (Exception $e) {

			$this->db->trans_rollback();



			// Set flashdata untuk error dan redirect kembali ke form edit

			$this->session->set_flashdata('message_type', 'error');

			$this->session->set_flashdata('message', $e->getMessage());

			redirect(base_url('admin/warehouses/edit/' . $warehouse_id));

		}

	}



	public function delete_warehouse($warehouse_id)

	{

		try {

			// Mulai transaksi

			$this->db->trans_start();



			$this->db->where('warehouse_id', $warehouse_id);

			$this->db->delete('stock');



			// Hapus data dari tabel warehouse

			$this->db->where('id', $warehouse_id);

			$this->db->delete('warehouse');



			if ($this->db->trans_status() === false) {

				throw new Exception('Gagal menghapus data gudang.');

			}



			$this->db->trans_commit();



			// Set flashdata sukses

			$this->session->set_flashdata('message_type', 'success');

			$this->session->set_flashdata('message', 'Gudang berhasil dihapus.');

		} catch (Exception $e) {

			$this->db->trans_rollback();



			// Set flashdata error

			$this->session->set_flashdata('message_type', 'error');

			$this->session->set_flashdata('message', $e->getMessage());

		}



		// Redirect kembali ke halaman warehouse

		redirect(base_url('admin/stocks/warehouses'));

	}





	private function getProvinces()

	{

		return $this->db->select('rajaongkir_province_id as id, province as name')

			->from('indonesia_provinces')

			->order_by('province', 'ASC')

			->get()

			->result();

	}



	public function edit($id = NULL)

	{



		if ($id == NULL) {

			if (($this->data['membership_type'] == "starter" && $this->data['jml_gudang'] >= 1) || ($this->data['membership_type'] == "business" && $this->data['jml_gudang'] >= 3) || (($this->data['membership_type'] == "enterprise" || $this->data['membership_type'] == "free trial") && $this->data['jml_gudang'] >= 5)) {

				redirect('admin/warehouses');

			}

			//create new warehouse



		} else {

		}



		//check if id exist. If not exist, show 404.

		$count = $this->warehouse_m->count_exist($id);



		if ($count == 0) {

			//page not exist

			show_404();

		}



		$this->warehouse_current_id = (int) $id;



		$this->db->select('*')->from('warehouse')->where('id', $id);

		$this->data['warehouse'] = $this->db->get()->row();



		$this->warehouse_current_priority = $this->data['warehouse']->priority;



		//get all provinces data from provinces table

		$this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC');

		$this->data['provinces'] = $this->db->get()->result();



		//get all countries data from countries table

		$this->db->select('*')->from('countries')->order_by('id_countries', 'ASC');

		$this->data['countries'] = $this->db->get()->result();



		//get current province

		$current_province_id = $this->data['warehouse']->id_province;

		$this->data['current_province_id'] = $current_province_id;



		//get district lists

		$this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $current_province_id);

		$this->data['district_lists'] = $this->db->get()->result();



		$current_district_id = $this->data['warehouse']->id_district;

		$this->data['current_district_id'] = $current_district_id;



		//get all initial subdistricts lists

		$this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $current_district_id);

		$this->data['subdistrict_lists'] = $this->db->get()->result();



		$current_subdistrict_id = $this->data['warehouse']->id_subdistrict;

		$this->data['current_subdistrict_id'] = $current_subdistrict_id;



		$this->warehouse_current_id = (int) $id;



		//validation check in action 

		$config = $this->warehouse_m->rules;



		$this->load->library('form_validation');

		$this->form_validation->set_rules($config);

		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');



		if ($this->form_validation->run($this) == TRUE) {



			$data = $this->table_data_processing();



			$this->warehouse_m->edit_page($id, $data);



			//add subdistrict_2hourdelivery for warehouse destination

			$subdistrict_rajaongkir_id_array_2hourdelivery = $this->input->post('subdistrict_2hourdelivery');

			$subdistrict_rajaongkir_id_array_1dayservice = $this->input->post('subdistrict_1dayservice');



			//remove all entry from database..

			$this->db->where('warehouse_id', $id);

			$this->db->delete('shipment_method_express');



			if ($subdistrict_rajaongkir_id_array_2hourdelivery != NULL) {

				foreach ($subdistrict_rajaongkir_id_array_2hourdelivery as $key => $item) {

					$data1 = array(

						'warehouse_id' => $id,

						'twohour_subdistrict_id' => $item

					);

					$this->db->insert('shipment_method_express', $data1);

				}

			}



			if ($subdistrict_rajaongkir_id_array_1dayservice != NULL) {

				foreach ($subdistrict_rajaongkir_id_array_1dayservice as $key => $item) {

					$data2 = array(

						'warehouse_id' => $id,

						'oneday_subdistrict_id' => $item

					);

					$this->db->insert('shipment_method_express', $data2);

				}

			}



			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Warehouse Edit Successful</p>');



			redirect('admin/warehouses/edit/' . $id);

		}



		//get current subdistricts for 2hour and 1day delivery

		$this->db->select('twohour_subdistrict_id')->from('shipment_method_express')->where('warehouse_id', $id);

		$this->data['current_2hour_subdistrict_id'] = $this->db->get()->result();



		$this->db->select('oneday_subdistrict_id')->from('shipment_method_express')->where('warehouse_id', $id);

		$this->data['current_1day_subdistrict_id'] = $this->db->get()->result();



		$this->data['subview'] = 'admin/warehouse/edit';

		$this->load->view('admin/templates/header', $this->data_header);

		$this->load->view('admin/_layout_main', $this->data);

		$this->load->view('admin/templates/footer');

	}



	//to add a new page 

	public function add()

	{



		$this->data['warehouse'] = $this->warehouse_m->get_new();



		//get ordering number and display at add form

		$this->db->select_max('priority')->from('warehouse');

		$current_priority = $this->db->get()->row()->priority;

		if ($current_priority == NULL) {

			$this->data['warehouse']->priority = 1;

		} else {

			$this->data['warehouse']->priority = $current_priority + 1;

		}



		//get all province data from RajaOngkir.com API

		//$this->data['provinces'] = get_rajaongkir_data('province'); //get from helper file



		//get all provinces data from provinces table

		$this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC');

		$this->data['provinces'] = $this->db->get()->result();



		//get all countries data from RajaOngkir.com API

		//$this->data['countries'] = get_rajaongkir_data('v2/internationalDestination'); //get from helper file



		//get all countries data from countries table

		$this->db->select('*')->from('countries')->order_by('id_countries', 'ASC');

		$this->data['countries'] = $this->db->get()->result();



		//validation in action

		$config = $this->warehouse_m->rules;



		$this->load->library('form_validation');

		$this->form_validation->set_rules($config);

		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');



		if ($this->form_validation->run($this) == TRUE) {



			$data = $this->table_data_processing();



			$warehouse_id = $this->warehouse_m->add_warehouse($data);



			//add subdistrict_2hourdelivery for warehouse destination

			$subdistrict_rajaongkir_id_array_2hourdelivery = $this->input->post('subdistrict_2hourdelivery');

			$subdistrict_rajaongkir_id_array_1dayservice = $this->input->post('subdistrict_1dayservice');



			if (!empty($subdistrict_rajaongkir_id_array_2hourdelivery)) {

				foreach ($subdistrict_rajaongkir_id_array_2hourdelivery as $key => $item) {

					$data = array(

						'warehouse_id' => $warehouse_id,

						'twohour_subdistrict_id' => $item

					);

					$this->db->insert('shipment_method_express', $data);

				}

			}



			if (!empty($subdistrict_rajaongkir_id_array_1dayservice)) {

				foreach ($subdistrict_rajaongkir_id_array_1dayservice as $key => $item) {

					$data = array(

						'warehouse_id' => $warehouse_id,

						'oneday_subdistrict_id' => $item

					);

					$this->db->insert('shipment_method_express', $data);

				}

			}



			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Warehouse Add Successful</p>');



			redirect('admin/warehouses');

		}



		$this->data['subview'] = 'admin/warehouse/edit';

		$this->load->view('admin/templates/header', $this->data_header);

		$this->load->view('admin/_layout_main', $this->data);

		$this->load->view('admin/templates/footer');

	}









	//to delete a page

	public function delete($id)

	{



		//check if id exist. If not exist, show 404.

		$count = $this->warehouse_m->count_exist($id);



		if ($count == 0) {

			//page not exist  

			show_404();

		}



		//delete page

		$this->db->where('id', $id);

		$this->db->delete('warehouse');



		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Warehouse Delete Successful</p>');

		redirect('admin/warehouses');

	}



	private function table_data_processing()

	{



		$data = array(

			'name' => $this->security->xss_clean($this->input->post('name')),

			'alias' => $this->security->xss_clean($this->input->post('alias')),

			'address' => $this->security->xss_clean($this->input->post('address')),

			'phone' => $this->security->xss_clean($this->input->post('phone')),

			'warehouse_type' => $this->input->post('warehouse_type'),

			'priority' => $this->input->post('priority')

		);



		$data['id_province'] = (int) $this->input->post('province');

		$data['id_district'] = (int) $this->input->post('district');

		$data['id_subdistrict'] = (int) $this->input->post('subdistrict');



		//$data['id_country'] =  0;

		//$data['country'] =  'Indonesia';



		//get province name

		/* $this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', (int) $this->input->post('province'));

		$data['province'] = $this->db->get()->row()->province;



		//get district name

		$this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', (int) $this->input->post('district'));

		$data['district'] = $this->db->get()->row()->district;

		

		//get subdistrict name

		$this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', (int) $this->input->post('subdistrict'));

		$data['subdistrict'] = $this->db->get()->row()->subdistrict; */



		return $data;

	}





	//callback function validation priority

	//make it private by adding _

	public function _cek_existing_priority($str)

	{



		$this->db->select('id');

		$this->db->from('warehouse');

		$this->db->where('priority', (int) $str);



		if ($this->warehouse_current_id != NULL) {

			$this->db->where('priority !=', $this->warehouse_current_priority);

		}

		$count_priority = $this->db->get()->num_rows();



		if ($count_priority != 0) {

			$this->form_validation->set_message('_cek_existing_priority', 'Priority must be unique!');

			return FALSE;

		} else {

			return TRUE;

		}

	}

}


https://t.me/RX1948 - 2025