Wednesday, 18 October 2017

Determining total amount for invoices applied to a payment in CAL code


Hello in one of my projects, i realized i needed to compute the totals for invoices that have been applied to a payment made by a customer.
I figured out i could do this by using flowfields.
Here is a summary

  • From the detailed Cust. Ledg. Entry table (379)
  • Identify the customer using there customer No.
  • The Document Type must be Payment
  • Entry Type must be Application
  • Identify the Document No for that specific payment

Sum credit Amount(LCY) field in this table using the criteria above.

Note

For me i wanted the totals field added to another table in my case Patient Payment Table.
Here is the formula i used to sum up my flowfield
Sum("Detailed Cust. Ledg. Entry"."Credit Amount (LCY)" WHERE (Customer No.=FIELD(Patient ID),Document Type=CONST(Payment),Document No.=FIELD(Receipt No.),Entry Type=CONST(Application),Initial Document Type=CONST(Invoice)))


GOOD LUCK!!

Monday, 28 August 2017

Dynamics NAV tax reporting





Value-Added Tax (VAT) is a tax on consumption that is paid by the end consumer. VAT is calculated on sales and purchases and reported to the tax authorities periodically.
In Dynamics NAV, VAT is calculated on sales and purchases invoices and credit memos. When the documents are posted, new VAT entries are created that will be used later on to report VAT to the authorities.
  • ·         All that is needed is to setup Dynamics NAV correctly
  • ·         Capture sales and purchases
  • ·         Run the VAT report
  • Dynamics updates the VAT record in real time every time a new entry is posted.  
I




Dynamics NAV Updating/ Checking WorkDate in code



Hello, there are times when you wish to perform an operation based on the work date set in NAV. For example, a colleague one time was modifying a POS system. He wanted to set the work date to the next day whenever it clocked 17 hrs in the evening. It was a requirement from a client. Definitely there were many proposals like
IF TIME > 17T THEN
  WORKDATE := TODAY +1 ;
// This only works if  the Days date is appropriately set for client PC
// It will modify the work date to today's date plus 1 day which sets it to tomorrow

In such a scenario, the risk is that you will only have correct results when the Operating System time on the client is correctly setup.
Details of the work date function are available on MSD Community. Click here





Thursday, 10 August 2017

Dynamics NAV checking applied customer ledger entries in code




Hello, i was sorting out a problem at one of our clients, it became evident that i needed to check out for applied entries for a customer ledger entry. First let me put the problem in perspective then i show you how i walked around it.
A customization had been done to help users post refunds on payments made. The system creates a refund journal entry and applies it to the payment and then posts the entry. The problem is that a refund can be posted multiple times which results in jumbled customer balances. We need to stop this by making sure that a full refund is posted strictly once against a particular payment.
Here is how i go about it.


  • First pick out a specific payment using its document number and customer Number in customer ledger entry table (21)
  • Capture the entry Number of the entry above. The entry Number in customer ledger entry table is a foreign key in detailed customer ledger entry table (379). The field is renamed as "Customer Entry No"
  • Search for a record of type "Refund", Entry type "Application" whose Customer Ledger Entry Number corresponds to the one captured above.
  • If such a record exists, then its conclusive to say a refund is already posted


Here is a sample code

CustLdgEntry.RESET; // CustLdgEntry is record variable of table 21
CustLdgEntry.SETRANGE(CustLdgEntry."Document Type",CustLdgEntry."Document Type"::Payment);
CustLdgEntry.SETRANGE(CustLdgEntry.Open,FALSE);
CustLdgEntry.SETRANGE(CustLdgEntry."Sell-to Customer No.",CustomerNo);
CustLdgEntry.SETRANGE(CustLdgEntry."Document No.",PaymentDocumentNo);
IF CustLdgEntry.FINDFIRST THEN BEGIN
  DetailedLdgEntry.RESET;//DetailedLdgEntry is a record variable of table 379
  DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Cust. Ledger Entry No.",CustLdgEntry."Entry No.");
  DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Entry Type",DetailedLdgEntry."Entry Type"::Application);
  DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Document Type",DetailedLdgEntry."Document Type"::Refund);
  IF DetailedLdgEntry.FINDFIRST THEN
    ERROR(TXT0004);// TXT0004 text variable informing user that a refund has already been posted against the payment

END;

Wednesday, 19 July 2017

Dynamics NAV 2016 Applying and posting entries in code



Hello, i was doing some customization then i realized i had to post an application of a payment against an invoice in code. I felt the urge to share with someone there that may be facing a hurdle doing so. Just follow these easy steps.

  • Search and found the invoice record in the customer Ledger Entry table
  • Once you have find the invoice entry from the customer ledger entry table, Search for the payment entry as well from the customer ledger entry table
  • Edit and update the Invoice ledger Entry you found above
  • Set Applies to ID
  • Post Application
Here is a  sample code to achieve that;


  CustomerLdgEntryInv.RESET;//CustomerLdgEntryInv is a record variable of table 21
  CustomerLdgEntryInv.SETRANGE(CustomerLdgEntryInv."Document Type",      CustomerLdgEntryInv."Document Type"::Invoice);//Find only Invoices
 CustomerLdgEntryInv.SETRANGE(CustomerLdgEntryInv.Open, TRUE);// Find only Open entries    to apply
  IF CustomerLdgEntryInv.FINDFIRST THEN BEGIN
    // Search for Payment entries in customer ledger entries
      CustomerLdgEntry.RESET;//CustomerLdgEntryInv is a record variable of table 21
      CustomerLdgEntry.SETRANGE(CustomerLdgEntry."Document Type",    CustomerLdgEntry."Document Type"::Payment);// Find the payment
      CustomerLdgEntry.SETRANGE(CustomerLdgEntry.Open, TRUE);// Find the payment Ledger Entry
      IF CustomerLdgEntry.FINDFIRST THEN REPEAT//Repeat for all the payment entries
          //set applies to ID
          CustomerLdgEntry.CALCFIELDS(Amount);
      //Update all the invoice entries
          CustomerLdgEntryInv.CALCFIELDS(Amount);
          CustomerLdgEntryInv."Applying Entry" := TRUE;
          CustomerLdgEntryInv."Applies-to ID" := USERID;
          CustomerLdgEntryInv.CALCFIELDS("Remaining Amount");
          CustomerLdgEntryInv.VALIDATE("Amount to Apply", CustomerLdgEntryInv."Remaining Amount");
          CODEUNIT.RUN(CODEUNIT::"Cust. Entry-Edit", CustomerLdgEntryInv);
          COMMIT;// Commit the change
          SetAppliesToID.SetApplId(CustomerLdgEntry,CustomerLdgEntryInv,USERID);// SatAppliesToID is a codeUnit variable of Code Unit 101
          // Post the application
          PostAppn.Apply(CustomerLdgEntryInv,SalesInvoiceHeader."No.",SalesInvoiceHeader."Posting Date"); // PostAppn is a codeUnit variable of CodeUnit 226
      UNTIL CustomerLdgEntry.NEXT = 0;
  END;

I would like to hear your opinion of this blog and article. Please leave a comment
Best regards
      Author

Thursday, 13 July 2017

Dynamics NAV Copy Document using Code




Hello, I was working on a project and i needed to copy a posted sales Invoice into a credit memo and post.
You may be trying to do the same. Let me save you the hurstle. Here's what you need to do.
You need to create a sales credit memo using the INIT function.Remember the INIT function ignores
the primary key. So VALIDATE the primary key for your credit memo
VALIDATE Sell-to Customer No. for your Credit memo
Here is a sample
SalesCreditMemo.INIT;// Initialises the Credit memo(SalesCreditMemo is a Record of table 36)
SalesCreditMemo.VALIDATE(SalesCreditMemo."No.",CrdMemoNo);//CrdMemoNo is a variable holding the Document No for the Sales Credit Memo
SalesCreditMemo.VALIDATE(SalesCreditMemo."Document Type",SalesCreditMemo."Document Type"::"Credit Memo");
SalesCreditMemo.VALIDATE(SalesCreditMemo."Sell-to Customer No.",[Put here your Customer No]);
SalesCreditMemo.INSERT;
Copy the lines from the posted sales Invoice
Here is a sample
//copy the Sales Invoice to the credit memo you have just made.
CopySalesDoc.SetSalesHeader(SalesCreditMemo);//CopySalesDoc is a Variable of Report 292
//CopyDocMgt is a variable of CodeUnite 6620
CopyDocMgt.SetProperties(TRUE,FALSE,FALSE,FALSE,FALSE,SalesSetup."Exact Cost Reversing Mandatory",FALSE);// SalesSetup is a Variable of Record 311
CopyDocMgt.CopySalesDoc(DocumentType::"Posted Invoice", [Put here Posted Sales Invoice Document No.],SalesCreditMemo);
//Post the credit memo
CLEAR(SalesPost);// SalesPost is a variable of CodeUnit 80
SalesPost.RUN(SalesCreditMemo);// This will post your Sales credit memo


************************************************************************************************
I would like to hear your feedback about this article. Please leave a comment.
Thank you
          Author

Monday, 3 July 2017

Dynamics NAV Account Schedules


Hello, you may need a special report from your chart of accounts data but can't get one from the generic reports provided along with Dynamics NAV. The best alternative is not coding your own report but instead creating an account schedule. Account schedules in Dynamics NAV give you the power to define your own reports from Chart of Accounts data without writing any code. In fact you will not need technical knowledge to create one.
Click this for a step by step procedure . Click here for a you tube video about the same