u8.java 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. package restcontroller.webmanage.sale.u8;
  2. import beans.data.BatchDeleteErr;
  3. import beans.datacontrllog.DataContrlLog;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.annotation.CACHEING;
  10. import common.annotation.CACHEING_CLEAN;
  11. import common.data.*;
  12. import org.apache.commons.lang.StringUtils;
  13. import restcontroller.R;
  14. import java.math.BigDecimal;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. @API(title = "销售出库U8上传")
  18. public class u8 extends Controller {
  19. public u8(JSONObject content) throws YosException {
  20. super(content);
  21. }
  22. @API(title = "新增更新销售出库U8上传", apiversion = R.ID2025073114070603.v1.class)
  23. @CACHEING_CLEAN(apiClass = {u8.class})
  24. public String insertormodify_u8() throws YosException {
  25. ArrayList<String> sqlList = new ArrayList<>();
  26. // 表名
  27. String tableName = "u8";
  28. Long u8id = content.getLong("u8id");
  29. String entity = content.getStringValue("entity");
  30. String remarks = content.getStringValue("remarks");
  31. String billdate = content.getStringValue("billdate");
  32. if (u8id <= 0) {
  33. u8id = createTableID(tableName);
  34. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
  35. insertSQL.setUniqueid(u8id);
  36. insertSQL.setSiteid(siteid);
  37. insertSQL.setValue("entity", entity);
  38. insertSQL.setValue("remarks", remarks);
  39. insertSQL.setValue("billdate", billdate);
  40. insertSQL.setValue("period", billdate.substring(0, 7));
  41. insertSQL.setValue("billno", createBillCode("u8"));
  42. insertSQL.setValue("createby", username);
  43. insertSQL.setDateValue("createdate");
  44. insertSQL.setValue("changeby", username);
  45. insertSQL.setDateValue("changedate");
  46. insertSQL.setValue("status", "新建");
  47. sqlList.add(insertSQL.getSQL());
  48. sqlList.add(DataContrlLog.createLog(this, "u8", u8id, "新增", "销售出库U8上传新增成功").getSQL());
  49. } else {
  50. Rows rows = dbConnect.runSqlQuery(
  51. "SELECT status from u8 WHERE u8id = "
  52. + u8id);
  53. if (rows.isNotEmpty()) {
  54. if (rows.get(0).getString("status").equals("新建")) {
  55. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
  56. updateSQL.setUniqueid(u8id);
  57. updateSQL.setSiteid(siteid);
  58. updateSQL.setValue("entity", entity);
  59. updateSQL.setValue("remarks", remarks);
  60. updateSQL.setValue("billdate", billdate);
  61. updateSQL.setValue("period", billdate.substring(0, 7));
  62. updateSQL.setValue("changeby", username);
  63. updateSQL.setDateValue("changedate");
  64. sqlList.add(updateSQL.getSQL());
  65. sqlList.add(DataContrlLog.createLog(this, "u8", u8id, "更新", "销售出库U8上传更新成功").getSQL());
  66. } else {
  67. return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
  68. }
  69. } else {
  70. return getErrReturnObject().setErrMsg("该销售出库U8上传不存在").toString();
  71. }
  72. }
  73. dbConnect.runSqlUpdate(sqlList);
  74. content.put("u8id", u8id);
  75. return queryu8Main();
  76. }
  77. @API(title = "销售出库U8上传详情", apiversion = R.ID2025073114072103.v1.class)
  78. @CACHEING
  79. public String queryu8Main() throws YosException {
  80. long u8id = content.getLong("u8id");
  81. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "u8","*");
  82. querySQL.setTableAlias("t1");
  83. querySQL.setWhere("t1.siteid", siteid);
  84. querySQL.setWhere("t1.u8id",u8id);
  85. Rows rows = querySQL.query();
  86. Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
  87. return getSucReturnObject().setData(row).toString();
  88. }
  89. @API(title = "销售出库U8上传列表", apiversion = R.ID2025073114074303.v1.class)
  90. @CACHEING
  91. public String queryu8List() throws YosException {
  92. StringBuffer where = new StringBuffer(" 1=1 ");
  93. if (content.containsKey("where")) {
  94. JSONObject whereObject = content.getJSONObject("where");
  95. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  96. where.append(" and(");
  97. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  98. where.append("or t1.entity like'%").append(whereObject.getString("condition")).append("%' ");
  99. where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  100. where.append(")");
  101. }
  102. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  103. where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
  104. }
  105. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  106. where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
  107. }
  108. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  109. where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
  110. }
  111. }
  112. // SQLFactory sqlFactory = new SQLFactory(this, "出入库单列表查询", pageSize, pageNumber, pageSorting);
  113. // sqlFactory.addParameter("siteid", siteid);
  114. // sqlFactory.addParameter_SQL("where", where);
  115. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  116. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "u8","*");
  117. querySQL.setTableAlias("t1");
  118. querySQL.setWhere("t1.siteid", siteid);
  119. querySQL.setWhere(where);
  120. querySQL.setPage(pageSize, pageNumber);
  121. querySQL.setOrderBy(pageSorting);
  122. Rows rows = querySQL.query();
  123. return getSucReturnObject().setData(rows).toString();
  124. }
  125. @API(title = "删除", apiversion = R.ID2025073114073103.v1.class)
  126. @CACHEING_CLEAN(apiClass = {u8.class})
  127. public String delete() throws YosException {
  128. JSONArray u8ids = content.getJSONArray("u8ids");
  129. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, u8ids.size());
  130. for (Object o : u8ids) {
  131. long u8id = Long.parseLong(o.toString());
  132. Rows RowsStatus = dbConnect.runSqlQuery("select u8id,status from u8 where siteid='"
  133. + siteid + "' and u8id='" + u8id + "'");
  134. if (RowsStatus.isNotEmpty()) {
  135. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  136. batchDeleteErr.addErr(u8id, "非新建状态的销售出库U8上传无法删除");
  137. continue;
  138. }
  139. }
  140. ArrayList<String> sqllist = new ArrayList<>();
  141. sqllist.add("delete from u8 where siteid='" + siteid + "' and u8id=" + u8id);
  142. sqllist.add("delete from u8billcodes where siteid='" + siteid + "' and u8id=" + u8id);
  143. sqllist.add("delete from u8bills where siteid='" + siteid + "' and u8id=" + u8id);
  144. sqllist.add("delete from u8itemprice where siteid='" + siteid + "' and u8id=" + u8id);
  145. dbConnect.runSqlUpdate(sqllist);
  146. }
  147. return batchDeleteErr.getReturnObject().toString();
  148. }
  149. @API(title = "审核", apiversion = R.ID2025073114081603.v1.class)
  150. @CACHEING_CLEAN(apiClass = {u8.class})
  151. public String check() throws YosException {
  152. long u8id = content.getLong("u8id");
  153. ArrayList<String> sqllist=new ArrayList<>();
  154. Rows department =dbConnect.runSqlQuery("select departmentid,depno from sys_department where siteid='"+siteid+"'");
  155. RowsMap departmentRowsMap = department.toRowsMap("depno");
  156. Rows stock =dbConnect.runSqlQuery("select stockid,stockno from st_stock where siteid='"+siteid+"'");
  157. RowsMap stockRowsMap = stock.toRowsMap("stockno");
  158. Rows u8=dbConnect.runSqlQuery("select * from u8 where u8id="+u8id);
  159. Rows u8billcodes=dbConnect.runSqlQuery("select * from u8billcodes where u8id="+u8id);
  160. RowsMap u8billcodesRowsMap= u8billcodes.toRowsMap("itemid");
  161. Rows u8bills=dbConnect.runSqlQuery("select t1.*,ifnull(t2.price,0) price,ifnull(t2.taxprice,0) taxprice,t2.taxrate,t3.itemname,t3.itemno,t3.model from (select siteid,itemid,u8id,stockid,rb,sum(qty) qty from u8billcodes group by siteid,itemid,u8id,stockid,rb) t1 left join u8itemprice t2 on t1.u8id=t2.u8id and t1.itemid=t2.itemid and t1.stockid=t2.stockid left join plm_item t3 on t1.itemid=t3.itemid and t1.siteid=t3.siteid where t1.u8id="+u8id);
  162. RowsMap u8billsRowsMap=u8bills.toRowsMap("rb");
  163. if(u8.isEmpty()){
  164. return getErrReturnObject().setErrMsg("该销售出库U8上传不存在").toString();
  165. }
  166. //销售出库蓝
  167. long st_stockbillid = createTableID("st_stockbill");
  168. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  169. insertSQL.setUniqueid(st_stockbillid);
  170. insertSQL.setSiteid(siteid);
  171. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("103")?departmentRowsMap.get("103").get(0).getLong("departmentid"):0);
  172. insertSQL.setValue("stockid", stockRowsMap.containsKey("103")?stockRowsMap.get("103").get(0).getLong("stockid"):0);
  173. insertSQL.setValue("type", "其他出库");
  174. insertSQL.setValue("typemx", "销售出库");
  175. insertSQL.setValue("rb", 1);
  176. insertSQL.setValue("remarks", "U8单据上传生成");
  177. insertSQL.setValue("billdate", u8.get(0).getString("billdate"));
  178. insertSQL.setValue("period",u8.get(0).getString("period"));
  179. insertSQL.setValue("billno", createBillCode("stockbill"));
  180. insertSQL.setValue("isconfirm", 0);
  181. insertSQL.setValue("sourceobject", "u8");
  182. insertSQL.setValue("sourceid", u8id);
  183. insertSQL.setValue("sys_enterpriseid", 0);
  184. insertSQL.setValue("createby", username);
  185. insertSQL.setDateValue("createdate");
  186. insertSQL.setValue("changeby", username);
  187. insertSQL.setDateValue("changedate");
  188. insertSQL.setValue("status", "审核");
  189. insertSQL.setValue("checkby", username);
  190. insertSQL.setDateValue("checkdate");
  191. sqllist.add(insertSQL.getSQL());
  192. if(u8billsRowsMap.containsKey("1")){
  193. int i=0;
  194. for(Row row : u8billsRowsMap.get("1")){
  195. InsertSQL insertSQLdetail = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  196. long st_stockbill_itemsid =createTableID("st_stockbill_items");
  197. insertSQLdetail.setUniqueid(st_stockbill_itemsid);
  198. insertSQLdetail.setSiteid(siteid);
  199. insertSQLdetail.setValue("rowno", i + 1);
  200. insertSQLdetail.setValue("st_stockbillid", st_stockbillid);
  201. insertSQLdetail.setValue("itemid", row.getLong("itemid"));
  202. insertSQLdetail.setValue("qty", row.getBigDecimal("qty"));
  203. insertSQLdetail.setValue("discountrate", 1);
  204. insertSQLdetail.setValue("sa_dispatch_itemsid", 0);
  205. insertSQLdetail.setValue("itemno", row.getString("itemno"));
  206. insertSQLdetail.setValue("itemname", row.getString("itemname"));
  207. insertSQLdetail.setValue("model", row.getString("model"));
  208. insertSQLdetail.setValue("price", row.getBigDecimal("price"));
  209. insertSQLdetail.setValue("amount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price")));
  210. insertSQLdetail.setValue("untaxedprice", row.getBigDecimal("taxprice"));
  211. insertSQLdetail.setValue("untaxedamount", row.getBigDecimal("qty").multiply(row.getBigDecimal("taxprice")));
  212. i++;
  213. sqllist.add(insertSQLdetail.getSQL());
  214. if(u8billcodesRowsMap.containsKey(row.getString("itemid"))){
  215. for(Row row1 :u8billcodesRowsMap.get(row.getString("itemid"))){
  216. if(row1.getBoolean("rb")){
  217. InsertSQL insertSQLdetailsku = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  218. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  219. insertSQLdetailsku.setUniqueid(st_stockbill_items_skuid);
  220. insertSQLdetailsku.setSiteid(siteid);
  221. insertSQLdetailsku.setValue("stockid", row1.getLong("stockid"));
  222. insertSQLdetailsku.setValue("itemid",row1.getLong("itemid"));
  223. insertSQLdetailsku.setValue("sku",StringUtils.isBlank(row1.getString("sku"))?"":row1.getString("sku"));
  224. insertSQLdetailsku.setValue("st_stockbillid",st_stockbillid);
  225. insertSQLdetailsku.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
  226. sqllist.add(insertSQLdetailsku.getSQL());
  227. }
  228. }
  229. }
  230. }
  231. }
  232. //销售出库红
  233. st_stockbillid = createTableID("st_stockbill");
  234. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  235. insertSQL.setUniqueid(st_stockbillid);
  236. insertSQL.setSiteid(siteid);
  237. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("103")?departmentRowsMap.get("103").get(0).getLong("departmentid"):0);
  238. insertSQL.setValue("stockid", stockRowsMap.containsKey("103")?stockRowsMap.get("103").get(0).getLong("stockid"):0);
  239. insertSQL.setValue("type", "其他出库");
  240. insertSQL.setValue("typemx", "销售出库");
  241. insertSQL.setValue("rb", 0);
  242. insertSQL.setValue("remarks", "U8单据上传生成");
  243. insertSQL.setValue("billdate", u8.get(0).getString("billdate"));
  244. insertSQL.setValue("period",u8.get(0).getString("period"));
  245. insertSQL.setValue("billno", createBillCode("stockbill"));
  246. insertSQL.setValue("isconfirm", 0);
  247. insertSQL.setValue("sourceobject", "u8");
  248. insertSQL.setValue("sourceid", u8id);
  249. insertSQL.setValue("sys_enterpriseid", 0);
  250. insertSQL.setValue("createby", username);
  251. insertSQL.setDateValue("createdate");
  252. insertSQL.setValue("changeby", username);
  253. insertSQL.setDateValue("changedate");
  254. insertSQL.setValue("status", "审核");
  255. insertSQL.setValue("checkby", username);
  256. insertSQL.setDateValue("checkdate");
  257. sqllist.add(insertSQL.getSQL());
  258. if(u8billsRowsMap.containsKey("0")){
  259. int i=0;
  260. for(Row row : u8billsRowsMap.get("0")){
  261. InsertSQL insertSQLdetail = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  262. long st_stockbill_itemsid =createTableID("st_stockbill_items");
  263. insertSQLdetail.setUniqueid(st_stockbill_itemsid);
  264. insertSQLdetail.setSiteid(siteid);
  265. insertSQLdetail.setValue("rowno", i + 1);
  266. insertSQLdetail.setValue("st_stockbillid", st_stockbillid);
  267. insertSQLdetail.setValue("itemid", row.getLong("itemid"));
  268. insertSQLdetail.setValue("qty", row.getBigDecimal("qty"));
  269. insertSQLdetail.setValue("discountrate", 1);
  270. insertSQLdetail.setValue("sa_dispatch_itemsid", 0);
  271. insertSQLdetail.setValue("itemno", row.getString("itemno"));
  272. insertSQLdetail.setValue("itemname", row.getString("itemname"));
  273. insertSQLdetail.setValue("model", row.getString("model"));
  274. insertSQLdetail.setValue("price", row.getBigDecimal("price"));
  275. insertSQLdetail.setValue("amount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price")));
  276. insertSQLdetail.setValue("untaxedprice", row.getBigDecimal("taxprice"));
  277. insertSQLdetail.setValue("untaxedamount", row.getBigDecimal("qty").multiply(row.getBigDecimal("taxprice")));
  278. i++;
  279. sqllist.add(insertSQLdetail.getSQL());
  280. if(u8billcodesRowsMap.containsKey(row.getString("itemid"))){
  281. for(Row row1 :u8billcodesRowsMap.get(row.getString("itemid"))){
  282. if(!row1.getBoolean("rb")){
  283. InsertSQL insertSQLdetailsku = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  284. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  285. insertSQLdetailsku.setUniqueid(st_stockbill_items_skuid);
  286. insertSQLdetailsku.setSiteid(siteid);
  287. insertSQLdetailsku.setValue("stockid", row1.getLong("stockid"));
  288. insertSQLdetailsku.setValue("itemid",row1.getLong("itemid"));
  289. insertSQLdetailsku.setValue("sku",StringUtils.isBlank(row1.getString("sku"))?"":row1.getString("sku"));
  290. insertSQLdetailsku.setValue("st_stockbillid",st_stockbillid);
  291. insertSQLdetailsku.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
  292. sqllist.add(insertSQLdetailsku.getSQL());
  293. }
  294. }
  295. }
  296. }
  297. }
  298. //外购入库蓝
  299. st_stockbillid = createTableID("st_stockbill");
  300. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  301. insertSQL.setUniqueid(st_stockbillid);
  302. insertSQL.setSiteid(siteid);
  303. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("101")?departmentRowsMap.get("101").get(0).getLong("departmentid"):0);
  304. insertSQL.setValue("stockid", stockRowsMap.containsKey("101")?stockRowsMap.get("101").get(0).getLong("stockid"):0);
  305. insertSQL.setValue("type", "其他入库");
  306. insertSQL.setValue("typemx", "外购入库");
  307. insertSQL.setValue("rb", 1);
  308. insertSQL.setValue("remarks", "U8单据上传生成");
  309. insertSQL.setValue("billdate", u8.get(0).getString("billdate"));
  310. insertSQL.setValue("period",u8.get(0).getString("period"));
  311. insertSQL.setValue("billno", createBillCode("stockbill"));
  312. insertSQL.setValue("isconfirm", 0);
  313. insertSQL.setValue("sourceobject", "u8");
  314. insertSQL.setValue("sourceid", u8id);
  315. insertSQL.setValue("sys_enterpriseid", 0);
  316. insertSQL.setValue("createby", username);
  317. insertSQL.setDateValue("createdate");
  318. insertSQL.setValue("changeby", username);
  319. insertSQL.setDateValue("changedate");
  320. insertSQL.setValue("status", "审核");
  321. insertSQL.setValue("checkby", username);
  322. insertSQL.setDateValue("checkdate");
  323. sqllist.add(insertSQL.getSQL());
  324. if(u8billsRowsMap.containsKey("1")){
  325. int i=0;
  326. for(Row row : u8billsRowsMap.get("1")){
  327. InsertSQL insertSQLdetail = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  328. long st_stockbill_itemsid =createTableID("st_stockbill_items");
  329. insertSQLdetail.setUniqueid(st_stockbill_itemsid);
  330. insertSQLdetail.setSiteid(siteid);
  331. insertSQLdetail.setValue("rowno", i + 1);
  332. insertSQLdetail.setValue("st_stockbillid", st_stockbillid);
  333. insertSQLdetail.setValue("itemid", row.getLong("itemid"));
  334. insertSQLdetail.setValue("qty", row.getBigDecimal("qty"));
  335. insertSQLdetail.setValue("discountrate", 1);
  336. insertSQLdetail.setValue("sa_dispatch_itemsid", 0);
  337. insertSQLdetail.setValue("itemno", row.getString("itemno"));
  338. insertSQLdetail.setValue("itemname", row.getString("itemname"));
  339. insertSQLdetail.setValue("model", row.getString("model"));
  340. insertSQLdetail.setValue("price", row.getBigDecimal("price"));
  341. insertSQLdetail.setValue("amount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price")));
  342. insertSQLdetail.setValue("untaxedprice", row.getBigDecimal("taxprice"));
  343. insertSQLdetail.setValue("untaxedamount", row.getBigDecimal("qty").multiply(row.getBigDecimal("taxprice")));
  344. i++;
  345. sqllist.add(insertSQLdetail.getSQL());
  346. if(u8billcodesRowsMap.containsKey(row.getString("itemid"))){
  347. for(Row row1 :u8billcodesRowsMap.get(row.getString("itemid"))){
  348. if(row1.getBoolean("rb")){
  349. InsertSQL insertSQLdetailsku = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  350. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  351. insertSQLdetailsku.setUniqueid(st_stockbill_items_skuid);
  352. insertSQLdetailsku.setSiteid(siteid);
  353. insertSQLdetailsku.setValue("stockid", row1.getLong("stockid"));
  354. insertSQLdetailsku.setValue("itemid",row1.getLong("itemid"));
  355. insertSQLdetailsku.setValue("sku",StringUtils.isBlank(row1.getString("sku"))?"":row1.getString("sku"));
  356. insertSQLdetailsku.setValue("st_stockbillid",st_stockbillid);
  357. insertSQLdetailsku.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
  358. sqllist.add(insertSQLdetailsku.getSQL());
  359. }
  360. }
  361. }
  362. }
  363. }
  364. //外购入库红
  365. st_stockbillid = createTableID("st_stockbill");
  366. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  367. insertSQL.setUniqueid(st_stockbillid);
  368. insertSQL.setSiteid(siteid);
  369. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("101")?departmentRowsMap.get("101").get(0).getLong("departmentid"):0);
  370. insertSQL.setValue("stockid", stockRowsMap.containsKey("101")?stockRowsMap.get("101").get(0).getLong("stockid"):0);
  371. insertSQL.setValue("type", "其他入库");
  372. insertSQL.setValue("typemx", "外购入库");
  373. insertSQL.setValue("rb", 0);
  374. insertSQL.setValue("remarks", "U8单据上传生成");
  375. insertSQL.setValue("billdate", u8.get(0).getString("billdate"));
  376. insertSQL.setValue("period",u8.get(0).getString("period"));
  377. insertSQL.setValue("billno", createBillCode("stockbill"));
  378. insertSQL.setValue("isconfirm", 0);
  379. insertSQL.setValue("sourceobject", "u8");
  380. insertSQL.setValue("sourceid", u8id);
  381. insertSQL.setValue("sys_enterpriseid", 0);
  382. insertSQL.setValue("createby", username);
  383. insertSQL.setDateValue("createdate");
  384. insertSQL.setValue("changeby", username);
  385. insertSQL.setDateValue("changedate");
  386. insertSQL.setValue("status", "审核");
  387. insertSQL.setValue("checkby", username);
  388. insertSQL.setDateValue("checkdate");
  389. sqllist.add(insertSQL.getSQL());
  390. if(u8billsRowsMap.containsKey("0")){
  391. int i=0;
  392. for(Row row : u8billsRowsMap.get("0")){
  393. InsertSQL insertSQLdetail = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  394. long st_stockbill_itemsid =createTableID("st_stockbill_items");
  395. insertSQLdetail.setUniqueid(st_stockbill_itemsid);
  396. insertSQLdetail.setSiteid(siteid);
  397. insertSQLdetail.setValue("rowno", i + 1);
  398. insertSQLdetail.setValue("st_stockbillid", st_stockbillid);
  399. insertSQLdetail.setValue("itemid", row.getLong("itemid"));
  400. insertSQLdetail.setValue("qty", row.getBigDecimal("qty"));
  401. insertSQLdetail.setValue("discountrate", 1);
  402. insertSQLdetail.setValue("sa_dispatch_itemsid", 0);
  403. insertSQLdetail.setValue("itemno", row.getString("itemno"));
  404. insertSQLdetail.setValue("itemname", row.getString("itemname"));
  405. insertSQLdetail.setValue("model", row.getString("model"));
  406. insertSQLdetail.setValue("price", row.getBigDecimal("price"));
  407. insertSQLdetail.setValue("amount", row.getBigDecimal("qty").multiply(row.getBigDecimal("price")));
  408. insertSQLdetail.setValue("untaxedprice", row.getBigDecimal("taxprice"));
  409. insertSQLdetail.setValue("untaxedamount", row.getBigDecimal("qty").multiply(row.getBigDecimal("taxprice")));
  410. i++;
  411. sqllist.add(insertSQLdetail.getSQL());
  412. if(u8billcodesRowsMap.containsKey(row.getString("itemid"))){
  413. for(Row row1 :u8billcodesRowsMap.get(row.getString("itemid"))){
  414. if(!row1.getBoolean("rb")){
  415. InsertSQL insertSQLdetailsku = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  416. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  417. insertSQLdetailsku.setUniqueid(st_stockbill_items_skuid);
  418. insertSQLdetailsku.setSiteid(siteid);
  419. insertSQLdetailsku.setValue("stockid", row1.getLong("stockid"));
  420. insertSQLdetailsku.setValue("itemid",row1.getLong("itemid"));
  421. insertSQLdetailsku.setValue("sku", StringUtils.isBlank(row1.getString("sku"))?"":row1.getString("sku"));
  422. insertSQLdetailsku.setValue("st_stockbillid",st_stockbillid);
  423. insertSQLdetailsku.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
  424. sqllist.add(insertSQLdetailsku.getSQL());
  425. }
  426. }
  427. }
  428. }
  429. }
  430. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "u8");
  431. updateSQL.setUniqueid(u8id);
  432. updateSQL.setSiteid(siteid);
  433. updateSQL.setValue("status", "审核");
  434. // updateSQL.setValue("checkby", username);
  435. // updateSQL.setDateValue("checkdate");
  436. sqllist.add(updateSQL.getSQL());
  437. dbConnect.runSqlUpdate(sqllist);
  438. updateIcinvbal(true,u8id);
  439. return getSucReturnObject().toString();
  440. }
  441. @API(title = "反审核", apiversion = R.ID2025073114082503.v1.class)
  442. @CACHEING_CLEAN(apiClass = {u8.class})
  443. public String uncheck() throws YosException {
  444. long u8id = content.getLong("u8id");
  445. ArrayList<String> sqllist=new ArrayList<>();
  446. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "u8");
  447. updateSQL.setUniqueid(u8id);
  448. updateSQL.setSiteid(siteid);
  449. updateSQL.setValue("status", "新建");
  450. // updateSQL.setValue("checkby", "");
  451. // updateSQL.setValue("checkdate","null");
  452. sqllist.add(updateSQL.getSQL());
  453. sqllist.add("delete from st_stockbill_items where st_stockbillid in(select st_stockbillid from st_stockbill where sourceid="+u8id +" and sourceobject='u8')");
  454. sqllist.add("delete from st_stockbill_items_sku where st_stockbillid in(select st_stockbillid from st_stockbill where sourceid="+u8id +" and sourceobject='u8')");
  455. sqllist.add("delete from st_stockbill where sourceid="+u8id +" and sourceobject='u8'");
  456. updateIcinvbal(false,u8id);
  457. dbConnect.runSqlUpdate(sqllist);
  458. return getSucReturnObject().toString();
  459. }
  460. public void updateIcinvbal(boolean ischeck,long u8id) throws YosException {
  461. StringBuffer sql = new StringBuffer();
  462. sql.append("select t.stockid,t.itemid,sum(t.qty)qty from (");
  463. sql.append("select t2.itemid,t2.stockid,");
  464. sql.append("CASE ");
  465. sql.append("WHEN t1.type='其他出库' and t1.rb='1' then -t2.qty ");
  466. sql.append("WHEN t1.type='其他出库' and t1.rb='0' then t2.qty ");
  467. sql.append("WHEN t1.type='其他入库' and t1.rb='1' then t2.qty ");
  468. sql.append("WHEN t1.type='其他入库' and t1.rb='0' then -t2.qty ");
  469. sql.append("end qty ");
  470. sql.append(" from st_stockbill t1 ");
  471. sql.append("inner join st_stockbill_items t2 on t1.st_stockbillid=t2.st_stockbillid ");
  472. sql.append("where t1.sourceobject='U8' and t1.sourceid='"
  473. + u8id + "' and t1.status='审核' ");
  474. sql.append(")t group by t.stockid,t.itemid");
  475. Rows rows= dbConnect.runSqlQuery(sql.toString());
  476. ArrayList<String> sqlList = new ArrayList<>();
  477. RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid", rows.toArrayList("itemid")).query().toRowsMap("itemid");
  478. RowsMap invbalsTotalRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal_total").setWhere("siteid", siteid).setWhere("itemid", rows.toArrayList("itemid")).query().toRowsMap("itemid");
  479. RowsMap invbalsSaleRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal_sale").setWhere("siteid", siteid).setWhere("itemid", rows.toArrayList("itemid")).query().toRowsMap("itemid");
  480. int i = 0;
  481. for (Row row : rows) {
  482. long itemid =row.getLong("itemid");
  483. long stockid = row.getLong("stockid");
  484. BigDecimal qty = ischeck ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
  485. if (!invbalsRowsMap.containsKey(String.valueOf(itemid)) || !invbalsRowsMap.get(String.valueOf(itemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
  486. InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal");
  487. invbalInsert.setValue("siteid", siteid);
  488. invbalInsert.setValue("stockid", stockid);
  489. invbalInsert.setValue("itemid", itemid);
  490. invbalInsert.setValue("qty", qty.doubleValue());
  491. sqlList.add(invbalInsert.getSQL());
  492. } else {
  493. UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal");
  494. invbalUpdate.addValue("qty", invbalsRowsMap.get(String.valueOf(itemid)).get(0).getBigDecimal("qty").add(qty));
  495. invbalUpdate.setWhere("itemid", itemid);
  496. invbalUpdate.setWhere("stockid", stockid);
  497. invbalUpdate.setWhere("siteid", siteid);
  498. sqlList.add(invbalUpdate.getSQL());
  499. }
  500. // //是否纳入总仓
  501. //
  502. // if (SQLFactory.getRow(this,"st_stock", stockid).getBoolean("isintotalstock")) {
  503. // if (!invbalsTotalRowsMap.containsKey(String.valueOf(itemid))) {
  504. // InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal_total");
  505. // invbalInsert.setValue("siteid", siteid);
  506. // invbalInsert.setValue("itemid", itemid);
  507. // invbalInsert.setValue("cansaleqty", qty.doubleValue());//可销售数量
  508. // invbalInsert.setValue("candispatchqty", qty.doubleValue());//可发货数量
  509. // invbalInsert.setValue("qty", qty.doubleValue());//库存数量
  510. // sqlList.add(invbalInsert.getSQL());
  511. // } else {
  512. // UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal_total");
  513. // invbalUpdate.addValue("qty", invbalsTotalRowsMap.get(String.valueOf(itemid)).get(0).getBigDecimal("qty").add(qty));//库存数量
  514. // invbalUpdate.setWhere("itemid", itemid);
  515. // invbalUpdate.setWhere("siteid", siteid);
  516. // sqlList.add(invbalUpdate.getSQL());
  517. // }
  518. // }
  519. //是否为销售仓库
  520. if (SQLFactory.getRow(this, "st_stock", stockid).getBoolean("issalestock")) {
  521. if (!invbalsSaleRowsMap.containsKey(String.valueOf(itemid))) {
  522. InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal_sale");
  523. invbalInsert.setValue("siteid", siteid);
  524. invbalInsert.setValue("itemid", itemid);
  525. invbalInsert.setValue("cansaleqty", qty.doubleValue());//可销售数量
  526. invbalInsert.setValue("candispatchqty", qty.doubleValue());//可发货数量
  527. invbalInsert.setValue("qty", qty.doubleValue());//库存数量
  528. sqlList.add(invbalInsert.getSQL());
  529. } else {
  530. UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal_sale");
  531. invbalUpdate.addValue("qty", invbalsSaleRowsMap.get(String.valueOf(itemid)).get(0).getBigDecimal("qty").add(qty));//库存数量
  532. invbalUpdate.setWhere("itemid", itemid);
  533. invbalUpdate.setWhere("siteid", siteid);
  534. sqlList.add(invbalUpdate.getSQL());
  535. }
  536. }
  537. }
  538. }
  539. @API(title = "一键清空", apiversion = R.ID2025073114272903.v1.class)
  540. @CACHEING_CLEAN(apiClass = {u8.class, u8billcodes.class, u8bills.class, u8itemprice.class})
  541. public String deleteAll() throws YosException {
  542. long u8id = content.getLong("u8id");
  543. ArrayList<String> sqllist=new ArrayList<>();
  544. Rows RowsStatus = dbConnect.runSqlQuery("select u8id,status from u8 where siteid='"
  545. + siteid + "' and u8id='" + u8id + "'");
  546. if (RowsStatus.isNotEmpty()) {
  547. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  548. return getErrReturnObject().setErrMsg("非新建状态的销售出库U8上传无法一键清空").toString();
  549. }
  550. }
  551. sqllist.add("delete from u8billcodes where siteid='" + siteid + "' and u8id=" + u8id);
  552. sqllist.add("delete from u8bills where siteid='" + siteid + "' and u8id=" + u8id);
  553. sqllist.add("delete from u8itemprice where siteid='" + siteid + "' and u8id=" + u8id);
  554. dbConnect.runSqlUpdate(sqllist);
  555. return getSucReturnObject().toString();
  556. }
  557. @API(title = "一键取单", apiversion = R.ID2025073114290603.v1.class)
  558. @CACHEING_CLEAN(apiClass = {u8.class, u8billcodes.class, u8bills.class, u8itemprice.class})
  559. public String oneclickaddbills() throws YosException {
  560. long u8id = content.getLong("u8id");
  561. ArrayList<String> sqllist=new ArrayList<>();
  562. sqllist.add("delete from u8billcodes where siteid='" + siteid + "' and u8id=" + u8id);
  563. sqllist.add("delete from u8bills where siteid='" + siteid + "' and u8id=" + u8id);
  564. sqllist.add("delete from u8itemprice where siteid='" + siteid + "' and u8id=" + u8id);
  565. SQLFactory sqlFactory =new SQLFactory(this,"销售出库U8上传序列号查询");
  566. sqlFactory.addParameter("u8id",u8id);
  567. Rows rows =dbConnect.runSqlQuery(sqlFactory);
  568. for(Row row : rows){
  569. long u8billcodesid = createTableID("u8billcodes");
  570. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "u8billcodes");
  571. insertSQL.setUniqueid(u8billcodesid);
  572. insertSQL.setSiteid(siteid);
  573. insertSQL.setValue("u8id", u8id);
  574. insertSQL.setValue("sourceid", row.getString("sourceid"));
  575. insertSQL.setValue("sourceobject", row.getString("sourceobject"));
  576. insertSQL.setValue("type", row.getString("type"));
  577. insertSQL.setValue("typemx", row.getString("typemx"));
  578. insertSQL.setValue("stockid", row.getString("stockid"));
  579. insertSQL.setValue("status", row.getString("status"));
  580. insertSQL.setValue("rb", row.getString("rb"));
  581. insertSQL.setValue("qty", row.getString("qty"));
  582. insertSQL.setValue("st_stockbillid", row.getString("st_stockbillid"));
  583. insertSQL.setValue("st_stockbill_items_skuid", row.getString("st_stockbill_items_skuid"));
  584. insertSQL.setValue("sku", row.getString("sku"));
  585. insertSQL.setValue("itemid", row.getString("itemid"));
  586. insertSQL.setValue("billno", row.getString("billno"));
  587. sqllist.add(insertSQL.getSQL());
  588. }
  589. dbConnect.runSqlUpdate(sqllist);
  590. sqllist=new ArrayList<>();
  591. sqlFactory =new SQLFactory(this,"销售出库U8上传单据查询");
  592. sqlFactory.addParameter("u8id",u8id);
  593. Rows rowsbill =dbConnect.runSqlQuery(sqlFactory);
  594. for(Row row : rowsbill){
  595. long u8billsid = createTableID("u8bills");
  596. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "u8bills");
  597. insertSQL.setUniqueid(u8billsid);
  598. insertSQL.setSiteid(siteid);
  599. insertSQL.setValue("u8id", u8id);
  600. insertSQL.setValue("name", row.getString("name"));
  601. insertSQL.setValue("address", row.getString("address"));
  602. insertSQL.setValue("billdate", row.getString("billdate"));
  603. insertSQL.setValue("outplace", row.getString("outplace"));
  604. insertSQL.setValue("remarks", row.getString("remarks"));
  605. insertSQL.setValue("period", row.getString("period"));
  606. insertSQL.setValue("sys_enterpriseid", row.getString("sys_enterpriseid"));
  607. insertSQL.setValue("rb", row.getString("rb"));
  608. insertSQL.setValue("sourceobject", row.getString("sourceobject"));
  609. insertSQL.setValue("sourceid", row.getString("sourceid"));
  610. insertSQL.setValue("phonenumber", row.getString("phonenumber"));
  611. insertSQL.setValue("st_stockbillid", row.getString("st_stockbillid"));
  612. insertSQL.setValue("type", row.getString("type"));
  613. insertSQL.setValue("typemx", row.getString("typemx"));
  614. insertSQL.setValue("billno", row.getString("billno"));
  615. sqllist.add(insertSQL.getSQL());
  616. }
  617. dbConnect.runSqlUpdate(sqllist);
  618. sqllist=new ArrayList<>();
  619. Rows stock =dbConnect.runSqlQuery("select stockid,stockno from st_stock where siteid='"+siteid+"'");
  620. RowsMap stockRowsMap = stock.toRowsMap("stockno");
  621. SQLFactory sqlFactory1 =new SQLFactory(this,"销售出库u8商品价格查询");
  622. sqlFactory1.addParameter("u8id",u8id);
  623. sqlFactory1.addParameter("tqstockid",stockRowsMap.containsKey("103")?stockRowsMap.get("103").get(0).getLong("stockid"):0);
  624. sqlFactory1.addParameter("mqstockid",stockRowsMap.containsKey("109")?stockRowsMap.get("109").get(0).getLong("stockid"):0);
  625. Rows rowsitemprice=dbConnect.runSqlQuery(sqlFactory1);
  626. for(Row row : rowsitemprice){
  627. long u8itempriceid = createTableID("u8itemprice");
  628. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "u8itemprice");
  629. insertSQL.setUniqueid(u8itempriceid);
  630. insertSQL.setSiteid(siteid);
  631. insertSQL.setValue("u8id", u8id);
  632. insertSQL.setValue("itemid", row.getString("itemid"));
  633. insertSQL.setValue("taxrate", row.getString("taxrate"));
  634. insertSQL.setValue("stockid", row.getString("stockid"));
  635. insertSQL.setValue("saleprice", row.getString("saleprice"));
  636. insertSQL.setValue("saleamount", row.getBigDecimal("saleprice").multiply(row.getBigDecimal("qty")));
  637. insertSQL.setValue("qty", row.getString("qty"));
  638. sqllist.add(insertSQL.getSQL());
  639. }
  640. dbConnect.runSqlUpdate(sqllist);
  641. return getSucReturnObject().toString();
  642. }
  643. @API(title = "选择取单", apiversion = R.ID2025073114292603.v1.class)
  644. @CACHEING_CLEAN(apiClass = {u8.class, u8billcodes.class, u8bills.class, u8itemprice.class})
  645. public String selectaddbills() throws YosException {
  646. return getSucReturnObject().toString();
  647. }
  648. @API(title = "价格调整", apiversion = R.ID2025073114312903.v1.class)
  649. @CACHEING_CLEAN(apiClass = {u8.class, u8billcodes.class, u8bills.class, u8itemprice.class})
  650. public String changeprice() throws YosException {
  651. long u8id = content.getLong("u8id");
  652. String changetype=content.getString("changetype");
  653. BigDecimal changevalue=content.getBigDecimal("changevalue");
  654. ArrayList<String> sqllist=new ArrayList<>();
  655. Rows u8itempricerows = dbConnect.runSqlQuery("select * from u8itemprice where siteid='"+siteid+"' and u8id="+u8id);
  656. for(Row row :u8itempricerows){
  657. BigDecimal taxprice=BigDecimal.ZERO;
  658. BigDecimal price=BigDecimal.ZERO;
  659. if(changetype.equals("百分比")){
  660. taxprice= row.getBigDecimal("saleprice").multiply(BigDecimal.valueOf(100).add(changevalue)).divide(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
  661. price=taxprice.multiply(BigDecimal.valueOf(100).add(row.getBigDecimal("taxrate"))).divide(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
  662. }else if (changetype.equals("金额")) {
  663. taxprice = row.getBigDecimal("saleprice").add(changevalue);
  664. price=taxprice.multiply(BigDecimal.valueOf(100).add(row.getBigDecimal("taxrate"))).divide(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
  665. }
  666. sqllist.add("update u8itemprice set price="+price+",taxprice="+taxprice+" where u8itempriceid="+ row.getLong("u8itempriceid"));
  667. }
  668. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "u8");
  669. updateSQL.setUniqueid(u8id);
  670. updateSQL.setSiteid(siteid);
  671. updateSQL.setValue("changetype",changetype);
  672. updateSQL.setValue("changevalue",changevalue);
  673. sqllist.add(updateSQL.getSQL());
  674. dbConnect.runSqlUpdate(sqllist);
  675. return getSucReturnObject().toString();
  676. }
  677. @API(title = "创建U8发货单", apiversion = R.ID2025080113261703.v1.class)
  678. public String createU8Bill() throws YosException {
  679. long u8id=content.getLong("u8id");
  680. Rows u8s=dbConnect.runSqlQuery("select * from u8 where u8id="+u8id);
  681. if(u8s.isEmpty()){
  682. return getErrReturnObject().setErrMsg("该销售出库U8上传不存在").toString();
  683. }
  684. Row u8=u8s.get(0);
  685. JSONObject object = new JSONObject();
  686. object.put("accesstoken", 1);
  687. object.put("classname", "U8System_Dispatch");
  688. object.put("method", "insert");
  689. JSONObject content = new JSONObject();
  690. content.put("cAcc_Id", "666");
  691. content.put("ddate", u8.getString("billdate"));
  692. content.put("cdlcode", u8.getString("billno"));
  693. content.put("sysfrom", "drp");
  694. JSONArray detail = new JSONArray();
  695. Rows rows = dbConnect.runSqlQuery("select t3.itemno,t1.itemid,t1.stockno,ifnull(t1.qty,0) qty,ifnull(t2.price,0) price,ifnull(t2.taxprice,0) taxprice,ifnull(t2.taxrate,0) taxrate,t2.stockid from (\n" +
  696. "select distinct t1.itemid,t1.u8id,case when t2.outplace='谈桥' then '103' when t2.outplace='马桥' then '109' else t3.stockno end as stockno,sum(t1.qty)qty from u8billcodes t1\n" +
  697. "inner join u8bills t2 on t1.billno=t2.billno and t1.u8id=t2.u8id \n" +
  698. "left join st_stock t3 on t1.stockid=t3.stockid\n" +
  699. "where t1.rb='1' and t1.u8id=" +u8id+
  700. " group by t1.itemid,case when t2.outplace='谈桥' then '103' when t2.outplace='马桥' then '109' else t3.stockno end,t1.u8id )t1 left join u8itemprice t2 on t1.u8id=t2.u8id and t1.itemid=t2.itemid left join plm_item t3 on t1.itemid=t3.itemid");
  701. int rowno = 1;
  702. for (Row row : rows) {
  703. BigDecimal qty = row.getBigDecimal("qty");
  704. BigDecimal taxrate = row.getBigDecimal("taxrate");
  705. BigDecimal taxprice = row.getBigDecimal("taxprice");
  706. BigDecimal price = row.getBigDecimal("price");
  707. JSONObject dObject = new JSONObject();
  708. dObject.put("cinvcode", row.getString("itemno"));
  709. dObject.put("iquantity", qty + "");
  710. dObject.put("irowno", rowno++);
  711. dObject.put("fprice", price + "");// 去税单价
  712. // dObject.put("famount", new BigDecimal(Math.mul(fprice, fqty,
  713. // 2)).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());//去税金额
  714. dObject.put(
  715. "famount",price.multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP)
  716. .toPlainString());// 去税金额
  717. dObject.put(
  718. "ftax", (taxprice.subtract(price)).multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());// 税额
  719. dObject.put("ftaxrate", taxrate + "");// 税率
  720. dObject.put(
  721. "ftaxamount", taxprice.multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());// 价税合计
  722. dObject.put("ftaxprice", taxprice + "");// 含税单价
  723. dObject.put("fstockno", row.getString("stockno").toString());
  724. Rows codeRows =dbConnect.runSqlQuery("select sku from u8billcodes where rb='1' and u8id='"
  725. + u8id
  726. + "' and "
  727. + "itemid='"
  728. + row.getString("itemid")
  729. + "' and stockid='"
  730. + row.getString("stockid")
  731. + "' and ifnull(sku,'')!=''");
  732. dObject.put("fmachinecodes", codeRows.toArrayList("sku"));
  733. detail.add(dObject);
  734. }
  735. content.put("detail", detail);
  736. object.put("content", content);
  737. // U8Rest rest = new U8Rest();
  738. // String a = rest.post(object.toString());
  739. return getSucReturnObject().toString();
  740. }
  741. @API(title = "创建U8退货单", apiversion = R.ID2025080113595003.v1.class)
  742. public String createU8ReturnBill() throws YosException {
  743. long u8id=content.getLong("u8id");
  744. Rows u8s=dbConnect.runSqlQuery("select * from u8 where u8id="+u8id);
  745. if(u8s.isEmpty()){
  746. return getErrReturnObject().setErrMsg("该销售出库U8上传不存在").toString();
  747. }
  748. Row u8=u8s.get(0);
  749. JSONObject object = new JSONObject();
  750. object.put("accesstoken", 1);
  751. object.put("classname", "U8System_Dispatch");
  752. object.put("method", "insertReturn");
  753. JSONObject content = new JSONObject();
  754. content.put("cAcc_Id", "666");
  755. content.put("ddate", u8.getString("billdate"));
  756. content.put("cdlcode", u8.getString("billno") + "R");
  757. content.put("sysfrom", "drp");
  758. JSONArray detail = new JSONArray();
  759. Rows rows = dbConnect.runSqlQuery("select t1.itemid,t1.stockno,ifnull(-t1.qty,0) qty,ifnull(t2.price,0) price,ifnull(t2.taxprice,0) taxprice,ifnull(t2.taxrate,0) taxrate,t3.itemno,t2.stockid from (\n" +
  760. "select distinct t1.itemid,t1.u8id,case when t2.outplace='谈桥' then '103' when t2.outplace='马桥' then '109' else t3.stockno end as stockno,sum(t1.qty)qty from u8billcodes t1\n" +
  761. "inner join u8bills t2 on t1.billno=t2.billno and t1.u8id=t2.u8id \n" +
  762. "left join st_stock t3 on t1.stockid=t3.stockid\n" +
  763. "where t1.rb='0' and t1.u8id=" +u8id+
  764. " group by t1.itemid,case when t2.outplace='谈桥' then '103' when t2.outplace='马桥' then '109' else t3.stockno end,t1.u8id )t1 left join u8itemprice t2 on t1.u8id=t2.u8id and t1.itemid=t2.itemid left join plm_item t3 on t1.itemid=t3.itemid");
  765. int rowno = 1;
  766. for (Row row : rows) {
  767. BigDecimal qty = row.getBigDecimal("qty");
  768. BigDecimal taxrate = row.getBigDecimal("taxrate");
  769. BigDecimal taxprice = row.getBigDecimal("taxprice");
  770. BigDecimal price = row.getBigDecimal("price");
  771. JSONObject dObject = new JSONObject();
  772. dObject.put("cinvcode", row.getString("itemno"));
  773. dObject.put("iquantity", qty + "");
  774. dObject.put("irowno", rowno++);
  775. dObject.put("fprice", price + "");
  776. dObject.put("famount", price.multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
  777. dObject.put(
  778. "ftax", (taxprice.subtract(price)).multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
  779. dObject.put("ftaxrate", taxrate + "");
  780. dObject.put(
  781. "ftaxamount", taxprice.multiply(qty).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
  782. dObject.put("ftaxprice", taxprice + "");
  783. dObject.put("fstockno", row.getString("fstockno").toString());
  784. Rows codeRows =dbConnect.runSqlQuery("select sku from u8billcodes where rb='0' and u8id='"
  785. + u8id
  786. + "' and "
  787. + "itemid='"
  788. + row.getString("itemid")
  789. + "' and stockid='"
  790. + row.getString("stockid")
  791. + "' and ifnull(sku,'')!=''");
  792. dObject.put("fmachinecodes", codeRows.toArrayList("sku"));
  793. detail.add(dObject);
  794. }
  795. content.put("detail", detail);
  796. object.put("content", content);
  797. U8Rest rest = new U8Rest();
  798. // String a = rest.post(object.toString());
  799. //System.err.println(a);
  800. // ((PaoSet) getThisPaoSet()).addWarning(new P2AppException("", a));
  801. return getSucReturnObject().toString();
  802. }
  803. }