Advertisement
Guest User

BT AddToListHandoverInvoiceArBackItem

a guest
Jan 21st, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.90 KB | None | 0 0
  1. package org.jleaf.erp.fin.bo.invoicearback;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.jleaf.common.ComboIdConstants;
  8. import org.jleaf.common.CommonExceptionConstants;
  9. import org.jleaf.core.BusinessFunction;
  10. import org.jleaf.core.BusinessTransaction;
  11. import org.jleaf.core.CoreException;
  12. import org.jleaf.core.DefaultBusinessTransaction;
  13. import org.jleaf.core.Dto;
  14. import org.jleaf.core.GeneralConstants;
  15. import org.jleaf.core.annotation.ErrorList;
  16. import org.jleaf.core.annotation.Info;
  17. import org.jleaf.core.annotation.InfoIn;
  18. import org.jleaf.core.annotation.InfoOut;
  19. import org.jleaf.erp.cb.CashBankConstants;
  20. import org.jleaf.erp.fin.ComboIdForSasa;
  21. import org.jleaf.erp.fin.FinanceConstants;
  22. import org.jleaf.erp.fin.FinanceConstantsForSasa;
  23. import org.jleaf.erp.fin.FinanceExceptionConstants;
  24. import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
  25. import org.jleaf.erp.fin.dao.AllocationArCostDao;
  26. import org.jleaf.erp.fin.dao.AllocationArDao;
  27. import org.jleaf.erp.fin.dao.AllocationArInvoiceDao;
  28. import org.jleaf.erp.fin.dao.InvoiceArBalanceDao;
  29. import org.jleaf.erp.fin.dao.InvoiceTaxArBalanceDao;
  30. import org.jleaf.erp.fin.dao.ReceiptArBalanceDao;
  31. import org.jleaf.erp.fin.entity.AllocationAr;
  32. import org.jleaf.erp.fin.entity.AllocationArCost;
  33. import org.jleaf.erp.fin.entity.AllocationArInvoice;
  34. import org.jleaf.erp.fin.entity.InvoiceArBalance;
  35. import org.jleaf.erp.fin.entity.InvoiceTaxArBalance;
  36. import org.jleaf.erp.fin.entity.ReceiptArBalance;
  37. import org.jleaf.erp.fin.invoicearbalancehandover.FindInvoiceArBalanceHandoverForSasaByIndex;
  38. import org.jleaf.erp.master.MasterConstants;
  39. import org.jleaf.erp.master.MasterExceptionConstants;
  40. //import org.jleaf.erp.sls.SalesExceptionConstantsForKtmt;
  41. import org.jleaf.erp.fin.entity.InvoiceArBalanceHandoverForSasa;
  42. import org.jleaf.erp.fin.dao.InvoiceArBalanceHandoverForSasaDao;
  43. import org.jleaf.erp.fin.entity.HandoverInvoiceAr;
  44. import org.jleaf.erp.fin.entity.HandoverInvoiceArItem;
  45. import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
  46. import org.jleaf.erp.fin.dao.HandoverInvoiceArItemDao;
  47. import org.jleaf.util.Calc;
  48. import org.jleaf.util.DateUtil;
  49. import org.jleaf.util.DtoUtil;
  50. import org.jleaf.util.GsonUtil;
  51. import org.jleaf.util.ValidationUtil;
  52. import org.jleaf.validator.CommonBusinessValidator;
  53. import org.slf4j.Logger;
  54. import org.slf4j.LoggerFactory;
  55. import org.springframework.beans.factory.annotation.Autowired;
  56. import org.springframework.beans.factory.annotation.Qualifier;
  57. import org.springframework.stereotype.Service;
  58.  
  59.  
  60.  
  61. /**
  62. * Add To ListHandover Invoice Ar Back Item
  63. *
  64. * @author Deo, Jan 17, 2020
  65. * @since 1.0.0
  66. * @version 1.0.0
  67. */
  68. //@formatter:off
  69. @Service
  70. @InfoIn(value = {
  71.  
  72. @Info(name = "tenantLoginId", description = "Tenant Login id", type = Long.class),
  73. @Info(name = "userLoginId", description = "User Login id", type = Long.class),
  74. @Info(name = "roleLoginId", description = "Role Login id", type = Long.class),
  75. @Info(name = "datetime", description = "Datetime", type = String.class),
  76.  
  77. @Info(name = "handoverInvoiceArId", description = "Handover Invoice Ar id", type = Long.class),
  78. @Info(name = "versionHeader", description = "Version Header", type = Long.class),
  79. @Info(name = "handoverInvoiceArItemList", description = "Handover Invoice Ar Item List", type = List.class)
  80.  
  81. })
  82. @InfoOut(value = {
  83.  
  84. @Info(name = "id", description = "Allocation Cash Bank In Id", type = Long.class),
  85. @Info(name = "tenantId", description = "tenantId", type = Long.class),
  86. @Info(name = "ouId", description = "ou Id", type = Long.class),
  87. @Info(name = "docTypeId", description = "doc Type Id", type = Long.class),
  88. @Info(name = "docNo", description = "doc No", type = String.class),
  89. @Info(name = "docDate", description = "doc Date", type = String.class),
  90. @Info(name = "extDocNo", description = "docDate", type = String.class),
  91. @Info(name = "extDocDate", description = "ext Doc No", type = String.class),
  92. @Info(name = "refId", description = "ref Id", type = Long.class),
  93. @Info(name = "refDocTypeId", description = "ref Doc Type Id", type = Long.class),
  94.  
  95. @Info(name = "employeeId", description = "employee Id", type = Long.class),
  96. @Info(name = "estimateReturnDate", description = "estimate Return Date", type = String.class),
  97. @Info(name = "remark", description = "remark", type = String.class),
  98. @Info(name = "statusDoc", description = "status Doc", type = String.class),
  99. @Info(name = "workflowStatus", description = "workflow Status", type = String.class),
  100. @Info(name = "createUserId", description = "create User Id", type = Long.class),
  101. @Info(name = "createDateTime", description = "create Date Time", type = String.class),
  102. @Info(name = "updateUserId", description = "update User Id", type = String.class),
  103. @Info(name = "updateDateTime", description = "update Date Time", type = String.class),
  104. @Info(name = "version", description = "version", type = Long.class)
  105. })
  106. @ErrorList(errorKeys ={
  107. })
  108. //@formatter:off
  109.  
  110.  
  111.  
  112. public class AddToListHandoverInvoiceArBackItem extends DefaultBusinessTransaction implements BusinessTransaction {
  113. private static final Logger log = LoggerFactory.getLogger(AddToListHandoverInvoiceArBackItem.class);
  114.  
  115. @Override
  116. public String getDescription() {
  117. return "Add to List Handover Invoice Ar Back Item";
  118. }
  119.  
  120. @Autowired
  121. HandoverInvoiceArDao handoverInvoiceArDao;
  122.  
  123. @Autowired
  124. HandoverInvoiceArItemDao handoverInvoiceArItemDao;
  125.  
  126. @Autowired
  127. @Qualifier("valComboValueByCode")
  128. private BusinessFunction valComboValueByCode;
  129.  
  130. @Autowired
  131. @Qualifier("isHandoverInvoiceArByIndex")
  132. private BusinessFunction isHandoverInvoiceArByIndex;
  133.  
  134. @Autowired
  135. @Qualifier("valTenantLoginCanUse")
  136. private BusinessFunction valTenantLoginCanUse;
  137.  
  138. @Autowired
  139. @Qualifier("findHandoverInvoiceArById")
  140. private BusinessFunction findHandoverInvoiceArById;
  141.  
  142. @Autowired
  143. @Qualifier("findInvoiceArBalanceHandoverForSasaByIndex")
  144. private BusinessFunction findInvoiceArBalanceHandoverForSasaByIndex;
  145.  
  146.  
  147.  
  148.  
  149. @SuppressWarnings("unchecked")
  150. @Override
  151. public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  152.  
  153. ValidationUtil.valNumeric(inputDto, "tenantLoginId");
  154. ValidationUtil.valNumeric(inputDto, "userLoginId");
  155. ValidationUtil.valNumeric(inputDto, "roleLoginId");
  156. ValidationUtil.valDatetime(inputDto, "datetime");
  157.  
  158. ValidationUtil.valNumeric(inputDto, "handoverInvoiceArId");
  159. ValidationUtil.valNumeric(inputDto, "versionHeader");
  160. ValidationUtil.valDtoContainsKey(inputDto, "handoverInvoiceArItemList");
  161.  
  162. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  163. Long userLoginId = inputDto.getLong("userLoginId");
  164. Long roleLoginId = inputDto.getLong("roleLoginId");
  165. String datetime = inputDto.getString("datetime");
  166.  
  167. Long handoverInvoiceArId = inputDto.getLong("handoverInvoiceArId");
  168. Long versionHeader = inputDto.getLong("versionHeader");
  169. List<Dto> handoverInvoiceArItemList = inputDto.getList("handoverInvoiceArItemList");
  170.  
  171. //========= Validation tenant login id can be use =========
  172. Dto loginDto = new Dto();
  173. loginDto.put("tenantLoginId", tenantLoginId);
  174. loginDto.put("userLoginId", userLoginId);
  175. loginDto.put("roleLoginId", roleLoginId);
  176. valTenantLoginCanUse.execute(loginDto);
  177.  
  178. Dto handoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", handoverInvoiceArId));
  179. //========= Validation tenantId nya sama dengan tenant login id =========
  180. if (!tenantLoginId.equals(handoverInvoiceArDto.getLong("tenantId"))) {
  181. throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Handover Invoice Ar Back Item");
  182. }
  183.  
  184. //========= Validation statusDoc masih draft =========
  185. if(!FinanceConstantsForSasa.DRAFT_TRANSACTION.equals(handoverInvoiceArDto.get("statusDoc"))){
  186. throw new CoreException(FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT);
  187. }
  188.  
  189. //========= Validation version harus uptodate =========
  190. if (!handoverInvoiceArDto.getLong("version").equals(versionHeader)) {
  191. throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back Item");
  192. }
  193.  
  194. List<Dto> resultHandoverInvoiceArBackItemList = new ArrayList<Dto>();
  195.  
  196. List<Dto> failList = new ArrayList<Dto>();
  197.  
  198. if(handoverInvoiceArItemList != null && handoverInvoiceArItemList.size() > 0){
  199. for(Dto HandoverInvoiceArBackItemDto : handoverInvoiceArItemList){
  200. try{
  201. ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"refId");
  202. ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"refDocTypeId");
  203. ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"partnerId");
  204. ValidationUtil.valDate(HandoverInvoiceArBackItemDto,"dueDate");
  205. ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"currCode");
  206. ValidationUtil.valNumber(HandoverInvoiceArBackItemDto,"invoiceAmount");
  207. ValidationUtil.valNumber(HandoverInvoiceArBackItemDto,"outstandingAmount");
  208. ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"handoverStatus");
  209. ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"remark");
  210.  
  211. //====================yg dikembalikin error exc===============
  212. Long refId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("refId"));
  213. Long refDocTypeId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("refDocTypeId"));
  214. Long partnerId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("partnerId"));
  215. String dueDate = String.valueOf(HandoverInvoiceArBackItemDto.getString("dueDate"));
  216. String currCode = String.valueOf(HandoverInvoiceArBackItemDto.getString("currCode"));
  217. Double invoiceAmount = Double.valueOf(HandoverInvoiceArBackItemDto.getDouble("invoiceAmount"));
  218. Double outstandingAmount = Double.valueOf(HandoverInvoiceArBackItemDto.getDouble("outstandingAmount"));
  219. String handoverStatus = String.valueOf(HandoverInvoiceArBackItemDto.getString("handoverStatus"));
  220. String remarkItem = String.valueOf(HandoverInvoiceArBackItemDto.getString("remark"));
  221.  
  222. //cek ke data balance serah terima invoice findInvoiceArBalanceHandoverForSasaByIndex data nya harus ada
  223. Dto invoiceArBalanceHandoverDto = new Dto();
  224. invoiceArBalanceHandoverDto.put("invoiceId", refId);
  225. invoiceArBalanceHandoverDto.put("docTypeId", refDocTypeId);
  226. Dto invoiceArBalanceHandoverDtoResult = findInvoiceArBalanceHandoverForSasaByIndex.execute(invoiceArBalanceHandoverDto);
  227.  
  228. //validasi invoice ar nya memang sudah dilakukan serah terima invoice
  229. if(!GeneralConstants.YES.equals(invoiceArBalanceHandoverDtoResult.getString("flgHandover")))
  230. {
  231. throw new CoreException(FinanceExceptionConstantsForSasa.INVOICE_AR_MUST_BE_ALREADY_HANDOVER, "invoiceArBalanceHandover","invoiceId");
  232. }
  233.  
  234. //validasi invoice ar nya belum dan tidak sedang dilakukan serah terima invoice balik di dokumen lain
  235. if(!GeneralConstants.NO.equals(invoiceArBalanceHandoverDtoResult.getString("flgHandoverBack")))
  236. {
  237. throw new CoreException(FinanceExceptionConstantsForSasa.INVOICE_AR_IS_ALREADY_OR_INPROGRESS_CREATED_IN_OTHER_DOC_HANDOVER_INVOICE_AR_BACK, "invoiceArBalanceHandover","invoiceId");
  238. }
  239.  
  240. //validasi employee_id atas invoice ar yang ada di fi_invoice_ar_balance_handover_for_sasa sama dengan employee_id atas data header serah terima invoice balik
  241. if(!handoverInvoiceArDto.getString("employeeId").equals(invoiceArBalanceHandoverDtoResult.getString("employeeId")))
  242. {
  243. throw new CoreException(FinanceExceptionConstantsForSasa.EMPLOYEE_ID_DOESNT_MATCH_WITH_INVOICE_AR_EMPLOYEE, "employeeId");
  244. }
  245.  
  246. //cek status nya harus ada di combo value handover status
  247. Dto comboValueHandoverStatusDto = new Dto();
  248. comboValueHandoverStatusDto.put("comboId", FinanceConstantsForSasa.HANDOVER_STATUS); //combo handover statu
  249. comboValueHandoverStatusDto.put("code", handoverStatus); //status
  250. comboValueHandoverStatusDto.put("varName", "Handover Status");
  251. valComboValueByCode.execute(comboValueHandoverStatusDto);
  252.  
  253. //======== Validation Unique Index isHandoverInvoiceArByIndex =======
  254. Dto uniqueIndexDto = new Dto();
  255. uniqueIndexDto.put("tenantId", tenantLoginId);
  256. uniqueIndexDto.put("ouId", handoverInvoiceArDto.getLong("ouId"));
  257. uniqueIndexDto.put("docTypeId", FinanceConstantsForSasa.DOCUMENT_TYPE_HANDOVER_INVOICE_AR_BACK);
  258. uniqueIndexDto.put("docNo", handoverInvoiceArDto.getLong("docNo"));
  259. uniqueIndexDto.put("docDate", handoverInvoiceArDto.getLong("docDate"));
  260. isHandoverInvoiceArByIndex.execute(uniqueIndexDto);
  261.  
  262. }
  263. catch (CoreException e)
  264. {
  265. log.error("add to list handover invoice ar back item error: " + e.getMessage(), e);
  266.  
  267. HandoverInvoiceArBackItemDto.put("errorKey", e.getErrorKey());
  268. List<Object> argsList = new ArrayList<Object>();
  269. if (e.getParamValues() != null && e.getParamValues().length > 0) for (Object paramValue : e.getParamValues()) {
  270. argsList.add(paramValue);
  271. }
  272. HandoverInvoiceArBackItemDto.put("args", argsList);
  273.  
  274. failList.add(HandoverInvoiceArBackItemDto);
  275. }
  276. }
  277. } else {
  278. throw new CoreException(FinanceExceptionConstantsForSasa.HANDOVER_INVOICE_AR_BACK_MUST_HAVE_AT_LEAST_ONE_ITEM);
  279. }
  280.  
  281.  
  282. Dto handoverInvoiceArBackItemDto = new Dto();
  283. handoverInvoiceArBackItemDto.put("handoverInvoiceArId", handoverInvoiceArId);
  284. handoverInvoiceArBackItemDto.put("tenantId", tenantLoginId);
  285. handoverInvoiceArBackItemDto.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
  286. handoverInvoiceArBackItemDto.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
  287. handoverInvoiceArBackItemDto.put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
  288. handoverInvoiceArBackItemDto.put("dueDate", GeneralConstants.EMPTY_VALUE);
  289. handoverInvoiceArBackItemDto.put("currCode", GeneralConstants.EMPTY_VALUE);
  290. handoverInvoiceArBackItemDto.put("invoiceAmount", GeneralConstants.NULL_REF_VALUE_LONG);
  291. handoverInvoiceArBackItemDto.put("outstandingAmount", GeneralConstants.NULL_REF_VALUE_LONG);
  292. handoverInvoiceArBackItemDto.put("handoverStatus", GeneralConstants.EMPTY_VALUE);
  293. handoverInvoiceArBackItemDto.put("remark", GeneralConstants.EMPTY_VALUE);
  294.  
  295. this.prepareInsertAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
  296. this.prepareUpdateAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
  297.  
  298. log.debug("resulthandoverInvoiceArBackItemDto>>>"+handoverInvoiceArBackItemDto);
  299. log.debug("resultHandoverInvoiceArBackItemList>>>"+resultHandoverInvoiceArBackItemList);
  300.  
  301.  
  302. inputDto.put("resultHandoverInvoiceArBackItemDto", handoverInvoiceArBackItemDto);
  303. inputDto.put("resultHandoverInvoiceArBackItemList", resultHandoverInvoiceArBackItemList);
  304.  
  305. return null;
  306. }
  307.  
  308.  
  309. // Menambah data item serah terima invoice ar balik di table fi_handover_invoice_ar_item
  310. // Update data header (version nya) di table fi_handover_invoice_ar
  311.  
  312. @SuppressWarnings({ "unchecked" })
  313. @Override
  314. public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  315.  
  316. // add Handover InvoiceAr
  317. HandoverInvoiceAr handoverInvoiceAr = GsonUtil.fromDto(inputDto.getDto("resultHandoverInvoiceArBackItemDto"), HandoverInvoiceAr.class);
  318. handoverInvoiceArDao.persist(handoverInvoiceAr);
  319.  
  320.  
  321. // add Handover InvoiceAr Item
  322. List<Dto> resultHandoverInvoiceArBackItemList = inputDto.getList("resultHandoverInvoiceArBackItemList");
  323. if(resultHandoverInvoiceArBackItemList != null && resultHandoverInvoiceArBackItemList.size() > 0){
  324. for (Dto handoverInvoiceArBackItemDto : resultHandoverInvoiceArBackItemList) {
  325.  
  326. // add Handover InvoiceAr Item
  327. handoverInvoiceArBackItemDto.put("handoverInvoiceArId", handoverInvoiceAr.getId());
  328.  
  329. HandoverInvoiceArItem handoverInvoiceArItem = GsonUtil.fromDto(handoverInvoiceArBackItemDto, HandoverInvoiceArItem.class);
  330. handoverInvoiceArItemDao.persist(handoverInvoiceArItem);
  331. }
  332. }
  333.  
  334.  
  335.  
  336.  
  337. return new Dto(handoverInvoiceAr);
  338. }
  339.  
  340.  
  341.  
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement