Pages

Banner 468 x 60px

 

Friday, November 17, 2017

Create InventJournalMovement using x++

0 comments
Create InventJournalMovement using x++ :

Invent Movement Journal Creation and Posting
static void MovementJournalImportExcel(Args _args)
{
    InventJournalTrans                  inventJournalTrans;
    InventJournalTableData          _InventJournalTableData;
    InventJournalTransData          _InventJournalTransData;
    InventDim                               inventDim;
    InventJournalTable                   inventJournalTable;
    InventJournalCheckPost          journalCheckPost;
    InventJournalId                       journalId;
    journalTableData                     journalTabledata;
    InventBatch                             inventBatch;
    InventBatch                             localInventBatch;
    NumberSeq                             numberSeq;
    NumberSequenceReference     numberSequenceReference;
    InventSerial                              inventSerial;
    InventSerial                              localinventSerial;
    int                                            j,countno=0,i,k;
    real                                          Scarp;
    FilenameOpen                          filename;

    Sysexcelapplication                  excelapp=sysexcelapplication::construct();
    sysexcelworksheet                   excelworksheet;
    sysexcelrange                          excelrange;
    sysexcelcells                            excelcells;
    // comvariant cellvalue=new comvariant();
    ;

    // Creating Journal Header
    inventJournaltable.initValue();
    inventJournalTable.JournalNameId = 'ERecover';
    numberSeq = new NumberSeq();
    numberSequenceReference = InventParameters::numRefInventJournalId();
    numberseq = NumberSeq::newGetNum(numberSequenceReference);

    inventJournalTable.JournalId = numberseq.num();
    inventJournalTable.Description = InventJournalName::find(     
        inventJournalTable.JournalNameId).Description;
    inventJournalTable.insert();


    excelapp.workbooks().open('C:\\Documents and
        Settings\\asrivastava\\Desktop\\ElectronicData_OnlyWstatus_10032007.xls');
    excelworksheet=excelapp.worksheets().itemFromNum(1);
    excelcells=excelworksheet.cells();

    // Creating Unit Numbers
    for(i=301;i<=5600;i++)
    {
        inventBatch.clear();
        inventBatch.initValue();
        inventBatch.itemId = excelcells.item(i,11).value().bStr();
        inventBatch.inventBatchId = excelcells.item(i,1).value().bStr();
        localinventBatch = InventBatch::find(inventBatch.inventBatchId,
            inventBatch.itemId);

        if(!localinventBatch)
        {
            inventBatch.OakSerialUnit = excelcells.item(i,2).value().bStr();
            inventBatch.insert();
        }
    }

    //Creating Appartment Numbers
    for(k=1;k<=648;k++)
    {
        inventSerial.clear();
        inventSerial.initValue();
        inventSerial.InventSerialId = excelcells.item(k,8).value().bStr();
        inventSerial.ItemId = excelcells.item(k,11).value().bStr();
        localinventSerial = InventSerial::find(inventSerial.InventSerialId,
            inventSerial.ItemId);

        if(!localInventSerial)
        {
            inventSerial.ProdDate = systemDateGet();
            inventSerial.insert();
        }
    }

    // Creating Journal Lines
    for(j=301;j<=5600;j++)
    {
        inventJournalTrans.clear();
        inventJournalTrans.initValue();
        inventJournalTrans.InitFromInventJournalTable(InventJournalTable); // added by adit
        _InventJournalTransData.initFromJournalTable();  // added by adit
        inventJournalTrans.TransDate         = systemDateGet();
        inventJournalTrans.LedgerAccountIdOffset = "99999";
        inventJournalTrans.JournalType      = InventJournalType::Movement;
        inventJournalTrans.JournalId          = inventJournalTable.JournalId;
        numberSeq                                   = new NumberSeq();
        numberSequenceReference           = InventParameters::numRefInventJournalVoucherId();
        numberseq                                    = NumberSeq::newGetNum(numberSequenceReference);
        inventJournalTrans.Voucher           = numberseq.num();
        inventJournalTrans.ItemId               = excelcells.item (j,11).value().bStr();

        // defaulting branch and item name
        inventJournalTrans.CostAmount = InventTable::find(inventJournalTrans.ItemId).inventTableModuleInvent().Price;
        inventJournalTable                      = InventJournalTable::find(inventJournalTrans.JournalId);
        inventDim.InventLocationId         = excelcells.item (j,10).value().bStr();
        inventDim.InventSiteid                = excelcell.item(j,11).value().bstr();
        inventDIm.wMSLocationId           = excelcell.item(j,12).value().bstr();
        inventDim.inventBatchId              = excelcells.item (j,1).value().bStr();
        inventDim.inventSerialId              = excelcells.item (j,8).value().bStr();
        inventJournalTrans.InventDimId =  inventDim::findOrCreate(inventDim).inventDimId;
        inventJournalTrans.Qty               = 1;
        inventJournalTrans.AdjustmentNotes = "Initial Data Load";
        inventJournalTrans.LineNum      = j;
        inventJournalTrans.insert();
    }

    excelapp.workbooks().item(1).saved(true);
    excelapp.workbooks().close();

    // Posting Journal
    journalTableData = JournalTableData::newTable(inventJournalTable);
    journalTableData.updateBlock(JournalBlockLevel::InUse,JournalBlockLevel::None);

    if (!infolog.num(Exception::Error))
    {
        infolog.clear(0);
        journalCheckPost =
        InventjournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post,InventJournalTable);
        journalCheckPost.parmAutoBlock(true);
        journalCheckPost.run();
    }
}

