Untitled

mail@pastecode.io avatar
unknown
php
4 years ago
11 kB
6
Indexable
Never
 $post = $this->input->post();
            $session = $this->session->userdata('hs_logged_in');
            $action = $post['action'];
            $detail = $post['detail'];
            $psNumber = $post['psNumber'];
			$document = substr($action, -2);
			var_dump($post); die;
			if(is_array($detail)) { 
				foreach($detail as $docCode => $arrayDet) {
					if($docCode == $document) {
						foreach($arrayDet as $matCode => $val) {
							$detailQty[$matCode] = $val; 
						}
					}
				}	
			}
		
			$getPSHeaderQuery = "SELECT	fleet_doch.doc_code,
						fleet_doch.doc_date,
						fleet_doch.date_exec,
						fleet_doch.ref_date,
						fleet_doch.sro_code,
						fleet_doch.receive_by,
						fleet_doch.userid,
						fleet_doch.doc_remark,
						fleet_doch.lastupdate,
						fleet_doch.region_code,
						fleet_doch.status_doc,
						fleet_doch.type_doc,
						fleet_doch.type_ref,
						fleet_doch.unit_code,
						fleet_doch.model_no,
						fleet_doch.no_wo,
						fleet_doch.time_reading,
						fleet_doch.type_source,
						fleet_doch.dept_code,
						fleet_doch.job_status,
						fleet_doch.OrderType,
						fleet_doch.tFullSupply,
						fleet_doch.Owner,
						fleet_doch.OwnStamp,
						fleet_doch.Printed,
						fleet_doch.Edited,
						fleet_doch.Otorisasi,
						fleet_doch.OtoUsr,
						fleet_doch.OtoStamp,
						fleet_doch.Lvl,
						fleet_doch.order_by,
						fleet_doch.approval_by,
						fleet_doch.WoOrderType,
						fleet_doch.WoJobStatus,
						fleet_doch.tAccept,
						fleet_doch.user_accept,
						fleet_doch.accept_date,
						fleet_doch.accept_time,
						fleet_doch.wh_code,
						fleet_doch.dept_id,		
						fleet_doch.wgCode,   
						fleet_doch.purHndlCode,    
						fleet_doch.Gapprove,
						fleet_doch.TotAppv,
						fleet_doch.LastAppv,
						fleet_doch.TstAppv,

						(SELECT	ms_jobsite.region_name
						FROM		ms_jobsite
						WHERE	ms_jobsite.region_code = fleet_doch.region_code) AS region_name,
						(CASE fleet_doch.type_ref
						WHEN '1' THEN 
								 (SELECT		fleet_sroh.sro_kind
									FROM 	fleet_sroh
									WHERE	fleet_sroh.sro_code = fleet_doch.sro_code)
						WHEN '2' THEN
								 (SELECT		fleet_grh.priority_code
									FROM 	fleet_grh
									WHERE	fleet_grh.doc_code = fleet_doch.sro_code)
						ELSE
							''
						END) AS Priority
			FROM		fleet_doch
			WHERE	fleet_doch.doc_code = '$psNumber'";            
			            $getPSHeaderArray = $this->Mmaster->getDataQuery($getPSHeaderQuery);
			            $getPSHeader = $getPSHeaderArray[0];
			            $siteCode = $getPSHeader['region_code'];
			            $yearNow = date('y') ;
			            $getBranchCodeQuery = "SELECT PlantCode, company_code, PlantName, sar_code FROM ms_branch where PlantName = '$siteCode'";
			            $getBranchCodeArray = $this->Mmaster->getDataQuery($getBranchCodeQuery);
			            $branchCode = $getBranchCodeArray[0]['PlantCode'];
			//            $kodePRDoc = 'PRA'.$getPSHeader[$branchCode];
			//            $kodePRDoc = 'PRA03HOF18';
			            $kodePRDoc = 'PRA'.$branchCode.$siteCode.$yearNow;
			            $getLastPRNumberQuery =  "SELECT MAX ( RIGHT ( tr_purchase_reqh.pr_code , 6 ) ) as computed FROM tr_purchase_reqh WHERE tr_purchase_reqh.pr_code LIKE '$kodePRDoc%' ";
			            $getLastPRNumberArray = $this->Mmaster->getDataQuery($getLastPRNumberQuery);
			//            print_r($getLastPRNumberArray); die;
			            $getLastPRNumbers = $getLastPRNumberArray[0];
			            $getLastPRNumber = $getLastPRNumbers['computed'];
			            $newPRNumber = sprintf("%06d",$getLastPRNumber + 1);
						$detail = array();

			            foreach($detailQty as $matCodes => $reqQty) {
			                   // echo $matCodes.'<br />';
			                if(strpos($matCodes, '|-----|') !== FALSE ) { 
			                    $matCodesArray = explode('|-----|', $matCodes);
			                    $matCodes = implode(' ', $matCodesArray);
			                   // print_r($matCodesArray); die;
			                }
							if(strpos($matCodes, '|COMMASIGN|') !== FALSE){
			                	$matCodes = str_replace("|COMMASIGN|", ",", $matCodes);
							}
			                if(strpos($matCodes, '|') !== FALSE){
			                	$matCodes = str_replace("|", ".", $matCodes);
			                }
			                $getPSDetailQuery = "select * from nv_ps_detail where doc_code = '$psNumber' AND part_code = '$matCodes'";
			                $getPSDetailArray = $this->Mmaster->getDataQuery($getPSDetailQuery);
			                $sroCode = $getPSDetailArray[0]['sro_code'];
			                $getSRODetailQuery = "select doc_code, part_code, prod_type, remark from fleet_grd where doc_code = '$sroCode' and part_code = '$matCodes'";
			                $getSRODetailArray = $this->Mmaster->getDataQuery($getSRODetailQuery);
			//                        print_r($getSRODetailArray); die;
			                $sroRemark = $getSRODetailArray[0]['remark'];
			//                        print_r($sroRemark); die;
			                $detail[$matCodes] = $getPSDetailArray[0];
			                $detail[$matCodes]['prQty'] = $reqQty;
			                $lastPriceQuery = "select TOP 1 * from tr_purchaseD where Prod_code = '$matCodes' order by nomer DESC";
			                $getLastPriceArray = $this->Mmaster->getDataQuery($lastPriceQuery);
			                if($getLastPriceArray) {
			                    $lastPrice = $getLastPriceArray[0]['harga'];
			                    $lastPO = $getLastPriceArray[0]['po_code'];
			                } else {
			                    $lastPrice = false;
			                    $lastPO = false;
			                }
			                $detail[$matCodes]['lastPrice'] = $lastPrice;
			                $detail[$matCodes]['lastPO'] = $lastPO;
			                $detail[$matCodes]['remark'] = $sroRemark;
			                        
			            } 
			            $getManPowerPRQuery = "SELECT 	ms_manpower_setB.nik as employee_code,  			
				upper(ms_manpower.name) as name,           		
				upper(ms_manpower.jabatan) as position_name,  			
				master_form.WindowName    FROM 	ms_manpower,  			
				ms_manpower_setA, ms_manpower_setB,  master_form  
					WHERE 	ms_manpower_setA.FromID =   ms_manpower_setB. FromID 
					AND  	ms_manpower_setB.Nik = ms_manpower.Nik 
					AND   	master_form.FromId = ms_manpower_setA.FromID 
					AND 	ms_manpower.stedit<> '4'   
					AND WindowName = 'w_pr_entry_modif'  ";
            $getManPowerPRArray = $this->Mmaster->getDataQuery($getManPowerPRQuery);
            $kdUser = $session['KdUser'];
            $getJobSiteQuery = "select a.kduser, a.region_code, b.region_name, a.status_default_region as 'default' from ms_users_jobsite a, ms_jobsite b where kduser = '$kdUser' and b.region_code = a.region_code and b.stEdit <> 4";
            $getJobSiteArray = $this->Mmaster->getDataQuery($getJobSiteQuery);
