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.
693 lines
24 KiB
693 lines
24 KiB
unit urelPrestacaoContas;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
System.Classes, Vcl.Graphics, System.DateUtils,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, RLReport, Data.DB, ZAbstractRODataset,
|
|
ZAbstractDataset, ZDataset, RLFilters, RLPDFFilter, RLRichText;
|
|
|
|
type
|
|
TrelPrestacaoContas = class(TForm)
|
|
frPrestacao: TRLReport;
|
|
frbnd_header: TRLBand;
|
|
frbnd_clmheader: TRLBand;
|
|
frbnd_detail: TRLBand;
|
|
frbnd_clmfooter: TRLBand;
|
|
frbnd_footer: TRLBand;
|
|
frpnl_logo: TRLPanel;
|
|
frdbimg_logo: TRLDBImage;
|
|
frpnl_headertop: TRLPanel;
|
|
frlbl_headertop: TRLLabel;
|
|
RLLabel2: TRLLabel;
|
|
RLLabel3: TRLLabel;
|
|
RLLabel4: TRLLabel;
|
|
RLLabel5: TRLLabel;
|
|
RLLabel6: TRLLabel;
|
|
RLLabel7: TRLLabel;
|
|
RLLabel8: TRLLabel;
|
|
RLLabel9: TRLLabel;
|
|
RLLabel10: TRLLabel;
|
|
RLLabel11: TRLLabel;
|
|
RLLabel12: TRLLabel;
|
|
zqryTitulos: TZQuery;
|
|
dtsTitulos: TDataSource;
|
|
zqryTitulosTX_NOME: TWideStringField;
|
|
zqryTitulosTX_PRODUTO: TWideStringField;
|
|
zqryTitulosDT_VENCIMENTO: TDateTimeField;
|
|
zqryTitulosDT_PAGAMENTO: TDateTimeField;
|
|
zqryTitulosVL_MULTA: TFloatField;
|
|
zqryTitulosVL_ENCARGOS: TFloatField;
|
|
zqryTitulosVL_CORRIGIDO: TFloatField;
|
|
zqryTitulosVL_REPASSE: TCurrencyField;
|
|
zqryTitulosVL_RETIDO: TCurrencyField;
|
|
RLDBText3: TRLDBText;
|
|
RLDBText4: TRLDBText;
|
|
RLDBText5: TRLDBText;
|
|
RLDBText6: TRLDBText;
|
|
RLDBText7: TRLDBText;
|
|
RLDBText8: TRLDBText;
|
|
RLDBText9: TRLDBText;
|
|
RLDBText10: TRLDBText;
|
|
RLDBText11: TRLDBText;
|
|
RLDBText1: TRLDBText;
|
|
RLDBText2: TRLDBText;
|
|
fr_filterpdf: TRLPDFFilter;
|
|
RLDBResult1: TRLDBResult;
|
|
RLDBResult2: TRLDBResult;
|
|
RLDBResult3: TRLDBResult;
|
|
RLDBResult4: TRLDBResult;
|
|
RLDBResult5: TRLDBResult;
|
|
RLDBResult6: TRLDBResult;
|
|
RLDBResult7: TRLDBResult;
|
|
RLLabel13: TRLLabel;
|
|
fr_date: TRLSystemInfo;
|
|
RLLabel14: TRLLabel;
|
|
RLLabel15: TRLLabel;
|
|
RLLabel16: TRLLabel;
|
|
RLLabel17: TRLLabel;
|
|
RLLabel18: TRLLabel;
|
|
RLLabel19: TRLLabel;
|
|
RLLabel20: TRLLabel;
|
|
RLLabel21: TRLLabel;
|
|
RLDBText12: TRLDBText;
|
|
RLDBText13: TRLDBText;
|
|
RLDBText14: TRLDBText;
|
|
RLDBText15: TRLDBText;
|
|
RLDBText16: TRLDBText;
|
|
RLDBText17: TRLDBText;
|
|
RLMemo1: TRLMemo;
|
|
RLLabel1: TRLLabel;
|
|
RLDBText18: TRLDBText;
|
|
zqryTitulosVL_DESC_PRINCIPAL: TFloatField;
|
|
RLLabel22: TRLLabel;
|
|
RLDBResult8: TRLDBResult;
|
|
zqryTitulosATRASO: TIntegerField;
|
|
RLSystemInfo1: TRLSystemInfo;
|
|
zqryTitulosID_TITULO: TIntegerField;
|
|
zqryTitulosVL_TITULO: TCurrencyField;
|
|
zqryTitulosVL_JUROS: TFloatField;
|
|
zqryTitulosID_DEVEDOR: TIntegerField;
|
|
zqryTitulosID_EMPRESA: 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;
|
|
zqryTitulosVL_REPASSE_PRIN: TFloatField;
|
|
zqryTitulosVL_DESC_JUROS: TFloatField;
|
|
zqryTitulosVL_REPASSE_JUROS: TFloatField;
|
|
zqryTitulosVL_DESC_MULTA: TFloatField;
|
|
zqryTitulosVL_REPASSE_MULTA: TFloatField;
|
|
zqryTitulosVL_INDICADOR: TFloatField;
|
|
zqryTitulosVL_DESC_INDICADOR: TFloatField;
|
|
zqryTitulosVL_REPASSE_CORRIGIDO: TFloatField;
|
|
zqryTitulosTP_PRESTACAO: TWideStringField;
|
|
zqryTitulosVL_REPASSE_ENCARGOS: TFloatField;
|
|
procedure frdbimg_logoBeforePrint(Sender: TObject; var PrintIt: Boolean);
|
|
procedure frPrestacaoBeforePrint(Sender: TObject; var PrintIt: Boolean);
|
|
procedure zqryTitulosCalcFields(DataSet: TDataSet);
|
|
procedure frPrestacaoAfterPrint(Sender: TObject);
|
|
procedure RLMemo1BeforePrint(Sender: TObject; var Text: string;
|
|
var PrintIt: Boolean);
|
|
private
|
|
sql, sqlt: string;
|
|
procedure SalvarReciboPDF;
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
relPrestacaoContas: TrelPrestacaoContas;
|
|
|
|
meses: array [1 .. 12] of string = (
|
|
'JANEIRO',
|
|
'FEVEREIRO',
|
|
'MARCO',
|
|
'ABRIL',
|
|
'MAIO',
|
|
'JUNHO',
|
|
'JULHO',
|
|
'AGOSTO',
|
|
'SETEMBRO',
|
|
'OUTUBRO',
|
|
'NOVEMBRO',
|
|
'DEZEMBRO'
|
|
);
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses udtmSystem;
|
|
|
|
procedure TrelPrestacaoContas.frdbimg_logoBeforePrint(Sender: TObject;
|
|
var PrintIt: Boolean);
|
|
begin
|
|
if not dtmSystem.tblEmpresa.Active then
|
|
begin
|
|
dtmSystem.tblEmpresa.Open;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TrelPrestacaoContas.frPrestacaoAfterPrint(Sender: TObject);
|
|
begin
|
|
SalvarReciboPDF;
|
|
dtmSystem.tblAcordos.sql.Text := sql;
|
|
dtmSystem.tblTitulos.sql.Text := sqlt;
|
|
dtmSystem.tblDevedores.Open;
|
|
dtmSystem.tblTitulos.Open;
|
|
end;
|
|
|
|
procedure TrelPrestacaoContas.frPrestacaoBeforePrint(Sender: TObject;
|
|
var PrintIt: Boolean);
|
|
begin
|
|
// zqryTitulos.Open;
|
|
dtmSystem.tblDevedores.Close;
|
|
dtmSystem.tblTitulos.Close;
|
|
end;
|
|
|
|
procedure TrelPrestacaoContas.RLMemo1BeforePrint(Sender: TObject;
|
|
var Text: string; var PrintIt: Boolean);
|
|
begin
|
|
if RLMemo1.Width >= frpnl_headertop.Width then
|
|
begin
|
|
// RLMemo1.AutoSize := false;
|
|
RLMemo1.Width := frpnl_headertop.Width - 10;
|
|
end;
|
|
end;
|
|
|
|
procedure TrelPrestacaoContas.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 + '\' + dtmSystem.tblCHGEmpresaTX_NOME.AsString;
|
|
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;
|
|
file_name := path + '\RELATORIO_PRESTACAO_CONTAS-' + FormatDateTime('HH-mm',
|
|
Time) + '.pdf';
|
|
fr_filterpdf.FileName := file_name;
|
|
frPrestacao.SaveToFile(file_name);
|
|
end;
|
|
|
|
procedure TrelPrestacaoContas.zqryTitulosCalcFields(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 tblEmpresaRepasse.Active then
|
|
begin
|
|
tblEmpresaRepasse.Open;
|
|
end;
|
|
if not tblRepasse.Active then
|
|
begin
|
|
tblRepasse.Open;
|
|
end;
|
|
if not tblRepasseFase.Active then
|
|
begin
|
|
tblRepasseFase.Open;
|
|
end;
|
|
if zqryTitulosID_TITULO.AsString <> '' then
|
|
begin
|
|
if zqryTitulosTP_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 = ' + zqryTitulosID_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;
|
|
// pt_principal := zqryTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
// pt_juros := zqryTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
// pt_multa := zqryTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
// pt_encargos := zqryTitulosVL_REPASSE_ENCARGOS.AsCurrency;
|
|
// pt_corrigido := zqryTitulosVL_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([strtoint(mes), strtoint(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 := zqryTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_principal := (zqryTitulosVL_TITULO.AsCurrency * pr_pr) / 100;
|
|
end;
|
|
if pr_j = 0 then
|
|
begin
|
|
pt_juros := zqryTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_juros := (zqryTitulosVL_JUROS.AsCurrency * pr_j) / 100;
|
|
end;
|
|
if pr_m = 0 then
|
|
begin
|
|
pt_multa := zqryTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_multa := (zqryTitulosVL_MULTA.AsCurrency * pr_m) / 100;
|
|
end;
|
|
if pr_enc = 0 then
|
|
begin
|
|
pt_encargos := zqryTitulosVL_REPASSE_ENCARGOS.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_encargos := (zqryTitulosVL_ENCARGOS.AsCurrency * pr_enc) / 100;
|
|
end;
|
|
if pr_cor = 0 then
|
|
begin
|
|
pt_corrigido := zqryTitulosVL_REPASSE_CORRIGIDO.AsCurrency;
|
|
end
|
|
else
|
|
begin
|
|
pt_corrigido := (zqryTitulosVL_CORRIGIDO.AsCurrency * pr_cor) / 100;
|
|
end;
|
|
|
|
// if (pr_pr = 0) and (pr_j = 0) and (pr_m = 0) and (pr_enc = 0) and
|
|
// (pr_cor = 0) then
|
|
// begin
|
|
// end
|
|
// else
|
|
// begin
|
|
// end;
|
|
end
|
|
else
|
|
begin
|
|
pt_principal := zqryTitulosVL_REPASSE_PRIN.AsCurrency;
|
|
pt_juros := zqryTitulosVL_REPASSE_JUROS.AsCurrency;
|
|
pt_multa := zqryTitulosVL_REPASSE_MULTA.AsCurrency;
|
|
pt_encargos := zqryTitulosVL_REPASSE_ENCARGOS.AsCurrency;
|
|
pt_corrigido := zqryTitulosVL_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 = ' + zqryTitulosID_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 := (zqryTitulosVL_TITULO.AsCurrency * pr_pr) / 100;
|
|
pt_juros := (zqryTitulosVL_JUROS.AsCurrency * pr_j) / 100;
|
|
pt_multa := (zqryTitulosVL_MULTA.AsCurrency * pr_m) / 100;
|
|
pt_encargos := (zqryTitulosVL_ENCARGOS.AsCurrency * pr_enc) / 100;
|
|
pt_corrigido := (zqryTitulosVL_CORRIGIDO.AsCurrency * pr_cor) / 100;
|
|
end
|
|
else
|
|
begin
|
|
|
|
tblDevedores.Locate('ID_DEVEDOR',
|
|
zqryTitulosID_DEVEDOR.AsInteger, []);
|
|
tblTitulos.Locate('ID_TITULO', zqryTitulosID_TITULO.AsInteger, []);
|
|
tblCHGEmpresa.Locate('ID_EMPRESA',
|
|
zqryTitulosID_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 := zqryTitulosVL_TITULO.AsCurrency *
|
|
(rotblRepasseFasePR_PRINCIPAL.AsCurrency / 100);
|
|
pt_juros := zqryTitulosVL_JUROS.AsCurrency *
|
|
(rotblRepasseFasePR_JUROS.AsCurrency / 100);
|
|
pt_multa := zqryTitulosVL_MULTA.AsCurrency *
|
|
(rotblRepasseFasePR_MULTA.AsCurrency / 100);
|
|
pt_encargos := zqryTitulosVL_ENCARGOS.AsCurrency *
|
|
(rotblRepasseFasePR_ENCARGOS.AsCurrency / 100);
|
|
pt_corrigido := zqryTitulosVL_CORRIGIDO.AsCurrency *
|
|
(rotblRepasseFasePR_CORRIGIDO.AsCurrency / 100);
|
|
end
|
|
else
|
|
begin
|
|
pt_principal := zqryTitulosVL_TITULO.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_PRINCIPAL.AsCurrency / 100);
|
|
pt_juros := zqryTitulosVL_JUROS.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_JUROS.AsCurrency / 100);
|
|
pt_multa := zqryTitulosVL_MULTA.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_MULTA.AsCurrency / 100);
|
|
pt_encargos := zqryTitulosVL_ENCARGOS.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_ENCARGOS.AsCurrency / 100);
|
|
pt_corrigido := zqryTitulosVL_CORRIGIDO.AsCurrency *
|
|
(dtmSystem.tblEmpresaRepassePR_CORRIGIDO.AsCurrency / 100);
|
|
end;
|
|
end;
|
|
end;
|
|
zqryTitulosVL_RETIDO.AsCurrency := pt_principal + pt_juros + pt_multa +
|
|
pt_encargos + pt_corrigido;
|
|
zqryTitulosVL_REPASSE.AsCurrency := zqryTitulosVL_CORRIGIDO.AsCurrency -
|
|
zqryTitulosVL_RETIDO.AsCurrency;
|
|
end;
|
|
end;
|
|
|
|
end;
|
|
|
|
end.
|