Interview Questions

Thursday, March 13, 2014

How to create Inventory Journal through code

static void createInventoryJournal(Args _args)///and also it will import the data from the Excel
{
    InventJournalNameId inventJournalNameId = "IMov";///Assign the journal Name
    AxInventJournalTrans axInventJournalTrans;
    InventJournalTable inventJournalTable;
    Dialog dialog;
    DialogField dialogField,dialogdate;
    Filename filename;
    COMVariant cOMVariant;
    SysExcelApplication sysExcelApp;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    SysExcelCell rCell;
    int i,j,k;
    SysOperationProgress simpleProgress;
    Container filterCriteria;
    #avifiles
    ;
    sysExcelApp = SysExcelApplication::construct();///SysExcelApplication
    workbooks = sysExcelApp.workbooks();///Workbooks

    Dialog = new dialog();
    dialogField = dialog.addField(typeId(FileNameOpen),'File Name');
    filterCriteria = ['*.xls','*. xlsx'];//// To filter only Excel files
    filterCriteria = dialog.filenameLookupFilter(filterCriteria);
    dialog.run();
    if(dialog.run())
    fileName = dialogField.value();

    cOMVariant = new COMVariant();
    cOMVariant.bStr(fileName);

    workBook = workBooks.add(cOMVariant);///Workbook
    worksheets = Workbook.worksheets();///WorkSheets
    worksheet = worksheets.itemFromNum(1);///WorkSheet
    Cells = workSheet.cells();///Cells

    i=2;
    rCell = Cells.item(i,1);///rCell

    if(fileName)
    {
        ttsBegin;
        inventJournalTable.JournalNameId = inventJournalNameId;
        inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
        inventJournalTable.insert();
        simpleProgress = SysOperationProgress::newGeneral(#aviUpdate,'Importing Transactions',100);///SysProgressOperation
        while(RCell.Value().bStr() != '')
        {
            j++;
            simpleProgress.incCount();
            simpleprogress.setText(strfmt("Transaction Imported: %1",i));
            sleep(10);
            simpleprogress.kill();
            axInventJournalTrans = new AxInventJournalTrans();
            axInventJournalTrans.parmJournalId(inventJournalTable.JournalId);
            axInventJournalTrans.parmTransDate(systemdateget());
            axInventJournalTrans.parmLineNum(j);
            rCell = Cells.Item(i, 1);
            axInventJournalTrans.parmItemId(RCell.value().bStr());
            rCell = Cells.Item(i, 2);
            axInventJournalTrans.axInventDim().parmInventSiteId(rCell.value().bStr());
            rCell = Cells.Item(i, 3);
            axInventJournalTrans.axInventDim().parmInventLocationId(rCell.value().bStr());
            rCell = Cells.Item(i, 4);
            axInventJournalTrans.parmQty(rCell.value().double());
            rCell = Cells.Item(i, 5);
            axInventJournalTrans.parmCostPrice(rCell.value().double());
            axInventJournalTrans.save();
            i++;
            rCell = Cells.Item(i, 1);
        }
        ttsCommit;
    }
}

No comments:

Post a Comment