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.view.PageParam;
import com.cowr.model.InvoiceLog;
import com.cowr.model.InvoiceReceive;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
@ -22,22 +21,18 @@ import java.util.List;
public class InvoiceLogService extends BaseService {
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) {
String selectsql = "select * ";
String fromsql = "from invoice_log t where 1=1 \n";
List<Object> paraList = new ArrayList<>();
String selectsql = "select t.*, \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<>();
if (state != null) {
fromsql += " and t.state = ? \n";

View File

@ -3,8 +3,10 @@ package com.cowr.ssjygl.invoice.receive;
import com.cowr.common.Const;
import com.cowr.common.base.BaseService;
import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result;
import com.cowr.model.InvoiceReceive;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
@ -19,7 +21,8 @@ import java.util.List;
* PrimaryKey: id
*/
public class InvoiceReceiveService extends BaseService {
public static final InvoiceReceiveService me = new InvoiceReceiveService();
private static Log log = Log.getLog(InvoiceReceiveService.class);
public static final InvoiceReceiveService me = new InvoiceReceiveService();
public InvoiceReceive foremostReceive(int supermarket_id) {
String sql = "select * from invoice_receive t\n" +
@ -33,6 +36,37 @@ public class InvoiceReceiveService extends BaseService {
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) {
String selectsql = "select * ";
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.Result;
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
import com.cowr.model.InvoiceLog;
import com.cowr.model.Sysuser;
import com.cowr.ssjygl.invoice.log.InvoiceLogPKValidator;
import com.cowr.ssjygl.invoice.log.InvoiceLogService;
import com.jfinal.aop.Before;
@ -59,4 +61,47 @@ public class InvoiceLogController extends Controller {
InvoiceLog model = getModel(InvoiceLog.class, "", true); // 忽略不在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.enums.Enums;
import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.base.BaseSyncService;
import com.cowr.local.ssjygl.order.OrderService;
import com.cowr.local.ssjygl.synctask.SyncTaskService;
import com.cowr.model.*;
import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService;
import com.cowr.ssjygl.modifylog.ModifyLogService;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import java.sql.SQLException;
import java.util.Date;
public class InvoiceLogSyncService extends BaseSyncService {
@ -22,34 +26,125 @@ public class InvoiceLogSyncService extends BaseSyncService {
* 使
* @return
*/
public Result save(String code, String invalid_memo, Sysuser sysuser){
return null;
public Result invalid(int supermarket_id, String code, String invalid_memo, Sysuser sysuser){
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);
if (invoiceLog != null) {
return Result.failed("发票已使用,请使用“取消发票”功能");
}
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, "处理失败");
}
/**
* 使
* @param id
* @param sysuser
* @return
*/
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){
InvoiceLog invoiceLog = InvoiceLog.dao.findById(id);
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();
BaseModel order = OrderService.me.getOrderBySn(invoiceLog.getOrderSn());
if(order == null){
return Result.failedstr("按[%s]未找到订单信息");
return Result.failedstr("未找到订单信息");
}
invoiceLog.setInvalidMemo(invalid_memo);
invoiceLog.setInvalidTime(new Date());
invoiceLog.setInvalidUserId(sysuser.getId());
invoiceLog.setInvalidUserName(sysuser.getName());
invoiceLog.setState(OrderStateEnum.INVALID.getStateid());
boolean ret = Db.tx(new IAtom() {
@Override

View File

@ -23,7 +23,7 @@ public class InvoiceReceiveController extends Controller {
* data = false
*/
@Before(InvoiceReceivePKValidator.class)
public void checkExistsByPk(){
public void checkExistsByPk() {
InvoiceReceive model = getModel(InvoiceReceive.class, "", true); // 忽略不在model中的字段
renderJson(InvoiceReceiveService.me.checkExistsByPk(model));
}
@ -31,7 +31,7 @@ public class InvoiceReceiveController extends Controller {
/**
* invoice_receive -
*/
public void find(){
public void find() {
PageParam pp = getBean(PageParam.class, "", true);
renderJson(Result.object(InvoiceReceiveService.me.find(pp)));
}
@ -40,7 +40,7 @@ public class InvoiceReceiveController extends Controller {
* invoice_receive -
*/
@Before(InvoiceReceivePKValidator.class)
public void findByPk(){
public void findByPk() {
InvoiceReceive model = getModel(InvoiceReceive.class, "", true); // 忽略不在model中的字段
renderJson(InvoiceReceiveService.me.findByPk(model));
}
@ -49,8 +49,26 @@ public class InvoiceReceiveController extends Controller {
* invoice_receive -
*/
@Before(InvoiceReceivePKValidator.class)
public void get(){
public void get() {
InvoiceReceive model = getModel(InvoiceReceive.class, "", true); // 忽略不在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.devicectrl.common.Const;
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.synctask.SyncTaskService;
import com.cowr.local.ssjygl.transport.TransportDeviceService;
import com.cowr.model.*;
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.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.ss.usermodel.Workbook;
@ -31,7 +25,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@ -553,127 +546,6 @@ public class OrderService {
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
*

View File

@ -114,13 +114,14 @@ public class OrderTempController extends BaseController {
}
String sn = get("sn");
String invalid_memo = get("invalid_memo");
String password = get("password");
renderJson(OrderTempSyncService.me.cancel(sn, tokenuser, password));
renderJson(OrderTempSyncService.me.cancel(sn, invalid_memo, tokenuser, password));
}
@Before(SnValidator.class)
public void print() {
public void invoice() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -134,7 +135,7 @@ public class OrderTempController extends BaseController {
if (Integer.parseInt(sn.substring(10, 12)) != OrderTypeEnum.TEMP.getTypeid()) {
renderJson(Result.failed("sn 不能为 null"));
} 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.utils.DateTimeUtil;
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.order.OrderService;
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 java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Date;
public class OrderTempSyncService {
@ -50,6 +52,16 @@ public class OrderTempSyncService {
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);
if (product == null) {
@ -62,12 +74,10 @@ public class OrderTempSyncService {
return Result.failedstr("未查到有效的单价信息");
}
BigDecimal min = new BigDecimal(0.001);
Date now = new Date();
SyncTask synctask = new SyncTask();
OrderTemp order = new OrderTemp();
InvoiceReceive receive = null;
String next_invoice_code = null;
BigDecimal min = new BigDecimal(0.001);
Date now = new Date();
SyncTask synctask = new SyncTask();
OrderTemp order = new OrderTemp();
order.setUuid(uuid);
@ -92,23 +102,7 @@ public class OrderTempSyncService {
BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次
// 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);
// }
order.setTransportId(transport.getId());
@ -144,7 +138,6 @@ public class OrderTempSyncService {
transport.setState(order.getState()); // 使用 order 的 state
transport.setType(OrderTypeEnum.TEMP.getTypeid());
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() {
@Override
@ -173,36 +166,36 @@ public class OrderTempSyncService {
}
// if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code);
// 这里的 finalReceive 在前面肯定验证过了
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(finalNext_invoice_code);
ret = finalReceive.update();
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code);
return false;
}
if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code);
return false;
}
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());
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(receive.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());
ret = invoiceLog.save();
ret = invoiceLog.save();
if (!ret) {
return false;
}
if (!ret) {
return false;
}
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive);
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(receive);
// }
synctask.addUpdateData(transport);
@ -243,6 +236,16 @@ public class OrderTempSyncService {
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);
if (ordercluster == null) {
return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id);
@ -277,8 +280,6 @@ public class OrderTempSyncService {
Date now = new Date();
SyncTask synctask = new SyncTask();
OrderTemp order = new OrderTemp();
InvoiceReceive receive = null;
String next_invoice_code = null;
order.setUuid(uuid);
@ -301,30 +302,14 @@ public class OrderTempSyncService {
}
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);
}
// 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);
// }
order.setTransportId(transport.getId());
@ -385,9 +370,6 @@ public class OrderTempSyncService {
transport.setArriveTime(now);
transport.setType(OrderTypeEnum.TEMP.getTypeid());
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
@ -428,36 +410,36 @@ public class OrderTempSyncService {
}
// if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code);
// 这里的 finalReceive 在前面肯定验证过了
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(next_invoice_code);
ret = finalReceive.update();
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code);
return false;
}
if (!ret) {
log.error("发票领用信息更新失败", next_invoice_code);
return false;
}
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());
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(next_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());
ret = invoiceLog.save();
ret = invoiceLog.save();
if (!ret) {
return false;
}
if (!ret) {
return false;
}
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive);
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(receive);
// }
// 在这里更新sn字段之后存入
@ -503,6 +485,16 @@ public class OrderTempSyncService {
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" +
" where t.truck_license = ? \n" +
" and t.ordercluster_id = ? ",
@ -598,27 +590,9 @@ public class OrderTempSyncService {
Date now = new Date();
SyncTask synctask = new SyncTask();
InvoiceReceive receive = null;
String next_invoice_code = null;
// 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);
// }
order.setTransportId(transport.getId());
@ -665,8 +639,6 @@ public class OrderTempSyncService {
return Result.failedstr("总价 %.2f,客户余额(%.2f)不足以支付");
}
InvoiceReceive finalReceive = receive;
String finalNext_invoice_code = next_invoice_code;
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
@ -726,36 +698,36 @@ public class OrderTempSyncService {
}
// if (req_receipt == 1) { // 需要同时开具发票
// 这里的 finalReceive 在前面肯定验证过了
finalReceive.setSurplus(finalReceive.getSurplus() - 1);
finalReceive.setCurrentCode(finalNext_invoice_code);
// 这里的 finalReceive 在前面肯定验证过了
receive.setSurplus(receive.getSurplus() - 1);
receive.setCurrentCode(next_invoice_code);
ret = finalReceive.update();
ret = receive.update();
if (!ret) {
log.error("发票领用信息更新失败", finalNext_invoice_code);
return false;
}
if (!ret) {
log.error("发票领用信息更新失败", next_invoice_code);
return false;
}
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());
InvoiceLog invoiceLog = new InvoiceLog();
invoiceLog.setId(StrKit.getRandomUUID());
invoiceLog.setInvoiceReceiveId(receive.getId());
invoiceLog.setCode(next_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());
ret = invoiceLog.save();
ret = invoiceLog.save();
if (!ret) {
return false;
}
if (!ret) {
return false;
}
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(finalReceive);
synctask.addSaveData(invoiceLog);
synctask.addUpdateData(receive);
// }
// 在这里更新sn字段之后存入
@ -774,8 +746,7 @@ public class OrderTempSyncService {
return OrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId);
}
public Result cancel(String sn, Sysuser sysuser, String password) {
public Result cancel(String sn, String invalid_memo, Sysuser sysuser, String password) {
// TODO: 判断权限
OrderTemp order = OrderTemp.dao.findById(sn);
@ -801,7 +772,6 @@ public class OrderTempSyncService {
return Result.failed("订单已经取消");
}
int oldstate = order.getState();
order.setState(OrderStateEnum.INVALID.getStateid()); // 将订单状态置为 9
Record logrecord = new Record();
@ -815,8 +785,7 @@ public class OrderTempSyncService {
SyncTask synctask = new SyncTask();
synctask.addUpdateData(order);
boolean ret = order.update()
&& ModifyLogService.me.save(order.tablename, "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser);
boolean ret = order.update();
if (!ret) {
return false;
@ -835,12 +804,35 @@ public class OrderTempSyncService {
// }
// 是集团客户订单
if (order.getOrderclusterId() != null) {
Ordercluster ordercluster = Ordercluster.dao.findById(order.getOrderclusterId());
// if (order.getOrderclusterId() != null) {
// 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());
return false;
// 已开具发票
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;
}
synctask.addUpdateData(invoiceLog);
} else {
log.error("订单[%s]没有找到开票记录", order.getSn());
}
}
@ -884,7 +876,8 @@ public class OrderTempSyncService {
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) {
log.error(e.getMessage(), e);
return false;
@ -894,4 +887,121 @@ public class OrderTempSyncService {
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.local.ssjygl.main.Config;
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.supermarket.product.SupermarketProductService;
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);
}