DEF VAR i1 AS INT NO-UNDO. DEF VAR nWW AS DEC NO-UNDO INIT 0.00. DEF VAR nProz AS DEC NO-UNDO INIT 100.00. DEF VAR nFakBetr AS DEC NO-UNDO. DEF VAR nTotNebenkosten AS DEC NO-UNDO DECIMALS 2. DEF VAR nRestNebenkosten AS DEC NO-UNDO DECIMALS 2. DEF VAR iFaktNebenkosten AS INT NO-UNDO. DEF VAR htMwstCalc AS HANDLE NO-UNDO. DEF VAR iStdCd AS INT NO-UNDO. DEF VAR nStdAnsatz AS DEC NO-UNDO. DEF VAR nRundbetr AS DEC NO-UNDO DECIMALS 4. DEF VAR iRundcode AS INT NO-UNDO INIT 1. DEF VAR cFrw AS CHAR NO-UNDO. { incl/tmwstcalc.i } DEF BUFFER btMwstCalc FOR tMwstCalc. DEFINE INPUT PARAMETER TABLE FOR tMwstParam. DEFINE OUTPUT PARAMETER TABLE FOR tMwstCalc . DEFINE OUTPUT PARAMETER opcMessage AS CHAR NO-UNDO. htMwstCalc = TEMP-TABLE tMwstCalc:DEFAULT-BUFFER-HANDLE. EMPTY TEMP-TABLE tMwstCalc. FIND FIRST tMwstParam. cFrw = tMwstParam.Frw. DO i1 = 1 TO 11: IF tMwstParam.MwstPfl[i1] = 0 THEN NEXT. FIND LAST MwstAns NO-LOCK WHERE MwstAns.Mwst_Cd = i1 AND MwstAns.Datum <= tMwstParam.Datum NO-ERROR. CREATE tMwstCalc. ASSIGN tMwstCalc.Mwst_Cd = i1 tMwstCalc.Faktor = (IF tMwstParam.MwstPfl[i1] >= 0 THEN 1 ELSE -1) tMwstCalc.Ansatz = MwstAns.Ansatz tMwstCalc.Brutto = tMwstParam.MwstPfl[i1] + tMwstParam.MwstBetr[i1] tMwstCalc.Mwst = tMwstParam.MwstBetr[i1]. IF tMwstParam.lInklusive THEN DO: ASSIGN tMwstCalc.Mwst = tMwstCalc.Brutto * tMwstCalc.Ansatz / (100 + tMwstCalc.Ansatz) tMwstCalc.Netto = tMwstCalc.Brutto - tMwstCalc.Mwst. END. ELSE DO: ASSIGN tMwstCalc.Netto = tMwstCalc.Brutto - tMwstCalc.Mwst. END. ASSIGN tMwstCalc.WW = tMwstCalc.Netto tMwstCalc.AbsBrutto = ABS(tMwstCalc.Brutto) tMwstCalc.AbsNetto = ABS(tMwstCalc.Netto ) tMwstCalc.AbsMwst = ABS(tMwstCalc.Mwst ) . nWW = nWW + ABS(tMwstCalc.WW). END. FIND FIRST tMwstCalc NO-ERROR. DO WHILE NOT AVAILABLE tMwstCalc: /* Nur Nebenkosten ? */ IF tMwstParam.MwstPfl[12] = 0 THEN /* Keine Nebenkosten, Keine Beträge */ DO: opcMessage = 'NORECORDS'. RETURN. END. opcMessage = 'NEBENKOSTENRECHNUNG'. /* Nebenkosten zum höchsten Ansatz wie Normale Artikel */ DO i1 = 1 TO 11: FIND Wust NO-LOCK WHERE Wust.CodeK = tMwstParam.MwstCdKd AND Wust.CodeA = i1 NO-ERROR. IF NOT AVAILABLE Wust THEN NEXT. FIND LAST MwstAns NO-LOCK WHERE MwstAns.Mwst_Cd = Wust.Wucd AND MwstAns.Datum <= tMwstParam.Datum NO-ERROR. IF NOT AVAILABLE MwstAns THEN NEXT. ASSIGN iStdCd = Wust.WuCd nStdAnsatz = MwstAns.Ansatz. LEAVE. END. /* Nur Kosten */ CREATE tMwstCalc. ASSIGN tMwstCalc.Mwst_Cd = iStdCd tMwstCalc.Faktor = (IF tMwstParam.MwstPfl[12] >= 0 THEN 1 ELSE -1) tMwstCalc.Ansatz = nStdAnsatz tMwstCalc.Fakbetr = 0 tMwstCalc.ProzAnt = 100.00 tMwstCalc.VerpAnt = tMwstParam.MwstPfl[12] tMwstCalc.Brutto = tMwstParam.MwstPfl[12] . ASSIGN tMwstCalc.WW = tMwstCalc.Netto tMwstCalc.AbsBrutto = ABS(tMwstCalc.Brutto) tMwstCalc.AbsNetto = ABS(tMwstCalc.Netto ) tMwstCalc.AbsMwst = ABS(tMwstCalc.Mwst ) . ASSIGN nWW = nWW + tMwstCalc.WW . LEAVE. END. DO WHILE tMwstParam.MwstPfl[12] <> 0: /* Nebenkosten zum verteilen */ CREATE tMwstCalc. ASSIGN tMwstCalc.Mwst_Cd = 999 tMwstCalc.Faktor = (IF tMwstParam.MwstPfl[12] >= 0 THEN 1 ELSE -1) tMwstCalc.Ansatz = 0.0 tMwstCalc.Brutto = tMwstParam.MwstPfl[12] tMwstCalc.Netto = tMwstParam.MwstPfl[12] tMwstCalc.Mwst = 0 tMwstCalc.AbsBrutto = ABS(tMwstCalc.Brutto) tMwstCalc.AbsNetto = ABS(tMwstCalc.Netto ) tMwstCalc.AbsMwst = 0 tMwstCalc.ProzAnt = 0. LEAVE. END. OUTPUT TO 'C:\TEMP\tMwstCalc_Faktura.csv'. DO i1 = 1 TO htMwstCalc:NUM-FIELDS: PUT CONTROL htMwstCalc:BUFFER-FIELD(i1):LABEL ';'. END. PUT CONTROL CHR(10). FOR EACH tMwstCalc: EXPORT DELIMITER ';' tMwstCalc. END. OUTPUT CLOSE. DO WHILE TRUE: FIND FIRST tMwstCalc NO-ERROR. IF NOT AVAILABLE tMwstCalc THEN DO: opcMessage = 'NORECORDS'. RETURN. END. FIND FIRST btMwstCalc WHERE btMwstCalc.Mwst_Cd = 999 NO-ERROR. IF NOT AVAILABLE btMwstCalc THEN LEAVE. nRestNebenkosten = btMwstCalc.Brutto. nTotNebenkosten = btMwstCalc.AbsBrutto. iFaktNebenkosten = btMwstCalc.Faktor. FOR EACH tMwstCalc WHERE tMwstCalc.Mwst_Cd < 999 BREAK BY tMwstCalc.Mwst_Cd: IF LAST(tMwstCalc.Mwst_Cd) THEN DO: tMwstCalc.ProzAnt = nProz. tMwstCalc.VerpAnt = nRestNebenkosten. IF tMwstParam.lInklusive THEN DO: tMwstCalc.Brutto = tMwstCalc.Brutto + nRestNebenkosten. tMwstCalc.Netto = tMwstCalc.Brutto * 100 / (100 + tMwstCalc.Ansatz). tMwstCalc.Mwst = tMwstCalc.Brutto - tMwstCalc.Netto. END. ELSE DO: tMwstCalc.Netto = tMwstCalc.Netto + nRestNebenkosten. nRundbetr = tMwstCalc.Netto * tMwstCalc.Ansatz / 100. RUN RUNDEN. tMwstCalc.Mwst = nRundbetr. tMwstCalc.Brutto = tMwstCalc.Netto + tMwstCalc.Mwst. END. nFakBetr = nFakbetr + tMwstCalc.Brutto. LEAVE. END. tMwstCalc.ProzAnt = tMwstCalc.AbsNetto * 100 / nWW. tMwstCalc.VerpAnt = nTotNebenkosten * tMwstCalc.ProzAnt / 100 * iFaktNebenkosten. IF tMwstParam.lInklusive THEN DO: tMwstCalc.Brutto = tMwstCalc.Brutto + tMwstCalc.VerpAnt. tMwstCalc.Netto = tMwstCalc.Brutto * 100 / (100 + tMwstCalc.Ansatz). tMwstCalc.Mwst = tMwstCalc.Brutto - tMwstCalc.Netto. END. ELSE DO: tMwstCalc.Netto = tMwstCalc.Netto + tMwstCalc.VerpAnt. nRundbetr = tMwstCalc.Netto * tMwstCalc.Ansatz / 100. RUN RUNDEN. tMwstCalc.Mwst = nRUndbetr. tMwstCalc.Brutto = tMwstCalc.Netto + tMwstCalc.Mwst. END. nProz = nProz - tMwstCalc.ProzAnt. nRestNebenkosten = nRestNebenkosten - tMwstCalc.VerpAnt. nFakBetr = nFakbetr + tMwstCalc.Brutto. END. LEAVE. END. opcMessage = opcMessage + (IF opcMessage = '' THEN '' ELSE CHR(10)) + SUBSTITUTE('&1', nFakbetr). OUTPUT TO 'C:\TEMP\tMwstCalc_Faktura.csv' APPEND. /* DO i1 = 1 TO htMwstCalc:NUM-FIELDS: */ /* PUT CONTROL htMwstCalc:BUFFER-FIELD(i1):LABEL ';'. */ /* END. */ PUT CONTROL CHR(10). FOR EACH tMwstCalc: EXPORT DELIMITER ';' tMwstCalc. END. OUTPUT CLOSE. PROCEDURE RUNDEN : /*------------------------------------------------------------------------------*/ /* Purpose: */ /* Parameters: */ /* Notes: */ /*------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Preis Runden */ /*---------------------------------------------------------------------------*/ /* Input: Rundbetr */ /* Rundcode 0 = keine Rundung */ /* 1 = 0.05 Rundung */ /* 2 = 0.50 Rundung */ /* 3 = 1.00 Rundung */ /* 4 = 5.00 Rundung */ /* 5 = 10.0 Rundung */ /* Output: Rundbetr */ /* */ /*---------------------------------------------------------------------------*/ DEFINE VARIABLE nBetr AS DECIMAL DECIMALS 4 NO-UNDO. DEFINE VARIABLE VOp AS DECIMAL INIT 0.2 NO-UNDO. /*---------------------------------------------------------------------------*/ nBetr = nRundbetr. IF cFrw <> 'CHF' AND iRundcode = 1 THEN iRundcode = 0. IF iRundcode > 5 THEN iRundcode = 0. IF iRundcode = 1 THEN nBetr = ROUND((nBetr / 100 * VOp), 4) / Vop * 100. IF iRundcode = 2 THEN nBetr = ROUND((nBetr / 100 * VOp), 3) / Vop * 100. IF iRundcode = 3 THEN nBetr = ROUND((nBetr / 100), 2) * 100. IF iRundcode = 4 THEN nBetr = ROUND((nBetr / 100 * VOp), 2) / Vop * 100. IF iRundcode = 5 THEN nBetr = ROUND((nBetr / 100), 1) * 100. nRundbetr = nBetr. END PROCEDURE.