Tuesday, 22 August 2017

Sales ValidateInvoiceAmtwithDiscount

public boolean validateInvoiceAmtwithDiscount()// calucalte the invocie amount with discount on 21-aug -17
{
    boolean         ret = true;
    container       displayFields;
    AmountCur       invocieAmt = 0.00, TotalSalesAmt = 0.00, TotalAmtWithDiscount = 0.00;
    salesLine       salesLine;
    smmParametersTable smmParametersTable;
    ;

    if(this && this.SalesType == salesType::Sales)

    {
        displayFields = SalesTotals::displayFieldsServer(this, salesUpdate::All, CompanyInfo::standardCurrency());

        invocieAmt    = conpeek(displayFields, TradeTotals::posTotalAmount());

        while select salesLine
                where salesLine.SalesId == this.SalesId
        {
            TotalSalesAmt += (salesLine.MSP * salesLine.SalesQty) ;
        }


        if(smmParametersTable::find().DiscountPercentage)
            TotalAmtWithDiscount = TotalSalesAmt - (TotalSalesAmt * (smmParametersTable::find().DiscountPercentage / 100));
        else
            TotalAmtWithDiscount = TotalSalesAmt;

        info(strFmt("discount percentage %1",smmParametersTable::find().DiscountPercentage));


        if(invocieAmt < TotalAmtWithDiscount)
             ret = checkFailed("Invocie Amount should not Less than the Sales Lines Amount. ");

    }

    return ret;
}

Wednesday, 26 April 2017

Fx exposure report

[
    SRSReportParameterAttribute(classStr(FxExposurePositionContract))
]
class FxExposurePositionDP extends SRSReportDataProviderBase
{
    FxExposurePositionTmp        fxExposurePositionTmp;
}


[SRSReportDataSetAttribute(tableStr(AEIFxExposurePositionTmp))]
public FxExposurePositionTmp getFxExposurePositionTmp()
{
    select fxExposurePositionTmp;
    return  fxExposurePositionTmp;
}


[SysEntryPointAttribute]
public void processreport()
{
    VendAgingReportContract         contract;
    VendAgingReportDP               vendAgingDp;
    VendAgingReportTmp              vendAgingTmp;
    AEIFxExposurePositionContract   aeiContract;

    aeiContract                     = this.parmDataContract();
    contract                        = new VendAgingReportContract();
    vendAgingDp                     = new VendAgingReportDP();

    contract.parmDateTransactionDuedate(DateTransactionDuedate::TransactionDate);
    contract.parmZeroDate(aeiContract.parmZeroDate());
    contract.parmPayments(NoYes::No);
    contract.parmPeriod(DayMonth::Day);
    contract.parmDetailed(NoYes::Yes);
    contract.parmExcludeZeroBalanceVendor(NoYes::Yes);
    contract.parmPrintZeroOrNegative(NoYes::Yes);
    contract.parmIncludeAmountCur(NoYes::Yes);

    vendAgingDp.parmDataContract(contract);
    vendAgingDp.processReport();

    vendAgingTmp                        = vendAgingDp.getVendAgingReportTmp();

    insert_recordset fxExposurePositionTmp (TransDate, CurrencyCode, AmountCur, AmountMST)
        select TransDate, CurrencyCode, Balance01Cur, Balance01 from vendAgingTmp;

}


Contract Class



[DataContractAttribute]
class FxExposurePositionContract
{
    TransDate   zeroDate;
}

[
    DataMemberAttribute('ZeroDate'),
    SysOperationLabelAttribute(literalStr("@SYS137399")),
    SysOperationHelpTextAttribute(literalStr("@SYS137399")),
    SysOperationDisplayOrderAttribute('1')
]
public TransDate parmZeroDate(TransDate _zeroDate = zeroDate)
{
    zeroDate = _zeroDate;
    return zeroDate;
}


Fx currency Report

