Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function saveCase(){
- //Creamos el objeto
- $caso = new Cases();
- $historia = new CasoHistorial();
- //Leemos Los Parametros Del Formulario
- $asunto = $this->post('subject');
- $fabrica = $this->post('fabrica_id');
- $cliente = $this->post('cliente_id');
- $subdistribuidor = $this->post('subdistri_id');
- $segmento = $this->post('segmento_id');
- $usuario_destino = $this->post('usuariodes_id');
- $usuario_emisor = $this->post('fabrica_id');
- $casotipo = $this->post('tipocaso_id');
- $file = $_FILES['file']['name'];
- //Creamos el array con la informacion para insertar
- $values = array('asunto' => $asunto,
- 'id_fabrica' => $fabrica,
- 'id_cliente' => $cliente,
- 'id_subdistri' => $subdistribuidor,
- 'fecha_creacion' => date("Y-m-d"),
- 'id_caso_tipo' => $casotipo,
- 'id_usuario' => $usuario_destino,
- 'id_segmento' => $segmento,
- 'id_usuario_emisor' => Session::get('usuario_id'),
- 'estado' => 1);//Seteamos por defecto que el caso quda abierto
- $this->error = false;
- //insertamos los datos y verificamos que no hubo errores
- if($caso->create($values)){
- $id = $caso->maximum('id');
- $this->casees = $acti = substr($this->post('act'), 0, -1);
- $actividades = explode(";", $acti);
- $this->i = 0;
- foreach($actividades as $a){
- $actividad = new CaseActividad();
- $act = explode("|",$a);
- $actividad_array = array(
- 'asunto' => $act[0],
- 'estado' => 2,//por defecto dejamos el estado en en progreso cuando creamos un caso
- 'fecha_inicio' => $act[2],
- //'comentario' => $act[3],
- 'hora' => $act[4],
- 'id_caso' => $id
- );
- if(!$actividad->save($actividad_array)){
- $this->error = true;
- } else {
- //objecto de la tabla caso comentario
- $comentObj = new CasoComentario();
- $id = $actividad->maximum("id");
- $commentInfo = array(
- 'comentario' => $act[3],
- 'fecha' => date('Y-m-d'),
- 'id_actividad' => $id
- );
- $comentObj->create($commentInfo);
- }
- $this->i++;
- }
- //relacionames el adjunto con el caso
- if(!empty($_FILES['file']['name'])){
- $casoObj = new CasoActividadAdjunto();
- $casoData = array(
- 'id_caso' => $id,
- 'nombre' => $_FILES['file']['name'],
- 'fecha_adjunto' => date('Y-m-d'),
- );
- if(!$casoObj->create($casoData)){
- $this->error = true;
- }
- Upload::file('file');
- $casoHis = array(
- 'id_caso' => $id,
- 'history' => "Accion : Adjunto ".$_FILES['file']['name'] ." Creado Fecha: ".date("Y-m-d h:i:s")." Usuario: ".$usuario
- );
- $historia->create($casoHis);
- }
- //ingresamos que se creo un caso
- $usuarios = new Usuario();
- $allusers = $usuarios->find();
- $usuario = $this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'login');
- $casoHis = array(
- 'id_caso' => $id,
- 'history' => "Accion : Caso Creado Fecha: ".date("Y-m-d h:i:s")." Usuario: ".$usuario
- );
- $historia->create($casoHis);
- if(Session::get('usuario_id') != $usuario_destino){
- $usuarioEmisor = $this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'nombre')." ".$this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'apellido');
- $usuario = $this->findBy($allusers , $usuario_destino, 'idusuario', 'nombre')." ". $this->findBy($allusers , $usuario_destino, 'idusuario', 'apellido');
- $usuarioCorreo = $this->findBy($allusers , $usuario_destino, 'idusuario', 'mail');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPAuth = false;
- $mail->Host = "192.168.10.1";
- $mail->Username = "hwalteros";
- $mail->Password = "123";
- $mail->From = "info@quinterossa.com";
- $mail->FromName = 'Informacion Quinteros S.A.';
- $mail->Subject = "Usted Tiene Un Nuevo Caso Asignado Por : ".$usuarioEmisor;
- $mail->AddAddress($usuarioCorreo,$usuario );
- $mail->MsgHTML("Usted Tiene Un Nuevo Caso Asignado Por : ".$usuarioEmisor." Asunto: $asunto");
- if(!$mail->Send()){
- $this->error = true;
- $this->mailerror = $mail->ErrorInfo;
- }
- }
- $tmp = new CasoCorreoTmp();
- $sel = $tmp->find_all_by_sql("SELECT * FROM caso_correo_tmp WHERE usuario = ".Session::get('usuario_id'));
- $mail = new PHPMailer();
- foreach($sel as $s){
- $mail->IsSMTP();
- $mail->SMTPAuth = false;
- $mail->Host = "192.168.10.1";
- $mail->Username = "hwalteros";
- $mail->Password = "123";
- $mail->From = "info@quinterossa.com";
- $mail->FromName = 'Informacion Quinteros S.A.';
- $mail->Subject = "Informacion CRM";
- $mail->AddAddress($s->correo);
- $mail->MsgHTML("Se Asigno Un Nuevo Caso a $usuario Por : ".$usuarioEmisor." Asunto: $asunto");
- if(!$mail->Send()){
- $this->error = true;
- $this->mailerror = $mail->ErrorInfo;
- }
- }
- $tmp->sql("DELETE FROM caso_correo_tmp WHERE usuario = ".Session::get('usuario_id'));
- }else{
- $this->error = true;
- }
- $this->set_response('view');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement