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,881

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,
      
     
     ));
        
   
    
    }

  
}

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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?

  • Faqruddin Profile Picture
    1,881 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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();
    
            }

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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,881 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

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

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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,881 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    No. I mean all sales of last one week.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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,881 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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,421 on at
    RE: Print Invoice details using CustInvoiceJour and CustInvoiceTrans job

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans