随笔之过账模版

AX2009中过账模版可以说已经是非常灵活了,可以根据物料+物料关系+账户(Vend or Cust)+增值税等等进行任意的组合设置,虽然有这么灵活,但是有的客户还是会不满意。例如,如果客户说,我也想按站点和仓库来组合。谁叫客户就是上帝啊,想让他给钱,就必须得满足他,只能去改代码了。

其实静下心来仔细想想,既然标准的都已经写了很多组合,我们也只不过是在它的基础上多加两个组合而已,只要能找到源头,也就没有我们当初想想的那么恐怖,怎么样能找到源头呢?想想看,组合再多,到最后我们也只是找到其中符合我们需要的一条对应的会计科目而已。所以,肯定它会有一个通用的Find方法,只要我们在这个方法中上加上我们需要的条件,然后,稍微的更改一下就应该能达到我们的要求了,看到代码后,发现查找的层次依次find>accountnum>item>accountBalanceSheet,知道这些后,改起来就方便了,具体看看是咋改的吧static InventPosting find(

    InventAccountType   _accountType,
    TableGroupAll       _itemCode,
    ItemRelation        _itemRelation,
    TableGroupAll       _accountCode,
    CustVendRel         _accountRelation,
    TaxGroup            _taxGroup,
    TableGroupAll       _costCode,
    CostRelation        _costRelation,
    boolean             _update = false,
    InventSiteId        _siteid = '',//ADD
    InventLocationId    _locationid = ''//ADD
    )
{
    InventPosting inventPosting;
    ;
    if (_update)
        inventPosting.selectForUpdate(_update);

    if (!InventParameters::find().IWS_SiteLoacPostingACFlag)
    {
        select firstonly inventPosting
            index hint ItemIdx
            where inventPosting.InventAccountType   == _accountType     &&
                  inventPosting.ItemCode            == _itemCode        &&
                  inventPosting.ItemRelation        == _itemRelation    &&
                  inventPosting.CustVendCode        == _accountCode     &&
                  inventPosting.CustVendRelation    == _accountRelation &&
                  inventPosting.TaxGroupId          == _taxGroup        &&
                  inventPosting.CostCode            == _costCode        &&
                  inventPosting.CostRelation        == _costRelation    &&
                  inventPosting.TaxGroupId          == _taxGroup;
    }
//ADD else {
return inventPosting::IWS_findSiteLoca(_accountType, _itemCode, _itemRelation, _accountCode, _accountRelation, _taxGroup, _costCode, _costRelation, _update, _siteid, _locationid); } //ADD return inventPosting; }

  

static InventPosting IWS_findSiteLoca(
    InventAccountType   _accountType,
    TableGroupAll       _itemCode,
    ItemRelation        _itemRelation,
    TableGroupAll       _accountCode,
    CustVendRel         _accountRelation,
    TaxGroup            _taxGroup,
    TableGroupAll       _costCode,
    CostRelation        _costRelation,
    boolean             _update = false,
    InventSiteId        _siteid = '',
    InventLocationId    _locationid = ''
    )
{
    InventPosting inventPosting;
    ;
    if (_update)
        inventPosting.selectForUpdate(_update);

    select firstonly inventPosting
        index hint ItemIdx
        where inventPosting.InventAccountType   == _accountType     &&
              inventPosting.ItemCode            == _itemCode        &&
              inventPosting.ItemRelation        == _itemRelation    &&
              inventPosting.CustVendCode        == _accountCode     &&
              inventPosting.CustVendRelation    == _accountRelation &&
              inventPosting.TaxGroupId          == _taxGroup        &&
              inventPosting.CostCode            == _costCode        &&
              inventPosting.CostRelation        == _costRelation    &&
              inventPosting.TaxGroupId          == _taxGroup        &&
              inventPosting.InventSiteId        == _siteid          &&  
              inventPosting.InventLocationId    == _locationid;        
    if (!inventposting && _siteid)
    {
        select firstonly inventPosting
            index hint ItemIdx
            where inventPosting.InventAccountType   == _accountType     &&
                  inventPosting.ItemCode            == _itemCode        &&
                  inventPosting.ItemRelation        == _itemRelation    &&
                  inventPosting.CustVendCode        == _accountCode     &&
                  inventPosting.CustVendRelation    == _accountRelation &&
                  inventPosting.TaxGroupId          == _taxGroup        &&
                  inventPosting.CostCode            == _costCode        &&
                  inventPosting.CostRelation        == _costRelation    &&
                  inventPosting.TaxGroupId          == _taxGroup        &&
                  inventPosting.InventSiteId        == ""               && 
                  inventPosting.InventLocationId    == _locationid; 
    }

    if (!inventposting && _locationid)
    {
        if (_siteid)
            select firstonly inventPosting
                index hint ItemIdx
                where inventPosting.InventAccountType   == _accountType     &&
                      inventPosting.ItemCode            == _itemCode        &&
                      inventPosting.ItemRelation        == _itemRelation    &&
                      inventPosting.CustVendCode        == _accountCode     &&
                      inventPosting.CustVendRelation    == _accountRelation &&
                      inventPosting.TaxGroupId          == _taxGroup        &&
                      inventPosting.CostCode            == _costCode        &&
                      inventPosting.CostRelation        == _costRelation    &&
                      inventPosting.TaxGroupId          == _taxGroup        &&
                      inventPosting.InventSiteId        == _siteid          && 
                      inventPosting.InventLocationId    == "";  
        if (!inventposting)
           select firstonly inventPosting
                index hint ItemIdx
                where inventPosting.InventAccountType   == _accountType     &&
                      inventPosting.ItemCode            == _itemCode        &&
                      inventPosting.ItemRelation        == _itemRelation    &&
                      inventPosting.CustVendCode        == _accountCode     &&
                      inventPosting.CustVendRelation    == _accountRelation &&
                      inventPosting.TaxGroupId          == _taxGroup        &&
                      inventPosting.CostCode            == _costCode        &&
                      inventPosting.CostRelation        == _costRelation    &&
                      inventPosting.TaxGroupId          == _taxGroup        &&
                      inventPosting.InventSiteId        == ""               && 
                      inventPosting.InventLocationId    == "";
    }

    return inventPosting;
}

  

