Показать сообщение отдельно
Старый 27.01.2014, 16:28   #1  
EVGL is offline
EVGL
Banned
Соотечественники
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
 
4,445 / 3001 (0) ++++++++++
Регистрация: 09.07.2002
Адрес: Parndorf, AT
Effective "Date effectivness"
Дамы и господа, как вы считаете, можно ли запрограммировать следующий код в AX2012 лаконичнее:

X++:
public static void setStopped(
    InventItemOrderSetupMap     _inventItemOrderSetupMap,
    ItemStopped                 _stopped,
    date                        _effectiveDate = systemDateGet())
{

    InventItemSetupStopped  record;

    ttsBegin;

    record = InventItemSetupStopped::find(_inventItemOrderSetupMap.TableId, _inventItemOrderSetupMap.RecId, _effectiveDate);

    record.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);

    if (record && record.Stopped != _stopped)
    {
        while select forUpdate validTimeState(_effectiveDate) record
            where record.InventItemSetupRecId   == _inventItemOrderSetupMap.RecId
               && record.InventItemSetupTableId == _inventItemOrderSetupMap.TableId
               && record.ValidTo                != _effectiveDate
        {
            record.ValidTo = max(_effectiveDate-1, record.ValidFrom);
            if (record.validateWrite())
                record.update();
        }

    }

    select forUpdate validTimeState(_effectiveDate) record
        where record.InventItemSetupRecId   == _inventItemOrderSetupMap.RecId
           && record.InventItemSetupTableId == _inventItemOrderSetupMap.TableId
           && record.ValidTo                == _effectiveDate;

    record.initFromInventItemOrderSetupMap(_inventItemOrderSetupMap);
    record.ValidFrom = _effectiveDate;
    record.ValidTo = dateMax();
    record.Stopped = _stopped;

    if (record.validateWrite())
        record.write();

    ttsCommit;
}