close

[ExtensionOf(formStr(PurchTable))]
final class DGS_PurchTable_Form_Extension
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormEventHandler(formStr(PurchTable), FormEventType::Initialized)]
    public void PurchTable_OnInitialized(xFormRun sender, FormEventArgs e)
    {
        FormFunctionButtonControl confirmBtn = sender.design(0).controlName("buttonConfirm");

        if(confirmBtn)
        {

            confirmBtn.registerOverrideMethod(methodStr(FormButtonControl, Clicked),FormMethodStr(PurchTable, DGS_buttonConfirmClicked), this);

        }
    }

    public void DGS_buttonConfirmClicked(FormFunctionButtonControl _sender)
    {
        DimensionAttributeValueSet _dimensionAttributeValueSet;
        DimensionValue _value;
        DimensionDefault  newDimensionDefault ;
        DimensionAttribute _dimensionAttribute;
        DimensionAttributeValue _dimensionAttributeValue;
        LedgerParameters                    ledgerParameters = LedgerParameters::find();

        str dimensionName = ledgerParameters.THK_FinancialDimCarrier;

        if(!purchTable.THK_VendorInvoiceNo)
        {
            throw Error(strFmt("@SYS26332", fieldPName(PurchTable, THK_VendorInvoiceNo)));
        }

        _value = TMSPurchTable::find(purchTable.purchId).CarrierCode;
        if(!_value)
        {
            throw Error(strFmt("@SYS26332", fieldPName(TMSPurchTable, CarrierCode )));
        }
        else
        {
            _dimensionAttribute = DimensionAttribute::findByName(dimensionName);
            if(_dimensionAttribute && _value)
            {
                _dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimensionAttribute,_value);
                // if have this display value inside Financial Dimension, create a new dimensiont value set to purchTable
                if(_dimensionAttributeValue)
                {
                    newDimensionDefault = DGS_CommonDimension::buildDimension(purchTable.defaultDimension,dimensionName,_value);
                    ttsbegin;
                    purchTable.selectForUpdate(true);
                    purchTable.DefaultDimension = newDimensionDefault;
                    purchTable.update();
                    ttscommit;
                }
                else
                {
                    throw Error(strFmt("@SYS26332", dimensionName));
                }
            }
            else
            {
                throw Error(strFmt("@SYS26332", dimensionName));
            }
        }

        // original code:
        PurchTable      purchTableSelection;
        Common          firstDatasourceCursor;
        boolean         tax1099SFieldsOK = true;
        int             originalPosition;

        if (isConfigurationkeyEnabled(configurationKeyNum(PublicSector)))
        {
            originalPosition = purchTable_DS.getPosition();
            firstDatasourceCursor = purchTable_ds.getFirst(true);

            for (purchTableSelection = (firstDatasourceCursor ? firstDatasourceCursor : purchTable_ds.cursor()) ; purchTableSelection && tax1099SFieldsOK == true ; purchTableSelection = purchTable_ds.getNext())
            {
                tax1099SFieldsOK = Tax1099BoxDetail::checkTax1099Fields(purchTableSelection.PurchId);
            }

            purchTable_DS.setPosition(originalPosition);

            if (tax1099SFieldsOK)
            {
               // super();
               _sender.clicked();
            }

            purchTable_ds.updateBudgetCheckResultDisplay();
        }
        else
        {
            try
            {
                //super();
                _sender.clicked();

                purchTable_ds.updateBudgetCheckResultDisplay();

                purchTableForm.parmIsHeaderVersioned(true);
            }
            catch
            {
                purchTable_ds.updateBudgetCheckResultDisplay();
            }
        }
    }

}

arrow
arrow
    文章標籤
    dynamics AX D365
    全站熱搜

    lionlionchopper 發表在 痞客邦 留言(0) 人氣()