|
|
@@ -1,113 +1,429 @@
|
|
|
package com.uas.platform.b2b.service.impl;
|
|
|
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
-import com.uas.platform.b2b.model.ApcheckField;
|
|
|
+import com.uas.platform.b2b.model.ApcheckKeyWord;
|
|
|
import com.uas.platform.b2b.model.ErpProdIODetail;
|
|
|
import com.uas.platform.b2b.service.ErpProdIODetailService;
|
|
|
import com.uas.platform.b2b.support.SystemSession;
|
|
|
import org.apache.axis.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import javax.persistence.EntityManager;
|
|
|
-import javax.persistence.StoredProcedureQuery;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+/**
|
|
|
+ * 对账单
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ * @date 2018-07-26 15:54
|
|
|
+ */
|
|
|
@Service
|
|
|
public class ErpProdIODetailServiceImpl implements ErpProdIODetailService {
|
|
|
|
|
|
@Autowired
|
|
|
private CommonDao commonDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private EntityManager entityManager;
|
|
|
-
|
|
|
- public List<ErpProdIODetail> findAllApChecks(List<Long> filter) {
|
|
|
- Long enUu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- String sql = "select p.pi_inoutno inOutNo,p.pd_detno detno ,p.pi_class piClass, p.pd_ordercode orderCode, p.pd_orderdetno orderDetno,"
|
|
|
- + " p.pd_prodcode prodCode,p.pr_spec prodSpec, p.pr_title prodTitle,p.pd_qty qty, p.pi_date piDate, p.pd_orderprice orderPrice, p.pi_currency currency, p.pd_taxrate taxrate,p.whname whname, p.pd_ycheckqty yCheckQty,"
|
|
|
- + " p.pd_thischeckqty thisCheckQty, p.custuu custUu, p.custname custName, p.enuu enUu, p.sourceid sourceId, p.pi_sourcetable sourceTable, p.pi_rate rate, p.pi_receivecode receiveCode,"
|
|
|
- + " p.pi_receivename receiveName, p.pd_factory factory, p.sendcode sendcode from erp$prodiodetail p where enuu = ?";
|
|
|
- // 查询近六个月的数据
|
|
|
- sql = sql + " and p.pi_date between adddate(now(), interval -6 month) and now() ";
|
|
|
- Object[] args = new Object[] { enUu };
|
|
|
- if (!CollectionUtils.isEmpty(filter)) {
|
|
|
- String[] str = new String[filter.size()];
|
|
|
- Long[] lon = new Long[filter.size() + 1];
|
|
|
- String s = "";
|
|
|
- for (int i = 0; i < filter.size(); i++) {
|
|
|
- if (i != filter.size() - 1) {
|
|
|
- str[i] = "?,";
|
|
|
- } else {
|
|
|
- str[i] = "?";
|
|
|
- }
|
|
|
- lon[i + 1] = filter.get(i);
|
|
|
- s = s + str[i];
|
|
|
- }
|
|
|
- sql = sql + " and custUu in (" + s + ")";
|
|
|
- lon[0] = enUu;
|
|
|
- args = lon;
|
|
|
- }
|
|
|
- sql = sql + " order by pi_date desc";
|
|
|
- List<ErpProdIODetail> erpProdIODetails = commonDao.query(sql, args, ErpProdIODetail.class);
|
|
|
- return erpProdIODetails;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public List<ErpProdIODetail> findXlsApChecks(List<Long> filter, String keyword, Long fromDate, Long endDate) {
|
|
|
- Long enUu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- String AND = " and ";
|
|
|
- String equal = " = ";
|
|
|
- String quotation = "'";
|
|
|
- StringBuffer con = new StringBuffer(AND).append(ApcheckField._venduu).append(equal).append(enUu);
|
|
|
- StringBuffer prod = new StringBuffer(" where 1=1 ");
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- // 物料名称和规格存在特殊符号,用|做分隔符
|
|
|
- String[] strs = keyword.split("\\|");
|
|
|
- if (strs.length >= 1) {
|
|
|
- prod.append(AND).append(ApcheckField.en_name).append(equal).append(quotation).append(strs[0]).append(quotation);
|
|
|
- }
|
|
|
- if (strs.length >= 2) {
|
|
|
- con.append(AND).append(ApcheckField._receivename).append(equal).append(quotation).append(strs[1]).append(quotation);
|
|
|
- }
|
|
|
- if (strs.length >= 3) {
|
|
|
- con.append(AND).append(ApcheckField._factory).append(equal).append(quotation).append(strs[2]).append(quotation);
|
|
|
- }
|
|
|
- if (strs.length >= 4) {
|
|
|
- prod.append(AND).append(ApcheckField.pr_title).append(equal).append(quotation).append(strs[3]).append(quotation);
|
|
|
- }
|
|
|
- if (strs.length >= 5) {
|
|
|
- prod.append(AND).append(ApcheckField.pr_spec).append(equal).append(quotation).append(strs[4]).append(quotation);
|
|
|
- }
|
|
|
- }
|
|
|
- if (fromDate != null) {
|
|
|
- con.append(AND).append(" DAYFORMDATE(_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
- }
|
|
|
- if (endDate != null) {
|
|
|
- con.append(AND).append(" DAYFORMDATE(_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(filter)) {
|
|
|
- String[] str = new String[filter.size()];
|
|
|
- Long[] lon = new Long[filter.size() + 1];
|
|
|
- String s = "";
|
|
|
- for (int i = 0; i < filter.size(); i++) {
|
|
|
- if (i != filter.size() - 1) {
|
|
|
- str[i] = filter.get(i).toString() + ",";
|
|
|
- } else {
|
|
|
- str[i] = filter.get(i).toString();
|
|
|
- }
|
|
|
- lon[i + 1] = filter.get(i);
|
|
|
- s = s + str[i];
|
|
|
- }
|
|
|
- con.append(AND).append(ApcheckField._enuu).append(" in (").append(s).append(") ");
|
|
|
- lon[0] = enUu;
|
|
|
- }
|
|
|
- StoredProcedureQuery storedProcedureQuery = this.entityManager.createNamedStoredProcedureQuery("findAllApChecks");
|
|
|
- storedProcedureQuery.setParameter("con", con.toString());
|
|
|
- storedProcedureQuery.setParameter("prod", prod.append(" ").toString());
|
|
|
- storedProcedureQuery.execute();
|
|
|
- return storedProcedureQuery.getResultList();
|
|
|
+ public List<ErpProdIODetail> findXlsApChecks(List<Long> filter, ApcheckKeyWord keyword, Long fromDate, Long endDate) {
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ StringBuffer distributes = new StringBuffer();
|
|
|
+ List<ErpProdIODetail> details = new ArrayList<>();
|
|
|
+ if (null != filter) {
|
|
|
+ filter.forEach(uu -> {
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ distributes.append(",");
|
|
|
+ }
|
|
|
+ distributes.append(uu);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 货款调账
|
|
|
+ List<ErpProdIODetail> adjustments = getAdjustments(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 采购验收单
|
|
|
+ List<ErpProdIODetail> saleAccepts = getSaleAccepts(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 采购验退单
|
|
|
+ List<ErpProdIODetail> saleReturns = getSaleReturns(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 客户不良品入库单
|
|
|
+ List<ErpProdIODetail> badIns = getBadIns(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 客户不良品出库单
|
|
|
+ List<ErpProdIODetail> badOuts = getBadOuts(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 委外验收单
|
|
|
+ List<ErpProdIODetail> makeAccepts = getMakeAccepts(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ // 委外验退单
|
|
|
+ List<ErpProdIODetail> makeReturns = getMakeReturns(distributes, keyword, fromDate, endDate, enUU);
|
|
|
+ details.addAll(adjustments);
|
|
|
+ details.addAll(saleAccepts);
|
|
|
+ details.addAll(saleReturns);
|
|
|
+ details.addAll(badIns);
|
|
|
+ details.addAll(badOuts);
|
|
|
+ details.addAll(makeAccepts);
|
|
|
+ details.addAll(makeReturns);
|
|
|
+ return details;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的委外验退单
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getMakeReturns(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select mr_code as inoutno, mr_date as pidate, mr_rate as rate, mr_receivecode as receivecode, " +
|
|
|
+ "mr_receivename as receivename, '客户委外验退单' as piclass, 'make$returnitem' as sourcetable, ma_code as ordercode, 0 as orderdetno, " +
|
|
|
+ "mri_number as detno, (-(1) * mri_qty ) as qty, mri_orderpice as orderprice, mr_currency as currency, mri_taxrate as taxrate, " +
|
|
|
+ "mri_whname as whname, mri_ycheckqty as ycheckqty, pr_code as prodcode, pr_spec as prodspec, pr_title as prodtitle, " +
|
|
|
+ "((-(1) * mri_qty ) - coalesce(mri_ycheckqty, 0)) as thischeckqty, mr_enuu as custuu, mr_venduu as enuu, mri_id as sourceid, " +
|
|
|
+ "mr_sendcode as sendcode, ma_factory as pd_factory, en_name custname from make$return " +
|
|
|
+ "join make$returnitem on mr_id = mri_paid " +
|
|
|
+ "join make$orders on mri_odid = ma_id " +
|
|
|
+ "left join sec$enterprises on mr_enuu = en_uu " +
|
|
|
+ " where mri_qty > abs(coalesce(mri_ycheckqty, 0)) and mr_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and mr_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and ma_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and make$orders.pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and make$orders.pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and mri_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and mr_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(mr_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(mr_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> makeReturns = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return makeReturns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的委外验收单
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getMakeAccepts(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select make$accept.ma_code as inoutno, make$accept.ma_date as pidate, make$accept.ma_rate as rate, " +
|
|
|
+ "ma_receivecode as receivecode, ma_receivename as receivename, '客户委外验收单' as piclass, 'make$acceptitem' as sourcetable, " +
|
|
|
+ "make$orders.ma_code as ordercode, 0 as orderdetno, mai_number as detno, mai_qty as qty, mai_orderpice as orderprice, " +
|
|
|
+ "make$accept.ma_currency as currency, mai_taxrate as taxrate, mai_whname as whname, mai_ycheckqty as ycheckqty, " +
|
|
|
+ "make$orders.pr_code as prodcode, make$orders.pr_spec as prodspec, make$orders.pr_title as prodtitle, " +
|
|
|
+ "(mai_qty - coalesce(mai_ycheckqty, 0)) as thischeckqty, make$accept.ma_enuu as custuu, make$accept.ma_venduu as enuu, " +
|
|
|
+ "mai_id as sourceid, ma_sendcode as sendcode, ma_factory as factory, en_name custname from make$accept " +
|
|
|
+ "join make$acceptitem on make$accept.ma_id = mai_paid " +
|
|
|
+ "join make$orders on mai_odid = make$orders.ma_id " +
|
|
|
+ "left join sec$enterprises on make$accept.ma_enuu = en_uu " +
|
|
|
+ "where mai_qty > coalesce(mai_ycheckqty, 0) and make$accept.ma_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and ma_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and ma_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and make$orders.pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and make$orders.pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and mai_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and make$accept.ma_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(make$accept.ma_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(make$accept.ma_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> makeAccepts = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return makeAccepts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的客户不良品出库单
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getBadOuts(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select po_code as inoutno, po_date as pidate, po_rate as rate, po_receivecode as receivecode, " +
|
|
|
+ "po_receivename as receivename, '客户不良品出库单' as piclass, 'purc$badoutitem' as sourcetable, pu_code as pd_ordercode, " +
|
|
|
+ "purc$orderitems.pd_number as orderdetno, poi_number as detno, (-(1) * poi_qty ) as qty, 0 as pd_orderprice, po_currency as currency, " +
|
|
|
+ "poi_taxrate as taxrate, poi_whname as whname, poi_ycheckqty as ycheckqty, pr_code as prodcode, pr_spec as prodspec, pr_title as prodtitle, " +
|
|
|
+ "((-(1) * poi_qty ) - coalesce( poi_ycheckqty, 0)) as thischeckqty, po_enuu as custuu, po_venduu as enuu, poi_id as sourceid, " +
|
|
|
+ "po_sendcode as sendcode, purc$orderitems.pd_factory as factory, en_name custname from purc$badout " +
|
|
|
+ "join purc$badoutitem on po_id = poi_poid " +
|
|
|
+ "left join purc$orderitems on poi_pdid = pd_id " +
|
|
|
+ "left join purc$orders on pu_id = pd_puid " +
|
|
|
+ "left join sec$enterprises on po_enuu = en_uu " +
|
|
|
+ "where poi_qty > abs(coalesce( poi_ycheckqty, 0)) and po_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and po_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and pd_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and poi_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and po_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(po_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(po_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> badOuts = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return badOuts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的客户不良品入库单
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getBadIns(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select pb_code as inoutno, pb_date as pidate, pb_rate as rate, pb_receivecode as receivecode, " +
|
|
|
+ "pb_receivename as receivename, '客户不良品入库单' as piclass, 'purc$badinitem' as sourcetable, pu_code as ordercode, " +
|
|
|
+ "pd_number as orderdetno, pbi_number as detno, pbi_qty as qty, 0 as pd_orderprice, pb_currency as currency, pbi_taxrate as taxrate, " +
|
|
|
+ "pbi_whname as whname, pbi_ycheckqty as ycheckqty, pr_code as prodcode, pr_spec as prodspec, pr_title as prodtitle, " +
|
|
|
+ "(pbi_qty - coalesce(pbi_ycheckqty, 0)) as thischeckqty, pb_enuu as custuu, pb_venduu as enuu, pbi_id as sourceid, " +
|
|
|
+ "pb_sendcode as sendcode, pd_factory as factory, en_name custname from purc$badin " +
|
|
|
+ "join purc$badinitem on pb_id = pbi_pbid " +
|
|
|
+ "left join purc$orderitems on pbi_pdid = pd_id " +
|
|
|
+ "left join purc$orders on pu_id = pd_puid " +
|
|
|
+ "left join sec$enterprises on pb_enuu = en_uu " +
|
|
|
+ "where pbi_qty > abs(coalesce(pbi_ycheckqty, 0)) and pb_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and pb_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and pd_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and pbi_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and pb_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pb_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pb_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> badIns = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return badIns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的客户采购验退单信息
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getSaleReturns(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select purc$return.pr_code as inoutno, pr_date as pidate, pr_rate as rate, pr_receivecode as receivecode, " +
|
|
|
+ "pr_receivename as receivename, '客户采购验退单' as piclass, 'purc$returnitem' as sourcetable, pu_code as ordercode, pd_number as orderdetno, " +
|
|
|
+ "pri_number as detno, (-(1) * pri_qty ) as qty, pri_orderprice as orderprice, pr_currency as pi_currency, pri_taxrate as taxrate, " +
|
|
|
+ "pri_whname as whname, purc$returnitem.pr_code as prodcode, purc$returnitem.pr_spec as prodspec, purc$returnitem.pr_title as prodtitle, " +
|
|
|
+ "pri_ycheckqty as ycheckqty, ((-(1) * pri_qty ) - coalesce(pri_ycheckqty, 0)) as thischeckqty, pr_enuu as custuu, pr_venduu as enuu, " +
|
|
|
+ "pri_id as sourceid, pr_sendcode as sendcode, pd_factory as factory, en_name custname from purc$return " +
|
|
|
+ "join purc$returnitem on pr_id = pri_prid " +
|
|
|
+ "left join purc$orderitems on pri_pdid = pd_id " +
|
|
|
+ "left join purc$orders on pu_id = pd_puid " +
|
|
|
+ "left join sec$enterprises on pr_enuu = en_uu " +
|
|
|
+ "where pri_qty > abs(coalesce(pri_ycheckqty, 0)) and pr_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and pr_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and pd_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and purc$returnitem.pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and purc$returnitem.pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and pri_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and pr_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pr_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pr_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> saleReturns = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return saleReturns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的客户采购验收单信息
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getSaleAccepts(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select pa_code as inoutno, pa_date as pidate, pa_rate as rate, pa_receivecode as receivcode, " +
|
|
|
+ "pa_receivename as receivename, '客户采购验收单' as piclass, 'purc$acceptitem' as sourcetable, pu_code as ordercode, " +
|
|
|
+ "pd_number as orderdetno, pai_number as detno, pai_qty as qty, pai_orderprice as orderprice, pa_currency as currency, " +
|
|
|
+ "pai_taxrate as taxrate, pai_whname as whname, purc$acceptitem.pr_code as prodcode, purc$acceptitem.pr_spec as prodspec, " +
|
|
|
+ "purc$acceptitem.pr_title as prodtitle, pai_ycheckqty as ycheckqty, (pai_qty - coalesce(pai_ycheckqty, 0)) as thischeckqty, " +
|
|
|
+ "pa_enuu as custuu, pa_venduu as enuu, pai_id as sourceid, pa_sendcode as sendcode, pd_factory as factory, en_name custname from purc$accept " +
|
|
|
+ "join purc$acceptitem on pai_paid = pa_id " +
|
|
|
+ "left join purc$orderitems on pai_pdid = pd_id " +
|
|
|
+ "left join purc$orders on purc$orders.pu_id = pd_puid " +
|
|
|
+ "left join sec$enterprises on pa_enuu = en_uu " +
|
|
|
+ "where pai_qty > coalesce(pai_ycheckqty, 0) and pa_venduu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and pa_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and pd_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and purc$acceptitem.pr_spec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and purc$acceptitem.pr_title = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and pai_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and en_name = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and pa_enuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pa_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(pa_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> saleAccepts = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return saleAccepts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取待对账的货款调账信息
|
|
|
+ *
|
|
|
+ * @param distributes 客户分配
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ * @param enUU 当前企业UU
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ErpProdIODetail> getAdjustments(StringBuffer distributes, ApcheckKeyWord keyword, Long fromDate, Long endDate, Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("select aa_inoutno inoutno, aa_orderdate pidate, aa_rate rate, aa_receivecode receivecode, " +
|
|
|
+ "aa_receivename receivename, '货款调账' as piclass, 'purc$apbilladjustment' as sourcetable, aa_ordercode ordercode, " +
|
|
|
+ "aa_orderdetno orderdetno, aa_detno detno, aa_prid prid, aa_prodcode prodcode, aa_prodspec prodspec, aa_prodtitle prodtitle, " +
|
|
|
+ "aa_qty qty, aa_orderprice orderprice, aa_currency currency, aa_taxrate taxrate, aa_whname whname, aa_ycheckqty ycheckqty, " +
|
|
|
+ "(aa_qty - coalesce(aa_ycheckqty, 0)) as thischeckqty, aa_custuu custuu, aa_enuu enuu, aa_id sourceid, aa_sendcode sendcode, " +
|
|
|
+ "aa_factory factory, aa_custname custname from purc$apbilladjustment where aa_enuu = ").append(enUU).append(" ");
|
|
|
+ if (!StringUtils.isEmpty(keyword.getReceiveName())) {
|
|
|
+ sql.append("and aa_receivename = '").append(keyword.getReceiveName()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getFactory())) {
|
|
|
+ sql.append("and aa_factory = '").append(keyword.getFactory()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdSpec())) {
|
|
|
+ sql.append("and aa_prodspec = '").append(keyword.getProdSpec()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getProdTitle())) {
|
|
|
+ sql.append("and aa_prodtitle = '").append(keyword.getProdTitle()).append("' ");
|
|
|
+ }
|
|
|
+ if (null != keyword.getTaxRate()) {
|
|
|
+ sql.append("and aa_taxrate = '").append(keyword.getTaxRate()).append("' ");
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(keyword.getSuuorname())) {
|
|
|
+ sql.append("and aa_custname = '").append(keyword.getSuuorname()).append("' ");
|
|
|
+ }
|
|
|
+ if (distributes.length() > 0) {
|
|
|
+ sql.append("and aa_custuu in (").append(distributes).append(") ");
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(aa_date) >= '").append(new java.sql.Date(new Date(fromDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ sql.append("and DAYFORMDATE(aa_date) <= '").append(new java.sql.Date(new Date(endDate).getTime())).append("' ");
|
|
|
+ }
|
|
|
+ List<ErpProdIODetail> adjustments = commonDao.query(sql.toString(), ErpProdIODetail.class);
|
|
|
+ return adjustments;
|
|
|
+ }
|
|
|
}
|