Este codigo te entrega codigos intercalados debido al
IF (Cod_Tpo_Ncf='0')
Dependiendo de esta condicion obtendra un MAX(Numero) Diferente...
Me tome la libertad reescribir el codigo...y eliminar algunas lineas que estan demas.
Código Delphi
[-]
procedure Tfrmprincipal.genera_numero_fact;
begin
with frmdata.st do
begin
DecodeDate(Date,Periodo,Mes,Dia);
st_ctr:=false;
If cod_tpo_ncf='0' Then
Begin
Sql.Text:='Select Max(Numero) As numero From tb_cd_fact_t Where cod_tipo_ncf='+QuotedStr(Cod_Tpo_Ncf);
st_ctr:=True;
End
Else
Sql.Text:='Select Max(Numero) As Numero From tb_cd_fact_t Where cod_tipo_ncf >0';
Open;
Cont:=1;
If (Not FieldByName('numero').IsNull) And (Periodo=FieldByName('Periodo').Value) Then
Cont:=FieldByName('Numero').Value+1;
Numero:=IntToStr(Cont);
Numero:=StringOfChar('0',7-Length(Numero))+Numero;
frmfactura.Num_Fact_Edit.Text:=Numero;
end;
end;
Espero haber ayudado...Un abrazo