Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
15 kB
2
Indexable
Never
local procedure ConsolidateMaksekeskusLines(var GenJournalLineTemplate: Record "Gen. Journal Line")
    var
        GenJournalLine: Record "Gen. Journal Line";
        OptimeraSetup: Record "Optimera Setup";
        OptimeraSetup2: Record "Optimera Setup 2";
        DocNo: Code[20];
        LineNo: Integer;
        MaxLineNo: Integer;
        GenJournalLineToConsolidateTMP: Record "Gen. Journal Line" temporary;
        GenJournalLineToDeleteTMP: Record "Gen. Journal Line" temporary;
        GenJournalLineIncomeTMP: Record "Gen. Journal Line" temporary;
        SalesDocumentNo: Code[20];
        SalesDocumentType: Option Quote,"Order",Invoice,"Credit Memo","Blanket Order","Return Order";
        SalesDocDate: Date;
    begin
        //59955,62086
        OptimeraSetup.GET;
        OptimeraSetup2.GET;

        GenJournalLine.SETRANGE("Journal Template Name", GenJournalLineTemplate."Journal Template Name");
        GenJournalLine.SETRANGE("Journal Batch Name", GenJournalLineTemplate."Journal Batch Name");

        IF GenJournalLine.FINDFIRST THEN
            DocNo := GenJournalLine."Document No.";

        LineNo := 10000;

        // Separate INCOME lines
        IF GenJournalLine.FINDSET THEN
            REPEAT
                IF GenJournalLine."EE Payment Description" = 'INCOME' THEN BEGIN
                    SalesDocumentNo := '';
                    GenJournalLineIncomeTMP.INIT;
                    GenJournalLineIncomeTMP := GenJournalLine;
                    GenJournalLineIncomeTMP."Line No." := LineNo;
                    GenJournalLineIncomeTMP.INSERT;
                    GenJournalLineIncomeTMP.VALIDATE("Document Type", GenJournalLineIncomeTMP."Document Type"::Payment);
                    GenJournalLineIncomeTMP.VALIDATE("Account Type", GenJournalLineIncomeTMP."Account Type"::Customer);
                    GenJournalLineIncomeTMP.VALIDATE("Account No.", FindSalesCustomerByRefNo(GenJournalLine."EE Reference No.", 0, SalesDocumentNo, SalesDocumentType, SalesDocDate));
                    //6488
                    //GenJournalLineIncomeTMP.Description := 'INCOME';
                    GenJournalLineIncomeTMP.Description := GenJournalLine.Description;
                    //
                    GenJournalLineIncomeTMP."EE Payment Description" := 'INCOME';
                    GenJournalLineIncomeTMP."EE Reference No." := GenJournalLine."EE Reference No.";
                    //194-387
                    GenJournalLineIncomeTMP."EE Bank Transaction Reference" := GenJournalLine."EE Bank Transaction Reference";
                    IF SalesDocDate <= GenJournalLineIncomeTMP."Posting Date" THEN
                        //
                        IF (SalesDocumentNo <> '') AND (SalesDocumentType = SalesDocumentType::Invoice) THEN BEGIN

                            GenJournalLineIncomeTMP.VALIDATE("Applies-to Doc. Type", GenJournalLineIncomeTMP."Applies-to Doc. Type"::Invoice);
                            GenJournalLineIncomeTMP.VALIDATE("Applies-to Doc. No.", SalesDocumentNo);
                        END;
                    GenJournalLineIncomeTMP.MODIFY;
                    //MESSAGE('%1 -> %2',GenJournalLine.Description,GenJournalLineIncomeTMP.Description);
                    LineNo += 10000;
                    GenJournalLine.DELETE;
                END;
                //60566,62086 -->
                IF GenJournalLine."EE Payment Description" = 'REFUND' THEN BEGIN
                    SalesDocumentNo := '';
                    GenJournalLineIncomeTMP.INIT;
                    GenJournalLineIncomeTMP := GenJournalLine;
                    GenJournalLineIncomeTMP."Line No." := LineNo;
                    GenJournalLineIncomeTMP.INSERT;
                    GenJournalLineIncomeTMP.VALIDATE("Document Type", GenJournalLineIncomeTMP."Document Type"::Refund);
                    GenJournalLineIncomeTMP.VALIDATE("Account Type", GenJournalLineIncomeTMP."Account Type"::Customer);
                    GenJournalLineIncomeTMP.VALIDATE("Account No.", FindSalesCustomerByRefNo(GenJournalLine."EE Reference No.", 1, SalesDocumentNo, SalesDocumentType, SalesDocDate));
                    //66488
                    //GenJournalLineIncomeTMP.Description := 'REFUND';
                    GenJournalLineIncomeTMP.Description := GenJournalLine.Description;
                    //
                    GenJournalLineIncomeTMP."EE Payment Description" := 'REFUND';
                    GenJournalLineIncomeTMP."EE Reference No." := GenJournalLine."EE Reference No.";
                    //194-387
                    GenJournalLineIncomeTMP."EE Bank Transaction Reference" := GenJournalLine."EE Bank Transaction Reference";

                    IF SalesDocDate <= GenJournalLineIncomeTMP."Posting Date" THEN
                        ////
                        IF SalesDocumentNo <> '' THEN BEGIN
                            GenJournalLineIncomeTMP.VALIDATE("Applies-to Doc. Type", GenJournalLineIncomeTMP."Applies-to Doc. Type"::"Credit Memo");
                            GenJournalLineIncomeTMP.VALIDATE("Applies-to Doc. No.", SalesDocumentNo);
                        END;
                    GenJournalLineIncomeTMP.MODIFY;
                    LineNo += 10000;
                    GenJournalLine.DELETE;
                END;
                //<--
                IF GenJournalLine."EE Payment Description" = 'ACCOUNT_FEE' THEN BEGIN
                    SalesDocumentNo := '';
                    GenJournalLineIncomeTMP.INIT;
                    GenJournalLineIncomeTMP := GenJournalLine;
                    GenJournalLineIncomeTMP."Line No." := LineNo;
                    GenJournalLineIncomeTMP.INSERT;
                    GenJournalLineIncomeTMP.VALIDATE("Document Type", GenJournalLineIncomeTMP."Document Type"::Payment);
                    GenJournalLineIncomeTMP.VALIDATE("Account Type", GenJournalLineIncomeTMP."Account Type"::"G/L Account");
                    GenJournalLineIncomeTMP.VALIDATE("Account No.", OptimeraSetup."CP Service Charge G/L Account");
                    //66488
                    //GenJournalLineIncomeTMP.Description := 'ACCOUNT_FEE';
                    GenJournalLineIncomeTMP.Description := GenJournalLine.Description;
                    //
                    GenJournalLineIncomeTMP."EE Payment Description" := 'ACCOUNT_FEE';
                    GenJournalLineIncomeTMP."EE Reference No." := GenJournalLine."EE Reference No.";
                    //194-387
                    GenJournalLineIncomeTMP."EE Bank Transaction Reference" := GenJournalLine."EE Bank Transaction Reference";
                    //
                    GenJournalLineIncomeTMP.MODIFY;
                    LineNo += 10000;
                    GenJournalLine.DELETE;
                END;
            UNTIL GenJournalLine.NEXT = 0;
        MaxLineNo := LineNo;

        //Consolidate FEE lines
        IF GenJournalLine.FINDSET THEN
            REPEAT
                IF (GenJournalLine."EE Payment Description" = 'TRX_FEE') OR (GenJournalLine."EE Payment Description" = 'TRX_FEE_FIX') THEN BEGIN
                    GenJournalLineIncomeTMP.SETRANGE("EE Reference No.", GenJournalLine."EE Reference No.");
                    //194-387 ei anna midagi aga siisei tule korduva rea viga
                    GenJournalLineIncomeTMP.SETRANGE("EE Bank Transaction Reference", GenJournalLine."EE Bank Transaction Reference");
                    //
                    IF GenJournalLineIncomeTMP.FINDFIRST THEN
                        LineNo := GenJournalLineIncomeTMP."Line No." + 5000
                    ELSE BEGIN
                        LineNo := MaxLineNo + 10000;
                        MaxLineNo := LineNo;
                    END;
                    GenJournalLineToConsolidateTMP.SETRANGE("EE Reference No.", GenJournalLine."EE Reference No.");
                    //194-387
                    GenJournalLineToConsolidateTMP.SETRANGE("EE Bank Transaction Reference", GenJournalLine."EE Bank Transaction Reference");
                    //
                    IF GenJournalLineToConsolidateTMP.FINDFIRST THEN BEGIN
                        GenJournalLineToConsolidateTMP.VALIDATE(Amount, GenJournalLineToConsolidateTMP.Amount + GenJournalLine.Amount);
                        GenJournalLineToConsolidateTMP.MODIFY;
                        GenJournalLine.DELETE;
                    END ELSE BEGIN
                        GenJournalLineToConsolidateTMP.INIT;
                        GenJournalLineToConsolidateTMP := GenJournalLine;
                        GenJournalLineToConsolidateTMP."Line No." := LineNo;
                        GenJournalLineToConsolidateTMP.INSERT;
                        GenJournalLineToConsolidateTMP.VALIDATE("Document Type", GenJournalLineToConsolidateTMP."Document Type"::Payment);
                        GenJournalLineToConsolidateTMP.VALIDATE("Account Type", GenJournalLineToConsolidateTMP."Account Type"::"G/L Account");
                        GenJournalLineToConsolidateTMP.VALIDATE("Account No.", OptimeraSetup."CP Service Charge G/L Account");
                        //66488
                        //GenJournalLineToConsolidateTMP.Description := 'FEE';
                        GenJournalLineIncomeTMP.Description := GenJournalLine.Description;
                        //
                        GenJournalLineToConsolidateTMP."EE Payment Description" := 'FEE';
                        GenJournalLineToConsolidateTMP."EE Reference No." := GenJournalLine."EE Reference No.";
                        //194-387
                        GenJournalLineToConsolidateTMP."EE Bank Transaction Reference" := GenJournalLine."EE Bank Transaction Reference";
                        //
                        GenJournalLineToConsolidateTMP.MODIFY;
                        GenJournalLine.DELETE;
                    END;
                END;
            UNTIL GenJournalLine.NEXT = 0;

        //Consolidate VAT lines
        IF GenJournalLine.FINDSET THEN
            REPEAT
                IF GenJournalLine."EE Payment Description" = 'VAT' THEN BEGIN
                    GenJournalLineIncomeTMP.SETRANGE("EE Reference No.", GenJournalLine."EE Reference No.");
                    //194-387
                    GenJournalLineIncomeTMP.SETRANGE("EE Bank Transaction Reference", GenJournalLine."EE Bank Transaction Reference");
                    //
                    IF GenJournalLineIncomeTMP.FINDFIRST THEN
                        LineNo := GenJournalLineIncomeTMP."Line No." + 7500
                    ELSE BEGIN
                        LineNo := MaxLineNo + 10000;
                        MaxLineNo := LineNo;
                    END;
                    GenJournalLineToConsolidateTMP.SETRANGE("EE Reference No.", GenJournalLine."EE Reference No.");
                    //194-387
                    GenJournalLineToConsolidateTMP.SETRANGE("EE Bank Transaction Reference", GenJournalLine."EE Bank Transaction Reference");
                    //
                    //66488
                    //GenJournalLineToConsolidateTMP.SETRANGE(Description,'VAT');
                    GenJournalLineToConsolidateTMP.SETRANGE("EE Payment Description", 'VAT');
                    //
                    IF GenJournalLineToConsolidateTMP.FINDFIRST THEN BEGIN
                        GenJournalLineToConsolidateTMP.VALIDATE(Amount, GenJournalLineToConsolidateTMP.Amount + GenJournalLine.Amount);
                        GenJournalLineToConsolidateTMP.MODIFY;
                        GenJournalLine.DELETE;
                    END ELSE BEGIN
                        GenJournalLineToConsolidateTMP.INIT;
                        GenJournalLineToConsolidateTMP := GenJournalLine;
                        GenJournalLineToConsolidateTMP."Line No." := LineNo;
                        GenJournalLineToConsolidateTMP.INSERT;
                        GenJournalLineToConsolidateTMP.VALIDATE("Document Type", GenJournalLineToConsolidateTMP."Document Type"::Payment);
                        GenJournalLineToConsolidateTMP.VALIDATE("Account Type", GenJournalLineToConsolidateTMP."Account Type"::"G/L Account");
                        GenJournalLineToConsolidateTMP.VALIDATE("Account No.", OptimeraSetup2."WI Maksekeskus VAT Account No.");
                        //66488
                        //GenJournalLineToConsolidateTMP.Description := 'VAT';
                        GenJournalLineIncomeTMP.Description := GenJournalLine.Description;
                        //
                        GenJournalLineToConsolidateTMP."EE Payment Description" := 'VAT';
                        GenJournalLineToConsolidateTMP."EE Reference No." := GenJournalLine."EE Reference No.";
                        //194-387
                        GenJournalLineToConsolidateTMP."EE Bank Transaction Reference" := GenJournalLine."EE Bank Transaction Reference";
                        //
                        GenJournalLineToConsolidateTMP.MODIFY;
                        GenJournalLine.DELETE;
                    END;
                END;
            UNTIL GenJournalLine.NEXT = 0;

        //Remove all Remaining lines
        IF GenJournalLine.FINDSET THEN
            REPEAT
                LineNo := MaxLineNo + 10000;
                MaxLineNo := LineNo;
                GenJournalLineToConsolidateTMP.INIT;
                GenJournalLineToConsolidateTMP := GenJournalLine;
                GenJournalLineToConsolidateTMP."Line No." := LineNo;
                GenJournalLineToConsolidateTMP.INSERT;
                GenJournalLine.DELETE;
            UNTIL GenJournalLine.NEXT = 0;


        //Restore INCOME and REFUND lines
        GenJournalLineIncomeTMP.RESET;
        IF GenJournalLineIncomeTMP.FINDSET THEN
            REPEAT
                CLEAR(GenJournalLine);
                GenJournalLine := GenJournalLineIncomeTMP;
                GenJournalLine.INSERT;
            UNTIL GenJournalLineIncomeTMP.NEXT = 0;
        //Restore consolidated FEE lines
        GenJournalLineToConsolidateTMP.RESET;
        IF GenJournalLineToConsolidateTMP.FINDSET THEN
            REPEAT
                CLEAR(GenJournalLine);
                GenJournalLine := GenJournalLineToConsolidateTMP;
                GenJournalLine.INSERT;
            UNTIL GenJournalLineToConsolidateTMP.NEXT = 0;

        GenJournalLine.SETRANGE("Journal Template Name", GenJournalLineTemplate."Journal Template Name");
        GenJournalLine.SETRANGE("Journal Batch Name", GenJournalLineTemplate."Journal Batch Name");

        IF GenJournalLine.FINDSET THEN
            REPEAT
                GenJournalLine.VALIDATE("Document No.", DocNo);
                GenJournalLine.MODIFY;
                DocNo := INCSTR(DocNo);
            UNTIL GenJournalLine.NEXT = 0
    end;
Leave a Comment