function processAllEmails($mailbox, $emails, $rucReceptor) { $returnArray = array("status" => true, "html" => ""); $handlerUserCore = new UserCore(); rsort($emails); $returnArray["html"] .= ' <table class="table table-condensed table-striped"> <thead> <tr> <th>ID</th> <th>Remitente</th> <th>Fecha</th> <th>Docs.</th> <th>Estado</th> <th>Proc.</th> </tr> </thead> <tbody>'; foreach ($emails as $email_number) { $status = ''; // Traer datos generales de e-mail $overview = imap_fetch_overview($mailbox, $email_number, 0); //$message = imap_fetchbody($mailbox, $email_number, 2); $structure = imap_fetchstructure($mailbox, $email_number); $attachments = getEmailAttachments($mailbox, $email_number, $structure); $returnArray["html"] .= '<tr>'; $returnArray["html"] .= '<td style="font-size: 11px;">' . $email_number . '</td>'; $returnArray["html"] .= '<td style="font-size: 11px;">' . $overview[0]->from . '</td>'; $returnArray["html"] .= '<td style="font-size: 11px;">' . date("Y-m-d", strtotime($overview[0]->date)) . '</td>'; $returnArray["html"] .= '<td style="font-size: 11px;">' . count($attachments) . '</td>'; $status .= '<ul class="pointmark" style="margin: 0px;">'; if (count($attachments) > 0) { // Leer cada adjunto XML y procesarlo foreach ($attachments as $attachment) { if (strtolower($attachment["xml_extension"]) == "xml") { $validArray = processXmlString($attachment["xml_attachment"], $attachment["pdf_attachment"], $attachment["pdf_extension"], $rucReceptor, $attachment["xml_basename"]); $processed = $validArray["status"]; } if ($processed) { $status .= "<li>Adjunto XML (" . $attachment["xml_basename"] . "): Procesado con éxito</li>"; } else { $status .= "<li>" . $validArray["html"] . "</li>"; } } } else { $status .= "<li>E-mail no tiene adjuntos</li>"; $processed = false; $usuarioDefault = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_DEF_ASIGNACION"); $usuarioData = $handlerUserCore->getUserData($usuarioDefault); $email = $usuarioData["user_email"]; $html = 'Estimado usuario<br /><br /> Le informamos que tiene un nuevo documento electrónico descargable en el buzón. Por favor ingrese a revisarlo y darle tratamiento'; MailController::sendGeneralMail([["email" => $email]], "Nuevo documento electrónico descargable", $html); } $status .= '</ul>'; if (FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_MC_PRUEBAS") != "1") { setEmailRead($email_number, $rucReceptor); } else { imap_clearflag_full($mailbox, $email_number, "\\Seen"); } $returnArray["html"] .= '<td style="font-size: 11px;">' . $status . '</td>'; if ($processed) { $returnArray["html"] .= '<td><span class="awe-ok" style="color: #6b9b20;"></span></td>'; } else { $returnArray["html"] .= '<td><span class="awe-remove" style="color: #d43f3f;"></span></td>'; } $returnArray["html"] .= '</tr>'; } $returnArray["html"] .= "</table>"; return $returnArray; }
function getHtmlDistribucion($cabeceraRecord) { $handlerTaskCore = new TaskCore(); $handlerUserCore = new UserCore(); $flowSettingsHandler = new FlowSettingsCore(); $handlerDocumentoCabeceraCore = new DocumentoCabeceraCore(); $handlerDocumentoLineaCore = new DocumentoLineaCore(); $handlerDistribucionCabeceraCore = new DistribucionCabeceraCore(); $handlerDistribucionLineaCore = new DistribucionLineaCore(); $handlerRequestMetadataCore = new RequestMetadataCore(); $cabeceraData = $handlerDocumentoCabeceraCore->getRecordById($cabeceraRecord["id"]); $lineasData = $handlerDocumentoLineaCore->getRecordsByFieldFilter(array(array("field" => "id_documento", "type" => "i", "value" => $cabeceraRecord["id"]))); $numero_req = $handlerRequestMetadataCore->getVariable($cabeceraRecord["ef_id"], "RDE-NUMERO-REQ"); $numero_oc = $handlerRequestMetadataCore->getVariable($cabeceraRecord["ef_id"], "RDE-NUMERO-OC"); $reclamo_seguro = $handlerRequestMetadataCore->getVariable($cabeceraRecord["ef_id"], "RDE-RECLAMO-SEGURO"); $comentarios = $handlerRequestMetadataCore->getVariable($cabeceraRecord["ef_id"], "RDE-COMENTARIO"); $dataPasosAprobador1 = $handlerTaskCore->getTaskDataByRequestFlowStep($cabeceraRecord["ef_id"], $_SESSION["user_flow"], $flowSettingsHandler->getSettingValue($_SESSION["user_flow"], "RDE_STEP_APROBACION_1")); $dataPasosAprobador2 = $handlerTaskCore->getTaskDataByRequestFlowStep($cabeceraRecord["ef_id"], $_SESSION["user_flow"], $flowSettingsHandler->getSettingValue($_SESSION["user_flow"], "RDE_STEP_APROBACION_2")); $aprobador1 = ""; $aprobador2 = ""; if (count($dataPasosAprobador1) > 0) { $dataAprobador1 = $handlerUserCore->getUserData($dataPasosAprobador1[0]["task_assignedto"]); $aprobador1 = $dataAprobador1["user_name"]; } if (count($dataPasosAprobador2) > 0) { $dataAprobador2 = $handlerUserCore->getUserData($dataPasosAprobador2[0]["task_assignedto"]); $aprobador2 = $dataAprobador2["user_name"]; } $lineasHtml = ""; foreach ($lineasData as $linea) { $distribucionLineaHtml = ''; if ($cabeceraRecord["tipo_distribucion"] == "detallada") { $lineasDistribucionData = $handlerDistribucionLineaCore->getRecordsByFieldFilter(array(array("field" => "id_documento_linea", "type" => "i", "value" => $linea["id"]))); foreach ($lineasDistribucionData as $lineaDist) { $distribucionLineaHtml .= $lineaDist["cc_id"] . ' : ' . $lineaDist["porcentaje"] . '% ($ ' . number_format($lineaDist["valor_distribuido"], 2, '.', '') . ')<br />'; } } $lineasHtml .= '<tr>'; $lineasHtml .= '<td>' . $linea["descripcion"] . '</td>'; $lineasHtml .= '<td>' . number_format($linea["cantidad"], 2, '.', '') . '</td>'; $lineasHtml .= '<td>$ ' . number_format($linea["precioUnitario"], 2, '.', '') . '</td>'; $lineasHtml .= '<td>' . $distribucionLineaHtml . '</td>'; $lineasHtml .= '<td>$ ' . number_format($linea["precioTotalSinImpuesto"], 2, '.', '') . '</td>'; $lineasHtml .= '</tr>'; } $lineasHtml .= '<tr> <td colspan="4" class="subtitle" style="text-align: right; background-color: #eee;">Subtotal IVA 12%</td> <td>$ ' . number_format($cabeceraData["subtotalIva12"], 2, '.', '') . '</td> </tr>'; $lineasHtml .= '<tr> <td colspan="4" class="subtitle" style="text-align: right; background-color: #eee;">IVA 12%</td> <td>$ ' . number_format($cabeceraData["subtotalIva12"], 2, '.', '') . '</td> </tr>'; $lineasHtml .= '<tr> <td colspan="4" class="subtitle" style="text-align: right; background-color: #eee;">Subtotal IVA 0%</td> <td>$ ' . number_format($cabeceraData["subtotalIva0"], 2, '.', '') . '</td> </tr>'; $lineasHtml .= '<tr> <td colspan="4" class="subtitle" style="text-align: right; background-color: #eee;">Subtotal Sin IVA</td> <td>$ ' . number_format($cabeceraData["subtotalSinIva"], 2, '.', '') . '</td> </tr>'; $lineasHtml .= '<tr> <td colspan="4" class="subtitle" style="text-align: right; background-color: #eee;">Importe Total</td> <td>$ ' . number_format($cabeceraData["importeTotal"], 2, '.', '') . '</td> </tr>'; $distribucionGlobalHtml = ''; if ($cabeceraData["distribucion"] == "global") { $cabeceraDistribucionData = $handlerDistribucionCabeceraCore->getRecordsByFieldFilter(array(array("field" => "id_documento", "type" => "i", "value" => $cabeceraData["id"]))); if (count($cabeceraDistribucionData) > 0) { $distribucionGlobalHtml .= '<h3>Distribución global</h3> <table style="width: 100%;"> <tr style="background-color: #ddd;"> <td class="strong centered subtitle" style="width: 70%; font-weight: bold;">Centro de costo</td> <td class="strong centered subtitle" style="width: 15%; font-weight: bold;">Porcentaje</td> <td class="strong centered subtitle" style="width: 15%; font-weight: bold;">Valor distribuido</td> </tr>'; foreach ($cabeceraDistribucionData as $cabecera) { $distribucionGlobalHtml .= '<tr>'; $distribucionGlobalHtml .= '<td style="width: 70%;">' . $cabecera["cc_id"] . ' - ' . $cabecera["cc_nombre"] . '</td>'; $distribucionGlobalHtml .= '<td style="width: 15%;">' . $cabecera["porcentaje"] . '</td>'; $distribucionGlobalHtml .= '<td style="width: 15%;">$ ' . number_format($cabecera["valor_distribuido"], 2, '.', '') . '</td>'; $distribucionGlobalHtml .= '</tr>'; } $distribucionGlobalHtml .= ' </table>'; } } $html = ' <table style="width: 100%;"> <tr> <td><strong>Tipo: </strong></td> <td>Factura</td> <td><strong>Número: </strong></td> <td>' . $cabeceraRecord["factura"] . '</td> <td><strong>Fecha: </strong></td> <td>' . $cabeceraRecord["fecha"] . '</td> </tr> <tr> <td><strong>Proveedor: </strong></td> <td>' . $cabeceraRecord["proveedor"] . '</td> <td><strong>N° requisición: </strong></td> <td>' . $numero_req . '</td> <td><strong>N° orden de compra: </strong></td> <td>' . $numero_oc . '</td> </tr> <tr> <td><strong>Comentarios: </strong></td> <td colspan="5">' . $comentarios . '</td> </tr> <tr> <td colspan="6" class="unbordered"> </td> </tr> <tr> <td colspan="6"> <h3>Detalles de documento</h3> <table style="width: 100%;"> <tr style="background-color: #ddd;"> <td><strong>Descripción</strong></td> <td style="width: 10%;"><strong>Cantidad</strong></td> <td style="width: 10%;"><strong>V. Uni</strong>.</td> <td><strong>Distribución</strong></td> <td style="width: 10%;"><strong>Total</strong></td> </tr> ' . $lineasHtml . ' </table> <br /> ' . $distribucionGlobalHtml . ' <br /> </td> </tr> <tr> <td colspan="6" class="unbordered"> </td> </tr> </table> '; return $html; }