How to use 2 payment methods

dimitrisdimitris Member Posts: 17
Hallo everybody
I have the following problem: I would like to know if it is possible for an invoice to have simultaneously two payment methods (e.g. cash and credit card). Example: A customer has to pay 100 Euros and he wishes to pay 60 Euros cash and another 40 Euros by a credit card. The bottom line is that I have to make some changes propably in codeunit 80 (sales/post) so as to add another line in customer ledger entry table? Does anyone knows where that piece of code is and what other tables do I have to take into consideration? Any good ideas?

I thank you in advance!

Comments

  • ssinglassingla Member Posts: 2,973
    Dear Dimitris,

    I found no problem with having two payment transaction for any invoice. Both Cash and Credit Card payment willbe recd. in two diffrent G/L & Bank account therefore two lines will be created in the customer ledger entry. Both transaction will be applied to single sale invoice.

    Is there something else you wanna inquire


    Best Regards,
    Sandeep Singla
    CA Sandeep Singla
    http://ssdynamics.co.in
  • dimitrisdimitris Member Posts: 17
    Thanks for your quick reply!
    In sales order form when I choose payment method code there is only one selection!
    How can I choose two different payment method codes and how can I define the amount that each payment method will cover?
  • ara3nara3n Member Posts: 9,258
    Hello Dimitris
    I did this a while back. You add a boolean to Payment method called split payment. Make sure Bal. Account No. is blank.
    Now On order menu button you add an option to open a split payment form.

    I used Gen. journal batch and added new fields to link to the sales order.
    This is code for onpush triger
    TESTFIELD("Payment Method Code",'SPLIT');
    TESTFIELD(Status,Status::Released);
    GenJournalLine.FILTERGROUP(0);
    //GenJournalLine.SETRANGE("Journal Template Name",'CASH RECEI');
    GenJournalLine.SETRANGE("Journal Batch Name",'SPLIT');
    GenJournalLine.SETRANGE("Sales Order No","No.");
    GenJournalLine.SETRANGE("Account Type",GenJournalLine."Account Type"::Customer);
    GenJournalLine.SETRANGE("Account No.","Sell-to Customer No.");
    GenJournalLine.FILTERGROUP(2);
    WarehouseSplitPayment.SETTABLEVIEW(GenJournalLine);
    WarehouseSplitPayment.SetRec(Rec);
    WarehouseSplitPayment.RUNMODAL;
    


    This is the split payment form that opens.
    OBJECT Form 50004 Split Cash Receipt Journal
    {
      OBJECT-PROPERTIES
      {
        Date=09/13/06;
        Time=[ 8:42:12 AM];
        Modified=Yes;
        Version List=NAVW14.00;
      }
      PROPERTIES
      {
        Width=14850;
        Height=8250;
        CaptionML=[ENU=Cash Receipt Journal;
                   ENC=Cash Receipt Journal];
        SaveValues=Yes;
        TableBoxID=1;
        SourceTable=Table81;
        DelayedInsert=Yes;
        DataCaptionFields=Journal Batch Name;
        OnOpenForm=VAR
                     JnlSelected@1000 : Boolean;
                   BEGIN
                     "Journal Batch Name" := 'SPLIT';
                     CurrentJnlBatchName := 'SPLIT';
                     xRec."Journal Batch Name" := 'SPLIT';
                     GenJnlManagement.TemplateSelection(FORM::"Cash Receipt Journal",3,FALSE,Rec,JnlSelected);
                     IF NOT JnlSelected THEN
                       ERROR('');
                     GenJnlManagement.OpenJnl(CurrentJnlBatchName,Rec);
    
                     IF SalesHeader.GET(SalesHeader."Document Type",GETFILTER("Sales Order No")) THEN BEGIN
                        SalesHeader.CALCFIELDS("Amount Including VAT");
                        OrderBalance := SalesHeader."Amount Including VAT";
                     END;
                   END;
    
        OnQueryCloseForm=BEGIN
                           IF (OrderBalance-TotalBalance) <> 0 THEN
                             IF NOT CONFIRM('Balance Difference is not Zero. Are you sure you want to close the form?') THEN
                               EXIT(FALSE)
                             ELSE
                               EXIT(TRUE);
                         END;
    
        OnAfterGetRecord=BEGIN
                           ShowShortcutDimCode(ShortcutDimCode);
                         END;
    
        OnAfterGetCurrRecord=BEGIN
                               GenJnlManagement.GetAccounts(Rec,AccName,BalAccName);
                               UpdateBalance;
                             END;
    
        OnBeforePutRecord=BEGIN
    
                            UpdateBalance;
                          END;
    
        OnNewRecord=BEGIN
                      UpdateBalance;
                      "Journal Batch Name" := 'SPLIT';
                      SetUpNewLine(xRec,Balance,BelowxRec);
                      CLEAR(ShortcutDimCode);
                      EVALUATE("Account Type",GETFILTER("Account Type"));
                      VALIDATE("Account No.",GETFILTER("Account No."));
                      VALIDATE("Sales Order No",GETFILTER("Sales Order No"));
                      //SalesHeader.GET(SalesHeader."Document Type"::Order,"Sales Order No");
                      SalesHeader.TESTFIELD("No.");
                      VALIDATE("Posting Date",SalesHeader."Posting Date");
                      VALIDATE("Document Date",SalesHeader."Document Date");
                      VALIDATE("Document Type","Document Type"::Payment);
                      VALIDATE("Document No.",SalesHeader."No.");
                    END;
    
        OnInsertRecord=BEGIN
                         GenJournal2.RESET;
                         GenJournal2.SETRANGE("Journal Template Name",'CASH RECEI');
                         GenJournal2.SETRANGE("Journal Batch Name",'SPLIT');
                         IF GenJournal2.FIND('+') THEN
                         "Line No." := GenJournal2."Line No." + 10000;
                       END;
    
      }
      CONTROLS
      {
        { 1   ;TableBox     ;110  ;220  ;14410;5500 ;HorzGlue=Both;
                                                     VertGlue=Both }
        { 1000000000;TextBox;31327;3410 ;1700 ;440  ;ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="Payment Method Code" }
        { 1000000001;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000000;
                                                     InColumnHeading=Yes }
        { 1000000010;TextBox;3493 ;3300 ;2200 ;440  ;ParentControl=1;
                                                     InColumn=Yes;
                                                     CaptionML=[ENU=" Pay Amount";
                                                                ENC=Credit Amount];
                                                     SourceExpr="Credit Amount";
                                                     OnValidate=BEGIN
                                                                  IF "Payment Method Code" = '' THEN
                                                                    Err('Please select a payment Method');
                                                                END;
                                                                 }
        { 1000000011;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000010;
                                                     InColumnHeading=Yes }
        { 1000000002;TextBox;3889 ;3850 ;1650 ;440  ;Visible=No;
                                                     ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="Bal. Account Type";
                                                     OnValidate=BEGIN
                                                                  IF "Payment Method Code" = '' THEN
                                                                    Err('Please select a payment Method');
                                                                END;
                                                                 }
        { 1000000003;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000002;
                                                     InColumnHeading=Yes }
        { 1000000012;TextBox;6244 ;3630 ;1700 ;440  ;ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="CC Approval Code";
                                                     OnValidate=BEGIN
                                                                  IF "Payment Method Code" = '' THEN
                                                                    Err('Please select a payment Method');
                                                                END;
                                                                 }
        { 1000000013;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000012;
                                                     InColumnHeading=Yes }
        { 1000000004;TextBox;5503 ;3960 ;1700 ;440  ;Visible=No;
                                                     ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="Bal. Account No.";
                                                     OnValidate=BEGIN
                                                                  IF "Payment Method Code" = '' THEN
                                                                    Err('Please select a payment Method');
                                                                END;
                                                                 }
        { 1000000005;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000004;
                                                     InColumnHeading=Yes }
        { 1000000014;TextBox;9472 ;2420 ;1700 ;440  ;ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="Credit Card No." }
        { 1000000015;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000014;
                                                     InColumnHeading=Yes }
        { 1000000016;TextBox;11172;2420 ;1700 ;440  ;ParentControl=1;
                                                     InColumn=Yes;
                                                     SourceExpr="CC No." }
        { 1000000017;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000016;
                                                     InColumnHeading=Yes }
        { 24  ;Frame        ;220  ;5830 ;12540;1430 ;HorzGlue=Both;
                                                     VertGlue=Bottom;
                                                     ShowCaption=No }
        { 27  ;TextBox      ;6160 ;6600 ;2200 ;440  ;Name=TotalBalance;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Editable=No;
                                                     ParentControl=24;
                                                     InFrame=Yes;
                                                     CaptionML=[ENU=Total Balance;
                                                                ENC=Total Balance];
                                                     SourceExpr=TotalBalance;
                                                     AutoFormatType=1 }
        { 28  ;Label        ;6160 ;6050 ;2200 ;440  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     ParentControl=27;
                                                     HorzAlign=Right;
                                                     LeaderDots=No }
        { 1000000006;TextBox;3740 ;6600 ;2200 ;440  ;Name=TotalBalance;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Editable=No;
                                                     ParentControl=24;
                                                     InFrame=Yes;
                                                     CaptionML=[ENU=OrderBalance;
                                                                ENC=Total Balance];
                                                     SourceExpr=OrderBalance;
                                                     AutoFormatType=1 }
        { 1000000007;Label  ;3740 ;6050 ;2200 ;440  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     ParentControl=1000000006;
                                                     HorzAlign=Right;
                                                     LeaderDots=No }
        { 1000000009;TextBox;770  ;6490 ;2200 ;440  ;Name=TotalBalance;
                                                     HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Editable=No;
                                                     ParentControl=24;
                                                     InFrame=Yes;
                                                     CaptionML=[ENU=Difference;
                                                                ENC=Total Balance];
                                                     SourceExpr=OrderBalance-TotalBalance;
                                                     AutoFormatType=1 }
        { 1000000008;Label  ;770  ;5940 ;2200 ;440  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     ParentControl=1000000009;
                                                     HorzAlign=Right;
                                                     LeaderDots=No }
        { 59  ;MenuButton   ;10010;7480 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     Visible=No;
                                                     CaptionML=[ENU=&Line;
                                                                ENC=&Line];
                                                     Menu=MENUITEMS
                                                     {
                                                       { ID=60;
                                                         PushAction=RunObject;
                                                         ShortCutKey=Shift+Ctrl+D;
                                                         CaptionML=[ENU=Dimensions;
                                                                    ENC=Dimensions];
                                                         RunObject=Form 545;
                                                         RunFormLinkType=OnUpdate;
                                                         RunFormLink=Table ID=CONST(81),
                                                                     Journal Template Name=FIELD(Journal Template Name),
                                                                     Journal Batch Name=FIELD(Journal Batch Name),
                                                                     Journal Line No.=FIELD(Line No.) }
                                                     }
                                                      }
      }
      CODE
      {
        VAR
          ChangeExchangeRate@1000 : Form 511;
          GLReconcile@1001 : Form 345;
          GenJnlManagement@1002 : Codeunit 230;
          ReportPrint@1003 : Codeunit 228;
          CurrentJnlBatchName@1004 : Code[10];
          AccName@1005 : Text[30];
          BalAccName@1006 : Text[30];
          Balance@1007 : Decimal;
          TotalBalance@1008 : Decimal;
          ShowBalance@1009 : Boolean;
          ShowTotalBalance@1010 : Boolean;
          ShortcutDimCode@1011 : ARRAY [8] OF Code[20];
          Text100@1102620002 : TextConst 'ENU=Create new transaction?';
          GenJournal2@1000000000 : Record 81;
          OrderBalance@1000000001 : Decimal;
          SalesHeader@1000000002 : Record 36;
    
        LOCAL PROCEDURE UpdateBalance@1();
        BEGIN
          GetTotalBalance;
        END;
    
        PROCEDURE GetTotalBalance@1000000000();
        VAR
          returnValue@1000000000 : Decimal;
          GenJournal3@1000000001 : Record 81;
        BEGIN
          TotalBalance := 0;
          GenJournal3.RESET;
          GenJournal3.SETRANGE("Journal Template Name",'CASH RECEI');
          GenJournal3.SETRANGE("Journal Batch Name",'SPLIT');
          GenJournal3.SETRANGE("Sales Order No","Sales Order No");
          IF GenJournal3.FIND('-') THEN REPEAT
            TotalBalance += GenJournal3."Credit Amount";
          UNTIL GenJournal3.NEXT = 0;
        END;
    
        PROCEDURE Err@1000000001(ltext@1000000000 : Text[1000]);
        BEGIN
            ERROR(ltext);
        END;
    
        PROCEDURE SetRec@1000000002(LSalesHeader@1000000000 : Record 36);
        BEGIN
          SalesHeader := LSalesHeader;
        END;
    
        BEGIN
        END.
      }
    }
    
    
    
    

    In codeunit 80 I added the following code.
        // Balancing account
        IF "Bal. Account No." <> '' THEN BEGIN
          //LS4.0 START
          IF ShowDialog() THEN
            Window.UPDATE(5,1);
          //LS4.0 STOP
          CustLedgEntry.FIND('+');
          GenJnlLine.INIT;
          GenJnlLine."Posting Date" := "Posting Date";
          GenJnlLine."Document Date" := "Document Date";
          GenJnlLine.Description := "Posting Description";
          GenJnlLine."Shortcut Dimension 1 Code" := "Shortcut Dimension 1 Code";
          GenJnlLine."Shortcut Dimension 2 Code" := "Shortcut Dimension 2 Code";
          GenJnlLine."Reason Code" := "Reason Code";
          GenJnlLine."Account Type" := GenJnlLine."Account Type"::Customer;
          GenJnlLine."Account No." := "Bill-to Customer No.";
          IF "Document Type" = "Document Type"::"Credit Memo" THEN
            GenJnlLine."Document Type" := GenJnlLine."Document Type"::Refund
          ELSE
            GenJnlLine."Document Type" := GenJnlLine."Document Type"::Payment;
          GenJnlLine."Document No." := GenJnlLineDocNo;
          GenJnlLine."External Document No." := GenJnlLineExtDocNo;
          IF "Bal. Account Type" = "Bal. Account Type"::"Bank Account" THEN
            GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"Bank Account";
          GenJnlLine."Bal. Account No." := "Bal. Account No.";
          GenJnlLine."Currency Code" := "Currency Code";
          GenJnlLine.Amount :=
            TotalSalesLine."Amount Including VAT" + CustLedgEntry."Remaining Pmt. Disc. Possible";
          GenJnlLine."Source Currency Code" := "Currency Code";
          GenJnlLine."Source Currency Amount" := GenJnlLine.Amount;
          GenJnlLine.Correction := Correction;
          CustLedgEntry.CALCFIELDS(Amount);
          IF CustLedgEntry.Amount = 0 THEN
            GenJnlLine."Amount (LCY)" := TotalSalesLineLCY."Amount Including VAT"
          ELSE
            GenJnlLine."Amount (LCY)" :=
              TotalSalesLineLCY."Amount Including VAT" +
              ROUND(
                CustLedgEntry."Remaining Pmt. Disc. Possible" /
                CustLedgEntry."Adjusted Currency Factor");
          IF SalesHeader."Currency Code" = '' THEN
            GenJnlLine."Currency Factor" := 1
          ELSE
            GenJnlLine."Currency Factor" :=  SalesHeader."Currency Factor";
          GenJnlLine."Applies-to Doc. Type" := GenJnlLineDocType;
          GenJnlLine."Applies-to Doc. No." := GenJnlLineDocNo;
          GenJnlLine."Source Type" := GenJnlLine."Source Type"::Customer;
          GenJnlLine."Source No." := "Bill-to Customer No.";
          GenJnlLine."Source Code" := SrcCode;
          GenJnlLine."Posting No. Series" := "Posting No. Series";
          GenJnlLine."IC Partner Code" := "Sell-to IC Partner Code";
          GenJnlLine."System-Created Entry" := TRUE;
          GenJnlPostLine.RunWithCheck(GenJnlLine,TempJnlLineDim);
        //S001 Start New Code
        //END;
        END ELSE BEGIN
          T_GenJournalLine.SETRANGE("Journal Template Name",'CASH RECEI');
          T_GenJournalLine.SETRANGE("Journal Batch Name",'SPLIT');
          T_GenJournalLine.SETRANGE("Sales Order No","No.");
          T_GenJournalLine.SETRANGE("Account Type",T_GenJournalLine."Account Type"::Customer);
          T_GenJournalLine.SETRANGE("Account No.","Sell-to Customer No.");
          IF T_GenJournalLine.FIND('-') THEN REPEAT
            IF "Document Type" IN ["Document Type"::"Credit Memo","Document Type"::"Return Order"] THEN
              T_GenJournalLine."Document Type" := T_GenJournalLine."Document Type"::Refund
            ELSE
              T_GenJournalLine."Document Type" := T_GenJournalLine."Document Type"::Payment;
            T_GenJournalLine."Posting Date" := "Posting Date";
            T_GenJournalLine."Document Date" := "Document Date";
            T_GenJournalLine.Description := "Posting Description";
            T_GenJournalLine."Shortcut Dimension 1 Code" := "Shortcut Dimension 1 Code";
            T_GenJournalLine."Shortcut Dimension 2 Code" := "Shortcut Dimension 2 Code";
            T_GenJournalLine."Reason Code" := "Reason Code";
            T_GenJournalLine."External Document No." := GenJnlLineExtDocNo;
            T_GenJournalLine."Document No." := GenJnlLineDocNo;
            T_GenJournalLine."Applies-to Doc. Type" := GenJnlLineDocType;
            T_GenJournalLine."Applies-to Doc. No." := GenJnlLineDocNo;
            T_GenJournalLine."Source Code" := SrcCode;
            IF T_GenJournalLine."Document Type" = T_GenJournalLine."Document Type"::Refund THEN
              T_GenJournalLine.VALIDATE(Amount, - T_GenJournalLine.Amount)
            ELSE
              T_GenJournalLine.VALIDATE(Amount, T_GenJournalLine.Amount);
            T_GenJournalLine."System-Created Entry" := TRUE;
            GenJnlPostLine.RunWithCheck(T_GenJournalLine,TempJnlLineDim);
            T_GenJournalLine.DELETE(TRUE);
          UNTIL T_GenJournalLine.NEXT = 0;
        END;
        //S001 End new Code
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dimitrisdimitris Member Posts: 17
    Thank you very much! I will try it and let you know if it worked for me!
  • ara3nara3n Member Posts: 9,258
    There are some variables and things that you need to define. Otherwise you should be set. Let me know if you have any questions on this.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dimitrisdimitris Member Posts: 17
    Thank you again. Excellent piece of code. It worked fine, after declaring all the necessary variables. Thank you again!
  • ara3nara3n Member Posts: 9,258
    You are welcome. :P I had done this in 30 min, for a quick one time kind of solution, I'm sure it can be cleaned up and fine tuned. I had harcoded some values etc. Which could be moved to setup :oops:
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.