|
|
@@ -98,9 +98,9 @@ public class XSCK extends BasicBill {
|
|
|
}
|
|
|
|
|
|
if ((ischeck && rb == 1) || (!ischeck && rb == 0)) {
|
|
|
- if (order_paymentnode.equals("3") && !Accountbalance.judgeBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.toRowsMap("sa_orderitemsidnum").get("0").sum("amount"))) {
|
|
|
- //throw new YosException("账户余额不足,还差" + Accountbalance.InsufficientBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.toRowsMap("sa_orderitemsidnum").get("0").sum("amount")) + "元!");
|
|
|
- }
|
|
|
+// if (order_paymentnode.equals("3") && !Accountbalance.judgeBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.toRowsMap("sa_orderitemsidnum").get("0").sum("amount"))) {
|
|
|
+// //throw new YosException("账户余额不足,还差" + Accountbalance.InsufficientBalance(dbConnect, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), itemRows.toRowsMap("sa_orderitemsidnum").get("0").sum("amount")) + "元!");
|
|
|
+// }
|
|
|
if(!billRow.getString("sourceobject").equals("tpartreimbursement")){
|
|
|
Rows rowsjudge = dbConnect.runSqlQuery("select * from (select sa_orderitemsid,sum(qty) qty from st_stockbill_items where st_stockbillid ='" + st_stockbillid + "' group by sa_orderitemsid) t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid where t1.qty>t2.undeliqty");
|
|
|
if (rowsjudge.isNotEmpty()) {
|
|
|
@@ -118,16 +118,17 @@ public class XSCK extends BasicBill {
|
|
|
|
|
|
@Override
|
|
|
public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
|
|
|
+
|
|
|
ArrayList<String> sqlList = super.getCheckSql(ischeck);
|
|
|
+ Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
if (ischeck) {
|
|
|
- Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
-
|
|
|
String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
|
|
|
if (rb == 1) {
|
|
|
if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount"), billRow.getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成");
|
|
|
+ CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount"), billRow.getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成","货款");
|
|
|
JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+
|
|
|
}
|
|
|
Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.sa_orderitemsid>0 and t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
for (Row row : rowsDispatchDetailGroup) {
|
|
|
@@ -168,6 +169,11 @@ public class XSCK extends BasicBill {
|
|
|
}
|
|
|
if(orderrows.size()==count){
|
|
|
sqlList.add("update sa_order set status='关闭',closeby='"+controller.username+"',closedate=CURRENT_TIME where sa_orderid=" +sa_orderid);
|
|
|
+ sqlList.add("UPDATE sa_accountbalance t1 " +
|
|
|
+ "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " +
|
|
|
+ "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " +
|
|
|
+ "WHERE t1.sa_accountbalanceid="+accountbalancerows.get(0).getLong("sa_accountbalanceid")+" and t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
|
|
|
+ sqlList.add("delete from sa_accountbalance_freez t1 WHERE t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -176,7 +182,7 @@ public class XSCK extends BasicBill {
|
|
|
sqlList.addAll(updateAccountbalance_freez(isInStock(ischeck)));
|
|
|
} else {
|
|
|
if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount").negate(), billRow.getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成");
|
|
|
+ CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount").negate(), billRow.getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成","货款");
|
|
|
JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
}
|
|
|
@@ -232,13 +238,14 @@ public class XSCK extends BasicBill {
|
|
|
|
|
|
|
|
|
} else {
|
|
|
- Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
|
|
|
if (rb == 1) {
|
|
|
if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount").negate(), billRow.getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成");
|
|
|
+ Rows cashbillRows =dbConnect.runSqlQuery("select amount,discountamount from sa_cashbill where ownerid="+st_stockbillid +" and ownertable='st_stockbill' and type=0 and class='货款'");
|
|
|
+ CashbillEntity entity = getCashbillEntity(cashbillRows.sum("amount").negate(), cashbillRows.sum("discountamount").negate(), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成","货款");
|
|
|
JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+
|
|
|
}
|
|
|
Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where sa_orderitemsid>0 and st_stockbillid=" + st_stockbillid + ")");
|
|
|
RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
@@ -264,9 +271,11 @@ public class XSCK extends BasicBill {
|
|
|
sqlList.addAll(updateAccountbalance_freez(isInStock(ischeck)));
|
|
|
} else {
|
|
|
if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(billRow.getBigDecimal("payamount"), billRow.getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成");
|
|
|
+ Rows cashbillRows =dbConnect.runSqlQuery("select amount,discountamount from sa_cashbill where ownerid="+st_stockbillid +" and ownertable='st_stockbill' and type=0 and class='货款'");
|
|
|
+ CashbillEntity entity = getCashbillEntity(cashbillRows.sum("amount").negate(), cashbillRows.sum("discountamount").negate(), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成","货款");
|
|
|
JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+
|
|
|
}
|
|
|
if(!billRow.getString("sourceobject").equals("tpartreimbursement")){
|
|
|
Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.sa_orderitemsid>0 and t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
@@ -332,6 +341,11 @@ public class XSCK extends BasicBill {
|
|
|
}
|
|
|
if(orderrows.size()==count){
|
|
|
sqlList.add("update sa_order set status='关闭',closeby='"+controller.username+"',closedate=CURRENT_TIME where sa_orderid=" +sa_orderid);
|
|
|
+ sqlList.add("UPDATE sa_accountbalance t1 " +
|
|
|
+ "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " +
|
|
|
+ "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " +
|
|
|
+ "WHERE t1.sa_accountbalanceid="+accountbalancerows.get(0).getLong("sa_accountbalanceid")+" and t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
|
|
|
+ sqlList.add("delete from sa_accountbalance_freez t1 WHERE t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -344,6 +358,58 @@ public class XSCK extends BasicBill {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public ArrayList<String> getCheckSql_custamount(boolean ischeck) throws YosException {
|
|
|
+ ArrayList<String> sqlList = super.getCheckSql_custamount(ischeck);
|
|
|
+ if (ischeck) {
|
|
|
+ Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
+
|
|
|
+ String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
|
|
|
+ if (rb == 1) {
|
|
|
+ if (order_paymentnode.equals("3")) {
|
|
|
+ BigDecimal custamount=BigDecimal.ZERO;
|
|
|
+ for(Row row :itemRows){
|
|
|
+ custamount=custamount.add(row.getBigDecimal("custamount").multiply(row.getBigDecimal("qty")));
|
|
|
+ }
|
|
|
+ CashbillEntity entity_custamount = getCashbillEntity(custamount, BigDecimal.ZERO, st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成","客户档案资料费");
|
|
|
+ JSONObject createCashbillPay_custamount = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity_custamount, true);
|
|
|
+ sqlList.addAll(createCashbillPay_custamount.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (order_paymentnode.equals("3")) {
|
|
|
+ BigDecimal custamount=BigDecimal.ZERO;
|
|
|
+ for(Row row :itemRows){
|
|
|
+ custamount=custamount.add(row.getBigDecimal("custamount").multiply(row.getBigDecimal("qty")));
|
|
|
+ }
|
|
|
+ CashbillEntity entity_custamount = getCashbillEntity(custamount.negate(), BigDecimal.ZERO, st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成","客户档案资料费");
|
|
|
+ JSONObject createCashbillPay_custamount = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity_custamount, true);
|
|
|
+ sqlList.addAll(createCashbillPay_custamount.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + sys_enterpriseid);
|
|
|
+ String order_paymentnode = Parameter.getString(siteid, "order_paymentnode");
|
|
|
+ if (rb == 1) {
|
|
|
+ if (order_paymentnode.equals("3")) {
|
|
|
+ Rows cashbillRows_custamount =dbConnect.runSqlQuery("select amount,discountamount from sa_cashbill where ownerid="+st_stockbillid +" and ownertable='st_stockbill' and type=0 and class='客户档案资料费'");
|
|
|
+ CashbillEntity entity_custamount = getCashbillEntity(cashbillRows_custamount.sum("amount").negate(), cashbillRows_custamount.sum("discountamount").negate(), st_stockbillid, "销售出库单反审核", billno, "由销售出库单" + billno + "反审核时生成","客户档案资料费");
|
|
|
+ JSONObject createCashbillPay_custamount = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity_custamount, true);
|
|
|
+ sqlList.addAll(createCashbillPay_custamount.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (order_paymentnode.equals("3")) {
|
|
|
+ Rows cashbillRows_custamount =dbConnect.runSqlQuery("select amount,discountamount from sa_cashbill where ownerid="+st_stockbillid +" and ownertable='st_stockbill' and type=0 and class='客户档案资料费'");
|
|
|
+ CashbillEntity entity_custamount = getCashbillEntity(cashbillRows_custamount.sum("amount").negate(),cashbillRows_custamount.sum("discountamount").negate(), st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成","客户档案资料费");
|
|
|
+ JSONObject createCashbillPay_custamount = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity_custamount, true);
|
|
|
+ sqlList.addAll(createCashbillPay_custamount.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return sqlList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 账户余额冻结
|
|
|
*
|
|
|
@@ -352,7 +418,7 @@ public class XSCK extends BasicBill {
|
|
|
public ArrayList<String> updateAccountbalance_freez(boolean addorsub) throws YosException {
|
|
|
ArrayList<String> sqllist = new ArrayList<>();
|
|
|
/******** 冻结数据 ********/
|
|
|
- Rows rows = dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,t3.type,ROUND(sum(t1.qty*t2.price*ifnull(t2.pricerate,1)*ifnull(t2.rwpricerate,1)), 2) amount from st_stockbill_items t1 \n" +
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,t3.type,ROUND(sum(t1.qty*(t1.price+t1.custamount)), 2) amount from st_stockbill_items t1 \n" +
|
|
|
" inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid\n" +
|
|
|
" inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid\n" +
|
|
|
"\t\t\t\t\t\t\t\t\tleft join sa_accountbalance t4 on t4.sa_accountclassid=t3.sa_accountclassid and t4.sys_enterpriseid=t3.sys_enterpriseid and t4.siteid=t3.siteid\n" +
|
|
|
@@ -389,8 +455,14 @@ public class XSCK extends BasicBill {
|
|
|
BigDecimal amount = row.getBigDecimal("amount");
|
|
|
Rows accountbalancefreezrows = dbConnect.runSqlQuery("select sa_accountbalance_freezid,amount from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + siteid + "'");
|
|
|
if (accountbalancefreezrows.size() > 0) {
|
|
|
- sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid);
|
|
|
- sqllist.add("update sa_accountbalance_freez set amount=amount-" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
+ if(accountbalancefreezrows.get(0).getBigDecimal("amount").compareTo(amount)>0){
|
|
|
+ sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid);
|
|
|
+ sqllist.add("update sa_accountbalance_freez set amount=amount-" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
+ }else{
|
|
|
+ sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-" + accountbalancefreezrows.get(0).getBigDecimal("amount") + " where sa_accountbalanceid=" + sa_accountbalanceid);
|
|
|
+ sqllist.add("update sa_accountbalance_freez set amount=0 where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -398,7 +470,7 @@ public class XSCK extends BasicBill {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static CashbillEntity getCashbillEntity(BigDecimal amount, BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks) throws YosException {
|
|
|
+ public static CashbillEntity getCashbillEntity(BigDecimal amount, BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks,String type) throws YosException {
|
|
|
CashbillEntity entity = new CashbillEntity();
|
|
|
entity.setAmount(amount);
|
|
|
entity.setDiscountamountamount(discountamount);
|
|
|
@@ -406,6 +478,7 @@ public class XSCK extends BasicBill {
|
|
|
entity.setOwnertable("st_stockbill");
|
|
|
entity.setSource(source);
|
|
|
entity.setRemarks(remarks);
|
|
|
+ entity.setType(type);
|
|
|
entity.setSourcenote(sourcenotes);
|
|
|
return entity;
|
|
|
|