Advertisement
Guest User

BT EditHandoverInvoiceArBackItem

a guest
Jan 23rd, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. package org.jleaf.erp.fin.bo.invoicear;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import org.jleaf.common.ComboIdConstants;
  6. import org.jleaf.common.CommonExceptionConstants;
  7. import org.jleaf.core.BusinessFunction;
  8. import org.jleaf.core.BusinessTransaction;
  9. import org.jleaf.core.CoreException;
  10. import org.jleaf.core.DefaultBusinessTransaction;
  11. import org.jleaf.core.Dto;
  12. import org.jleaf.core.annotation.ErrorList;
  13. import org.jleaf.core.annotation.Info;
  14. import org.jleaf.core.annotation.InfoIn;
  15. import org.jleaf.core.annotation.InfoOut;
  16. import org.jleaf.erp.fin.FinanceConstantsForSasa;
  17. import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
  18. import org.jleaf.erp.fin.dao.InvoiceArBalanceHandoverForSasaDao;
  19. import org.jleaf.erp.fin.entity.HandoverInvoiceAr;
  20. import org.jleaf.erp.fin.entity.HandoverInvoiceArItem;
  21. import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
  22. import org.jleaf.erp.fin.dao.HandoverInvoiceArItemDao;
  23. import org.jleaf.util.Calc;
  24. import org.jleaf.util.DateUtil;
  25. import org.jleaf.util.DtoUtil;
  26. import org.jleaf.util.GsonUtil;
  27. import org.jleaf.util.ValidationUtil;
  28. import org.jleaf.validator.CommonBusinessValidator;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Qualifier;
  33. import org.springframework.stereotype.Service;
  34.  
  35.  
  36. /**
  37. * Edit Handover Invoice Ar Back Item
  38. *
  39. * @author Deo, Jan 23, 2020
  40. * @since 1.0.0
  41. * @version 1.0.0
  42. */
  43. //@formatter:off
  44. @Service
  45.  
  46.  
  47. @InfoIn(value = {
  48. @Info(name = "tenantLoginId", description = "Tenant Login id", type = Long.class),
  49. @Info(name = "userLoginId", description = "User Login id", type = Long.class),
  50. @Info(name = "roleLoginId", description = "Role Login id", type = Long.class),
  51. @Info(name = "datetime", description = "Datetime", type = String.class),
  52.  
  53. @Info(name = "id", description = "id", type = Long.class),
  54. @Info(name = "remark", description = "remark", type = String.class),
  55. @Info(name = "version", description = "version", type = Long.class),
  56. @Info(name = "handoverStatus", description = "handover status", type = String.class),
  57. @Info(name = "handoverInvoiceArId", description = "handover invoice ar id", type = Long.class)
  58.  
  59. })
  60. @InfoOut(value = {
  61. @Info(name = "id", description = "id", type = Long.class),
  62. @Info(name = "handoverInvoiceArId", description = "Handover Invoice Ar Id", type = Long.class),
  63. })
  64. @ErrorList(errorKeys ={
  65. CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT,
  66. FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT,
  67. FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE
  68. })
  69. //@formatter:off
  70.  
  71.  
  72. public class EditHandoverInvoiceArBackItem extends DefaultBusinessTransaction implements BusinessTransaction {
  73. private static final Logger log = LoggerFactory.getLogger(EditHandoverInvoiceArBack.class);
  74.  
  75. @Override
  76. public String getDescription() {
  77. return "Edit Handover Invoice Ar Back Item";
  78. }
  79.  
  80. @Autowired
  81. HandoverInvoiceArItemDao handoverInvoiceArItemDao;
  82.  
  83. @Autowired
  84. HandoverInvoiceArDao handoverInvoiceArDao;
  85.  
  86. @Autowired
  87. @Qualifier("valTenantLoginCanUse")
  88. private BusinessFunction valTenantLoginCanUse;
  89.  
  90. @Autowired
  91. @Qualifier("valComboValueByCode")
  92. private BusinessFunction valComboValueByCode;
  93.  
  94. @Autowired
  95. @Qualifier("findHandoverInvoiceArById")
  96. private BusinessFunction findHandoverInvoiceArById;
  97.  
  98. @Autowired
  99. @Qualifier("findHandoverInvoiceArItemByIndex")
  100. private BusinessFunction findHandoverInvoiceArItemByIndex;
  101.  
  102. @Autowired
  103. @Qualifier("getHandoverInvoiceArBackItemListByHandoverInvoiceArId")
  104. private BusinessFunction getHandoverInvoiceArBackItemListByHandoverInvoiceArId;
  105.  
  106. @Autowired
  107. @Qualifier("findHandoverInvoiceArItemById")
  108. private BusinessFunction findHandoverInvoiceArItemById;
  109.  
  110. @SuppressWarnings("unchecked")
  111. @Override
  112. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  113.  
  114. ValidationUtil.valNumeric(inputDto, "tenantLoginId");
  115. ValidationUtil.valNumeric(inputDto, "userLoginId");
  116. ValidationUtil.valNumeric(inputDto, "roleLoginId");
  117. ValidationUtil.valDatetime(inputDto, "datetime");
  118.  
  119. ValidationUtil.valNumeric(inputDto, "id");
  120. ValidationUtil.valDtoContainsKey(inputDto, "remark");
  121. ValidationUtil.valNumeric(inputDto, "version");
  122. ValidationUtil.valBlankOrNull(inputDto, "handoverStatus");
  123. ValidationUtil.valNumeric(inputDto, "handoverInvoiceArId");
  124.  
  125. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  126. Long userLoginId = inputDto.getLong("userLoginId");
  127. Long roleLoginId = inputDto.getLong("roleLoginId");
  128. String datetime = inputDto.getString("datetime");
  129.  
  130. Long id = inputDto.getLong("id");
  131. String remark = inputDto.getString("remark");
  132. Long version = inputDto.getLong("version");
  133. String handoverStatus = inputDto.getString("handoverStatus");
  134. Long handoverInvoiceArId = inputDto.getLong("handoverInvoiceArId");
  135.  
  136.  
  137. //========= Validation tenant login nya bukan superadmin =========
  138. Dto loginDto = new Dto();
  139. loginDto.put("tenantLoginId", tenantLoginId);
  140. loginDto.put("userLoginId", userLoginId);
  141. loginDto.put("roleLoginId", roleLoginId);
  142. valTenantLoginCanUse.execute(loginDto);
  143.  
  144.  
  145. //get data header
  146. Dto handoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", id));
  147.  
  148. //========= Validation tenantId nya sama dengan tenant login id =========
  149. if (!tenantLoginId.equals(handoverInvoiceArDto.getLong("tenantId"))) {
  150. throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Handover Invoice Ar Back");
  151. }
  152.  
  153. //========= Validation statusDoc masih draft =========
  154. if(!FinanceConstantsForSasa.DRAFT_TRANSACTION.equals(handoverInvoiceArDto.get("statusDoc"))){
  155. throw new CoreException(FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT);
  156. }
  157.  
  158. //========= Validation version harus uptodate =========
  159. if (!handoverInvoiceArDto.getLong("version").equals(version)) {
  160. throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back");
  161. }
  162.  
  163.  
  164.  
  165. //=========== get data item ==============
  166.  
  167. Dto handoverInvoiceArItemDto = findHandoverInvoiceArItemById.execute(new Dto().put("id", id));
  168.  
  169. //validasi tenant login id dengan tenant id
  170. if (!tenantLoginId.equals(handoverInvoiceArItemDto.getLong("tenantId"))) {
  171. throw new CoreException(CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT, "Handover Invoice AR Back Item", "Invoice Ar Handover Item");
  172. }
  173.  
  174. if (!handoverInvoiceArItemDto.getLong("version").equals(version)) {
  175. throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back Item");
  176. }
  177.  
  178. //cek status nya harus ada di combo value handover status
  179. Dto comboValueHandoverStatusDto = new Dto();
  180. comboValueHandoverStatusDto.put("comboId", FinanceConstantsForSasa.HANDOVER_STATUS);
  181. comboValueHandoverStatusDto.put("code", handoverInvoiceArItemDto.getString("handoverStatus"));
  182. comboValueHandoverStatusDto.put("varName", "Handover Status");
  183. valComboValueByCode.execute(comboValueHandoverStatusDto);
  184.  
  185.  
  186.  
  187. inputDto.put("handoverInvoiceArItemDto", handoverInvoiceArItemDto);
  188. inputDto.put("handoverInvoiceArDto", handoverInvoiceArDto);
  189.  
  190. this.prepareUpdateAudit(handoverInvoiceArItemDto, userLoginId, datetime);
  191. handoverInvoiceArItemDto.put("status", handoverStatus);
  192. handoverInvoiceArItemDto.put("remark", remark);
  193. handoverInvoiceArItemDto.put("version", version);
  194.  
  195. this.prepareUpdateAudit(handoverInvoiceArDto, userLoginId, datetime);
  196. handoverInvoiceArDto.put("version", version);
  197.  
  198. inputDto.put("handoverInvoiceArDto", handoverInvoiceArDto);
  199. inputDto.put("handoverInvoiceArItemDto", handoverInvoiceArItemDto);
  200.  
  201. return null;
  202. }
  203.  
  204. @Override
  205. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  206.  
  207. Dto handoverInvoiceArDto = inputDto.getDto("handoverInvoiceArDto");
  208. // Update data header
  209. HandoverInvoiceAr handoverInvoiceAr = GsonUtil.fromDto(handoverInvoiceArDto, HandoverInvoiceAr.class);
  210. handoverInvoiceAr = handoverInvoiceArDao.merge(handoverInvoiceArDto.getLong("id"), handoverInvoiceAr);
  211.  
  212. Dto handoverInvoiceArItemDto = inputDto.getDto("handoverInvoiceArItemDto");
  213. // Update data item
  214. HandoverInvoiceArItem handoverInvoiceArItem = GsonUtil.fromDto(handoverInvoiceArItemDto, HandoverInvoiceArItem.class);
  215. handoverInvoiceArItem = handoverInvoiceArItemDao.merge(handoverInvoiceArItemDto.getLong("id"), handoverInvoiceArItem);
  216.  
  217. return new Dto().put("handoverInvoiceArId", handoverInvoiceAr.getId());
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement