[AX2012]关于财务默认维度
和以前的版本一样,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]关于财务默认维度的更多相关文章
- [AX2012]代码更改默认财务维度
在前文(http://www.cnblogs.com/duanshuiliu/p/3243048.html)最后演示了如何使用代码更改默认财务维度,那段代码模拟了创建各数据表记录的过程,实际上AX提供 ...
- Keras中图像维度介绍
报错问题: ValueError: Negative dimension size caused by subtracting 5 from 1 for 'conv2d_1/convolution' ...
- H2的MVStore
翻译自http://www.h2database.com/html/mvstore.html 转载请著名出处,及译者信息. 第一次翻译,诸多不妥请谅解,谢谢. 概述 MVStore是一个持久化的.日志 ...
- 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上 ove ...
- PyTorch入门(一)向量
什么是PyTorch? PyTorch是Facebook人工智能团队开发的一个机器学习和深度学习工具,用于处理大规模图像分析,包括物体检测,分割与分类.但是它的功能不仅限于此.它与其它深度学习框架 ...
- PROJ.4学习——初识PROJ
PROJ.4介绍——初始认识 前言 PROJ是一个通用的坐标转换软件,它将地理空间坐标从一个坐标系转换为另一个坐标系.这包括地图投影和大地坐标变换. PROJ包含命令行应用程序,可以方便地从文本文件或 ...
- OLAP了解与OLAP引擎——Mondrian入门
一. OLAP的基本概念 OLAP(On-Line Analysis Processing)在线分析处理是一种共享多维信息的快速分析技术:OLAP利用多维数据库技术使用户从不同角度观察数据:OLAP ...
- C++Primer学习笔记《2》
数组是一种复合类型,由类型名+数组名+维度组成. 数组定义中的类型能够是C++基本内置类型.也能够是类类型的.数组元素的类型能够是除了引用类型以外的其它不论什么类型.没有全部的元素都是引用的数组. 数 ...
- Python numpy的基本操作你一般人都不会
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要最新Python学习资料的小伙伴可以加点击下方链接自行获取 ...
随机推荐
- JavaScript系列文章:谈谈let和const
JavaScript系列文章:谈谈let和const 最近接触到ES6的一些相关新特性,想借let和const两个命令谈谈JavaScript在变量方面的改进. 由于let和const有很多相似之 ...
- Java 高效并发之volatile关键字解析
摘录 1. 计算机在执行程序时,每条指令都是在CPU中执行的,而执行指令过程中,势必涉及到数据的读取和写入.由于程序运行过程中的临时数据是存放在主存(物理内存)当中的,这时就存在一个问题,由于CPU执 ...
- R语言使用tryCatch进行简单的错误处理
最近在看<机器学习:实用案例解析>,做邮件过滤器的时候,参考书中的代码读取邮件文件进行分类器训练,在读取过程中会出现下面的错误: seq.default(which(text == & ...
- 如何使用Javascript XSLT 处理XML文件(支持Firefox)
最近使用Firefox进行网页的调试,发现有些Javascript XSLT处理XML的语句仅仅支持IE浏览器.而网络中的一些介绍javascript XSLT 处理XML的文章基本上都是依据AJAX ...
- css小贴士备忘录
前言:在CSS的学习实践过程中,我经常遗忘一些貌似常用的代码,为了能够强化记忆特在此作归纳整理并将陆续增删,以备即时查阅.但愿今后能遇到问题及时解决,牢牢记住这些奇怪的字符们. 一.关于段落文本强制对 ...
- How to properly release Excel COM objects
Posted on Tuesday, November 5th, 2013 at 7:18 am by Pieter van der Westhuizen. You’ll see a lot ...
- [转]Android精品开源项目整理
前言: 无论你是android的初学者,还有是android开发多年的高手,可能都会有很多想法和经验希望与人分享交流,渴望能够接触到更多的实战项目,正所谓所谓与高手论道才能互补所长,与英雄 ...
- VoltDB
VoltDB VoltDB,一个内存数据库,提供了 NoSQL 数据库的可伸缩性和传统关系数据库系统的 ACID 一致性. VoltDB是一个内存中的开源OLTP SQL数据库,能够保证事务的完整性( ...
- R绘图系统中的坐标系
在R语言中,对于图中的点来说,有很多种坐标系来进行定位 举个例子: par(omi = c(1, 1, 1, 1), mai = c(1, 1, 1, 1), mfrow = c(1, 2)) plo ...
- c# 连接mysql配置config,不用装net connector
<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient&qu ...