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