'', 'status' => 0, 'header' => [ 'rowID'=> '', 'accounthierarchy'=> '', 'serialnumber'=>'', 'hw_version'=>'', 'sw_version'=>'', 'service_date'=>'', 'warranty_date'=> '', 'order_ref'=>'', 'sw_version_latest'=>'', 'servicereport_available' => '', 'productrowid' => '', 'productcode'=> '', 'productname'=> '', 'return_reason' => '', 'return_reason_note' => '' ], 'questions' => [], 'created' => '', 'createdby' => '', 'updated' => '', 'updatedby' => '', 'accounthierarchy' => '' ]; if (isset($_GET['rowID'])) { // ID param exists, edit an existing product //CALL TO API $api_url = '/v2/rma/rowID='.$_GET['rowID']; $responses = ioServer($api_url,''); //Decode Payload if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;} $rma = json_decode(json_encode($responses[0]), true); //GET DETAILS $rma['header'] = json_decode($rma['header'],true) ?? ''; $rma['questions'] = json_decode($rma['questions'],true) ?? ''; $serial_input = ''; if ($update_allowed === 1){ if (isset($_POST['save'])) { //UPLOAD ALL PICTURES foreach ($_FILES["fileToUpload"]["name"] as $key => $value){ //ONLY UPDATE PICTURES IF SOMETHING IS RETURNED if($value !='' || !empty($value)){ uploadrequest($key); } } //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/rma', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=rma&rowID='.$_GET['rowID'].'&success_msg=2'); exit; } } } if ($delete_allowed === 1){ if (isset($_POST['delete'])) { //GET ALL POST DATA $payload = json_encode($_POST , JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/rma', $payload); // Redirect and delete equipment if ($responses === 'NOK'){ } else { header('Location: index.php?page=rmas&success_msg=3'); exit; } } } } else { if (isset($_POST['assetID'])){ //GET RELATED DATA $api_url = '/v2/equipments/serialnumber='.$_POST['assetID']; $equipment = ioServer($api_url,''); //Decode Payload if (!empty($equipment)){$equipment = json_decode( $equipment,true);}else{$equipment = null;} if (isset($equipment[0]['rowID'])){ //CHECK FOR LATEST SERVICEREPORT $servicereport_date = date("Y-m-d", strtotime("-457 days")); $api_url = '/v2/history/equipmentid='.$equipment[0]['rowID'].'&type=servicereport&created='.$servicereport_date; $servicereport = ioServer($api_url,''); //Decode Payload if (!empty($servicereport)){$servicereport = json_decode( $servicereport,true);}else{$servicereport = null;} //GetPartnerDetails $partner_data = json_decode($equipment[0]['accounthierarchy'],true) ?? ''; if (is_array($partner_data)){ $soldto = getPartnerName($partner_data['soldto']) ?? '-'; $shipto = getPartnerName($partner_data['shipto']) ?? '-'; $location = getPartnerName($partner_data['location']) ?? '-'; } $rma = [ 'rowID' => '', 'status' => 0, 'header' => [ 'rowID'=> $equipment[0]['rowID'], 'serialnumber'=> $equipment[0]['serialnumber'], 'hw_version'=> $equipment[0]['hw_version'], 'sw_version'=>$equipment[0]['sw_version'], 'service_date'=> date('Y-m-d', strtotime($equipment[0]['service_date']. ' + 365 days')), 'warranty_date'=> date('Y-m-d', strtotime($equipment[0]['warranty_date']. ' + 365 days')), 'order_ref'=>$equipment[0]['order_ref'], 'sw_version_latest'=>$equipment[0]['sw_version_latest'], 'servicereport_available' => ((count($servicereport) !=0) ? 1 : 0), 'productrowid'=> $equipment[0]['productrowid'], 'productcode'=> $equipment[0]['productcode'], 'productname'=> $equipment[0]['productname'], 'return_reason' => '', 'return_reason_note' => '', 'soldto'=> $soldto, 'shipto'=> $shipto, 'location'=> $location ], 'questions' => [], 'created' => '', 'createdby' => '', 'updated' => '', 'updatedby' => '', 'accounthierarchy' => '' ]; $serial_input = ''; } else { $serial_input = ''; } } else { //GET RELATED SERIALNUMBERS //CALL TO API $api_url = '/v2/equipments/list='; $assets_keys = ioServer($api_url,''); //Decode Payload if (!empty($assets_keys)){$assets_keys = json_decode($assets_keys,true);}else{$assets_keys = null;} //CREATE SERIALNUMBER DROPDOWN $serial_input =' '; foreach ($assets_keys as $assets_key) { $serial_input .= ''; } $serial_input .= ''; //END DROPDOWN } // Create a new equipment if (isset($_POST['save'])) { //UPLOAD ALL PICTURES foreach ($_FILES["fileToUpload"]["name"] as $key => $value){ //ONLY UPDATE PICTURES IF SOMETHING IS RETURNED if($value !='' || !empty($value)){ uploadrequest($key); } } //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/rma', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=rmas&success_msg=1'); exit; } } } template_header('RMA', 'rma','manage'); $view ='

'.($rma_h2 ?? 'Return Material Request').'

'.$button_cancel.' '; if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ $view .= ''; } $view .= '
'; $view .= '
'; $view .= '
'.($rma_information ?? 'RMA details').'

'.$equipment_label2.'

'.$serial_input.'

'.$equipment_label3.'

'.$product_code.'

'.(($view_product == 1)? ''.$rma['header']['productcode'].'':'').'

'.$product_name.'

'.(($view_product == 1)? ''.(${$rma['header']['productname']} ?? $rma['header']['productname']).'':'').'

'.$equipment_label10.'

'.($rma_sw_version_latest ?? 'Latest software version').'

'.($rma_servicereport_latest ?? 'Servicereport created last 7days').'

'; if ($rma['header']['servicereport_available']==1){ $view .='

'.$service_report_id.'

'; } $view .='
'; $view .='
'.$view_asset_partners.'

'.$general_soldto.'

'.$general_shipto.'

'.$general_location.'

'; $view .= '
'; // ------------------------------- //BUILD TO INPUT FORM BASED ON ARRAY // ------------------------------ // $view .='
'.($rma_return_tab1 ?? 'Return reason').''; if($rma['header']['servicereport_available'] == 0 ){ $view .=''.($rma_return_tab2 ?? 'Questions').''; } $view .= '
'; $view .= '

'.($rma_return_reason ?? 'Return reason').'

'.($rma_return_reason_note ?? 'Return reason note').'

'; $view .= '
'; if($rma['header']['servicereport_available'] == 0 ){ foreach($arrayQuestions_rma as $group){ foreach($group['Questions_in_group'] as $question){ switch ($question['Type']) { case 'dropdown': $view .= ''; $view .= ''; break; case 'textarea': $view .= ''; $view .= ''; break; case 'file'; $view .= ''; if ($question['QuestionID'] !=''){ $view .= ' '; } else { $view .= ''; } break; } } } } $view .= '
'; $view .= ' '; //OUTPUT echo $view; template_footer(); ?>