Beispiel #1
0
 function update_so_header()
 {
     $ERROR = 1;
     $id = $this->input->post('NO_BUKTI');
     unset($_POST['NAMA_WILAYAH']);
     unset($_POST['NAMA_SALES']);
     unset($_POST['NO_URUT']);
     //***************************
     //VALIDATION
     $record_hdr = $this->model_so->get_so_header(array('no_bukti' => $id));
     if ($this->_is_so_approved($record_hdr)) {
         $message = lang('ErrorTxApproved');
         die(sprintf('@@%s@@%s', 0, lang('ErrorTxApproved')));
     }
     if ($this->_is_tx_canceled($record_hdr)) {
         $message = lang('ErrorTxCanceled');
         die(sprintf('@@%s@@%s', 0, lang('ErrorTxCanceled')));
     }
     //****************************
     if ($id) {
         //unset($_POST['strseq']);
         $_POST['TGL'] = formatdatemon($_POST['TGL']);
         $_POST['TGL_KIRIM'] = formatdatemon($_POST['TGL_KIRIM']);
         $this->model_so->add_so_header($_POST, $id);
         die(sprintf('@@%s@@%s', $ERROR, lang('message_success_update')));
     } else {
         die(sprintf('@@%s@@%s', $ERROR, lang('message_ErrorIdIsNull')));
     }
 }
 function get_so_header_detail($params = array())
 {
     $datefrom = $dateto = null;
     $dateFlag = True;
     $usrBasePeriode = date('m-Y');
     // get user information
     $user_id = $this->session->userdata('user_info')->id;
     $user_name = $this->session->userdata('user_info')->username;
     $user_rank = $this->session->userdata('user_info')->rank_id;
     $rank_priority = $this->get_user_rank_priority($user_rank);
     $user_location_id = $this->get_user_location_id($user_id);
     $ids = array();
     // untuk simpan location user yang bersangkutan..
     /*
     			Search by dateto dan datefrom belum 100%
     */
     if (isset($params['NO_BUKTI']) and $params['NO_BUKTI'] != '') {
         $this->db->where('a.NO_BUKTI', $params['NO_BUKTI']);
         $dateFlag = False;
     }
     if (isset($params['NO_PO_CUST']) and $params['NO_PO_CUST'] != '') {
         $this->db->where('a.NO_PO_CUST', $params['NO_PO_CUST']);
         $dateFlag = False;
     }
     //if( isset( $params['NAMA_CUST']) and $params['NAMA_CUST']!='')
     if (isset($params['customer_code']) and $params['customer_code'] != '') {
         //$this->db->where('a.NAMA_CUST', $params['NAMA_CUST']);
         $this->db->where('a.CUST', $params['customer_code']);
         $dateFlag = False;
     }
     if (isset($params['sales_code']) and $params['sales_code'] != '') {
         $this->db->where('a.KODE_SALES', $params['sales_code']);
     }
     if (isset($params['KODE_WIL']) and $params['KODE_WIL'] != '') {
         if ($params['KODE_WIL'] != 'ALL') {
             $this->db->where('a.KODE_WIL', $params['KODE_WIL']);
         }
     }
     //item related
     if (isset($params['item_no']) and $params['item_no'] != '') {
         $this->db->where('b.BRG', $params['item_no']);
     }
     if ($dateFlag) {
         if (isset($params['datefrom']) and $params['datefrom'] != '') {
             $datefrom = formatdatemon($params['datefrom']);
         } else {
             $datefrom = date('d-M-Y', COMPILE_iFIRSTDATE($usrBasePeriode));
         }
         if (isset($params['dateto']) and $params['dateto'] != '') {
             $dateto = formatdatemon($params['dateto']);
         } else {
             $dateto = date('d-M-Y', COMPILE_iLASTDATE($usrBasePeriode));
         }
     }
     if (!is_null($datefrom)) {
         $this->db->where('a.TGL >=', $datefrom);
     }
     if (!is_null($dateto)) {
         $this->db->where('a.TGL <=', $dateto);
     }
     /*$this->db->select(
           'a.NO_BUKTI, a.TGL, a.TGL_KIRIM, a.STATUS, a.NO_PO_CUST, a.NAMA_CUST, a.VLT, a.KET, a.TGL_INPUT,
           b.NO_URUT, b.BRG, u.username, u.rank_id, ul.location_id, sl.NAMA'
       ); */
     /*$this->db->select(
           'a.NO_BUKTI, a.TGL, a.TGL_KIRIM, a.STATUS, a.NO_PO_CUST, a.NAMA_CUST, a.VLT, a.KET, a.TGL_INPUT,
               b.NO_URUT, b.BRG, u.username, u.rank_id, ul.location_id, sl.NAMA'
       );*/
     $this->db->select('a.*,
         b.NO_URUT, 
         b.BRG, 
         sl.NAMA, 
         brg.NAMA as NAMABARANG');
     // refer to model_po's model
     $this->db->join($this->prefix . '_AR..ARF08 sl', 'sl.SLM = a.KODE_SALES', 'left');
     $this->db->join($this->prefix . '_SO..SOT01B b', 'b.NO_BUKTI = a.NO_BUKTI', 'left');
     $this->db->join($this->prefix . '_ST..STF02 brg', 'brg.BRG = b.BRG', 'left');
     $this->db->join('[user] u', 'a.USER_NAME = u.username', 'left');
     $this->db->join('[user_location] ul', 'ul.user_id = u.id', 'left');
     $this->db->order_by("a.NO_BUKTI", "asc");
     //if($user_rank > 30){
     if ($rank_priority > 30) {
         foreach ($user_location_id as $id) {
             $ids[] = $id->location_id;
         }
         //$this->db->where('ul.location_id', $user_location_id);  // hanya pilih lokasi user nya aja
         //$this->db->where_in('ul.location_id', $ids);
         $this->db->where_in('a.KODE_WIL', $ids);
     }
     $query = $this->db->get($this->prefix . '_SO..SOT01A a')->result();
     return $query;
 }