Pages

Banner 468 x 60px

 

Tuesday, November 21, 2017

UPLOAD PO using x++

1 comments
UPLOAD PO using x++ :

static void BIT_Upload_PO_Lines(Args _args)
{
    PurchTable                          purchTable;
    PurchLine                           purchLine;
    PurchId                             purchId;

    InvenTtable                         invenTtable;
    inventDim                           inventDim;

    FileNameFilter                      filter;
    Dialog                              dialog;
    DialogField                         field;
    FilenameOpen                        filenameOpen;

    COMVariant                          COMVariant;
    COMVariantType                      type;
    SysExcelApplication                 app;
    SysExcelWorkbooks                   Workbooks;
    SysExcelWorkbook                    Workbook;
    SysExcelWorksheets                  Worksheets;
    SysExcelWorksheet                   Worksheet1, Worksheet2;
    SysExcelCells                       Cells;
    SysExcelCell                        Cell;
    int                                 row,j;
    #excel
    ;

    filter = ["*.xlsx","*.xls"];

    dialog = new Dialog("Choose Excel");
    field = dialog.addField(extendedTypeStr(filenameOpen), "File Name");
    dialog.run();

    if (dialog.closedOK())
    {
         app = SysExcelApplication::construct();
         Workbooks = app.Workbooks();
         COMVariant = new COMVariant();
         COMVariant.bStr(field.value());
         Workbook = Workbooks.Add(COMVariant);
         Worksheets = Workbook.worksheets();
         Worksheet1 = Worksheets.itemFromNum(1);
         Cells = Worksheet1.Cells();
    }

        /*
        // Purchase Order Header pada sheet 1
        Worksheet1 = Worksheets.itemFromNum(1);
        Cells = Worksheet1.cells();

        row  = 2;
        type = cells.item(row, 1).value().variantType();

    ttsBegin;
    while (Cells.item(row, 2).value().variantType() != COMVariantType::VT_EMPTY)
    {

        purchtable.clear();
        purchTable.initValue(PurchaseType::Purch);
        Purchid                             = cells.item(row, 1).value().bStr();  // Purchase Order
        purchtable.PurchId                  = Purchid;
        purchTable.OrderAccount             = cells.item(row, 2).value().bStr();  // Vendor Account

        purchTable.initFromVendTable(VendTable::find(cells.item(row, 2).value().bStr()));

        if (cells.item(row, 5).value().bStr())                                      // Status
        {
            Purchtable.PurchStatus = purchstatus::Backorder;
        }

        PurchTable.CurrencyCode             = cells.item(row, 6).value().bStr();    // Currency
        PurchTable.ProjId                   = cells.item(row, 7).value().bStr();    // Project
        purchtable.InventSiteId             = Cells.item(row, 8).value().bStr();    // Site
        purchtable.InventLocationId         = Cells.item(row, 9).value().bStr();    // Warehouse
        PurchTable.PostingProfile           = Cells.item(row, 10).value().bStr();   // Posting Profile
        PurchTable.AccountingDate           = Cells.item(row, 11).value().date();   // Accounting Date
        PurchTable.VendGroup                = Cells.item(row, 12).value().bStr();   // Vendor Group
        purchTable.LanguageId               = "en-us";

        if (Cells.item(row, 13).value().bStr())
        {
            purchTable.DocumentState        = VersioningDocumentState::Draft;
        }

        purchTable.InvoiceAccount           = Cells.item(row, 14).value().bStr();   // Invoice Account

        if(cells.item(row, 1).value().bStr() != '')
        {
            row++;
            type = cells.item(row, 1).value().variantType();
            Purchtable.insert();
        }
    }
    ttsCommit;
    */

    // Purchase Order Lines pada sheet 2
    worksheet2 = worksheets.itemFromNum(2);
    cells     = worksheet2.cells();

    row  = 2;
    type = cells.item(row, 1).value().variantType();

 
    while (Cells.item(row, 2).value().variantType() != COMVariantType::VT_EMPTY)
    {
          ttsBegin;
        Purchline.clear();

        purchLine.initValue(purchTable::find(Cells.item(row, 1).value().bStr()).PurchaseType);
        purchLine.initFromPurchTable(purchTable::find(Cells.item(row, 1).value().bStr()));
        purchLine.initFromInventTable(InventTable::find(cells.item(row, 2).value().bStr()));

        PurchLine.PurchId                   = Cells.item(row, 1).value().bStr();//cells.item(row, 1).value().bStr();
        PurchLine.ItemId                    = cells.item(row, 2).value().bStr();        // Item number


        inventDim.configId                  = cells.item(row, 4).value().bStr();
        inventDim.InventColorId             = cells.item(row, 5).value().bStr();
        inventDim.InventStyleId             = Cells.item(row, 6).value().bStr();
        inventDim.InventSizeId              = cells.item(row, 7).value().bStr();
        inventDim.InventSiteId              = cells.item(row, 8).value().bStr();
        inventDim.InventLocationId          = cells.item(row, 9).value().bStr();

        inventDim                           = InventDim::findOrCreate(inventDim);
        PurchLine.InventDimId               = inventDim.inventDimId;

        /*purchLine.setPriceDisc(InventDim::find(purchLine.InventDimId));*/

        PurchLine.PurchQty                  = cells.item(row, 10).value().double();      // Quantity
        PurchLine.PurchUnit                 = cells.item(row, 11).value().bStr();        // Unit
        PurchLine.PurchPrice                = cells.item(row, 12).value().double();      // Unit Price
        PurchLine.LineDisc                  = cells.item(row, 13).value().double();      // Discount
        PurchLine.LinePercent               = cells.item(row, 14).value().double();      // Disc. pct.
        PurchLine.LineAmount                = cells.item(row, 15).value().double();      // Net Amount
        Purchline.itemName();

        purchline.CustPurchaseOrderFormNum  = Cells.item(row, 16).value().bStr();
        purchLine.TaxGroup                  = Cells.item(row, 17).value().bStr();
        purchLine.TaxItemGroup              = Cells.item(row, 18).value().bStr();
        purchLine.VendAccount               = Cells.item(row, 19).value().bStr();
        purchLine.VendGroup                 = Cells.item(row, 20).value().bStr();
        PurchLine.PurchStatus               = PurchStatus::Backorder;
        //purchLine.PurchaseType              = PurchaseType::Purch;
        purchLine.CurrencyCode              = "IDR";
        //purchLine.Blocked                   = NoYes::No;

        //PurchLine.createLine(noyes::No, noyes::No,noyes::No, noyes::No, noyes::No, noyes::No);
        //PurchLine.createLine(true, true, true, true, true, false);

        if(cells.item(row, 1).value().bStr() != "") //&& purchLine.validateWrite())
            {
                row++;
                type = cells.item(row, 1).value().variantType();
                PurchLine.insert();
                ttsCommit;
            }

        info(purchLine.PurchId);
    }
   

    info("Finished");
}

1 comments:

Anonymous said...

I was just searching for this information for some time.
After six hours of continuous Googleing, at last I got
it in your web site. I wonder what's the lack
of Google strategy that don't rank this type of informative websites in top
of the list. Usually the top websites are full of garbage.

A financial dimension value is based on the LAND-00013 record and has been used on a transaction. You cannot delete the LAND-00013 record AX 2012

 A financial dimension value is based on the LAND-00013 record and has been used on a  transaction. You cannot delete the LAND-00013 record ...