1DanielLee9

GetSummaryInvoiceVisitPlanByCustomer

May 14th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. package org.jleaf.erp.sls.bo.tasksales;
  2.  
  3. import javax.persistence.Query;
  4.  
  5. import org.jleaf.core.AbstractBusinessFunction;
  6. import org.jleaf.core.BusinessFunction;
  7. import org.jleaf.core.Dto;
  8. import org.jleaf.core.GeneralConstants;
  9. import org.jleaf.core.annotation.ErrorList;
  10. import org.jleaf.core.annotation.Info;
  11. import org.jleaf.core.annotation.InfoIn;
  12. import org.jleaf.core.annotation.InfoOut;
  13. import org.jleaf.core.dao.QueryBuilder;
  14. import org.jleaf.erp.sls.SalesConstants;
  15. import org.jleaf.erp.sls.dao.AdminProcessVisitPlanDao;
  16. import org.jleaf.util.ValidationUtil;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21.  
  22.  
  23. /**
  24. * Get Summary Invoice Visit Plan By Customer
  25. * @author Danielli, May 14, 2020
  26. * @version 1.0
  27. *
  28. */
  29.  
  30. @Service
  31. @InfoIn(value={
  32. @Info(name = "tenantLoginId", description = "Tenant Login Id", type = Long.class),
  33. @Info(name = "userLoginId", description = "User Login Id",type = Long.class),
  34. @Info(name = "roleLoginId", description = "Role Login Id", type = Long.class),
  35. @Info(name = "datetime", description = "Date Time", type = String.class),
  36.  
  37. @Info(name = "customerId", description = "Customer Id", type = Long.class),
  38. @Info(name = "visitDate", description = "Visit Date", type = String.class)
  39. })
  40. @InfoOut(value={
  41. @Info(name = "totalInvoicePayment", description = "Total Invoice Payment",type = Long.class),
  42. @Info(name = "totalInvoiceExchangedPayment", description = "Total Invoice Exchanged Payment",type = Long.class),
  43. @Info(name = "totalInvoiceUnexchangedPayment", description = "Total Invoice Unexchanged Payment",type = Long.class),
  44. @Info(name = "totalInvoiceCancelledPayment", description = "Total Invoice Cancelled Payment",type = Long.class)
  45. })
  46. @ErrorList(errorKeys={})
  47.  
  48. public class GetSummaryInvoiceVisitPlanByCustomer extends AbstractBusinessFunction implements BusinessFunction {
  49. private static final Logger log = LoggerFactory.getLogger(GetSummaryInvoiceVisitPlanByCustomer.class);
  50.  
  51. @Autowired
  52. AdminProcessVisitPlanDao adminProcessVisitPlanDao;
  53.  
  54. @Override
  55. public String getDescription() {
  56. return "mengambil summary invoice customer ketika salesman sedang check in";
  57. }
  58.  
  59. @Override
  60. public Dto execute(Dto inputDto) throws Exception {
  61. log.info("INPUT DTO : " + inputDto);
  62. //validasi
  63. ValidationUtil.valBlankOrNull(inputDto, "customerId");
  64. ValidationUtil.valBlankOrNull(inputDto, "visitDate");
  65. //define input
  66. Long tenantLoginId = inputDto.getLong("tenantLoginId");
  67. log.info("TENANT LOGIN ID : " + tenantLoginId);
  68. Long userLoginId = inputDto.getLong("userLoginId");
  69. log.info("USER LOGIN ID : " + userLoginId);
  70. Long customerId = inputDto.getLong("customerId");
  71. log.info("CUSTOMER ID : " + customerId);
  72. String visitDate = inputDto.getString("visitDate");
  73. log.info("VISIT DATE : " + visitDate);
  74.  
  75. //define query for output
  76. //get employeeId
  77. QueryBuilder builderForEmployeeId = new QueryBuilder();
  78. builderForEmployeeId.add(" SELECT A.partner_id ")
  79. .add(" FROM ts_user_partner A ")
  80. .add(" INNER JOIN t_user B on A.user_id = B.user_id ")
  81. .add(" WHERE A.user_id = :userLoginId AND A.tenant_id = :tenantLoginId ");
  82. Query queryForEmployeeId = adminProcessVisitPlanDao.createNativeQuery(builderForEmployeeId.toString());
  83. queryForEmployeeId.setParameter("userLoginId", userLoginId);
  84. queryForEmployeeId.setParameter("tenantLoginId", tenantLoginId);
  85.  
  86. Object objectEmployeeId = queryForEmployeeId.getSingleResult();
  87. Long employeeId = Long.valueOf(objectEmployeeId.toString());
  88. log.info("EMPLOYEE ID : " + employeeId);
  89. //get adminProcessVisitPlanId
  90. QueryBuilder builderForAdminProcessVisitPlanId = new QueryBuilder();
  91. builderForAdminProcessVisitPlanId.add(" SELECT admin_process_visit_plan_id ")
  92. .add(" FROM sl_admin_process_visit_plan ")
  93. .add(" WHERE employee_id = :employeeId AND :visitDate BETWEEN start_date AND end_date ");
  94. Query queryForAdminProcessVisitPlanId = adminProcessVisitPlanDao.createNativeQuery(builderForAdminProcessVisitPlanId.toString());
  95. queryForAdminProcessVisitPlanId.setParameter("employeeId",employeeId);
  96. queryForAdminProcessVisitPlanId.setParameter("visitDate",visitDate);
  97.  
  98. Object objectAdminProcessVisitPlanId = queryForAdminProcessVisitPlanId.getSingleResult();
  99. Long adminProcessVisitPlanId = Long.valueOf(objectAdminProcessVisitPlanId.toString());
  100. log.info("ADMIN PROCESS VISIT PLAN ID : "+ adminProcessVisitPlanId);
  101.  
  102. //define proses
  103. //get totalInvoicePayment
  104. QueryBuilder builderTotalInvoicePayment = new QueryBuilder();
  105. builderTotalInvoicePayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoicePayment ")
  106. .add(" FROM sl_invoice_visit_plan A ")
  107. .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
  108. .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
  109.  
  110. Query queryTotalInvoicePayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoicePayment.toString());
  111.  
  112. queryTotalInvoicePayment.setParameter("customerId", customerId);
  113. queryTotalInvoicePayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
  114. queryTotalInvoicePayment.setParameter("status", SalesConstants.PAYMENT);
  115.  
  116. Object objectTotalInvoicePayment = queryTotalInvoicePayment.getSingleResult();
  117. Long totalInvoicePayment = Long.valueOf(objectTotalInvoicePayment.toString());
  118. log.info("TOTAL INVOICE PAYMENT : " + totalInvoicePayment);
  119. //get totalInvoiceExchangedPayment
  120. QueryBuilder builderTotalInvoiceExchangedPayment = new QueryBuilder();
  121. builderTotalInvoiceExchangedPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceExchangedPayment ")
  122. .add(" FROM sl_invoice_visit_plan A ")
  123. .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
  124. .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
  125.  
  126. Query queryTotalInvoiceExchangedPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceExchangedPayment.toString());
  127.  
  128. queryTotalInvoiceExchangedPayment.setParameter("customerId", customerId);
  129. queryTotalInvoiceExchangedPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
  130. queryTotalInvoiceExchangedPayment.setParameter("status", SalesConstants.EXCHANGED_PAYMENT);
  131.  
  132. Object objectTotalInvoiceExchangedPayment = queryTotalInvoiceExchangedPayment.getSingleResult();
  133. Long totalInvoiceExchangedPayment = Long.valueOf(objectTotalInvoiceExchangedPayment.toString());
  134. log.info("TOTAL INVOICE EXCHANGED PAYMENT : " + totalInvoiceExchangedPayment);
  135. //get totalInvoiceUnexchangedPayment
  136. QueryBuilder builderTotalInvoiceUnexchangedPayment = new QueryBuilder();
  137. builderTotalInvoiceUnexchangedPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceUnexchangedPayment ")
  138. .add(" FROM sl_invoice_visit_plan A ")
  139. .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
  140. .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
  141.  
  142. Query queryTotalInvoiceUnexchangedPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceUnexchangedPayment.toString());
  143.  
  144. queryTotalInvoiceUnexchangedPayment.setParameter("customerId", customerId);
  145. queryTotalInvoiceUnexchangedPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
  146. queryTotalInvoiceUnexchangedPayment.setParameter("status", GeneralConstants.NO);
  147.  
  148. Object objectTotalInvoiceUnexchangedPayment = queryTotalInvoiceUnexchangedPayment.getSingleResult();
  149. Long totalInvoiceUnexchangedPayment = Long.valueOf(objectTotalInvoiceUnexchangedPayment.toString());
  150. log.info("TOTAL INVOICE UNEXCHANGED PAYMENT : " + totalInvoiceUnexchangedPayment);
  151. //get totalInvoiceCancelledPayment
  152. QueryBuilder builderTotalInvoiceCancelledPayment = new QueryBuilder();
  153. builderTotalInvoiceCancelledPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceCancelledPayment ")
  154. .add(" FROM sl_invoice_visit_plan A ")
  155. .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
  156. .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
  157.  
  158. Query queryTotalInvoiceCancelledPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceCancelledPayment.toString());
  159.  
  160. queryTotalInvoiceCancelledPayment.setParameter("customerId", customerId);
  161. queryTotalInvoiceCancelledPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
  162. queryTotalInvoiceCancelledPayment.setParameter("status", SalesConstants.CANCELED_TRANSACTION);
  163.  
  164. Object objectTotalInvoiceCancelledPayment = queryTotalInvoiceCancelledPayment.getSingleResult();
  165. Long totalInvoiceCancelledPayment = Long.valueOf(objectTotalInvoiceCancelledPayment.toString());
  166. log.info("TOTAL INVOICE CANCELLED PAYMENT : " + totalInvoiceCancelledPayment);
  167. //define output
  168. Dto outputDto = new Dto();
  169. outputDto.put("totalInvoicePayment", totalInvoicePayment);
  170. outputDto.put("totalInvoiceExchangedPayment", totalInvoiceExchangedPayment);
  171. outputDto.put("totalInvoiceUnexchangedPayment", totalInvoiceUnexchangedPayment);
  172. outputDto.put("totalInvoiceCancelledPayment", totalInvoiceCancelledPayment);
  173. log.info(" OUTPUT DTO : " + outputDto);
  174.  
  175. return outputDto;
  176. }
  177.  
  178. }
Add Comment
Please, Sign In to add comment