Hello guys, we are back once again with a very interesting topic, In retail we can apply discount based on Product Category or based on Product Variant which requires a manual effort. In your business you may meet a requirement regarding discount based on Product specific variant such as Product style like one of our retail customer who deals with fabric demanded us for the same.

Below is the job that automate the discount process by importing discount lines in the system by Product style.

//Start

static void axpCreateDiscountLine(Args _args)
{

int                                          row, totalRowCount;
dialog                                    dialog;
Filename                              filename;
DialogField                          dialogFilename;
SysExcelApplication          xlsApplication;
SysExcelWorkBooks          xlsWorkBookCollection;
SysExcelWorkBook            xlsWorkBook;
SysExcelWorkSheets         xlsWorkSheetCollection;
SysExcelWorkSheet           xlsWorkSheet;
SysExcelRange                    range;
SysExcelCells                       cells;

RetailGroupMemberLine           retailGroupMemberLine;
RetailPeriodicDiscountLine      retailPeriodicDiscountLine;
InventDimCombination             inventDimComb;
InventDim                                     inventDim;
EcoResProductRecId                  product;
RetailDiscountLineOffer            retailDiscLineOffer;
RetailPeriodicDiscount               retailPeriodicDisc;
ItemId                                             itemId;
EcoResItemStyleName               ecoResItemStyle;

SysOperationProgress progress = new SysOperationProgress();
COMVariantType type;
NumberSeq _sequence;
#Excel
#AviFiles
#define.Star(‘*’)
#define.Space(‘ ‘)

progress.setCaption(“Processing…”);
progress.setAnimation(#AviUpdate);

dialog = new dialog();
dialog.caption(“Select a file”);
dialogFilename = dialog.addField(extendedTypeStr(FilenameSave));//add a field where you select your file in a                                                                                                                                             specific path
dialog.filenameLookupFilter([“@SYS28576”, #XLSX, “@SYS28576”, “*.xls”]);
dialog.run();//execute dialog

if(dialog.closedOk())
{
filename = dialogFilename.value();//return path file value

//Initialize Excel instance
xlsApplication = SysExcelApplication::construct();

//Create Excel WorkBook and WorkSheet
xlsWorkBookCollection = xlsApplication.workbooks();

//xlsWorkBook = xlsWorkBookCollection.add();

xlsWorkBookCollection.open(filename);
xlsWorkBook = xlsWorkBookCollection.item(1);
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
cells = xlsWorkSheet.cells();
range = cells.range(#ExcelTotalRange);
row = 1;
try
{
// Finds the row where the first contents is found.
range = range.find(#Star, null, #xlFormulas, #xlWhole, #xlByRows, #xlPrevious);
totalRowCount = range.row();
progress.setTotal(totalRowCount);
}
catch (Exception::Error)
{
error(“@SYS59926”);
totalRowCount = 0;
progress.setTotal(totalRowCount);
}

ttsbegin;
do
{
row++;

retailPeriodicDisc = _args.record();
ecoResItemStyle = xlsWorkSheet.cells().item(row, 1).value().bStr();
itemId = xlsWorkSheet.cells().item(row, 2).value().bStr();

retailDiscLineOffer.OfferId = retailPeriodicDisc.OfferId;

while select inventDimComb
where inventDimComb.ItemId == itemId
join inventDim
where inventDim.inventDimId == inventDimComb.InventDimId
&& inventDim.InventStyleId == ecoResItemStyle
{
product = InventTable::find(inventDimComb.ItemId).Product;
retailDiscLineOffer.discPct = xlsWorkSheet.cells().item(row, 3).value().double();
retailDiscLineOffer.discountMethod = RetailDiscountOfferLineDiscMethodBase::PercentOff;
retailDiscLineOffer.RetailGroupMemberLine =RetailGroupMemberLine::createRetailGroupMember(

0,product,inventDimComb.DistinctProductVariant);
retailDiscLineOffer.UnitOfMeasure =       UnitOfMeasure::findBySymbol(

InventTableModule::find(inventDimComb.ItemId,ModuleInventPurchSales::Sales)

.UnitId).RecId;
retailDiscLineOffer.Name = EcoResProduct::find(product).displayProductName();
retailDiscLineOffer.LineNum = RetailPeriodicDiscountLine::

nextLineNum(retailDiscLineOffer.OfferId);

if(retailDiscLineOffer.validateWrite())
retailDiscLineOffer.insert();
}

type = cells.item(row + 1, 1).value().variantType();
progress.setText(strfmt(“No. of records inserted %1/%2”, row, totalRowCount));
progress.setCount(row, 1);
}while(type != COMVariantType::VT_EMPTY);

info(‘upload completed, please refresh the form’);

ttscommit;

}
}

// End

The above job requires a excel DiscountLineUpload template which contains item and style information to implement discount without any manual intervention.

 

In this way you can automate and apply discount based on specific Product style.

I hope this blog will help you in various identical scenario.

 

Leave a Reply

Recent Comments

    Archives

    Categories