客户对账统计修改

dev
wany 2025-03-28 15:09:20 +08:00
parent ef63210e7a
commit f43cc279a6
4 changed files with 122 additions and 63 deletions

View File

@ -40,10 +40,10 @@ public class CustomerStatService {
tempSql = " select t.customer_id,\n" +
" sum(ifnull((case when t.sale_type = 0 THEN t.total_price END), 0)) sh_total_price,\n" +
" sum(ifnull((case when t.sale_type = 0 THEN t.weight END), 0)) sh_total_weight,\n" +
" sum(ifnull((case when t.sale_type = 0 THEN t.count END), 0)) sh_total_cnt,\n" +
" sum(ifnull((case when t.sale_type = 1 THEN t.total_price END), 0)) yh_total_price,\n" +
" sum(ifnull((case when t.sale_type = 1 THEN t.weight END), 0)) yh_total_weight,\n" +
" sum(ifnull((case when t.sale_type = 1 THEN t.count END), 0)) yh_total_cnt \n" +
" sum(ifnull((case when t.sale_type = 0 THEN t.count END), 0)) sh_total_cnt\n" +
// " sum(ifnull((case when t.sale_type = 1 THEN t.total_price END), 0)) yh_total_price,\n" +
// " sum(ifnull((case when t.sale_type = 1 THEN t.weight END), 0)) yh_total_weight,\n" +
// " sum(ifnull((case when t.sale_type = 1 THEN t.count END), 0)) yh_total_cnt \n" +
" from order_end t\n" +
" where t.customer_id > 0\n" +
" and t.date <= ? \n" +
@ -54,6 +54,19 @@ public class CustomerStatService {
paraList.add(customer_id);
}
String invoiceSql = " select t.customer_id,\n" +
" sum(ifnull((case when t.invoice_code is not null THEN t.total_price END), 0)) invoice_price,\n" +
" sum(ifnull((case when t.invoice_code is null THEN t.total_price END), 0)) no_invoice_price \n" +
" from order_temp t\n" +
" where t.customer_id > 0\n" +
" and t.create_time <= ? \n" +
customerSql +
" group by t.customer_id\n";
paraList.add(tm);
if (customer_id != null) {
paraList.add(customer_id);
}
// // 如果是当天的就加上销售订单数据
// if (LocalDate.now().toString().equals(tm)){
//
@ -95,19 +108,17 @@ public class CustomerStatService {
" t.customer_id id,\n" +
" c.`name`,\n" +
" ifnull(a.sh_total_price, 0) sh_total_price,\n" +
" ifnull(a.yh_total_price,0) yh_total_price,\n" +
" ifnull(a.sh_total_weight,0) sh_total_weight,\n" +
" ifnull(a.yh_total_weight,0) yh_total_weight,\n" +
" ifnull(a.sh_total_cnt,0) sh_total_cnt,\n" +
" ifnull(a.yh_total_cnt,0) yh_total_cnt,\n" +
" ifnull(b.amount,0) amount,\n" +
" ifnull(b.refund_amount,0) refund_amount,\n" +
" ifnull(p.presell_amount,0) presell_amount,\n" +
" ifnull(p.presell_amount,0) - ifnull(a.yh_total_price,0) yh_surplus,\n" +
" ifnull(b.amount,0) - ifnull(a.sh_total_price,0) - ifnull(b.refund_amount,0) - ifnull(p.presell_amount,0) then_surplus" +
" ifnull(b.amount,0) - ifnull(a.sh_total_price,0) - ifnull(b.refund_amount,0) then_surplus,\n" +
" ifnull(i.invoice_price,0) invoice_price,\n" +
" ifnull(i.no_invoice_price,0) no_invoice_price\n" +
" from prepay_customer t\n" +
" left join customer c on c.id= t.customer_id\n" +
" left join (\n" + tempSql + " ) a on a.customer_id = t.customer_id\n" +
" left join (\n" + invoiceSql + " ) i on i.customer_id = t.customer_id\n" +
" left join(\n" +
" select a.customer_id, a.amount, ifnull(b.amount, 0) refund_amount\n" +
" from(\n" +
@ -129,27 +140,18 @@ public class CustomerStatService {
" and a.confirm_time <= ?\n" +
" group by t.customer_id\n" +
" ) b on b.customer_id= a.customer_id\n" +
" ) b on b.customer_id= t.customer_id\n" +
" left join (select customer_id, ifnull(sum(presell_amount), 0) presell_amount from presell_order where del = 0" +
" and presell_date <= ?" +
" group by customer_id) p\n" +
" on p.customer_id = t.customer_id\n";
" ) b on b.customer_id= t.customer_id\n";
paraList.add(querytm);
if (customer_id != null) {
paraList.add(querytm);
// paraList.add(customer_id);
// paraList.add(querytm);
paraList.add(querytm);
paraList.add(customer_id);
String _sql = " select g.* from (\n" + sql + "\n) g where g.id = ?";
ret = Db.find(_sql, paraList.toArray());
} else {
// paraList.add(querytm);
paraList.add(querytm);
paraList.add(querytm);
if (customer_type_id != null) { // 客户对账不管临散订单
@ -167,44 +169,42 @@ public class CustomerStatService {
double hj_sh_total_weight = 0.0;
double hj_sh_total_price = 0.0;
int hj_yh_total_cnt = 0;
double hj_yh_total_weight = 0.0;
double hj_yh_total_price = 0.0;
double hj_total_amount = 0.0;
double hj_refund_amount = 0.0;
double hj_presell_amount = 0.0;
double hj_yh_surplus = 0.0;
double hj_then_surplus = 0.0;
double hj_invoice_price = 0.0;
double hj_no_invoice_price = 0.0;
for (Record r : ret) {
int sh_total_cnt = r.getInt("sh_total_cnt") == null ? 0 : r.getInt("sh_total_cnt");
double sh_total_weight = r.getDouble("sh_total_weight") == null ? 0.0 : r.getDouble("sh_total_weight");
double sh_total_price = r.getDouble("sh_total_price") == null ? 0.0 : r.getDouble("sh_total_price");
int yh_total_cnt = r.getInt("yh_total_cnt") == null ? 0 : r.getInt("yh_total_cnt");
double yh_total_weight = r.getDouble("yh_total_weight") == null ? 0.0 : r.getDouble("yh_total_weight");
double yh_total_price = r.getDouble("yh_total_price") == null ? 0.0 : r.getDouble("yh_total_price");
double total_amount = r.getDouble("amount") == null ? 0.0 : r.getDouble("amount");
double refund_amount = r.getDouble("refund_amount") == null ? 0.0 : r.getDouble("refund_amount");
double presell_amount = r.getDouble("presell_amount") == null ? 0.0 : r.getDouble("presell_amount");
double yh_surplus = r.getDouble("yh_surplus") == null ? 0.0 : r.getDouble("yh_surplus");
double then_surplus = r.getDouble("then_surplus") == null ? 0.0 : r.getDouble("then_surplus");
double invoice_price = r.getDouble("invoice_price") == null ? 0.0 : r.getDouble("invoice_price");
double no_invoice_price = r.getDouble("no_invoice_price") == null ? 0.0 : r.getDouble("no_invoice_price");
hj_sh_total_cnt += sh_total_cnt;
hj_sh_total_weight += sh_total_weight;
hj_sh_total_price += sh_total_price;
hj_yh_total_cnt += yh_total_cnt;
hj_yh_total_weight += yh_total_weight;
hj_yh_total_price += yh_total_price;
hj_total_amount += total_amount;
hj_refund_amount += refund_amount;
hj_presell_amount += presell_amount;
hj_yh_surplus += yh_surplus;
hj_then_surplus += then_surplus;
hj_invoice_price += invoice_price;
hj_no_invoice_price += no_invoice_price;
}
Record hj = new Record();
@ -213,14 +213,13 @@ public class CustomerStatService {
hj.set("sh_total_cnt", hj_sh_total_cnt);
hj.set("sh_total_weight", hj_sh_total_weight);
hj.set("sh_total_price", hj_sh_total_price);
hj.set("yh_total_cnt", hj_yh_total_cnt);
hj.set("yh_total_weight", hj_yh_total_weight);
hj.set("yh_total_price", hj_yh_total_price);
hj.set("amount", hj_total_amount);
hj.set("refund_amount", hj_refund_amount);
hj.set("presell_amount", hj_presell_amount);
hj.set("yh_surplus", hj_yh_surplus);
hj.set("then_surplus", hj_then_surplus);
hj.set("invoice_price", hj_invoice_price);
hj.set("no_invoice_price", hj_no_invoice_price);
ret.add(hj);
}
@ -241,20 +240,15 @@ public class CustomerStatService {
row.createCell(a++).setCellValue("客户名称");
row.createCell(a++).setCellValue("销售");
a += 2;
row.createCell(a++).setCellValue("预售提货");
a += 2;
row.createCell(a++).setCellValue("付费金额(元)");
row.createCell(a++).setCellValue("退费金额(元)");
row.createCell(a++).setCellValue("预售金额(元)");
row.createCell(a++).setCellValue("预售余额(元)");
row.createCell(a++).setCellValue("账户余额(元)");
row.createCell(a++).setCellValue("已开票金额(元)");
row.createCell(a++).setCellValue("未开票金额(元)");
Row row2 = sheet.createRow(1);
int a2 = 2;
row2.createCell(a2++).setCellValue("运输次数");
row2.createCell(a2++).setCellValue("重量(吨)");
row2.createCell(a2++).setCellValue("总价(元)");
row2.createCell(a2++).setCellValue("运输次数");
row2.createCell(a2++).setCellValue("重量(吨)");
row2.createCell(a2++).setCellValue("总价(元)");
@ -262,12 +256,13 @@ public class CustomerStatService {
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 2, 4));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 7));
// sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 7));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 9, 9));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 10, 10));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 11, 11));
sheet.addMergedRegion(new CellRangeAddress(0, 1, 12, 12));
int datalen = list.size();
int colcnt = a;
@ -282,14 +277,16 @@ public class CustomerStatService {
row.createCell(a++).setCellValue(record.getInt("sh_total_cnt") == null ? 0 : record.getInt("sh_total_cnt"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "sh_total_weight"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "sh_total_price"));
row.createCell(a++).setCellValue(record.getInt("yh_total_cnt") == null ? 0 : record.getInt("yh_total_cnt"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_weight"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_price"));
// row.createCell(a++).setCellValue(record.getInt("yh_total_cnt") == null ? 0 : record.getInt("yh_total_cnt"));
// row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_weight"));
// row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_price"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "amount"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "refund_amount"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "presell_amount"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_surplus"));
// row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "presell_amount"));
// row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_surplus"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "then_surplus"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "invoice_price"));
row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "no_invoice_price"));
}
// 通用单元格格式

View File

@ -13,6 +13,7 @@ import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -3356,6 +3357,7 @@ public class OrderStatService {
List<Record> list = typemap.get(trans_co_id);
record.set("children", list);
if(!CollectionUtils.isEmpty(list)){
record.set("count", list.stream().map(o->o.getBigDecimal("count")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("source_weight", list.stream().map(o->o.getBigDecimal("source_weight")).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("trans_price", list.stream().map(o->o.getBigDecimal("trans_price")).reduce(BigDecimal.ZERO, BigDecimal::add));
@ -3366,11 +3368,9 @@ public class OrderStatService {
record.set("xss_"+id, list.stream().map(o->o.getBigDecimal("xss_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
record.set("xsw_"+id, list.stream().map(o->o.getBigDecimal("xsw_"+id)).reduce(BigDecimal.ZERO, BigDecimal::add));
}
}
}
}
// typelist.sort(Comparator.comparing(o ->
// Objects.nonNull(o.getInt("trans_co_id")) && o.getInt("trans_co_id") > 0 ? o.getInt("trans_co_id") : Integer.valueOf(-1)));

View File

@ -0,0 +1,48 @@
package com.cowr.service.ssjygl.transpriceconfig;
import com.cowr.common.view.Result;
import com.cowr.model.Product;
import com.cowr.model.Sysuser;
import com.cowr.model.TransPriceConfigTransfer;
import com.cowr.service.ssjygl.product.ProductSyncService;
import com.cowr.service.ssjygl.system.sysuser.SysuserSyncService;
import com.cowr.ssjygl.product.ProductValidator;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;
/**
* Generated by COWR Mon Apr 06 09:50:28 CST 2020
* TableName: trans_price_config_transfer
* Remarks:
* PrimaryKey: id
*/
public class TransPriceConfigTransferController extends Controller {
/**
* trans_price_config_transfer
*/
@Before(ProductValidator.class)
public void edit() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
renderJson(Result.noauth());
return;
}
TransPriceConfigTransfer model = getModel(TransPriceConfigTransfer.class, "", true); // 忽略不在model中的字段
renderJson(TransPriceConfigTransferService.me.update(model, tokenuser));
}
/**
* trans_price_config_transfer
*/
public void list() {
renderJson(Result.object(TransPriceConfigTransferService.me.list()));
}
}

View File

@ -0,0 +1,14 @@
package com.cowr.service.ssjygl.transpriceconfig;
import com.cowr.model.TransPriceConfigTransfer;
import com.cowr.service.ssjygl.base.BaseSyncService;
import java.util.List;
public class TransPriceConfigTransferService extends BaseSyncService {
public static TransPriceConfigTransferService me = new TransPriceConfigTransferService();
public List<TransPriceConfigTransfer> list() {
return TransPriceConfigTransfer.dao.find("select * from trans_price_config_transfer t order by t.id");
}
}