lisai17@sina.com 2020-09-13 00:08:03 +08:00
parent 05277bb98c
commit f45d260574
9 changed files with 487 additions and 314 deletions

View File

@ -4,7 +4,6 @@ import com.cowr.common.Const;
import com.cowr.common.base.BaseService; import com.cowr.common.base.BaseService;
import com.cowr.common.view.PageParam; import com.cowr.common.view.PageParam;
import com.cowr.model.InvoiceLog; import com.cowr.model.InvoiceLog;
import com.cowr.model.InvoiceReceive;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
@ -22,21 +21,17 @@ import java.util.List;
public class InvoiceLogService extends BaseService { public class InvoiceLogService extends BaseService {
public static final InvoiceLogService me = new InvoiceLogService(); public static final InvoiceLogService me = new InvoiceLogService();
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;
}
public Page<Record> find(PageParam pp, Integer state, String order_sn, String stm, String etm, String code, Integer invoice_type) { public Page<Record> find(PageParam pp, Integer state, String order_sn, String stm, String etm, String code, Integer invoice_type) {
String selectsql = "select * "; String selectsql = "select t.*, \n" +
String fromsql = "from invoice_log t where 1=1 \n"; " case when t.type = 1 then s.weight when t.type = 3 then p.weight end weight, \n" +
" case when t.type = 1 then s.total_price when t.type = 3 then p.total_price end total_price, \n" +
" case when t.type = 1 then s.create_time when t.type = 3 then p.create_time end create_time, \n" +
" case when t.type = 1 then s.settlement_user_name when t.type = 3 then p.settlement_user_name end settlement_user_name, \n" +
" case when t.type = 1 then s.customer_name when t.type = 3 then p.customer_name end customer_name ";
String fromsql = "from invoice_log t \n" +
" left join order_sale s on s.sn = t.order_sn \n" +
" left join order_temp p on p.sn = t.order_sn \n" +
" where 1=1 \n";
List<Object> paraList = new ArrayList<>(); List<Object> paraList = new ArrayList<>();
if (state != null) { if (state != null) {

View File

@ -3,8 +3,10 @@ package com.cowr.ssjygl.invoice.receive;
import com.cowr.common.Const; import com.cowr.common.Const;
import com.cowr.common.base.BaseService; import com.cowr.common.base.BaseService;
import com.cowr.common.view.PageParam; import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result;
import com.cowr.model.InvoiceReceive; import com.cowr.model.InvoiceReceive;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
@ -19,6 +21,7 @@ import java.util.List;
* PrimaryKey: id * PrimaryKey: id
*/ */
public class InvoiceReceiveService extends BaseService { public class InvoiceReceiveService extends BaseService {
private static Log log = Log.getLog(InvoiceReceiveService.class);
public static final InvoiceReceiveService me = new InvoiceReceiveService(); public static final InvoiceReceiveService me = new InvoiceReceiveService();
public InvoiceReceive foremostReceive(int supermarket_id) { public InvoiceReceive foremostReceive(int supermarket_id) {
@ -33,6 +36,37 @@ public class InvoiceReceiveService extends BaseService {
return receive; return receive;
} }
public String nextInvoice(InvoiceReceive receive) {
if (receive == null) {
log.debug("没有有效的领用记录");
return null;
}
if (receive.getSurplus() == 0) {
log.debug("没有可用发票");
return null;
}
if (receive.getCurrentCode() == null) {
return receive.getStartCode();
} else {
return String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode()) + 1);
}
}
/**
*
* TODO:
* @param supermarket_id
* @return
*/
public String nextInvoice(int supermarket_id) {
InvoiceReceive receive = foremostReceive(supermarket_id);
return nextInvoice(receive);
}
public Page<Record> find(PageParam pp) { public Page<Record> find(PageParam pp) {
String selectsql = "select * "; String selectsql = "select * ";
String fromsql = "from invoice_receive t where 1=1 "; String fromsql = "from invoice_receive t where 1=1 ";

View File

@ -2,7 +2,9 @@ package com.cowr.local.ssjygl.invoice.log;
import com.cowr.common.view.PageParam; import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result; import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
import com.cowr.model.InvoiceLog; import com.cowr.model.InvoiceLog;
import com.cowr.model.Sysuser;
import com.cowr.ssjygl.invoice.log.InvoiceLogPKValidator; import com.cowr.ssjygl.invoice.log.InvoiceLogPKValidator;
import com.cowr.ssjygl.invoice.log.InvoiceLogService; import com.cowr.ssjygl.invoice.log.InvoiceLogService;
import com.jfinal.aop.Before; import com.jfinal.aop.Before;
@ -59,4 +61,47 @@ public class InvoiceLogController extends Controller {
InvoiceLog model = getModel(InvoiceLog.class, "", true); // 忽略不在model中的字段 InvoiceLog model = getModel(InvoiceLog.class, "", true); // 忽略不在model中的字段
renderJson(InvoiceLogService.me.findByPk(model)); renderJson(InvoiceLogService.me.findByPk(model));
} }
public void cancel() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
renderJson(Result.noauth());
return;
}
String id = get("id");
String invalid_memo = get("invalid_memo");
renderJson(InvoiceLogSyncService.me.cancel(id, invalid_memo, tokenuser));
}
public void cancelByCode() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
renderJson(Result.noauth());
return;
}
String code = get("code");
String invalid_memo = get("invalid_memo");
renderJson(InvoiceLogSyncService.me.cancelByCode(code, invalid_memo, tokenuser));
}
public void invalid() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
renderJson(Result.noauth());
return;
}
Integer supermarket_id = getInt("supermarket_id", 0);
String code = get("code");
String invalid_memo = get("invalid_memo");
renderJson(InvoiceLogSyncService.me.invalid(supermarket_id, code, invalid_memo, tokenuser));
}
} }

View File

@ -2,16 +2,20 @@ package com.cowr.local.ssjygl.invoice.log;
import com.cowr.common.base.BaseModel; import com.cowr.common.base.BaseModel;
import com.cowr.common.enums.Enums; import com.cowr.common.enums.Enums;
import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.view.Result; import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.base.BaseSyncService; import com.cowr.local.ssjygl.base.BaseSyncService;
import com.cowr.local.ssjygl.order.OrderService; import com.cowr.local.ssjygl.order.OrderService;
import com.cowr.local.ssjygl.synctask.SyncTaskService; import com.cowr.local.ssjygl.synctask.SyncTaskService;
import com.cowr.model.*; import com.cowr.model.*;
import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService;
import com.cowr.ssjygl.modifylog.ModifyLogService; import com.cowr.ssjygl.modifylog.ModifyLogService;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log; import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom; import com.jfinal.plugin.activerecord.IAtom;
import java.sql.SQLException;
import java.util.Date; import java.util.Date;
public class InvoiceLogSyncService extends BaseSyncService { public class InvoiceLogSyncService extends BaseSyncService {
@ -22,34 +26,125 @@ public class InvoiceLogSyncService extends BaseSyncService {
* 使 * 使
* @return * @return
*/ */
public Result save(String code, String invalid_memo, Sysuser sysuser){ public Result invalid(int supermarket_id, String code, String invalid_memo, Sysuser sysuser){
return null; Supermarket supermarket = Supermarket.dao.findById(supermarket_id);
if(supermarket == null){
return Result.failed("未找到超市信息");
} }
/** InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t where code = ? limit 1 ", code);
* 使
* @param id if (invoiceLog != null) {
* @param sysuser return Result.failed("发票已使用,请使用“取消发票”功能");
* @return }
*/
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(supermarket_id);
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
return Result.failed("没有可用发票");
}
if(!next_invoice_code.equals(code)){
return Result.failed("只能按顺序作废发票");
}
invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvalidUserId(sysuser.getId());
invoiceLog.setInvalidUserName(sysuser.getName());
invoiceLog.setInvalidTime(new Date());
invoiceLog.setInvalidMemo(invalid_memo);
invoiceLog.setState(OrderStateEnum.INVALID.getStateid());
invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(code);
InvoiceLog finalInvoiceLog = invoiceLog;
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() throws SQLException {
try {
boolean ret = finalInvoiceLog.save();
if(!ret){
return false;
}
SyncTask synctask = new SyncTask();
synctask.addSaveData(finalInvoiceLog);
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(next_invoice_code);
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", next_invoice_code);
return false;
}
synctask.addUpdateData(receive);
return SyncTaskService.me.save(synctask)
&& ModifyLogService.me.save(finalInvoiceLog, null, Enums.DataOpType.SAVE.getId(), sysuser);
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
}
}
});
return ret ? Result.success(invoiceLog) : Result.failed(false, "处理失败");
}
public Result cancelByCode(String code, String invalid_memo, Sysuser sysuser){
InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t where code = ? limit 1 ", code);
if (invoiceLog == null) {
return Result.failed("未找到发票记录");
}
return cancel(invoiceLog, invalid_memo, sysuser);
}
public Result cancel(String id, String invalid_memo, Sysuser sysuser){ public Result cancel(String id, String invalid_memo, Sysuser sysuser){
InvoiceLog invoiceLog = InvoiceLog.dao.findById(id); InvoiceLog invoiceLog = InvoiceLog.dao.findById(id);
if(invoiceLog == null){ if(invoiceLog == null){
return Result.failed("未找到记录"); return Result.failed("未找到发票记录");
}
return cancel(invoiceLog, invalid_memo, sysuser);
}
/**
* 使
* @param invoiceLog
* @param sysuser
* @return
*/
public Result cancel(InvoiceLog invoiceLog, String invalid_memo, Sysuser sysuser){
if(invoiceLog.getState() == OrderStateEnum.INVALID.getStateid()){
return Result.failed("记录已作废");
} }
InvoiceLog old = invoiceLog.clone(); InvoiceLog old = invoiceLog.clone();
BaseModel order = OrderService.me.getOrderBySn(invoiceLog.getOrderSn()); BaseModel order = OrderService.me.getOrderBySn(invoiceLog.getOrderSn());
if(order == null){ if(order == null){
return Result.failedstr("按[%s]未找到订单信息"); return Result.failedstr("未找到订单信息");
} }
invoiceLog.setInvalidMemo(invalid_memo); invoiceLog.setInvalidMemo(invalid_memo);
invoiceLog.setInvalidTime(new Date()); invoiceLog.setInvalidTime(new Date());
invoiceLog.setInvalidUserId(sysuser.getId()); invoiceLog.setInvalidUserId(sysuser.getId());
invoiceLog.setInvalidUserName(sysuser.getName()); invoiceLog.setInvalidUserName(sysuser.getName());
invoiceLog.setState(OrderStateEnum.INVALID.getStateid());
boolean ret = Db.tx(new IAtom() { boolean ret = Db.tx(new IAtom() {
@Override @Override

View File

@ -53,4 +53,22 @@ public class InvoiceReceiveController extends Controller {
InvoiceReceive model = getModel(InvoiceReceive.class, "", true); // 忽略不在model中的字段 InvoiceReceive model = getModel(InvoiceReceive.class, "", true); // 忽略不在model中的字段
renderJson(InvoiceReceiveService.me.findByPk(model)); renderJson(InvoiceReceiveService.me.findByPk(model));
} }
public void nextInvoice() {
Integer supermarket_id = getInt("supermarket_id", 0);
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(supermarket_id);
if (receive == null) {
renderJson(Result.failed("没有有效的领用记录"));
return;
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
renderJson(Result.failed("没有可用发票"));
return;
}
renderJson(Result.success(next_invoice_code));
}
} }

View File

@ -10,20 +10,14 @@ import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.actioncmdlog.ActionCmdLogService; import com.cowr.local.ssjygl.actioncmdlog.ActionCmdLogService;
import com.cowr.local.ssjygl.devicectrl.common.Const; import com.cowr.local.ssjygl.devicectrl.common.Const;
import com.cowr.local.ssjygl.devicectrl.printer.ExcelHelper; import com.cowr.local.ssjygl.devicectrl.printer.ExcelHelper;
import com.cowr.local.ssjygl.invoice.log.InvoiceLogSyncService;
import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.main.Config;
import com.cowr.local.ssjygl.synctask.SyncTaskService;
import com.cowr.local.ssjygl.transport.TransportDeviceService; import com.cowr.local.ssjygl.transport.TransportDeviceService;
import com.cowr.model.*; import com.cowr.model.*;
import com.cowr.ssjygl.CacheData; import com.cowr.ssjygl.CacheData;
import com.cowr.ssjygl.invoice.log.InvoiceLogService;
import com.cowr.ssjygl.modifylog.ModifyLogService;
import com.cowr.ssjygl.transprice.TransPriceService; import com.cowr.ssjygl.transprice.TransPriceService;
import com.jfinal.kit.PathKit; import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import com.jfinal.log.Log; import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
@ -31,7 +25,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -553,127 +546,6 @@ public class OrderService {
return Result.success("打印指令已发送"); return Result.success("打印指令已发送");
} }
/**
*
*
* @param sn
* @param printerId
* @param sysuser
* @return
*/
public Result printInvoice(String sn, String printerId, Sysuser sysuser) {
if (StrKit.isBlank(sn)) {
return Result.failed("sn 不能为 null");
}
int sntype = Integer.parseInt(sn.substring(10, 12));
if (sntype != OrderTypeEnum.SALE.getTypeid() && sntype != OrderTypeEnum.TEMP.getTypeid()) {
return Result.failed("订单类型错误,只有配送订单和外销订单才能开具发票");
}
BaseModel order = getOrderBySn(sn);
if (order == null) {
return Result.failed("未找到订单信息");
}
if (order.getInt("state") != OrderStateEnum.RECEIVED.getStateid()) {
return Result.failed("订单未完成、或者已经取消");
}
if (sntype == OrderTypeEnum.SALE.getTypeid()) {
if (((OrderSale) order).getInvoiceCode() != null) {
return Result.failed("已经开具了发票。若需重新开票,请将旧的发票作废"); // TODO: 发票作废的流程
}
} else if (sntype == OrderTypeEnum.TEMP.getTypeid()) {
if (((OrderTemp) order).getInvoiceCode() != null) {
return Result.failed("已经开具了发票。若需重新开票,请将旧的发票作废"); // TODO: 发票作废的流程
}
} else {
return Result.failed("订单类型错误,只有配送订单和外销订单才能开具发票");
}
InvoiceReceive receive = InvoiceLogService.me.lastReceive(order.getInt("supermarket_id"));
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
if (receive.getSurplus() == 0) {
return Result.failed("没有可用发票");
}
String next_invoice_code;
if (receive.getCurrentCode() == null) {
next_invoice_code = receive.getStartCode();
} else {
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode()) + 1);
}
order.set("invoice_code", next_invoice_code);
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
Record logrecord = new Record();
logrecord.set("sn", sn);
logrecord.set("invoice_code", next_invoice_code);
SyncTask synctask = new SyncTask();
boolean ret = order.update();
if (!ret) {
log.error("跟新订单 %s 开票信息失败", next_invoice_code);
return false;
}
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(next_invoice_code);
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", next_invoice_code);
return false;
}
synctask.addUpdateData(receive);
synctask.addUpdateData(order);
return SyncTaskService.me.save(synctask)
&& ModifyLogService.me.save(order.getTablename(), "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser);
}
});
Transport transport = Transport.dao.findById(order.get("transport_id"));
if (transport == null) {
return Result.failed("运输记录不存在");
}
Record printdata = order.toRecord();
printdata.set("first_weight", transport.getFirstWeight());
printdata.set("second_weight", transport.getSecondWeight());
try {
Config.deviceThread.print(printerId, getPrintFile(printdata));
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.failed("打印指令失败");
}
Record cmd = new Record();
cmd.set("cmd", "print");
cmd.set("sn", sn);
cmd.set("printer", printerId);
ActionCmdLogService.me.save(cmd.toJson(), sysuser);
return Result.success("打印指令已发送");
}
/** /**
* sn * sn
* *

View File

@ -114,13 +114,14 @@ public class OrderTempController extends BaseController {
} }
String sn = get("sn"); String sn = get("sn");
String invalid_memo = get("invalid_memo");
String password = get("password"); String password = get("password");
renderJson(OrderTempSyncService.me.cancel(sn, tokenuser, password)); renderJson(OrderTempSyncService.me.cancel(sn, invalid_memo, tokenuser, password));
} }
@Before(SnValidator.class) @Before(SnValidator.class)
public void print() { public void invoice() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) { if (tokenuser == null) {
@ -134,7 +135,7 @@ public class OrderTempController extends BaseController {
if (Integer.parseInt(sn.substring(10, 12)) != OrderTypeEnum.TEMP.getTypeid()) { if (Integer.parseInt(sn.substring(10, 12)) != OrderTypeEnum.TEMP.getTypeid()) {
renderJson(Result.failed("sn 不能为 null")); renderJson(Result.failed("sn 不能为 null"));
} else { } else {
renderJson(OrderService.me.print(sn, printer, tokenuser)); renderJson(OrderTempSyncService.me.invoice(sn, printer, tokenuser));
} }
} }
} }

View File

@ -5,6 +5,7 @@ import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.enums.OrderTypeEnum; import com.cowr.common.enums.OrderTypeEnum;
import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.utils.DateTimeUtil;
import com.cowr.common.view.Result; import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.actioncmdlog.ActionCmdLogService;
import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.main.Config;
import com.cowr.local.ssjygl.order.OrderService; import com.cowr.local.ssjygl.order.OrderService;
import com.cowr.local.ssjygl.order.orderseq.OrderSeqService; import com.cowr.local.ssjygl.order.orderseq.OrderSeqService;
@ -24,6 +25,7 @@ import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Date; import java.util.Date;
public class OrderTempSyncService { public class OrderTempSyncService {
@ -50,6 +52,16 @@ public class OrderTempSyncService {
return Result.failed("进出场记录已完结或者已作废,不能使用"); return Result.failed("进出场记录已完结或者已作废,不能使用");
} }
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
return Result.failed("没有可用发票");
}
Product product = Product.dao.findById(product_id); Product product = Product.dao.findById(product_id);
if (product == null) { if (product == null) {
@ -66,8 +78,6 @@ public class OrderTempSyncService {
Date now = new Date(); Date now = new Date();
SyncTask synctask = new SyncTask(); SyncTask synctask = new SyncTask();
OrderTemp order = new OrderTemp(); OrderTemp order = new OrderTemp();
InvoiceReceive receive = null;
String next_invoice_code = null;
order.setUuid(uuid); order.setUuid(uuid);
@ -92,22 +102,6 @@ public class OrderTempSyncService {
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次 BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
if (receive.getSurplus() == 0) {
return Result.failed("没有可用发票");
}
if (receive.getCurrentCode() == null) {
next_invoice_code = receive.getStartCode();
} else {
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode()) + 1);
}
order.setInvoiceCode(next_invoice_code); order.setInvoiceCode(next_invoice_code);
// } // }
@ -144,7 +138,6 @@ public class OrderTempSyncService {
transport.setState(order.getState()); // 使用 order 的 state transport.setState(order.getState()); // 使用 order 的 state
transport.setType(OrderTypeEnum.TEMP.getTypeid()); transport.setType(OrderTypeEnum.TEMP.getTypeid());
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code; String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() { boolean ret = Db.tx(new IAtom() {
@Override @Override
@ -174,10 +167,10 @@ public class OrderTempSyncService {
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了 // 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1); receive.setSurplus(receive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code); receive.setCurrentCode(finalNext_invoice_code);
ret = finalReceive.update(); ret = receive.update();
if (!ret) { if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code); log.error("发票领用信息更新失败", finalNext_invoice_code);
@ -186,7 +179,7 @@ public class OrderTempSyncService {
InvoiceLog invoiceLog = new InvoiceLog(); InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID()); invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(finalReceive.getId()); invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(finalNext_invoice_code); invoiceLog.setCode(finalNext_invoice_code);
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
invoiceLog.setSettlementTime(now); invoiceLog.setSettlementTime(now);
@ -202,7 +195,7 @@ public class OrderTempSyncService {
} }
synctask.addSaveData(invoiceLog); synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive); synctask.addUpdateData(receive);
// } // }
synctask.addUpdateData(transport); synctask.addUpdateData(transport);
@ -243,6 +236,16 @@ public class OrderTempSyncService {
return Result.failed("进出场记录已完结或者已作废,不能使用"); return Result.failed("进出场记录已完结或者已作废,不能使用");
} }
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
return Result.failed("没有可用发票");
}
Ordercluster ordercluster = Ordercluster.dao.findById(ordercluster_id); Ordercluster ordercluster = Ordercluster.dao.findById(ordercluster_id);
if (ordercluster == null) { if (ordercluster == null) {
return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id); return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id);
@ -277,8 +280,6 @@ public class OrderTempSyncService {
Date now = new Date(); Date now = new Date();
SyncTask synctask = new SyncTask(); SyncTask synctask = new SyncTask();
OrderTemp order = new OrderTemp(); OrderTemp order = new OrderTemp();
InvoiceReceive receive = null;
String next_invoice_code = null;
order.setUuid(uuid); order.setUuid(uuid);
@ -301,29 +302,13 @@ public class OrderTempSyncService {
} }
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次 BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
BigDecimal overweight = OrderclusterService.me.getOverWeight(ordercluster_id); // 集团订单剩余 BigDecimal overweight = OrderclusterService.me.getOverWeight(ordercluster_id); // 集团订单已完成
// 不能超过集团订单剩余量 // 不能超过集团订单剩余量
if (net_weight.compareTo(overweight) > 0) { if (net_weight.compareTo(ordercluster.getTotalWeight().subtract(overweight)) > 0) {
return Result.failedstr("净重 %.2f 吨,超过了剩余的 %.2f 余量", net_weight, overweight); return Result.failedstr("净重 %.2f 吨,超过了剩余的 %.2f 余量", net_weight, overweight);
} }
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
if (receive.getSurplus() == 0) {
return Result.failed("没有可用发票");
}
if (receive.getCurrentCode() == null) {
next_invoice_code = receive.getStartCode();
} else {
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode()) + 1);
}
order.setInvoiceCode(next_invoice_code); order.setInvoiceCode(next_invoice_code);
// } // }
@ -385,9 +370,6 @@ public class OrderTempSyncService {
transport.setArriveTime(now); transport.setArriveTime(now);
transport.setType(OrderTypeEnum.TEMP.getTypeid()); transport.setType(OrderTypeEnum.TEMP.getTypeid());
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() { boolean ret = Db.tx(new IAtom() {
@Override @Override
public boolean run() { public boolean run() {
@ -429,20 +411,20 @@ public class OrderTempSyncService {
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了 // 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1); receive.setSurplus(receive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code); receive.setCurrentCode(next_invoice_code);
ret = finalReceive.update(); ret = receive.update();
if (!ret) { if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code); log.error("发票领用信息更新失败", next_invoice_code);
return false; return false;
} }
InvoiceLog invoiceLog = new InvoiceLog(); InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID()); invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(finalReceive.getId()); invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(finalNext_invoice_code); invoiceLog.setCode(next_invoice_code);
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
invoiceLog.setSettlementTime(now); invoiceLog.setSettlementTime(now);
invoiceLog.setSettlementUserId(order.getSettlementUserId()); // 发票使用人 invoiceLog.setSettlementUserId(order.getSettlementUserId()); // 发票使用人
@ -457,7 +439,7 @@ public class OrderTempSyncService {
} }
synctask.addSaveData(invoiceLog); synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive); synctask.addUpdateData(receive);
// } // }
// 在这里更新sn字段之后存入 // 在这里更新sn字段之后存入
@ -503,6 +485,16 @@ public class OrderTempSyncService {
return Result.failed("进出场记录已完结或者已作废,不能使用"); return Result.failed("进出场记录已完结或者已作废,不能使用");
} }
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
return Result.failed("没有可用发票");
}
OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" + OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" +
" where t.truck_license = ? \n" + " where t.truck_license = ? \n" +
" and t.ordercluster_id = ? ", " and t.ordercluster_id = ? ",
@ -598,26 +590,8 @@ public class OrderTempSyncService {
Date now = new Date(); Date now = new Date();
SyncTask synctask = new SyncTask(); SyncTask synctask = new SyncTask();
InvoiceReceive receive = null;
String next_invoice_code = null;
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
if (receive.getSurplus() == 0) {
return Result.failed("没有可用发票");
}
if (receive.getCurrentCode() == null) {
next_invoice_code = receive.getStartCode();
} else {
next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode()) + 1);
}
order.setInvoiceCode(next_invoice_code); order.setInvoiceCode(next_invoice_code);
// } // }
@ -665,8 +639,6 @@ public class OrderTempSyncService {
return Result.failedstr("总价 %.2f,客户余额(%.2f)不足以支付"); return Result.failedstr("总价 %.2f,客户余额(%.2f)不足以支付");
} }
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() { boolean ret = Db.tx(new IAtom() {
@Override @Override
public boolean run() { public boolean run() {
@ -727,20 +699,20 @@ public class OrderTempSyncService {
// if (req_receipt == 1) { // 需要同时开具发票 // if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了 // 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1); receive.setSurplus(receive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code); receive.setCurrentCode(next_invoice_code);
ret = finalReceive.update(); ret = receive.update();
if (!ret) { if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code); log.error("发票领用信息更新失败", next_invoice_code);
return false; return false;
} }
InvoiceLog invoiceLog = new InvoiceLog(); InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID()); invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(finalReceive.getId()); invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(finalNext_invoice_code); invoiceLog.setCode(next_invoice_code);
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
invoiceLog.setSettlementTime(now); invoiceLog.setSettlementTime(now);
invoiceLog.setSettlementUserId(order.getSettlementUserId()); invoiceLog.setSettlementUserId(order.getSettlementUserId());
@ -755,7 +727,7 @@ public class OrderTempSyncService {
} }
synctask.addSaveData(invoiceLog); synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive); synctask.addUpdateData(receive);
// } // }
// 在这里更新sn字段之后存入 // 在这里更新sn字段之后存入
@ -774,8 +746,7 @@ public class OrderTempSyncService {
return OrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId); return OrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId);
} }
public Result cancel(String sn, String invalid_memo, Sysuser sysuser, String password) {
public Result cancel(String sn, Sysuser sysuser, String password) {
// TODO: 判断权限 // TODO: 判断权限
OrderTemp order = OrderTemp.dao.findById(sn); OrderTemp order = OrderTemp.dao.findById(sn);
@ -801,7 +772,6 @@ public class OrderTempSyncService {
return Result.failed("订单已经取消"); return Result.failed("订单已经取消");
} }
int oldstate = order.getState();
order.setState(OrderStateEnum.INVALID.getStateid()); // 将订单状态置为 9 order.setState(OrderStateEnum.INVALID.getStateid()); // 将订单状态置为 9
Record logrecord = new Record(); Record logrecord = new Record();
@ -815,8 +785,7 @@ public class OrderTempSyncService {
SyncTask synctask = new SyncTask(); SyncTask synctask = new SyncTask();
synctask.addUpdateData(order); synctask.addUpdateData(order);
boolean ret = order.update() boolean ret = order.update();
&& ModifyLogService.me.save(order.tablename, "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser);
if (!ret) { if (!ret) {
return false; return false;
@ -835,13 +804,36 @@ public class OrderTempSyncService {
// } // }
// 是集团客户订单 // 是集团客户订单
if (order.getOrderclusterId() != null) { // if (order.getOrderclusterId() != null) {
Ordercluster ordercluster = Ordercluster.dao.findById(order.getOrderclusterId()); // Ordercluster ordercluster = Ordercluster.dao.findById(order.getOrderclusterId());
//
// if (ordercluster == null) {
// log.error("关联集团订单信息未找到ordercluster_id:【%s】", order.getOrderclusterId());
// return false;
// }
// }
if (ordercluster == null) { // 已开具发票
log.error("关联集团订单信息未找到ordercluster_id:【%s】", order.getOrderclusterId()); if (order.getInvoiceCode() != null) {
InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t where code = ? limit 1 ", order.getInvoiceCode());
if (invoiceLog != null) {
invoiceLog.setInvalidUserId(sysuser.getId());
invoiceLog.setInvalidUserName(sysuser.getName());
invoiceLog.setInvalidTime(new Date());
invoiceLog.setInvalidMemo(invalid_memo);
invoiceLog.setState(OrderStateEnum.INVALID.getStateid());
ret = invoiceLog.update();
if (!ret) {
return false; return false;
} }
synctask.addUpdateData(invoiceLog);
} else {
log.error("订单[%s]没有找到开票记录", order.getSn());
}
} }
// 是预付费订单 // 是预付费订单
@ -884,7 +876,8 @@ public class OrderTempSyncService {
synctask.addUpdateData(stock); synctask.addUpdateData(stock);
return ret && SyncTaskService.me.save(synctask); return ret && SyncTaskService.me.save(synctask)
&& ModifyLogService.me.save(order.tablename, "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
return false; return false;
@ -894,4 +887,121 @@ public class OrderTempSyncService {
return ret ? Result.success(order) : Result.failed("取消失败"); return ret ? Result.success(order) : Result.failed("取消失败");
} }
public Result invoice(String sn, String printerId, Sysuser sysuser) {
// TODO: 判断权限
OrderTemp order = OrderTemp.dao.findById(sn);
if (order == null) {
return Result.failedstr("按订单号【%s】未找到记录", sn);
}
int orderstate = order.getState();
if (orderstate == OrderStateEnum.INVALID.getStateid()) {
return Result.failed("订单已经取消");
}
InvoiceReceive receive = InvoiceReceiveService.me.foremostReceive(order.getSupermarketId());
if (receive == null) {
return Result.failed("没有有效的领用记录");
}
String next_invoice_code = InvoiceReceiveService.me.nextInvoice(receive);
if (next_invoice_code == null) {
return Result.failed("没有可用发票");
}
if (StrKit.notBlank(order.getInvoiceCode())) {
return Result.failedstr("请先将已开具的发票[%s]取消", order.getInvoiceCode());
}
order.setInvoiceCode(next_invoice_code);
Record logrecord = new Record();
logrecord.set("sn", sn);
logrecord.set("invoice", next_invoice_code);
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
try{
boolean ret = order.update();
if (!ret) {
return false;
}
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(next_invoice_code);
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", next_invoice_code);
return false;
}
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(next_invoice_code);
invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid());
invoiceLog.setSettlementTime(new Date());
invoiceLog.setSettlementUserId(order.getSettlementUserId());
invoiceLog.setSettlementUserName(order.getSettlementUserName());
invoiceLog.setOrderSn(order.getSn());
invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid());
ret = invoiceLog.save();
if (!ret) {
return false;
}
SyncTask synctask = new SyncTask();
synctask.addUpdateData(order);
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(receive);
return ret && SyncTaskService.me.save(synctask)
&& ModifyLogService.me.save(order.tablename, "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser);
}catch (Exception e){
log.error(e.getMessage(), e);
return false;
}
}
});
if(ret){
Transport transport = Transport.dao.findById(order.get("transport_id"));
if (transport == null) {
return Result.failed("运输记录不存在");
}
Record printdata = order.toRecord();
printdata.set("first_weight", transport.getFirstWeight());
printdata.set("second_weight", transport.getSecondWeight());
try {
Config.deviceThread.print(printerId, OrderService.me.getPrintFile(printdata));
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.failed("打印指令失败");
}
Record cmd = new Record();
cmd.set("cmd", "print");
cmd.set("sn", sn);
cmd.set("printer", printerId);
ActionCmdLogService.me.save(cmd.toJson(), sysuser);
return Result.success("开票成功,打印指令已发送");
}
return Result.failed("开票失败");
}
} }

View File

@ -8,6 +8,7 @@ import com.cowr.common.utils.ImageUtil;
import com.cowr.common.view.Result; import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.main.Config;
import com.cowr.local.ssjygl.order.OrderService; import com.cowr.local.ssjygl.order.OrderService;
import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService;
import com.cowr.ssjygl.order.ordercluster.truck.OrderclusterTruckService; import com.cowr.ssjygl.order.ordercluster.truck.OrderclusterTruckService;
import com.cowr.ssjygl.supermarket.product.SupermarketProductService; import com.cowr.ssjygl.supermarket.product.SupermarketProductService;
import com.cowr.model.*; import com.cowr.model.*;
@ -119,6 +120,8 @@ public class TransportQueryService {
} }
} }
transobj.set("next_invoice_code", InvoiceReceiveService.me.nextInvoice(transport.getSupermarketId())); // TODO 专票?
return Result.success(transobj); return Result.success(transobj);
} }