Tuesday, May 28, 2019

code to fetch records between time

public real getSalesCount12to1(TransDate _dateInvoice,inventlocationid _location)
{
    CustInvoiceTrans             custinvoiceTrans;
    InventDim                    inventDim;
    InventLocation               inventLocation;
     utcDateTime         rangeStart, rangeEnd;
     TimeOfDay           startTime, endTime;
    int                     i;

 select custinvoiceTrans where custinvoiceTrans.InvoiceDate == _dateInvoice;
    startTime   = str2time("12:00:00 pm");
    endTime     = str2time("1:00:00 pm");
    rangeStart = DateTimeUtil::removeTimeZoneOffset(DateTimeUtil::newDateTime(custInvoiceTrans.InvoiceDate,startTime), DateTimeUtil::getUserPreferredTimeZone());
    rangeEnd   = DateTimeUtil::removeTimeZoneOffset(DateTimeUtil::newDateTime(custInvoiceTrans.InvoiceDate,endTime),DateTimeUtil::getUserPreferredTimeZone());

    while select count(RecId) from custInvoiceTrans group  by InvoiceId
            join inventDim
            where inventDim.inventDimId == custInvoiceTrans.InventDimId
            && inventDim.InventLocationId == _location
             && (custInvoiceTrans.InvoiceDate == _dateInvoice)
            && (custInvoiceTrans.createdDateTime >= rangeStart && custInvoiceTrans.createdDateTime < rangeEnd)
        {
            i++;
        }
        AWD_SaleshourlyTmp.NoOfInvoices12pm = i;//str2int(custInvoiceTrans.InvoiceId);


    return AWD_SaleshourlyTmp.NoOfInvoices12pm;

}

UI Builder Sample code

class SalesItemCategoryUIBuilder extends SrsReportDataContractUIBuilder
{
    DialogField  dialogFromDate,dialogToDate,dialogWarehouseName;
}
//
public void build()
{
    SalesItemCategoryContract rdpcontract = this.dataContractObject();

    dialogFromDate          = this.addDialogField(methodstr(SalesItemCategoryContract, parmFromDate), rdpContract);
    dialogToDate          = this.addDialogField(methodstr(SalesItemCategoryContract, ParmtoDate), rdpContract);
    dialogWarehouseName = this.addDialogField(methodstr(SalesItemCategoryContract, parmLocation), rdpContract);

}
//
public void getFromDialog()
{
    SalesItemCategoryContract contract = this.dataContractObject();
    super();
}
//
 public void initializeFields()
{
    SalesItemCategoryContract rdpcontract = this.dataContractObject();
}
//
public void postRun()
{
    Dialog      dialogLocal = this.dialog();
    DialogField dialogField;
    NoYes   confirm;

    super();
    dialogLocal.dialogForm().formRun().controlMethodOverload(false);
    dialogField  = this.bindInfo().getDialogField(this.dataContractObject(), methodstr(SalesItemCategoryContract, parmLocation));

    dialogField.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(SalesItemCategoryUIBuilder,  warehouseLookup), this);
    dialogField.lookupButton(FormLookupButton::Always);
}//
private void warehouseLookup(FormStringControl warehouseLookUp)
{
    Query                   query= new Query();
    QueryBuildDataSource    qbds_SalesLocation;
    SysTableLookup          sysTableLookup;
    QueryBuildRange         qbr;
    container cnt;
    ForecastModel           forecastModel;
    ForecastSales           forecastsales;

   if (warehouseLookUp != null)
   {
        // Create an instance of SysTableLookup with
        // the current calling form control.
        sysTableLookup = SysTableLookup::newParameters(tablenum(AWDSalesLocation), warehouseLookUp);
        // Add fields to be shown in the lookup form.

        sysTableLookup.addLookupfield(fieldnum(AWDSalesLocation, warehousename), false);
        sysTableLookup.addLookupfield(fieldnum(AWDSalesLocation, Description), false);

        qbds_SalesLocation = query.addDataSource(tableNum(AWDSalesLocation));

        qbr = qbds_SalesLocation.addRange(fieldNum(AWDSalesLocation, warehousename));
        //qbr.value(dialogprojid.value());

        sysTableLookup.parmUseLookupValue(false);
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
   }
}

Sample RDP Code

[
    SRSReportQueryAttribute(queryStr(SalesItemcategoryQ)),

    SRSReportParameterAttribute(classStr(SalesItemCategoryContract))
]
class SalesItemCategoryDP extends SRSReportDataProviderBase
{
    SalesItemCategoryContract contract;
    SalesCategoryTmp         aWD_SalesItemCategoryTmp;


}


//Process Report


public void processReport()
{

     Query                   query;
     QueryRun                queryRun;
     SalesTable              salesTable;
     SalesLine               salesLine;
     EcoResCategory          ecoResCategory;
     Name                    salesLocation;
     TransDate               fromDate, toDate;

     contract              = this.parmDataContract() as AWDSalesItemCategoryContract;
     fromDate              = contract.parmFromDate();
     toDate                = contract.parmToDate();
     salesLocation         = contract.parmLocation();

    query =  this.parmQuery();

    query.dataSourceNo(1).addRange(fieldNum(SalesTable, CreatedDateTime)).value(queryRange(fromDate,toDate));
    query.dataSourceNo(1).addRange(fieldNum(SalesTable,AWDSalesLocation)).value(salesLocation);

    queryRun = new QueryRun(query);

    while(queryRun.next())
    {
        salesTable = queryRun.get(tableNum(salesTable));
        salesLine = queryRun.get(tableNum(salesLine));
        ecoResCategory = queryRun.get(tableNum(ecoResCategory));


        aWD_SalesItemCategoryTmp.ItemCategory = ecoResCategory.Code;
        aWD_SalesItemCategoryTmp.Location     = salesTable.AWDSalesLocation;
        aWD_SalesItemCategoryTmp.Sales        = salesLine.LineAmount;

        aWD_SalesItemCategoryTmp.insert();

    }



}



//getMethod

[
SRSReportDataSetAttribute('AWD_SalesCategoryTmp')
]
public AWD_SalesCategoryTmp getAWD_SalesItemCategory()
{
    select * from aWD_SalesItemCategoryTmp;

    return aWD_SalesItemCategoryTmp;
}