[
    SRSReportParameterAttribute(classStr(FxCurrencyContract)),
    SRSReportQueryAttribute(queryStr(FxCurrency))
]
class FxCurrencyDP extends SRSReportDataProviderBase
{
    FxCurrencyTmp            fxCurrencyTmp;
}



[SRSReportDataSetAttribute('FxCurrencyTmp')]
public FxCurrencyTmp getFxCurrencyTmp()
{
    select  fxCurrencyTmp;
    return  fxCurrencyTmp;
}

[SysEntryPointAttribute]
public void processReport()
{
    AEIFxCurrencyContract       contract;
    TransDate                   fromDate;
    TransDate                   toDate;
    String255                   rateType;
    CurrencyCode                fromCurrencyCode;
    Query                       query;
    QueryRun                    queryRun;

    ExchangeRate                queryExchangeRate;
    ExchangeRateCurrencyPair    queryExchangeRateCurrencyPair;

    contract                    = this.parmDataContract();

    fromDate                    = contract.parmFromDate();
    toDate                      = contract.parmToDate();
    rateType                    = contract.parmExchangeRateType();
    fromCurrencyCode            = contract.parmFromCurrencyCode();

    query                       = this.parmQuery();

    query.validTimeStateDateTimeRange(DateTimeUtil::minValue(), DateTimeUtil::maxValue());

    query.dataSourceTable(tableNum(ExchangeRate)).addRange(fieldNum(ExchangeRate, ValidFrom)).value(queryRange(fromDate, toDate));
    query.dataSourceTable(tableNum(ExchangeRateType)).addRange(fieldNum(ExchangeRateType, Name)).value(rateType);
    query.dataSourceTable(tableNum(ExchangeRateCurrencyPair)).addRange(fieldNum(ExchangeRateCurrencyPair, FromCurrencyCode)).value(fromCurrencyCode);

    queryRun                    = new QueryRun(query);

    while(queryRun.next())
    {
        fxCurrencyTmp.clear();

        queryExchangeRate                   = queryRun.get(tableNum(ExchangeRate));
        queryExchangeRateCurrencyPair       = queryRun.get(tableNum(ExchangeRateCurrencyPair));

        fxCurrencyTmp.Currency              = queryExchangeRateCurrencyPair.ToCurrencyCode;
        fxCurrencyTmp.Date                  = queryExchangeRate.ValidFrom;

        if(enum2str(queryExchangeRateCurrencyPair.ExchangeRateDisplayFactor) == '' && queryExchangeRateCurrencyPair.FromCurrencyCode == queryExchangeRateCurrencyPair.ToCurrencyCode)
        {
            fxCurrencyTmp.ExchangeRate      = 1;
        }
        else
        {
            fxCurrencyTmp.ExchangeRate      = ExchangeRateHelper::displayStoredExchangeRate_Static(queryExchangeRate.ExchangeRate, queryExchangeRateCurrencyPair.ExchangeRateDisplayFactor);
        }

        fxCurrencyTmp.insert();
    }

}









Contract CLass



[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(FxCurrencyUIBuilder))
]
class AeiFxCurrencyContract implements SysOperationValidatable
{
    TransDate       fromDate;
    TransDate       toDate;
    String255       rateType;
    CurrencyCode    fromCurrencyCode;
    ExchangeRateTypeName exchangeRateTypeName;
}

[
    DataMemberAttribute('Exchange rate type'),
    SysOperationLabelAttribute(literalStr("@SYS312339")),
    SysOperationDisplayOrderAttribute('3')
]
public ExchangeRateTypeName parmExchangeRateType(ExchangeRateTypeName _exchangeRateTypeName = exchangeRateTypeName)
{
    exchangeRateTypeName = _exchangeRateTypeName;
    return exchangeRateTypeName;
}



[
    DataMemberAttribute('From currency code'),
    SysOperationLabelAttribute(literalStr("@SYS315108")),
    SysOperationDisplayOrderAttribute('4')
]
public CurrencyCode parmFromCurrencyCode(CurrencyCode _fromCurrencyCode = fromCurrencyCode)
{
    fromCurrencyCode = _fromCurrencyCode;
    return fromCurrencyCode;
}

