Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. public function saveCase(){
  2.  
  3. //Creamos el objeto
  4. $caso = new Cases();
  5. $historia = new CasoHistorial();
  6.  
  7. //Leemos Los Parametros Del Formulario
  8. $asunto = $this->post('subject');
  9. $fabrica = $this->post('fabrica_id');
  10. $cliente = $this->post('cliente_id');
  11. $subdistribuidor = $this->post('subdistri_id');
  12. $segmento = $this->post('segmento_id');
  13. $usuario_destino = $this->post('usuariodes_id');
  14. $usuario_emisor = $this->post('fabrica_id');
  15. $casotipo = $this->post('tipocaso_id');
  16. $file = $_FILES['file']['name'];
  17.  
  18. //Creamos el array con la informacion para insertar
  19. $values = array('asunto' => $asunto,
  20. 'id_fabrica' => $fabrica,
  21. 'id_cliente' => $cliente,
  22. 'id_subdistri' => $subdistribuidor,
  23. 'fecha_creacion' => date("Y-m-d"),
  24. 'id_caso_tipo' => $casotipo,
  25. 'id_usuario' => $usuario_destino,
  26. 'id_segmento' => $segmento,
  27. 'id_usuario_emisor' => Session::get('usuario_id'),
  28. 'estado' => 1);//Seteamos por defecto que el caso quda abierto
  29.  
  30.  
  31. $this->error = false;
  32.  
  33.  
  34. //insertamos los datos y verificamos que no hubo errores
  35.  
  36. if($caso->create($values)){
  37.  
  38. $id = $caso->maximum('id');
  39.  
  40. $this->casees = $acti = substr($this->post('act'), 0, -1);
  41.  
  42. $actividades = explode(";", $acti);
  43.  
  44. $this->i = 0;
  45.  
  46. foreach($actividades as $a){
  47.  
  48. $actividad = new CaseActividad();
  49.  
  50. $act = explode("|",$a);
  51.  
  52. $actividad_array = array(
  53. 'asunto' => $act[0],
  54. 'estado' => 2,//por defecto dejamos el estado en en progreso cuando creamos un caso
  55. 'fecha_inicio' => $act[2],
  56. //'comentario' => $act[3],
  57. 'hora' => $act[4],
  58. 'id_caso' => $id
  59. );
  60.  
  61. if(!$actividad->save($actividad_array)){
  62. $this->error = true;
  63. } else {
  64. //objecto de la tabla caso comentario
  65. $comentObj = new CasoComentario();
  66. $id = $actividad->maximum("id");
  67.  
  68. $commentInfo = array(
  69. 'comentario' => $act[3],
  70. 'fecha' => date('Y-m-d'),
  71. 'id_actividad' => $id
  72. );
  73.  
  74. $comentObj->create($commentInfo);
  75. }
  76. $this->i++;
  77. }
  78.  
  79. //relacionames el adjunto con el caso
  80. if(!empty($_FILES['file']['name'])){
  81.  
  82. $casoObj = new CasoActividadAdjunto();
  83.  
  84. $casoData = array(
  85. 'id_caso' => $id,
  86. 'nombre' => $_FILES['file']['name'],
  87. 'fecha_adjunto' => date('Y-m-d'),
  88. );
  89.  
  90. if(!$casoObj->create($casoData)){
  91.  
  92. $this->error = true;
  93. }
  94.  
  95. Upload::file('file');
  96.  
  97.  
  98. $casoHis = array(
  99. 'id_caso' => $id,
  100. 'history' => "Accion : Adjunto ".$_FILES['file']['name'] ." Creado Fecha: ".date("Y-m-d h:i:s")." Usuario: ".$usuario
  101. );
  102.  
  103. $historia->create($casoHis);
  104. }
  105.  
  106. //ingresamos que se creo un caso
  107. $usuarios = new Usuario();
  108. $allusers = $usuarios->find();
  109. $usuario = $this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'login');
  110.  
  111. $casoHis = array(
  112. 'id_caso' => $id,
  113. 'history' => "Accion : Caso Creado Fecha: ".date("Y-m-d h:i:s")." Usuario: ".$usuario
  114. );
  115.  
  116.  
  117. $historia->create($casoHis);
  118.  
  119. if(Session::get('usuario_id') != $usuario_destino){
  120.  
  121. $usuarioEmisor = $this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'nombre')." ".$this->findBy($allusers , Session::get('usuario_id'), 'idusuario', 'apellido');
  122. $usuario = $this->findBy($allusers , $usuario_destino, 'idusuario', 'nombre')." ". $this->findBy($allusers , $usuario_destino, 'idusuario', 'apellido');
  123. $usuarioCorreo = $this->findBy($allusers , $usuario_destino, 'idusuario', 'mail');
  124.  
  125. $mail = new PHPMailer();
  126. $mail->IsSMTP();
  127. $mail->SMTPAuth = false;
  128. $mail->Host = "192.168.10.1";
  129. $mail->Username = "hwalteros";
  130. $mail->Password = "123";
  131. $mail->From = "info@quinterossa.com";
  132. $mail->FromName = 'Informacion Quinteros S.A.';
  133.  
  134. $mail->Subject = "Usted Tiene Un Nuevo Caso Asignado Por : ".$usuarioEmisor;
  135. $mail->AddAddress($usuarioCorreo,$usuario );
  136. $mail->MsgHTML("Usted Tiene Un Nuevo Caso Asignado Por : ".$usuarioEmisor." Asunto: $asunto");
  137. if(!$mail->Send()){
  138. $this->error = true;
  139. $this->mailerror = $mail->ErrorInfo;
  140. }
  141. }
  142.  
  143. $tmp = new CasoCorreoTmp();
  144.  
  145. $sel = $tmp->find_all_by_sql("SELECT * FROM caso_correo_tmp WHERE usuario = ".Session::get('usuario_id'));
  146.  
  147. $mail = new PHPMailer();
  148.  
  149. foreach($sel as $s){
  150.  
  151. $mail->IsSMTP();
  152. $mail->SMTPAuth = false;
  153. $mail->Host = "192.168.10.1";
  154. $mail->Username = "hwalteros";
  155. $mail->Password = "123";
  156. $mail->From = "info@quinterossa.com";
  157. $mail->FromName = 'Informacion Quinteros S.A.';
  158. $mail->Subject = "Informacion CRM";
  159. $mail->AddAddress($s->correo);
  160. $mail->MsgHTML("Se Asigno Un Nuevo Caso a $usuario Por : ".$usuarioEmisor." Asunto: $asunto");
  161. if(!$mail->Send()){
  162. $this->error = true;
  163. $this->mailerror = $mail->ErrorInfo;
  164. }
  165. }
  166.  
  167. $tmp->sql("DELETE FROM caso_correo_tmp WHERE usuario = ".Session::get('usuario_id'));
  168. }else{
  169.  
  170. $this->error = true;
  171.  
  172. }
  173.  
  174.  
  175. $this->set_response('view');
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement