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.
2195 lines
61 KiB
2195 lines
61 KiB
unit ucadCampanha;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
System.Classes, Vcl.Graphics, System.DateUtils, System.win.ComObj,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, umstMaster, Vcl.StdCtrls, Vcl.ExtCtrls,
|
|
Vcl.ComCtrls, Vcl.CheckLst, Vcl.Menus, StrUtils, Data.DB, ZAbstractRODataset,
|
|
ZAbstractDataset, ZDataset, Vcl.Grids, Vcl.DBGrids, ZSqlProcessor;
|
|
|
|
type
|
|
TcadCampanha = class(TmstMaster)
|
|
pnl_beneficiarios: TPanel;
|
|
pnl_providências: TPanel;
|
|
Panel2: TPanel;
|
|
cb_beneficiarios: TCheckBox;
|
|
cb_providencias: TCheckBox;
|
|
clb_beneficiarios: TCheckListBox;
|
|
clb_cobradores: TCheckListBox;
|
|
clb_providencias: TCheckListBox;
|
|
ppm_marcar: TPopupMenu;
|
|
MarcarTodos1: TMenuItem;
|
|
DesmarcarTodos1: TMenuItem;
|
|
N1: TMenuItem;
|
|
dtsCadCampanha: TDataSource;
|
|
queryCampanha: TZQuery;
|
|
btn_pesquisa: TButton;
|
|
btn_cancel: TButton;
|
|
btn_ok: TButton;
|
|
pnl_agendamento: TPanel;
|
|
cb_agendamento: TCheckBox;
|
|
dtp_agendcomeco: TDateTimePicker;
|
|
lbl_agendcomeco: TLabel;
|
|
lbl_agendfim: TLabel;
|
|
dtp_agendfim: TDateTimePicker;
|
|
pnl_buttons: TPanel;
|
|
rb_todos: TRadioButton;
|
|
rb_somente: TRadioButton;
|
|
rb_periodo: TRadioButton;
|
|
rb_vencido: TRadioButton;
|
|
rb_naoincluir: TRadioButton;
|
|
edt_nomecamp: TEdit;
|
|
Label1: TLabel;
|
|
pnl_vencimento: TPanel;
|
|
cb_vencimento: TCheckBox;
|
|
lbl_vencicomeco: TLabel;
|
|
dtp_vencicomeco: TDateTimePicker;
|
|
lbl_vencifim: TLabel;
|
|
dtp_vencifim: TDateTimePicker;
|
|
pnl_qntdevedores: TPanel;
|
|
lbl_qntdevedores: TLabel;
|
|
pnl_qnttitulos: TPanel;
|
|
lbl_qnttitulos: TLabel;
|
|
pnl_valorestitulos: TPanel;
|
|
lbl_valorestitulos: TLabel;
|
|
Panel4: TPanel;
|
|
cb_campativa: TCheckBox;
|
|
Label2: TLabel;
|
|
pnl_ordem: TPanel;
|
|
cb_saldocresc: TCheckBox;
|
|
cb_saldodesc: TCheckBox;
|
|
dtp_entradacomeco: TDateTimePicker;
|
|
Label3: TLabel;
|
|
Label4: TLabel;
|
|
dtp_entradafim: TDateTimePicker;
|
|
cb_entrada: TCheckBox;
|
|
sbx_filtro: TScrollBox;
|
|
rg_filtroprov: TRadioGroup;
|
|
pnl_filtroprov: TPanel;
|
|
pnl_faixavalor: TPanel;
|
|
cb_faixavalor: TCheckBox;
|
|
lbl_faixain: TLabel;
|
|
lbl_faixafim: TLabel;
|
|
edt_faixain: TEdit;
|
|
edt_faixafim: TEdit;
|
|
Label5: TLabel;
|
|
dtp_provin: TDateTimePicker;
|
|
Label6: TLabel;
|
|
dtp_provfim: TDateTimePicker;
|
|
cb_periodoprov: TCheckBox;
|
|
pnl_alfabeto: TPanel;
|
|
cb_faixanome: TCheckBox;
|
|
Label7: TLabel;
|
|
Label8: TLabel;
|
|
edt_nomein: TEdit;
|
|
edt_nomefim: TEdit;
|
|
pnl_atraso: TPanel;
|
|
Label9: TLabel;
|
|
Label10: TLabel;
|
|
cb_atraso: TCheckBox;
|
|
edt_atrasoin: TEdit;
|
|
edt_atrasofim: TEdit;
|
|
dtsQueryRel: TDataSource;
|
|
queryRel: TZQuery;
|
|
pnl_escolhefiltro: TPanel;
|
|
pnl_tipopessoa: TPanel;
|
|
cb_tipopessoa: TCheckBox;
|
|
Panel1: TPanel;
|
|
rg_tipopessoa: TRadioGroup;
|
|
pnl_titulo: TPanel;
|
|
cb_titulo: TCheckBox;
|
|
Panel5: TPanel;
|
|
rg_titulo: TRadioGroup;
|
|
mnuFiltro: TMainMenu;
|
|
Filtrodepesquisa1: TMenuItem;
|
|
Novofiltro1: TMenuItem;
|
|
Salvarfiltro1: TMenuItem;
|
|
dtsFiltros: TDataSource;
|
|
ppmnuDeletar: TPopupMenu;
|
|
ApagarFiltro1: TMenuItem;
|
|
dbgrd_filtro: TDBGrid;
|
|
Relatrio1: TMenuItem;
|
|
Gerarplanilha1: TMenuItem;
|
|
pnl_cobradores: TPanel;
|
|
clb_usuarios: TCheckListBox;
|
|
cb_cobradores: TCheckBox;
|
|
cb_bacalhau: TCheckBox;
|
|
ppmnuAcoesExtras: TPopupMenu;
|
|
mnuMassprov: TMenuItem;
|
|
edt_pcredor: TEdit;
|
|
edt_pprov: TEdit;
|
|
edt_puser: TEdit;
|
|
ZSqlProcessor: TZSQLProcessor;
|
|
pnl_txt: TPanel;
|
|
cb_credorentrada: TCheckBox;
|
|
Label11: TLabel;
|
|
dtp_credorentrada1: TDateTimePicker;
|
|
Label12: TLabel;
|
|
dtp_credorentrada2: TDateTimePicker;
|
|
cb_credorvencimento: TCheckBox;
|
|
Label13: TLabel;
|
|
dtp_credorvenc1: TDateTimePicker;
|
|
Label14: TLabel;
|
|
dtp_credorvenc2: TDateTimePicker;
|
|
Panel3: TPanel;
|
|
rg_credortptitulo: TRadioGroup;
|
|
mem_desc: TMemo;
|
|
dbgrd_camp: TDBGrid;
|
|
mnuFichaDev: TMenuItem;
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure clb_beneficiariosClickCheck(Sender: TObject);
|
|
procedure cb_beneficiariosClick(Sender: TObject);
|
|
procedure cb_providenciasClick(Sender: TObject);
|
|
procedure clb_cobradoresClickCheck(Sender: TObject);
|
|
procedure clb_providenciasClickCheck(Sender: TObject);
|
|
procedure MarcarTodos1Click(Sender: TObject);
|
|
procedure DesmarcarTodos1Click(Sender: TObject);
|
|
procedure ppm_marcarPopup(Sender: TObject);
|
|
procedure btn_pesquisaClick(Sender: TObject);
|
|
procedure btn_cancelClick(Sender: TObject);
|
|
procedure btn_okClick(Sender: TObject);
|
|
procedure rb_todosClick(Sender: TObject);
|
|
procedure rb_somenteClick(Sender: TObject);
|
|
procedure rb_periodoClick(Sender: TObject);
|
|
procedure rb_vencidoClick(Sender: TObject);
|
|
procedure rb_naoincluirClick(Sender: TObject);
|
|
procedure cb_agendamentoClick(Sender: TObject);
|
|
procedure cb_vencimentoClick(Sender: TObject);
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
procedure cb_saldodescClick(Sender: TObject);
|
|
procedure cb_saldocrescClick(Sender: TObject);
|
|
procedure cb_entradaClick(Sender: TObject);
|
|
procedure FormShow(Sender: TObject);
|
|
procedure edt_faixainKeyPress(Sender: TObject; var Key: Char);
|
|
procedure edt_faixafimKeyPress(Sender: TObject; var Key: Char);
|
|
procedure cb_faixavalorClick(Sender: TObject);
|
|
procedure cb_periodoprovClick(Sender: TObject);
|
|
procedure cb_faixanomeClick(Sender: TObject);
|
|
procedure edt_nomeinKeyPress(Sender: TObject; var Key: Char);
|
|
procedure edt_nomefimKeyPress(Sender: TObject; var Key: Char);
|
|
procedure edt_atrasoinChange(Sender: TObject);
|
|
procedure edt_atrasofimChange(Sender: TObject);
|
|
procedure sbx_filtroMouseWheelUp(Sender: TObject; Shift: TShiftState;
|
|
MousePos: TPoint; var Handled: Boolean);
|
|
procedure sbx_filtroMouseWheelDown(Sender: TObject; Shift: TShiftState;
|
|
MousePos: TPoint; var Handled: Boolean);
|
|
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
|
|
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
|
procedure cb_tipopessoaClick(Sender: TObject);
|
|
procedure cb_tituloClick(Sender: TObject);
|
|
procedure Novofiltro1Click(Sender: TObject);
|
|
procedure Salvarfiltro1Click(Sender: TObject);
|
|
procedure cb_atrasoClick(Sender: TObject);
|
|
procedure dbgrd_filtroCellClick(Column: TColumn);
|
|
procedure ApagarFiltro1Click(Sender: TObject);
|
|
procedure Gerarplanilha1Click(Sender: TObject);
|
|
procedure clb_usuariosClickCheck(Sender: TObject);
|
|
procedure cb_cobradoresClick(Sender: TObject);
|
|
procedure dbgrd_campTitleClick(Column: TColumn);
|
|
procedure DBGrid2TitleClick(Column: TColumn);
|
|
procedure mnuMassprovClick(Sender: TObject);
|
|
procedure rg_filtroprovClick(Sender: TObject);
|
|
procedure edt_pcredorChange(Sender: TObject);
|
|
procedure edt_pprovChange(Sender: TObject);
|
|
procedure edt_puserChange(Sender: TObject);
|
|
procedure cb_credorentradaClick(Sender: TObject);
|
|
procedure cb_credorvencimentoClick(Sender: TObject);
|
|
procedure cb_credortptituloClick(Sender: TObject);
|
|
procedure mnuFichaDevClick(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
procedure HandlePopupItem(Sender: TObject);
|
|
procedure marca_todos(clb: TCheckListBox);
|
|
procedure WMMoving(var Msg: TWMMoving); message WM_MOVING;
|
|
procedure AdjustCheckListBox(var CB: TCheckListBox);
|
|
function FindSubcontrolAtPos(AControl: TControl;
|
|
AScreenPos, AClientPos: TPoint): TControl;
|
|
public
|
|
desc: string;
|
|
posi: TPoint;
|
|
total_titulos: Integer;
|
|
valor_total: double;
|
|
id_old: Integer;
|
|
mass_prov: string;
|
|
pesquisando: Boolean;
|
|
function checa_marcados: Boolean;
|
|
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
cadCampanha: TcadCampanha;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses udtmSystem, ufrmCampanha, ufrmCobranca,
|
|
System.UITypes, ufrmEscolheProvidencia, ucadDevedores;
|
|
|
|
procedure TcadCampanha.AdjustCheckListBox(var CB: TCheckListBox);
|
|
var
|
|
i, nMaxWidth, nItemWidth: Integer;
|
|
begin
|
|
// ajustar os checklistbox para poder ter scroll horizontal
|
|
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 TcadCampanha.ApagarFiltro1Click(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if MessageDlg('Deseja realmente apagar o filtro?', mtConfirmation,
|
|
[mbYes, mbNo], 0) = mrYes then
|
|
begin
|
|
dtmSystem.tblFiltros.Delete;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.btn_cancelClick(Sender: TObject);
|
|
begin
|
|
// d'uh
|
|
Close;
|
|
end;
|
|
|
|
procedure TcadCampanha.btn_okClick(Sender: TObject);
|
|
var
|
|
i, campanha: Integer;
|
|
algumcob: Boolean;
|
|
begin
|
|
algumcob := false;
|
|
for i := 1 to clb_cobradores.Items.Count - 1 do
|
|
begin
|
|
if clb_cobradores.Checked[i] then
|
|
begin
|
|
algumcob := true;
|
|
end;
|
|
end;
|
|
if algumcob = false then
|
|
begin
|
|
if MessageDlg('Você está prestes a criar uma campanha sem cobradores.' +
|
|
' Deseja continuar?', mtInformation, mbYesNo, 0) = mrNo then
|
|
begin
|
|
ModalResult := mrNone;
|
|
Abort;
|
|
end;
|
|
end;
|
|
// cria a campanha conforme o resultado do filtro utilizado
|
|
if edt_nomecamp.Text <> '' then
|
|
begin
|
|
Screen.Cursor := crHourGlass;
|
|
with dtmSystem do
|
|
begin
|
|
tblCobCampanha.Append;
|
|
tblCobCampanhaTX_NOME.AsString := edt_nomecamp.Text;
|
|
tblCobCampanhaDT_CAD.AsString := FormatDateTime('DD/MM/YYYY', Date);
|
|
tblCobCampanhaTX_DESC.AsString := desc;
|
|
tblCobCampanhaTL_DESC.AsString := mem_desc.Lines.Text;
|
|
if cb_campativa.Checked then
|
|
begin
|
|
tblCobCampanhaTP_ATIVA.AsString := '1';
|
|
end
|
|
else
|
|
begin
|
|
tblCobCampanhaTP_ATIVA.AsString := '0';
|
|
end;
|
|
tblCobCampanhaTP_CONCLUIDA.AsInteger := 0;
|
|
tblCobCampanhaQUEM_CAD.AsInteger := dtmSystem.id_usuario;
|
|
tblCobCampanha.Post;
|
|
campanha := tblCobCampanhaID_CAMPANHA.AsInteger;
|
|
// dbgrd_camp.DataSource.DataSet.DisableControls;
|
|
// frmCampanha.dbg_consultados.DataSource.DataSet.DisableControls;
|
|
// queryCampanha.DisableControls;
|
|
// queryCampanha.First;
|
|
// tblCampanhaDevedores.DisableControls;
|
|
// pb_campanha.Position := 0;
|
|
// if not tblCampanhaDevedores.Active then
|
|
// begin
|
|
// tblCampanhaDevedores.Open;
|
|
// end;
|
|
// while not queryCampanha.Eof do
|
|
// begin
|
|
// tblCampanhaDevedores.Append;
|
|
// tblCampanhaDevedoresID_CAMPANHA.AsInteger := campanha;
|
|
// tblCampanhaDevedoresID_DEVEDOR.AsInteger :=
|
|
// queryCampanha.FieldByName('ID_DEVEDOR').AsInteger;
|
|
// tblCampanhaDevedoresTX_DOCUMENTO.AsString :=
|
|
// queryCampanha.FieldByName('TX_DOCUMENTO').AsString;
|
|
// tblCampanhaDevedoresTP_ESTADO.AsString := 'A';
|
|
// tblCampanhaDevedoresTP_COBRANDO.AsInteger := -1;
|
|
// tblCampanhaDevedores.Post;
|
|
// Application.ProcessMessages;
|
|
// queryCampanha.Next;
|
|
// pb_campanha.StepIt;
|
|
// end;
|
|
pnl_txt.Caption :=
|
|
'Montando campanha. Este procedimento pode demorar alguns minutos. Por favor aguarde.';
|
|
ZSqlProcessor.Script.Text := StringReplace(queryCampanha.SQL.Text,
|
|
'select t.id_devedor,',
|
|
'insert into chg_campanhas_devedores(id_item, id_campanha, id_devedor, tx_documento, tp_estado, tp_cobrando) select coalesce((select max(id_item) + 1 from chg_campanhas_devedores), 1) as id_item,'
|
|
+ tblCobCampanhaID_CAMPANHA.AsString +
|
|
' as id_campanha, g.id_devedor, g.tx_documento, ''A'' as tp_estado, -1 as tp_cobrando from ( select t.id_devedor,',
|
|
[rfIgnoreCase]);
|
|
ZSqlProcessor.Script.Add(') g');
|
|
ZSqlProcessor.Execute;
|
|
// queryCampanha.EnableControls;
|
|
// tblCampanhaDevedores.EnableControls;
|
|
// dbgrd_camp.DataSource.DataSet.EnableControls;
|
|
// frmCampanha.dbg_consultados.DataSource.DataSet.EnableControls;
|
|
|
|
for i := 1 to clb_cobradores.Items.Count - 1 do
|
|
begin
|
|
if clb_cobradores.Checked[i] then
|
|
begin
|
|
tblCampanhaCob.Append;
|
|
// monta tabela de relação campanha - cobrador
|
|
tblCampanhaCobID_CAMPANHA.AsInteger := campanha;
|
|
tblUsuariosConsulta.Locate('TX_NOME', clb_cobradores.Items[i], []);
|
|
tblCampanhaCobID_COBRADOR.AsInteger :=
|
|
tblUsuariosConsultaID_USUARIO.AsInteger;
|
|
tblCampanhaCobID_ULTIMO_USUARIO.AsInteger := dtmSystem.id_usuario;
|
|
tblCampanhaCobDT_HORA_ULTIMA_ATT.AsDateTime := Now;
|
|
tblCampanhaCob.Post;
|
|
end;
|
|
end;
|
|
end;
|
|
Screen.Cursor := crDefault;
|
|
ModalResult := mrOk;
|
|
pnl_txt.Caption := 'Campanha gerada.';
|
|
end
|
|
else
|
|
begin
|
|
MessageDlg('Por favor insira um nome para a campanha.', mtError, [mbok], 0);
|
|
ModalResult := mrNone;
|
|
edt_nomecamp.SetFocus;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.btn_pesquisaClick(Sender: TObject);
|
|
var
|
|
string_selecionados, dt_inicio, dt_fim, order_by: string;
|
|
i: Integer;
|
|
//qtde: integer;
|
|
begin
|
|
pesquisando := true;
|
|
valor_total := 0;
|
|
total_titulos := 0;
|
|
if checa_marcados = false then
|
|
begin
|
|
MessageDlg('Por favor escolha um filtro antes de realizar uma pesquisa.',
|
|
mtWarning, [mbok], 0);
|
|
Abort;
|
|
end;
|
|
if cb_beneficiarios.Checked and (rg_credortptitulo.ItemIndex < 0) then
|
|
begin
|
|
MessageDlg('Por favor escolha o tipo de título para o filtro.', mtWarning,
|
|
[mbok], 0);
|
|
Abort;
|
|
end;
|
|
string_selecionados := '';
|
|
desc := 'Campos Selecionados:';
|
|
|
|
// pb_campanha.Position := 0;
|
|
|
|
// começa o sofrimento
|
|
queryCampanha.SQL.Clear;
|
|
with queryCampanha.SQL do // início dasql
|
|
begin
|
|
Add('select t.id_devedor,');
|
|
Add('d.tx_nome,');
|
|
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('count(t.id_titulo) as quant,');
|
|
Add('sum(t.vl_titulo) as total');
|
|
Add('from chg_titulos t');
|
|
Add('left join chg_devedores d on d.id_devedor = t.id_devedor');
|
|
Add('where');
|
|
end;
|
|
|
|
mem_desc.Lines.Clear;
|
|
|
|
if cb_beneficiarios.Checked then // se beneficiarios tá selecionado
|
|
begin
|
|
mem_desc.Lines.Add('Credores:');
|
|
//qtde := 0;
|
|
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 + ',';
|
|
mem_desc.Lines.Add(dtmSystem.tblCHGEmpresaTX_NOME.AsString + '.');
|
|
//Inc(qtde, 1);
|
|
end;
|
|
end;
|
|
string_selecionados := LeftStr(string_selecionados,
|
|
length(string_selecionados) - 1);
|
|
with queryCampanha.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));
|
|
mem_desc.Lines.Add('Entrada entre ' + DateToStr(dtp_credorentrada1.Date)
|
|
+ ' e ' + DateToStr(dtp_credorentrada2.Date) + '.');
|
|
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));
|
|
mem_desc.Lines.Add('Vencimento entre ' +
|
|
DateToStr(dtp_credorentrada1.Date) + ' e ' +
|
|
DateToStr(dtp_credorentrada2.Date) + '.');
|
|
end;
|
|
// if cb_credortptitulo.Checked then
|
|
// begin
|
|
Add('and');
|
|
case rg_credortptitulo.ItemIndex of
|
|
0:
|
|
begin
|
|
Add('t.TP_SITUACAO <> ' + QuotedStr('Ç'));
|
|
mem_desc.Lines.Add('Todos os títulos.');
|
|
end;
|
|
1:
|
|
begin
|
|
Add('(t.TP_SITUACAO = ' + QuotedStr('A') + 'or t.TP_SITUACAO = ' +
|
|
QuotedStr('AC') + ')');
|
|
mem_desc.Lines.Add('Títulos abertos.');
|
|
end;
|
|
2:
|
|
begin
|
|
Add('(t.TP_SITUACAO = ' + QuotedStr('B') + ' OR ');
|
|
Add('t.TP_SITUACAO = ' + QuotedStr('QC')+ ' OR ');
|
|
Add('t.TP_SITUACAO = ' + QuotedStr('QB') + ')');
|
|
mem_desc.Lines.Add('Títulos baixados.');
|
|
end;
|
|
end;
|
|
// end;
|
|
Add('and ');
|
|
end;
|
|
string_selecionados := '';
|
|
desc := desc + ' Credores, ';
|
|
end;
|
|
|
|
if cb_providencias.Checked then // se providências ta selecionado
|
|
begin
|
|
// selecionoup := 0;
|
|
mem_desc.Lines.Add('Providências.');
|
|
//qtde := 0;
|
|
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 + ',';
|
|
// selecionoup := 1;
|
|
mem_desc.Lines.Add(dtmSystem.tblProvidenciasTX_NOME.AsString + '.');
|
|
//Inc(qtde, 1);
|
|
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:
|
|
begin
|
|
with queryCampanha.SQL do
|
|
// contenha providencia
|
|
begin
|
|
Add('t.id_devedor in');
|
|
Add('(select h.id_devedor from chg_historico h');
|
|
Add('where h.id_providencia in');
|
|
Add('(' + string_selecionados + ')');
|
|
mem_desc.Lines.Add('Contenha as providências acima.');
|
|
end;
|
|
end;
|
|
1: // não contenha
|
|
begin
|
|
with queryCampanha.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 + ')');
|
|
mem_desc.Lines.Add('Não contenha as providências acima.');
|
|
end;
|
|
end;
|
|
2: // seja a última providencia lançada
|
|
begin
|
|
with queryCampanha.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 + ')');
|
|
mem_desc.Lines.Add
|
|
('Última providência tenha sido alguma das acima.');
|
|
// Add('group by id_devedor)');
|
|
// Add('hist on hist.id_devedor = h.id_devedor and h.id_historico = hist.max_hist)');
|
|
end;
|
|
end;
|
|
3: // positivas
|
|
begin
|
|
with queryCampanha.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') + ')');
|
|
mem_desc.Lines.Add('Todas as providências positivas.');
|
|
end;
|
|
end;
|
|
4: // negativas
|
|
begin
|
|
with queryCampanha.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') + ')');
|
|
mem_desc.Lines.Add('Todas as providências negativas.');
|
|
end;
|
|
end;
|
|
end;
|
|
string_selecionados := '';
|
|
with queryCampanha.SQL do
|
|
begin
|
|
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);
|
|
Add('and ');
|
|
Add('cast(h.dt_contato as date) >= ' + QuotedStr(dt_inicio));
|
|
Add('and ');
|
|
Add('cast(h.dt_contato as date) <= ' + QuotedStr(dt_fim));
|
|
mem_desc.Lines.Add('Período de acionamento entre ' +
|
|
DateToStr(dtp_provin.Date) + ' e ' +
|
|
DateToStr(dtp_provfim.Date) + '.');
|
|
Add(') ');
|
|
// Add('hist on hist.id_devedor = h.id_devedor and h.id_historico = hist.maxhist)');
|
|
Add('and ');
|
|
end
|
|
else
|
|
begin
|
|
Add(') ');
|
|
// Add('hist on hist.id_devedor = h.id_devedor and h.id_historico = hist.maxhist)');
|
|
// Add(')');
|
|
Add('and ');
|
|
end;
|
|
end;
|
|
end;
|
|
string_selecionados := '';
|
|
desc := desc + ' Providências, ';
|
|
end;
|
|
|
|
if cb_tipopessoa.Checked then // tipo de pessoa
|
|
begin
|
|
mem_desc.Lines.Add('Tipo de pessoas:');
|
|
with queryCampanha.SQL do
|
|
begin
|
|
case rg_tipopessoa.ItemIndex of
|
|
0:
|
|
begin
|
|
Add('d.tp_cliente = ' + QuotedStr('F'));
|
|
Add('and ');
|
|
mem_desc.Lines.Add('Física.');
|
|
end;
|
|
1:
|
|
begin
|
|
Add('d.tp_cliente = ' + QuotedStr('J'));
|
|
Add('and ');
|
|
mem_desc.Lines.Add('Jurídica.');
|
|
end;
|
|
end;
|
|
end;
|
|
desc := desc + ' Tipo de pessoa, ';
|
|
end;
|
|
|
|
if cb_agendamento.Checked then // Agendamento
|
|
begin
|
|
mem_desc.Lines.Add('Agendamento:');
|
|
with queryCampanha.SQL do
|
|
begin
|
|
if rb_todos.Checked then // todos
|
|
begin
|
|
// Add('chg_devedores.id_devedor in');
|
|
// Add('(select id_devedor from chg_agenda where tp_situacao = ''A'' or tp_situacao = ''C'')');
|
|
// Add('and ');
|
|
mem_desc.Lines.Add('Incluir todos agendados.');
|
|
end;
|
|
|
|
if rb_somente.Checked then // somente os abertos
|
|
begin
|
|
Add('t.id_devedor in');
|
|
Add('(select a.id_devedor from chg_agenda a where a.tp_situacao = ' +
|
|
QuotedStr('A') + ')');
|
|
Add('and ');
|
|
mem_desc.Lines.Add('Apenas aqueles em aberto.');
|
|
end;
|
|
|
|
if rb_periodo.Checked then // durante período
|
|
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 ');
|
|
mem_desc.Lines.Add('Período de acionamento entre ' +
|
|
DateToStr(dtp_agendcomeco.Date) + ' e ' +
|
|
DateToStr(dtp_agendfim.Date) + '.');
|
|
end;
|
|
|
|
if rb_vencido.Checked then // vencimento do agendamento
|
|
begin
|
|
// Add('chg_devedores.id_devedor in');
|
|
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 ');
|
|
mem_desc.Lines.Add('Agendamentos vencidos.');
|
|
end;
|
|
|
|
if rb_naoincluir.Checked then // não incluir
|
|
begin
|
|
Add('t.id_devedor not in');
|
|
Add('(select a.id_devedor from chg_agenda a where tp_situacao = ' +
|
|
QuotedStr('A') + ')');
|
|
Add('and ');
|
|
mem_desc.Lines.Add('Não incluir agendados.');
|
|
end;
|
|
end;
|
|
desc := desc + ' Agendamento, ';
|
|
end;
|
|
|
|
if cb_faixanome.Checked then // faixa de nomes
|
|
begin
|
|
with queryCampanha.SQL do
|
|
begin
|
|
// Upper(d.TX_NOME) similar to '[A-M]_*'
|
|
Add('Upper(d.TX_NOME COLLATE WIN_PTBR) similar to ' + '''[' + edt_nomein.Text + '-' +
|
|
edt_nomefim.Text + ']_*''');
|
|
Add('and ');
|
|
end;
|
|
desc := desc + ' Nome, ';
|
|
mem_desc.Lines.Add('Nomes entre ' + edt_nomein.Text + ' e ' +
|
|
edt_nomefim.Text + '.');
|
|
end;
|
|
|
|
if cb_atraso.Checked then // dias de atraso no título
|
|
begin
|
|
with queryCampanha.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 ');
|
|
mem_desc.Lines.Add('Títulos com atrasado entre ' + edt_atrasoin.Text +
|
|
' e ' + edt_atrasofim.Text + '.');
|
|
end;
|
|
desc := desc + ' Atraso, ';
|
|
end;
|
|
|
|
desc := LeftStr(desc, length(desc) - 2);
|
|
desc := desc + '.';
|
|
queryCampanha.SQL.Delete(queryCampanha.SQL.Count - 1);
|
|
queryCampanha.SQL.Add('group by t.ID_DEVEDOR, d.TX_NOME, TX_DOCUMENTO');
|
|
// agrupar a query
|
|
|
|
if cb_faixavalor.Checked then // valor do título
|
|
begin
|
|
queryCampanha.SQL.Add('having');
|
|
queryCampanha.SQL.Add('(' + StringReplace(edt_faixain.Text, ',', '.',
|
|
[rfReplaceAll, rfReplaceAll]) + ' <= sum(t.vl_titulo))');
|
|
queryCampanha.SQL.Add('and');
|
|
queryCampanha.SQL.Add('(' + 'sum(t.vl_titulo) <= ' +
|
|
StringReplace(edt_faixafim.Text, ',', '.',
|
|
[rfReplaceAll, rfReplaceAll]) + ')');
|
|
desc := desc + ' Valor devido, ';
|
|
mem_desc.Lines.Add('Títulos com valores entre ' + edt_faixain.Text + ' e ' +
|
|
edt_faixafim.Text + '.');
|
|
end;
|
|
|
|
order_by := '';
|
|
if cb_saldocresc.Checked then
|
|
begin
|
|
order_by := 'total, d.tx_nome';
|
|
end
|
|
else if cb_saldodesc.Checked then
|
|
begin
|
|
order_by := 'total desc, d.tx_nome';
|
|
end
|
|
else
|
|
begin
|
|
order_by := 'd.tx_nome';
|
|
end;
|
|
queryCampanha.SQL.Add('order by ' + order_by);
|
|
// if (selecionoub =1) and (selecionouc =1) and (selecionoup = 1) then //se escolheu algo dentro dos filtros
|
|
// if erro_sql = '' then
|
|
// begin
|
|
pnl_txt.Caption :=
|
|
'Realizando a Pesquisa. Este procedimento pode demorar alguns minutos. Por favor aguarde.';
|
|
Screen.Cursor := crHourGlass;
|
|
// Application.ProcessMessages;
|
|
queryCampanha.Open;
|
|
dbgrd_camp.Columns[0].Title.Caption := 'ID';
|
|
dbgrd_camp.Columns[1].Title.Caption := 'Nome';
|
|
dbgrd_camp.Columns[2].Title.Caption := 'Documento';
|
|
dbgrd_camp.Columns[3].Visible := false;
|
|
dbgrd_camp.Columns[4].Visible := false;
|
|
total_titulos := 0;
|
|
queryCampanha.First;
|
|
|
|
while not queryCampanha.Eof do
|
|
begin
|
|
total_titulos := total_titulos + queryCampanha.FieldByName('quant')
|
|
.AsInteger;
|
|
valor_total := valor_total + queryCampanha.FieldByName('total').AsFloat;
|
|
Application.ProcessMessages;
|
|
queryCampanha.Next;
|
|
end;
|
|
|
|
queryCampanha.First;
|
|
lbl_qntdevedores.Caption := 'Devedores: ' +
|
|
IntToStr(queryCampanha.RecordCount) + '.';
|
|
lbl_qnttitulos.Caption := 'Títulos: ' + IntToStr(total_titulos) + '.';
|
|
lbl_valorestitulos.Caption := 'Total: R$' + FormatFloat('0.00',
|
|
valor_total) + '.';
|
|
// FormatFloat('0.00',valor_total)
|
|
Screen.Cursor := crDefault;
|
|
if queryCampanha.RecordCount > 0 then
|
|
begin
|
|
btn_ok.Enabled := true;
|
|
// pb_campanha.max := queryCampanha.RecordCount;
|
|
queryCampanha.First;
|
|
end
|
|
else
|
|
begin
|
|
btn_ok.Enabled := false;
|
|
end;
|
|
pnl_txt.Caption := 'Pesquisa realizada.';
|
|
// end
|
|
// else
|
|
// begin
|
|
// MessageDlg('Você selecinou o(os) filtro(os): ' + erro_sql +
|
|
// 'mas não os configurou corretamente.' + ' Por favor configure-os.',
|
|
// mtWarning, [mbok], 0);
|
|
// end;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_agendamentoClick(Sender: TObject);
|
|
begin
|
|
|
|
// habilitar ou desabilitar o panel
|
|
if cb_agendamento.Checked = true then
|
|
begin
|
|
pnl_buttons.Enabled := true;
|
|
end
|
|
else
|
|
begin
|
|
pnl_buttons.Enabled := false;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_atrasoClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
edt_atrasoin.Enabled := cb_atraso.Checked;
|
|
edt_atrasofim.Enabled := cb_atraso.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_beneficiariosClick(Sender: TObject);
|
|
begin
|
|
// habilitar ou desabilitar o list box
|
|
clb_beneficiarios.Enabled := cb_beneficiarios.Checked;
|
|
edt_pcredor.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorentrada.Enabled := cb_beneficiarios.Checked;
|
|
cb_credorvencimento.Enabled := cb_beneficiarios.Checked;
|
|
rg_credortptitulo.Enabled := cb_beneficiarios.Checked;
|
|
// cb_credortptitulo.Enabled := cb_beneficiarios.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_cobradoresClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
clb_usuarios.Enabled := cb_cobradores.Checked;
|
|
edt_puser.Enabled := cb_cobradores.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_credorentradaClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
dtp_credorentrada1.Enabled := cb_credorentrada.Checked;
|
|
dtp_credorentrada2.Enabled := cb_credorentrada.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_credortptituloClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// rg_credortptitulo.Enabled := cb_credortptitulo.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_credorvencimentoClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
dtp_credorvenc1.Enabled := cb_credorvencimento.Checked;
|
|
dtp_credorvenc2.Enabled := cb_credorvencimento.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.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 TcadCampanha.cb_faixanomeClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
edt_nomein.Enabled := cb_faixanome.Checked;
|
|
edt_nomefim.Enabled := cb_faixanome.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_faixavalorClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
edt_faixain.Enabled := cb_faixavalor.Checked;
|
|
edt_faixafim.Enabled := cb_faixavalor.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_periodoprovClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
dtp_provin.Enabled := cb_periodoprov.Checked;
|
|
dtp_provfim.Enabled := cb_periodoprov.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_providenciasClick(Sender: TObject);
|
|
begin
|
|
|
|
// habilitar ou desabilitar o list box
|
|
if cb_providencias.Checked = true then
|
|
begin
|
|
clb_providencias.Enabled := true;
|
|
edt_pprov.Enabled := true;
|
|
end
|
|
else
|
|
begin
|
|
clb_providencias.Enabled := false;
|
|
edt_pprov.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_saldocrescClick(Sender: TObject);
|
|
begin
|
|
if cb_saldocresc.Checked then
|
|
begin
|
|
cb_saldodesc.Checked := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_saldodescClick(Sender: TObject);
|
|
begin
|
|
if cb_saldodesc.Checked then
|
|
begin
|
|
cb_saldocresc.Checked := false;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_tipopessoaClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
rg_tipopessoa.Enabled := cb_tipopessoa.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_tituloClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// rg_credortptitulo.Enabled := cb_credortptitulo.Checked;
|
|
end;
|
|
|
|
procedure TcadCampanha.cb_vencimentoClick(Sender: TObject);
|
|
begin
|
|
// habilitar ou desabilitar o list box
|
|
if cb_vencimento.Checked = true then
|
|
begin
|
|
dtp_vencicomeco.Enabled := true;
|
|
dtp_vencifim.Enabled := true;
|
|
end
|
|
else
|
|
begin
|
|
dtp_vencicomeco.Enabled := false;
|
|
dtp_vencifim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.clb_beneficiariosClickCheck(Sender: TObject);
|
|
begin
|
|
marca_todos(clb_beneficiarios);
|
|
end;
|
|
|
|
procedure TcadCampanha.clb_cobradoresClickCheck(Sender: TObject);
|
|
begin
|
|
|
|
marca_todos(clb_cobradores);
|
|
end;
|
|
|
|
procedure TcadCampanha.clb_providenciasClickCheck(Sender: TObject);
|
|
begin
|
|
|
|
marca_todos(clb_providencias);
|
|
end;
|
|
|
|
procedure TcadCampanha.clb_usuariosClickCheck(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
marca_todos(clb_usuarios);
|
|
end;
|
|
|
|
procedure TcadCampanha.dbgrd_filtroCellClick(Column: TColumn);
|
|
var
|
|
campos: TStringList;
|
|
i: Integer;
|
|
begin
|
|
inherited;
|
|
// montar as opções conforme filtro escolhido
|
|
with dtmSystem do
|
|
begin
|
|
if tblFiltros.RecordCount > 0 then
|
|
begin
|
|
if tblFiltrosTP_CREDOR.AsString = '1' then
|
|
begin
|
|
cb_beneficiarios.Checked := true;
|
|
cb_beneficiariosClick(Self);
|
|
if length(tblFiltrosTX_CREDOR.AsString) > 0 then
|
|
begin
|
|
campos := TStringList.Create;
|
|
try
|
|
campos.Clear;
|
|
campos.Delimiter := ';';
|
|
campos.DelimitedText := tblFiltrosTL_CREDOR.AsString;
|
|
finally
|
|
for i := 0 to campos.Count - 2 do
|
|
begin
|
|
clb_beneficiarios.Checked[strtoint(campos[i])] := true;
|
|
end;
|
|
end;
|
|
end;
|
|
if tblFiltrosTP_TITULO.AsString = '1' then
|
|
begin
|
|
// cb_credortptitulo.Checked := true;
|
|
// cb_credortptituloClick(self);
|
|
if tblFiltrosCD_TITULO.AsInteger >= 0 then
|
|
begin
|
|
rg_credortptitulo.ItemIndex := tblFiltrosCD_TITULO.AsInteger;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if tblFiltrosTP_PROVIDENCIA.AsString = '1' then
|
|
begin
|
|
cb_providencias.Checked := true;
|
|
cb_providenciasClick(Self);
|
|
if length(tblFiltrosTX_CREDOR.AsString) > 0 then
|
|
begin
|
|
campos := TStringList.Create;
|
|
try
|
|
campos.Clear;
|
|
campos.Delimiter := ';';
|
|
campos.DelimitedText := tblFiltrosTL_PROV.AsString;
|
|
finally
|
|
for i := 0 to campos.Count - 2 do
|
|
begin
|
|
clb_providencias.Checked[strtoint(campos[i])] := true;
|
|
end;
|
|
end;
|
|
end;
|
|
if tblFiltrosCD_PROVIDENCIA.AsInteger >= 0 then
|
|
begin
|
|
rg_filtroprov.ItemIndex := tblFiltrosCD_PROVIDENCIA.AsInteger;
|
|
end;
|
|
end;
|
|
|
|
if tblFiltrosTP_VALOR.AsString = '1' then
|
|
begin
|
|
cb_faixavalor.Checked := true;
|
|
cb_faixavalorClick(Self);
|
|
if tblFiltrosVL_VALORIN.AsString <> '' then
|
|
begin
|
|
edt_faixain.Text := tblFiltrosVL_VALORIN.AsString;
|
|
end;
|
|
if tblFiltrosVL_VALORFIM.AsString <> '' then
|
|
begin
|
|
edt_faixafim.Text := tblFiltrosVL_VALORFIM.AsString;
|
|
end;
|
|
end;
|
|
|
|
if tblFiltrosTP_AGENDADO.AsString = '1' then
|
|
begin
|
|
cb_agendamento.Checked := true;
|
|
cb_agendamentoClick(Self);
|
|
case tblFiltrosTX_AGENDADO.AsInteger of
|
|
0:
|
|
begin
|
|
rb_todos.Checked := true;
|
|
end;
|
|
1:
|
|
begin
|
|
rb_somente.Checked := true;
|
|
end;
|
|
2:
|
|
begin
|
|
rb_periodo.Checked := true;
|
|
end;
|
|
3:
|
|
begin
|
|
rb_vencido.Checked := true;
|
|
end;
|
|
4:
|
|
begin
|
|
rb_naoincluir.Checked := true;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if tblFiltrosTP_NOME.AsString = '1' then
|
|
begin
|
|
cb_faixanome.Checked := true;
|
|
cb_faixanomeClick(Self);
|
|
edt_nomein.Text := copy(tblFiltrosTX_NOME.AsString, 1, 1);
|
|
edt_nomefim.Text := copy(tblFiltrosTX_NOME.AsString, 2, 1);
|
|
end;
|
|
|
|
if tblFiltrosTP_ATRASO.AsString = '1' then
|
|
begin
|
|
cb_atraso.Checked := true;
|
|
cb_atrasoClick(Self);
|
|
edt_atrasoin.Text := tblFiltrosTX_ATRASOIN.AsString;
|
|
edt_atrasofim.Text := tblFiltrosTX_ATRASOFIM.AsString;
|
|
end;
|
|
|
|
if tblFiltrosTP_PESSOA.AsString = '1' then
|
|
begin
|
|
cb_tipopessoa.Checked := true;
|
|
cb_tipopessoaClick(Self);
|
|
if tblFiltrosCD_PESSOA.AsInteger >= 0 then
|
|
begin
|
|
rg_tipopessoa.ItemIndex := tblFiltrosCD_PESSOA.AsInteger;
|
|
end;
|
|
end;
|
|
|
|
if tblFiltrosCD_ORDEM.AsString <> '' then
|
|
begin
|
|
case tblFiltrosCD_ORDEM.AsInteger of
|
|
1:
|
|
begin
|
|
cb_saldocresc.Checked := true;
|
|
end;
|
|
2:
|
|
begin
|
|
cb_saldodesc.Checked := true;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.dbgrd_campTitleClick(Column: TColumn);
|
|
begin
|
|
inherited;
|
|
// dar sorting na tabela conforme a coluna clicada
|
|
if Column.Title.Caption <> '' then
|
|
begin
|
|
if Pos(Column.Field.FieldName, queryCampanha.SortedFields) = 1 then
|
|
begin
|
|
if queryCampanha.SortType = stAscending then
|
|
begin
|
|
queryCampanha.SortType := stDescending;
|
|
end
|
|
else
|
|
begin
|
|
queryCampanha.SortType := stAscending;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
queryCampanha.SortedFields := Column.Field.FieldName;
|
|
if queryCampanha.SortType = stAscending then
|
|
begin
|
|
queryCampanha.SortType := stDescending;
|
|
end
|
|
else
|
|
begin
|
|
queryCampanha.SortType := stAscending;
|
|
end;
|
|
end;
|
|
end;
|
|
queryCampanha.First;
|
|
end;
|
|
|
|
procedure TcadCampanha.DBGrid2TitleClick(Column: TColumn);
|
|
begin
|
|
inherited;
|
|
if Column.Title.Caption <> '' then
|
|
begin
|
|
if Pos(Column.Field.FieldName, queryRel.SortedFields) = 1 then
|
|
begin
|
|
if queryRel.SortType = stAscending then
|
|
begin
|
|
queryRel.SortType := stDescending;
|
|
end
|
|
else
|
|
begin
|
|
queryRel.SortType := stAscending;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
queryRel.SortedFields := Column.Field.FieldName;
|
|
if queryRel.SortType = stAscending then
|
|
begin
|
|
queryRel.SortType := stDescending;
|
|
end
|
|
else
|
|
begin
|
|
queryRel.SortType := stAscending;
|
|
end;
|
|
end;
|
|
end;
|
|
queryRel.First;
|
|
end;
|
|
|
|
procedure TcadCampanha.DesmarcarTodos1Click(Sender: TObject);
|
|
var
|
|
i: Integer; // func do popupmenu pra desmarcar todos
|
|
begin // dependendo de quem chamou o popup
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_beneficiarios' then
|
|
begin
|
|
for i := 0 to clb_beneficiarios.Items.Count - 1 do
|
|
begin
|
|
clb_beneficiarios.Checked[i] := false;
|
|
end;
|
|
end;
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_cobradores' then
|
|
begin
|
|
for i := 0 to clb_cobradores.Items.Count - 1 do
|
|
begin
|
|
clb_cobradores.Checked[i] := false;
|
|
end;
|
|
end;
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_providencias' then
|
|
begin
|
|
for i := 0 to clb_providencias.Items.Count - 1 do
|
|
begin
|
|
clb_providencias.Checked[i] := false;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
//function TcadCampanha.FindControlAtPos(AScreenPos: TPoint): TControl;
|
|
//var
|
|
// i: Integer;
|
|
// f, m: TForm;
|
|
// p: TPoint;
|
|
// r: TRect;
|
|
//begin
|
|
// // função para descobrir o controle que se encontra abaixo do mouse
|
|
// Result := nil;
|
|
// for i := Screen.FormCount - 1 downto 0 do
|
|
// begin
|
|
// f := Screen.Forms[i];
|
|
// if f.Visible and (f.Parent = nil) and (f.FormStyle <> fsMDIChild) and
|
|
// TRect.Create(f.Left, f.Top, f.Left + f.Width, f.Top + f.Height)
|
|
// .Contains(AScreenPos) then
|
|
// Result := f;
|
|
// end;
|
|
// Result := FindSubcontrolAtPos(Result, AScreenPos, AScreenPos);
|
|
// if (Result is TForm) and (TForm(Result).ClientHandle <> 0) then
|
|
// begin
|
|
// Winapi.Windows.GetWindowRect(TForm(Result).ClientHandle, r);
|
|
// p := TPoint.Create(AScreenPos.X - r.Left, AScreenPos.Y - r.Top);
|
|
// m := nil;
|
|
// for i := TForm(Result).MDIChildCount - 1 downto 0 do
|
|
// begin
|
|
// f := TForm(Result).MDIChildren[i];
|
|
// if TRect.Create(f.Left, f.Top, f.Left + f.Width, f.Top + f.Height)
|
|
// .Contains(p) then
|
|
// m := f;
|
|
// end;
|
|
// if m <> nil then
|
|
// Result := FindSubcontrolAtPos(m, AScreenPos, p);
|
|
// end;
|
|
//end;
|
|
|
|
function TcadCampanha.FindSubcontrolAtPos(AControl: TControl;
|
|
AScreenPos, AClientPos: TPoint): TControl;
|
|
var
|
|
i: Integer;
|
|
C: TControl;
|
|
begin
|
|
Result := nil;
|
|
C := AControl;
|
|
if (C = nil) or not C.Visible or not TRect.Create(C.Left, C.Top,
|
|
C.Left + C.Width, C.Top + C.Height).Contains(AClientPos) then
|
|
exit;
|
|
Result := AControl;
|
|
if AControl is TWinControl then
|
|
for i := 0 to TWinControl(AControl).ControlCount - 1 do
|
|
begin
|
|
C := FindSubcontrolAtPos(TWinControl(AControl).Controls[i], AScreenPos,
|
|
AControl.ScreenToClient(AScreenPos));
|
|
if C <> nil then
|
|
Result := C;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
begin
|
|
queryCampanha.Close;
|
|
dtmSystem.tblCHGEmpresa.Close;
|
|
dtmSystem.tblUsuariosConsulta.Close;
|
|
dtmSystem.tblProvidencias.Close;
|
|
dtmSystem.tblGrupos.Close;
|
|
// cadCampanha := nil;
|
|
Action := caFree;
|
|
end;
|
|
|
|
procedure TcadCampanha.FormCreate(Sender: TObject);
|
|
var
|
|
Item: TMenuItem;
|
|
begin
|
|
mass_prov := '';
|
|
with dtmSystem do
|
|
begin
|
|
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_cobradores.Items.Add('Marcar Todos');
|
|
clb_usuarios.Items.Add('Marcar Todos');
|
|
while not tblUsuariosConsulta.Eof do // preenche o list box
|
|
begin
|
|
clb_cobradores.Items.Add(tblUsuariosConsultaTX_NOME.AsString);
|
|
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(tblGrupos.Active) then
|
|
begin
|
|
tblGrupos.Open;
|
|
end;
|
|
tblGrupos.First;
|
|
while not tblGrupos.Eof do
|
|
begin
|
|
Item := TMenuItem.Create(ppm_marcar);
|
|
Item.Caption := tblGruposTX_NOME.AsString;
|
|
// cria os menus extras do popupmenu
|
|
Item.Visible := false; // conforme necessidade dos grupos
|
|
Item.OnClick := HandlePopupItem;
|
|
ppm_marcar.Items.Add(Item);
|
|
tblGrupos.Next;
|
|
end;
|
|
|
|
if not tblFiltros.Active then
|
|
begin
|
|
tblFiltros.Open;
|
|
end;
|
|
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
|
|
end;
|
|
cb_saldodesc.Checked := true;
|
|
dtp_credorentrada1.Date := Date;
|
|
dtp_credorentrada2.Date := Date;
|
|
dtp_credorvenc1.Date := Date;
|
|
dtp_credorvenc2.Date := Date;
|
|
dtp_provin.Date := Date;
|
|
dtp_provfim.Date := Date;
|
|
dtp_vencicomeco.Date := Date;
|
|
dtp_vencifim.Date := Date;
|
|
dtp_entradacomeco.Date := Date;
|
|
dtp_entradafim.Date := Date;
|
|
|
|
id_old := -1;
|
|
|
|
AdjustCheckListBox(clb_beneficiarios);
|
|
AdjustCheckListBox(clb_cobradores);
|
|
AdjustCheckListBox(clb_providencias);
|
|
AdjustCheckListBox(clb_usuarios);
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.FormKeyDown(Sender: TObject; var Key: Word;
|
|
Shift: TShiftState);
|
|
begin
|
|
inherited;
|
|
if Key = VK_ESCAPE then
|
|
begin
|
|
Key := 0;
|
|
Close;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.FormMouseWheel(Sender: TObject; Shift: TShiftState;
|
|
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
|
|
begin
|
|
// posi := Mouse.CursorPos;
|
|
// Control := FindControlAtPos(posi);
|
|
// if Control is TScrollBox then
|
|
// begin
|
|
sbx_filtro.VertScrollBar.Position := sbx_filtro.VertScrollBar.Position -
|
|
(WheelDelta div 12);
|
|
// end;
|
|
end;
|
|
|
|
procedure TcadCampanha.FormShow(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
sbx_filtro.VertScrollBar.Position := 0;
|
|
end;
|
|
|
|
procedure TcadCampanha.Gerarplanilha1Click(Sender: TObject);
|
|
|
|
var
|
|
OpenOffice, OpenDesktop, OOCalc, OOExec, Planilha, LoadParams, Param: Variant;
|
|
i, j: Integer;
|
|
begin
|
|
// gera a planilha do relatório da campanha
|
|
if dbgrd_camp.DataSource.DataSet.RecordCount = 0 then
|
|
begin
|
|
Abort;
|
|
end;
|
|
|
|
btn_pesquisa.Enabled := false;
|
|
btn_ok.Enabled := false;
|
|
btn_cancel.Enabled := false;
|
|
|
|
Screen.Cursor := crHourGlass;
|
|
|
|
if VarIsEmpty(OpenOffice) then
|
|
begin
|
|
OpenOffice := CreateOleObject('com.sun.star.ServiceManager');
|
|
end;
|
|
OpenDesktop := OpenOffice.CreateInstance('com.sun.star.frame.Desktop');
|
|
|
|
LoadParams := VarArrayCreate([0, 0], varVariant);
|
|
Param := OpenOffice.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
|
|
Param.Name := 'Hidden';
|
|
Param.Value := true;
|
|
LoadParams[0] := Param;
|
|
|
|
OOExec := OpenDesktop.LoadComponentFromURL('private:factory/scalc', '_blank',
|
|
0, LoadParams);
|
|
OOCalc := OOExec.Sheets;
|
|
Planilha := OOCalc.getbyIndex(0);
|
|
|
|
// pb_campanha.max := DBGrid2.DataSource.DataSet.RecordCount;
|
|
// pb_campanha.Position := 0;
|
|
|
|
dbgrd_camp.DataSource.DataSet.First;
|
|
|
|
for j := 0 to dbgrd_camp.DataSource.DataSet.RecordCount do
|
|
begin
|
|
for i := 0 to dbgrd_camp.Columns.Count - 1 do
|
|
begin
|
|
if j = 0 then
|
|
begin
|
|
Planilha.getCellByPosition(i, j).string := dbgrd_camp.Columns[i]
|
|
.Title.Caption;
|
|
end
|
|
else
|
|
begin
|
|
Planilha.getCellByPosition(i, j).string := dbgrd_camp.Columns[i]
|
|
.Field.AsString;
|
|
end;
|
|
Planilha.getCellByPosition(i, j).getColumns.getbyIndex(0)
|
|
.OptimalWidth := true;
|
|
Application.ProcessMessages;
|
|
end;
|
|
if j > 0 then
|
|
begin
|
|
if not(dbgrd_camp.DataSource.DataSet.Eof) then
|
|
begin
|
|
dbgrd_camp.DataSource.DataSet.Next;
|
|
end;
|
|
// pb_campanha.StepIt;
|
|
end;
|
|
end;
|
|
|
|
try
|
|
OOExec.CurrentController.Frame.ContainerWindow.Visible := true;
|
|
finally
|
|
OpenOffice := Unassigned;
|
|
btn_pesquisa.Enabled := true;
|
|
btn_ok.Enabled := true;
|
|
btn_cancel.Enabled := true;
|
|
end;
|
|
|
|
Screen.Cursor := crDefault;
|
|
end;
|
|
|
|
procedure TcadCampanha.MarcarTodos1Click(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
// marca todos conforme quem chamou o popupmenu
|
|
begin
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_beneficiarios' then
|
|
begin
|
|
for i := 0 to clb_beneficiarios.Items.Count - 1 do
|
|
begin
|
|
clb_beneficiarios.Checked[i] := true;
|
|
end;
|
|
end;
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_cobradores' then
|
|
begin
|
|
for i := 0 to clb_cobradores.Items.Count - 1 do
|
|
begin
|
|
clb_cobradores.Checked[i] := true;
|
|
end;
|
|
end;
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_providencias' then
|
|
begin
|
|
for i := 0 to clb_providencias.Items.Count - 1 do
|
|
begin
|
|
clb_providencias.Checked[i] := true;
|
|
end;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.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 TcadCampanha.mnuFichaDevClick(Sender: TObject);
|
|
begin
|
|
if not dtmSystem.tblDevedores.Active then
|
|
begin
|
|
dtmSystem.tblDevedores.Open;
|
|
end
|
|
else
|
|
begin
|
|
dtmSystem.tblDevedores.Refresh;
|
|
end;
|
|
if dtmSystem.tblDevedores.Locate('ID_DEVEDOR',
|
|
queryCampanha.FieldByName('ID_DEVEDOR').AsString, []) then
|
|
begin
|
|
cadDevedores := TcadDevedores.Create(Self);
|
|
cadDevedores.ShowModal;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.mnuMassprovClick(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
// lançar providência em massa
|
|
// if queryRel.RecordCount > 0 then
|
|
// begin
|
|
// frmEscolheProv := TfrmEscolheProv.Create(Self);
|
|
// frmEscolheProv.ShowModal;
|
|
// if frmEscolheProv.ModalResult = mrOk then
|
|
// begin
|
|
// // pb_campanha.max := queryRel.RecordCount;
|
|
// // pb_campanha.Position := 0;
|
|
// // pb_campanha.Step := 1;
|
|
// queryRel.First;
|
|
// dtmSystem.tblProvidencias.Locate('TX_NOME', mass_prov, []);
|
|
// if not(dtmSystem.tblHistorico.Active) then
|
|
// begin
|
|
// dtmSystem.tblHistorico.Open;
|
|
// end;
|
|
// Application.ProcessMessages;
|
|
// while not(queryRel.Eof) do
|
|
// begin
|
|
// with dtmSystem do
|
|
// begin
|
|
// tblDevedores.Locate('TX_NOME', queryRel.FieldByName('TX_NOME')
|
|
// .AsString, []);
|
|
// tblHistorico.Append;
|
|
// tblHistoricoID_DEVEDOR.AsInteger := tblDevedoresID_DEVEDOR.AsInteger;
|
|
// tblHistoricoID_PROVIDENCIA.AsInteger :=
|
|
// tblProvidenciasID_PROVIDENCIA.AsInteger;
|
|
// tblHistoricoID_COBRADOR.AsInteger := id_usuario;
|
|
// tblHistoricoDT_CONTATO.AsDateTime := Date;
|
|
// tblHistorico.Post;
|
|
// end;
|
|
// queryRel.Next;
|
|
// // pb_campanha.StepIt;
|
|
// end;
|
|
// dtmSystem.tblHistorico.Close;
|
|
// showmessage('Lançamento das providências em massa terminou!');
|
|
// end;
|
|
// end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.Novofiltro1Click(Sender: TObject);
|
|
var
|
|
nome: string;
|
|
begin
|
|
inherited;
|
|
nome := '';
|
|
while (nome = '') do
|
|
begin
|
|
if InputQuery('Insira o nome do filtro', 'Nome: ', nome) then
|
|
begin
|
|
if nome <> '' then
|
|
begin
|
|
with dtmSystem do
|
|
begin
|
|
tblFiltros.Append;
|
|
tblFiltrosTX_NOME_FILTRO.AsString := nome;
|
|
tblFiltros.Post;
|
|
end;
|
|
MessageDlg('Por favor salve o filtro ao terminar de configurá-lo.',
|
|
mtWarning, [mbok], 0);
|
|
end
|
|
else
|
|
begin
|
|
MessageDlg('Não é possível criar um filtro sem nome.', mtWarning,
|
|
[mbok], 0);
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
MessageDlg('Você cancelou a criação de um novo filtro.', mtWarning,
|
|
[mbok], 0);
|
|
end;
|
|
end;
|
|
|
|
end;
|
|
|
|
//function TcadCampanha.PixtoCM(pix: Integer): double;
|
|
//var
|
|
// ppcm: double;
|
|
//begin
|
|
// ppcm := Screen.PixelsPerInch / 2540;
|
|
// Result := pix / ppcm;
|
|
//end;
|
|
|
|
procedure TcadCampanha.ppm_marcarPopup(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
// mostra ou esconde os menus extras do popupmenu
|
|
begin // conforme quem chamou o popupmenu
|
|
|
|
if ppm_marcar.PopupComponent.Name = 'clb_cobradores' then
|
|
begin
|
|
for i := 0 to ppm_marcar.Items.Count - 1 do
|
|
begin
|
|
if i >= 3 then
|
|
begin
|
|
ppm_marcar.Items.Items[i].Visible := true;
|
|
end;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
for i := 0 to ppm_marcar.Items.Count - 1 do
|
|
begin
|
|
if i >= 3 then
|
|
begin
|
|
ppm_marcar.Items.Items[i].Visible := false;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rb_naoincluirClick(Sender: TObject);
|
|
begin
|
|
|
|
if rb_naoincluir.Checked then
|
|
begin
|
|
rb_somente.Checked := false;
|
|
rb_periodo.Checked := false;
|
|
rb_vencido.Checked := false;
|
|
rb_todos.Checked := false;
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rb_periodoClick(Sender: TObject);
|
|
begin
|
|
|
|
if rb_periodo.Checked then
|
|
begin
|
|
rb_somente.Checked := false;
|
|
rb_todos.Checked := false;
|
|
rb_vencido.Checked := false;
|
|
rb_naoincluir.Checked := false;
|
|
dtp_agendcomeco.Enabled := true;
|
|
dtp_agendfim.Enabled := true;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rb_somenteClick(Sender: TObject);
|
|
begin
|
|
|
|
if rb_somente.Checked then
|
|
begin
|
|
rb_todos.Checked := false;
|
|
rb_periodo.Checked := false;
|
|
rb_vencido.Checked := false;
|
|
rb_naoincluir.Checked := false;
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rb_todosClick(Sender: TObject);
|
|
begin
|
|
|
|
if rb_todos.Checked then
|
|
begin
|
|
rb_somente.Checked := false;
|
|
rb_periodo.Checked := false;
|
|
rb_vencido.Checked := false;
|
|
rb_naoincluir.Checked := false;
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rb_vencidoClick(Sender: TObject);
|
|
begin
|
|
|
|
if rb_vencido.Checked then
|
|
begin
|
|
rb_somente.Checked := false;
|
|
rb_periodo.Checked := false;
|
|
rb_todos.Checked := false;
|
|
rb_naoincluir.Checked := false;
|
|
dtp_agendcomeco.Enabled := false;
|
|
dtp_agendfim.Enabled := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.rg_filtroprovClick(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
inherited;
|
|
if (rg_filtroprov.ItemIndex = 3) or (rg_filtroprov.ItemIndex = 4) then
|
|
begin
|
|
for i := 0 to clb_providencias.Items.Count - 1 do
|
|
begin
|
|
clb_providencias.Checked[i] := false;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.Salvarfiltro1Click(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
str_helper: string;
|
|
begin
|
|
inherited;
|
|
with dtmSystem do
|
|
begin
|
|
tblFiltros.Edit;
|
|
if cb_beneficiarios.Checked then
|
|
begin
|
|
tblFiltrosTP_CREDOR.AsInteger := 1;
|
|
str_helper := '';
|
|
for i := 0 to clb_beneficiarios.Items.Count - 1 do
|
|
begin
|
|
if clb_beneficiarios.Checked[i] then
|
|
begin
|
|
str_helper := str_helper + IntToStr(i) + ';'
|
|
end;
|
|
end;
|
|
tblFiltrosTL_CREDOR.AsString := str_helper;
|
|
tblFiltrosTP_TITULO.AsInteger := 1;
|
|
tblFiltrosCD_TITULO.AsInteger := rg_credortptitulo.ItemIndex;
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_CREDOR.AsInteger := 0;
|
|
tblFiltrosTX_CREDOR.AsString := '';
|
|
tblFiltrosTP_TITULO.AsInteger := 0;
|
|
tblFiltrosCD_TITULO.AsString := '';
|
|
end;
|
|
|
|
if cb_providencias.Checked then
|
|
begin
|
|
tblFiltrosTP_PROVIDENCIA.AsInteger := 1;
|
|
str_helper := '';
|
|
for i := 0 to clb_providencias.Items.Count - 1 do
|
|
begin
|
|
if clb_providencias.Checked[i] then
|
|
begin
|
|
str_helper := str_helper + IntToStr(i) + ';';
|
|
end;
|
|
end;
|
|
tblFiltrosTL_PROV.AsString := str_helper;
|
|
tblFiltrosCD_PROVIDENCIA.AsInteger := rg_filtroprov.ItemIndex;
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_PROVIDENCIA.AsInteger := 0;
|
|
tblFiltrosTX_PROVIDENCIA.AsString := '';
|
|
tblFiltrosCD_PROVIDENCIA.AsString := '';
|
|
end;
|
|
|
|
if cb_faixavalor.Checked then
|
|
begin
|
|
tblFiltrosTP_VALOR.AsInteger := 1;
|
|
tblFiltrosVL_VALORIN.AsCurrency := StrToCurr(edt_faixain.Text);
|
|
tblFiltrosVL_VALORFIM.AsCurrency := StrToCurr(edt_faixafim.Text);
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_VALOR.AsInteger := 0;
|
|
tblFiltrosVL_VALORIN.AsString := '';
|
|
tblFiltrosVL_VALORFIM.AsString := '';
|
|
end;
|
|
|
|
if cb_agendamento.Checked then
|
|
begin
|
|
tblFiltrosTP_AGENDADO.AsInteger := 1;
|
|
if rb_todos.Checked then
|
|
tblFiltrosTX_AGENDADO.AsString := '0';
|
|
if rb_somente.Checked then
|
|
tblFiltrosTX_AGENDADO.AsString := '1';
|
|
if rb_periodo.Checked then
|
|
tblFiltrosTX_AGENDADO.AsString := '2';
|
|
if rb_vencido.Checked then
|
|
tblFiltrosTX_AGENDADO.AsString := '3';
|
|
if rb_naoincluir.Checked then
|
|
tblFiltrosTX_AGENDADO.AsString := '4';
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_AGENDADO.AsInteger := 0;
|
|
tblFiltrosTX_AGENDADO.AsString := '';
|
|
end;
|
|
|
|
if cb_faixanome.Checked then
|
|
begin
|
|
tblFiltrosTP_NOME.AsInteger := 1;
|
|
tblFiltrosTX_NOME.AsString := edt_nomein.Text + edt_nomefim.Text;
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_NOME.AsInteger := 0;
|
|
tblFiltrosTX_NOME.AsString := '';
|
|
end;
|
|
|
|
if cb_atraso.Checked then
|
|
begin
|
|
tblFiltrosTX_ATRASOIN.AsString := edt_atrasoin.Text;
|
|
tblFiltrosTX_ATRASOFIM.AsString := edt_atrasofim.Text;
|
|
end;
|
|
|
|
if cb_tipopessoa.Checked then
|
|
begin
|
|
tblFiltrosTP_PESSOA.AsInteger := 1;
|
|
tblFiltrosCD_PESSOA.AsInteger := rg_tipopessoa.ItemIndex;
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosTP_PESSOA.AsInteger := 0;
|
|
tblFiltrosCD_PESSOA.AsString := '';
|
|
end;
|
|
|
|
if cb_saldocresc.Checked then
|
|
begin
|
|
tblFiltrosCD_ORDEM.AsInteger := 1;
|
|
end
|
|
else if cb_saldodesc.Checked then
|
|
begin
|
|
tblFiltrosCD_ORDEM.AsInteger := 2;
|
|
end
|
|
else
|
|
begin
|
|
tblFiltrosCD_ORDEM.AsInteger := 0;
|
|
end;
|
|
tblFiltros.Post;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.sbx_filtroMouseWheelDown(Sender: TObject;
|
|
Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
|
|
begin
|
|
inherited;
|
|
sbx_filtro.Perform(WM_VSCROLL, 1, 0);
|
|
end;
|
|
|
|
procedure TcadCampanha.sbx_filtroMouseWheelUp(Sender: TObject;
|
|
Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
|
|
begin
|
|
inherited;
|
|
sbx_filtro.Perform(WM_VSCROLL, 0, 0);
|
|
end;
|
|
|
|
procedure TcadCampanha.WMMoving(var Msg: TWMMoving);
|
|
var
|
|
workArea: TRect;
|
|
begin
|
|
workArea := Screen.WorkareaRect;
|
|
|
|
with Msg.DragRect^ do
|
|
begin
|
|
if Left < workArea.Left then
|
|
OffsetRect(Msg.DragRect^, workArea.Left - Left, 0);
|
|
|
|
if Top < workArea.Top then
|
|
OffsetRect(Msg.DragRect^, 0, workArea.Top - Top);
|
|
|
|
if Right > workArea.Right then
|
|
OffsetRect(Msg.DragRect^, workArea.Right - Right, 0);
|
|
|
|
if Bottom > workArea.Bottom then
|
|
OffsetRect(Msg.DragRect^, 0, workArea.Bottom - Bottom);
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.HandlePopupItem(Sender: TObject);
|
|
var
|
|
menuItem: TMenuItem;
|
|
helper: string;
|
|
// handler dos menus extras do popupmenu
|
|
id_helper: string;
|
|
i, cont_helper, cont_helper2: Integer;
|
|
begin
|
|
cont_helper := 0;
|
|
cont_helper2 := 0;
|
|
menuItem := TMenuItem(Sender);
|
|
helper := ReplaceStr(menuItem.Caption, '&', '');
|
|
with dtmSystem do
|
|
begin
|
|
tblGrupos.Open;
|
|
tblGrupos.First;
|
|
while not tblGrupos.Eof do
|
|
begin
|
|
if helper = tblGruposTX_NOME.AsString then
|
|
begin
|
|
id_helper := tblGruposID_GRUPO.AsString;
|
|
end;
|
|
tblGrupos.Next;
|
|
end;
|
|
end;
|
|
|
|
for i := 1 to clb_cobradores.Items.Count - 1 do
|
|
begin
|
|
dtmSystem.tblUsuariosConsulta.Locate('TX_NOME',
|
|
clb_cobradores.Items[i], []);
|
|
if dtmSystem.tblUsuariosConsultaID_GRUPO.AsString = id_helper then
|
|
begin
|
|
if clb_cobradores.Checked[i] = false then
|
|
begin
|
|
clb_cobradores.Checked[i] := true;
|
|
end
|
|
else
|
|
begin
|
|
clb_cobradores.Checked[i] := false;
|
|
end;
|
|
end;
|
|
|
|
if (clb_cobradores.Checked[i] = false) and (i > 0) then
|
|
begin
|
|
cont_helper := cont_helper + 1
|
|
end;
|
|
if (clb_cobradores.Checked[i] = true) and (i > 0) then
|
|
begin
|
|
cont_helper2 := cont_helper2 + 1
|
|
end;
|
|
|
|
end;
|
|
|
|
if cont_helper = clb_cobradores.Items.Count - 1 then
|
|
begin
|
|
clb_cobradores.Checked[0] := false;
|
|
end;
|
|
if cont_helper2 = clb_cobradores.Items.Count - 1 then
|
|
begin
|
|
clb_cobradores.Checked[0] := true;
|
|
end;
|
|
end;
|
|
|
|
function TcadCampanha.checa_marcados: Boolean;
|
|
begin
|
|
if (cb_beneficiarios.Checked = false) and (cb_providencias.Checked = false)
|
|
and (cb_agendamento.Checked = false) and (cb_vencimento.Checked = false) and
|
|
(cb_faixavalor.Checked = false) and (cb_faixanome.Checked = false) and
|
|
(cb_atraso.Checked = false) and (cb_tipopessoa.Checked = false) and
|
|
(cb_titulo.Checked = false) and (cb_entrada.Checked = false) and
|
|
(cb_cobradores.Checked = false) then
|
|
begin
|
|
Result := false;
|
|
end
|
|
else
|
|
begin
|
|
Result := true;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_atrasofimChange(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if strtoint(edt_atrasofim.Text) < 0 then
|
|
begin
|
|
edt_atrasofim.Text := '0';
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_atrasoinChange(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if strtoint(edt_atrasoin.Text) < 0 then
|
|
begin
|
|
edt_atrasoin.Text := '0';
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_faixafimKeyPress(Sender: TObject; var Key: Char);
|
|
begin
|
|
inherited;
|
|
if not(Key in [#8, '0' .. '9',
|
|
System.SysUtils.FormatSettings.DecimalSeparator]) then
|
|
begin
|
|
Key := #0;
|
|
end
|
|
else if (Key = System.SysUtils.FormatSettings.DecimalSeparator) and
|
|
(Pos(Key, edt_faixafim.Text) > 0) then
|
|
begin
|
|
Key := #0;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_faixainKeyPress(Sender: TObject; var Key: Char);
|
|
begin
|
|
inherited;
|
|
if not(Key in [#8, '0' .. '9',
|
|
System.SysUtils.FormatSettings.DecimalSeparator]) then
|
|
begin
|
|
Key := #0;
|
|
end
|
|
else if (Key = System.SysUtils.FormatSettings.DecimalSeparator) and
|
|
(Pos(Key, edt_faixain.Text) > 0) then
|
|
begin
|
|
Key := #0;
|
|
end;
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_nomefimKeyPress(Sender: TObject; var Key: Char);
|
|
begin
|
|
inherited;
|
|
if Key in ['A' .. 'Z', 'a' .. 'z'] then
|
|
else
|
|
Key := #0;
|
|
end;
|
|
|
|
procedure TcadCampanha.edt_nomeinKeyPress(Sender: TObject; var Key: Char);
|
|
begin
|
|
inherited;
|
|
if Key in ['A' .. 'Z', 'a' .. 'z'] then
|
|
else
|
|
Key := #0;
|
|
end;
|
|
|
|
procedure TcadCampanha.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 TcadCampanha.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 TcadCampanha.edt_puserChange(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to clb_usuarios.Items.Count do
|
|
begin
|
|
try
|
|
if ContainsText(clb_usuarios.Items[i], edt_puser.Text) then
|
|
begin
|
|
clb_usuarios.ItemIndex := i;
|
|
break;
|
|
end;
|
|
except
|
|
break;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
end.
|
|
|
|
|
|
|