[
    DataMemberAttribute('ValidFrom'),
    SysOperationLabelAttribute(literalStr("@SYS24050")),
    SysOperationDisplayOrderAttribute('1')
]
public TransDate parmFromDate(TransDate _fromDate = fromDate)
{
    fromDate = _fromDate;
    return fromDate;
}


[
    DataMemberAttribute('ValidTo'),
    SysOperationLabelAttribute(literalStr("@SYS35904")),
    SysOperationDisplayOrderAttribute('2')
]
public TransDate parmToDate(TransDate _toDate = toDate)
{
    toDate = _toDate;
    return toDate;
}


/// Determines whether the parameters are valid.
/// </summary>
/// <returns>
/// true when the parameters are valid; otherwise, false.
/// </returns>
public boolean validate()
{
    boolean isValid = true;
    if (!fromDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS24050"));
    }
    if (!toDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS35904"));
    }
    if (fromDate > toDate)
    {
        isValid = checkFailed(strFmt("@SYS103965", date2StrUsr(fromDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));
    }
    if (!fromCurrencyCode)
    {
        isValid = checkFailed(strFmt("@SYS84753","@SYS3392"));
    }
    if (!exchangeRateTypeName)
    {
        isValid = checkFailed(strFmt("@SYS84753","@SYS312339"));
    }
    return isValid;
}



UIBuilder Class



public class FxCurrencyUIBuilder extends SrsReportDataContractUIBuilder
{
    FxCurrencyContract   contract;
}

public void build()
{
    contract = this.dataContractObject();

    this.addDialogField(methodStr(FxCurrencyContract, parmFromDate), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmToDate), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmFromCurrencyCode), contract);
    this.addDialogField(methodStr(FxCurrencyContract, parmExchangeRateType), contract);
}

public void lookupExchRateName(FormStringControl _exchangeRateTypeControl)
{
    Query q = new Query();
    SysTableLookup  sysTableLookup;

    sysTableLookup = SysTableLookup::newParameters(tableNum(ExchangeRateType), _exchangeRateTypeControl);
    sysTableLookup.addLookupfield(fieldNum(ExchangeRateType, Name));

    q.addDataSource(tableNum(ExchangeRateType));

    sysTableLookup.parmQuery(q);
    sysTableLookup.performFormLookup();
}

public void postBuild()
{
    DialogField     exchangeRateTypeDialog;

    super();

    exchangeRateTypeDialog = this.bindInfo().getDialogField(this.dataContractObject(),
                methodStr(FxCurrencyContract,parmExchangeRateType));

    exchangeRateTypeDialog.registerOverrideMethod(
          methodStr(FormStringControl, lookup),
          methodStr(AEIFxCurrencyUIBuilder,lookupExchRateName),
          this);
}


Purch Report



[
//SRSReportQueryAttribute(queryStr(PurchQuery)),
SRSReportQueryAttribute(queryStr(PurchQuery)),
SRSReportParameterAttribute(classStr(PurchContract))
]
//public class PurchDP extends  SRSReportDataProviderBase
public class PurchDP extends  SrsReportDataProviderPreProcess
{
    PurchTem                purchTem;

    PurchContract                contract;

    DataAreaId              dataArearId;
    CurrencyCode            currencyCode;
    //PurchStatus             PurchStatus;

}

[SRSReportDataSetAttribute(tableStr(PurchTem))]
public purchTem GetPurchTem()
{
    select  purchTem;
    return  purchTem;
}