void BIT_GetAccount8Dimesions()
{
    container                           conDimValue;

    RefRecId                            ledgerDimension;

    DimensionAttributeValueCombination  _DimensionAttributeValueCombination;

    InventJournalTrans                  _getJournalID;

    int                                 recordsCount;

    str                                 _mainAccount, CashFlow, Location , Divison, YOPID, Fields, Vehicle, Station, Category;

    container                           con;

    container                           accountCon;

    MainAccount                         mainAcc;

    DimensionStorage                    dimensionStorage;

    DimensionAttributeValueCombination  dimCombination;

    int                                 hierarchyCount, hierarchyIndex, segmentCount, segmentIndex;

    RefRecId                            recordvalue;

    int                                 dimCount;

    DimensionStorageSegment             segment;

    DimensionHierarchyLevel             hierarchyLevel;

    DimensionAttribute                  dimAttribute;

    DimensionServiceProvider            DimensionServiceProvider = new DimensionServiceProvider();

    LedgerAccountContract               LedgerAccountContract = new LedgerAccountContract();

    DimensionAttributeValueContract     ValueContract;

    List                                ListValueContract = new List(Types::Class);

    dimensionAttributeValueCombination  dimensionAttributeValueCombination;

    DimensionStorage                    dimStorage;
   
    // Get Voucher
    NumberSeq                           numberSeq;
   
    NumberSequenceReference             numberSequenceReference;
    ;

    recordsCount    = InventJournalTrans_ds.recordsMarked().lastIndex();  // Total number of marked records.

    _getJournalID  = InventJournalTrans_ds.getFirst(1);

    ttsBegin;

    while (_getJournalID)
    {
                _mainAccount    = _getJournalID.BIT_MainAccountNum;

                CashFlow        = _getJournalID.BIT_CashFlow;   // #1

                Location        = _getJournalID.BIT_Location;   // #2

                Divison         = _getJournalID.BIT_Division;   // #3

                YOPID           = _getJournalID.BIT_YOPid;      // #4

                Fields          = _getJournalID.BIT_Fields;     // #5

                Vehicle         = _getJournalID.BIT_Vehicle;    // #6

                Station         = _getJournalID.BIT_Station;    // #7

                Category        = _getJournalID.BIT_Category;   // #8

                accountCon = [_mainAccount, _mainAccount];

                mainAcc = MainAccount::findByMainAccountId(_mainAccount);

                if(!mainAcc)
                {
                    error ("COA does not exist in this company");
                }
                else

                recordvalue = DimensionHierarchy::getAccountStructure(mainAcc.RecId);


                            //If the ledgerDimension already created then we can find it in below table

                            select  recid from dimCombination where  dimCombination.MainAccount == mainAcc.RecId

                            && dimCombination.AccountStructure == recordvalue;


                            if (!dimCombination)
                            {

                                accountCon = [_mainAccount, _mainAccount, 0];


                                if (CashFlow)               // #1
                                {

                                accountCon += ["CashFlow", CashFlow];

                                dimCount++;

                                }

                                if (Location)               // #2
                                {

                                accountCon += ["Location", Location];

                                dimCount++;

                                }

                                if (Divison)                // #3
                                {

                                accountCon += ["Divison", Divison];

                                dimCount++;

                                }


                                if (YOPID)                  // #4
                                {

                                accountCon += ["YOPID", YOPID];

                                dimCount++;

                                }

                                }

                                if (Vehicle)                // #5
                                {

                                accountCon += ["Vehicle", Vehicle];

                                dimCount++;

                                }

                                if (Fields)                 // #6
                                {

                                accountCon += ["Fields", Fields];

                                dimCount++;

                                if (Station)                // #7
                                {

                                accountCon += ["Station", Station];

                                dimCount++;

                                }

                                if (Category)               // #8
                                {

                                accountCon += ["Category", Category];

                                dimCount++;

                                }

                                accountCon = conPoke(accountCon, 9 , dimCount);
                        }

//below code lines create ledgerdimension as per chart of account setup

dimensionStorage = DimensionStorage::findById(dimCombination.RecId);

if (dimensionStorage == null)
{

                warning("This is a new COA + new Dimension");

                if (CashFlow)       // #1
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('CashFlow') ;
                    ValueContract.parmValue(CashFlow);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Location)       // #2
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Location') ;
                    ValueContract.parmValue(Location);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Divison)        // #3
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Divison') ;
                    ValueContract.parmValue(Divison);
                    ListValueContract.addEnd(ValueContract);
                }

               if (YOPID)           // #4
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('YOPID') ;
                    ValueContract.parmValue(YOPID);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Vehicle)        // #5
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Vehicle') ;
                    ValueContract.parmValue(Vehicle);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Fields)         // #6
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Fields') ;
                    ValueContract.parmValue(Fields);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Station)        // #7
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Station') ;
                    ValueContract.parmValue(Station);
                    ListValueContract.addEnd(ValueContract);
                }

                if (Category)       // #8
                {
                    ValueContract = new DimensionAttributeValueContract();
                    ValueContract.parmName('Category') ;
                    ValueContract.parmValue(Category);
                    ListValueContract.addEnd(ValueContract);
                }

                LedgerAccountContract.parmMainAccount(_mainAccount);

                LedgerAccountContract.parmValues(ListValueContract);

                dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

                dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());

              

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
                {
                   _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
                }

                if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
                {
                    _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
                }

                _getJournalID.Qty               = abs(_getJournalID.Qty) * -1;
   
                _getJournalID.LedgerDimension   = dimensionAttributeValueCombination.RecId;

                _getJournalID.InventTransId     = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
   
                numberSeq = new NumberSeq();
               
                numberSequenceReference         = InventParameters::numRefInventJournalVoucherId();
               
                numberseq = NumberSeq::newGetNum(numberSequenceReference);

                _getJournalID.Voucher           = numberseq.num();

                info(strFmt("Account %1 has been inserted - JournalID %2", dimensionAttributeValueCombination.DisplayValue , _getJournalID.JournalID));

                _getJournalID.update();

                _getJournalID = InventJournalTrans_ds.getNext();
  }

  else

  {
                hierarchyCount = dimensionStorage.hierarchyCount();

                for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
                {
                    segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);

                    accountCon += [0];

                    //Loop through segments and display required values

                    for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)

                    {
                        segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);

                        hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(recordvalue, segmentIndex);

                        dimAttribute = DimensionAttribute::find(hierarchyLevel.DimensionAttribute);

                        switch (dimAttribute.Name)
                           {

                                 case "CashFlow" :      // #1
                                 if(CashFlow)
                                 {

                                    accountCon += ["CashFlow", CashFlow];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                 }
                                 break;

                                 case "Location":       // #2
                                 if(Location)
                                 {

                                    accountCon += ["Location", Location];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }
                                  break;

                                  case "Divison":       // #3
                                  if(Divison)
                                  {

                                    accountCon += ["Divison", Divison];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }
                                  break;

                                  case "YOPID":         // #4
                                  if(YOPID)
                                  {

                                     accountCon += ["YOPID", YOPID];

                                     accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }

                                  break;

                                  case "Vehicle":       // #5
                                  if(Vehicle)
                                  {

                                    accountCon += ["Vehicle", Vehicle];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }
                                  break;

                                  case "Fields":        // #6
                                  if(Fields)
                                  {

                                    accountCon += ["Fields", Fields];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);
                                  }
                                  break;


                                  case "Station":       // #7
                                  if(Station)
                                  {

                                    accountCon += ["Station", Station];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }
                                  break;

                                  case "Category":      // #8
                                  if(Category)
                                  {

                                    accountCon += ["Category", Category];

                                    accountCon = conPoke(accountCon, 3, conPeek(accountCon, 3) + 1);

                                  }
                                  break;


                                  }
                           }
                    }

                    ledgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);

                    select _DimensionAttributeValueCombination where _DimensionAttributeValueCombination.RecId == ledgerDimension;                

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet1 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret1;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet2 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret2;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet3 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret3;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet4 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret4;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet5 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret5;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet6 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret6;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet7 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret7;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet8 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret8;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet9 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret9;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet10 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret10;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet11 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret11;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet12 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret12;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet13 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret13;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet14 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret14;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet15 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret15;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet16 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret16;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet17 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret17;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet18 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret18;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet19 && _getJournalID.LedgerDimension == 0)
                    {
                       _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret19;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet20 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret20;
                    }

                    if(_getJournalID.ItemId == InventParameters::find().BIT_Item_FFB_Karet21 && _getJournalID.LedgerDimension == 0)
                    {
                        _getJournalID.InventDimId = InventParameters::find().BIT_InventdimidFFBKaret21;
                    }
     
                    _getJournalID.LedgerDimension = _DimensionAttributeValueCombination.RecId;

                    _getJournalID.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
     
                    numberSeq = new NumberSeq();
               
                    numberSequenceReference         = InventParameters::numRefInventJournalVoucherId();
               
                    numberseq = NumberSeq::newGetNum(numberSequenceReference);

                    _getJournalID.Voucher           = numberseq.num();

                    _getJournalID.Qty           = abs(_getJournalID.Qty) * -1;

                    info(strFmt("Account %1 has been inserted - JournalID %2", _getJournalID.LedgerDimension, _getJournalID.JournalId));

                    _getJournalID.update();

                    _getJournalID = InventJournalTrans_ds.getNext();
                }

    }
     
     ttsCommit;

    InventJournalTrans_ds.executeQuery();

}













static void CreateTransferJournal(Args _args)
{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventJournalCheckPost inventJournalCheckPost;
NumberSeq num;
boolean _throwserror=true;
boolean _showinforesult=true;
InventDim frominventDim,ToinventDim;
;
ttsbegin; 

inventJournalTable.clear();
num = new NumberSeq();
num = NumberSeq::newGetNum
(InventParameters::numRefTransferId());
inventJournalTable.initFromInventJournalName(InventJournalName::find
(InventParameters::find().TransferJournalNameId));
inventJournalTable.Description = “Inventory Transfer Journal”;
inventJournalTable.SystemBlocked = true;
inventJournalTable.insert(); 

inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.ItemId = “xxxxxx”;
frominventDim.InventLocationId=”xx”;
frominventDim.inventSiteId =”xx”;
ToinventDim.InventLocationId = “xxxx”;
ToinventDim.InventSiteId = “xx”;
ToinventDim = InventDim::findOrCreate(ToinventDim); 

frominventDim = InventDim::findOrCreate(frominventDim);
inventJournalTrans.InventDimId = frominventDim.inventDimId;
inventJournalTrans.initFromInventTable(InventTable::find(“1101″));
inventJournalTrans.Qty = 10;
inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
inventJournalTrans.TransDate = SystemDateget();
inventJournalTrans.insert();
 
inventJournalCheckPost =
InventJournalCheckPost::newJournalCheckPost
(JournalCheckpostType::Post,inventJournalTable);
inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
inventJournalCheckPost.parmShowInfoResult(_showinforesult);
inventJournalCheckPost.run(); 

inventJournalTable.SystemBlocked = false;
inventJournalTable.update(); 

ttscommit;
}
static void createMovementJournalAx(Args _args)
{
AxInventJournalTable AxinventJournalTable = new AxinventJournalTable();
AxInventJournalTrans AxinventJournalTrans = new AxinventJournalTrans();
InventJournalNameId inventJournalName;
AxInventDim axinventDim = new axinventDim();
JournalCheckPost journalCheckPost;
//Below code creates journal header
//inventJournalTable.clear();
inventJournalName = InventJournalName::standardJournalName(InventJournalType::Movement);
AxinventJournalTable.parmJournalNameId(inventJournalName);
AxinventJournalTable.parmLedgerDimension(InventJournalName::find(inventJournalName).LedgerDimension);
AxinventJournalTable.save();
//Below code creates journal lines
//inventJournalTrans.clear();
// AXinventJournalTrans.inventJournalTableRecord(AxinventJournalTable.inventJournalTable());
AXinventJournalTrans.parmJournalId(AXinventJournalTable.parmJournalId());
AXinventJournalTrans.parmTransDate(systemDateGet());
AXinventJournalTrans.parmLedgerDimension(AxinventJournalTable.parmLedgerDimension());
//inventJournalTrans.ItemId = “S0010″;
// AXinventJournalTrans.inventTableRecord(InventTable::find(“S0010″));
AXinventJournalTrans.parmItemId(‘TestProductModelCP’);
AxinventJournalTrans.parmQty(10);
//AxinventJournalTrans.parmCostPrice(10);
// AxinventJournalTrans
axinventDim.parmInventSiteId(‘1′);
//inventDim.InventColorId = “Black”;
axinventDim.parmInventLocationId(’11’);
// inventDim.wMSLocationId = ‘BULK-001′;
AxinventJournalTrans.parmInventDimId(inventDim::findOrCreate(axinventDim.inventDim()).inventDimId);
AxinventJournalTrans.save();
axinventDim.save();
//The below code posts the journal
journalCheckPost = InventJournalCheckPost::newPostJournal(AxinventJournalTable.inventJournalTable());
journalCheckPost.run();
}



// Cara dapatkan Default dimension
public static RefRecId getDefaultDimension (str CashFlow, str Location, str Divison, str YOPID, str Fields,
                                                 str Vehicle, str Station, str Category)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
    InventJournalTrans      _inventjournaltrans;
    InventDim               _inventdim;
    InventTable             _inventtable;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully

    container                conAttr;
    container                conValue;

    str                      dimValue;

    conAttr = ["CashFlow", "Location", "Divison", "YOPID", "Fields", "Vehicle", "Station", "Category"];

    conValue = [CashFlow, Location, Divison, YOPID, Fields, Vehicle, Station, Category];

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue=dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();

    return result;
}






================= atau ================
// Call the static method to post the journal
if(InventJournalCheckPost::newPostJournal(journalTable).validate())

if(box::yesNo("Do you want to Post Now?",DialogButton::No)==DialogButton::Yes)
{
InventJournalCheckPost::newPostJournal(journalTable).run();
}
else
{
box::info("Not Posted");
}
info("done");






======================Get Default Dimension ===================================

public static refRecId Addit_getDefaultDimension(str CashFlow = '', str Location = '', str Divison = '', str YOPID = '', str Fields = '',
                                                 str Vehicle = '', str Station = '', str Category = '')
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
    InventJournalTrans      _inventjournaltrans;
    InventDim               _inventdim;
    InventTable             _inventtable;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully

    container                conAttr;
    container                conValue;
 
    str                      dimValue;
   
    //conAttr=["Site","ItemGroup"];
    conAttr = ["CashFlow", "Location", "Divison", "YOPID", "Fields", "Vehicle", "Station", "Category"];
   
    //conValue=[_site,_itemgroupid];
    conValue = ['', 'M8', '','','','','',''];
   
    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue=dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();
    info(strFmt("%1", result));

    return result;
}


0 comments:

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

  SOLUTION delete in table DimensionAttributeLevelValue base on Bank Account  :  and Delete the Bank Account FINISH