和以前的版本一样,AX2012中很多地方都使用财务维度,比如客户、销售订单、销售订单行等,根据相应的财务维度设置,生成的相应财务分录将带有财务维度,方便后续对财务分录交易的分析。下图是在客户记录上设置默认财务维度的情况:

默认财务维度只包括CostCenter、Department和ExpensePurpose,如果要象上图要添加显示其他的财务维度,在以前的版本中需要编程实现,但是在AX2012我们只需要配置即可实现。

首先需要创建相应的财务维度(General ledger>Setup>Financial dimensions>Financial dimensions,表DimensionAttribute的一条记录对应一个财务维度):

需要注意的是“use values from”选项,系统集成了几种维度值来源,比如这里维度“Customer”的维度取值为“Customers”,维度的值将来自于CustTable表由系统自动生成不能手工添加(其实来自于视图DimAttributeCustTable)。“use values from”可以是“<Custom dimension>”,这种维度的维度值是手工维护的,点击“Financial dimension values”可以维护维度的值列表:

维度“Customer”取值来自于系统,所以上图中是不能修改维度取值的,“new”、“delete”等按钮是灰化的。

创建的财务维度我们需要添加到相应公司的总账账号结构中,找到General ledger>Setup>Ledger:

Account structures有两条记录,选择一条记录点击“Config account structure”:

上图中我们把“Customer”和“Vendor”添加到默认的总账账号结构中,激活后我们在客户记录的默认财务维度中就能看到“Customer”和“Vendor”两个维度了。

再来看看相关的数据是如何保存的,客户表CusTable.DefaultDimension保存的是来自于DimensionAttributeValueSet表的一条记录RecId,表单上维度信息的显示与编辑由类DimensionDefaultingController实现,它用下面的代码根据DimensionAttributeValueSet.RecId获取各个维度的设置值:

protected container getAttributeValueSet(DimensionDefault _dimAttributeValueSetId, selectableDataArea _company)
{
return DimensionControllerObject::getAttributeValueSetServer(_dimAttributeValueSetId, _company);
}

这里用到另外一个表DimensionAttributeValueSetItem,假设我们在图1中同时设置客户的Department和Department两个财务维度,这个过程会创建1条DimensionAttributeValueSet记录和2条DimensionAttributeValueSetItem记录:

  • DimensionAttributeValueSetItem.DimensionAttributeValueSet 字段 -> DimensionAttributeValueSet.RecId
  • DimensionAttributeValueSetItem.DimensionAttributeValue 字段 -> DimensionAttributeValue.RecId (该表的一条记录保存财务维度的一个取值)
  • DimensionAttributeValue.DimensionAttribute 字段 -> DimensionAttribute.RecId

通过关联查询这几个表,我们就能查找出CustTable.DefaultDimension所代表的一组Dimension及其值的组合。DimensionAttributeValueSet表只有一个字段Hash,且被设置为不能重复的索引,它表示的是其代表的一组维度值HashKey经过运算后得到的哈希值,存放在表DimensionAttributeValueSet以表示这样的财务组合已经存在,以防止重复生成相应的维度组合。

在有一定的了解后,我们来看看如何通过代码设置默认维度:

static void setCustTableDefaultFinancialDimension(Args _args)

{

    #LedgerSHA1Hash

    DimensionSHA1Hash               hash; //To store the calculated hash for DimensionAttributeValueSet
HashKey valueKeyHashArray[]; //To store the has key of dimension in question
Map dimAttrIdx; //to store the dimension index and backing entity type
DimensionAttributeSetItem dimAttrSetItem; // Contains the number of dimensions active for a account structure ledger
DimensionAttribute dimAttr; // Contains the financial dimensions records
DimensionAttributeValue dimAttrValue; // Contains used financial dimension values
DimensionAttributeValueSet dimAttrValueSet; //Contains default dimension records
DimensionAttributeValueSetItem dimAttrValueSetItem; //Contains individual records for default dimensions
DimAttributeCustTable dimAttrCustTable; //Backing entity view for Employee type dimension
DimensionEnumeration dimensionSetId; //Record id for table that contains active dimensions for current ledger
CustTable custTable; //Record of the customer used to set the dimension int dimAttrCount, i;
int custBackEntityType; //Stores the backing entity type for Employee type dimension
; //The employee backing entity will be the view DimAttributeHcmWorker
custBackEntityType = tableNum(DimAttributeCustTable); //Initialize the map to store the backing entity types
dimAttrIdx = new Map(Types::Integer, Types::Integer); //Get the record Id (dimension set id) for current ledger to find active dimensions
dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger(); //Find all the active dimensions for current ledger except main account and store there
//backing entity type in the map
while select * from dimAttr
order by Name
where dimAttr.Type != DimensionAttributeType::MainAccount
join RecId from dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
dimAttrSetItem.DimensionAttributeSet == dimensionSetId
{
dimAttrCount++;
dimAttrIdx.insert(dimAttr.BackingEntityType, dimAttrCount);
info(dimAttr.Name);
} //initialize hash key array to null
for (i = ; i<= dimAttrCount; i++)
valueKeyHashArray[i] = emptyGuid(); //Find the Dimension attribute record for the dimension to work on
dimAttr.clear();
select firstonly dimAttr
where dimAttr.BackingEntityType == custBackEntityType; //Get the backing entity type for the dimension value to process
select firstOnly dimAttrCustTable
where dimAttrCustTable.Value == ''; //Find the required Dimension Attribute Value record
//Create if necessary
dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndEntityInst(dimAttr.RecId, dimAttrCustTable.RecId, false, true); //Store the required combination hash keys
valueKeyHashArray[dimAttrIdx.lookup(custBackEntityType)] = dimAttrValue.HashKey; //Calculate the hash for the current values
hash = DimensionAttributeValueSetStorage::getHashFromArray(valueKeyHashArray, dimAttrCount); //Null hash indicates no values exist, which may occur if the user entered an invalid value for one dimension attribute
if (hash == conNull())
{
throw error("Wrong value for Customer Dimension");
} // Search for existing value set
dimAttrValueSet = DimensionAttributeValueSet::findByHash(hash); // This value set does not exist, so it must be persisted
if (!dimAttrValueSet)
{
ttsbegin; // Insert the value set with appropriate hash
dimAttrValueSet.Hash = hash;
dimAttrValueSet.insert(); //Insert Customer dimension set item
dimAttrValueSetItem.clear();
dimAttrValueSetItem.DimensionAttributeValueSet = dimAttrValueSet.RecId;
dimAttrValueSetItem.DimensionAttributeValue = dimAttrValue.RecId;
dimAttrValueSetItem.DisplayValue = dimAttrCustTable.Value;
dimAttrValueSetItem.insert(); ttscommit; } //Update the customer default dimension field
ttsBegin;
select forUpdate custTable where custTable.AccountNum == '';
custTable.DefaultDimension = dimAttrValueSet.RecId;
custTable.Update();
ttsCommit; info(strFmt("%1", dimAttrValueSet.RecId)); }

上面代码参考http://sumitsaxfactor.wordpress.com/2011/12/28/defaulting-financial-dimensions-ax-2012/,设置客户代码为“1101”客户的“Customer”维度为其自身。

代码更改默认维度还有其他一些方法,在以后的文章中再讨论。

[AX2012]关于财务默认维度的更多相关文章

  1. [AX2012]代码更改默认财务维度

    在前文(http://www.cnblogs.com/duanshuiliu/p/3243048.html)最后演示了如何使用代码更改默认财务维度,那段代码模拟了创建各数据表记录的过程,实际上AX提供 ...

  2. Keras中图像维度介绍

    报错问题: ValueError: Negative dimension size caused by subtracting 5 from 1 for 'conv2d_1/convolution' ...

  3. H2的MVStore

    翻译自http://www.h2database.com/html/mvstore.html 转载请著名出处,及译者信息. 第一次翻译,诸多不妥请谅解,谢谢. 概述 MVStore是一个持久化的.日志 ...

  4. 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题

    受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上  ove ...

  5. PyTorch入门(一)向量

    什么是PyTorch?   PyTorch是Facebook人工智能团队开发的一个机器学习和深度学习工具,用于处理大规模图像分析,包括物体检测,分割与分类.但是它的功能不仅限于此.它与其它深度学习框架 ...

  6. PROJ.4学习——初识PROJ

    PROJ.4介绍——初始认识 前言 PROJ是一个通用的坐标转换软件,它将地理空间坐标从一个坐标系转换为另一个坐标系.这包括地图投影和大地坐标变换. PROJ包含命令行应用程序,可以方便地从文本文件或 ...

  7. OLAP了解与OLAP引擎——Mondrian入门

    一.  OLAP的基本概念 OLAP(On-Line Analysis Processing)在线分析处理是一种共享多维信息的快速分析技术:OLAP利用多维数据库技术使用户从不同角度观察数据:OLAP ...

  8. C++Primer学习笔记《2》

    数组是一种复合类型,由类型名+数组名+维度组成. 数组定义中的类型能够是C++基本内置类型.也能够是类类型的.数组元素的类型能够是除了引用类型以外的其它不论什么类型.没有全部的元素都是引用的数组. 数 ...

  9. Python numpy的基本操作你一般人都不会

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.  PS:如有需要最新Python学习资料的小伙伴可以加点击下方链接自行获取 ...

随机推荐

  1. .net修炼笔记

    1. 底层基础概念 CIL(Common Intermediate Language) 中间语言(C# VB 最终编译成CIL语言) BCL(Base Class Library) 基础类库 (Sys ...

  2. 关于使用mybatis的一个惨痛教训

    事情大概是这样的: 某个时刻之后所有的交易都崩溃了,查看数据库得知所有的数据都变成一样的了!!! 再查看log,发现执行了这样的语句:UPDATE XXX SET c1=v1,c2=v2 ...,没有 ...

  3. 记一些常用到的python中的函数

    1. zip()函数 它的作用是从参数中按顺序一一抽出子参数组出一个新的tuple.  直接看例子: >>> mean = np.array([2, 5, 4]) >>& ...

  4. 一个类似于postman的协议测试工具

    协议测试工具使用postman相当便捷,不过有一个问题,就是每个人都要装一个这个东西,并且测试文件导来导去,还是觉得麻烦了点. 最重要的是postman不能修改,有一些定制功能postman明显力不从 ...

  5. Android Notification和权限机制探讨

    近期为了在部门内做一次小型的技术分享.深入了解了一下Notification的实现原理.以及android的权限机制.在此做个记录.文章可能比較长,没耐心的话就直接看题纲吧. 先看一下以下两张图 图一 ...

  6. Dynamics CRM 2015/2016 Web API:聚合查询

    各位小伙伴们,今天是博主2016年发的第一篇文章.首先祝大家新年快乐.工资Double,哈哈.今天我们来看一个比較重要的Feature--使用Web API运行FetchXML查询! 对的,各位.你们 ...

  7. QIIME1 聚OTU

    qiime 本身不提供聚类的算法,它只是对其他聚otu软件的封装 根据聚类软件的算法,分成了3个方向: de novo:                   pick_de_novo_otus.py  ...

  8. JS性能细节学习初步总结

    1,声明变量要赋初值2,尽量避免声明全局变量,可以减少与系统的重名3,当编写大量js代码时,难免会遇到命名冲突,这是可以通过模拟命名空间方式     来避免冲突4,尽量避免使用全局变量,搜索全局变量是 ...

  9. UART Receive FIFO and Receive Timeout

    为什么UART要有FIFO? 现代的CPU运转速度越来越快.UART的波特率通常达不到10M,在没有FIFO的情况下.每次填充数据给UART 或者 从UART取数据都会占用CPU的时间.这是极大的浪费 ...

  10. ML基础 : 训练集,验证集,测试集关系及划分 Relation and Devision among training set, validation set and testing set

    首先三个概念存在于 有监督学习的范畴 Training set: A set of examples used for learning, which is to fit the parameters ...