[SysEntryPointAttribute]
public void processReport()
{
    Query                       query;
    QueryRun                    queryRun;
    PurchTable                  purchTable;
    PurchLine                   purchLine;
    InventDim                   inventDim;
    InventSite                  inventsite;
    VendTable                   vendTable;
    VendTrans                   vendTrans;
    VendInvoiceJour             vendInvoiceJour;


    contract                = this.parmDataContract() as PurchContract;

    dataArearId             = contract.pramDataAreaId();
    currencyCode            = contract.pramCurrencyCode();
    //purchStatus             = contract.prampurchStatus();

    query                       = this.parmQuery();
    queryRun                    = new QueryRun(query);
    while(queryRun.next())
    {
    purchTable                  = queryRun.get(tableNum(PurchTable));
    purchLine                   = queryRun.get(tableNum(purchLine));
    inventDim                   = queryRun.get(tableNum(InventDim));
    inventsite                  = queryRun.get(tableNum(InventSite));
    vendTable                   = queryRun.get(tableNum(VendTable));
    vendTrans                   = queryRun.get(tableNum(VendTrans));
    //vendInvoiceJour             = queryRun.get(tableNum(VendInvoiceJour));
//breakpoint;
    purchTem.clear();

    purchTem.PurchId            = purchTable.PurchId;
    purchTem.PurchName          = purchTable.PurchName;
    purchTem.PurchStatus        = purchTable.PurchStatus;
    purchTem.InvoiceAccount     = purchTable.InvoiceAccount;
    purchTem.ItemId             = purchLine.ItemId;
    purchTem.Name               = purchLine.Name;
    purchTem.LineAmount         = purchLine.LineAmount;
    purchTem.PurchPrice         = purchLine.PurchPrice;
    purchTem.CurrencyCode       = purchLine.CurrencyCode;
    purchTem.PurchUnit          = purchLine.PurchUnit;
    purchTem.PurchQty           = purchLine.PurchQty;
    purchTem.QtyOrdered         = purchLine.QtyOrdered;
    purchTem.VendGroup          = purchLine.VendGroup;
    purchTem.InventDimId        = purchLine.InventDimId;
    purchTem.InventLocationId   = inventDim.InventLocationId;
    purchTem.InventSiteId       = inventDim.InventSiteId;
    purchTem.DefaultDimension   = inventsite.DefaultDimension;
    purchTem.InventColorId      = inventDim.InventColorId;
    purchTem.InventSizeId       = inventDim.InventSizeId;
    purchTem.DefaultInventStatusId = inventsite.DefaultInventStatusId;



     




        // add by pramod vendTable,vendTrans
    purchTem.AccountNum         = vendTable.AccountNum;
    purchTem.CashDisc           = vendTable.CashDisc;
    purchTem.PaymMode           = vendTable.PaymMode;
    purchTem.PaymSched          = vendTable.PaymSched;
    purchTem.AmountCur          = vendTrans.AmountCur;
    purchTem.AmountMST          = vendTrans.AmountMST;
    purchTem.PaymId             = vendTrans.PaymId;
    purchTem.PostingProfile     = vendTrans.PostingProfile;
    purchTem.SettleAmountCur    = vendTrans.SettleAmountCur;
    purchTem.SettleAmountMST    = vendTrans.SettleAmountMST;
    purchTem.TransDate          = vendTrans.TransDate;
    purchTem.TransType          = vendTrans.TransType;
    purchTem.Voucher            = vendTrans.Voucher;
    //purchTem.CountryRegionId    = vendInvoiceJour.CountryRegionId;
    //purchTem.DeliveryName       = vendInvoiceJour.DeliveryName;
    //purchTem.InvoiceAmount      = vendInvoiceJour.InvoiceAmount;
    //purchTem.InvoiceAmountMST   = vendInvoiceJour.InvoiceAmountMST;
    //purchTem.InvoiceId          = vendInvoiceJour.InvoiceId;
    //purchTem.InvoiceDate        = vendInvoiceJour.InvoiceDate;
    //purchTem.InvoiceType        = vendInvoiceJour.InvoiceType;
    //purchTem.LedgerVoucher      = vendInvoiceJour.LedgerVoucher;

    //purchTem


     purchTem.insert();
    }

}