//            $getWarehouseQuery = "select a.wh_code, b.wh_name from ms_users_wh as a, ms_warehouse as b where b.wh_code = a.wh_code and a.kduser = '$kdUser' and a.region_code = '$siteCode' and b.stEdit <> 4";
            $getWarehouseQuery = "select a.wh_code, b.wh_name from ms_users_wh as a, ms_warehouse as b where b.wh_code = a.wh_code and a.kduser = '$kdUser' and b.stEdit <> 4";
            $getWarehouseArray = $this->Mmaster->getDataQuery($getWarehouseQuery);
            $costCenter = $getPSHeader['dept_code'];
            $getCostCenterQuery = "select CostCenter, CostCenterName from ms_cost_center where region_code = '$siteCode'";
            $getCostCenterArray = $this->Mmaster->getDataQuery($getCostCenterQuery);
            $deptId = $getPSHeader['dept_id']; 
            $getDeptQuery = "select dept_code, dept_name from ms_department where stEdit <> 4";
            $getDeptArray = $this->Mmaster->getDataQuery($getDeptQuery);
            $scope = $getPSHeader['Gapprove'];
            $getScopeQuery = "select a.GAppCode, b.GAppName, a.status_default_scope as 'default' from ms_users_scope as a, ms_approve_group as b where b.GAppCode = a.GAppCode and a.kduser = '$kdUser' and b.stEdit <> 4";
            $getScopeArray = $this->Mmaster->getDataQuery($getScopeQuery);
            $getPICQuery = "select purHndlCode, purHndlName from ms_purHndl where stEdit <> 4";
            $getPICArray = $this->Mmaster->getDataQuery($getPICQuery);
            $getWGQuery = "select a.kduser, a.wgCode, a.status_default_wgroup as 'default', b.wgName from ms_users_WGroup as a, ms_purwkgrp as b where b.wgCode = a.wgCode and a.kduser='$kdUser' and b.stEdit <> 4";
            $getWGArray = $this->Mmaster->getDataQuery($getWGQuery);
			$getUnitCodeQuery = "SELECT  ms_unit.unit_code, ms_unit.model_no, ms_unit.unit_name, ms_unit.region_code, ms_unit.dept_code FROM ms_unit WHERE ( ms_unit.active = '1' ) and ( ms_unit.tMain = 1 )";
			$getUnitCode = $this->Mmaster->getDataQuery($getUnitCodeQuery);
            
            $data['post'] = $post;
            $data['detail'] = $detail;
            $data['psHeader'] = $getPSHeader;
            $data['manPowerPR'] = $getManPowerPRArray;
            $data['jobsite'] = $getJobSiteArray;
            $data['projectArea'] = $siteCode;
            $data['warehouses'] = $getWarehouseArray;
            $data['whCode'] = $getPSHeader['wh_code'];
            $data['costCenter'] = $costCenter;
            $data['costCenters'] = $getCostCenterArray;
            $data['deptId'] = $deptId;
            $data['departments'] = $getDeptArray;
            $data['scope'] = $scope;
            $data['unitCode'] = $getUnitCode;
            $data['scopes'] = $getScopeArray;
            $data['pic'] = $getPSHeader['purHndlCode'];
            $data['pics'] = $getPICArray;
            $data['workgroup'] = $getWGArray;
            $data['custSupp'] = $session['db'];
            $data['refNo'] = $psNumber;
			$data['remark'] = $getPSHeader['doc_remark'];
            // printExit($getCostCenterQuery);
            
//            echo '<pre>'; print_r($data); die;
//            print_r($getLastPRNumber); echo '<br/>' . $newPRNumber.'<br/>';
//            die;
            if($post['action'] == 'createPR') {
                $this->load->view('template/header');
                $this->load->view('template/sidebar');
                $this->load->view('vcreatepr',$data);
                $this->load->view('template/footer');
                $this->load->view('template/controlsidebar');
            } elseif($post['action'] == 'createGI') {
                $this->load->view('template/header');
                $this->load->view('template/sidebar');
                $this->load->view('vcreategi',$data);
                $this->load->view('template/footer');
                $this->load->view('template/controlsidebar');
            }