static LedgerAccount accountNum(
    InventAccountType   _accountType,
    TableGroupAll       _itemCode,
    ItemRelation        _itemRelation,
    TableGroupAll       _accountCode,
    CustVendRel         _accountRelation,
    TaxGroup            _taxGroup,
    TableGroupAll       _costCode           = TableGroupAll::All,
    CostRelation        _costRelation       = '',
    InventSiteId        _siteid = '',
    InventLocationId    _locationid = ''
    )
{
    return InventPosting::find(
            _accountType,
            _itemCode,
            _itemRelation,
            _accountCode,
            _accountRelation,
            _taxGroup,
            _costCode,
            _costRelation,
            false, 
            _siteid,//ADD
            _locationid).LedgerAccountId;//ADD
}

  

static LedgerAccount item(
    InventAccountType accountType,
    ItemId          itemId,
    ItemGroupId     itemGroup  = '',
    InventSiteId        _siteid = '',
    InventLocationId    _locationid = ''
    )
{

    LedgerAccount           ledgerAccount;
    InventPostingParameters inventPostingParameters = InventPostingParameters::find();
    ;
    if (! itemGroup)
        itemGroup  = InventTable::find(itemId).ItemGroupId;

    if (inventPostingParameters.itemRelationEnabled(TableGroupAll::Table))
    {
        ledgerAccount = InventPosting::accountNum(
            accountType,
            TableGroupAll::Table,
            itemId,
            TableGroupAll::All,
            '','',
            TableGroupAll::All,
            '',
            _siteid,//ADD
            _locationid);//ADD
        if (ledgerAccount)
            return ledgerAccount;
    }

    if (inventPostingParameters.itemRelationEnabled(TableGroupAll::GroupId))
    {
        ledgerAccount = InventPosting::accountNum(
            accountType,
            TableGroupAll::GroupId,
            itemGroup,
            TableGroupAll::All,
            '','',
            TableGroupAll::All,
            '',
            _siteid,//ADD
            _locationid);//ADD
        if (ledgerAccount)
            return ledgerAccount;
    }

    if (inventPostingParameters.itemRelationEnabled(TableGroupAll::All))
    {
        ledgerAccount = InventPosting::accountNum(
            accountType,
            TableGroupAll::All,
            '',
            TableGroupAll::All,
            '','',
            TableGroupAll::All,
            '',
            _siteid,//ADD
            _locationid);//ADD
    }

    return ledgerAccount;

}

  只针对具体某一个业务类型进行修改(例如转移日记账-InventMov_Jour_Trans),

/// <summary>
/// When a fixed asset is assigned to the record and we have a ledger account for InventIssueFA
/// we will use that instead of the account defined for the InventIssue inventory account type.
/// </summary>
/// <returns>
/// A LedgerAccount needed for the account balance sheet.
/// </returns>

LedgerAccount accountBalanceSheet()
{
    ;

    if (! cacheAccountBalanceSheet)
    {
        // <GBR>
        if (BrazilParameters::isEnabled() && this.ledgerAccount_BR())
        {
            cacheAccountBalanceSheet = this.ledgerAccount_BR();
        }
        else
        {
        // </GBR>
            if (this.transQty() >= 0)
                    cacheAccountBalanceSheet = InventPosting::item(InventAccountType::InventReceipt,this.itemId(),this.inventTable().ItemGroupId,
                                                       
                                                       InventJournalTrans.toInventDim().InventSiteId,//ADD
                                                       InventJournalTrans.toInventDim().InventLocationId);//ADD
                                                       
            else
            {
                if (this.assetId())
                {
                        cacheAccountBalanceSheet = InventPosting::item(InventAccountType::InventIssueFixedAsset,
                                                    this.itemId(),this.inventTable().ItemGroupId,
                                                    
                                                    this.inventdim().InventSiteId,//ADD
                                                    this.inventdim().InventLocationId);//ADD
                                                   
                }
                if (!cacheAccountBalanceSheet)
                {
                        cacheAccountBalanceSheet = InventPosting::item(InventAccountType::InventIssue,
                                                    this.itemId(),this.inventTable().ItemGroupId,
                                                    
                                                    this.inventdim().InventSiteId,//ADD
                                                    this.inventdim().InventLocationId);//ADD
//ADD
} } // <GBR> } // </GBR> } return cacheAccountBalanceSheet; }

  

  

原文地址:https://www.cnblogs.com/dingkui/p/3677449.html