party payable report


DP Class

[SRSReportQueryAttribute(queryStr(PartyPayable)),
    SRSReportParameterAttribute(classStr(PartyPayableContract))]
class PartyPayableDP extends SRSReportDataProviderBase
{
    PartyPayableTmp       partyPayableTmp;
    TmpSysQuery                 tmpSysQuery;

    #define.chargeCode('Charge code')
}


[SRSReportDataSetAttribute(tableStr(PartyPayableTmp))]
public PartyPayableTmp    getPartyPayableTmp()
{
    select partyPayableTmp;
    return partyPayableTmp;
}


[SRSReportDataSetAttribute(tableStr(TmpSysQuery))]
public TmpSysQuery getTmpSysQuery()
{
    select tmpSysQuery;
    return tmpSysQuery;
}






[SysEntryPointAttribute]
public void processReport()
{
    PartyPayableContract                                contract;
    ProjInvoiceJour                                     projInvoiceJour;
    ProjInvoiceItem                                     projInvoiceItem;
    ProjTable                                           projTable;
    MarkupTrans                                         markupTrans;
    ProjInvoiceItemDetail                               projInvoiceItemDetail;
    AEGOlapDefaultDimensionFramework                    defaultDimensionView;
    AEGChannelView                                      channelView;
    str                                                 chargeCodeParm;

    List                                                chargeCode;
    ListIterator                                        chargeCodeIterator;

    Query                                               query;
    QueryRun                                            queryRun;
    QueryBuildDataSource                                qbdMarkupTrans;
    QueryBuildRange                                     qbrMarkupTrans;

     contract                         = this.parmDataContract() as PartyPayableContract;
    chargeCode                                          = contract.parmChargeCode();
    chargeCodeIterator                                  = new ListIterator(chargeCode);

    query                                               = this.parmQuery();
    qbdMarkupTrans                             = query.dataSourceTable(tableNum(MarkupTrans));

    while(chargeCodeIterator.more())
    {
  qbrMarkupTrans                  = qbdMarkupTrans.addRange(fieldNum(MarkupTrans, MarkupCode));
        qbrMarkupTrans.value(chargeCodeIterator.value());
        qbrMarkupTrans.status(RangeStatus::Hidden);

        chargeCodeParm                                  += ((chargeCodeParm != '' ? ';' : '') + chargeCodeIterator.value());

        chargeCodeIterator.next();
    }

    queryRun                                            = new QueryRun(query);

    tmpSysQuery                  = SRSDynamicQuery::rangesToTmpSysQuery(this.parmQuery());

    tmpSysQuery.clear();
    tmpSysQuery.FieldLabel                              = #chargeCode;
    tmpSysQuery.RangeValue                              = chargeCodeParm;
    tmpSysQuery.insert();

    while(queryRun.next())
    {
        projInvoiceJour                             = queryRun.get(tableNum(ProjInvoiceJour));
        projInvoiceItem                             = queryRun.get(tableNum(ProjInvoiceItem));
        projTable                                   = queryRun.get(tableNum(ProjTable));
        markupTrans                                 = queryRun.get(tableNum(MarkupTrans));
        projInvoiceItemDetail                 = queryRun.get(tableNum(ProjInvoiceItemDetail));

        partyPayableTmp.clear();

        partyPayableTmp.InvoiceAccount                  = projInvoiceJour.InvoiceAccount;
        partyPayableTmp.CustomerName                    = projInvoiceJour.DeliveryName;
        partyPayableTmp.ProjInvoiceId                   = projInvoiceJour.ProjInvoiceId;
        partyPayableTmp.InvoiceDate                     = projInvoiceJour.InvoiceDate;
        partyPayableTmp.CurrencyId                      = projInvoiceJour.CurrencyId;
        partyPayableTmp.ProjId                          = projInvoiceItem.ProjId;
        partyPayableTmp.CampaignProjId                  = projTable.AEGCampaignProjId;

        //Note:- substring is taken taken from 1 to strLen-1,
        //because some project name string are containing 'GS' (group seperator) special character....
        partyPayableTmp.Name                     = char2num(projTable.Name, strLen(projTable.Name)) > 31 ? projTable.Name : subStr(projTable.Name, 1, strLen(projTable.Name)-1);

        select firstOnly maxOf(ChannelKey) from defaultDimensionView
         where   defaultDimensionView.defaultDimension   == projInvoiceItem.DefaultDimension;

        if(defaultDimensionView.ChannelKey != 0)
        {
            select firstOnly Value, Description from channelView
                where   channelView.RecId               == defaultDimensionView.ChannelKey;

            partyPayableTmp.ChannelName                 = channelView.Description;
            partyPayableTmp.ChannelId                   = channelView.Value;
        }

        partyPayableTmp.PartyPayableVendorId            = projTable.aegAgencyPayable;
  partyPayableTmp.PartyPayableVendorName = VendTable::find(projTable.AEGAgencyPayable).name();

        partyPayableTmp.PartyPayablePercentage          = markupTrans.Value;

partyPayableTmp.TransactionCurrencyGross  = (projInvoiceItem.Qty * projInvoiceItemDetail.SalesPrice);
        partyPayableTmp.TransactionCurrencyNet          = projInvoiceItemDetail.LineAmount;
        partyPayableTmp.AccountingCurrencyGross         = (partyPayableTmp.TransactionCurrencyGross * (projInvoiceJour.ExchRate/100));
        partyPayableTmp.AccountingCurrencyNet           = (partyPayableTmp.TransactionCurrencyNet * (projInvoiceJour.ExchRate/100));

        partyPayableTmp.TransactionPartyPayableAmount   = markupTrans.CalculatedAmount;

        partyPayableTmp.AccountingPartyPayableAmount    = (partyPayableTmp.TransactionPartyPayableAmount * (projInvoiceJour.ExchRate/100));

        partyPayableTmp.insert();
    }
}




