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.
1065 lines
32 KiB
1065 lines
32 KiB
unit ufrmMandaMensagem;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
System.Classes, Vcl.Graphics, System.StrUtils, System.DateUtils, System.UITypes,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, umstMaster, Data.DB, ACBrBase, ACBrMail,
|
|
ZAbstractRODataset, ZAbstractDataset, ZDataset, Vcl.StdCtrls, Vcl.ComCtrls,
|
|
Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.ExtCtrls, Vcl.CheckLst;
|
|
|
|
type
|
|
TfrmMandaMensagem = class(TmstMaster)
|
|
dbg_textoemail: TDBGrid;
|
|
btn_pesquisa: TButton;
|
|
pb_pesquisa: TProgressBar;
|
|
dbre_textomensagem: TDBRichEdit;
|
|
dtsTextoEmail: TDataSource;
|
|
dtsQPesquisa: TDataSource;
|
|
QPesquisa: TZQuery;
|
|
dbg_pesquisa: TDBGrid;
|
|
ACBrMail: TACBrMail;
|
|
rg_email: TRadioGroup;
|
|
btn_mandaemail: TButton;
|
|
edt_assunto: TEdit;
|
|
Label1: TLabel;
|
|
sbx_filtro: TScrollBox;
|
|
pnl_providências: TPanel;
|
|
Label5: TLabel;
|
|
Label6: TLabel;
|
|
cb_providencias: TCheckBox;
|
|
clb_providencias: TCheckListBox;
|
|
pnl_filtroprov: TPanel;
|
|
rg_filtroprov: TRadioGroup;
|
|
dtp_provin: TDateTimePicker;
|
|
dtp_provfim: TDateTimePicker;
|
|
cb_periodoprov: TCheckBox;
|
|
cb_bacalhau: TCheckBox;
|
|
edt_pprov: TEdit;
|
|
cb_cobradoresprov: TCheckBox;
|
|
edt_puserprov: TEdit;
|
|
clb_usuariosprov: TCheckListBox;
|
|
pnl_beneficiarios: TPanel;
|
|
Label11: TLabel;
|
|
Label12: TLabel;
|
|
Label13: TLabel;
|
|
Label14: TLabel;
|
|
cb_beneficiarios: TCheckBox;
|
|
clb_beneficiarios: TCheckListBox;
|
|
edt_pcredor: TEdit;
|
|
cb_credorentrada: TCheckBox;
|
|
dtp_credorentrada1: TDateTimePicker;
|
|
dtp_credorentrada2: TDateTimePicker;
|
|
cb_credorvencimento: TCheckBox;
|
|
dtp_credorvenc1: TDateTimePicker;
|
|
dtp_credorvenc2: TDateTimePicker;
|
|
cb_credortptitulo: TCheckBox;
|
|
Panel3: TPanel;
|
|
rg_credortptitulo: TRadioGroup;
|
|
pnl_agendamento: TPanel;
|
|
lbl_agendcomeco: TLabel;
|
|
lbl_agendfim: TLabel;
|
|
cb_agendamento: TCheckBox;
|
|
dtp_agendcomeco: TDateTimePicker;
|
|
dtp_agendfim: TDateTimePicker;
|
|
clb_usuariosagenda: TCheckListBox;
|
|
cb_cobradoresagenda: TCheckBox;
|
|
edt_puseragenda: TEdit;
|
|
Panel2: TPanel;
|
|
rg_agendamento: TRadioGroup;
|
|
pnl_alfabeto: TPanel;
|
|
Label7: TLabel;
|
|
Label8: TLabel;
|
|
cb_faixanome: TCheckBox;
|
|
edt_nomein: TEdit;
|
|
edt_nomefim: TEdit;
|
|
pnl_atraso: TPanel;
|
|
Label9: TLabel;
|
|
Label10: TLabel;
|
|
cb_atraso: TCheckBox;
|
|
edt_atrasoin: TEdit;
|
|
edt_atrasofim: TEdit;
|
|
pnl_tipopessoa: TPanel;
|
|
cb_tipopessoa: TCheckBox;
|
|
Panel1: TPanel;
|
|
rg_tipopessoa: TRadioGroup;
|
|
QPesquisaTX_NOME: TWideStringField;
|
|
QPesquisaTX_DOCUMENTO: TWideStringField;
|
|
QPesquisaTX_EMAIL: TWideStringField;
|
|
dblulb_provs: TDBLookupComboBox;
|
|
lbl_prov: TLabel;
|
|
cb_retornaprov: TCheckBox;
|
|
QPesquisaID_DEVEDOR: TIntegerField;
|
|
Label2: TLabel;
|
|
mb_log: TMemo;
|
|
lbl_resultado: TLabel;
|
|
procedure btn_pesquisaClick(Sender: TObject);
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure cb_beneficiariosClick(Sender: TObject);
|
|
procedure cb_providenciasClick(Sender: TObject);
|
|
procedure cb_periodoprovClick(Sender: TObject);
|
|
procedure cb_cobradoresClick(Sender: TObject);
|
|
procedure cb_faixavalorClick(Sender: TObject);
|
|
procedure cb_entradaClick(Sender: TObject);
|
|
procedure cb_agendamentoClick(Sender: TObject);
|
|
procedure cb_faixanomeClick(Sender: TObject);
|
|
procedure cb_atrasoClick(Sender: TObject);
|
|
procedure cb_tipopessoaClick(Sender: TObject);
|
|
procedure clb_beneficiariosClickCheck(Sender: TObject);
|
|
procedure clb_providenciasClickCheck(Sender: TObject);
|
|
procedure btn_mandaemailClick(Sender: TObject);
|
|
procedure Button1Click(Sender: TObject);
|
|
procedure edt_pcredorChange(Sender: TObject);
|
|
procedure edt_pprovChange(Sender: TObject);
|
|
procedure cb_credorentradaClick(Sender: TObject);
|
|
procedure cb_credorvencimentoClick(Sender: TObject);
|
|
procedure cb_credortptituloClick(Sender: TObject);
|
|
procedure cb_cobradoresprovClick(Sender: TObject);
|
|
procedure edt_puserprovClick(Sender: TObject);
|
|
procedure clb_usuariosprovClickCheck(Sender: TObject);
|
|
procedure rg_agendamentoClick(Sender: TObject);
|
|
procedure cb_cobradoresagendaClick(Sender: TObject);
|
|
procedure edt_puseragendaChange(Sender: TObject);
|
|
procedure clb_usuariosagendaClickCheck(Sender: TObject);
|
|
private
|
|
procedure AdjustCheckListBox(var CB: TCheckListBox);
|
|
procedure marca_todos(clb: TCheckListBox);
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
frmMandaMensagem: TfrmMandaMensagem;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses udtmSystem;
|
|
|
|
{ TfrmMandaEmail }
|
|
|
|
procedure TfrmMandaMensagem.AdjustCheckListBox(var CB: TCheckListBox);
|
|
var
|
|
i, nMaxWidth, nItemWidth: Integer;
|
|
begin
|
|
nMaxWidth := CB.ClientWidth;
|
|
for i := 0 to CB.Items.Count - 1 do
|
|
begin
|
|
nItemWidth := CB.Canvas.TextWidth(CB.Items[i]) + 20;
|
|
if (nItemWidth > nMaxWidth) then
|
|
nMaxWidth := nItemWidth;
|
|
end;
|
|
if (nMaxWidth > CB.ClientWidth) then
|
|
begin
|
|
CB.ScrollWidth := nMaxWidth;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.btn_mandaemailClick(Sender: TObject);
|
|
begin
|
|
if edt_assunto.Text = '' then
|
|
begin
|
|
MessageDlg('Por favor especifique um assunto antes de enviar os e-mails.',
|
|
mtWarning, [mbOK], 0);
|
|
abort;
|
|
end;
|
|
// if dblulb_provs.KeyValue < 0 then
|
|
// begin
|
|
// MessageDlg
|
|
// ('Por favor selecione a providência a ser lançada antes de enviar os e-mails.',
|
|
// mtWarning, [mbOK], 0);
|
|
// abort;
|
|
// end;
|
|
Screen.Cursor := crHourGlass;
|
|
QPesquisa.DisableControls;
|
|
QPesquisa.First;
|
|
pb_pesquisa.Position := 0;
|
|
pb_pesquisa.Max := QPesquisa.RecordCount;
|
|
pb_pesquisa.Step := 1;
|
|
// safe := 'teste1';
|
|
// if safe <> 'teste' then
|
|
// begin
|
|
mb_log.lines.add('Iniciando envio de emails.');
|
|
while not QPesquisa.Eof do
|
|
begin
|
|
// enviou := true;
|
|
try
|
|
case rg_email.ItemIndex of
|
|
0: // Empresa
|
|
begin
|
|
with ACBrMail do
|
|
begin
|
|
Clear;
|
|
IsHTML := true;
|
|
Subject := edt_assunto.Text;
|
|
From := dtmSystem.tblEmpresaTX_EMAIL.AsString;
|
|
FromName := dtmSystem.tblEmpresaTX_EMAILNOME.AsString;
|
|
Host := dtmSystem.tblEmpresaTX_SMTP.AsString;
|
|
Username := dtmSystem.tblEmpresaTX_USUARIO.AsString;
|
|
Password := dtmSystem.tblEmpresaTX_SENHA.AsString;
|
|
Port := dtmSystem.tblEmpresaTX_PORTA.AsString;
|
|
if dtmSystem.tblEmpresaTP_TLS.AsString = 'S' then
|
|
begin
|
|
SetTLS := true;
|
|
end
|
|
else
|
|
begin
|
|
SetTLS := false;
|
|
end;
|
|
if dtmSystem.tblEmpresaTP_SSL.AsString = 'S' then
|
|
begin
|
|
SetSSL := true;
|
|
end
|
|
else
|
|
begin
|
|
SetSSL := false;
|
|
end;
|
|
DefaultCharset := TMailCharset(0);
|
|
IDECharset := TMailCharset(0);
|
|
AddAddress(QPesquisaTX_EMAIL.AsString, QPesquisaTX_NOME.AsString);
|
|
Body.Text :=
|
|
stringreplace(dtsTextoEmail.DataSet.FieldByName('TL_TEXTO')
|
|
.AsString, '% DEVEDOR %', QPesquisaTX_NOME.AsString,
|
|
[rfReplaceAll]);
|
|
Screen.Cursor := crHourGlass;
|
|
Send(false);
|
|
Screen.Cursor := crDefault;
|
|
end;
|
|
end;
|
|
1: // Usuário
|
|
begin
|
|
dtmSystem.tblUsuariosConsulta.Locate('ID_USUARIO',
|
|
dtmSystem.id_usuario, []);
|
|
with ACBrMail do
|
|
begin
|
|
Clear;
|
|
IsHTML := true;
|
|
Subject := edt_assunto.Text;
|
|
From := dtmSystem.tblUsuariosConsultaTX_EMAIL.AsString;
|
|
FromName := dtmSystem.tblUsuariosConsultaTX_EMAILNOME.AsString;
|
|
Host := dtmSystem.tblUsuariosConsultaTX_SMTP.AsString;
|
|
Username := dtmSystem.tblUsuariosConsultaTX_USUARIOEMAIL.AsString;
|
|
Password := dtmSystem.tblUsuariosConsultaTX_SENHAEMAIL.AsString;
|
|
Port := dtmSystem.tblUsuariosConsultaTX_PORTA.AsString;
|
|
if dtmSystem.tblUsuariosConsultaTP_TLS.AsString = 'S' then
|
|
begin
|
|
SetTLS := true;
|
|
end
|
|
else
|
|
begin
|
|
SetTLS := false;
|
|
end;
|
|
if dtmSystem.tblUsuariosConsultaTP_SSL.AsString = 'S' then
|
|
begin
|
|
SetSSL := true;
|
|
end
|
|
else
|
|
begin
|
|
SetSSL := false;
|
|
end;
|
|
DefaultCharset := TMailCharset(0);
|
|
IDECharset := TMailCharset(0);
|
|
AddAddress(QPesquisaTX_EMAIL.AsString, QPesquisaTX_NOME.AsString);
|
|
Body.Text :=
|
|
stringreplace(dtsTextoEmail.DataSet.FieldByName('TL_TEXTO')
|
|
.AsString, '% DEVEDOR %', QPesquisaTX_NOME.AsString,
|
|
[rfReplaceAll]);
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
Send(false);
|
|
Screen.Cursor := crDefault;
|
|
end;
|
|
end;
|
|
end;
|
|
Application.ProcessMessages;
|
|
mb_log.lines.add('Email enviado com sucesso.');
|
|
except
|
|
on E: Exception do
|
|
begin
|
|
// enviou := false;
|
|
mb_log.lines.add('Falha ao enviar email. Devedor: ' +
|
|
QPesquisaTX_NOME.AsString);
|
|
mb_log.lines.add(E.ClassName + ' error raised, with message : ' +
|
|
E.Message);
|
|
end;
|
|
end;
|
|
sleep(750);
|
|
QPesquisa.Next;
|
|
pb_pesquisa.StepIt;
|
|
end;
|
|
// end;
|
|
QPesquisa.First;
|
|
QPesquisa.EnableControls;
|
|
cb_retornaprov.Checked := false;
|
|
mb_log.lines.add('Fim do processo de envio.');
|
|
Screen.Cursor := crDefault;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.btn_pesquisaClick(Sender: TObject);
|
|
var
|
|
string_selecionados, dt_inicio, dt_fim: string;
|
|
i: Integer;
|
|
begin
|
|
|
|
if (not cb_beneficiarios.Checked) and (not cb_providencias.Checked) and
|
|
(not cb_agendamento.Checked) and (not cb_faixanome.Checked) and
|
|
(not cb_atraso.Checked) and (not cb_tipopessoa.Checked) then
|
|
begin
|
|
MessageDlg('Por favor escolha um filtro para a pesquisa.', mtWarning,
|
|
[mbOK], 0);
|
|
abort;
|
|
end;
|
|
lbl_resultado.caption := 'Resultado: ';
|
|
string_selecionados := '';
|
|
mb_log.lines.Clear;
|
|
mb_log.lines.add('Montado a Pesquisa.');
|
|
// começa o sofrimento
|
|
QPesquisa.SQL.Clear;
|
|
with QPesquisa.SQL do // início dasql
|
|
begin
|
|
add('select');
|
|
add('d.tx_nome, t.id_devedor,');
|
|
add('case when d.tp_cliente = ' + QuotedStr('F') + ' then d.cd_cpf');
|
|
add('when d.tp_cliente = ' + QuotedStr('J') + ' then d.cd_cnpj');
|
|
add('end as tx_documento');
|
|
add(',e.tx_email');
|
|
add('from chg_titulos t');
|
|
add('left join chg_devedores d on d.id_devedor = t.id_devedor');
|
|
add('left join chg_emails e on t.id_devedor = e.id_devedor');
|
|
add('where');
|
|
add('char_length(e.tx_email) > 3 and');
|
|
end;
|
|
|
|
if cb_beneficiarios.Checked then // se beneficiarios tá selecionado
|
|
begin
|
|
for i := 1 to clb_beneficiarios.Items.Count - 1 do
|
|
begin
|
|
if clb_beneficiarios.Checked[i] then
|
|
begin
|
|
dtmSystem.tblCHGEmpresa.RecNo := i;
|
|
string_selecionados := string_selecionados +
|
|
dtmSystem.tblCHGEmpresaID_EMPRESA.AsString + ',';
|
|
end;
|
|
end;
|
|
string_selecionados := LeftStr(string_selecionados,
|
|
length(string_selecionados) - 1);
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_empresa in ');
|
|
add('(' + string_selecionados + ')');
|
|
if cb_credorentrada.Checked then
|
|
begin
|
|
dt_inicio := DateToStr(dtp_credorentrada1.Date);
|
|
dt_inicio := RightStr(dt_inicio, 4) + '-' + copy(dt_inicio, 4, 2) + '-'
|
|
+ LeftStr(dt_inicio, 2);
|
|
dt_fim := DateToStr(dtp_credorentrada2.Date);
|
|
dt_fim := RightStr(dt_fim, 4) + '-' + copy(dt_fim, 4, 2) + '-' +
|
|
LeftStr(dt_fim, 2);
|
|
add('and');
|
|
add('cast(t.dt_entrada as date) >= ' + QuotedStr(dt_inicio) + ' and ');
|
|
add('cast(t.dt_entrada as date) <= ' + QuotedStr(dt_fim));
|
|
end;
|
|
if cb_credorvencimento.Checked then
|
|
begin
|
|
dt_inicio := DateToStr(dtp_credorvenc1.Date);
|
|
dt_inicio := RightStr(dt_inicio, 4) + '-' + copy(dt_inicio, 4, 2) + '-'
|
|
+ LeftStr(dt_inicio, 2);
|
|
dt_fim := DateToStr(dtp_credorvenc2.Date);
|
|
dt_fim := RightStr(dt_fim, 4) + '-' + copy(dt_fim, 4, 2) + '-' +
|
|
LeftStr(dt_fim, 2);
|
|
add('and');
|
|
add('cast(t.dt_vencimento as date) >= ' + QuotedStr(dt_inicio)
|
|
+ ' and ');
|
|
add('cast(t.dt_vencimento as date) <= ' + QuotedStr(dt_fim));
|
|
end;
|
|
if cb_credortptitulo.Checked then
|
|
begin
|
|
add('and');
|
|
case rg_credortptitulo.ItemIndex of
|
|
0:
|
|
begin
|
|
add('t.TP_SITUACAO <> ' + QuotedStr('Ç'));
|
|
end;
|
|
1:
|
|
begin
|
|
add('(t.TP_SITUACAO = ' + QuotedStr('A') + 'or t.TP_SITUACAO = ' +
|
|
QuotedStr('AC') + ')');
|
|
end;
|
|
2:
|
|
begin
|
|
add('(t.TP_SITUACAO = ' + QuotedStr('B') + ' OR ');
|
|
add('t.TP_SITUACAO = ' + QuotedStr('QC') + ' OR ');
|
|
add('t.TP_SITUACAO = ' + QuotedStr('QB') + ')');
|
|
end;
|
|
end;
|
|
end;
|
|
add('and ');
|
|
end;
|
|
string_selecionados := '';
|
|
end;
|
|
|
|
if cb_providencias.Checked then // se providências ta selecionado
|
|
begin
|
|
for i := 1 to clb_providencias.Items.Count - 1 do
|
|
begin
|
|
if clb_providencias.Checked[i] then
|
|
begin
|
|
dtmSystem.tblProvidencias.RecNo := i;
|
|
string_selecionados := string_selecionados +
|
|
dtmSystem.tblProvidenciasID_PROVIDENCIA.AsString + ',';
|
|
end;
|
|
end;
|
|
string_selecionados := LeftStr(string_selecionados,
|
|
length(string_selecionados) - 1);
|
|
if rg_filtroprov.ItemIndex >= 0 then
|
|
// se escolheu algum filtro
|
|
begin
|
|
case rg_filtroprov.ItemIndex of
|
|
0: // contenha providencia
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('where h.id_providencia in');
|
|
add('(' + string_selecionados + ')');
|
|
end;
|
|
end;
|
|
1: // não contenha
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_devedor not in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('where h.id_providencia in');
|
|
add('(' + string_selecionados + ')');
|
|
end;
|
|
end;
|
|
2: // seja a última providencia lançada
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('inner join (SELECT h.id_devedor, MAX(h.ID_HISTORICO) AS MAXHIST FROM CHG_HISTORICO h');
|
|
add('group by id_devedor)');
|
|
add('hist on hist.id_devedor = h.id_devedor and h.id_historico = hist.maxhist');
|
|
add('where h.id_providencia in');
|
|
add('(' + string_selecionados + ')');
|
|
end;
|
|
end;
|
|
3: // positivas
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('where');
|
|
add('h.id_providencia in');
|
|
add('(select p.id_providencia from chg_providencias p where');
|
|
add('p.tp_providencia = ' + QuotedStr('Positiva') + ')');
|
|
end;
|
|
end;
|
|
4: // negativas
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('where');
|
|
add('h.id_providencia in');
|
|
add('(select p.id_providencia from chg_providencias p where');
|
|
add('p.tp_providencia = ' + QuotedStr('Negativa') + ')');
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if cb_periodoprov.Checked then
|
|
// se escolheu um período de lançamento da providencia
|
|
begin
|
|
dt_inicio := DateToStr(dtp_provin.Date);
|
|
dt_inicio := RightStr(dt_inicio, 4) + '-' + copy(dt_inicio, 4, 2) + '-'
|
|
+ LeftStr(dt_inicio, 2);
|
|
dt_fim := DateToStr(dtp_provfim.Date);
|
|
dt_fim := RightStr(dt_fim, 4) + '-' + copy(dt_fim, 4, 2) + '-' +
|
|
LeftStr(dt_fim, 2);
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('and ');
|
|
add('cast(h.dt_contato as date) >= ' + QuotedStr(dt_inicio));
|
|
add('and ');
|
|
add('cast(h.dt_contato as date) <= ' + QuotedStr(dt_fim));
|
|
end;
|
|
end;
|
|
if cb_cobradoresprov.Checked then
|
|
begin
|
|
for i := 1 to clb_usuariosprov.Items.Count - 1 do
|
|
begin
|
|
if clb_usuariosprov.Checked[i] then
|
|
begin
|
|
dtmSystem.tblUsuariosConsulta.RecNo := i;
|
|
string_selecionados := string_selecionados +
|
|
dtmSystem.tblUsuariosConsultaID_USUARIO.AsString + ',';
|
|
end;
|
|
end;
|
|
string_selecionados := LeftStr(string_selecionados,
|
|
length(string_selecionados) - 1);
|
|
with QPesquisa.SQL do
|
|
begin
|
|
add('and ');
|
|
add('t.id_devedor in');
|
|
add('(select h.id_devedor from chg_historico h');
|
|
add('where h.id_cobrador in');
|
|
add('(' + string_selecionados + '))');
|
|
end;
|
|
end;
|
|
with QPesquisa.SQL do
|
|
begin
|
|
|
|
add(') ');
|
|
|
|
add('and');
|
|
end;
|
|
string_selecionados := '';
|
|
end;
|
|
end;
|
|
|
|
if cb_tipopessoa.Checked then // tipo de pessoa
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
case rg_tipopessoa.ItemIndex of
|
|
0:
|
|
begin
|
|
add('d.tp_cliente = ' + QuotedStr('F'));
|
|
add('and ');
|
|
end;
|
|
1:
|
|
begin
|
|
add('d.tp_cliente = ' + QuotedStr('J'));
|
|
add('and ');
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if cb_agendamento.Checked then // Agendamento
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
case rg_agendamento.ItemIndex of
|
|
0:
|
|
begin
|
|
|
|
end;
|
|
1:
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select a.id_devedor from chg_agenda a where a.tp_situacao = '
|
|
+ QuotedStr('A') + ')');
|
|
add('and ');
|
|
end;
|
|
2:
|
|
begin
|
|
dt_inicio := DateToStr(dtp_agendcomeco.Date);
|
|
dt_inicio := RightStr(dt_inicio, 4) + '-' + copy(dt_inicio, 4, 2) +
|
|
'-' + LeftStr(dt_inicio, 2);
|
|
dt_fim := DateToStr(dtp_agendfim.Date);
|
|
dt_fim := RightStr(dt_fim, 4) + '-' + copy(dt_fim, 4, 2) + '-' +
|
|
LeftStr(dt_fim, 2);
|
|
add('t.id_devedor in');
|
|
add('(select a.id_devedor from chg_agenda a where a.tp_situacao = '
|
|
+ QuotedStr('A'));
|
|
add('and ');
|
|
add('cast(dt_agendada as date) >= ' + QuotedStr(dt_inicio) + ' ');
|
|
add('and ');
|
|
add('cast(dt_agendada as date) <= ' + QuotedStr(dt_fim) + ')');
|
|
add('and ');
|
|
end;
|
|
3:
|
|
begin
|
|
add('t.id_devedor in');
|
|
add('(select a.id_devedor from chg_agenda a where a.tp_situacao = '
|
|
+ QuotedStr('A'));
|
|
add('and ');
|
|
add('a.dt_agendada <= ' + QuotedStr(FormatDateTime('YYYY-MM-DD',
|
|
Date)) + ')');
|
|
add('and ');
|
|
end;
|
|
4:
|
|
begin
|
|
add('t.id_devedor not in');
|
|
add('(select a.id_devedor from chg_agenda a where tp_situacao = ' +
|
|
QuotedStr('A') + ')');
|
|
add('and ');
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if cb_faixanome.Checked then // faixa de nomes
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
// Upper(d.TX_NOME) similar to '[A-M]_*'
|
|
add('Upper(d.TX_NOME) similar to ' + '''[' + edt_nomein.Text + '-' +
|
|
edt_nomefim.Text + ']_*''');
|
|
add('and ');
|
|
end;
|
|
end;
|
|
|
|
if cb_atraso.Checked then // dias de atraso no título
|
|
begin
|
|
with QPesquisa.SQL do
|
|
begin
|
|
// datediff(day,t.dt_vencimento,cast('now' as date)) >= 1
|
|
add('datediff(day,cast(t.dt_vencimento as date),cast(''now'' as date)) >= '
|
|
+ edt_atrasoin.Text);
|
|
add('and ');
|
|
add('datediff(day,cast(t.dt_vencimento as date),cast(''now'' as date)) <= '
|
|
+ edt_atrasofim.Text);
|
|
add('and ');
|
|
end;
|
|
end;
|
|
|
|
QPesquisa.SQL.Delete(QPesquisa.SQL.Count - 1);
|
|
|
|
QPesquisa.SQL.add
|
|
('group by d.tx_nome, tx_documento, e.tx_email, t.id_devedor');
|
|
|
|
QPesquisa.SQL.add('order by d.tx_nome');
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
mb_log.lines.add('Iniciando a Pesquisa.');
|
|
|
|
QPesquisa.Open;
|
|
|
|
QPesquisa.First;
|
|
|
|
Screen.Cursor := crDefault;
|
|
if QPesquisa.RecordCount > 0 then
|
|
begin
|
|
QPesquisa.First;
|
|
lbl_resultado.caption := 'Resultado: ' + inttostr(QPesquisa.RecordCount) +
|
|
' emails.';
|
|
end;
|
|
mb_log.lines.add('Pesquisa realizada.');
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.Button1Click(Sender: TObject);
|
|
begin
|
|
with ACBrMail do
|
|
begin
|
|
Clear;
|
|
// IsHTML := false;
|
|
IsHTML := true;
|
|
Subject := edt_assunto.Text;
|
|
From := dtmSystem.tblEmpresaTX_EMAIL.AsString;
|
|
FromName := dtmSystem.tblEmpresaTX_EMAILNOME.AsString;
|
|
Host := dtmSystem.tblEmpresaTX_SMTP.AsString;
|
|
Username := dtmSystem.tblEmpresaTX_USUARIO.AsString;
|
|
Password := dtmSystem.tblEmpresaTX_SENHA.AsString;
|
|
Port := dtmSystem.tblEmpresaTX_PORTA.AsString;
|
|
SetTLS := true;
|
|
SetSSL := true;
|
|
DefaultCharset := TMailCharset(0);
|
|
IDECharset := TMailCharset(0);
|
|
AddAddress('marcus@nexverse.com.br', 'marcus');
|
|
Body.Text := stringreplace(dbre_textomensagem.Text, '% DEVEDOR %',
|
|
QPesquisaTX_NOME.AsString, [rfReplaceAll]);
|
|
Application.ProcessMessages;
|
|
Screen.Cursor := crHourGlass;
|
|
Send(false);
|
|
Screen.Cursor := crDefault;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_agendamentoClick(Sender: TObject);
|
|
begin
|
|
case cb_agendamento.Checked of
|
|
true:
|
|
begin
|
|
rg_agendamento.Enabled := cb_agendamento.Checked;
|
|
cb_cobradoresagenda.Enabled := cb_agendamento.Checked;
|
|
end;
|
|
false:
|
|
begin
|
|
rg_agendamento.Enabled := cb_agendamento.Checked;
|
|
cb_cobradoresagenda.Enabled := cb_agendamento.Checked;
|
|
edt_puseragenda.Enabled := cb_agendamento.Checked;
|
|
clb_usuariosagenda.Enabled := cb_agendamento.Checked;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_atrasoClick(Sender: TObject);
|
|
begin
|
|
edt_atrasoin.Enabled := cb_atraso.Checked;
|
|
edt_atrasofim.Enabled := cb_atraso.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_beneficiariosClick(Sender: TObject);
|
|
begin
|
|
case cb_beneficiarios.Checked of
|
|
true:
|
|
begin
|
|
clb_beneficiarios.Enabled := cb_beneficiarios.Checked;
|
|
edt_pcredor.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorentrada.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorvencimento.Enabled := cb_beneficiarios.Checked;
|
|
cb_credortptitulo.Enabled := cb_beneficiarios.Checked;
|
|
end;
|
|
false:
|
|
begin
|
|
clb_beneficiarios.Enabled := cb_beneficiarios.Checked;
|
|
edt_pcredor.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorentrada.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorentrada.Checked := cb_beneficiarios.Checked;
|
|
dtp_credorentrada1.Enabled := cb_beneficiarios.Checked;
|
|
dtp_credorentrada2.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorvencimento.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorvencimento.Checked := cb_beneficiarios.Checked;
|
|
dtp_credorvenc1.Enabled := cb_beneficiarios.Checked;
|
|
dtp_credorvenc2.Enabled := cb_beneficiarios.Checked;
|
|
cb_credortptitulo.Enabled := cb_beneficiarios.Checked;
|
|
rg_credortptitulo.ItemIndex := -1;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_cobradoresagendaClick(Sender: TObject);
|
|
begin
|
|
edt_puseragenda.Enabled := cb_cobradoresagenda.Checked;
|
|
clb_usuariosagenda.Enabled := cb_cobradoresagenda.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_cobradoresClick(Sender: TObject);
|
|
begin
|
|
// clb_usuarios.Enabled := cb_cobradores.Checked;
|
|
// edt_puser.Enabled := cb_cobradores.Enabled;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_cobradoresprovClick(Sender: TObject);
|
|
begin
|
|
edt_puserprov.Enabled := cb_cobradoresprov.Checked;
|
|
clb_usuariosprov.Enabled := cb_cobradoresprov.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_credorentradaClick(Sender: TObject);
|
|
begin
|
|
dtp_credorentrada1.Enabled := cb_credorentrada.Checked;
|
|
dtp_credorentrada2.Enabled := cb_credorentrada.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_credortptituloClick(Sender: TObject);
|
|
begin
|
|
rg_credortptitulo.Enabled := cb_credortptitulo.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_credorvencimentoClick(Sender: TObject);
|
|
begin
|
|
dtp_credorvenc1.Enabled := cb_credorvencimento.Checked;
|
|
dtp_credorvenc2.Enabled := cb_credorvencimento.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_entradaClick(Sender: TObject);
|
|
begin
|
|
// if cb_entrada.Checked = true then
|
|
// begin
|
|
// dtp_entradacomeco.Enabled := true;
|
|
// dtp_entradafim.Enabled := true;
|
|
// end
|
|
// else
|
|
// begin
|
|
// dtp_entradacomeco.Enabled := false;
|
|
// dtp_entradafim.Enabled := false;
|
|
// end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_faixanomeClick(Sender: TObject);
|
|
begin
|
|
edt_nomein.Enabled := cb_faixanome.Checked;
|
|
edt_nomefim.Enabled := cb_faixanome.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_faixavalorClick(Sender: TObject);
|
|
begin
|
|
// edt_faixain.Enabled := cb_faixavalor.Checked;
|
|
// edt_faixafim.Enabled := cb_faixavalor.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_periodoprovClick(Sender: TObject);
|
|
begin
|
|
dtp_provin.Enabled := cb_periodoprov.Checked;
|
|
dtp_provfim.Enabled := cb_periodoprov.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_providenciasClick(Sender: TObject);
|
|
begin
|
|
case cb_providencias.Checked of
|
|
true:
|
|
begin
|
|
clb_providencias.Enabled := cb_providencias.Checked;
|
|
edt_pprov.Enabled := cb_providencias.Checked;
|
|
rg_filtroprov.Enabled := cb_providencias.Checked;
|
|
cb_periodoprov.Enabled := cb_providencias.Checked;
|
|
cb_cobradoresprov.Enabled := cb_providencias.Checked;
|
|
end;
|
|
false:
|
|
begin
|
|
clb_providencias.Enabled := cb_providencias.Checked;
|
|
edt_pprov.Enabled := cb_providencias.Checked;
|
|
rg_filtroprov.Enabled := cb_providencias.Checked;
|
|
dtp_provin.Enabled := cb_providencias.Checked;
|
|
dtp_provfim.Enabled := cb_providencias.Checked;
|
|
cb_periodoprov.Enabled := cb_providencias.Checked;
|
|
cb_cobradoresprov.Enabled := cb_providencias.Checked;
|
|
edt_puserprov.Enabled := cb_providencias.Checked;
|
|
clb_usuariosprov.Enabled := cb_providencias.Checked;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.cb_tipopessoaClick(Sender: TObject);
|
|
begin
|
|
rg_tipopessoa.Enabled := cb_tipopessoa.Checked;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.clb_beneficiariosClickCheck(Sender: TObject);
|
|
begin
|
|
marca_todos(clb_beneficiarios);
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.clb_providenciasClickCheck(Sender: TObject);
|
|
begin
|
|
marca_todos(clb_providencias);
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.clb_usuariosagendaClickCheck(Sender: TObject);
|
|
begin
|
|
marca_todos(clb_usuariosagenda);
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.clb_usuariosprovClickCheck(Sender: TObject);
|
|
begin
|
|
marca_todos(clb_usuariosprov);
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.edt_pcredorChange(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to clb_beneficiarios.Items.Count do
|
|
begin
|
|
try
|
|
if ContainsText(clb_beneficiarios.Items[i], edt_pcredor.Text) then
|
|
begin
|
|
clb_beneficiarios.ItemIndex := i;
|
|
break;
|
|
end;
|
|
except
|
|
break;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.edt_pprovChange(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to clb_providencias.Items.Count do
|
|
begin
|
|
try
|
|
if ContainsText(clb_providencias.Items[i], edt_pprov.Text) then
|
|
begin
|
|
clb_providencias.ItemIndex := i;
|
|
break;
|
|
end;
|
|
except
|
|
break;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.edt_puseragendaChange(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to clb_usuariosagenda.Items.Count do
|
|
begin
|
|
try
|
|
if ContainsText(clb_usuariosagenda.Items[i], edt_puseragenda.Text) then
|
|
begin
|
|
clb_usuariosagenda.ItemIndex := i;
|
|
break;
|
|
end;
|
|
except
|
|
break;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.edt_puserprovClick(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to clb_usuariosprov.Items.Count do
|
|
begin
|
|
try
|
|
if ContainsText(clb_usuariosprov.Items[i], edt_puserprov.Text) then
|
|
begin
|
|
clb_usuariosprov.ItemIndex := i;
|
|
break;
|
|
end;
|
|
except
|
|
break;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.FormCreate(Sender: TObject);
|
|
begin
|
|
sbx_filtro.VertScrollBar.Position := 0;
|
|
|
|
with dtmSystem do
|
|
begin
|
|
if not tblProvidencias.Active then
|
|
begin
|
|
tblProvidencias.Open;
|
|
end
|
|
else
|
|
begin
|
|
tblProvidencias.Refresh;
|
|
end;
|
|
if not tblDevedores.Active then
|
|
begin
|
|
tblDevedores.Open;
|
|
end
|
|
else
|
|
begin
|
|
tblDevedores.Refresh;
|
|
end;
|
|
if not tblHistorico.Active then
|
|
begin
|
|
tblHistorico.Open;
|
|
end
|
|
else
|
|
begin
|
|
tblHistorico.Refresh;
|
|
end;
|
|
if not(tblCHGEmpresa.Active) then
|
|
begin
|
|
tblCHGEmpresa.Open;
|
|
end;
|
|
tblCHGEmpresa.First;
|
|
clb_beneficiarios.Items.add('Marcar Todos');
|
|
while not tblCHGEmpresa.Eof do // preenche o list box
|
|
begin
|
|
clb_beneficiarios.Items.add(tblCHGEmpresaTX_NOME.AsString);
|
|
tblCHGEmpresa.Next;
|
|
end;
|
|
|
|
if not(tblUsuariosConsulta.Active) then
|
|
begin
|
|
tblUsuariosConsulta.Open;
|
|
end;
|
|
tblUsuariosConsulta.First;
|
|
// clb_usuarios.Items.Add('Marcar Todos');
|
|
// while not tblUsuariosConsulta.Eof do // preenche o list box
|
|
// begin
|
|
// clb_usuarios.Items.Add(tblUsuariosConsultaTX_NOME.AsString);
|
|
// tblUsuariosConsulta.Next;
|
|
// end;
|
|
|
|
if not(tblProvidencias.Active) then
|
|
begin
|
|
tblProvidencias.Open;
|
|
end;
|
|
tblProvidencias.First;
|
|
clb_providencias.Items.add('Marcar Todos');
|
|
while not tblProvidencias.Eof do // preenche o list box
|
|
begin
|
|
clb_providencias.Items.add(tblProvidenciasTX_NOME.AsString);
|
|
tblProvidencias.Next;
|
|
end;
|
|
|
|
if not tblTextoEmail.Active then
|
|
begin
|
|
tblTextoEmail.Open;
|
|
end;
|
|
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
|
|
dtp_provin.Date := Date;
|
|
dtp_provfim.Date := Date;
|
|
// dtp_vencicomeco.Date := Date;
|
|
// dtp_vencifim.Date := Date;
|
|
// dtp_entradacomeco.Date := Date;
|
|
// dtp_entradafim.Date := Date;
|
|
|
|
AdjustCheckListBox(clb_beneficiarios);
|
|
AdjustCheckListBox(clb_providencias);
|
|
// AdjustCheckListBox(clb_usuarios);
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.marca_todos(clb: TCheckListBox);
|
|
var
|
|
i, j: Integer;
|
|
begin
|
|
with clb do
|
|
begin
|
|
if Checked[ItemIndex] then
|
|
begin
|
|
Items.beginupdate; // marcou o marca todos, marca todos
|
|
for i := 0 to Items.Count - 1 do
|
|
begin
|
|
if (ItemIndex = 0) and (Checked[i] = true) then
|
|
begin
|
|
for j := 1 to Items.Count - 1 do
|
|
begin
|
|
Checked[j] := true;
|
|
end;
|
|
end;
|
|
Items.EndUpdate;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
Items.beginupdate;
|
|
for i := 0 to Items.Count - 1 do
|
|
// desmarcou o marca todos, desmarca todos
|
|
begin
|
|
if (ItemIndex = 0) and (Checked[i] = false) then
|
|
begin
|
|
for j := 1 to Items.Count - 1 do
|
|
begin
|
|
Checked[j] := false;
|
|
end;
|
|
end;
|
|
Items.EndUpdate;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrmMandaMensagem.rg_agendamentoClick(Sender: TObject);
|
|
begin
|
|
if rg_agendamento.ItemIndex = 2 then
|
|
begin
|
|
dtp_agendcomeco.Enabled := true;
|
|
dtp_agendfim.Enabled := true;
|
|
end
|
|
else
|
|
begin
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
end.
|