load( local!pagingInfo: a!pagingInfo( startIndex: 1, batchSize: -1, sort: a!sortInfo( field: "Status", ascending: true ) ), local!pagingInfo1: a!pagingInfo( startIndex: 1, batchSize: -1, sort: a!sortInfo( field: "id", ascending: true ) ), local!gridPagingInfo: a!pagingInfo( startIndex: 1, batchSize: 20 ), local!gridDatasubset, local!statusType, local!labFilter, local!viewChosen, local!selectedLab, local!sdate, local!startDate, local!edate, local!endDate, with( local!datasubset1: a!queryEntity( entity: cons!TEST_VIEW, query: a!query( logicalExpression:{ a!queryLogicalExpression( operator:"AND", filters:{ a!queryFilter(field: "LabCode", operator: "<>", value:" "), a!queryFilter(field: "Status", operator: "=", value:"Released"), if(isnull(local!startDate),{},a!queryFilter(field: "releaseTimestamp", operator: ">=", value:local!startDate)), if(isnull(local!endDate),{},a!queryFilter(field: "releaseTimestamp", operator: "<=", value:local!endDate)) } ) }, aggregation: a!queryAggregation(aggregationColumns: { a!queryAggregationColumn(field: "sampleid", aggregationFunction: "COUNT"), a!queryAggregationColumn(field: "LabCode", isGrouping: true), } ), pagingInfo: local!pagingInfo1 ) ), local!labCode1: if(rule!APN_isEmpty(local!datasubset1.data),{},union(local!datasubset1.data.LabCode, cast(typeof(local!datasubset1.data.LabCode), {}))), local!labCodes1:apply(rule!LST2_GetLabNamefromLabCode(_),local!labCode1), local!series1: rule!Generate_P( data: local!datasubset1.data, categoryField:"LabCode", labelField: "LabCode", datapointField: "id", selectedField:local!selectedLab, datasubset:local!datasubset1 ), local!gridDatasubset: a!queryEntity( entity: cons!LST2_ALL_SAMPLES_VIEW, query: a!query( selection: a!querySelection(columns: { a!queryColumn(field: "Lot"), a!queryColumn(field: "LabCode"), a!queryColumn(field: "IsSpecialSample"), a!queryColumn(field: "id"), a!queryColumn(field: "releaseTimestamp"), a!queryColumn(field: "Status") }), logicalExpression:{ a!queryLogicalExpression( operator:"AND", filters:{ a!queryFilter(field: "LabCode", operator: "<>", value:" "), if(isnull(local!viewChosen),{}, {if(local!viewChosen="Current View", a!queryFilter(field: "Status", operator: "not in", value:{"Released","Rejected"}), a!queryFilter(field: "Status", operator: "=", value:"Released")) } ), if(isnull(local!statusType),{},a!queryFilter(field: "Status", operator: "=", value: local!statusType)), if(isnull(local!labFilter),{},a!queryFilter(field: "LabCode", operator: "=", value:local!labFilter)), if(isnull(local!selectedLab),{},a!queryFilter(field: "LabCode", operator: "=", value: local!selectedLab)), if(isnull(local!startDate),{},a!queryFilter(field: "releaseTimestamp", operator: ">=", value:local!startDate)), if(isnull(local!endDate),{},a!queryFilter(field: "releaseTimestamp", operator: "<=", value:local!endDate)) } ) }, pagingInfo: local!gridPagingInfo ) ), a!formLayout( label:"Global Report", firstColumnContents:{ a!sectionLayout( firstColumnContents:{ a!radioButtonField( label: "Choose View", labelPosition: "ADJACENT", choiceLabels: {"Current View", "Released View"}, choiceValues: {"Current View", "Released View"}, value:local!viewChosen, saveInto:{local!viewChosen, a!save(local!labFilter,null), a!save(local!sdate,null), a!save(local!edate,null), a!save(local!startDate,null), a!save(local!endDate,null), a!save(local!statusType,null), a!save(local!selectedLab,null) }, choiceLayout: "STACKED" )} ), if( isnull(local!viewChosen), {}, { if(local!viewChosen="Current View", { }, { a!sectionLayout( firstColumnContents:{ a!dateField( label:"Start Date", labelPosition:"ADJACENT", value:local!sdate, saveInto:{local!sdate, a!save(local!startDate,if(isnull(local!sdate),null,userdatetime(year(local!sdate), month(local!sdate), day(local!sdate)))) } ) }, secondColumnContents:{ a!dateField( label:"End Date", labelPosition:"ADJACENT", value:local!edate, saveInto:{local!edate, a!save(local!endDate,if(isnull(local!edate),null,userdatetime(year(local!edate), month(local!edate), day(local!edate)))) }, validations:if(and(not(isnull(local!sDate)),not(isnull(local!eDate))),if(local!sDate>local!eDate,"End Date cannot be less than Start Date",""),"") )} ), if(or(isnull(local!startDate),isnull(local!endDate)),{}, { if(rule!APN_isEmpty(local!datasubset1.data),{}, { if( isnull(local!selectedLab), a!columnChartField( categories: local!labCodes1, series: local!series1, xAxisTitle: "Lab Code", yAxisTitle: "Count of Lots", stacking: "NORMAL" ), { a!columnChartField( categories: local!labCodes1, series: local!series1, xAxisTitle: "Lab Code", yAxisTitle: "Count of Lots", stacking: "NORMAL" ), a!sectionLayout( firstColumnContents:{ a!gridField( label: rule!LST2_GetLabNamefromLabCode(local!selectedLab) & " Samples", totalCount: local!gridDatasubset.totalCount, columns: { a!gridTextColumn( label: "Lot #", field : "Lot", data: index(local!gridDatasubset.data, "Lot" , {}), alignment: "CENTER" ), a!gridTextColumn( label: "Lab", field :"LabCode", data: apply(rule!GetLabNamefromLabCode(_),index(local!gridDatasubset.data, "LabCode" , {})), alignment: "CENTER" ), a!gridTextColumn( label: "Is Special Sample?", field :"IsSpecialSample", data: index(local!gridDatasubset.data, "IsSpecialSample" , {}), alignment: "CENTER" ), a!gridTextColumn( label: "Release Date", field :"releaseTimestamp", data: index(local!gridDatasubset.data, "releaseTimestamp" , {}), alignment: "CENTER" ) }, value: local!gridPagingInfo, saveInto: local!gridPagingInfo ) } ) } ) } ) } ) } ) } ) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidgetSubmit( label: "Exit", style: "NORMAL", value:"Exit", saveInto: ri!buttonSelected, skipValidation:true ) }, secondaryButtons:{ a!buttonWidgetSubmit( label: "Back", style: "PRIMARY", value:"Back", saveInto: ri!buttonSelected ) } ) ) ) )