Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

X++ job Print Current and Previous year Sales

(0) ShareShare
ReportReport
Posted on by 1,871

Dear all,

I'm executing following job to print Current and Previous year Sales and its not returning any value. Please check below code and advice.

static void custInvoiceSum(Args _args)
{

int                     currentYear = year(systemDateGet());
int                     previousYear = currentYear - 1; // previous year
int                     nextYear = currentYear   1; // Next year
// I have another way to get previous year and next year. But, this will match the exact date in the previous year and next year.

//date                     prvyear = prevYr(systemDateGet());
//date                     nextyears = nextYr(systemDateGet());

String30                    CurrentYearStart = "01" "/" "01" "/" int2Str(currentYear);
String30                     CurrentYearEnd = "12" "/" "31" "/" int2Str(currentYear);
 String30                     previousYearStart = "01" "/" "01" "/" int2Str(previousYear);
  String30                      previousYearEnd = "12" "/" "31" "/" int2Str(previousYear);

 CustInvoiceJour custInvoiceJourPrvYear,  custInvoiceJourCurrentYear;
 SalesTable salesTable;   

    //Invoiceamount previous year
 select sum(InvoiceAmount) from custInvoiceJourPrvYear where custInvoiceJourPrvYear.InvoiceDate >= str2Date(previousYearStart, 213)
&& custInvoiceJourPrvYear.InvoiceDate <= str2Date(previousYearEnd, 213)
&& custInvoiceJourPrvYear.InvoiceAccount == salesTable.InvoiceAccount
&& custInvoiceJourPrvYear.InvoiceAmount > 0.00;

    select sum(InvoiceAmount) from custInvoiceJourCurrentYear where custInvoiceJourCurrentYear.InvoiceDate >= str2Date(CurrentYearStart, 213)
&& custInvoiceJourCurrentYear.InvoiceDate <= str2Date(CurrentYearEnd, 213)
&& custInvoiceJourCurrentYear.InvoiceAccount == salesTable.InvoiceAccount
&& custInvoiceJourCurrentYear.InvoiceAmount > 0.00;
    
     
     info(strFmt("Previous Year %1 ", custInvoiceJourPrvYear.InvoiceAmount));
    info(strFmt("Current Year %1 ", custInvoiceJourCurrentYear.InvoiceAmount));



}

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: X++ job Print Current and Previous year Sales

    You can use the functions dateStartMnth and endMnth for start date of month and end of current month.

    Date currDate = systemDateGet();
    Date currStartMth, currEndMth;
    
    currStartMth = dateStartMth(currDate);
    currEndMth   = endMth(currDate);

    For previous month you can use prevMnth function using the current date. Then you can use the afore mentioned functions for start and end dates of previous month.

  • Faqruddin Profile Picture
    Faqruddin 1,871 on at
    RE: X++ job Print Current and Previous year Sales

    Hello Gunjan,

    Thank you. Its working. But how can I do following.

    ->Starting of Current month and Ending of Current month

    ->Starting of Previous month and Ending of Previous month

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: X++ job Print Current and Previous year Sales

    Hi Fagru,

    You have declared a table buffer for SalesTable but haven't assigned anything to it.

    In the query you are you have a condition to look for totals corresponding to salesTable.InvoiceAccount. Since this field will always be null, the queries won't return any value. You can try removing this condition from the where clause and check if you get any values.

    Additionally, you can use mkDate function for the date variables instead of using string variables. For an example,

    InvoiceDate currentYearStart = mkDate(1, 1, currentYear);

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,759 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans