调整结算打印
parent
57b1eff310
commit
6fb1bf253f
|
|
@ -5,7 +5,7 @@ import com.jfinal.plugin.activerecord.IBean;
|
|||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* Generated by COWR Mon Aug 17 10:47:18 CST 2020
|
||||
* Generated by COWR Fri Aug 28 00:25:03 CST 2020
|
||||
* TableName: invoice_receive
|
||||
* Remarks: 发票管理 - 领用记录
|
||||
* PrimaryKey: id
|
||||
|
|
@ -22,46 +22,24 @@ public abstract class BaseInvoiceReceive<M extends BaseInvoiceReceive<M>> extend
|
|||
|
||||
/**
|
||||
* name: id
|
||||
* type: CHAR(32)
|
||||
* type: INT(10)
|
||||
* isNullable: NO
|
||||
* isPrimaryKey: YES
|
||||
* defaultValue:
|
||||
* @param id uuid
|
||||
* @param id
|
||||
*/
|
||||
@JSONField(name="id")
|
||||
public void setId(String id) {
|
||||
public void setId(Integer id) {
|
||||
set("id", id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return id uuid
|
||||
* @return id
|
||||
*/
|
||||
@JSONField(name="id")
|
||||
public String getId() {
|
||||
return getStr("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* name: num
|
||||
* type: INT(10)
|
||||
* isNullable: NO
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param num 领取数量
|
||||
*/
|
||||
@JSONField(name="num")
|
||||
public void setNum(Integer num) {
|
||||
set("num", num);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return num 领取数量
|
||||
*/
|
||||
@JSONField(name="num")
|
||||
public Integer getNum() {
|
||||
return getInt("num");
|
||||
public Integer getId() {
|
||||
return getInt("id");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,6 +86,28 @@ public abstract class BaseInvoiceReceive<M extends BaseInvoiceReceive<M>> extend
|
|||
return getStr("start_code");
|
||||
}
|
||||
|
||||
/**
|
||||
* name: end_code
|
||||
* type: VARCHAR(20)
|
||||
* isNullable: NO
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param endCode 发票截止号码
|
||||
*/
|
||||
@JSONField(name="end_code")
|
||||
public void setEndCode(String endCode) {
|
||||
set("end_code", endCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return end_code 发票截止号码
|
||||
*/
|
||||
@JSONField(name="end_code")
|
||||
public String getEndCode() {
|
||||
return getStr("end_code");
|
||||
}
|
||||
|
||||
/**
|
||||
* name: current_code
|
||||
* type: VARCHAR(20)
|
||||
|
|
@ -224,7 +224,7 @@ public abstract class BaseInvoiceReceive<M extends BaseInvoiceReceive<M>> extend
|
|||
* isNullable: NO
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param supermarketId 领取砂站id
|
||||
* @param supermarketId 领取超市id
|
||||
*/
|
||||
@JSONField(name="supermarket_id")
|
||||
public void setSupermarketId(Integer supermarketId) {
|
||||
|
|
@ -233,7 +233,7 @@ public abstract class BaseInvoiceReceive<M extends BaseInvoiceReceive<M>> extend
|
|||
|
||||
|
||||
/**
|
||||
* @return supermarket_id 领取砂站id
|
||||
* @return supermarket_id 领取超市id
|
||||
*/
|
||||
@JSONField(name="supermarket_id")
|
||||
public Integer getSupermarketId() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@ import java.util.List;
|
|||
public class InvoiceReceiveService extends BaseService {
|
||||
public static final InvoiceReceiveService me = new InvoiceReceiveService();
|
||||
|
||||
public InvoiceReceive foremostReceive(int supermarket_id) {
|
||||
String sql = "select * from invoice_receive t\n" +
|
||||
" where t.supermarket_id = ? \n" +
|
||||
" and t.surplus > 0\n" +
|
||||
" order by t.start_code asc\n" +
|
||||
" limit 1";
|
||||
|
||||
InvoiceReceive receive = InvoiceReceive.dao.findFirst(sql, supermarket_id);
|
||||
|
||||
return receive;
|
||||
}
|
||||
|
||||
public Page<Record> find(PageParam pp) {
|
||||
String selectsql = "select * ";
|
||||
String fromsql = "from invoice_receive t where 1=1 ";
|
||||
|
|
|
|||
|
|
@ -21,11 +21,17 @@ public class InvoiceReceiveValidator extends CrudParamValidator {
|
|||
validateString("id", 1, 32, "id", "id 长度 1~32");
|
||||
}
|
||||
|
||||
validateInteger("num", 1, 2147483647, "num", "num 范围 1~2147483647");
|
||||
validateString("start_code", 1, 20, "start_code", "start_code 长度 1~20");
|
||||
validateString("end_code", 1, 20, "end_code", "end_code 长度 1~20");
|
||||
validateInteger("receive_user_id", 1, 2147483647, "receive_user_id", "receive_user_id 范围 1~2147483647");
|
||||
validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647");
|
||||
|
||||
if(StrKit.notBlank(c.get("start_code"), c.get("end_code"))){
|
||||
if(c.getInt("end_code") - c.getInt("start_code") < 0){
|
||||
addError("end_code", "end_code 必须大于等于 start_code");
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 model 更新时,model 不能只有主键有值
|
||||
// 这里用 getActionMethodName 写死,判断是 update 时,才做验证
|
||||
// 如果确实是需要将主键外的字段置为 null,可以在代码生成后删掉这段
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.cowr.ssjygl.prepay;
|
||||
|
||||
import com.cowr.common.enums.OrderTypeEnum;
|
||||
import com.cowr.common.utils.DateTimeUtil;
|
||||
import com.cowr.model.*;
|
||||
import com.cowr.ssjygl.CacheData;
|
||||
|
|
@ -18,7 +19,6 @@ import org.apache.poi.ss.usermodel.*;
|
|||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
|
@ -33,14 +33,13 @@ public class PrepayService {
|
|||
* @param pp 分页参数
|
||||
* @param name 客户名称
|
||||
* @param customer_id 客户id
|
||||
* @param supermarket_id 超时id
|
||||
* @param stm 开始时间
|
||||
* @param etm 截止时间
|
||||
* @param start 开始金额
|
||||
* @param end 截止金额
|
||||
* @return
|
||||
*/
|
||||
public Page<Record> find(PageParam pp, String name, Integer customer_id, Integer supermarket_id, String stm, String etm, Double start, Double end) {
|
||||
public Page<Record> find(PageParam pp, String name, Integer customer_id, String stm, String etm, Double start, Double end) {
|
||||
String selectsql = " select p.*, c.name customer_name, c.address, c.texpayer_name, c.texpayer_num, c.memo, pc.surplus, s.name supermarket_name \n";
|
||||
String fromsql = " from ( \n" +
|
||||
" select t.customer_id, t.supermarket_id, max(t.create_time) maxtm, max(t.id) maxid from prepay_detail t \n" +
|
||||
|
|
@ -49,7 +48,7 @@ public class PrepayService {
|
|||
" ) a \n" +
|
||||
" left join prepay_detail p on p.id = a.maxid \n" +
|
||||
" left join customer c on c.id = p.customer_id \n" +
|
||||
" left join prepay_customer pc on pc.customer_id = p.customer_id and pc.supermarket_id = a.supermarket_id\n" +
|
||||
" left join prepay_customer pc on pc.customer_id = p.customer_id \n" +
|
||||
" left join supermarket s on s.id = a.supermarket_id\n" +
|
||||
" where 1 = 1";
|
||||
List<Object> paraList = new ArrayList<>();
|
||||
|
|
@ -64,11 +63,6 @@ public class PrepayService {
|
|||
paraList.add(customer_id);
|
||||
}
|
||||
|
||||
if (supermarket_id != null) {
|
||||
fromsql += " and a.supermarket_id = ? \n";
|
||||
paraList.add(supermarket_id);
|
||||
}
|
||||
|
||||
if (StrKit.notBlank(stm)) {
|
||||
fromsql += " and p.create_time >= ?";
|
||||
paraList.add(stm);
|
||||
|
|
@ -115,20 +109,24 @@ public class PrepayService {
|
|||
return null;
|
||||
}
|
||||
|
||||
PrepayTruck pt = PrepayTruck.dao.findFirst("select * from prepay_truck t \n" +
|
||||
" where t.supermarket_id = ? \n" +
|
||||
" and t.truck_license = ? \n" +
|
||||
OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" +
|
||||
" where t.truck_license = ? \n" +
|
||||
" and t.valid_date = ? ",
|
||||
transport.getSupermarketId(),
|
||||
transport.getTruckLicense(),
|
||||
DateTimeUtil.sdf.get().format(transport.getInTime())
|
||||
);
|
||||
|
||||
if (pt == null) {
|
||||
if (ot == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Customer customer = Customer.dao.findById(pt.getCustomerId());
|
||||
Ordercluster ordercluster = Ordercluster.dao.findById(ot.getOrderclusterId());
|
||||
|
||||
if (ordercluster == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Customer customer = Customer.dao.findById(ordercluster.getCustomerId());
|
||||
|
||||
if (customer == null) {
|
||||
return null;
|
||||
|
|
@ -158,7 +156,7 @@ public class PrepayService {
|
|||
|
||||
out.set("prepay_truck", true);
|
||||
out.set("prepay_threshold", prepayCustomer.getThreshold());
|
||||
out.set("prepay_truck_type", pt.getType());
|
||||
out.set("prepay_truck_type", OrderTypeEnum.TEMP.getTypeid()); // 浠水固定只有外销
|
||||
out.set("prepay_customer_id", customer.getId());
|
||||
out.set("prepay_customer_name", customer.getName());
|
||||
out.set("prepay_contact_name", pd.getContactName());
|
||||
|
|
@ -166,25 +164,7 @@ public class PrepayService {
|
|||
out.set("prepay_surplus", prepayCustomer.getSurplus());
|
||||
out.set("prepay_customer", customer);
|
||||
out.set("prepay_customer_info", prepayCustomer);
|
||||
|
||||
Truck truck = Truck.dao.findById(transport.getTruckLicense());
|
||||
|
||||
if(truck != null){
|
||||
// 预付费关联集团客户订单
|
||||
List<Record> list = Db.find("select t.*, c.`name` customer_name from ordercluster t\n" +
|
||||
" left join customer c on c.id = t.customer_id\n" +
|
||||
" where t.state < ? \n" +
|
||||
" and t.supermarket_id = ? \n" +
|
||||
" and t.trans_co_id = ? \n" +
|
||||
" and t.customer_id = ? ",
|
||||
OrderStateEnum.RECEIVED.getStateid(),
|
||||
transport.getSupermarketId(),
|
||||
truck.getTransCoId(),
|
||||
pt.getCustomerId()
|
||||
);
|
||||
|
||||
out.set("prepay_ordercluster", list);
|
||||
}
|
||||
out.set("prepay_ordercluster", ordercluster); // 预付费关联集团客户订单
|
||||
|
||||
List<Record> list = CustomerReceiverService.me.list(customer.getId(), null, null, transport.getSupermarketId());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,10 @@
|
|||
package com.cowr.local.ssjygl.invoice.log;
|
||||
|
||||
import com.cowr.common.view.Result;
|
||||
import com.cowr.local.ssjygl.base.BaseSyncService;
|
||||
import com.cowr.model.InvoiceReceive;
|
||||
import com.jfinal.log.Log;
|
||||
|
||||
public class InvoiceLogSyncService extends BaseSyncService {
|
||||
private static Log log = Log.getLog(InvoiceLogSyncService.class);
|
||||
public static InvoiceLogSyncService me = new InvoiceLogSyncService();
|
||||
|
||||
/**
|
||||
* 通过第三方税盘接口获取当前的 发票号码
|
||||
*
|
||||
* @param supermarket_id
|
||||
* @return
|
||||
*/
|
||||
public String taxationLastCode(int supermarket_id) {
|
||||
// TODO: 通过税盘获取当前发票号码
|
||||
return null;
|
||||
}
|
||||
|
||||
public InvoiceReceive lastReceive(int supermarket_id) {
|
||||
String sql = "select * from invoice_receive t\n" +
|
||||
" where t.supermarket_id = ? \n" +
|
||||
" and t.surplus > 0\n" +
|
||||
" order by t.start_code asc\n" +
|
||||
" limit 1";
|
||||
|
||||
InvoiceReceive receive = InvoiceReceive.dao.findFirst(sql, supermarket_id);
|
||||
|
||||
|
||||
return receive;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -603,7 +603,6 @@ public class OrderService {
|
|||
return Result.failed("没有可用发票");
|
||||
}
|
||||
|
||||
String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id"));
|
||||
String next_invoice_code;
|
||||
if (receive.getCurrentCode() == null) {
|
||||
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getStartCode() + 1));
|
||||
|
|
@ -611,10 +610,6 @@ public class OrderService {
|
|||
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode() + 1));
|
||||
}
|
||||
|
||||
if (!next_invoice_code.equals(taxation_invoice_code)) {
|
||||
return Result.failed("本地记录和税务系统不一致");
|
||||
}
|
||||
|
||||
order.set("invoice_code", next_invoice_code);
|
||||
|
||||
boolean ret = Db.tx(new IAtom() {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import com.cowr.common.enums.OrderStateEnum;
|
|||
import com.cowr.common.enums.OrderTypeEnum;
|
||||
import com.cowr.common.utils.DateTimeUtil;
|
||||
import com.cowr.common.view.Result;
|
||||
import com.cowr.local.ssjygl.invoice.log.InvoiceLogSyncService;
|
||||
import com.cowr.local.ssjygl.main.Config;
|
||||
import com.cowr.local.ssjygl.order.OrderService;
|
||||
import com.cowr.local.ssjygl.order.orderseq.OrderSeqService;
|
||||
import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService;
|
||||
import com.cowr.ssjygl.supermarket.product.SupermarketProductService;
|
||||
import com.cowr.local.ssjygl.synctask.SyncTaskService;
|
||||
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
|
||||
|
|
@ -91,7 +91,7 @@ public class OrderTempSyncService {
|
|||
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
|
||||
|
||||
if (req_receipt == 1) { // 需要同时开具发票
|
||||
receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId());
|
||||
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
|
||||
|
||||
if (receive == null) {
|
||||
return Result.failed("没有有效的领用记录");
|
||||
|
|
@ -183,14 +183,24 @@ public class OrderTempSyncService {
|
|||
return false;
|
||||
}
|
||||
|
||||
// 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息
|
||||
String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id"));
|
||||
InvoiceLog invoiceLog = new InvoiceLog();
|
||||
invoiceLog.setId(StrKit.getRandomUUID());
|
||||
invoiceLog.setInvoiceReceiveId(finalReceive.getId());
|
||||
invoiceLog.setCode(finalNext_invoice_code);
|
||||
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
|
||||
invoiceLog.setSettlementTime(now);
|
||||
invoiceLog.setSettlementUserId(order.getSettlementUserId());
|
||||
invoiceLog.setSettlementUserName(order.getSettlementUserName());
|
||||
invoiceLog.setOrderSn(order.getSn());
|
||||
invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid());
|
||||
|
||||
if (!finalNext_invoice_code.equals(taxation_invoice_code)) {
|
||||
log.error("本地记录和税务系统不一致");
|
||||
ret = invoiceLog.save();
|
||||
|
||||
if(!ret){
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(invoiceLog);
|
||||
synctask.addUpdateData(finalReceive);
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +296,7 @@ public class OrderTempSyncService {
|
|||
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
|
||||
|
||||
if (req_receipt == 1) { // 需要同时开具发票
|
||||
receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId());
|
||||
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
|
||||
|
||||
if (receive == null) {
|
||||
return Result.failed("没有有效的领用记录");
|
||||
|
|
@ -380,6 +390,18 @@ public class OrderTempSyncService {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(ordercluster.getState() == OrderStateEnum.INITIAL.getStateid()){
|
||||
ordercluster.setState(OrderStateEnum.ENTERED.getStateid());
|
||||
|
||||
ret = ordercluster.update();
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addUpdateData(ordercluster);
|
||||
}
|
||||
|
||||
Stock stock = Stock.dao.findByIds(transport.getSupermarketId(), order.getProductId());
|
||||
if (stock == null) {
|
||||
log.error("未找到库存信息 %s, %s", order.getSupermarketId(), order.getProductId());
|
||||
|
|
@ -405,14 +427,24 @@ public class OrderTempSyncService {
|
|||
return false;
|
||||
}
|
||||
|
||||
// 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息
|
||||
String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id"));
|
||||
InvoiceLog invoiceLog = new InvoiceLog();
|
||||
invoiceLog.setId(StrKit.getRandomUUID());
|
||||
invoiceLog.setInvoiceReceiveId(finalReceive.getId());
|
||||
invoiceLog.setCode(finalNext_invoice_code);
|
||||
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
|
||||
invoiceLog.setSettlementTime(now);
|
||||
invoiceLog.setSettlementUserId(order.getSettlementUserId());
|
||||
invoiceLog.setSettlementUserName(order.getSettlementUserName());
|
||||
invoiceLog.setOrderSn(order.getSn());
|
||||
invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid());
|
||||
|
||||
if (!finalNext_invoice_code.equals(taxation_invoice_code)) {
|
||||
log.error("本地记录和税务系统不一致");
|
||||
ret = invoiceLog.save();
|
||||
|
||||
if(!ret){
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(invoiceLog);
|
||||
synctask.addUpdateData(finalReceive);
|
||||
}
|
||||
|
||||
|
|
@ -459,22 +491,28 @@ public class OrderTempSyncService {
|
|||
return Result.failed("进出场记录已完结或者已作废,不能使用");
|
||||
}
|
||||
|
||||
PrepayTruck pt = PrepayTruck.dao.findFirst("select * from prepay_truck t \n" +
|
||||
" where t.supermarket_id = ? \n" +
|
||||
" and t.truck_license = ? \n" +
|
||||
OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" +
|
||||
" where t.truck_license = ? \n" +
|
||||
" and t.valid_date = ? ",
|
||||
transport.getSupermarketId(),
|
||||
transport.getTruckLicense(),
|
||||
DateTimeUtil.sdf.get().format(transport.getInTime())
|
||||
);
|
||||
|
||||
if (pt == null) {
|
||||
if (ot == null) {
|
||||
return Result.failedstr("【%s】不是今日预付费车辆", transport.getTruckLicense());
|
||||
}
|
||||
|
||||
Customer customer;
|
||||
Product product;
|
||||
Ordercluster ordercluster = null;
|
||||
Ordercluster ordercluster = Ordercluster.dao.findById(ordercluster_id);
|
||||
|
||||
if (ordercluster == null) {
|
||||
return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id);
|
||||
}
|
||||
|
||||
if (ordercluster.getState() == OrderStateEnum.INVALID.getStateid()) {
|
||||
return Result.failedstr("集团订单【%s】已完结,请重新下单", ordercluster_id);
|
||||
}
|
||||
|
||||
// 验证重量
|
||||
if (transport.getFirstWeight() == null
|
||||
|
|
@ -492,16 +530,6 @@ public class OrderTempSyncService {
|
|||
|
||||
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
|
||||
|
||||
if (ordercluster_id != null) {
|
||||
ordercluster = Ordercluster.dao.findById(ordercluster_id);
|
||||
if (ordercluster == null) {
|
||||
return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id);
|
||||
}
|
||||
|
||||
if (ordercluster.getState() == OrderStateEnum.INVALID.getStateid()) {
|
||||
return Result.failedstr("集团订单【%s】已完结,请重新下单", ordercluster_id);
|
||||
}
|
||||
|
||||
if (!DateTimeUtil.isToday(ordercluster.getCutoffTime())) {
|
||||
return Result.failedstr("集团订单只能在%s使用", DateTimeUtil.sdfymd.get().format(ordercluster.getCutoffTime()));
|
||||
}
|
||||
|
|
@ -527,11 +555,6 @@ public class OrderTempSyncService {
|
|||
transport.setTransCoPhone(ordercluster.getTransCoPhone());
|
||||
transport.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName());
|
||||
transport.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum());
|
||||
} else {
|
||||
customer = Customer.dao.findById(pt.getCustomerId());
|
||||
|
||||
product = Product.dao.findById(product_id);
|
||||
}
|
||||
|
||||
if (product == null) {
|
||||
return Result.failedstr("未找到有效的品类信息");
|
||||
|
|
@ -567,7 +590,7 @@ public class OrderTempSyncService {
|
|||
String next_invoice_code = null;
|
||||
|
||||
if (req_receipt == 1) { // 需要同时开具发票
|
||||
receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId());
|
||||
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
|
||||
|
||||
if (receive == null) {
|
||||
return Result.failed("没有有效的领用记录");
|
||||
|
|
@ -626,6 +649,10 @@ public class OrderTempSyncService {
|
|||
transport.setArriveTime(now);
|
||||
transport.setType(OrderTypeEnum.TEMP.getTypeid());
|
||||
|
||||
if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) < 1) {
|
||||
return Result.failedstr("总价 %.2f,客户余额(%.2f)不足以支付");
|
||||
}
|
||||
|
||||
InvoiceReceive finalReceive = receive;
|
||||
String finalNext_invoice_code = next_invoice_code;
|
||||
boolean ret = Db.tx(new IAtom() {
|
||||
|
|
@ -641,74 +668,11 @@ public class OrderTempSyncService {
|
|||
order.setPrepayCustomerId(prepayCustomer.getId());
|
||||
prepayCustomer.setSpendTime(now);
|
||||
|
||||
if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) > -1) {
|
||||
if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
prepayCustomer.setSurplus(prepayCustomer.getSurplus().subtract(order.getTotalPrice()));
|
||||
} else {
|
||||
// 对于支付的差额,算作一次即充即用的预付费充值
|
||||
prepayCustomer.setSurplus(new BigDecimal(0));
|
||||
|
||||
String paidmemo = "现场补足预付金额:" + order.getPaid().intValue() + "元";
|
||||
|
||||
if (StrKit.isBlank(order.getMemo())) {
|
||||
order.setMemo(paidmemo);
|
||||
} else {
|
||||
order.setMemo(order.getMemo() + "。" + paidmemo);
|
||||
}
|
||||
|
||||
PrepayDetail pd = new PrepayDetail();
|
||||
pd.setId(StrKit.getRandomUUID());
|
||||
pd.setCustomerId(order.getCustomerId());
|
||||
pd.setSupermarketId(order.getSupermarketId());
|
||||
pd.setAmount(order.getTotalPrice().subtract(prepayCustomer.getSurplus())); // 订单总价减去余额,就是本次补的差价
|
||||
pd.setType(2);
|
||||
pd.setContactName("");
|
||||
pd.setContactPhone("");
|
||||
pd.setBankName("");
|
||||
pd.setSerialnum("");
|
||||
pd.setState(2);
|
||||
pd.setChangeTime(now);
|
||||
pd.setCreateTime(now);
|
||||
pd.setVerifyTime(now);
|
||||
|
||||
ret = pd.save();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(pd);
|
||||
|
||||
PrepayDetailStateHistory his = new PrepayDetailStateHistory();
|
||||
his.setId(StrKit.getRandomUUID());
|
||||
his.setPrepayDetailId(pd.getId());
|
||||
his.setChangeUserId(sysuser.getId());
|
||||
his.setChangeUserName(sysuser.getName());
|
||||
his.setState(1);
|
||||
his.setChangeTime(now);
|
||||
his.setMemo(paidmemo);
|
||||
|
||||
ret = his.save();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(his);
|
||||
|
||||
his = new PrepayDetailStateHistory();
|
||||
his.setId(StrKit.getRandomUUID());
|
||||
his.setPrepayDetailId(pd.getId());
|
||||
his.setChangeUserId(sysuser.getId());
|
||||
his.setChangeUserName(sysuser.getName());
|
||||
his.setState(2);
|
||||
his.setChangeTime(now);
|
||||
his.setMemo(paidmemo);
|
||||
|
||||
ret = his.save();
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(his);
|
||||
}
|
||||
|
||||
synctask.addUpdateData(prepayCustomer);
|
||||
|
||||
|
|
@ -724,10 +688,18 @@ public class OrderTempSyncService {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(ordercluster.getState() == OrderStateEnum.INITIAL.getStateid()){
|
||||
ordercluster.setState(OrderStateEnum.ENTERED.getStateid());
|
||||
|
||||
ret = ordercluster.update();
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addUpdateData(ordercluster);
|
||||
}
|
||||
|
||||
Stock stock = Stock.dao.findByIds(transport.getSupermarketId(), order.getProductId());
|
||||
if (stock == null) {
|
||||
log.error("未找到库存信息 %s, %s", order.getSupermarketId(), order.getProductId());
|
||||
|
|
@ -753,14 +725,24 @@ public class OrderTempSyncService {
|
|||
return false;
|
||||
}
|
||||
|
||||
// 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息
|
||||
String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id"));
|
||||
InvoiceLog invoiceLog = new InvoiceLog();
|
||||
invoiceLog.setId(StrKit.getRandomUUID());
|
||||
invoiceLog.setInvoiceReceiveId(finalReceive.getId());
|
||||
invoiceLog.setCode(finalNext_invoice_code);
|
||||
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
|
||||
invoiceLog.setSettlementTime(now);
|
||||
invoiceLog.setSettlementUserId(order.getSettlementUserId());
|
||||
invoiceLog.setSettlementUserName(order.getSettlementUserName());
|
||||
invoiceLog.setOrderSn(order.getSn());
|
||||
invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid());
|
||||
|
||||
if (!finalNext_invoice_code.equals(taxation_invoice_code)) {
|
||||
log.error("本地记录和税务系统不一致");
|
||||
ret = invoiceLog.save();
|
||||
|
||||
if(!ret){
|
||||
return false;
|
||||
}
|
||||
|
||||
synctask.addSaveData(invoiceLog);
|
||||
synctask.addUpdateData(finalReceive);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,14 +14,12 @@ public class PrepayController extends BaseController {
|
|||
public void find() {
|
||||
String name = get("name");
|
||||
Integer customer_id = getInt("customer_id");
|
||||
|
||||
Integer supermarket_id = getInt("supermarket_id");
|
||||
String stm = get("stm");
|
||||
String etm = get("etm");
|
||||
Double start = getParaToDouble("start");
|
||||
Double end = getParaToDouble("end");
|
||||
PageParam pp = getBean(PageParam.class, "", true);
|
||||
renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, supermarket_id, stm, etm, start, end)));
|
||||
renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, stm, etm, start, end)));
|
||||
}
|
||||
|
||||
@Before(StartAndEndTimeValidator.class)
|
||||
|
|
|
|||
|
|
@ -36,10 +36,25 @@ public class InvoiceReceiveSyncService extends BaseSyncService {
|
|||
return Result.failed("未找到对应砂站信息");
|
||||
}
|
||||
|
||||
// TODO: 这里需要验证输入的起始发票号码和领用份数,避免多个批次的领用和多个砂站的领用出现发票代码重复的情况
|
||||
try {
|
||||
// 十位或者更长的发票号码要转 long,否则可能超过 Integer.MAX_VALUE 2147483647
|
||||
Long start = Long.parseLong(receive.getStartCode());
|
||||
Long end = Long.parseLong(receive.getEndCode());
|
||||
|
||||
receive.setId(StrKit.getRandomUUID());
|
||||
receive.setSurplus(receive.getNum());
|
||||
List<InvoiceReceive> chklist = InvoiceReceive.dao.find("select * from invoice_receive t\n" +
|
||||
" where ( t.start_code <= ? and t.end_code >= ? )\n" +
|
||||
" or ( t.start_code <= ? and t.end_code >= ? )", start, start, end, end);
|
||||
|
||||
if (!chklist.isEmpty()) {
|
||||
return Result.failed("发票段和已领用的记录冲突");
|
||||
}
|
||||
|
||||
receive.setSurplus((int) (end - start) + 1);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
||||
return Result.failed("数据检查错误");
|
||||
}
|
||||
|
||||
try {
|
||||
boolean ret = Db.tx(new IAtom() {
|
||||
|
|
|
|||
|
|
@ -28,13 +28,12 @@ public class PrepayController extends BaseController {
|
|||
customer_id = tokenuser.getEntityId();
|
||||
}
|
||||
|
||||
Integer supermarket_id = getInt("supermarket_id");
|
||||
String stm = get("stm");
|
||||
String etm = get("etm");
|
||||
Double start = getParaToDouble("start");
|
||||
Double end = getParaToDouble("end");
|
||||
PageParam pp = getBean(PageParam.class, "", true);
|
||||
renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, supermarket_id, stm, etm, start, end)));
|
||||
renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, stm, etm, start, end)));
|
||||
}
|
||||
|
||||
@Before(StartAndEndTimeValidator.class)
|
||||
|
|
|
|||
Loading…
Reference in New Issue