วันอังคารที่ 11 กันยายน พ.ศ. 2555

ดึงราคาจากPO ก่อน Movement/Transfer จากรายงาน inventTranlist


display real PricePerUnit()
{
  real realRet;
  PurchIdBase ret;
  InventTrans  inventTrans_PONO;

  PurchLine  purchline;
  ;

     while select inventTrans_PONO
     where inventTrans_PONO.TransType == InventTransType::Purch
     && inventTrans_PONO.ItemId    == InventTrans.ItemId
     && inventTrans_PONO.InventTransId <= InventTrans.InventTransId
     {
        ret = inventTrans_PONO.TransRefId;
     }
  if(inventTrans.TransType == InventTransType::Purch)
   {
      ret = "";
   }

 if(ret != "")
{
      select purchline
      where purchline.PurchId == ret
         && purchline.ItemId == InventTrans.ItemId;

     realRet = purchline.PurchPrice;
      }
  else
 {
    realRet = 0;
  }

  return  realRet;
}

วันอาทิตย์ที่ 2 กันยายน พ.ศ. 2555

Create JournalMovement


Boolean CreateJournalMovement()
{

InventJournalTable journalTable;
InventJournalTrans journalTrans;
JournalTableData journalTableData;

InventJournalId journalId;
InventJournalName journalName;

;
ttsbegin;
//journalName = InventJournalName::find([MyJournalName]);
journalName = InventJournalName::find("M-FG");

journalTable.clear();

journalTable.JournalNameId=journalName.JournalNameId;
//rint journalTable.JournalNameId;
//ause;


journalTableData = JournalTableData::newTable(journalTable);
journalTableData.initFromJournalName(journalTableData.JournalStatic().findJournalName(journalTable.journalNameId));

journalTable.JournalId = journalTableData.nextJournalId();
   print journalTable.JournalId;
journalTable.Reservation = ItemReservation::Automatic;
journalTable.insert();


//=== Journal Trans ===//
journalTrans.clear();
journalTrans.JournalId = journalTable.JournalId;
journalTrans.JournalType = journalName.JournalType;
journalTrans.LedgerAccountIdOffset = journalName.LedgerAccountIdOffset;

   print journalTrans.JournalId;
   print journalTrans.JournalType;
   print journalTrans.LedgerAccountIdOffset;
   pause;
 
 //  BBCN0001

//journalTrans.ItemId = [MyItemId];
journalTrans.ItemId = "BBCN0001";

//journalTrans.initFromInventTable(InventTable::find([MyItemId]),False,False);
journalTrans.initFromInventTable(InventTable::find("BBCN0001"),False,False);



//ournalTrans.InventDimId = [MyInventDimId];
journalTrans.InventDimId = "DM-0000001";

journalTrans.TransDate = SystemDateGet();
//journalTrans.Qty = [MyQty];
journalTrans.Qty = 1000;
//journalTrans.PriceUnit = [MyPriceUnit];
journalTrans.PriceUnit = 1000;
//journalTrans.CostPrice = [MyCostPrice];
journalTrans.CostPrice = 999;
journalTrans.CostAmount = journalTrans.calcCostAmount();

print journalTrans.CostAmount;
pause;


journalTrans.insert();
ttscommit;

 info("Create journal movement is done.");

return true;

}

Reference http://oromux.wordpress.com/2008/07/02/ax-create-journal-movement-via-x/
Thanks....

SysGlobalCache ไว้เก็บค่า Global


static void SysGlobalCache(Args _args)
{
   SysGlobalCache globalCache;
   ;
   globalCache = ClassFactory.globalCache();
   globalCache.set(curuserid(), 1, "One");
   globalCache.set(curuserid(), 2, "two");
 
   print globalCache.get(curuserid(), 1);
   print globalCache.get(curuserid(), 2);
   globalcache.remove(curuserid(), 1);
   pause;
   print globalCache.get(curuserid(), 1);
   print globalCache.get(curuserid(), 2);
   pause;
}

อ้างอิง http://learnax.blogspot.com/2010/01/globalcache-alternative-to.html
Thanks.... Nagaraj Jadhav | India 

How to use:
To Set a Value:
static void GlobalCacheSet(Args _args)
{
SysGlobalCache globalCache;
;
globalCache = ClassFactory.globalCache();
globalCache.set(curuserid(), 1, "One");

To Get the Value:
static void GlobalCacheGet(Args _args)
{
SysGlobalCache globalCache;
;
globalCache = ClassFactory.globalCache();
print globalCache.get(curuserid(), 1);
globalcache.remove(curuserid(), 1);
pause;
}