Tuesday 29 May 2018

Item Variants Exporting Using X++

                               Item Variants Exporting 

public void ProductVarientsExport(ItemId    _itemid)
{
    EcoResProduct                           ecoResProduct;
    EcoResProductMaster                ecoResProductMaster;
    InventDimCombination              inventDimCombination;
    EcoResProductTranslation          ecoResProductTranslation;
    EcoResDistinctProductVariant    ecoResDistinctProductVariant;
    InventDim                                    inventDim;
    InventTable                                  inventTable;

    SysExcelApplication                    excel;
    SysExcelWorkbooks                    workbooks;
    SysExcelWorkbook                      workbook;
    SysExcelWorksheets                    worksheets;
    SysExcelWorksheet                      worksheet;
    SysExcelFont                               font;
    SysExcelStyles                            styles;
    SysExcelStyle                              style;
    SysExcelCells                              cells;
    SysExcelCell                                cell;
    int                                                 row,i;
    container                                      con;
    ItemId                                          items;

    excel       = SysExcelApplication::construct();
    workbooks   = excel.workbooks();
    workbook    = workbooks.add();
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1);
    //add bold and color
    //worksheet.rows().item(1).style('Header');
    styles      = workbook.styles();
    style       = styles.add("Header");
    font        = style.font();
    font.bold(true);
    font.color(255);

    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');
    cells.range('C:C').numberFormat('@');

    cell = cells.item(row+1, 1);
    cell.value("Item Number");
    cell = cells.item(row+1, 2);
    cell.value("Item Name");
    cell = cells.item(row+1, 3);
    cell.value("item ConfigurationId");
    cell = cells.item(row+1, 4);
    cell.value("item ColorId");
    cell = cells.item(row+1, 5);
    cell.value("item SizeId");
    cell = cells.item(row+1, 6);
    cell.value("item StyleId");
    cell = cells.item(row+1, 7);
    cell.value("item BatchId");
    cell = cells.item(row+1, 8);
    cell.value("item SiteId");
    cell = cells.item(row+1, 8);
    cell.value("item WareHouse");


    con = str2con(_itemid);
    for(i=1;i<=conLen(con);i++)
    {
        items = conPeek(con,i);
            while select ecoResProductMaster
                        where ecoResProductMaster.DisplayProductNumber ==items //"C0003"
                            join ecoResDistinctProductVariant
                                where ecoResDistinctProductVariant.ProductMaster == ecoResProductMaster.RecId
                                    join inventDimCombination
                                        where inventDimCombination.DistinctProductVariant == ecoResDistinctProductVariant.RecId
                                            join inventDim
                                                where inventDim.inventDimId == inventDimCombination.InventDimId
                                                    join  ecoResProductTranslation
                                                        where  ecoResProductTranslation.Product== ecoResProductMaster.RecId
            {
                row++;
                cell = cells.item(row+1, 1);
                cell.value(inventDimCombination.ItemId);
                cell = cells.item(row+1, 2);
                cell.value(ecoResProductTranslation.Name);
                cell = cells.item(row+1, 3);
                cell.value(inventDim.configId);
                cell = cells.item(row+1, 4);
                cell.value(inventDim.InventColorId);
                cell = cells.item(row+1, 5);
                cell.value(inventDim.InventSizeId);
                cell = cells.item(row+1, 6);
                cell.value(inventDim.InventStyleId);
                cell = cells.item(row+1, 7);
                cell.value(inventDim.inventBatchId);
                cell = cells.item(row+1, 8);
                cell.value(inventDim.InventSiteId);
                cell = cells.item(row+1, 9);
                cell.value(inventDim.InventLocationId);
            }
    }
    excel.visible(true);
    worksheet.columns().autoFit();
}

No comments:

Post a Comment