Geração Duplicatas Delphi - Firebird

20/03/2021

0

Olá boa noite!
Galera é o seguinte! Tenho uma tela de venda aonde na finalização da mesma, o usuário irá selecionar a forma de pagamento. Ao selecionar a forma de pagamento que gere uma parcela Ex: Duplicata, quero que minha aplicação incremente no banco de dados as parcelas com as datas predefinidas, com a data de vencimento de 30 em 30 dias.

Ex:

Venda em um valor total de R$300, no qual foi dividida em 3 vezes para o cliente.

Tabela Recebimento:

ID_VENDA FORMA PAGAMENTO ID_CLINTE NOME CLIENTE VALOR_PARCELA DATA_VENCIMENTO
1 DUPLICTAS 10 CONSUMIDOR FINAL 100 20/04/2021

ID_VENDA FORMA PAGAMENTO ID_CLINTE NOME CLIENTE VALOR_PARCELA DATA_VENCIMENTO
1 DUPLICTAS 10 CONSUMIDOR FINAL 100 20/05/2021

ID_VENDA FORMA PAGAMENTO ID_CLINTE NOME CLIENTE VALOR_PARCELA DATA_VENCIMENTO
1 DUPLICTAS 10 CONSUMIDOR FINAL 100 20/06/2021
Jefferson

Jefferson

Responder

Posts

20/03/2021

Jefferson

Não ficou organizado o exemplo da tabela, reformulei.

ID_VENDA : FORMA PAGAMENTO : ID_CLINTE : NOME CLIENTE : VALOR_PARCELA : DATA_VENCIMENTO
1 : DUPLICTAS : 10 : CONSUMIDOR FINAL : 100 : 20/04/2021

ID_VENDA : FORMA PAGAMENTO : ID_CLINTE : NOME CLIENTE : VALOR_PARCELA : DATA_VENCIMENTO
1 : DUPLICTAS : 10 : CONSUMIDOR FINAL : 100 : 20/05/2021

ID_VENDA : FORMA PAGAMENTO : ID_CLINTE : NOME CLIENTE : VALOR_PARCELA : DATA_VENCIMENTO
1 : DUPLICTAS : 10 : CONSUMIDOR FINAL : 100 : 20/06/2021

Responder

22/03/2021

Emerson Nascimento

vamos lá... primeiro você deveria publicar o código que você está tentando usar. ou não tentou nada?
depois, indicar como está a modelagem do banco para a(s) tabela(s) envolvida(s) nesse processo.
você tem uma tabela de venda e outra de duplicatas?
o ideal seria uma tabela de venda, e outra somente com as duplicatas.
ID_VENDA
DATA_VENCIMENTO
VALOR_PARCELA

você pode criar um procedimento para esse parcelamento (pode também fazer por stored procedure).

procedure TForm1.Parcelamento(IDVenda: integer; ValorVenda: Currency; Parcelas: integer);
var
  ValorParcela, Diferenca: Currency;
  Vencimento: TDateTime;
  iParcela: integer;
begin
  ValorParcela := System.Math.SimpleRoundTo(ValorVenda / Parcelas);
  Diferenca := ValorVenda - (ValorParcela * Parcelas);
  Vencimento := Date;

  for iParcela := 1 to Parcelas do
  begin
    if iParcela = Parcelas then
      ValorParcela := ValorParcela - Diferenca; // tira a diferenca na última parcela

    Vencimento := IncDay(Vencimento, 30);

    // insere o registro da parcela na tabela de duplicatas
    // insert into duplicatas (ID_VENDA, DATA_VENCIMENTO, VALOR_PARCELA)
    // values (IDVenda, Vencimento, ValorParcela)
    
  end;


end;



Responder

24/03/2021

Jefferson

Olá amigo boa noite!
Realmente as informações no qual eu repassei está vaga. Vou explicar novamente.


Seguinte, Tenha 3 tabelas ( VENDA_ORC, VENDA_ORC_PRODUTO, VENDA_PAGAMENTO), as 3 estão ´parametrizadas e interligadas, de modo para que eu tenha que gerar uma informação na tabela filho, tenho que conter um registro já gerado na tabela pai.

No minha UNIT: Tenho 2 DBLookupComboBox e 3 dbedit , vamos dividir, onde irá ficar 2 lados, do 1° lado temos DBLookupComboBox1 e dbedit1 onde o usuário irá informar se na venda contém um valor de entrada (no caso se houver mais de uma forma de pagamento), e no 2° lado temos DBLookupComboBox2, dbedit2 e dbedit3(Onde será informado a quantidade de parcelas, se o pagamento for do tipo prazo), o 2° lado será informado o pagamento total, o dbedit2 receberá o valor total da venda menos o valor do dbedit1 se houver entrada.

O que estou necessitando? Então, assim que for pressionado o enter no dbedit3, confirmando o numero das parcelas, quero que minhã aplicação crie as parcelar referente a venda e minha tabela (VENDA_PAGAMENTO) receba as informações das parcelas que forem geradas

Ex: Uma venda em um total de R$400,00.
(Id venda, Valor Total venda, N° parcela, valor parcela, data vencimento).
10 400 10/1 R$100 24/04/2021
10 400 10/2 R$100 24/05/2021
10 400 10/3 R$100 24/06/2021
10 400 10/4 R$100 24/07/2021




