ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/controllers/ |
Current File : //home2/selectio/www/mm-tailor-billing/app/controllers/Material_usage.php |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Material_usage extends MY_Controller { public function __construct() { parent::__construct(); if (!$this->loggedIn) { redirect('login'); } $this->load->library('form_validation'); $this->load->model('material_usage_model'); } public function material_usage_delete($id = null, $material = null, $qty = null) { if (DEMO) { $this->session->set_flashdata('error', lang('disabled_in_demo')); redirect($_SERVER['HTTP_REFERER'] ?? 'welcome'); } if (!$this->Admin) { $this->session->set_flashdata('error', lang('access_denied')); redirect('material_usage'); } if ($this->input->get('id')) { $id = $this->input->get('id'); $material = $this->input->get('material'); $qty = $this->input->get('qty'); } if ($this->material_usage_model->materialUsageDelete($id,$material,$qty)) { $this->session->set_flashdata('message', lang('material_usage_deleted')); redirect('material_usage'); } } public function add() { if (!$this->session->userdata('store_id')) { $this->session->set_flashdata('warning', lang('please_select_store')); redirect('stores'); } if ($this->input->post('add_material_usage')) { $date=array(); $material=array(); $unit=array(); $quantity=array(); $remarks=array(); $date = $this->input->post('date'); $material = $this->input->post('material'); $unit = $this->input->post('unit'); $quantity = $this->input->post('quantity'); $remarks = $this->input->post('remarks'); $created_by = $this->session->userdata('user_id'); $this->material_usage_model->addMaterialUsageRowBased($date,$material,$quantity,$remarks,$created_by,$unit); $this->session->set_flashdata('message', lang('material_usage_added')); redirect('material_usage'); } else { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['product_material'] = $this->site->getAllServiceProducts(); $this->data['user_data'] = $this->material_usage_model->getAllStaff(); $this->data['units'] = $this->material_usage_model->getAllUnits(); $this->data['page_title'] = lang('add_material_usage'); $bc = [['link' => site_url('material_usage'), 'page' => lang('material_usage')], ['link' => site_url('material_usage/add'), 'page' => lang('material_usage')], ['link' => '#', 'page' => lang('add_material_usage')]]; $meta = ['page_title' => lang('add_material_usage'), 'bc' => $bc]; $this->page_construct('material_usage/add', $this->data, $meta); } } public function edit($id = null) { if (!$this->session->userdata('store_id')) { $this->session->set_flashdata('warning', lang('please_select_store')); redirect('stores'); } if ($this->input->post('edit_material_usage')) { $date = $this->input->post('date'); $id = $this->input->post('id'); $material = $this->input->post('material'); $unit = $this->input->post('unit'); $quantity = $this->input->post('quantity'); $remarks = $this->input->post('remarks'); $created_by = $this->session->userdata('user_id'); $already_updated_qty = $this->input->post('already_updated_qty'); $this->material_usage_model->UpdateMaterialUsage($date,$material,$quantity,$remarks,$created_by,$unit,$already_updated_qty,$id); $this->session->set_flashdata('message', lang('material_usage_updated')); redirect('material_usage'); } else { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['product_material'] = $this->site->getAllServiceProducts(); $this->data['units'] = $this->material_usage_model->getAllUnits(); $this->data['material_usage'] = $this->material_usage_model->getMaterialUsageByID($id); $this->data['page_title'] = lang('edit_material_usage'); $bc = [['link' => site_url('material_usage'), 'page' => lang('material_usage')], ['link' => site_url('material_usage/edit'), 'page' => lang('material_usage')], ['link' => '#', 'page' => lang('edit_material_usage')]]; $meta = ['page_title' => lang('edit_material_usage'), 'bc' => $bc]; $this->page_construct('material_usage/edit', $this->data, $meta); } } /* ------------------ Unit Section Starts Here --------------------- */ public function unit_add() { if (!$this->session->userdata('store_id')) { $this->session->set_flashdata('warning', lang('please_select_store')); redirect('material_usage'); } if ($this->input->post('add_units')) { $name = $this->input->post('name'); $description = $this->input->post('description'); $this->material_usage_model->addUnits($name,$description); $this->session->set_flashdata('message', lang('units_added')); redirect('material_usage/units'); } else { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['product_material'] = $this->site->getAllServiceProducts(); $this->data['categories'] = $this->site->getAllCategories(); $this->data['user_data'] = $this->material_usage_model->getAllStaff(); $this->data['page_title'] = lang('add_material_usage'); $bc = [['link' => site_url('material_usage'), 'page' => lang('material_usage')], ['link' => site_url('material_usage/unit_add'), 'page' => lang('material_usage')], ['link' => '#', 'page' => lang('add_material_usage')]]; $meta = ['page_title' => lang('add_units'), 'bc' => $bc]; $this->page_construct('material_usage/unit_add', $this->data, $meta); } } public function get_category_products() { $category = $this->input->get('category'); $data = $this->material_usage_model->getcategoryBasedProducts($category); $content=''; if($data){ foreach($data as $d){ $content.='<option value="'.$d->id.'">'.$d->name.'</option>'; } }else{ $content.='<option value="">No Data Available</option>'; } echo $content; } public function unit_edit($id = null) { if (!$this->Admin) { $this->session->set_flashdata('error', lang('access_denied')); redirect('pos'); } if ($this->input->get('id')) { $id = $this->input->get('id'); } $this->form_validation->set_rules('name', lang('name'), 'required'); if ($this->form_validation->run() == true) { $data = ['name' => $this->input->post('name'), 'description' => $this->input->post('description')]; } if ($this->form_validation->run() == true && $this->material_usage_model->updateUnits($id, $data)) { $this->session->set_flashdata('message', lang('units_updated')); redirect('material_usage/units'); } else { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['units'] = $this->site->getUnitsByID($id); $this->data['page_title'] = lang('new_category'); $bc = [['link' => site_url('material_usage'), 'page' => lang('material_usage')], ['link' => '#', 'page' => lang('edit_units')]]; $meta = ['page_title' => lang('edit_units'), 'bc' => $bc]; $this->page_construct('material_usage/unit_edit', $this->data, $meta); } } public function units() { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['material_usage'] = $this->site->getAllCategories(); $this->data['page_title'] = lang('units'); $bc = [['link' => '#', 'page' => lang('units')]]; $meta = ['page_title' => lang('units'), 'bc' => $bc]; $this->page_construct('material_usage/units', $this->data, $meta); } public function get_units() { $this->load->library('datatables'); $this->datatables->select('id, name, description, conf1, status'); $this->datatables->from('units'); //$this->datatables->edit_column('unit', "<span class='btn btn-info btn-xs'>$4</span>", 'id, date, user, unit_name'); $this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><a href='" . site_url('material_usage/unit_edit/$1') . "' title='" . lang('edit_units') . "' class='tip btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> <a href='" . site_url('material_usage/unit_delete/$1') . "' onClick=\"return confirm('" . lang('alert_x_category') . "')\" title='" . lang('delete_units') . "' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></a></div></div>", 'id, image, code, name'); $this->datatables->unset_column('id'); echo $this->datatables->generate(); } public function unit_delete($id = null) { if (DEMO) { $this->session->set_flashdata('error', lang('disabled_in_demo')); redirect($_SERVER['HTTP_REFERER'] ?? 'welcome'); } if (!$this->Admin) { $this->session->set_flashdata('error', lang('access_denied')); redirect('material_usage'); } if ($this->input->get('id')) { $id = $this->input->get('id'); } if ($this->material_usage_model->deleteUnits($id)) { $this->session->set_flashdata('message', lang('units_deleted')); redirect('material_usage/units'); } } /* ------------------ Unit Section Ends Here --------------------- */ public function delete($id = null) { if (DEMO) { $this->session->set_flashdata('error', lang('disabled_in_demo')); redirect($_SERVER['HTTP_REFERER'] ?? 'welcome'); } if (!$this->Admin) { $this->session->set_flashdata('error', lang('access_denied')); redirect('pos'); } if ($this->input->get('id')) { $id = $this->input->get('id'); } if ($this->extra_option_model->deleteExtraOption($id)) { $this->session->set_flashdata('message', lang('category_deleted')); redirect('extra_option'); } } public function get_material_usage() { /*IF(unit="1","KG",IF(unit="2","Quantity","Undefined")) as unit_name, IF(tec_material_usage.unit=tec_units.id,units.name,unit) as unit_name CONCAT(' . $this->db->dbprefix('users') . ".first_name, ' ', " . $this->db->dbprefix('users') . '.last_name) as user_name,*/ $material = $this->input->get('material') ? $this->input->get('material') : NULL; $start_date = $this->input->get('start_date') ? $this->input->get('start_date') : NULL; $end_date = $this->input->get('end_date') ? $this->input->get('end_date') : NULL; $date = $this->input->get('date') ? $this->input->get('date') : NULL; $this->load->library('datatables'); $this->datatables->select('material_usage.id, DATE_FORMAT(date, "%d-%m-%Y") as date, user, material, unit, qty, created_by, remarks, IF(tec_material_usage.material=tec_products.id,products.name,code) as material_name'); $this->datatables->from('material_usage'); $this->datatables->join('products', 'material_usage.material = products.id','inner'); /*$this->datatables->join('units', 'material_usage.unit = units.id','inner'); $this->datatables->join('users', 'material_usage.user = users.id','inner');*/ //$this->datatables->edit_column('unit', "<span class='btn btn-info btn-xs'>$4</span>", 'id, date, user, unit_name'); //$this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><a href='" . site_url('extra_option/edit/$1') . "' title='" . lang('edit_extra_option') . "' class='tip btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> <a href='" . site_url('extra_option/delete/$1') . "' onClick=\"return confirm('" . lang('alert_x_category') . "')\" title='" . lang('delete_category') . "' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></a></div></div>", 'id, image, code, name'); $this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><a href='" . site_url('material_usage/edit/$1') . "' title='" . lang('edit_material_usage') . "' class='tip btn btn-info btn-xs'><i class='fa fa-edit'></i></a> <a href='" . site_url('material_usage/expense_note/$1') . "' title='Material Usage View' class='tip btn btn-primary btn-xs' data-toggle='ajax-modal'><i class='fa fa-file-text-o'></i></a><a href='" . site_url('material_usage/material_usage_delete/$1/$2/$3') . "' onClick=\"return confirm('" . lang('alert_x_category') . "')\" title='Delete Material Usage' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></a></div></div>", 'id, material, qty'); if($start_date) { $this->datatables->where('date >=', $start_date); } if($end_date) { $this->datatables->where('date <=', $end_date); } if($material) { $this->datatables->where('material', $material); } if($date) { $this->datatables->where('date >=', $date); } if($date) { $this->datatables->where('date <=', $date); } $this->datatables->unset_column('id'); echo $this->datatables->generate(); } public function index() { $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error')); $this->data['products'] = $this->site->getAllProducts(); $this->data['material_usage'] = $this->site->getAllCategories(); $this->data['page_title'] = lang('material_usage'); $bc = [['link' => '#', 'page' => lang('material_usage')]]; $meta = ['page_title' => lang('material_usage'), 'bc' => $bc]; $this->page_construct('material_usage/index', $this->data, $meta); } public function expense_note($id = null) { if (!$this->Admin) { if ($expense->created_by != $this->session->userdata('user_id')) { $this->session->set_flashdata('error', lang('access_denied')); redirect($_SERVER['HTTP_REFERER'] ?? 'pos'); } } $expense = $this->material_usage_model->getMaterialUsageByID($id); $this->data['user'] = $this->site->getUser($expense->created_by); $this->data['expense'] = $expense; $this->data['page_title'] = $this->lang->line('expense_note'); $this->load->view($this->theme . 'material_usage/expense_note', $this->data); } /*public function get_sub_category() { $category = $this->input->get('category'); $data = $this->site->getAllMmSubCategory($category); $content=''; if($data){ foreach($data as $d){ //$content.='<option value="'.$d->id.'">'.$d->sub_name.'</option>'; $content.='<option value="'.$d->id.'">'.$d->sub_name.'</option>'; } }else{ $content.='<option value="">No Data Available</option>'; } echo $content; }*/ public function select_unit() { $material = $this->input->get('material'); $data = $this->material_usage_model->getAllmaterial($material); $content=''; if($data){ foreach($data as $d){ $content.='<option value="'.$d->units.'">'.$d->unit_name.'</option>'; //$content.='<input type="text" value="'.$d->units.'>'; } }else{ $content.='<option value="">No Data Available</option>'; } echo $content; } }