load( local!pagingInfo: a!pagingInfo( startIndex: 1, batchSize: - 1 ), local!modules: rule!ICAMS_getDealModuleViewByDealIdAndActiveFlag( dealId: ri!dealId, pagingInfo: a!pagingInfo( 1, - 1 ), activeFlag: true, selection: rule!ICAMS_querySelectionForInitiatePurchaseOrder() ), local!approvalEvents: rule!ICAMS_getApprovalEventsByDealIdAndActiveFlag( dealId: ri!dealId, activeFlag: true ), local!updatedModules, local!sapResult, a!formLayout( label: "Initiate Purchase Process", firstColumnContents: { rule!ICAMS_taskHeader( dealId: ri!dealId ), rule!ICAMS_supplierSection(dealId: ri!dealId), a!sectionLayout( firstColumnContents: { a!richTextDisplayField( label: "Initiate Purchase Checklist", value: { a!richTextBulletedList( items: { a!richTextListItem( text: "Please Complete the Following", nestedList: a!richTextBulletedList( items: { "Create Part No using ZMATGEN", "Create Info Record using ME11", "Create Source List Using ZME01", "Create PO using ME21N", "Create RAM using ZRAM001", "Place Purchase Order" } ) ) } ) } ) } ) , a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Update New Part No", value: "Search", saveInto: { a!save( local!sapResult, rule!ICAMS_getModuleSerialDataBySerialNumber( /* needs to be superior serial numbers eventually */ serialNumbers: index(local!modules, "serialNumber", {}) ) ), a!save( local!modules, a!applyComponents( function: rule!iCAMS_insertSAPPartNumbersIntoModule( sapResult: index(local!sapResult.result[1], "T_DATA", {}), module: _ ), array: local!modules ) ) } ), a!buttonWidget( label: "Update PO Info", value: "Search", saveInto: { a!save( local!sapResult, rule!ICAMS_getSAPPurchaseDataForModules( local!modules ) ), a!save( local!modules, a!applyComponents( function: rule!iCAMS_insertSAPPurchseDataIntoModule( sapResult: local!sapResult, module: _ ), array: local!modules ) ) } ) } ), a!gridLayout( totalCount: count( local!modules ), headerCells: { a!gridLayoutHeaderCell(label: "Serial Number"), a!gridLayoutHeaderCell(label: "Platform"), a!gridLayoutHeaderCell(label: "Std Description"), a!gridLayoutHeaderCell(label: "Plant"), a!gridLayoutHeaderCell(label: "SAP Location"), a!gridLayoutHeaderCell(label: "New Part Number"), a!gridLayoutHeaderCell(label: "Info Record"), a!gridLayoutHeaderCell(label: "Purchase Order No."), a!gridLayoutHeaderCell(label: "RAM No."), a!gridLayoutHeaderCell(label: "SAP Purchase Value") }, rows: { if( or( rule!APN_isEmpty( local!modules ), count( local!modules ) < 1 ), {}, a!applyComponents( function: rule!ICAMS_initiatePurchaseProcessGridRow( module: local!modules, index: _ ), array: 1 + enumerate( count( local!modules ) ) ) ) } ), a!sectionLayout( firstColumnContents: { a!textField( value: " ", readOnly: true ) }, secondColumnContents: { a!textField( label: "Total Amount", labelPosition: "ADJACENT", value: sum(index(local!modules, "SAPpurchaseValue", {} )), readOnly: true ) } ), rule!ICAMS_approvalHistorySection(local!approvalEvents) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidgetSubmit( label: cons!ICAMS_USER_ACTION_INITIATE_PAYMENT, style: "PRIMARY", value: cons!ICAMS_USER_ACTION_INITIATE_PAYMENT, saveInto: { ri!userAction, a!save( ri!modules, local!modules ) } ) }, secondaryButtons: { a!buttonWidgetSubmit( label: cons!ICAMS_USER_ACTION_CANCEL, value: cons!ICAMS_USER_ACTION_CANCEL, saveInto: ri!userAction, skipValidation: true ), a!buttonWidgetSubmit( label: cons!ICAMS_USER_ACTION_SAVE_AND_CLOSE, value: cons!ICAMS_USER_ACTION_SAVE_AND_CLOSE, saveInto: { ri!userAction, a!save(ri!modules, local!modules) } ) } ) ) )