mudzlam

controller

Sep 21st, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.70 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Insertdo extends CI_Controller {
  4.     private $limit = 10;
  5.    
  6.     function __construct()
  7.     {
  8.         parent::__construct();
  9.         $this->is_logged_in();
  10.         $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
  11.         $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  12.         $this->output->set_header('Pragma: no-chace');
  13.         $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  14.        
  15.         // load model
  16.         $this->load->model('minsertdo');
  17.     }
  18.    
  19.     function cekLevel()
  20.     {
  21.         if($this->session->userdata('level') == "admin")
  22.         {
  23.             $this->load->view('vapp_header');
  24.             $this->load->view('vapp_nav_menu');
  25.         } else {
  26.             $this->load->view('vapp_header');
  27.             $this->load->view('vapp_nav_menu2');
  28.         }      
  29.     }
  30.    
  31.     function index($offset = 0)
  32.     {
  33.         $data['title']  = "Insert DO";
  34.        
  35.         // offset
  36.         $uri_segment = 4;
  37.         $offset = $this->uri->segment($uri_segment);
  38.        
  39.         // load data
  40.         $cfields = $this->minsertdo->listData($this->limit, $offset)->result();
  41.        
  42.         // generate pagination
  43.         $this->load->library('pagination');
  44.        
  45.         $config['base_url']     = site_url('erp/insertdo/index/');
  46.         $config['total_rows']   = $this->minsertdo->count_allData();
  47.         $config['per_page']     = $this->limit;
  48.         $config['uri_segment']  = $uri_segment;
  49.         $this->pagination->initialize($config);
  50.         $data['pagination'] = $this->pagination->create_links();
  51.        
  52.         // generate table data
  53.         $this->load->library('table');
  54.         $this->table->set_empty("&nbsp;");
  55.         $this->table->set_heading('No', 'NO POLISI', 'NAMA DRIVER', 'PERUSAHAAN', 'TUJUAN', 'TGL. UANG JALAN', 'JML UANG JALAN', '');
  56.         $i = 0 + $offset;
  57.         foreach ($cfields as $cf)
  58.         {
  59.             $this->table->add_row(++$i, $cf->no_polisi, $cf->nama_driver, $cf->name_partner, $cf->name_location, $cf->tgl_uj, $cf->jml_uj,
  60.                 anchor('erp/insertdo/new_insertdo/'.$cf->id_timeline,'Insert DO',array('class'=>'delete'))
  61.             );
  62.  
  63.         }
  64.         $data['table'] = $this->table->generate();
  65.        
  66.         // load view
  67.         $this->cekLevel();
  68.         $this->load->view('vinsert_do/vinsert_do',$data);
  69.         $this->load->view('vapp_right_menu');
  70.         $this->load->view('vapp_footer');
  71.     }
  72.    
  73. /* Add Insert DO
  74. --------------------------------------------------------------------------*/   
  75.     function new_insertdo($id_timeline)
  76.     {
  77.         // set common properties
  78.         $data['back']       = anchor('erp/insertdo','Back',array('class'=>'back'));
  79.         $data['proses']     = site_url('erp/insertdo/act_insertdo');
  80.         $data['title']      = 'Insert DO';
  81.         $data['message']    = '';
  82.         $data['category'] = $this->minsertdo->get_partner();
  83.                
  84.         $cf = $this->minsertdo->get_by_id($id_timeline)->row();
  85.        
  86.         // prefill form values
  87.         $this->form_data = new stdClass();
  88.         $this->form_data->id_timeline = $id_timeline;
  89.         $this->form_data->no_polisi = $cf->no_polisi;
  90.         $this->form_data->id_driver = $cf->id_driver;
  91.         $this->form_data->id_partner = $cf->id_partner;
  92.         $this->form_data->id_class_partner = $cf->id_class_partner;
  93.         $this->form_data->tgl_uj = $cf->tgl_uj;
  94.         $this->form_data->jml_uj = $cf->jml_uj;
  95.         $this->form_data->tgl_ido = $cf->tgl_ido;
  96.         $this->form_data->no_do = $cf->no_do;
  97.         $this->form_data->jml_muatan = $cf->jml_muatan;
  98.            
  99.         // load view
  100.         $this->cekLevel();
  101.         $this->load->view('vinsert_do/vnewinsert_do',$data);
  102.         $this->load->view('vapp_right_menu');      
  103.         $this->load->view('vapp_footer');
  104.     }
  105.  
  106.     function src_insertdo($id_timeline)
  107.     {
  108.         $data['src_do'] = $this->minsertdo->get_by_id($id_timeline)->row();
  109.         $this->load->library('table');
  110.         $this->table->set_empty("&nbsp;");
  111.         $this->table->set_heading('NO POLISI', 'NAMA DRIVER', 'PERUSAHAAN', 'TUJUAN', 'TGL. UANG JALAN', 'JML UANG JALAN', '');
  112.         $src_do = $this->minsertdo->get_by_id($id_timeline)->row();
  113.  
  114.         $this->table->add_row($src_do->no_polisi, $src_do->nama_driver, $src_do->name_partner, $src_do->name_location, $src_do->tgl_uj, $src_do->jml_uj,
  115.                 anchor('erp/insertdo/new_insertdo/'.$src_do->id_timeline,'Insert DO',array('class'=>'delete'))
  116.             );
  117.  
  118.         $data['show_src_do']= $this->table->generate();
  119.  
  120.         $data['title']      = 'Insert DO';
  121.         $this->cekLevel();
  122.         $this->load->view('vinsert_do/vsrc_insert_do', $data);
  123.         $this->load->view('vapp_right_menu');      
  124.         $this->load->view('vapp_footer');
  125.     }
  126.    
  127.     function act_insertdo()
  128.     {
  129.         $data['back']       = anchor('erp/insertdo','Back',array('class'=>'back'));
  130.         $data['proses']     = site_url('erp/insertdo/act_insertdo');
  131.         $data['title']      = 'Insert DO';
  132.         $data['message']    = '';
  133.         $data['category'] = $this->minsertdo->get_partner();
  134.        
  135.  
  136.         // set validation properties
  137.         $this->_set_rules();
  138.         $this->_set_fields();      
  139.        
  140.         // run validation
  141.         if ($this->form_validation->run() == FALSE)
  142.         {
  143.             $data['message'] = '';
  144.         }
  145.         else
  146.         {
  147.             // save data
  148.             $id = $this->input->post('id_timeline');
  149.             $updatedata = array(                       
  150.                         'no_polisi' => $this->input->post('no_polisi'),
  151.                         'id_driver' => $this->input->post('id_driver'),
  152.                         'id_partner' => $this->input->post('id_partner'),
  153.                         'id_class_partner' => $this->input->post('id_class_partner'),
  154.                         'tgl_uj' => $this->input->post('tgl_uj'),
  155.                         'jml_uj' => $this->input->post('jml_uj'),
  156.                         'tgl_ido' => $this->input->post('tgl_ido'),
  157.                         'no_do' => $this->input->post('no_do'),
  158.                         'jml_muatan' => $this->input->post('jml_muatan'),
  159.                         'status' => "pending",
  160.                         'id' => $this->session->userdata('id')
  161.                         );
  162.  
  163.             $id_driver = $this->input->post('id_driver');
  164.             $rotation = array(                     
  165.                         'status' => "pending"
  166.                         );
  167.            
  168.             $this->minsertdo->rotasi($id_driver, $rotation);
  169.  
  170.             $this->minsertdo->update($id, $updatedata);
  171.             redirect('erp/insertdo/success');
  172.         }
  173.                
  174.         // load view
  175.         $this->cekLevel();
  176.         $this->load->view('vinsert_do/vnewinsert_do',$data);
  177.         $this->load->view('vapp_right_menu');      
  178.         $this->load->view('vapp_footer');
  179.                
  180.     }
  181.    
  182.     function success()
  183.     {
  184.         $data['back']       = anchor('erp/insertdo','Insert DO',array('class'=>'back'));
  185.         $data['message'] = '<div class="success">Insert DO success</div>';
  186.         // load view       
  187.         $this->cekLevel();
  188.         $this->load->view('success', $data);
  189.         $this->load->view('vapp_right_menu');      
  190.         $this->load->view('vapp_footer');
  191.        
  192.     }
  193.  
  194. /* cari
  195. --------------------------------------------------------------------------*/
  196.     function do_src()
  197.     {
  198.         $this->load->model('minsertdo');
  199.  
  200.         $this->_set_fieldssrc();
  201.                
  202.         $this->_set_fieldssrc();
  203.  
  204.        
  205.         $this->form_validation->set_rules('nama_driver', 'Nama_driver', 'required');
  206.         $this->form_validation->set_message('required', '* required');
  207.         $this->form_validation->set_message('isset', '* required');
  208.         $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
  209.        
  210.        
  211.         if ($this->form_validation->run() == FALSE)
  212.         {
  213.             $data['message'] = '';
  214.         }
  215.         else
  216.         {
  217.            
  218.             $nama_driver = $this->input->post('nama_driver');
  219.            
  220.             $this->minsertdo->search_do($nama_driver);
  221.            
  222.         }
  223.        
  224.         $data['title']  = "Insert DO";
  225.        
  226.         // offset
  227.         $uri_segment = 4;
  228.         $offset = $this->uri->segment($uri_segment);
  229.  
  230.         //load data search
  231.         $this->load->model('minsertdo');
  232.        
  233.         $this->load->library('table');
  234.         $this->table->set_empty("&nbsp;");
  235.         $this->table->set_heading('No', 'NO POLISI', 'NAMA DRIVER', 'PERUSAHAAN', 'TUJUAN', 'TGL. UANG JALAN', 'JML UANG JALAN', '');
  236.         $i = 0 + $offset;
  237.         $isi = $this->minsertdo->search_do($nama_driver);
  238.         foreach ($isi as $baris)
  239.         {
  240.             $this->table->add_row(++$i, $baris->no_polisi, $baris->nama_driver, $baris->name_partner, $baris->name_location, $baris->tgl_uj, $baris->jml_uj,
  241.                 anchor('erp/insertdo/new_insertdo/'.$baris->id_timeline,'Insert DO',array('class'=>'delete'))
  242.             );
  243.  
  244.         }
  245.         $data['src_show_do']= $this->table->generate();
  246.  
  247.         // load view
  248.         $this->cekLevel();
  249.         $this->load->view('vinsert_do/vinsert_do_search',$data);
  250.         $this->load->view('vapp_right_menu');
  251.         $this->load->view('vapp_footer');
  252.     }
  253.  
  254.     function _set_fieldssrc()
  255.     {
  256.         $this->form_data = new stdClass();
  257.         $this->form_data->nama_driver = '';
  258.     }
  259.  
  260.  
  261.  
  262. /* Add Devinisi Order
  263. --------------------------------------------------------------------------*/       
  264.     //function untuk menampilkan tujuan submodul dari partner
  265.     function show_subcategory($id)
  266.     {
  267.         $tmp    = '';
  268.         $data   = $this->minsertdo->get_subcategory($id);
  269.         if(!empty($data))
  270.         {
  271.             $tmp .= "<option value=''>Pilih Tempat</option>";
  272.             $valYgDIpilih=$this->form_data->id_partner;
  273.             foreach($data as $row)
  274.             {
  275.                 if($valYgDIpilih == $row->id_partner)
  276.                     {
  277.                         $sel ='selected';
  278.                     }
  279.                     else
  280.                     {
  281.                         $sel='';
  282.                     }
  283.                 $tmp .= "<option $sel value='".$row->id_class_partner."'>".$row->name_location."</option>";
  284.             }
  285.         }
  286.         else
  287.         {
  288.             $tmp .= "<option value=''>Pilih Tempat</option>";
  289.         }
  290.         die($tmp);
  291.     }
  292.    
  293.     // set empty default form field values
  294.     function _set_fields()
  295.     {
  296.         $this->form_data = new stdClass();     
  297.         $this->form_data->id_timeline = '';
  298.         $this->form_data->no_polisi = '';
  299.         $this->form_data->id_driver = '';
  300.         $this->form_data->id_partner = '';
  301.         $this->form_data->id_class_partner = '';
  302.         $this->form_data->tgl_uj = '';
  303.         $this->form_data->jml_uj = '';
  304.         $this->form_data->tgl_ido = '';
  305.         $this->form_data->no_do = '';
  306.         $this->form_data->jml_muatan = '';
  307.        
  308.     }
  309.    
  310.     // validation rules
  311.     function _set_rules()
  312.     {
  313.         $this->form_validation->set_rules('id_timeline', 'id timeline', 'trim|required');
  314.         $this->form_validation->set_rules('no_polisi', 'no polisi', 'trim|required');
  315.         $this->form_validation->set_rules('id_driver', 'nama driver', 'trim|required');
  316.         $this->form_validation->set_rules('id_partner', 'perusahaan', 'trim|required');
  317.         $this->form_validation->set_rules('id_class_partner', 'tujuan', 'trim|required');
  318.         $this->form_validation->set_rules('tgl_uj', 'tanggal uang jala', 'trim|required');
  319.         $this->form_validation->set_rules('jml_uj', 'jumlah uang jalan', 'trim|required');
  320.         $this->form_validation->set_rules('tgl_ido', 'tanggal insert do', 'trim|required');
  321.         $this->form_validation->set_rules('no_do', 'no do', 'trim|required');
  322.         $this->form_validation->set_rules('jml_muatan', 'jumlah muatan', 'trim|required');
  323.        
  324.         $this->form_validation->set_message('isset', '* required');
  325.         $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
  326.     }
  327.     //valiation login
  328.     function is_logged_in()
  329.     {
  330.         $is_logged_in = $this->session->userdata('is_logged_in');
  331.         if(!isset($is_logged_in) || $is_logged_in != true)
  332.         {
  333.             echo 'You don\'t have permission to access this page. <a href="app">Login</a>';
  334.  
  335.             die();     
  336.             //$this->load->view('login_form');
  337.         }
  338.     }
  339.    
  340. }
  341.  
  342. /* End of file insertdo.php */
  343. /* Location: ./application/controllers/insertdo.php */
Advertisement
Add Comment
Please, Sign In to add comment