Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.fin.bo.invoicear;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.DefaultBusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.erp.fin.FinanceConstantsForSasa;
- import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
- import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
- import org.jleaf.erp.fin.entity.HandoverInvoiceAr;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.jleaf.workflow.core.DefaultConstants;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- //@formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "id", description = "Handover Invoice Ar back id", type = Long.class),
- @Info(name = "workflowStatus", description = "doc status", type = String.class),
- @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
- @Info(name = "userLoginId", description = "user login id", type = Long.class),
- @Info(name = "roleLoginId", description = "role user login id", type = Long.class),
- @Info(name = "datetime", description = "process date time", type = String.class),
- @Info(name = "version", description = "version", type = Long.class)})
- public class UpdateHandoverInvoiceARBackWorkflowStatus extends DefaultBusinessTransaction implements BusinessTransaction {
- private static Logger log = LoggerFactory.getLogger(UpdateHandoverInvoiceARBackWorkflowStatus.class);
- @Autowired
- HandoverInvoiceArDao handoverInvoiceArDao;
- @Autowired
- @Qualifier("findHandoverInvoiceArById")
- BusinessFunction findHandoverInvoiceArById;
- @Autowired
- @Qualifier("valTenantLoginCanUse")
- BusinessFunction valTenantLoginCanUse;
- @Override
- public String getDescription() {
- return "Handover invoice ar workflow status";
- }
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- // Validation
- ValidationUtil.valDtoContainsKey(inputDto, "id");
- ValidationUtil.valBlankOrNull(inputDto, "workflowStatus");
- // Get variables
- Long docId = inputDto.getLong("id");
- String workflowStatus = inputDto.getString("workflowStatus");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- Long roleLoginId = inputDto.getLong("roleLoginId");
- Long userLoginId = inputDto.getLong("userLoginId");
- String datetime = inputDto.getString("datetime");
- Long version = inputDto.getLong("version");
- // Validation tenant login id is not SUPER ADMIN
- Dto tenantLoginCanUseDto = new Dto();
- tenantLoginCanUseDto.put("tenantLoginId", tenantLoginId);
- tenantLoginCanUseDto.put("roleLoginId", roleLoginId);
- tenantLoginCanUseDto.put("userLoginId", userLoginId);
- valTenantLoginCanUse.execute(tenantLoginCanUseDto);
- // Get original Handover Invoice Ar
- Dto originalHandoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", docId));
- // validate version
- if (!originalHandoverInvoiceArDto.getLong("tenantId").equals(inputDto.getLong("tenantLoginId"))) {
- throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Handover Invoice Ar");
- }
- originalHandoverInvoiceArDto.put("workflowStatus", workflowStatus);
- if (DefaultConstants.STATE_DRAFT.equals(workflowStatus)) {
- originalHandoverInvoiceArDto.put("statusDoc", FinanceConstantsForSasa.DRAFT_TRANSACTION);
- } else if (DefaultConstants.STATE_REJECTED.equals(workflowStatus)) {
- originalHandoverInvoiceArDto.put("statusDoc", FinanceConstantsForSasa.CANCELED_TRANSACTION);
- }
- this.prepareUpdateAudit(originalHandoverInvoiceArDto, userLoginId, datetime);
- originalHandoverInvoiceArDto.put("version", version);
- inputDto.put("docDto", originalHandoverInvoiceArDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- // Prepare variables
- Dto docDto = inputDto.getDto("docDto");
- // Update data leave form
- HandoverInvoiceAr document = GsonUtil.fromDto(docDto, HandoverInvoiceAr.class);
- document = handoverInvoiceArDao.merge(docDto.getLong("id"), document);
- return new Dto(document);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement