예제 #1
0
 public function postEnvioofsc()
 {
     $datos = array();
     $datos['hf'] = explode("||", Input::get('hf'));
     $datos['fecha'] = $datos['hf'][0];
     $datos['bucket'] = $datos['hf'][1];
     $datos['slot'] = $datos['hf'][2];
     //time slot
     $datos['horas'] = explode("-", $datos['hf'][3]);
     $datos['empresa_id'] = Input::get('empresa_id');
     $datos['codactu'] = Input::get('codactu');
     $sla = false;
     $slaInicio = "0000-00-00 00:00";
     //retorno de transaccion
     $save = array("rst" => 2, "msj" => "Sin reultados.", "error" => "", "gestion_id" => 0);
     $inbound = new Inbound();
     $gestionId = "";
     $codactu = $datos['codactu'];
     //"35268199"; //
     $date = $datos['fecha'];
     //date("Y-m-d"); //
     $bucket = $datos['bucket'];
     //"BK_PRUEBAS_TOA";
     $tini = trim($datos['horas'][0]);
     //"09:00"
     $tend = trim($datos['horas'][1]);
     //"13:00"
     $tobooking = date("Y-m-d H:i");
     $slot = $datos['slot'];
     //"AM"
     $cuadrante = "Something";
     $techTp = "NULL";
     $techBb = "NULL";
     $techTv = "NULL";
     $wzKey = "";
     $wtLabel = "";
     $wType = "";
     $accTech = "COAXIAL";
     $businessType = "";
     $phone = array(0 => "", 1 => "");
     //Datos de la actuacion
     $actu = \Gestion::getCargar($codactu);
     //Existe la actuacion
     if (isset($actu["datos"][0])) {
         $actuObj = $actu["datos"][0];
         $actuArray = (array) $actuObj;
         $actuArray['noajax'] = "ok";
         //Motivo/Submotivo
         $actuArray['gestion_id'] = $actuObj->id;
         $actuArray['motivo'] = 1;
         $actuArray['submotivo'] = 1;
         $actuArray['estado'] = 2;
         //GestionID
         $gestionId = $actuObj->id;
         //Tipo de actividad: tabla "actividaes_tipos"
         $actTipo = DB::table('actividades_tipos')->select('nombre', 'label', 'sla', 'duracion')->where('id', '=', $actuArray['actividad_tipo_id'])->first();
         //Duracion en minutos
         $duration = $actTipo->duracion;
         //Quiebre grupo
         $quiebreGrupo = DB::table('quiebre_grupos')->select('nombre')->where('id', '=', $actuArray['quiebre_grupo_id'])->first();
         //Negocio por texto
         if (strpos($actuArray['tipo_averia'], "catv") > 0) {
             $businessType = "CATV";
         }
         if (strpos($actuArray['tipo_averia'], "adsl") > 0) {
             $businessType = "ADSL";
         }
         if (strpos($actuArray['tipo_averia'], "bas") > 0) {
             $businessType = "BASICA";
         }
         $wtLabel = $actTipo->label;
         $wType = $actTipo->nombre;
         //Telefonos de contacto
         $phoneArray = explode("|", $actuArray['fonos_contacto']);
         if (isset($phoneArray[0])) {
             $phone[0] = $phoneArray[0];
         }
         if (isset($phoneArray[1])) {
             $phone[1] = $phoneArray[1];
         }
         //Si no hay telefono de contacto
         if (strlen(trim($actuArray['fonos_contacto'])) < 6) {
             $phone = array("0000000", "0000000");
         }
         //Datos XY Web
         $actuArray['x'] = $actuArray['coord_x'];
         $actuArray['y'] = $actuArray['coord_y'];
         //Facilidades técnicas
         $ffttController = new \FfttController();
         $val = new stdClass();
         $val->fftt = $actuArray['fftt'];
         $val->tipoactu = $actuArray['tipo_averia'];
         $ffttArray = $ffttController->getExplodefftt($val);
         if ($ffttArray["tipo"] == 'catv') {
             $wzKey = $ffttArray["nodo"] . "_" . $ffttArray["troba"];
         } else {
             $wzKey = $ffttArray["mdf"] . "_" . $ffttArray["armario"];
         }
         //Parche: datos no concuerdan -> enumeration
         if ($actuArray['segmento'] == "NO-VIP") {
             $actuArray['segmento'] = "N";
         }
         //Homologacion de campos
         $dataOfsc = array("bucket" => $datos['bucket'], "actividad" => strtolower($actuObj->actividad), "date" => $date, "type" => "update_activity", "external_id" => $bucket, "start_time" => $tini, "end_time" => $tend, "appt_number" => $actuArray['codactu'], "customer_number" => $actuArray['inscripcion'], "worktype_label" => $wtLabel, "time_slot" => $slot, "time_of_booking" => $tobooking, "duration" => $duration, "name" => $actuArray['nombre_cliente'], "phone" => $phone[0], "email" => "", "cell" => $phone[1], "address" => $actuArray['direccion_instalacion'], "city" => "Lima", "state" => "Lima", "zip" => "LIMA 05", "language" => "1", "reminder_time" => "15", "time_zone" => "19", "coordx" => $actuArray['coord_x'], "coordy" => $actuArray['coord_y'], "XA_CREATION_DATE" => $tobooking, "XA_SOURCE_SYSTEM" => "PSI", "XA_CUSTOMER_SEGMENT" => $actuArray['segmento'], "XA_CUSTOMER_TYPE" => "", "XA_CONTACT_NAME" => "", "XA_CONTACT_PHONE_NUMBER_2" => "", "XA_CONTACT_PHONE_NUMBER_3" => "", "XA_CONTACT_PHONE_NUMBER_4" => "", "XA_CITY_CODE" => "", "XA_DISTRICT_CODE" => $actuArray['codigo_distrito'], "XA_DISTRICT_NAME" => $actuArray['distrito'], "XA_ZONE" => $actuArray['zonal'], "XA_QUADRANT" => $cuadrante, "XA_WORK_ZONE_KEY" => $wzKey, "XA_RURAL" => "", "XA_RED_ZONE" => "", "XA_WORK_TYPE" => $wType, "XA_APPOINTMENT_SCHEDULER" => "CLI", "XA_USER" => "", "XA_REQUIREMENT_NUMBER" => $actuArray['codactu'], "XA_NUMBER_SERVICE_ORDER" => $actuArray['orden_trabajo'], "XA_CHANNEL_ORIGIN" => "", "XA_SALES_POINT_CODE" => "", "XA_SALES_POINT_DESCRIPTION" => "", "XA_COMMERCIAL_VALIDATION" => "", "XA_TECHNICAL_VALIDATION" => "", "XA_WEB_UNIFICADA" => "", "XA_ORDER_AREA" => "", "XA_COMMERCIAL_PACKET" => "", "XA_COMPANY_NAME" => $actuArray['empresa'], "XA_GRUPO_QUIEBRE" => $quiebreGrupo->nombre, "XA_QUIEBRES" => $actuArray['quiebre'], "XA_BUSINESS_TYPE" => $businessType, "XA_PRODUCTS_SERVICES" => "", "XA_CURRENT_PRODUCTS_SERVICES" => "", "XA_EQUIPMENT" => "", "XA_NOTE" => $actuArray['observacion'], "XA_TELEPHONE_TECHNOLOGY" => $techTp, "XA_BROADBAND_TECHNOLOGY" => $techBb, "XA_TV_TECHNOLOGY" => $techTv, "XA_ACCESS_TECHNOLOGY" => $accTech, "XA_HFC_ZONE" => "", "XA_HFC_NODE" => "", "XA_HFC_TROBA" => "", "XA_HFC_AMPLIFIER" => "", "XA_HFC_TAP" => "", "XA_HFC_BORNE" => "", "XA_REQUIREMENT_TYPE" => "", "XA_REQUIREMENT_REASON" => "", "XA_CATV_SERVICE_CLASS" => "", "XA_MDF" => $actuArray['mdf'], "XA_CABLE" => "", "XA_CABINET" => "", "XA_BOX" => "", "XA_TERMINAL_ADDRESS" => "", "XA_TERMINAL_LINKHTTP" => "", "XA_ADSLSTB_PREFFIX" => "NULL", "XA_ADSLSTB_MOVEMENT" => "NULL", "XA_ADSL_SPEED" => "", "XA_ADSLSTB_SERVICE_TYPE" => "", "XA_PENDING_EXTERNAL_ACTION" => "", "XA_SMS_1" => $actuArray['sms1'], "XA_DIAGNOSIS" => "", "XA_TOTAL_REPAIRS" => $actuArray['total_averias']);
         //Envio por SLA
         if (Input::get('agdsla') == 'sla' and Input::get('slaini') != '') {
             $sla = true;
             $slaInicio = strtotime(Input::get('slaini'));
             $slaDay = $actTipo->sla * 3600;
             $slaFin = $slaInicio + $slaDay;
             $dataOfsc["sla_window_start"] = date("Y-m-d H:i", $slaInicio);
             $dataOfsc["sla_window_end"] = date("Y-m-d H:i", $slaFin);
             $dataOfsc["date"] = date("Y-m-d", $slaInicio);
         }
         //Campos adicionales para averia
         if (strtolower($actuObj->actividad) == 'averia') {
             $dataOfsc["XA_DIAGNOSIS"] = "SB_01";
         }
         /**
          * Guardar en tablas de gestion
          * - gestiones
          * - gestiones_detalles
          * - gestiones_movimientos
          * - ultimos_movimientos
          */
         $actuArray['fecha_agenda'] = $date;
         $horario = Horario::where('horario', '=', $slot)->first();
         if ($horario != NULL and $horario != '') {
             $actuArray['horario_id'] = $horario->id;
             $actuArray['dia_id'] = date("N", strtotime($date));
         }
         $actuArray['estado_agendamiento'] = "1-1";
         unset($actuArray["tecnico"]);
         unset($actuArray["tecnico_id"]);
         unset($actuArray["celula_id"]);
         Input::replace($actuArray);
         $save = $this->_gestionMovimientoController->postRegistrar();
         unset($actuArray["fecha_agenda"]);
         unset($actuArray["horario_id"]);
         unset($actuArray["dia_id"]);
         $actuArray['estado_agendamiento'] = "3-0";
         $actuArray['motivo'] = 2;
         $actuArray['submotivo'] = 18;
         $actuArray['estado'] = 7;
         if ($save["rst"] == 1) {
             //Crear actividad en OFSC
             /*if ( $dataOfsc['date']==0 ) {
                   $dataOfsc['date']=date("Y-m-d",strtotime(Input::get('slaini')) );
               }*/
             $response = $inbound->createActivity($dataOfsc, $sla);
             $report = $response->data->data->commands->command->appointment->report;
             $resultBool = true;
             /**
              * $report->message:
              * 
              * El mensaje de respuesta puede ser un arreglo
              * o un único mensaje.
              * Se valida la respuesta para cada mensaje recibido.
              */
             if (is_array($report->message)) {
                 foreach ($report->message as $val) {
                     if ($val->result == 'warning') {
                         $save["error"][] = $val->description;
                     }
                     if ($val->result == 'error') {
                         $save["error"][] = $val->description;
                     }
                 }
             } else {
                 if ($report->message->result == 'error') {
                     $resultBool = false;
                     $save["error"][] = $report->message->description;
                 }
             }
             //$result = $report->message->result;
             //Retorno OK
             if ($resultBool) {
                 //Appointment id
                 $aid = $response->data->data->commands->command->appointment->aid;
                 $datosofsc = array();
                 $datosofsc['aid'] = $aid;
                 $datosofsc['gestion_id'] = $save['gestion_id'];
                 $datosofsc['envio_ofsc'] = 2;
                 if ($sla == false) {
                     $datosofsc['envio_ofsc'] = 1;
                 }
                 $datosofsc['gestion_movimiento_id'] = $save['gestion_movimiento_id'];
                 GestionMovimiento::ActOfscAid($datosofsc);
                 $save["msj"] = "Registro y envío a OFSC correcto.";
                 $save["aid"] = $aid;
             }
             //Retorno ERROR
             if (!$resultBool) {
                 $errArray['type'] = $report->message->type;
                 $errArray['code'] = $report->message->code;
                 $errArray['desc'] = $report->message->description;
                 Input::replace($actuArray);
                 $save = $this->_gestionMovimientoController->postRegistrar();
                 $save["rst"] = 2;
                 $save["msj"] = "No se pudo enviar a OFSC. " . $report->message->description;
             }
         }
     }
     return json_encode($save);
 }