Monthwise number sequence


Refreshing the number sequencing for sales order each month so that sales order creation month can be identified based on the number.

Initial setup:

m1

///

/// This batch will update the numbersequence format ‘yr/Month/######’ for salesorder number.
///

class Monthwisenumberseq extends RunBaseBatch
{
}

protected boolean canGoBatchJournal()
{
return true;
}

public void run()
{
NumberSequenceReference numberseqref;
NumberSequenceTable numberSeqTable;
container segments;
str annotatedFormat, format, datestr;
;
ttsBegin;
datestr = date2str(systemDateGet(),
321,
DateDay::Digits2,
DateSeparator::Slash, // separator1
DateMonth::Short,
DateSeparator::Slash, // separator2
DateYear::Digits4,
DateFlags::None);

datestr = subStr(datestr, 1, strLen(datestr)- 2);
segments = [[-1,datestr]];
segments += [[-2,’######’]];

annotatedFormat = NumberSeq::createAnnotatedFormatFromSegments(segments);
format = NumberSeq::createAnnotatedFormatFromSegments(segments, false);

numberseqref = NumberSeqReference::findReference(extendedTypeNum(SalesId));

select firstOnly forupdate numberSeqTable
where numberSeqTable.RecId == numberseqref.NumberSequenceId &&
numberSeqTable.NumberSequenceScope == numberseqref.NumberSequenceScope;

if (numberSeqTable)
{
numberSeqTable.AnnotatedFormat = annotatedFormat;
numberSeqTable.Format = format;
numberSeqTable.NextRec = 1;
numberSeqTable.doUpdate();
}
ttsCommit;
}

public static ClassDescription description()
{
return “Monthwise numbersequence”;
}

public server static void main(Args _args)
{
Monthwisenumberseq monthwisenumberseq = new Monthwisenumberseq();

if (monthwisenumberseq.prompt())
{
monthwisenumberseq.run();
}
}

m2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s