Monday, 16 April 2012

form field value calculated related to other field

there is a  field in the form and when you change the value of that field then calculated value related to another form should reflact on adjusent field.
form having datasource table which contain calculated field so in that table method (modified) write code:
public void modifiedField(fieldId _fieldId)
{
    SheCRBankMaster     sheCRBankMaster;
    SheCRStampDutyRates sheCRStampDutyRates;
    SheCRPurchTable     sheCRPurchTable;
    SheCRSalesTable     sheCRSalesTable;
    ;
    super(_fieldId);

    switch(_fieldId)
    {
        case fieldnum(SheCRAgrStampDuty, StampingBankName):
            select sheCRBankMaster where sheCRBankMaster.BankName == this.StampingBankName;
            this.Branch = sheCRBankMaster.Branch;
            break;
        case fieldnum(SheCRAgrStampDuty,AmountOrigin):
            sheCRPurchTable = SheCRPurchTable::find(this.AgreementNum);
            if(sheCRPurchTable)
            {
                this.AgreementDate = sheCRPurchTable.AgreementDate;
                this.AgreementType = sheCRPurchTable.AgreementType;
                this.PartyName = VendTable::find(sheCRPurchTable.SigningParty).Name;
                this.Rate = sheCRStampDutyRates.getStampDutyRate(this.AmountOrigin);
                this.StampDutyAmount = this.AmountOrigin * this.Rate / 100;
            }
            else
            {
                sheCRSalesTable = SheCRSalesTable::find(this.AgreementNum);
                this.AgreementDate = sheCRSalesTable.AgreementDate;
                this.AgreementType = sheCRSalesTable.AgreementType;
                this.PartyName = CustTable::find(sheCRSalesTable.SigningParty).Name;
                this.Rate = sheCRStampDutyRates.getStampDutyRate(this.AmountOrigin);
                this.StampDutyAmount = this.AmountOrigin * this.Rate / 100;
            }
            break;
        case fieldnum(SheCRAgrStampDuty,BankAccNum):
            this.BankAccName = BankAccountTable::find(this.BankAccNum).Name;
            break;
    }
}
table on the datasource of the 2nd form write method on table.

public real  getStampDutyRate(real _amountOrigin)
{
    SheCRStampDutyRates sheCRStampDutyRates;
    real                _rate;
    ;

    _rate = 0;

    select sheCRStampDutyRates
        where sheCRStampDutyRates.FromDate <= SystemDateGet()
        && sheCRStampDutyRates.ToDate >= SystemDateGet();
        if(_amountOrigin >= sheCRStampDutyRates.MinimumLimit)
        {
            _rate = sheCRStampDutyRates.MinRate;
        }
        else if(_amountOrigin >= sheCRStampDutyRates.MaximumLimit)
        {
            _rate = sheCRStampDutyRates.MaxRate;
        }
       
    return _rate;
}

No comments:

Post a Comment