| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- package restcontroller.webmanage.sale.stockbill;
- import beans.brand.Brand;
- import beans.data.BatchDeleteErr;
- import beans.datacontrllog.DataContrlLog;
- import beans.itemprice.ItemPrice;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.annotation.CACHEING;
- import common.annotation.CACHEING_CLEAN;
- import common.data.*;
- import org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- public class stockbillitems extends Controller {
- public stockbillitems(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "出库商品列表查询", apiversion = R.ID2025050614581203.v1.class)
- @CACHEING
- public String queryOrderItemgList() throws YosException {
- /*
- * 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.unit like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.sonum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.typemx like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("sa_orderid") && !"".equals(whereObject.getString("sa_orderid"))) {
- Long sa_orderid = whereObject.getLongValue("sa_orderid");
- if (sa_orderid > 0) {
- where.append(" and t1.sa_orderid ='").append(sa_orderid).append("' ");
- }
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and t3.checkdate >='").append(whereObject.getString("begindate")).append("' ");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and t3.checkdate <='").append(getDate_Str(whereObject.getDate("enddate"), 1)).append("' ");
- }
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
- where.append(" and t3.type ='").append(whereObject.getString("type")).append("' ");
- }
- }
- // SQLFactory sqlFactory = new SQLFactory(this, "发货商品列表查询", pageSize, pageNumber, pageSorting);
- // sqlFactory.addParameter_SQL("where", where);
- // sqlFactory.addParameter("sys_enterpriseid", content.getLongValue("sys_enterpriseid"));
- // sqlFactory.addParameter("sa_dispatchid", content.getLongValue("sa_dispatchid"));
- // sqlFactory.addParameter("siteid", siteid);
- //
- // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_orderitems", "sa_orderitemsid", "sa_orderid",
- "itemid", "unit", "undeliqty", "remarks", "rowno", "customproperties", "price", "defaultprice", "custamount");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.siteid = t2.siteid and t1.itemid = t2.itemid", "itemno", "itemname", "model", "spec", "batchcontrol", "icaddqty", "icminqty", "outplace");
- querySQL.addJoinTable(JOINTYPE.left, "sa_order", "t3", "t1.siteid=t3.siteid and t1.sa_orderid=t3.sa_orderid", "sonum", "billdate", "createdate", "submitdate", "checkdate", "typemx", "abstract", "delivery", "invoicename", "invoicetaxno", "invoiceaddress");
- querySQL.addQueryFields("orderremarks", "t3.remarks");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("t3.STATUS = '审核' and ifnull(t1.undeliqty, 0) !=0 and ifnull(t1.isfreeze, 0) =0 AND ifnull( t1.isclose, 0 )= 0");
- querySQL.setWhere("t3.sys_enterpriseid", content.getLongValue("sys_enterpriseid"));
- querySQL.setWhere("if(ifnull(t2.batchcontrol,0)!=0,1=1,not EXISTS(select 1 from st_stockbill_items where st_stockbillid='" + content.getLongValue("st_stockbillid") + "' and sa_orderitemsid=t1.sa_orderitemsid))");
- //querySQL.setWhere("t1.sa_orderitemsid not in(select t1.sa_orderitemsid from (select t1.sa_orderitemsid,t1.siteid,SUM(t1.qty) qty from sa_dispatch_items t1 inner join sa_dispatch t2 on t1.sa_dispatchid=t2.sa_dispatchid and t1.siteid=t2.siteid where t2.status in('新建','提交') group by t1.sa_orderitemsid,t1.siteid) t1 inner join sa_orderitems t3 on t1.sa_orderitemsid=t3.sa_orderitemsid and t1.siteid=t3.siteid where t3.undeliqty=t1.qty)");
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "商品档案添加商品", apiversion = R.ID2025101713485003.v1.class)
- public String queryItemList() throws YosException {
- long st_stockbillid = content.getLong("st_stockbillid");
- Rows stockbillrows = dbConnect.runSqlQuery("select sys_enterpriseid from st_stockbill where st_stockbillid=" + st_stockbillid);
- if (stockbillrows.isEmpty()) {
- return getErrReturnObject().setErrMsg("该出入库单不存在").toString();
- }
- /*
- * 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.unit like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item",
- "itemid", "itemno", "itemname", "model", "spec", "batchcontrol", "outplace", "icaddqty", "icminqty");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "t1.siteid = t2.siteid and t1.unitid = t2.unitid", "unitname");
- querySQL.setSiteid(siteid);
- querySQL.addQueryFields("qty", "t1.icminqty");
- querySQL.setWhere("t1.STATUS = '审核' and t1.isused=1");
- querySQL.setWhere("t1.itemid not in (select itemid from st_stockbill_items where st_stockbillid='" + st_stockbillid + "')");
- //querySQL.setWhere("t1.sa_orderitemsid not in(select t1.sa_orderitemsid from (select t1.sa_orderitemsid,t1.siteid,SUM(t1.qty) qty from sa_dispatch_items t1 inner join sa_dispatch t2 on t1.sa_dispatchid=t2.sa_dispatchid and t1.siteid=t2.siteid where t2.status in('新建','提交') group by t1.sa_orderitemsid,t1.siteid) t1 inner join sa_orderitems t3 on t1.sa_orderitemsid=t3.sa_orderitemsid and t1.siteid=t3.siteid where t3.undeliqty=t1.qty)");
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- //查询附件
- RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
- //商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- //品牌
- RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
- //价格
- HashMap<Long, ItemPrice> itemPriceRowsMap = ItemPrice.getItemPrice(this, stockbillrows.get(0).getLong("sys_enterpriseid"), ids);
- for (Row row : rows) {
- row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- row.put("brand", brandRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- if (itemPriceRowsMap.containsKey(row.getLong("itemid"))) {
- row.put("price", itemPriceRowsMap.get(row.getLong("itemid")).getPrice());
- } else {
- row.put("price", 0);
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "出入库单明细新增更新", apiversion = R.ID2025050614284803.v1.class)
- @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
- public String insertormodify_stcokbillItems() throws YosException {
- Long st_stockbillid = content.getLong("st_stockbillid");
- JSONArray iteminfos = content.getJSONArray("iteminfos");
- ArrayList<String> sqlList = new ArrayList<>();
- Rows rowscount = dbConnect.runSqlQuery("select billno,status,sourceobject,stockid,type,name,phonenumber,address,departmentid from st_stockbill where st_stockbillid=" + st_stockbillid);
- if (!rowscount.isEmpty()) {
- if (!rowscount.get(0).getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("非新建状态的出库单无法新增修改").toString();
- }
- if (rowscount.get(0).getString("sourceobject").equals("tpartreimbursement")) {
- return getErrReturnObject().setErrMsg("由核销生成的出入库单无法新增修改").toString();
- }
- } else {
- return getErrReturnObject().setErrMsg("出入库单不存在").toString();
- }
- int i = 0;
- long maxid = 0;
- long[] st_stockbill_itemsid = createTableID("st_stockbill_items", iteminfos.size());
- Rows maxidRows = dbConnect
- .runSqlQuery("select MAX(rowno) rowno from st_stockbill_items where st_stockbillid=" + st_stockbillid);
- Rows detailRows = dbConnect
- .runSqlQuery("select rowno,price,defaultprice,discountrate,st_stockbill_itemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid);
- RowsMap detailRowsMap = detailRows.toRowsMap("st_stockbill_itemsid");
- if (!maxidRows.isEmpty()) {
- maxid = maxidRows.get(0).getLong("rowno");
- }
- List<Long> list = new ArrayList<>();
- for (Object object : iteminfos) {
- list.add(((JSONObject) object).getLong("itemid"));
- }
- RowsMap itemRowsMap = SQLFactory.createQuerySQL(this, "plm_item", "*").setTableAlias("t1").addJoinTable(JOINTYPE.left, "st_stock", "t2", "t1.siteid = t2.siteid and t1.stockno = t2.stockno", "stockid").setWhere("itemid", list).query().toRowsMap("itemid");
- RowsMap stockRowsMap = SQLFactory.createQuerySQL(this, "st_stock", "stockid", "stockno").query().toRowsMap("stockno");
- for (Object obj : iteminfos) {
- JSONObject iteminfo = (JSONObject) obj;
- if (!iteminfo.containsKey("custamount")) {
- iteminfo.put("custamount", 0);
- }
- if (iteminfo.getLong("st_stockbill_itemsid") <= 0 || dbConnect
- .runSqlQuery("select st_stockbill_itemsid from st_stockbill_items where st_stockbill_itemsid="
- + iteminfo.getLong("st_stockbill_itemsid"))
- .isEmpty()) {
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
- insertSQL.setUniqueid(st_stockbill_itemsid[i]);
- insertSQL.setSiteid(siteid);
- insertSQL.setValue("rowno", maxid + i + 1);
- insertSQL.setValue("st_stockbillid", st_stockbillid);
- insertSQL.setValue("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
- if (rowscount.get(0).getString("type").equals("其他入库")) {
- if (rowscount.get(0).getLong("stockid") != 0) {
- insertSQL.setValue("stockid", rowscount.get(0).getLong("stockid"));
- } else {
- insertSQL.setValue("stockid", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getLong("stockid") : iteminfo.getLongValue("stockid"));
- }
- } else if (rowscount.get(0).getString("type").equals("销售出库")) {
- if (itemRowsMap.containsKey(iteminfo.getStringValue("itemid"))) {
- if (itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getBoolean("ismodule")) {
- insertSQL.setValue("stockid", stockRowsMap.get("105").get(0).getLong("stockid"));
- } else {
- insertSQL.setValue("stockid", stockRowsMap.get("101").get(0).getLong("stockid"));
- }
- }
- } else if (rowscount.get(0).getString("type").equals("其他出库")) {
- if (rowscount.get(0).getLong("stockid") != 0) {
- insertSQL.setValue("stockid", rowscount.get(0).getLong("stockid"));
- } else {
- insertSQL.setValue("stockid", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getLong("stockid") : iteminfo.getLongValue("stockid"));
- }
- } else {
- insertSQL.setValue("stockid", iteminfo.getLong("stockid"));
- }
- insertSQL.setValue("itemid", iteminfo.getStringValue("itemid"));
- insertSQL.setValue("sa_orderid", iteminfo.getLongValue("sa_orderid"));
- insertSQL.setValue("qty", iteminfo.getStringValue("qty"));
- insertSQL.setValue("discountrate", 1);
- insertSQL.setValue("sa_dispatch_itemsid", 0);
- insertSQL.setValue("defaultprice", iteminfo.getBigDecimal("price").subtract(iteminfo.getBigDecimal("custamount")));
- insertSQL.setValue("remarks", iteminfo.getStringValue("remarks"));
- insertSQL.setValue("itemno", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getString("itemno") : iteminfo.getString("itemno"));
- insertSQL.setValue("itemname", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getString("itemname") : iteminfo.getString("itemname"));
- insertSQL.setValue("model", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getString("model") : iteminfo.getString("model"));
- insertSQL.setValue("price", iteminfo.getBigDecimal("price").subtract(iteminfo.getBigDecimal("custamount")));
- insertSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply((iteminfo.getBigDecimal("price").subtract(iteminfo.getBigDecimal("custamount")))));
- insertSQL.setValue("custamount", iteminfo.getBigDecimal("custamount"));
- insertSQL.setValue("untaxedprice", iteminfo.getBigDecimal("price").divide(new BigDecimal(1.13), 2, BigDecimal.ROUND_HALF_UP));
- insertSQL.setValue("untaxedamount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price").divide(new BigDecimal(1.13), 2, BigDecimal.ROUND_HALF_UP)));
- insertSQL.setValue("skucontrol", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getBoolean("skucontrol") : iteminfo.getBoolean("skucontrol"));
- i++;
- if (StringUtils.isBlank(rowscount.get(0).getString("name"))
- || StringUtils.isBlank(rowscount.get(0).getString("phonenumber"))
- || StringUtils.isBlank(rowscount.get(0).getString("address"))) {
- Rows orderRows = dbConnect.runSqlQuery("select * from sa_order where sa_orderid=" + iteminfo.getLongValue("sa_orderid"));
- if (orderRows.isNotEmpty()) {
- sqlList.add("update st_stockbill set name='" + orderRows.get(0).getString("contact") + "',phonenumber='" + orderRows.get(0).getString("phonenumber") + "',address='" + orderRows.get(0).getString("address") + "' where st_stockbillid=" + st_stockbillid);
- }
- } else {
- String depname = "";
- Rows departmentrows = dbConnect.runSqlQuery("select depname from sys_department where departmentid=" + rowscount.get(0).getLong("departmentid"));
- if (departmentrows.isNotEmpty()) {
- depname = departmentrows.get(0).getString("depname");
- }
- if (depname.equals("售后部")) {
- Rows orderRows = dbConnect.runSqlQuery("select * from sa_order where sa_orderid=" + iteminfo.getLongValue("sa_orderid"));
- if (orderRows.isNotEmpty()) {
- sqlList.add("update st_stockbill set name='" + orderRows.get(0).getString("contact") + "',phonenumber='" + orderRows.get(0).getString("phonenumber") + "',address='" + orderRows.get(0).getString("address") + "' where st_stockbillid=" + st_stockbillid);
- }
- }
- }
- sqlList.add(insertSQL.getSQL());
- } else {
- Rows rows = dbConnect.runSqlQuery(
- "SELECT status from st_stockbill WHERE st_stockbillid = "
- + st_stockbillid);
- if (rows.isNotEmpty()) {
- if (rows.get(0).getString("status").equals("新建")) {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_stockbill_items");
- updateSQL.setUniqueid(iteminfo.getLong("st_stockbill_itemsid"));
- updateSQL.setSiteid(siteid);
- updateSQL.setValue("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
- updateSQL.setValue("itemid", iteminfo.getString("itemid"));
- updateSQL.setValue("sa_orderid", iteminfo.getString("sa_orderid"));
- updateSQL.setValue("qty", iteminfo.getString("qty"));
- updateSQL.setValue("discountrate", iteminfo.getString("discountrate"));
- updateSQL.setValue("defaultprice", iteminfo.getString("defaultprice"));
- updateSQL.setValue("remarks", iteminfo.getString("remarks"));
- updateSQL.setValue("itemno", iteminfo.getString("itemno"));
- updateSQL.setValue("itemname", iteminfo.getString("itemname"));
- updateSQL.setValue("model", iteminfo.getString("model"));
- updateSQL.setValue("price", iteminfo.getString("price"));
- updateSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
- updateSQL.setValue("untaxedprice", iteminfo.getBigDecimal("price").divide(new BigDecimal(1.13), 2, BigDecimal.ROUND_HALF_UP));
- updateSQL.setValue("untaxedamount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price").divide(new BigDecimal(1.13), 2, BigDecimal.ROUND_HALF_UP)));
- updateSQL.setValue("batchno", iteminfo.getString("batchno"));
- updateSQL.setValue("stockid", iteminfo.getString("stockid"));
- updateSQL.setValue("skucontrol", itemRowsMap.containsKey(iteminfo.getStringValue("itemid")) ? itemRowsMap.get(iteminfo.getStringValue("itemid")).get(0).getBoolean("skucontrol") : iteminfo.getBoolean("skucontrol"));
- if (detailRowsMap.containsKey(iteminfo.getString("st_stockbill_itemsid"))) {
- if (iteminfo.getBigDecimal("discountrate").compareTo(detailRowsMap.get(iteminfo.getString("st_stockbill_itemsid")).get(0).getBigDecimal("discountrate")) != 0
- || iteminfo.getBigDecimal("defaultprice").compareTo(detailRowsMap.get(iteminfo.getString("st_stockbill_itemsid")).get(0).getBigDecimal("defaultprice")) != 0
- || iteminfo.getBigDecimal("price").compareTo(detailRowsMap.get(iteminfo.getString("st_stockbill_itemsid")).get(0).getBigDecimal("price")) != 0) {
- sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "明细金额变更", "行号【" + detailRowsMap.get(iteminfo.getString("st_stockbill_itemsid")).get(0).getString("rowno") + "】原价:" + iteminfo.getBigDecimal("defaultprice") + ",折后价:" + iteminfo.getBigDecimal("price") + ",折扣率:" + iteminfo.getBigDecimal("discountrate")).getSQL());
- }
- }
- sqlList.add(updateSQL.getSQL());
- } else {
- return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
- }
- } else {
- return getErrReturnObject().setErrMsg("该销售出库单不存在").toString();
- }
- }
- }
- dbConnect.runSqlUpdate(sqlList);
- Rows rowsdetail = dbConnect.runSqlQuery("select amount,qty from st_stockbill_items where st_stockbillid=" + st_stockbillid);
- Rows stockbillrows = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.paydiscountamount,t2.depname from st_stockbill t1 left join sys_department t2 on t1.departmentid=t2.departmentid where t1.st_stockbillid=" + st_stockbillid);
- 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=" + stockbillrows.get(0).getLong("sys_enterpriseid"));
- String depname = stockbillrows.get(0).getString("depname");
- BigDecimal payamount = rowsdetail.sum("amount");
- if (depname.equals("售后部")) {
- if (accountbalancerows.isNotEmpty()) {
- if (accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(BigDecimal.ZERO) > 0) {
- if (accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(payamount) > 0) {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=0,paydiscountamount=" + payamount + " where st_stockbillid=" + st_stockbillid);
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount.subtract(accountbalancerows.get(0).getBigDecimal("discountamount")) + ",paydiscountamount=" + accountbalancerows.get(0).getBigDecimal("discountamount") + " where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- return querStcokbillItemsList();
- }
- @API(title = "出入库单明细列表", apiversion = R.ID20230719154303.v1.class)
- @CACHEING
- public String querStcokbillItemsList() throws YosException {
- /*
- * 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long st_stockbillid = content.getLong("st_stockbillid");
- Rows stockbillrows = dbConnect.runSqlQuery("select st_stockbillid,status,billno,rb,type from st_stockbill where st_stockbillid ='"
- + st_stockbillid + "' and siteid='" + siteid + "'");
- String type = "销售出库";
- if (stockbillrows.isNotEmpty()) {
- type = stockbillrows.get(0).getString("type");
- }
- SQLFactory sqlFactory;
- if (type.equals("销售出库")) {
- sqlFactory = new SQLFactory(this, "出入库单明细列表查询");
- } else {
- sqlFactory = new SQLFactory(this, "出入库单明细列表查询(红)");
- }
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("st_stockbillid", st_stockbillid);
- sqlFactory.addParameter("siteid", siteid);
- // Rows rows = dbConnect.runSqlQuery(sqlFactory);
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_site_parameter", "sys_site_parameterid");
- querySQL.setTableAlias("t0");
- querySQL.addJoinTable(JOINTYPE.right, sqlFactory, "t1", "t0.siteid='111'", "*");
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- Rows stockbillskuRows = dbConnect.runSqlQuery("select t1.sku,t1.st_stockbill_itemsid from st_stockbill_items_sku t1 left join sa_itemsku t2 on t1.sku=t2.sku where t1.st_stockbillid!=t1.st_stockbill_itemsid and t1.st_stockbillid=" + st_stockbillid);
- RowsMap stockbillskuRowsMap = stockbillskuRows.toRowsMap("st_stockbill_itemsid");
- for (Row row : rows) {
- if (stockbillskuRowsMap.containsKey(row.getString("st_stockbill_itemsid"))) {
- row.put("scanqty", stockbillskuRowsMap.get(row.getString("st_stockbill_itemsid")).size());
- } else {
- row.put("scanqty", 0);
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "删除明细", apiversion = R.ID2025050614510403.v1.class)
- @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
- public String deletemx() throws YosException {
- JSONArray st_stockbill_itemsids = content.getJSONArray("st_stockbill_itemsids");
- BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_stockbill_itemsids.size());
- long st_stockbillid = 0;
- for (Object o : st_stockbill_itemsids) {
- long st_stockbill_itemsid = Long.parseLong(o.toString());
- Rows RowsStatus = dbConnect.runSqlQuery("select t1.st_stockbill_itemsid,t2.status,t1.st_stockbillid from st_stockbill_items t1 left join st_stockbill t2 on t1.st_stockbillid=t2.st_stockbillid and t1.siteid=t2.siteid where t1.siteid='"
- + siteid + "' and t1.st_stockbill_itemsid='" + st_stockbill_itemsid + "'");
- if (RowsStatus.isNotEmpty()) {
- st_stockbillid = RowsStatus.get(0).getLong("st_stockbillid");
- if (!RowsStatus.get(0).getString("status").equals("新建")) {
- batchDeleteErr.addErr(st_stockbill_itemsid, "非新建状态的出库单明细无法删除");
- continue;
- }
- }
- ArrayList<String> list = new ArrayList<>();
- list.add("delete from st_stockbill_items where siteid='" + siteid
- + "' and st_stockbill_itemsid=" + st_stockbill_itemsid);
- list.add("delete from st_stockbill_items_sku where siteid='" + siteid
- + "' and st_stockbill_itemsid=" + st_stockbill_itemsid);
- dbConnect.runSqlUpdate(list);
- }
- //重新排序
- updateRowNo(st_stockbillid);
- Rows rowsdetail = dbConnect.runSqlQuery("select amount,qty from st_stockbill_items where st_stockbillid=" + st_stockbillid);
- Rows stockbillrows = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.paydiscountamount,t2.depname from st_stockbill t1 left join sys_department t2 on t1.departmentid=t2.departmentid where t1.st_stockbillid=" + st_stockbillid);
- 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=" + stockbillrows.get(0).getLong("sys_enterpriseid"));
- String depname = stockbillrows.get(0).getString("depname");
- BigDecimal payamount = rowsdetail.sum("amount");
- if (depname.equals("售后部")) {
- if (accountbalancerows.isNotEmpty()) {
- if (accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(BigDecimal.ZERO) > 0) {
- if (accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(payamount) > 0) {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=0,paydiscountamount=" + payamount + " where st_stockbillid=" + st_stockbillid);
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount.subtract(accountbalancerows.get(0).getBigDecimal("discountamount")) + ",paydiscountamount=" + accountbalancerows.get(0).getBigDecimal("discountamount") + " where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- } else {
- dbConnect.runSqlUpdate("update st_stockbill set payamount=" + payamount + ",paydiscountamount=0 where st_stockbillid=" + st_stockbillid);
- }
- return batchDeleteErr.getReturnObject().toString();
- }
- /**
- * 重新对发货单行进行排序
- *
- * @param
- * @throws YosException
- */
- public void updateRowNo(Long st_stockbillid) throws YosException {
- String sql = "SELECT st_stockbill_itemsid from st_stockbill_items WHERE st_stockbillid= " + st_stockbillid + " and siteid = '" + siteid + "' ORDER BY st_stockbill_itemsid asc ";
- ArrayList<Long> st_stockbill_itemsids = dbConnect.runSqlQuery(sql).toArrayList("st_stockbill_itemsid", new ArrayList<>());
- ArrayList<String> sqlList = new ArrayList<>();
- int rowno = 1;
- for (Long id : st_stockbill_itemsids) {
- sqlList.add("UPDATE st_stockbill_items SET rowno=" + rowno + " WHERE st_stockbill_itemsid = " + id);
- rowno++;
- }
- dbConnect.runSqlUpdate(sqlList);
- }
- }
|