Autor Beitrag
landwehr
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

WIN XP, WIN 7, WIN 8
Delphi 6, Delphi 2007, Delphi XE2
BeitragVerfasst: Fr 14.01.11 12:00 
Hallo,

kann ich in einem Trigger roundto einsetzen.

Hier der Trigger.
ausblenden SQL-Anweisung
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
begin
    if (new.Typ <> 'D'then begin
       if ((new.FAKTOR is Nullor (new.FAKTOR = 0)) then
          new.FAKTOR = 1;
       if ((new.MENGE is Nullor (new.MENGE = 0)) then

          new.MENGE = 1;
       New.GESAMTBETRAG = New.MENGE * new.FAKTOR * New.EINZELPREIS;
       if (new.STEUERSATZ is not nullthen
          new.STEUERBETRAG = new.GESAMTBETRAG * new.STEUERSATZ / 100;
       if (new.Steuersatz is not NULLand (New.LKZ = 'CH'THEN
          new.STEUERBETRAG = roundto((new.GESAMTBETRAG * new.STEUERSATZ / 100)*2,-1)/2 ; <- Um diese Zeile handelt es sich
    end
end


Für eine schnelle Antwort vielen Dank

Moderiert von user profile iconMartok: SQL-Tag gesetzt
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 14.01.11 12:10 
Hilft das?:
www.firebirdsql.org/...1-intfunc-round.html

Auch unten den roten Kasten lesen.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
landwehr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

WIN XP, WIN 7, WIN 8
Delphi 6, Delphi 2007, Delphi XE2
BeitragVerfasst: Fr 14.01.11 12:53 
Nein nicht so richtig. Ich muß die MwSt in der Schweiz berechnen. In Delphi geht das so.

roundto((strtofloat(EINGABE))*2,-1)/2;

Walter
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Fr 14.01.11 13:02 
Das heißt, Du musst auf 5 Rappen genau runden, wenn ich mich richtig errinner?

Trick 17: 1. Verdoppeln 2. Runden 3. halbieren:
ausblenden SQL-Anweisung
1:
select round((cast(:wert as numeric(15,2)) * 2), 1) / 2 from rdb$database					

also prinzipiell das selbe, wie in Deinem Codeschnippsel

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
landwehr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

WIN XP, WIN 7, WIN 8
Delphi 6, Delphi 2007, Delphi XE2
BeitragVerfasst: Fr 14.01.11 18:37 
OK

Werde ich am Wochenende mal testen.

Gebe Feedback wenn OK.

Zunächst schon mal Danke.

Gruß Walter
landwehr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

WIN XP, WIN 7, WIN 8
Delphi 6, Delphi 2007, Delphi XE2
BeitragVerfasst: Di 18.01.11 18:07 
Hallo,

habe es hinbekommen,
ausblenden SQL-Anweisung
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
begin
    if (new.Typ <> 'D'then begin
       if ((new.FAKTOR is Nullor (new.FAKTOR = 0)) then
          new.FAKTOR = 1;
       if ((new.MENGE is Nullor (new.MENGE = 0)) then
          new.MENGE = 1;
       New.GESAMTBETRAG = New.MENGE * new.FAKTOR * New.EINZELPREIS;
       if (new.STEUERSATZ is not nullthen
          new.STEUERBETRAG = new.GESAMTBETRAG * new.STEUERSATZ / 100;
       if (new.Lkz = 'CH'then
        begin
         new.STEUERBETRAG = new.GESAMTBETRAG * new.STEUERSATZ / 100;
        new.STEUERBETRAG = round((cast(new.STEUERBETRAG as numeric(15,2)) * 2), 1) / 2;
       end   
    end
end;
Vielen Dank

mfg
Walter

Moderiert von user profile iconNarses: SQL-Tags hinzugefügt
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Di 18.01.11 18:38 
Den (cast(new.STEUERBETRAG as numeric(15,2)) kannst Du Dir an der Stelle sparen. Der war nur meinem Beispiel drin, damit der Parameter als Numeric behandelt wird. Schreib einfach new.STEUERBETRAG

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
Josef-B
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Di 25.01.11 14:43 
Aber bei roundto gibts meines Wissens die Problematik, dass roundto nicht kaufmännisch rundet sondern amerikanisch.

Deshalb mach ich dass immer mit Wert = trunc(wert*100+.5)/100, bei negativen Werten -0.5

Sonst gibts bei der MWST-Berechnung öfter Differenzen von 0,01 Euro

Moderiert von user profile iconNarses: Überflüssige Zeilenumbrüche/Leerzeilen entfernt.