Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.sls.bo.tasksales;
- import javax.persistence.Query;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.core.dao.QueryBuilder;
- import org.jleaf.erp.sls.SalesConstants;
- import org.jleaf.erp.sls.dao.AdminProcessVisitPlanDao;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * Get Summary Invoice Visit Plan By Customer
- * @author Danielli, May 14, 2020
- * @version 1.0
- *
- */
- @Service
- @InfoIn(value={
- @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 Login Id", type = Long.class),
- @Info(name = "datetime", description = "Date Time", type = String.class),
- @Info(name = "customerId", description = "Customer Id", type = Long.class),
- @Info(name = "visitDate", description = "Visit Date", type = String.class)
- })
- @InfoOut(value={
- @Info(name = "totalInvoicePayment", description = "Total Invoice Payment",type = Long.class),
- @Info(name = "totalInvoiceExchangedPayment", description = "Total Invoice Exchanged Payment",type = Long.class),
- @Info(name = "totalInvoiceUnexchangedPayment", description = "Total Invoice Unexchanged Payment",type = Long.class),
- @Info(name = "totalInvoiceCancelledPayment", description = "Total Invoice Cancelled Payment",type = Long.class)
- })
- @ErrorList(errorKeys={})
- public class GetSummaryInvoiceVisitPlanByCustomer extends AbstractBusinessFunction implements BusinessFunction {
- private static final Logger log = LoggerFactory.getLogger(GetSummaryInvoiceVisitPlanByCustomer.class);
- @Autowired
- AdminProcessVisitPlanDao adminProcessVisitPlanDao;
- @Override
- public String getDescription() {
- return "mengambil summary invoice customer ketika salesman sedang check in";
- }
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- log.info("INPUT DTO : " + inputDto);
- //validasi
- ValidationUtil.valBlankOrNull(inputDto, "customerId");
- ValidationUtil.valBlankOrNull(inputDto, "visitDate");
- //define input
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- log.info("TENANT LOGIN ID : " + tenantLoginId);
- Long userLoginId = inputDto.getLong("userLoginId");
- log.info("USER LOGIN ID : " + userLoginId);
- Long customerId = inputDto.getLong("customerId");
- log.info("CUSTOMER ID : " + customerId);
- String visitDate = inputDto.getString("visitDate");
- log.info("VISIT DATE : " + visitDate);
- //define query for output
- //get employeeId
- QueryBuilder builderForEmployeeId = new QueryBuilder();
- builderForEmployeeId.add(" SELECT A.partner_id ")
- .add(" FROM ts_user_partner A ")
- .add(" INNER JOIN t_user B on A.user_id = B.user_id ")
- .add(" WHERE A.user_id = :userLoginId AND A.tenant_id = :tenantLoginId ");
- Query queryForEmployeeId = adminProcessVisitPlanDao.createNativeQuery(builderForEmployeeId.toString());
- queryForEmployeeId.setParameter("userLoginId", userLoginId);
- queryForEmployeeId.setParameter("tenantLoginId", tenantLoginId);
- Object objectEmployeeId = queryForEmployeeId.getSingleResult();
- Long employeeId = Long.valueOf(objectEmployeeId.toString());
- log.info("EMPLOYEE ID : " + employeeId);
- //get adminProcessVisitPlanId
- QueryBuilder builderForAdminProcessVisitPlanId = new QueryBuilder();
- builderForAdminProcessVisitPlanId.add(" SELECT admin_process_visit_plan_id ")
- .add(" FROM sl_admin_process_visit_plan ")
- .add(" WHERE employee_id = :employeeId AND :visitDate BETWEEN start_date AND end_date ");
- Query queryForAdminProcessVisitPlanId = adminProcessVisitPlanDao.createNativeQuery(builderForAdminProcessVisitPlanId.toString());
- queryForAdminProcessVisitPlanId.setParameter("employeeId",employeeId);
- queryForAdminProcessVisitPlanId.setParameter("visitDate",visitDate);
- Object objectAdminProcessVisitPlanId = queryForAdminProcessVisitPlanId.getSingleResult();
- Long adminProcessVisitPlanId = Long.valueOf(objectAdminProcessVisitPlanId.toString());
- log.info("ADMIN PROCESS VISIT PLAN ID : "+ adminProcessVisitPlanId);
- //define proses
- //get totalInvoicePayment
- QueryBuilder builderTotalInvoicePayment = new QueryBuilder();
- builderTotalInvoicePayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoicePayment ")
- .add(" FROM sl_invoice_visit_plan A ")
- .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
- .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
- Query queryTotalInvoicePayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoicePayment.toString());
- queryTotalInvoicePayment.setParameter("customerId", customerId);
- queryTotalInvoicePayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
- queryTotalInvoicePayment.setParameter("status", SalesConstants.PAYMENT);
- Object objectTotalInvoicePayment = queryTotalInvoicePayment.getSingleResult();
- Long totalInvoicePayment = Long.valueOf(objectTotalInvoicePayment.toString());
- log.info("TOTAL INVOICE PAYMENT : " + totalInvoicePayment);
- //get totalInvoiceExchangedPayment
- QueryBuilder builderTotalInvoiceExchangedPayment = new QueryBuilder();
- builderTotalInvoiceExchangedPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceExchangedPayment ")
- .add(" FROM sl_invoice_visit_plan A ")
- .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
- .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
- Query queryTotalInvoiceExchangedPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceExchangedPayment.toString());
- queryTotalInvoiceExchangedPayment.setParameter("customerId", customerId);
- queryTotalInvoiceExchangedPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
- queryTotalInvoiceExchangedPayment.setParameter("status", SalesConstants.EXCHANGED_PAYMENT);
- Object objectTotalInvoiceExchangedPayment = queryTotalInvoiceExchangedPayment.getSingleResult();
- Long totalInvoiceExchangedPayment = Long.valueOf(objectTotalInvoiceExchangedPayment.toString());
- log.info("TOTAL INVOICE EXCHANGED PAYMENT : " + totalInvoiceExchangedPayment);
- //get totalInvoiceUnexchangedPayment
- QueryBuilder builderTotalInvoiceUnexchangedPayment = new QueryBuilder();
- builderTotalInvoiceUnexchangedPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceUnexchangedPayment ")
- .add(" FROM sl_invoice_visit_plan A ")
- .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
- .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
- Query queryTotalInvoiceUnexchangedPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceUnexchangedPayment.toString());
- queryTotalInvoiceUnexchangedPayment.setParameter("customerId", customerId);
- queryTotalInvoiceUnexchangedPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
- queryTotalInvoiceUnexchangedPayment.setParameter("status", GeneralConstants.NO);
- Object objectTotalInvoiceUnexchangedPayment = queryTotalInvoiceUnexchangedPayment.getSingleResult();
- Long totalInvoiceUnexchangedPayment = Long.valueOf(objectTotalInvoiceUnexchangedPayment.toString());
- log.info("TOTAL INVOICE UNEXCHANGED PAYMENT : " + totalInvoiceUnexchangedPayment);
- //get totalInvoiceCancelledPayment
- QueryBuilder builderTotalInvoiceCancelledPayment = new QueryBuilder();
- builderTotalInvoiceCancelledPayment.add(" SELECT COALESCE(COUNT(1),0) AS totalInvoiceCancelledPayment ")
- .add(" FROM sl_invoice_visit_plan A ")
- .add(" INNER JOIN sl_admin_process_visit_plan B ON A.admin_process_visit_plan_id = B.admin_process_visit_plan_id ")
- .add(" WHERE A.customer_id = :customerId AND A.admin_process_visit_plan_id = :adminProcessVisitPlanId AND A.status = :status");
- Query queryTotalInvoiceCancelledPayment = adminProcessVisitPlanDao.createNativeQuery(builderTotalInvoiceCancelledPayment.toString());
- queryTotalInvoiceCancelledPayment.setParameter("customerId", customerId);
- queryTotalInvoiceCancelledPayment.setParameter("adminProcessVisitPlanId", adminProcessVisitPlanId);
- queryTotalInvoiceCancelledPayment.setParameter("status", SalesConstants.CANCELED_TRANSACTION);
- Object objectTotalInvoiceCancelledPayment = queryTotalInvoiceCancelledPayment.getSingleResult();
- Long totalInvoiceCancelledPayment = Long.valueOf(objectTotalInvoiceCancelledPayment.toString());
- log.info("TOTAL INVOICE CANCELLED PAYMENT : " + totalInvoiceCancelledPayment);
- //define output
- Dto outputDto = new Dto();
- outputDto.put("totalInvoicePayment", totalInvoicePayment);
- outputDto.put("totalInvoiceExchangedPayment", totalInvoiceExchangedPayment);
- outputDto.put("totalInvoiceUnexchangedPayment", totalInvoiceUnexchangedPayment);
- outputDto.put("totalInvoiceCancelledPayment", totalInvoiceCancelledPayment);
- log.info(" OUTPUT DTO : " + outputDto);
- return outputDto;
- }
- }
Add Comment
Please, Sign In to add comment