/** * Genera un listado en PDF con todos clientes del comercial * separados por dia (el rutero) */ public function HojaLlamadasAction() { if ($this->values['permisos']['permisosModulo']['LI']) { $idComercial = $this->request[2]; $comercial = new Agentes($idComercial); $dia = $this->request[3]; $dias = new DiasSemana($dia); $opciones = array('title' => 'Hoja de llamadas para el ' . strtoupper($dias->getDescripcion()) . ' del comercial ' . strtoupper($comercial->getNombre())); unset($comercial); unset($dias); //CREAR EL DOCUMENTO------------------------------------------------------------- $pdf = new HojaLlamadasPDF('L', 'mm', 'A4', $opciones); //$pdf->SetTopMargin($MEDIDAS['MargenSup']); //$pdf->SetLeftMargin($MEDIDAS['MargenIzq']); $pdf->SetAuthor("Informatica ALBATRONIC, SL"); $pdf->SetTitle('Hoja de llamadas Ventas'); $pdf->AliasNbPages(); $pdf->SetFillColor(210); $pdf->AddPage(); $pdf->SetAutoPageBreak(1, 15); $lis = new $this->entity(); $rows = $lis->cargaCondicion("Id", "IDComercial='{$idComercial}' and Dia='{$dia}'", "OrdenCliente,IDZona ASC"); unset($lis); //CUERPO------------------------------------------------------------------------- $pdf->SetFont('Courier', '', 8); foreach ($rows as $value) { $datos = new $this->entity($value['Id']); $pdf->Cell(10, 6, "", 0, 0); $pdf->Cell(100, 6, $pdf->DecodificaTexto($datos->getIDCliente()->getRazonSocial() . " - " . $datos->getIDCliente()->getNombreComercial(), 59), 0, 0); $pdf->Cell(20, 6, $pdf->DecodificaTexto($datos->getIDCliente()->getIDPoblacion()->getMunicipio(), 11), 0, 0); $pdf->Cell(45, 6, trim($datos->getIDCliente()->getTelefono() . " " . $datos->getIDCliente()->getMovil()), 0, 0); $pdf->Cell(10, 6, $datos->getIDCliente()->getLimiteRiesgo(), 0, 0, "R"); $pdf->Ln(); $dEntrega = new ClientesDentrega(); $direcciones = $dEntrega->cargaCondicion("IDDirec", "IDCliente='{$datos->getIDCliente()->getIDCliente()}' and IDZona='{$datos->getIDZona()->getIDZona()}'"); foreach ($direcciones as $direccion) { $dEntrega = new ClientesDentrega($direccion['IDDirec']); $pdf->Cell(15, 4, $dEntrega->getHorarioLlamadas(), 0, 0); $pdf->Cell(0, 4, $dEntrega->getDireccion(), 0, 1); } unset($dEntrega); $pdf->Cell(0, 3, str_repeat("-", 159), 0, 1); } unset($datos); $archivo = "docs/docs" . $_SESSION['emp'] . "/pdfs/" . md5(date('d-m-Y H:i:s')) . ".pdf"; $pdf->Output($archivo, 'F'); unset($pdf); $this->values['archivo'] = $archivo; return array('template' => '_global/listadoPdf.html.twig', 'values' => $this->values); } else { return array('template' => '_global/forbiden.html.twig'); } }
/** * Envia por email el parte de elaboracion en formato PDF * @return <type> */ public function enviarAction() { if ($this->request['accion'] == 'Enviar') { $para = $this->request['Para']; $de = $this->request['De']; $deNombre = $this->request['DeNombre']; $asunto = $this->request['Asunto']; $mensaje = $this->request['Mensaje']; $adjuntos = array($this->request['Adjunto']); $envio = new Mail(); $this->values['resultadoEnvio'] = $envio->send($para, $de, $deNombre, $asunto, $mensaje, $adjuntos); unset($envio); } else { $usuario = new Agentes($_SESSION['usuarioPortal']['Id']); $datos = new ManufacCab($this->request['ManufacCab']['IDManufac']); $formatos = DocumentoPdf::getFormatos('parteElaboracion'); $formato = $this->request['Formato']; if ($formato == '') { $formato = 0; } $this->values['archivo'] = $this->generaPdf('parteElaboracion', array('0' => $datos->getIDManufac()), $formato); $this->values['email'] = array('Para' => $datos->getIDElaborador()->getEMail(), 'De' => $usuario->getEMail(), 'DeNombre' => $usuario->getNombre(), 'Cc' => '', 'Asunto' => 'Parte de Elaboración n. ' . $datos->getIDManufac(), 'Formatos' => $formatos, 'Formato' => $formato, 'Mensaje' => 'Le adjunto el parte de elaboración ' . $datos->getIDManufac() . "\n\nUn saludo.", 'idManufac' => $datos->getIDManufac()); unset($usuario); unset($datos); } return parent::enviarAction(); }
/** * Devuelve un array con los agentes que son CAMARISTAS (ROL=3) * y están adscritos a la empresa y sucursal indicada. * Si el agente en curso es camarista, solo se mostrará el mismo. * * @param integer $idEmpresa Opcional * @param integer $idSucursal Opcional * @return array */ public function getCamaristas($idEmpresa = '', $idSucursal = '') { $usuario = new Agentes($_SESSION['usuarioPortal']['Id']); switch ($usuario->getIDRol()->getIDTipo()) { case '3': // ROLL CAMARISTA $camaristas[] = array('Id' => $usuario->getIDAgente(), 'Value' => $usuario->getNombre()); break; default: // RESTO DE ROLES //if ($idEmpresa == '') // $idEmpresa = $_SESSION['emp']; if ($idSucursal == '') { $idSucursal = $_SESSION['suc']; } $em = new EntityManager($this->getConectionName()); $link = $em->getDbLink(); if (is_resource($link)) { $query = "select IDAgente as Id, Nombre as Value from {$this->getTableName()} where " . "(a.IDAgente <> 1) AND " . "(Rol='3') AND " . "(Activo='1') AND ( " . "(IDSucursal='{$idSucursal}') OR isnull(IDSucursal))"; $em->query($query); $camaristas = $em->fetchResult(); $em->desConecta(); } unset($em); break; } unset($usuario); return $camaristas; }
/** * Devuelve un array con los agentes que son CAMARISTAS (ROL=3) * y están adscritos a la empresa y sucursal indicada. * Si el agente en curso es camarista, solo se mostrará el mismo. * * @param integer $idEmpresa Opcional * @param integer $idSucursal Opcional * @return array */ public function getCamaristas($idEmpresa = '', $idSucursal = '') { $usuario = new Agentes($_SESSION['usuarioPortal']['Id']); switch ($usuario->getRol()->getIDTipo()) { case '3': // ROLL CAMARISTA $camaristas[] = array('Id' => $usuario->getIDAgente(), 'Value' => $usuario->getNombre()); break; default: // RESTO DE ROLES if ($idEmpresa == '') { $idEmpresa = $_SESSION['emp']; } if ($idSucursal == '') { $idSucursal = $_SESSION['suc']; } $em = new EntityManager("empresas"); $link = $em->getDbLink(); if (is_resource($link)) { $query = "select IDAgente as Id, Nombre as Value from agentes where " . "(Rol='3') AND " . "(Activo='1') AND ( " . "(IDEmpresa='" . $idEmpresa . "' and IDSucursal='" . $idSucursal . "') OR " . "isnull(IDEmpresa) OR " . "(IDEmpresa='" . $idEmpresa . "' AND isnull(IDSucursal)) ) ORDER BY Nombre"; $em->query($query); $camaristas = $em->fetchResult(); $em->desConecta(); } unset($em); break; } unset($usuario); return $camaristas; }
/** * Importar el contenido del archivo $filename, genera un archivo log * cuyo path devuelve. * * Comprueba la existencias de los lotes y ubicaciones indicados * Si no existe el lote, lo crea. * * @param string $fileName * @return string El path al archivo log generado en la importación */ private function importarArchivo($fileName) { set_time_limit(0); $archivoImportar = new Archivo($fileName); if ($archivoImportar->open("r")) { // Abrir en modo escritura el archivo de log. $usuario = new Agentes($_SESSION['usuarioPortal']['Id']); $pathArchivoLog = "docs/docs" . $_SESSION['emp'] . "/tmp/logImportarInventario.txt"; $archivoLog = new Archivo($pathArchivoLog); $archivoLog->open("w"); $archivoLog->writeLine("IMPORTACIÓN DE ARCHIVO DE INVENTARIO"); $archivoLog->writeLine("FECHA: " . date('d-m-Y H:i:s')); $archivoLog->writeLine("ARCHIVO: " . $archivoImportar->getBaseName()); $archivoLog->writeLine("USUARIO: " . $usuario->getNombre()); $archivoLog->writeLine(str_repeat("-", 50)); unset($usuario); $fila = 1; $fallidos = 0; $cargados = 0; $primeraLinea = $archivoImportar->readLine(); // Pongo los títulos con la primera letra en mayúscula y le doy // la vuelta al array $titulos = $primeraLinea; foreach ($titulos as $key => $value) { $titulos[$key] = ucwords(trim($value)); } $titulos = array_flip($titulos); while (($linea = $archivoImportar->readLine()) !== FALSE) { $fila++; $lineaInventario = new InventariosLineas(); $lineaInventario->setIDInventario($this->request['InventariosCab']['IDInventario']); // Buscar el id del articulo a partir del codigo $articulo = new Articulos(); $articulo = $articulo->find("Codigo", trim($linea[$titulos['Codigo']])); $lineaInventario->setIDArticulo($articulo->getIDArticulo()); // Buscar el id del lote a partir del nombre de lote $nombreLote = trim($linea[$titulos['Lote']]); $lote = new Lotes(); $rows = $lote->cargaCondicion("IDLote", "IDArticulo='{$articulo->getIDArticulo()}' and Lote='" . $nombreLote . "'"); $idLote = $rows[0]['IDLote']; // Si no existe el lote, lo creo. if ($idLote == '' and $nombreLote != '') { $lote->setIDArticulo($articulo->getIDArticulo()); $lote->setLote($nombreLote); $idLote = $lote->create(); } $lineaInventario->setIDLote($idLote); // Buscar la id de la ubicacion del almacen en curso $ubicacion = new AlmacenesMapas(); $rows = $ubicacion->cargaCondicion("IDUbicacion", "IDAlmacen='{$this->request['InventariosCab']['IDAlmacen']}' and Ubicacion='" . trim($linea[$titulos['Ubicacion']]) . "'"); $lineaInventario->setIDUbicacion($rows[0]['IDUbicacion']); // A los valores numéricos les cambio la coma decimal por el punto $lineaInventario->setStock(str_replace(",", ".", $linea[$titulos['Stock']])); $lineaInventario->setCajas(str_replace(",", ".", $linea[$titulos['Cajas']])); $lineaInventario->validaLogico(); if (count($lineaInventario->getErrores()) == 0) { $lineaInventario->create(); $cargados++; } else { // Si hay errores de validacion muestro la linea y los errores $fallidos++; $archivoLog->writeLine("Error en línea: " . $fila); foreach ($linea as $key => $value) { $string = "\t" . $primeraLinea[$key] . " : " . $value; $archivoLog->writeLine($string); } foreach ($lineaInventario->getErrores() as $error) { $archivoLog->writeLine("\t* " . $error); } } } $archivoLog->writeLine("" . str_repeat("-", 50)); $archivoLog->writeLine("Total registros : " . ($fila - 1)); $archivoLog->writeLine("Registros cargados: " . $cargados); $archivoLog->writeLine("Registros fallidos: " . $fallidos); $archivoImportar->close(); $archivoLog->close(); unset($archivoLog); } else { $resultado[] = "El archivo de importación no existe"; } unset($archivoImportar); return $pathArchivoLog; }
/** * Envia por email el parte de elaboracion en formato PDF * @return <type> */ public function enviarAction() { if ($this->request['accion'] == 'Enviar') { $para = $this->request['Para']; $de = $this->request['De']; $deNombre = $this->request['DeNombre']; $asunto = $this->request['Asunto']; $mensaje = $this->request['Mensaje']; $adjuntos = array($this->request['Adjunto']); $envio = new Mail(); $this->values['resultadoEnvio'] = $envio->send($para, $de, $deNombre, $asunto, $mensaje, $adjuntos); unset($envio); } else { $usuario = new Agentes($_SESSION['usuarioPortal']['Id']); $datos = new TraspasosCab($this->request['TraspasosCab']['IDTraspaso']); $formatos = DocumentoPdf::getFormatos('ordenTraspaso'); $formato = $this->request['Formato']; if ($formato == '') { $formato = 0; } $this->values['archivo'] = $this->generaPdf('ordenTraspaso', array('0' => $datos->getIDTraspaso()), $formato); $this->values['email'] = array('Para' => $datos->getIDAlmacenDestino()->getEMail(), 'De' => $usuario->getEMail(), 'DeNombre' => $usuario->getNombre(), 'Cc' => '', 'Asunto' => 'Orden de traspaso n. ' . $datos->getNumeroTraspaso(), 'Formatos' => $formatos, 'Formato' => $formato, 'Mensaje' => 'Le adjunto el traspaso ' . $datos->getNumeroTraspaso() . "\n\nUn saludo.", 'idTraspaso' => $datos->getIDTraspaso()); unset($usuario); unset($datos); } return parent::enviarAction(); }