Contract Class




[
DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(PartyPayableUIBuilder))
]
class AEI3rdPartyPayableContract implements SysOperationValidatable
{
    List        chargeCode;
}




[
    DataMemberAttribute('chargeCode'),
    AifCollectionTypeAttribute('chargeCode', Types::String),
    SysOperationLabelAttribute(literalstr("@AEG694"))
]
public List parmChargeCode(List _chargeCode = chargeCode)
{
    chargeCode  = _chargeCode;
    return      chargeCode;
}


public boolean validate()
{
    boolean isValid = true;

    if(chargeCode.empty())
    {
        isValid     = checkFailed('Charge code cannot be blank');
    }

    return isValid;
}




UIBuilder Class



class PartyPayableUIBuilder extends SrsReportDataContractUIBuilder
{
    DialogField     dialogFieldChargeCode;
}


public void build()
{
    PartyPayableContract      contract;

    contract                        = this.dataContractObject() as PartyPayableContract;

    dialogFieldChargeCode           = this.addDialogField(methodStr(PartyPayableContract, parmChargeCode), contract);
}


public void lookupChargeCode(FormStringControl    _control)
{
    Query       query = new Query(queryStr(PartyPayableChargeCodeParm));
    container   cnt;

    SysLookupMultiSelectGrid::lookup(query, _control, _control, cnt);
}


public void postBuild()
{
    PartyPayableContract  contract;

    super();

    contract                    = this.dataContractObject() as PartyPayableContract;

    dialogFieldChargeCode       = this.bindInfo().getDialogField(contract,
                                                                    methodStr(PartyPayableContract, parmChargeCode));

    dialogFieldChargeCode.registerOverrideMethod(methodStr(FormStringControl, lookup),
                                            methodStr(PartyPayableUIBuilder, lookupChargeCode), this);

    if (dialogFieldChargeCode)
    {
        dialogFieldChargeCode.lookupButton(2);
    }
}


public void postRun()
{
    //super();
}