Advertisement
samuel025

IsCtgrPartnerExistsByInvoiceId

Aug 16th, 2021
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.sls.bo.invoice;
  2.  
  3. import org.jleaf.core.AbstractBusinessFunction;
  4. import org.jleaf.core.BusinessFunction;
  5. import org.jleaf.core.Dto;
  6. import org.jleaf.core.annotation.ErrorList;
  7. import org.jleaf.core.annotation.Info;
  8. import org.jleaf.core.annotation.InfoIn;
  9. import org.jleaf.core.annotation.InfoOut;
  10. import org.jleaf.core.dao.QueryBuilder;
  11. import org.jleaf.erp.master.entity.CtgrPartner;
  12. import org.jleaf.erp.master.entity.Partner;
  13. import org.jleaf.erp.sls.SalesConstants;
  14. import org.jleaf.erp.sls.dao.SalesInvoiceDao;
  15. import org.jleaf.erp.sls.entity.SalesInvoice;
  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. import javax.persistence.Query;
  23. import java.util.List;
  24.  
  25.  
  26. /**
  27.  * Is InvoiceAdvance exists by id
  28.  * @author Fredi, Sep 19, 2014
  29.  * @version 1.0
  30.  */
  31.  
  32. //@ formatter:off
  33. @Service
  34. @InfoIn(value = {
  35.     @Info(name = "invoiceId", description = "invoiceId", type = Long.class, required = true)
  36. })
  37. @InfoOut(value = {
  38.     @Info(name = "exists", description = "InvoiceAdvance exists", type = Boolean.class, required = true),
  39.  
  40. })
  41. @ErrorList(errorKeys = {
  42.  
  43. })
  44. //@ formatter:on
  45. public class IsCtgrPartnerExistsByInvoiceId extends AbstractBusinessFunction implements BusinessFunction {
  46.     private static Logger log = LoggerFactory.getLogger(IsCtgrPartnerExistsByInvoiceId.class);
  47.    
  48.     @Autowired
  49.     private SalesInvoiceDao salesInvoiceDao;
  50.  
  51.     @Override
  52.     public Dto execute(Dto inputDto) throws Exception {    
  53.         ValidationUtil.valDtoContainsKey(inputDto, "invoiceId");
  54.  
  55.         Dto outputDto = new Dto();
  56.  
  57.         List<Object[]> result = null;
  58.  
  59.         QueryBuilder builder = new QueryBuilder();
  60.         builder.add("SELECT A FROM ")
  61.                 .add("org.jleaf.erp.sls.entity.SalesInvoice")
  62.                 .add(" A INNER JOIN ")
  63.                 .add("org.jleaf.erp.master.entity.Partner")
  64.                 .add(" B ON A.partnerId = B.id INNER JOIN ")
  65.                 .add("org.jleaf.erp.master.entity.CtgrPartner")
  66.                 .add(" C ON B.ctgrPartnerId = C.id  ")
  67.                 .add(" WHERE A.id = :invoiceId ")
  68.                 .add(" AND C.code = :CLIENT_CORPORATE ");
  69.  
  70.         Query q = salesInvoiceDao.createQuery(builder.toString());
  71.         q.setParameter("invoiceId", inputDto.getLong("invoiceId"));
  72.         q.setParameter("CLIENT_CORPORATE", SalesConstants.CLIENT_CORPORATE);
  73.  
  74.         result = q.getResultList();
  75.        
  76.         boolean isExists = false;
  77.         if (result != null && result.size()>0) {
  78.             isExists = true;
  79.         }
  80.        
  81.         outputDto.put("exists", isExists);
  82.         log.debug("outputDtoEmailTemplate >> "+outputDto);
  83.         log.info("outputDtoEmailTemplate >> "+outputDto);
  84.        
  85.         return outputDto;
  86.     }
  87.  
  88.     @Override
  89.     public String getDescription() {
  90.         return "Is Category Parnter exists by Invoice id";
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement