web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

(0) ShareShare
ReportReport
Posted on by 1,883

Dear all,

I'm trying to print CustInvocieJour header and CustInvoiceTrans details. Its printing correct but every time repeating CustInvocieJOur header values along with custinvoicetrans item details. I need CustInvoiceJour as single line print and its related transactions with CustInvoiceTrans. Please check below job and advice.

static void custInvoiceTran(Args _args)
{
    CustInvoiceJour custInvoiceJour;
    CustInvoiceTrans custInvoiceTrans;
 
    
    while select *from custInvoiceTrans join custInvoiceJour  where  custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId 
     && custInvoiceJour.InvoiceId == "SI-0000033659"
    {
     info(strFmt("Invoice date %1, InvoieId %2, SalesId %3, DeliveryName %4, totalDiscountAmount %5, totalSalesAmount %6, netAmount %7, totalAmount %8, totalItemsDiscountAmount %9", 
     custInvoiceJour.InvoiceDate,
     custInvoiceJour.InvoiceId,
     custInvoiceJour.SalesId,
     custInvoiceJour.DeliveryName,
     custInvoiceJour.SumLineDisc,
     custInvoiceJour.SalesBalance,
     custInvoiceJour.SalesBalance - custInvoiceJour.SumLineDisc,
     custInvoiceJour.InvoiceAmount,
     custInvoiceJour.SumLineDisc));
        
     info(strFmt("ItemName %1, ItemId %2, Salesunit %3, SalesQty %4, SalesTotal %5 ", 
     custInvoiceTrans.itemName(), 
     custInvoiceTrans.ItemId,
     custInvoiceTrans.SalesUnit,
     custInvoiceTrans.Qty,
     custInvoiceTrans.Qty * custInvoiceTrans.SalesPrice,
      
     
     ));
        
   
    
    }

  
}

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Faqru,

    A very simple way would be to check if there is a new Invoice Id changes and print the header only when it does accordingly.

    static void custInvoiceTran(Args _args)
    {
        CustInvoiceJour     custInvoiceJour;
        CustInvoiceTrans    custInvoiceTrans;
        InvoiceId           invoiceId;
     
        
        while select * from custInvoiceTrans 
            join custInvoiceJour
                order by InvoiceId
                where  custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId 
        {
            if (invoiceId != custInvoiceJour.InvoiceId)
            {
                info(strFmt("Invoice date %1, InvoieId %2, SalesId %3, DeliveryName %4, totalDiscountAmount %5, totalSalesAmount %6, netAmount %7, totalAmount %8, totalItemsDiscountAmount %9", 
                 custInvoiceJour.InvoiceDate,
                 custInvoiceJour.InvoiceId,
                 custInvoiceJour.SalesId,
                 custInvoiceJour.DeliveryName,
                 custInvoiceJour.SumLineDisc,
                 custInvoiceJour.SalesBalance,
                 custInvoiceJour.SalesBalance - custInvoiceJour.SumLineDisc,
                 custInvoiceJour.InvoiceAmount,
                 custInvoiceJour.SumLineDisc));
            }
            
            info(strFmt("ItemName %1, ItemId %2, Salesunit %3, SalesQty %4, SalesTotal %5 ", 
             custInvoiceTrans.itemName(), 
             custInvoiceTrans.ItemId,
             custInvoiceTrans.SalesUnit,
             custInvoiceTrans.Qty,
             custInvoiceTrans.Qty * custInvoiceTrans.SalesPrice));
            
            invoiceId = custInvoiceJour.InvoiceId;
        }
    
      
    }

    You can follow this if you are printing all invoices. In your code you have mentioned an invoice Id in the where clause. If you are going to do that, you can use a boolean variable as well. The header will get printed when the variable is not set, and you can set the variable to true after printing the header.

  • Faqruddin Profile Picture
    1,883 on at

    Hello Gunjan,

    Yes printing in correct format. But also I need to print lastweek sales in the same code. I couldn't find any function for that could you please add it a line for lastweek sales.

    Thank you.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Faqru,

    By last week, do you mean for the last 7 days? If yes, then you can include that in the where clause using invoice date.

    CustInvoiceJour     custInvoiceJour;
    CustInvoiceTrans    custInvoiceTrans;
    InvoiceId           invoiceId;
    InvoiceDate         currDate, lastWkDate;
    
    currDate    = systemDateGet();
    lastWkDate  = currDate - 7;
    
    while select * from custInvoiceTrans 
        join custInvoiceJour
            order by InvoiceId
            where  custInvoiceJour.InvoiceId    == custInvoiceTrans.InvoiceId 
                && custInvoiceJour.InvoiceDate  >= lastWkDate
                && custInvoiceJour.InvoiceDate  < currDate
    

  • Faqruddin Profile Picture
    1,883 on at

    No. I mean all sales of last one week.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    By all sales, you mean all the sales orders created in the last week or all invoices from last week?

    Also, considering today's date, what date range will you consider for last week?

  • Faqruddin Profile Picture
    1,883 on at

    I mean all invoices from last week.  For range I will consider system date.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    In that case you can use the code I provided earlier. That should get you all the invoices for the past 7 days. Have you tried running that to see if you get all the records as expected?

    In case you need a different date range, you can replace the values in the query and it should work.

  • Faqruddin Profile Picture
    1,883 on at

    Great its working. But I have an issue with printing same code in .net console application. I deploy above code in service group and call below client .net Console app  it not bringing me values as expected in header and related lines. Its bring only one invoice id as repeated. Did I miss anything while printing.

    //Service claas 
    [SysEntryPointAttribute(true),AifCollectionTypeAttribute("return" , Types::Class, classStr(EinvoiceLinesParam))]
    public List getSalesInvoices()
    {
    
       CustInvoiceTrans custInvoiceTrans;
       CustInvoiceJour custInvoiceJour;
       InvoiceId           invoiceId;
        EinvoiceLinesParam esalesClassObj;
       List esaleslist = new List(Types::Class);
       TransDate d;
        ;
       d = systemDateget();
           esalesClassObj = new  EinvoiceLinesParam();
      while select * from custInvoiceTrans
            join custInvoiceJour
                order by InvoiceId
                where  custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId
            && custInvoiceTrans.InvoiceDate >= d
          &&   custInvoiceTrans.InvoiceDate <= d
        {
            if (invoiceId != custInvoiceJour.InvoiceId)
            {
    
       
           esalesClassObj.parmInvoiceDate(custInvoiceJour.InvoiceDate);
           esalesClassObj.parmInvoiceId(custInvoiceJour.InvoiceId);
           esalesClassObj.parmSalesId(custInvoiceJour.SalesId);
           esalesClassObj.parmCustName(custInvoiceJour.DeliveryName);
           esalesClassObj.parmtotalAmountWithDisc(custInvoiceJour.SumLineDisc);
           esalesClassObj.parmtotalSalesAmount(custInvoiceJour.SalesBalance);
           esalesClassObj.parmnetAmount(custInvoiceJour.SalesBalance - custInvoiceJour.SumLineDisc);
           esalesClassObj.parmtotalAmount(custInvoiceJour.InvoiceAmount);
           esalesClassObj.parmtotalItemsDiscountAmount(custInvoiceJour.SumLineDisc);
            }
           esalesClassObj.parmItemNameDisplay(custInvoiceTrans.itemName());
           esalesClassObj.parmItemId(custInvoiceTrans.ItemId);
           invoiceId = custInvoiceJour.InvoiceId;
            
            esaleslist.addEnd(esalesClassObj);
    
        }
    
           
    
    
         return esaleslist;
    
    }
    
    .Net claas to print results in console  
    class Program
        {
            static void Main(string[] args)
            {
              
             getEinvoiceSales()
            }
             
            static void getEinvoiceSales()
            {
                ServiceReference3.EinvoicesalesServiceClient serviceCLient = new  EinvoicesalesServiceClient();
                ServiceReference3.CallContext callCont = new ServiceReference3.CallContext();
                callCont.Company = " ";
                serviceCLient.ClientCredentials.Windows.ClientCredential.Domain = " ";
                serviceCLient.ClientCredentials.Windows.ClientCredential.UserName = " ";
                serviceCLient.ClientCredentials.Windows.ClientCredential.Password = " ";
    
                ServiceReference3.EinvoiceLinesParam[]  salesList = serviceCLient.getSalesInvoices(callCont);
              
                foreach (EinvoiceLinesParam _sales in salesList) { 
                Console.WriteLine(_sales.internalID); //Invoiceid
                }
    
                Console.ReadKey();
    
            }

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    This is a different issue than the question you asked originally. Could you please mark the helpful answer(s) as verified, close this thread and ask a new question on the forum related to this issue?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans