Advertisement
Guest User

BT UpdateHandoverInvoiceARBackWorkflowStatus

a guest
Jan 23rd, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. package org.jleaf.erp.fin.bo.invoicear;
  2.  
  3.  
  4. import org.jleaf.common.CommonExceptionConstants;
  5. import org.jleaf.core.BusinessFunction;
  6. import org.jleaf.core.BusinessTransaction;
  7. import org.jleaf.core.CoreException;
  8. import org.jleaf.core.DefaultBusinessTransaction;
  9. import org.jleaf.core.Dto;
  10. import org.jleaf.core.annotation.Info;
  11. import org.jleaf.core.annotation.InfoIn;
  12. import org.jleaf.erp.fin.FinanceConstantsForSasa;
  13. import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
  14. import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
  15. import org.jleaf.erp.fin.entity.HandoverInvoiceAr;
  16. import org.jleaf.util.GsonUtil;
  17. import org.jleaf.util.ValidationUtil;
  18. import org.jleaf.workflow.core.DefaultConstants;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.beans.factory.annotation.Qualifier;
  23. import org.springframework.stereotype.Service;
  24.  
  25. //@formatter:off
  26. @Service
  27. @InfoIn(value = {
  28. @Info(name = "id", description = "Handover Invoice Ar back id", type = Long.class),
  29. @Info(name = "workflowStatus", description = "doc status", type = String.class),
  30. @Info(name = "tenantLoginId", description = "tenant login id", type = Long.class),
  31. @Info(name = "userLoginId", description = "user login id", type = Long.class),
  32. @Info(name = "roleLoginId", description = "role user login id", type = Long.class),
  33. @Info(name = "datetime", description = "process date time", type = String.class),
  34. @Info(name = "version", description = "version", type = Long.class)})
  35. public class UpdateHandoverInvoiceARBackWorkflowStatus extends DefaultBusinessTransaction implements BusinessTransaction {
  36.  
  37. private static Logger log = LoggerFactory.getLogger(UpdateHandoverInvoiceARBackWorkflowStatus.class);
  38.  
  39. @Autowired
  40. HandoverInvoiceArDao handoverInvoiceArDao;
  41.  
  42. @Autowired
  43. @Qualifier("findHandoverInvoiceArById")
  44. BusinessFunction findHandoverInvoiceArById;
  45.  
  46. @Autowired
  47. @Qualifier("valTenantLoginCanUse")
  48. BusinessFunction valTenantLoginCanUse;
  49.  
  50. @Override
  51. public String getDescription() {
  52. return "Handover invoice ar workflow status";
  53. }
  54.  
  55. @Override
  56. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  57. // Validation
  58. ValidationUtil.valDtoContainsKey(inputDto, "id");
  59. ValidationUtil.valBlankOrNull(inputDto, "workflowStatus");
  60.  
  61. // Get variables
  62. Long docId = inputDto.getLong("id");
  63. String workflowStatus = inputDto.getString("workflowStatus");
  64. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  65. Long roleLoginId = inputDto.getLong("roleLoginId");
  66. Long userLoginId = inputDto.getLong("userLoginId");
  67. String datetime = inputDto.getString("datetime");
  68. Long version = inputDto.getLong("version");
  69.  
  70. // Validation tenant login id is not SUPER ADMIN
  71. Dto tenantLoginCanUseDto = new Dto();
  72. tenantLoginCanUseDto.put("tenantLoginId", tenantLoginId);
  73. tenantLoginCanUseDto.put("roleLoginId", roleLoginId);
  74. tenantLoginCanUseDto.put("userLoginId", userLoginId);
  75. valTenantLoginCanUse.execute(tenantLoginCanUseDto);
  76.  
  77. // Get original Handover Invoice Ar
  78. Dto originalHandoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", docId));
  79.  
  80.  
  81. // validate version
  82. if (!originalHandoverInvoiceArDto.getLong("tenantId").equals(inputDto.getLong("tenantLoginId"))) {
  83. throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Handover Invoice Ar");
  84. }
  85.  
  86. originalHandoverInvoiceArDto.put("workflowStatus", workflowStatus);
  87. if (DefaultConstants.STATE_DRAFT.equals(workflowStatus)) {
  88. originalHandoverInvoiceArDto.put("statusDoc", FinanceConstantsForSasa.DRAFT_TRANSACTION);
  89. } else if (DefaultConstants.STATE_REJECTED.equals(workflowStatus)) {
  90. originalHandoverInvoiceArDto.put("statusDoc", FinanceConstantsForSasa.CANCELED_TRANSACTION);
  91. }
  92. this.prepareUpdateAudit(originalHandoverInvoiceArDto, userLoginId, datetime);
  93.  
  94. originalHandoverInvoiceArDto.put("version", version);
  95.  
  96. inputDto.put("docDto", originalHandoverInvoiceArDto);
  97.  
  98. return null;
  99. }
  100.  
  101. @Override
  102. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  103. // Prepare variables
  104. Dto docDto = inputDto.getDto("docDto");
  105.  
  106. // Update data leave form
  107. HandoverInvoiceAr document = GsonUtil.fromDto(docDto, HandoverInvoiceAr.class);
  108. document = handoverInvoiceArDao.merge(docDto.getLong("id"), document);
  109.  
  110. return new Dto(document);
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement