diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_RunMaterialReceiptJasper.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_RunMaterialReceiptJasper.java new file mode 100644 index 000000000..1cba04609 --- /dev/null +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_RunMaterialReceiptJasper.java @@ -0,0 +1,72 @@ +package de.metas.ui.web.handlingunits.process; + +import org.springframework.context.annotation.Profile; + +import de.metas.handlingunits.model.I_M_ReceiptSchedule; +import de.metas.handlingunits.report.HUReceiptScheduleReportExecutor; +import de.metas.process.IProcessPrecondition; +import de.metas.process.IProcessPreconditionsContext; +import de.metas.process.JavaProcess; +import de.metas.process.ProcessPreconditionsResolution; +import de.metas.ui.web.WebRestApiApplication; + +/* + * #%L + * metasfresh-webui-api + * %% + * Copyright (C) 2017 metas GmbH + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +@Profile(value = WebRestApiApplication.PROFILE_Webui) +public class WEBUI_M_ReceiptSchedule_RunMaterialReceiptJasper extends JavaProcess implements IProcessPrecondition +{ + @Override + public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context) + { + if (context.isNoSelection()) + { + return ProcessPreconditionsResolution.rejectBecauseNoSelection(); + } + if (!context.isSingleSelection()) + { + return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection(); + } + + final I_M_ReceiptSchedule receiptSchedule = context.getSelectedModel(I_M_ReceiptSchedule.class); + + // guard against null (might happen if the selected ID is not valid) + if (receiptSchedule == null) + { + return ProcessPreconditionsResolution.rejectBecauseNoSelection(); + } + + return ProcessPreconditionsResolution.accept(); + } + + @Override + protected String doIt() throws Exception + { + final I_M_ReceiptSchedule receiptSchedule = getRecord(I_M_ReceiptSchedule.class); + + HUReceiptScheduleReportExecutor + .get(receiptSchedule) + .executeHUReport(); + + return MSG_OK; + } +}