You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
715 lines
26 KiB
715 lines
26 KiB
unit urelPrestacaoAnaSin2;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
System.Classes, Vcl.Graphics, System.DateUtils,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, ZAbstractRODataset, ZDataset,
|
|
RLReport, Datasnap.DBClient, RLFilters, RLPDFFilter;
|
|
|
|
type
|
|
TrelPrestacaoAnaSin2 = class(TForm)
|
|
dtsTitulos: TDataSource;
|
|
zroqryTitulos: TZReadOnlyQuery;
|
|
relPrestacao2: TRLReport;
|
|
RLBand1: TRLBand;
|
|
RLPanel1: TRLPanel;
|
|
RLDBImage1: TRLDBImage;
|
|
RLPanel2: TRLPanel;
|
|
RLLabel14: TRLLabel;
|
|
RLMemo2: TRLMemo;
|
|
cdsSintetico: TClientDataSet;
|
|
zroqryTitulosTX_PRODUTO: TWideStringField;
|
|
zroqryTitulosDT_VENCIMENTO: TDateTimeField;
|
|
zroqryTitulosDT_PAGAMENTO: TDateTimeField;
|
|
zroqryTitulosVL_JUROS: TFloatField;
|
|
zroqryTitulosVL_MULTA: TFloatField;
|
|
zroqryTitulosVL_ENCARGOS: TFloatField;
|
|
zroqryTitulosVL_CORRIGIDO: TFloatField;
|
|
zroqryTitulosVL_DESC_PRINCIPAL: TFloatField;
|
|
zroqryTitulosID_TITULO: TIntegerField;
|
|
zroqryTitulosID_EMPRESA: TIntegerField;
|
|
zroqryTitulosATRASO: TIntegerField;
|
|
zroqryTitulosVL_RETIDO: TCurrencyField;
|
|
zroqryTitulosVL_REPASSE: TCurrencyField;
|
|
cdsSinteticoVL_TITULO: TCurrencyField;
|
|
cdsSinteticoVL_JUROS: TCurrencyField;
|
|
cdsSinteticoVL_MULTA: TCurrencyField;
|
|
cdsSinteticoVL_ENCARGOS: TCurrencyField;
|
|
cdsSinteticoVL_DESC_PRINCIPAL: TCurrencyField;
|
|
cdsSinteticoVL_CORRIGIDO: TCurrencyField;
|
|
cdsSinteticoVL_RETIDO: TCurrencyField;
|
|
cdsSinteticoVL_REPASSADO: TCurrencyField;
|
|
cdsSinteticoID_EMPRESA: TIntegerField;
|
|
zroqryTitulosTX_FANTASIA: TWideStringField;
|
|
cdsSinteticoTX_FANTASIA: TStringField;
|
|
RLBand4: TRLBand;
|
|
RLLabel27: TRLLabel;
|
|
RLLabel28: TRLLabel;
|
|
RLLabel29: TRLLabel;
|
|
RLLabel30: TRLLabel;
|
|
RLLabel31: TRLLabel;
|
|
RLLabel32: TRLLabel;
|
|
RLLabel33: TRLLabel;
|
|
RLLabel34: TRLLabel;
|
|
RLBand5: TRLBand;
|
|
RLDBText22: TRLDBText;
|
|
RLDBText24: TRLDBText;
|
|
RLDBText25: TRLDBText;
|
|
RLDBText26: TRLDBText;
|
|
RLDBText27: TRLDBText;
|
|
RLDBText28: TRLDBText;
|
|
RLDBText29: TRLDBText;
|
|
RLDBText32: TRLDBText;
|
|
RLBand6: TRLBand;
|
|
RLDBResult9: TRLDBResult;
|
|
RLDBResult10: TRLDBResult;
|
|
RLDBResult11: TRLDBResult;
|
|
RLDBResult12: TRLDBResult;
|
|
RLDBResult13: TRLDBResult;
|
|
RLDBResult14: TRLDBResult;
|
|
RLDBResult15: TRLDBResult;
|
|
RLLabel35: TRLLabel;
|
|
RLLabel36: TRLLabel;
|
|
RLLabel37: TRLLabel;
|
|
RLLabel38: TRLLabel;
|
|
RLLabel39: TRLLabel;
|
|
RLLabel40: TRLLabel;
|
|
RLLabel41: TRLLabel;
|
|
RLLabel42: TRLLabel;
|
|
RLLabel43: TRLLabel;
|
|
RLDBResult16: TRLDBResult;
|
|
RLDBText1: TRLDBText;
|
|
zroqryCredores: TZReadOnlyQuery;
|
|
zroqryCredoresID_EMPRESA: TIntegerField;
|
|
zroqryCredoresTX_NOME: TWideStringField;
|
|
zroqryCredoresTX_FANTASIA: TWideStringField;
|
|
zroqryCredoresTX_CNPJ: TWideStringField;
|
|
zroqryCredoresTX_IE: TWideStringField;
|
|
zroqryCredoresTX_ENDERECO: TWideStringField;
|
|
zroqryCredoresTX_COMPLEMENTO: TWideStringField;
|
|
zroqryCredoresID_CIDADE: TIntegerField;
|
|
zroqryCredoresTX_BAIRRO: TWideStringField;
|
|
zroqryCredoresID_ESTADO: TIntegerField;
|
|
zroqryCredoresTX_CEP: TWideStringField;
|
|
zroqryCredoresTX_TELEFONE: TWideStringField;
|
|
zroqryCredoresTX_EMAIL: TWideStringField;
|
|
zroqryCredoresTX_WEBSITE: TWideStringField;
|
|
zroqryCredoresNR_NUMERO: TIntegerField;
|
|
zroqryCredoresTX_IM: TWideStringField;
|
|
zroqryCredoresTL_OBSERVACOES: TWideMemoField;
|
|
zroqryCredoresID_REPASSE: TIntegerField;
|
|
zroqryCredoresTP_ENTRADA: TWideStringField;
|
|
zroqryCredoresPR_MULTA: TFloatField;
|
|
zroqryCredoresPR_JUROS: TFloatField;
|
|
zroqryCredoresNR_PARCELAS: TIntegerField;
|
|
zroqryCredoresPR_DESC_QUIT_PRIN: TFloatField;
|
|
zroqryCredoresPR_DESC_QUIT_JUROS: TFloatField;
|
|
zroqryCredoresPR_DESC_QUIT_MULTA: TFloatField;
|
|
zroqryCredoresPR_DESC_QUIT_IND_FIN: TFloatField;
|
|
zroqryCredoresPR_DESC_QUIT_COR: TFloatField;
|
|
zroqryCredoresPR_DESC_FINAN_PRIN: TFloatField;
|
|
zroqryCredoresPR_DESC_FINAN_JUROS: TFloatField;
|
|
zroqryCredoresPR_DESC_FINAN_MULTA: TFloatField;
|
|
zroqryCredoresPR_DESC_FINAN_IND_FIN: TFloatField;
|
|
zroqryCredoresPR_DESC_FINAN_COR: TFloatField;
|
|
zroqryCredoresPR_INDICADOR_FINANCEIRO: TFloatField;
|
|
zroqryCredoresPR_JUROS_PARCELAR: TFloatField;
|
|
zroqryCredoresPR_ENTRADA_MIN: TFloatField;
|
|
zroqryCredoresPR_ENTRADA_MAX: TFloatField;
|
|
zroqryCredoresTP_CHEQUE: TWideStringField;
|
|
zroqryCredoresTP_CRED: TWideStringField;
|
|
zroqryCredoresTP_DIN: TWideStringField;
|
|
zroqryCredoresID_ULTIMO_USUARIO: TIntegerField;
|
|
zroqryCredoresDT_HORA_ULTIMA_ATT: TDateTimeField;
|
|
fr_filterpdf: TRLPDFFilter;
|
|
zroqryTitulosTX_CNPJ: TWideStringField;
|
|
cdsSinteticoTX_CNPJ: TStringField;
|
|
RLSystemInfo1: TRLSystemInfo;
|
|
fr_date: TRLSystemInfo;
|
|
zroqryTitulosVL_TITULO: TCurrencyField;
|
|
frlbl_dep: TRLLabel;
|
|
zroqryCredoresID_DEPARTAMENTO: TIntegerField;
|
|
zroqryTitulosID_DEVEDOR: TIntegerField;
|
|
rotblRepasseFase: TZReadOnlyQuery;
|
|
rotblRepasseFaseID_FASE: TIntegerField;
|
|
rotblRepasseFasePR_PRINCIPAL: TFloatField;
|
|
rotblRepasseFasePR_JUROS: TFloatField;
|
|
rotblRepasseFasePR_MULTA: TFloatField;
|
|
rotblRepasseFasePR_ENCARGOS: TFloatField;
|
|
rotblRepasseFasePR_CORRIGIDO: TFloatField;
|
|
rotblRepasseFaseMIN_ATRASO: TIntegerField;
|
|
rotblRepasseFaseMAX_ATRASO: TIntegerField;
|
|
rotblRepasseFaseID_REPASSE: TIntegerField;
|
|
rotblRepasseFaseID_ULTIMO_USUARIO: TIntegerField;
|
|
rotblRepasseFaseDT_HORA_ULTIMA_ATT: TDateTimeField;
|
|
zroqryTitulosVL_REPASSE_PRIN: TFloatField;
|
|
zroqryTitulosVL_DESC_JUROS: TFloatField;
|
|
zroqryTitulosVL_REPASSE_JUROS: TFloatField;
|
|
zroqryTitulosVL_DESC_MULTA: TFloatField;
|
|
zroqryTitulosVL_REPASSE_MULTA: TFloatField;
|
|
zroqryTitulosVL_INDICADOR: TFloatField;
|
|
zroqryTitulosVL_DESC_INDICADOR: TFloatField;
|
|
zroqryTitulosVL_REPASSE_CORRIGIDO: TFloatField;
|
|
zroqryTitulosTP_PRESTACAO: TWideStringField;
|
|
zroqryTitulosVL_REPASSE_ENCARGOS: TFloatField;
|
|
procedure zroqryTitulosCalcFields(DataSet: TDataSet);
|
|
procedure relPrestacao2AfterPrint(Sender: TObject);
|
|
procedure relPrestacao2BeforePrint(Sender: TObject; var PrintIt: Boolean);
|
|
procedure FormCreate(Sender: TObject);
|
|
private
|
|
sql: string;
|
|
sqlt: string;
|
|
procedure SalvarReciboPDF;
|
|
{ Private declarations }
|
|
public
|
|
deps: Boolean;
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
relPrestacaoAnaSin2: TrelPrestacaoAnaSin2;
|
|
meses: array [1 .. 12] of string = (
|
|
'JANEIRO',
|
|
'FEVEREIRO',
|
|
'MARCO',
|
|
'ABRIL',
|
|
'MAIO',
|
|
'JUNHO',
|
|
'JULHO',
|
|
'AGOSTO',
|
|
'SETEMBRO',
|
|
'OUTUBRO',
|
|
'NOVEMBRO',
|
|
'DEZEMBRO'
|
|
);
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses udtmSystem;
|
|
|
|
procedure TrelPrestacaoAnaSin2.FormCreate(Sender: TObject);
|
|
begin
|
|
deps := false;
|
|
end;
|
|
|
|
procedure TrelPrestacaoAnaSin2.relPrestacao2AfterPrint(Sender: TObject);
|
|
begin
|
|
SalvarReciboPDF;
|
|
dtmSystem.tblAcordos.sql.Text := sql;
|
|
dtmSystem.tblTitulos.sql.Text := sqlt;
|
|
dtmSystem.tblDevedores.Open;
|
|
dtmSystem.tblTitulos.Open;
|
|
end;
|
|
|
|
procedure TrelPrestacaoAnaSin2.relPrestacao2BeforePrint(Sender: TObject;
|
|
var PrintIt: Boolean);
|
|
begin
|
|
dtmSystem.tblDevedores.Close;
|
|
dtmSystem.tblTitulos.Close;
|
|
end;
|
|
|
|
procedure TrelPrestacaoAnaSin2.SalvarReciboPDF;
|
|
var
|
|
path, file_name: string;
|
|
Fmt: TFormatSettings;
|
|
i: Integer;
|
|
begin
|
|
Fmt := TFormatSettings.Create;
|
|
for i := 0 to High(meses) do
|
|
begin
|
|
Fmt.LongMonthNames[i] := meses[i];
|
|
end;
|
|
// path := ExtractFilePath(Application.ExeName) + 'RELATORIOS';
|
|
path := dtmSystem.path_executavel + '\RELATORIOS';
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
path := path + '\PRESTACAO_CONTAS';
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
path := path + '\SINTETICO';
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
path := TrimRight(path);
|
|
path := path + '\' + FormatDateTime('YYYY', Date);
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
path := path + '\' + FormatDateTime('mmmm', Date, Fmt);
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
path := path + '\' + FormatDateTime('dd', Date);
|
|
if not DirectoryExists(path) then
|
|
begin
|
|
CreateDir(path);
|
|
end;
|
|
if deps then
|
|
begin
|
|
file_name := path + '\RELATORIO_PRESTACAO_CONTAS-SINTETICO-DEPARTAMENTOS' +
|
|
FormatDateTime('HH-mm', Time) + '.pdf';
|
|
end
|
|
else
|
|
begin
|
|
file_name := path + '\RELATORIO_PRESTACAO_CONTAS-SINTETICO' +
|
|
FormatDateTime('HH-mm', Time) + '.pdf';
|
|
end;
|
|
fr_filterpdf.FileName := file_name;
|
|
relPrestacao2.SaveToFile(file_name);
|
|
end;
|
|
|
|
procedure TrelPrestacaoAnaSin2.zroqryTitulosCalcFields(DataSet: TDataSet);
|
|
var
|
|
pt_principal, pt_juros, pt_multa, pt_encargos, pt_corrigido: Currency;
|
|
atraso, index: Integer;
|
|
ac_pr, ac_j, ac_m, ac_enc, ac_cor: array of Currency;
|
|
vl_pr, vl_j, vl_m, vl_enc, vl_cor, pr_pr, pr_j, pr_m, pr_enc, pr_cor, help_pr,
|
|
help_j, help_m, help_enc, help_cor: Currency;
|
|
mes, ano: string;
|
|
begin
|
|
with dtmSystem do
|
|
begin
|
|
if not tblDevedores.Active then
|
|
begin
|
|
tblDevedores.Open;
|
|
end;
|
|
if not tblTitulos.Active then
|
|
begin
|
|
tblTitulos.Open;
|
|
end;
|
|
if not tblAcordos.Active then
|
|
begin
|
|
tblAcordos.Open;
|
|
end;
|
|
if not tblCHGEmpresa.Active then
|
|
begin
|
|
tblCHGEmpresa.Open;
|
|
end;
|
|
if not tblRepasse.Active then
|
|
begin
|
|
tblRepasse.Open;
|
|
end;
|
|
if not tblRepasseFase.Active then
|
|
begin
|
|
tblRepasseFase.Open;
|
|
end;
|
|
if zroqryTitulosID_TITULO.AsString <> '' then
|
|
begin
|
|
if zroqryTitulosTP_PRESTACAO.AsString = 'N' then
|
|
begin
|
|
sql := tblAcordos.sql.Text;
|
|
sqlt := tblTitulos.sql.Text;
|
|
tblAcordos.sql.Text := 'select * from sys_acordos';
|
|
tblAcordos.Filtered := false;
|
|
tblAcordos.Filter := 'ID_PARCELA = ' + zroqryTitulosID_TITULO.AsString;
|
|
tblAcordos.Filtered := true;
|
|
tblTitulos.sql.Text := 'select * from chg_titulos';
|
|
tblTitulos.Open;
|
|
tblAcordos.Open;
|
|
// pt_principal := 0;
|
|
// pt_juros := 0;
|
|
// pt_multa := 0;
|
|
// pt_encargos := 0;
|
|
// pt_corrigido := 0;
|
|
if not tblAcordos.IsEmpty then
|
|
begin
|
|
tblAcordos.First;
|
|
vl_pr := 0;
|
|
vl_j := 0;
|
|
vl_m := 0;
|
|
vl_enc := 0;
|
|
vl_cor := 0;
|
|
setlength(ac_pr, 0);
|
|
setlength(ac_j, 0);
|
|
setlength(ac_m, 0);
|
|
setlength(ac_enc, 0);
|
|
setlength(ac_cor, 0);
|
|
setlength(ac_pr, tblAcordos.RecordCount);
|
|
setlength(ac_j, tblAcordos.RecordCount);
|
|
setlength(ac_m, tblAcordos.RecordCount);
|
|
setlength(ac_enc, tblAcordos.RecordCount);
|
|
setlength(ac_cor, tblAcordos.RecordCount);
|
|
pr_pr := 0;
|
|
pr_j := 0;
|
|
pr_m := 0;
|
|
pr_enc := 0;
|
|
pr_cor := 0;
|
|
index := 0;
|
|
while not tblAcordos.Eof do
|
|
begin
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
tblAcordosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_ORIGINAL.AsInteger, []);
|
|
|
|
if not(tblTitulosTP_PRESTACAO.AsString = 'N') then
|
|
begin
|
|
vl_pr := vl_pr + tblTitulosVL_TITULO.AsCurrency;
|
|
vl_j := vl_j + tblTitulosVL_JUROS.AsCurrency;
|
|
vl_m := vl_m + tblTitulosVL_MULTA.AsCurrency;
|
|
vl_enc := vl_enc + tblTitulosVL_ENCARGOS.AsCurrency;
|
|
vl_cor := vl_cor + tblTitulosVL_CORRIGIDO.AsCurrency;
|
|
end;
|
|
// else
|
|
// begin
|
|
// pt_principal := pt_principal +
|
|
// tblTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
// pt_juros := pt_juros + tblTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
// pt_multa := pt_multa + tblTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
// pt_encargos := pt_encargos + tblTitulosVL_REPASSE_ENCARGOS.
|
|
// AsCurrency;
|
|
// pt_corrigido := pt_corrigido +
|
|
// tblTitulosVL_REPASSE_CORRIGIDO.AsCurrency;
|
|
// end;
|
|
|
|
tblAcordos.Next;
|
|
end;
|
|
tblAcordos.First;
|
|
while not tblAcordos.Eof do
|
|
begin
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
tblAcordosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_ORIGINAL.AsInteger, []);
|
|
if not(tblTitulosTP_PRESTACAO.AsString = 'N') then
|
|
begin
|
|
atraso := DaysBetween(tblTitulosDT_PAGAMENTO.AsDateTime,
|
|
tblTitulosDT_VENCIMENTO.AsDateTime);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
tblTitulosID_EMPRESA.AsInteger, []);
|
|
|
|
mes := inttostr
|
|
(strtoint(copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 6, 2)));
|
|
ano := copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 1, 4);
|
|
tblTitulos.Locate('ID_TITULO',
|
|
tblAcordosID_PARCELA.AsInteger, []);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
tblTitulosID_EMPRESA.AsInteger, []);
|
|
|
|
tblEmpresaRepasse.Filtered := false;
|
|
tblEmpresaRepasse.Locate('ID_MES;ID_ANO',
|
|
VarArrayOf([mes, ano]), []);
|
|
rotblRepasseFase.Close;
|
|
rotblRepasseFase.sql.Text :=
|
|
'select * from sys_repasses_fases where id_repasse = ' +
|
|
QuotedStr(tblEmpresaRepasseID_ITEM.AsString) +
|
|
' and min_atraso <= ' + inttostr(atraso) + ' and ' +
|
|
inttostr(atraso) + ' <= max_atraso';
|
|
rotblRepasseFase.Open;
|
|
|
|
if not rotblRepasseFase.IsEmpty then
|
|
begin
|
|
help_pr := (rotblRepasseFasePR_PRINCIPAL.AsCurrency / 100);
|
|
help_j := (rotblRepasseFasePR_JUROS.AsCurrency / 100);
|
|
help_m := (rotblRepasseFasePR_MULTA.AsCurrency / 100);
|
|
help_enc := (rotblRepasseFasePR_ENCARGOS.AsCurrency / 100);
|
|
help_cor := (rotblRepasseFasePR_CORRIGIDO.AsCurrency / 100);
|
|
end
|
|
else
|
|
begin
|
|
help_pr :=
|
|
(dtmSystem.tblEmpresaRepassePR_PRINCIPAL.AsCurrency / 100);
|
|
help_j := (dtmSystem.tblEmpresaRepassePR_JUROS.
|
|
AsCurrency / 100);
|
|
help_m := (dtmSystem.tblEmpresaRepassePR_MULTA.
|
|
AsCurrency / 100);
|
|
help_enc :=
|
|
(dtmSystem.tblEmpresaRepassePR_ENCARGOS.AsCurrency / 100);
|
|
help_cor :=
|
|
(dtmSystem.tblEmpresaRepassePR_CORRIGIDO.AsCurrency / 100);
|
|
end;
|
|
|
|
tblTitulos.Locate('ID_TITULO',
|
|
tblAcordosID_ORIGINAL.AsInteger, []);
|
|
|
|
ac_pr[index] := tblTitulosVL_TITULO.AsCurrency * help_pr;
|
|
ac_j[index] := tblTitulosVL_JUROS.AsCurrency * help_j;
|
|
ac_m[index] := tblTitulosVL_MULTA.AsCurrency * help_m;
|
|
ac_enc[index] := tblTitulosVL_ENCARGOS.AsCurrency * help_enc;
|
|
ac_cor[index] := tblTitulosVL_CORRIGIDO.AsCurrency * help_cor;
|
|
|
|
if vl_pr <> 0 then
|
|
begin
|
|
pr_pr := pr_pr + ((ac_pr[index] * 100) / vl_pr);
|
|
end;
|
|
if vl_j <> 0 then
|
|
begin
|
|
pr_j := pr_j + ((ac_j[index] * 100) / vl_j);
|
|
end;
|
|
if vl_m <> 0 then
|
|
begin
|
|
pr_m := pr_m + ((ac_m[index] * 100) / vl_m);
|
|
end;
|
|
if vl_enc <> 0 then
|
|
begin
|
|
pr_enc := pr_enc + ((ac_enc[index] * 100) / vl_enc);
|
|
end;
|
|
if vl_cor <> 0 then
|
|
begin
|
|
pr_cor := pr_cor + ((ac_cor[index] * 100) / vl_cor);
|
|
end;
|
|
end;
|
|
Inc(index, 1);
|
|
tblAcordos.Next;
|
|
end;
|
|
if pr_pr = 0 then
|
|
begin
|
|
pt_principal := zroqryTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_principal := (zroqryTitulosVL_TITULO.AsCurrency * pr_pr) / 100;
|
|
end;
|
|
if pr_j = 0 then
|
|
begin
|
|
pt_juros := zroqryTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_juros := (zroqryTitulosVL_JUROS.AsCurrency * pr_j) / 100;
|
|
end;
|
|
if pr_m = 0 then
|
|
begin
|
|
pt_multa := zroqryTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_multa := (zroqryTitulosVL_MULTA.AsCurrency * pr_m) / 100;
|
|
end;
|
|
if pr_enc = 0 then
|
|
begin
|
|
pt_encargos := zroqryTitulosVL_REPASSE_ENCARGOS.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_encargos := (zroqryTitulosVL_ENCARGOS.AsCurrency * pr_enc) / 100;
|
|
end;
|
|
if pr_cor = 0 then
|
|
begin
|
|
pt_corrigido := zroqryTitulosVL_REPASSE_CORRIGIDO.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_corrigido := (zroqryTitulosVL_CORRIGIDO.AsCurrency * pr_cor) / 100;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
pt_principal := zroqryTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
pt_juros := zroqryTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
pt_multa := zroqryTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
pt_encargos := zroqryTitulosVL_REPASSE_ENCARGOS.AsCurrency;
|
|
pt_corrigido := zroqryTitulosVL_REPASSE_CORRIGIDO.AsCurrency;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
sql := tblAcordos.sql.Text;
|
|
sqlt := tblTitulos.sql.Text;
|
|
tblAcordos.sql.Text := 'select * from sys_acordos';
|
|
tblAcordos.Filtered := false;
|
|
tblAcordos.Filter := 'ID_PARCELA = ' + zroqryTitulosID_TITULO.AsString;
|
|
tblAcordos.Filtered := true;
|
|
tblTitulos.sql.Text := 'select * from chg_titulos';
|
|
tblTitulos.Open;
|
|
tblAcordos.Open;
|
|
if not tblAcordos.IsEmpty then
|
|
begin
|
|
tblAcordos.First;
|
|
setlength(ac_pr, 0);
|
|
setlength(ac_j, 0);
|
|
setlength(ac_m, 0);
|
|
setlength(ac_enc, 0);
|
|
setlength(ac_cor, 0);
|
|
setlength(ac_pr, tblAcordos.RecordCount);
|
|
setlength(ac_j, tblAcordos.RecordCount);
|
|
setlength(ac_m, tblAcordos.RecordCount);
|
|
setlength(ac_enc, tblAcordos.RecordCount);
|
|
setlength(ac_cor, tblAcordos.RecordCount);
|
|
vl_pr := 0;
|
|
vl_j := 0;
|
|
vl_m := 0;
|
|
vl_enc := 0;
|
|
vl_cor := 0;
|
|
pr_pr := 0;
|
|
pr_j := 0;
|
|
pr_m := 0;
|
|
pr_enc := 0;
|
|
pr_cor := 0;
|
|
index := 0;
|
|
while not tblAcordos.Eof do
|
|
begin
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
tblAcordosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_ORIGINAL.AsInteger, []);
|
|
vl_pr := vl_pr + tblTitulosVL_TITULO.AsCurrency;
|
|
vl_j := vl_j + tblTitulosVL_JUROS.AsCurrency;
|
|
vl_m := vl_m + tblTitulosVL_MULTA.AsCurrency;
|
|
vl_enc := vl_enc + tblTitulosVL_ENCARGOS.AsCurrency;
|
|
vl_cor := vl_cor + tblTitulosVL_CORRIGIDO.AsCurrency;
|
|
tblAcordos.Next;
|
|
end;
|
|
tblAcordos.First;
|
|
while not tblAcordos.Eof do
|
|
begin
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
tblAcordosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_ORIGINAL.AsInteger, []);
|
|
atraso := DaysBetween(tblTitulosDT_PAGAMENTO.AsDateTime,
|
|
tblTitulosDT_VENCIMENTO.AsDateTime);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
tblTitulosID_EMPRESA.AsInteger, []);
|
|
|
|
mes := inttostr(strtoint(copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 6, 2)));
|
|
ano := copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 1, 4);
|
|
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_PARCELA.AsInteger, []);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
tblTitulosID_EMPRESA.AsInteger, []);
|
|
|
|
tblEmpresaRepasse.Locate('ID_MES;ID_ANO',
|
|
VarArrayOf([mes, ano]), []);
|
|
|
|
rotblRepasseFase.Close;
|
|
rotblRepasseFase.sql.Text :=
|
|
'select * from sys_repasses_fases where id_repasse = ' +
|
|
QuotedStr(tblEmpresaRepasseID_ITEM.AsString) +
|
|
' and min_atraso <= ' + inttostr(atraso) + ' and ' +
|
|
inttostr(atraso) + ' <= max_atraso';
|
|
rotblRepasseFase.Open;
|
|
|
|
if not rotblRepasseFase.IsEmpty then
|
|
begin
|
|
help_pr := (rotblRepasseFasePR_PRINCIPAL.AsCurrency / 100);
|
|
help_j := (rotblRepasseFasePR_JUROS.AsCurrency / 100);
|
|
help_m := (rotblRepasseFasePR_MULTA.AsCurrency / 100);
|
|
help_enc := (rotblRepasseFasePR_ENCARGOS.AsCurrency / 100);
|
|
help_cor := (rotblRepasseFasePR_CORRIGIDO.AsCurrency / 100);
|
|
end
|
|
else
|
|
begin
|
|
help_pr :=
|
|
(dtmSystem.tblEmpresaRepassePR_PRINCIPAL.AsCurrency / 100);
|
|
help_j := (dtmSystem.tblEmpresaRepassePR_JUROS.AsCurrency / 100);
|
|
help_m := (dtmSystem.tblEmpresaRepassePR_MULTA.AsCurrency / 100);
|
|
help_enc :=
|
|
(dtmSystem.tblEmpresaRepassePR_ENCARGOS.AsCurrency / 100);
|
|
help_cor :=
|
|
(dtmSystem.tblEmpresaRepassePR_CORRIGIDO.AsCurrency / 100);
|
|
end;
|
|
|
|
tblTitulos.Locate('ID_TITULO', tblAcordosID_ORIGINAL.AsInteger, []);
|
|
|
|
ac_pr[index] := tblTitulosVL_TITULO.AsCurrency * help_pr;
|
|
ac_j[index] := tblTitulosVL_JUROS.AsCurrency * help_j;
|
|
ac_m[index] := tblTitulosVL_MULTA.AsCurrency * help_m;
|
|
ac_enc[index] := tblTitulosVL_ENCARGOS.AsCurrency * help_enc;
|
|
ac_cor[index] := tblTitulosVL_CORRIGIDO.AsCurrency * help_cor;
|
|
|
|
if vl_pr <> 0 then
|
|
begin
|
|
pr_pr := pr_pr + ((ac_pr[index] * 100) / vl_pr);
|
|
end;
|
|
if vl_j <> 0 then
|
|
begin
|
|
pr_j := pr_j + ((ac_j[index] * 100) / vl_j);
|
|
end;
|
|
if vl_m <> 0 then
|
|
begin
|
|
pr_m := pr_m + ((ac_m[index] * 100) / vl_m);
|
|
end;
|
|
if vl_enc <> 0 then
|
|
begin
|
|
pr_enc := pr_enc + ((ac_enc[index] * 100) / vl_enc);
|
|
end;
|
|
if vl_cor <> 0 then
|
|
begin
|
|
pr_cor := pr_cor + ((ac_cor[index] * 100) / vl_cor);
|
|
end;
|
|
tblRepasseFase.Filtered := true;
|
|
Inc(index, 1);
|
|
tblAcordos.Next;
|
|
end;
|
|
pt_principal := (zroqryTitulosVL_TITULO.AsCurrency * pr_pr) / 100;
|
|
pt_juros := (zroqryTitulosVL_JUROS.AsCurrency * pr_j) / 100;
|
|
pt_multa := (zroqryTitulosVL_MULTA.AsCurrency * pr_m) / 100;
|
|
pt_encargos := (zroqryTitulosVL_ENCARGOS.AsCurrency * pr_enc) / 100;
|
|
pt_corrigido := (zroqryTitulosVL_CORRIGIDO.AsCurrency * pr_cor) / 100;
|
|
end
|
|
else
|
|
begin
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
zroqryTitulosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', zroqryTitulosID_TITULO.AsInteger, []);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
zroqryTitulosID_EMPRESA.AsInteger, []);
|
|
atraso := DaysBetween(tblTitulosDT_PAGAMENTO.AsDateTime,
|
|
tblTitulosDT_VENCIMENTO.AsDateTime);
|
|
|
|
mes := inttostr(strtoint(copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 6, 2)));
|
|
ano := copy(FormatDateTime('yyyy-mm-dd',
|
|
tblTitulosDT_PAGAMENTO.AsDateTime), 1, 4);
|
|
tblEmpresaRepasse.Locate('ID_MES;ID_ANO', VarArrayOf([mes, ano]), []);
|
|
rotblRepasseFase.Close;
|
|
rotblRepasseFase.sql.Text :=
|
|
'select * from sys_repasses_fases where id_repasse = ' +
|
|
QuotedStr(tblEmpresaRepasseID_ITEM.AsString) +
|
|
' and min_atraso <= ' + inttostr(atraso) + ' and ' +
|
|
inttostr(atraso) + ' <= max_atraso';
|
|
rotblRepasseFase.Open;
|
|
|
|
if not rotblRepasseFase.IsEmpty then
|
|
begin
|
|
pt_principal := zroqryTitulosVL_TITULO.AsCurrency *
|
|
(rotblRepasseFasePR_PRINCIPAL.AsCurrency / 100);
|
|
pt_juros := zroqryTitulosVL_JUROS.AsCurrency *
|
|
(rotblRepasseFasePR_JUROS.AsCurrency / 100);
|
|
pt_multa := zroqryTitulosVL_MULTA.AsCurrency *
|
|
(rotblRepasseFasePR_MULTA.AsCurrency / 100);
|
|
pt_encargos := zroqryTitulosVL_ENCARGOS.AsCurrency *
|
|
(rotblRepasseFasePR_ENCARGOS.AsCurrency / 100);
|
|
pt_corrigido := zroqryTitulosVL_CORRIGIDO.AsCurrency *
|
|
(rotblRepasseFasePR_CORRIGIDO.AsCurrency / 100);
|
|
end
|
|
else
|
|
begin
|
|
|
|
pt_principal := zroqryTitulosVL_TITULO.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_PRINCIPAL.AsCurrency / 100);
|
|
pt_juros := zroqryTitulosVL_JUROS.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_JUROS.AsCurrency / 100);
|
|
pt_multa := zroqryTitulosVL_MULTA.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_MULTA.AsCurrency / 100);
|
|
pt_encargos := zroqryTitulosVL_ENCARGOS.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_ENCARGOS.AsCurrency / 100);
|
|
pt_corrigido := zroqryTitulosVL_CORRIGIDO.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_CORRIGIDO.AsCurrency / 100);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
zroqryTitulosVL_RETIDO.AsCurrency := pt_principal + pt_juros + pt_multa +
|
|
pt_encargos + pt_corrigido;
|
|
zroqryTitulosVL_REPASSE.AsCurrency := zroqryTitulosVL_CORRIGIDO.AsCurrency
|
|
- zroqryTitulosVL_RETIDO.AsCurrency;
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end.
|