Segue meu código:

private
{ Private declarations }
ValorParcela, Diferenca: real;
Vencimento: TDateTime;
iParcela: integer;
public
{ Public declarations }
VlrEnt, VlrTotal: real;
parcela, id_venda: Integer;
end;



Chamada Função:

procedure TFrmFormaPagOrcVenda.DBCbParcelasKeyPress(Sender: TObject;
var Key: Char);
begin
if key = #13 then
begin
id_venda := StrToInt(FDQryFormPagtoVenda.FieldByName('ID_VDA_ORC').AsString);
VlrTotal := StrToFloat(DBEditVlrTotalPagamento.Text);
parcela := StrToInt(DBCbParcelas.Text);
ValorParcela := (VlrTotal / parcela);
Diferenca := VlrTotal - (ValorParcela * parcela);
Vencimento := date;
for iParcela := 1 to parcela do
begin
if iParcela = parcela then
begin
ValorParcela := (ValorParcela - Diferenca);
Vencimento := DateToStr(Date + 30);
FDQuery1.SQL.Clear;
FDQuery1.SQL.Add('insert into VENDA_PAGAMENTO(ID_VDA_ORC, VLR_PGTO_VENDA, VENC_PARC)');
FDQuery1.SQL.Add('values('+ id_venda, ValorParcela , Vencimento + ')');
BtnConfirmarPag.SetFocus;
end;
end;

end;
end;



Mensagem de erro ao executar código :
[dcc32 Error] UnitFormaPag.pas(134): E1019 For loop control variable must be simple local variable
Responder

29/03/2021

Jefferson

Olá! Alguém se disponibiliza a me dar essa informação?
Responder

30/03/2021

Emerson Nascimento

procedure TFrmFormaPagOrcVenda.DBCbParcelasKeyPress(Sender: TObject; var Key: Char);
var
	ValorParcela, Diferenca: real;
	Vencimento: TDateTime;
	iParcela: integer;
begin
	if key = #13 then
	begin
		id_venda := FDQryFormPagtoVenda.FieldByName('ID_VDA_ORC').AsInteger;
		VlrTotal := DBEditVlrTotalPagamento.Field.AsFloat;
		parcela := DBCbParcelas.Field.AsInteger;
		ValorParcela := RoundTo(VlrTotal / parcela, -2);
		Diferenca := VlrTotal - (ValorParcela * parcela);
		Vencimento := date;

		if FDQuery1.Active then
			FDQuery1.Close;

		FDQuery1.SQL.Text := 'insert into VENDA_PAGAMENTO(ID_VDA_ORC, VLR_PGTO_VENDA, VENC_PARC) values(':idvenda, :vlrparc, :dtvenc')';

		for iParcela := 1 to parcela do
		begin
			if iParcela = parcela then
				ValorParcela := (ValorParcela + Diferenca);

			Vencimento := (Vencimento + 30);
			FDQuery1.Params[0].AsInteger := id_venda;
			FDQuery1.Params[1].AsFloat := ValorParcela;
			FDQuery1.Params[2].AsDateTime := Vencimento;
			FDQuery1.ExecSQL;

		end;
		BtnConfirmarPag.SetFocus;

	end;
end;
Responder

30/03/2021

Emerson Nascimento

procedure TFrmFormaPagOrcVenda.DBCbParcelasKeyPress(Sender: TObject; var Key: Char);
var
    ValorParcela, Diferenca: real;
    Vencimento: TDateTime;
    iParcela: integer;
begin
    if key = #13 then
    begin
        id_venda := FDQryFormPagtoVenda.FieldByName('ID_VDA_ORC').AsInteger;
        VlrTotal := DBEditVlrTotalPagamento.Field.AsFloat;
        parcela := DBCbParcelas.Field.AsInteger;
        ValorParcela := RoundTo(VlrTotal / parcela, -2);
        Diferenca := VlrTotal - (ValorParcela * parcela);
        Vencimento := date;
 
        if FDQuery1.Active then
            FDQuery1.Close;
 
        FDQuery1.SQL.Text := 'insert into VENDA_PAGAMENTO(ID_VDA_ORC, VLR_PGTO_VENDA, VENC_PARC) values(:idvenda, :vlrparc, :dtvenc)';
 
        for iParcela := 1 to parcela do
        begin
            if iParcela = parcela then
                ValorParcela := (ValorParcela + Diferenca);
 
            Vencimento := (Vencimento + 30);
            FDQuery1.Params[0].AsInteger := id_venda;
            FDQuery1.Params[1].AsFloat := ValorParcela;
            FDQuery1.Params[2].AsDateTime := Vencimento;
            FDQuery1.ExecSQL;
 
        end;
        BtnConfirmarPag.SetFocus;
 
    end;
end;
Responder

Que tal ter acesso a um e-book gratuito que vai te ajudar muito nesse momento decisivo?

Ver ebook

Recomendado pra quem ainda não iniciou o estudos.

Eu quero
Ver ebook

Recomendado para quem está passando por dificuldades nessa etapa inicial

Eu quero

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar