|
@@ -369,7 +369,7 @@ public class aftersalesmag extends Controller {
|
|
|
Long sa_aftersalesmagid = content.getLong("sa_aftersalesmagid");
|
|
Long sa_aftersalesmagid = content.getLong("sa_aftersalesmagid");
|
|
|
Long sa_orderid = 0L;
|
|
Long sa_orderid = 0L;
|
|
|
Rows rows = dbConnect.runSqlQuery(
|
|
Rows rows = dbConnect.runSqlQuery(
|
|
|
- "select t1.sa_aftersalesmagid,t1.status,t1.billno,t1.sa_orderid,t1.returnamount,t1.payamount,t1.sys_enterpriseid,t1.sa_accountclassid,t2.sonum,t1.type from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid ='"
|
|
|
|
|
|
|
+ "select t1.sa_aftersalesmagid,t1.status,t1.billno,ifnull(t1.sa_orderid,0) sa_orderid ,t1.returnamount,t1.payamount,t1.sys_enterpriseid,t1.sa_accountclassid,t2.sonum,t1.type from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid ='"
|
|
|
+ sa_aftersalesmagid + "' and t1.siteid='" + siteid + "'");
|
|
+ sa_aftersalesmagid + "' and t1.siteid='" + siteid + "'");
|
|
|
if (rows.isEmpty()) {
|
|
if (rows.isEmpty()) {
|
|
|
return getErrReturnObject().setErrMsg("该返退单不存在").toString();
|
|
return getErrReturnObject().setErrMsg("该返退单不存在").toString();
|
|
@@ -382,77 +382,53 @@ public class aftersalesmag extends Controller {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- if (rows.get(0).getString("type").equals("借用归还单")) {
|
|
|
|
|
- if (rows.get(0).getDouble("returnamount") != 0) {
|
|
|
|
|
- /******** 生成负数收入凭证 ********/
|
|
|
|
|
- BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
|
|
|
|
|
- CashbillEntity cashbillEntity = new CashbillEntity();
|
|
|
|
|
- cashbillEntity.setAmount(returnamount);
|
|
|
|
|
- cashbillEntity.setOwnerid(sa_aftersalesmagid);
|
|
|
|
|
- cashbillEntity.setOwnertable("sa_aftersalesmag");
|
|
|
|
|
- cashbillEntity.setRemarks("借用归还单号:" + rows.get(0).getString("billno") + ";借出单号:" + rows.get(0).getString("sonum"));
|
|
|
|
|
- cashbillEntity.setSource("借用归还单复核");
|
|
|
|
|
-
|
|
|
|
|
- sqlList.addAll(Accountbalance.createCashbillIncome(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- if (rows.get(0).getDouble("payamount") != 0) {
|
|
|
|
|
- /******** 生成支出凭证 ********/
|
|
|
|
|
- BigDecimal payamount = rows.get(0).getBigDecimal("payamount");
|
|
|
|
|
- CashbillEntity cashbillEntity = new CashbillEntity();
|
|
|
|
|
- cashbillEntity.setAmount(payamount);
|
|
|
|
|
- cashbillEntity.setOwnerid(sa_aftersalesmagid);
|
|
|
|
|
- cashbillEntity.setOwnertable("sa_aftersalesmag");
|
|
|
|
|
- cashbillEntity.setRemarks("借用归还单号:" + rows.get(0).getString("billno") + ";借出单号:" + rows.get(0).getString("sonum"));
|
|
|
|
|
- cashbillEntity.setSource("借用归还单复核");
|
|
|
|
|
- sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- if (rows.get(0).getDouble("returnamount") != 0) {
|
|
|
|
|
- /******** 生成支出凭证 ********/
|
|
|
|
|
- BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
|
|
|
|
|
- CashbillEntity cashbillEntity = new CashbillEntity();
|
|
|
|
|
- cashbillEntity.setAmount(returnamount);
|
|
|
|
|
- cashbillEntity.setOwnerid(sa_aftersalesmagid);
|
|
|
|
|
- cashbillEntity.setOwnertable("sa_aftersalesmag");
|
|
|
|
|
- cashbillEntity.setRemarks("退货单号:" + rows.get(0).getString("billno") + ";订单号:" + rows.get(0).getString("sonum"));
|
|
|
|
|
- cashbillEntity.setSource("返退单复核");
|
|
|
|
|
-
|
|
|
|
|
- sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * * 核销对冲计算
|
|
|
|
|
- */
|
|
|
|
|
- {
|
|
|
|
|
- HashMap<Long, Row> orderdetailmap = new HashMap<>();
|
|
|
|
|
- HashMap<Long, BigDecimal> orderdetailchangeamount = new HashMap<>();
|
|
|
|
|
- Rows rowsOrder = dbConnect.runSqlQuery("select * from sa_order t1 where t1.sa_orderid=" + sa_orderid);
|
|
|
|
|
- Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.price,t1.returnqty,t1.amount,t1.sa_orderitemsid,t1.writeoffamount from sa_orderitems t1 where t1.sa_orderid=" + sa_orderid);
|
|
|
|
|
- RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
|
|
- Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
|
|
|
|
|
- for (Row row : sa_aftersalesmag_itemsRows) {
|
|
|
|
|
- Rows orderitemsRows = rowsMap.get(row.getString("sa_orderitemsid"));
|
|
|
|
|
- BigDecimal price = orderitemsRows.get(0).getBigDecimal("price");
|
|
|
|
|
- BigDecimal qty = row.getBigDecimal("qty");
|
|
|
|
|
- BigDecimal returnamount_detail = qty.multiply(price);//退货金额
|
|
|
|
|
- BigDecimal writeoffamount = orderitemsRows.get(0).getBigDecimal("writeoffamount");//订单行已核销金额
|
|
|
|
|
- if (writeoffamount.compareTo(BigDecimal.ZERO) > 0 && (orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)).compareTo(writeoffamount) < 0) {
|
|
|
|
|
- //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲
|
|
|
|
|
- orderdetailmap.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), orderitemsRows.get(0));
|
|
|
|
|
- orderdetailchangeamount.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), writeoffamount.subtract(orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * * 核销对冲
|
|
|
|
|
- */
|
|
|
|
|
- if (!orderdetailmap.isEmpty()) {
|
|
|
|
|
- sqlList.addAll(new twriteoffbill_orderchange(rowsOrder.get(0), orderdetailmap, orderdetailchangeamount).hedging());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(rows.get(0).getString("type").equals("退货单")) {
|
|
|
|
|
+ if( rows.get(0).getLong("sa_orderid") !=0){
|
|
|
|
|
+ if (rows.get(0).getDouble("returnamount") != 0) {
|
|
|
|
|
+ /******** 生成支出凭证 ********/
|
|
|
|
|
+ BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
|
|
|
|
|
+ CashbillEntity cashbillEntity = new CashbillEntity();
|
|
|
|
|
+ cashbillEntity.setAmount(returnamount);
|
|
|
|
|
+ cashbillEntity.setOwnerid(sa_aftersalesmagid);
|
|
|
|
|
+ cashbillEntity.setOwnertable("sa_aftersalesmag");
|
|
|
|
|
+ cashbillEntity.setRemarks("退货单号:" + rows.get(0).getString("billno") + ";订单号:" + rows.get(0).getString("sonum"));
|
|
|
|
|
+ cashbillEntity.setSource("退货单复核");
|
|
|
|
|
+
|
|
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// /**
|
|
|
|
|
+// * * 核销对冲计算
|
|
|
|
|
+// */
|
|
|
|
|
+// {
|
|
|
|
|
+// HashMap<Long, Row> orderdetailmap = new HashMap<>();
|
|
|
|
|
+// HashMap<Long, BigDecimal> orderdetailchangeamount = new HashMap<>();
|
|
|
|
|
+// Rows rowsOrder = dbConnect.runSqlQuery("select * from sa_order t1 where t1.sa_orderid=" + sa_orderid);
|
|
|
|
|
+// Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.price,t1.returnqty,t1.amount,t1.sa_orderitemsid,t1.writeoffamount from sa_orderitems t1 where t1.sa_orderid=" + sa_orderid);
|
|
|
|
|
+// RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
|
|
+// Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
|
|
|
|
|
+// for (Row row : sa_aftersalesmag_itemsRows) {
|
|
|
|
|
+// Rows orderitemsRows = rowsMap.get(row.getString("sa_orderitemsid"));
|
|
|
|
|
+// BigDecimal price = orderitemsRows.get(0).getBigDecimal("price");
|
|
|
|
|
+// BigDecimal qty = row.getBigDecimal("qty");
|
|
|
|
|
+// BigDecimal returnamount_detail = qty.multiply(price);//退货金额
|
|
|
|
|
+// BigDecimal writeoffamount = orderitemsRows.get(0).getBigDecimal("writeoffamount");//订单行已核销金额
|
|
|
|
|
+// if (writeoffamount.compareTo(BigDecimal.ZERO) > 0 && (orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)).compareTo(writeoffamount) < 0) {
|
|
|
|
|
+// //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲
|
|
|
|
|
+// orderdetailmap.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), orderitemsRows.get(0));
|
|
|
|
|
+// orderdetailchangeamount.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), writeoffamount.subtract(orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)));
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * * 核销对冲
|
|
|
|
|
+// */
|
|
|
|
|
+// if (!orderdetailmap.isEmpty()) {
|
|
|
|
|
+// sqlList.addAll(new twriteoffbill_orderchange(rowsOrder.get(0), orderdetailmap, orderdetailchangeamount).hedging());
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|