Ajustando relatorio de movimentações

This commit is contained in:
Kenio 2025-09-02 13:54:10 -03:00
parent f4df29469a
commit 3cd12cf4ce
2 changed files with 267 additions and 2 deletions

View file

@ -142,7 +142,7 @@ try{
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 90px">PAGAMENTO</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 90px">PAGAMENTO</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center">DESCRIÇÃO</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center">DESCRIÇÃO</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center">CNS</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center">CNS</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center">Observação</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center">OBSERVAÇÃO</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">VALOR R$</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">VALOR R$</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">MULTA R$</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">MULTA R$</td>';
$header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">TAXAS R$</td>'; $header .= ' <td style="color: #FFF; padding: 4px; text-align: center; width: 60px">TAXAS R$</td>';
@ -193,7 +193,7 @@ try{
$body .= ' <td style="text-align: left">'.$Result->cns.'</td>'; $body .= ' <td style="text-align: left">'.$Result->cns.'</td>';
$body .= ' <td style="text-align: left">'.( isset($Result->note) ? $Result->note : '' ).'</td>'; $body .= ' <td style="text-align: left">'.( isset($Result->note) ? $Result->note : '' ).'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.number_format($Result->movement_value, 2, ',', '.').'</td>'; $body .= ' <td style="text-align: right; width: 60px">'.number_format($Result->movement_value, 2, ',', '.').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid-$Result->movement_value), 2, ',', '.') : '').'</td>'; $body .= ' <td style="text-align: right; width: 60px color:red">- '.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid-$Result->movement_value), 2, ',', '.') : '').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_registration_tariff) ? number_format($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff, 2, ',', '.') : '').'</td>'; $body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_registration_tariff) ? number_format($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff, 2, ',', '.') : '').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid+($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff)), 2, ',', '.') : number_format($Result->movement_value, 2, ',', '.')).'</td>'; $body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid+($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff)), 2, ',', '.') : number_format($Result->movement_value, 2, ',', '.')).'</td>';
$body .= ' </tr>'; $body .= ' </tr>';

View file

@ -0,0 +1,265 @@
<?php
/** Carregamento da classe de gerar PDF */
require_once('vendor/library/mpdf/vendor/autoload.php');
/** Importação de classes */
use vendor\model\FinancialMovements;
use vendor\controller\financial_movements\FinancialMovementsValidate;
try{
/** Verifica se o token de acesso é válido */
if($Main->verifyToken()){
/** Instânciamento de classes */
$FinancialMovements = new FinancialMovements();
$FinancialMovementsValidate = new FinancialMovementsValidate();
/** Parametros de filtro por company */
$companyId = isset($_SESSION['USERSCOMPANYID']) ? (int)$_SESSION['USERSCOMPANYID'] : 0;
/** Parametros de entrada */
$search = isset($_POST['search']) ? (string)filter_input(INPUT_POST,'search', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$type = isset($_POST['type']) ? (string)filter_input(INPUT_POST,'type', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$status = isset($_POST['status']) ? (int)filter_input(INPUT_POST,'status', FILTER_SANITIZE_SPECIAL_CHARS) : 0;
$dateStart = isset($_POST['dateStart']) ? (string)filter_input(INPUT_POST,'dateStart', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$dateEnd = isset($_POST['dateEnd']) ? (string)filter_input(INPUT_POST,'dateEnd', FILTER_SANITIZE_SPECIAL_CHARS) : '';
$printType = isset($_POST['printType']) ? (int)filter_input(INPUT_POST,'printType', FILTER_SANITIZE_SPECIAL_CHARS) : 0;
$orientation = null;
$dir = 'temp/';
/** Controles */
$i=0;
$total = '0.00';
$totalGeneral = '0.00';
$totalReceivables = '0.00';
$totalOutputs = '0.00';
$totalEntries = '0.00';
$qtdeOutputs = '0.00';
$qtdeEntries = '0.00';
$totalOutputsPaid = '0.00';
$totalEntriesPaid = '0.00';
$header = null;
$totalFees = '0.00';
/** Verifica se existe consulta informada para validar os campos */
/** Verifica se a consulta foi informada */
if( !empty($search) ){
/** Valida os campos de entrada */
$FinancialMovementsValidate->setSearch($search);
}
/** Verifica se o tipo da consulta foi informada */
if( !empty($type) ){
$FinancialMovementsValidate->setType($type);
}
/** Verifica se o status da consulta foi informada */
if( $status > 0 ){
$FinancialMovementsValidate->setStatusSearch($status);
}
/** Verifica se a data inicial da consulta foi informada */
if( !empty($dateStart) ){
$FinancialMovementsValidate->setDateStart($dateStart);
}
/** Verifica se a data final da consulta foi informada */
if( !empty($dateEnd) ){
$FinancialMovementsValidate->setDateEnd($dateEnd);
}
/** Verifico a existência de erros */
if (!empty($FinancialMovementsValidate->getErrors())) {
/** Mensagem de erro */
throw new Exception($FinancialMovementsValidate->getErrors(), 0);
} else {
/** Consulta a quantidade de registros */
$NumberRecords = $FinancialMovements->Count($companyId,
$FinancialMovementsValidate->getSearch(),
$FinancialMovementsValidate->getType(),
$FinancialMovementsValidate->getStatusSearch(),
$FinancialMovementsValidate->getDateStart(),
$FinancialMovementsValidate->getDateEnd())->qtde;
/** Verifico a quantidade de registros localizados */
if ($NumberRecords > 0){
/** Aumenta o uso de memória */
ini_set('memory_limit','512M');
/**Carrega a biblioteca par agerar o arquivo*/
chdir('library/Excel/phpxls');
require_once 'Writer.php';
chdir('..');
/**Instancia da classe*/
$workbook = new Spreadsheet_Excel_Writer(date("Y-m-d").'-'.rand(999,99999).'.xls');
/**Defino o header da planilha*/
$header =& $workbook->addFormat();
$header->setBottom(2);//thick
$header->setBold();
$header->setBgColor('black');
$header->setFgColor(22);
$header->setColor('black');
$header->setFontFamily('Arial');
$header->setSize(8);
$header->setAlign('center');
//Criação da página
$worksheet =& $workbook->addWorksheet("Lista");
//Defino o body da planilha
$body =& $workbook->addFormat();
$body->setColor('black');
$body->setFontFamily('Arial');
$body->setSize(8);
//Definições das colunas
$worksheet->setColumn(0,0,30);//Coluna inicial, coluna final, largura
$worksheet->setColumn(1,1,30);
$worksheet->setColumn(2,2,5);
$worksheet->setColumn(3,3,10);
$worksheet->setColumn(4,5,12);
//Escrevendo o header da planilha
$worksheet->write(0, 0, "REFERÊNCIA", $header);//Linha, coluna, label, parametros
$worksheet->write(0, 1, "VENCIMENTO", $header);
$worksheet->write(0, 2, "PAGAMENTO", $header);
$worksheet->write(0, 3, "DESCRIÇÃO", $header);
$worksheet->write(0, 4, "CNS", $header);
$worksheet->write(0, 4, "OBSERVAÇÃO", $header);
$worksheet->write(0, 4, "VALOR R$", $header);
$worksheet->write(0, 4, "MULTA R$", $header);
$worksheet->write(0, 4, "TAXAS R$", $header);
$worksheet->write(0, 4, "TOTAL R$", $header);
$line=1;//Linha inicial
$col=0;//Coluna inicial
/** Consulta as movimentações cadastradas*/
$FinancialMovementsResult = $FinancialMovements->All($companyId, 0, 0,
$FinancialMovementsValidate->getSearch(),
$FinancialMovementsValidate->getType(),
$FinancialMovementsValidate->getStatusSearch(),
$FinancialMovementsValidate->getDateStart(),
$FinancialMovementsValidate->getDateEnd());
foreach($FinancialMovementsResult as $FinancialMovementsKey => $Result){
/** Calcula o total de taxas */
$totalFees += $Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff;
$body .= ' <tr style="'.($i % 2 == 0 ? 'background-color: #f2f2f2;' : '').'">';
$body .= ' <td style="text-align: center; width: 90px">'.$Result->movement_reference.'</td>';
$body .= ' <td style="text-align: center; width: 90px">'.date('d/m/Y', strtotime($Result->movement_date_scheduled)).'</td>';
$body .= ' <td style="text-align: center; width: '.($FinancialMovementsValidate->getStatusSearch() == 1 ? '120' : '90').'px">'.(isset($Result->movement_date_paid) ? date('d/m/Y', strtotime($Result->movement_date_paid)) : ($Main->CheckDay($Result->movement_date_scheduled) > 1 ? $Main->diffDate($Result->movement_date_scheduled, date('Y-m-d')).' dia(s) de atraso' : '')).'</td>';
$body .= ' <td style="text-align: left">'.$Result->description.'</td>';
$body .= ' <td style="text-align: left">'.$Result->cns.'</td>';
$body .= ' <td style="text-align: left">'.( isset($Result->note) ? $Result->note : '' ).'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.number_format($Result->movement_value, 2, ',', '.').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid-$Result->movement_value), 2, ',', '.') : '').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_registration_tariff) ? number_format($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff, 2, ',', '.') : '').'</td>';
$body .= ' <td style="text-align: right; width: 60px">'.( isset($Result->movement_value_paid) ? number_format(($Result->movement_value_paid+($Result->movement_value_registration_tariff+$Result->movement_value_settlement_tariff)), 2, ',', '.') : number_format($Result->movement_value, 2, ',', '.')).'</td>';
$body .= ' </tr>';
$i++;
/** Contabiliza o total geral */
$totalGeneral += isset($Result->movement_value_paid) ? $Result->movement_value_paid : $Result->movement_value;
}
$body .= ' </tbody>';
$body .= '</table>';
$body .= '<br/>';
$body .= 'Total R$ '.number_format($totalGeneral, 2, ',', '.').'<br/>';
$body .= 'Total Taxas R$ '.number_format($totalFees, 2, ',', '.').'<br/>';
$body .= 'Total Geral R$ '.number_format(($totalGeneral-$totalFees), 2, ',', '.').'<br/>';
/** Acrescenta os dados ao corpo do relatório */
$mpdf->WriteHTML($body);
/** Nome que será dado ao relatório */
$nameFile = 'IMPRESSAO-RELATORIO-MOVIMENTACAO-FINANCEIRA-'. date('d-m-Y-H-i-s').'.pdf';
/** Salva o relatório em uma pasta temporária */
$mpdf->Output($dir.$nameFile);
/** Verifica se o arquivo foi gerado com sucesso */
if(is_file($dir.$nameFile)){
/** Se não houver erros
* envio o relatório para a tela
*/
$result = [
'cod' => 98,
'title' => 'Visualizando o arquivo do boleto',
'file' => $dir.$nameFile
];
/** Envio **/
echo json_encode($result);
/** Paro o procedimento **/
exit;
} else {
/** Informo */
throw new InvalidArgumentException('Não foi possivel gerar o relatório', 0);
}
} else {
/** Informo */
throw new InvalidArgumentException('Não há registros a serem listados', 0);
}
}
/** Caso o token de acesso seja inválido, informo */
}else{
/** Informa que o usuário precisa efetuar autenticação junto ao sistema */
$authenticate = true;
/** Informo */
throw new InvalidArgumentException('Sua sessão expirou é necessário efetuar nova autenticação junto ao sistema', 0);
}
}catch(Exception $exception){
/** Preparo o formulario para retorno **/
$result = [
'cod' => 0,
'message' => '<div class="alert alert-danger" role="alert">'.$exception->getMessage().'</div>',
'title' => 'Atenção',
'type' => 'exception',
'authenticate' => $authenticate
];
/** Envio **/
echo json_encode($result);
/** Paro o procedimento **/
exit;
}