123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- package restcontroller.webmanage.sale.toolbill;
- import beans.accountbalance.Accountbalance;
- import beans.accountbalance.CashbillEntity;
- import beans.datacontrllog.DataContrlLog;
- import beans.dataextend.DataExtend;
- import beans.datateam.DataTeam;
- import beans.hr.Hr;
- import beans.parameter.Parameter;
- import beans.remind.Remind;
- import beans.uploaderpdata.UploadDataToERP;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.annotation.CACHEING;
- import common.annotation.CACHEING_CLEAN;
- import common.data.Row;
- import common.data.Rows;
- import common.data.RowsMap;
- import common.data.SQLFactory;
- import restcontroller.R;
- import restcontroller.webmanage.sale.order.Order;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- import static beans.order.Order.getOrderRows;
- /**
- * 工具借用单
- */
- public class ToolBill extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public ToolBill(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "查询企业的工具合同", apiversion = R.ID20230114092502.v1.class)
- public String queryEnterpriseToolContract() 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.billno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.title like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- if (content.containsKey("sys_enterpriseid")) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- }
- SQLFactory sqlFactory = new SQLFactory(this, "查询企业的工具合同", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "新增或更新", apiversion = R.ID20230116092702.v1.class, intervaltime = 200)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String insertOrUpdate() throws YosException {
- //表名
- String tableName = "sa_order";
- Long sa_orderid = content.getLong("sa_orderid");
- if (content.getLongValue("sys_enterpriseid") > 0) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- }
- Long sa_brandid = content.getLongValue("sa_brandid");
- Long sa_contractid = content.getLongValue("sa_contractid");
- Long sa_projectid = content.getLongValue("sa_projectid");
- boolean isAdd;
- SQLFactory sqlFactory = new SQLFactory(this, "工具借用单新增");
- if (sa_orderid <= 0) {
- isAdd = true;
- sa_orderid = createTableID(tableName);
- //默认当前用户为负责人
- DataTeam.createTeam(this, "sa_order", sa_orderid, userid);
- dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "新增", "工具借用单新增成功").getSQL());
- } else {
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_order WHERE sa_orderid = " + sa_orderid);
- if (rows.isNotEmpty()) {
- sqlFactory = new SQLFactory(this, "工具借用单更新");
- isAdd = false;
- dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "更新", "订单更新成功").getSQL());
- } else {
- return getErrReturnObject().setErrMsg("未找到数据").toString();
- }
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- //订单编号
- sqlFactory.addParameter("sonum", createBillCode("orderbill"));
- //订单类型
- sqlFactory.addParameter("type", "工具借用单");
- //明细分类
- sqlFactory.addParameter("typemx", content.getStringValue("typemx"));
- //订货企业id
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- //营销账户类型ID
- sqlFactory.addParameter("sa_accountclassid", beans.order.Order.getDefaultAccount(siteid, "工具借用单"));
- //品牌ID
- sqlFactory.addParameter("sa_brandid", sa_brandid);
- //合同ID
- sqlFactory.addParameter("sa_contractid", sa_contractid);
- //工程项目表ID
- sqlFactory.addParameter("sa_projectid", sa_projectid);
- //合作企业财务信息ID(开票信息)
- Long sys_enterprise_financeid = content.getLongValue("sys_enterprise_financeid");
- if (sys_enterprise_financeid <= 0 && isAdd) {
- sys_enterprise_financeid = new Order(content).getDefaultEnterpriseFinanceid(sys_enterpriseid);
- }
- sqlFactory.addParameter("sys_enterprise_financeid", sys_enterprise_financeid);
- //物流公司档案ID
- //sqlFactory.addParameter("sa_logiscompid", content.getLongValue("sa_logiscompid"));
- //合作企业联系人表ID(收货信息)
- //合作企业联系人表ID(收货信息),设置默认
- Long rec_contactsid = content.getLongValue("rec_contactsid");
- if (rec_contactsid <= 0 && isAdd) {
- rec_contactsid = new Order(content).getDefaultContactsid(sys_enterpriseid);
- }
- sqlFactory.addParameter("rec_contactsid", rec_contactsid);
- //备注说明
- sqlFactory.addParameter("remarks", content.getStringValue("remarks"));
- //销售人员hrid,业务员hrid
- sqlFactory.addParameter("saler_hrid", new Order(content).getSaleHrid(sys_enterpriseid));
- //制单方 1表示工厂方,0表示客户方
- if (usertype == 21 || usertype == 22) {
- sqlFactory.addParameter("createflag", 0);
- } else {
- sqlFactory.addParameter("createflag", 1);
- }
- // 领域
- sqlFactory.addParameter("tradefield", content.getStringValue("tradefield"));
- //结算单位
- Long pay_enterpriseid = content.getLongValue("pay_enterpriseid");
- if (isAdd) {
- pay_enterpriseid = sys_enterpriseid;
- }
- sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
- //单据日期
- String billdate = content.getStringValue("billdate");
- //订单新增时
- if (isAdd) {
- if (billdate.equals("")) {
- sqlFactory.addParameter_SQL("billdate", "current_time");
- } else {
- sqlFactory.addParameter("billdate", billdate);
- }
- } else {
- //订单更新时
- if (billdate.equals("")) {
- sqlFactory.addParameter_SQL("billdate", "createdate");
- } else {
- sqlFactory.addParameter("billdate", billdate);
- }
- }
- sqlFactory.addParameter("rebate_used", content.getBooleanValue("rebate_used"));
- sqlFactory.addParameter("signbacknum", content.getStringValue("signbacknum"));
- sqlFactory.addParameter("tradefieldmx", content.getStringValue("tradefieldmx"));
- sqlFactory.addParameter("sa_promotionid", "null");
- sqlFactory.addParameter("freightstatus", content.getStringValue("freightstatus"));
- //套
- Long toolcount = content.getLongValue("toolcount", 1L);
- sqlFactory.addParameter("toolcount", toolcount);
- String sql = sqlFactory.getSQL();
- dbConnect.runSqlUpdate(sql);
- content.put("sa_orderid", sa_orderid);
- return selectDetail();
- }
- @API(title = "更改套数", apiversion = R.ID20230202135502.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String changeToolCount() throws YosException {
- //表名
- Long sa_orderid = content.getLong("sa_orderid");
- Long toolcount = content.getLongValue("toolcount", 1L);
- SQLFactory sqlFactory = new SQLFactory(this, "工具借用单更新套数");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlFactory.addParameter("toolcount", toolcount);
- String sql = sqlFactory.getSQL();
- dbConnect.runSqlUpdate(sql);
- content.put("sa_orderid", sa_orderid);
- return selectDetail();
- }
- @API(title = "工具借用单列表", apiversion = R.ID20230114105002.v1.class)
- @CACHEING
- public String queryToolList() throws YosException, IOException {
- 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.sonum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t5.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- //状态
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and(");
- where.append("t1.status like'%").append(whereObject.getString("status")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("' ");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and t1.billdate <='").append(whereObject.getString("enddate")).append("' ");
- }
- }
- //是否管理端
- Long isManage = content.getLongValue("isManage", 2L);
- //经销商
- if (isManage == 1 && (usertype == 21 || usertype == 22)) {
- where.append(" and t1.sys_enterpriseid = " + sys_enterpriseid + " ");
- }
- //业务员
- if (isManage == 0 && usertype == 1) {
- ArrayList<Long> sys_enterpriseids = new ArrayList<>();
- sys_enterpriseids.addAll(Hr.getAgents(this, hrid));
- sys_enterpriseids.addAll(Hr.getCustomers(this, hrid));
- String sql = " and t1.sys_enterpriseid IN " + sys_enterpriseids;
- sql = sql.replace("[", "(").replace("]", ")");
- where.append(sql);
- }
- boolean isExport = content.getBooleanValue("isExport");
- SQLFactory sqlFactory = new SQLFactory(this, "工具借用单列表", pageSize, pageNumber, pageSorting);
- if (isExport) {
- sqlFactory = new SQLFactory(this, "工具借用单列表");
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_SQL("where", where);
- String sql = sqlFactory.getSQL();
- Rows rows = dbConnect.runSqlQuery(sql);
- //查询数据:amount,defaultamount,qty
- ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
- sqlFactory = new SQLFactory(this, "查询工具数据");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_in("sa_orderid", sa_orderids);
- RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
- for (Row row : rows) {
- Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
- if (dataRows.isNotEmpty()) {
- row.putAll(dataRows.get(0));
- } else {
- row.put("amount", 0);
- row.put("qty", 0);
- }
- }
- // if (isExport) {
- // Rows uploadRows = uploadExcelToObs("order", "工具借用单列表", rows, new HashMap<>());
- // return getSucReturnObject().setData(uploadRows).toString();
- // }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "工具借用单详情", apiversion = R.ID20230114140402.v1.class)
- @CACHEING
- public String selectDetail() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- //查询详情
- SQLFactory sqlFactory = new SQLFactory(this, "工具借用单详情");
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- //查询数据
- ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
- sqlFactory = new SQLFactory(this, "查询工具数据");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_in("sa_orderid", sa_orderids);
- RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
- ArrayList<Long> sys_enterpriseids = rows.toArrayList("pay_enterpriseid", new ArrayList<>());
- //查询开票信息
- sqlFactory = new SQLFactory(this, "查询经销商默认开票信息");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseids);
- RowsMap financeRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sys_enterpriseid");
- for (Row row : rows) {
- row.put("pay_finance", financeRowsMap.getOrDefault(row.getString("sys_enterpriseid"), new Rows()));
- Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
- if (dataRows.isNotEmpty()) {
- row.putAll(dataRows.get(0));
- } else {
- row.put("amount", 0);
- row.put("qty", 0);
- }
- }
- Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
- Long pay_enterpriseid = row.getLong("pay_enterpriseid");
- Long sa_accountclassid = row.getLong("sa_accountclassid");
- //开票信息
- sqlFactory = new SQLFactory(this, "工具_开票信息");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- Rows financeRows = dbConnect.runSqlQuery(sqlFactory);
- row.put("finance", financeRows.isNotEmpty() ? financeRows.get(0) : new Row());
- //物流
- // sqlFactory = new SQLFactory(this, "工具-查询物流信息");
- // sqlFactory.addParameter("siteid", siteid);
- // sqlFactory.addParameter("sa_orderid", sa_orderid);
- // Rows logiscompRows = dbConnect.runSqlQuery(sqlFactory);
- // row.put("logiscomp", logiscompRows.isNotEmpty() ? logiscompRows.get(0) : new Row());
- //营销账户类型
- sqlFactory = new SQLFactory(this, "工具-查询营销账号");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
- sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- String sql = sqlFactory.getSQL();
- Rows accountclassRows = dbConnect.runSqlQuery(sql);
- if (accountclassRows.isNotEmpty()) {
- accountclassRows.get(0).put("amount", row.getBigDecimal("amount"));
- accountclassRows.get(0).put("rebate_used", row.getBigDecimal("rebate_used"));
- accountclassRows.get(0).put("rebate_userate", row.getBigDecimal("rebate_userate"));
- accountclassRows.get(0).put("rebate_amount", row.getBigDecimal("amount").multiply(row.getBigDecimal("rebate_userate")));
- }
- row.put("accountclass", accountclassRows.isNotEmpty() ? accountclassRows.get(0) : new Row());
- //收货信息
- row.put("contacts", beans.order.Order.getContactsRow(this, row.getLong("rec_contactsid")));
- Rows deliveryRows = dbConnect.runSqlQuery("SELECT count(0) count from plm_item WHERE itemid in (SELECT itemid from sa_orderitems WHERE sa_orderid = " + sa_orderid + " and siteid = '" + siteid + "') and delivery >0 and siteid = '" + siteid + "'");
- if (deliveryRows.get(0).getLong("count") > 0) {
- row.put("isdelivery", 1);
- } else {
- row.put("isdelivery", 0);
- }
- Rows contractrow = dbConnect.runSqlQuery("SELECT * from sa_contract WHERE sa_contractid in (SELECT sa_contractid FROM sa_order WHERE sa_orderid=" + sa_orderid + ")");
- if (contractrow.isNotEmpty()) {
- row.put("contract", contractrow.get(0));
- } else {
- row.put("contract", new Row());
- }
- row.put("rebatebalance", Accountbalance.getRebateBalance(this, pay_enterpriseid));
- return getSucReturnObject().setData(row).toString();
- }
- @API(title = "删除", apiversion = R.ID20230116100002.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String delete() throws YosException {
- JSONArray sa_orderids = content.getJSONArray("sa_orderids");
- if (sa_orderids.size() <= 0) {
- return getErrReturnObject().setErrMsg("请选择要执行删除操作的数据。").toString();
- }
- String sql = "SELECT 1 from sa_order WHERE sa_orderid in " + sa_orderids + " and `status` !='新建' and siteid = '" + siteid + "'";
- sql = sql.replace("[", "(").replace("]", ")");
- if (dbConnect.runSqlQuery(sql).isNotEmpty()) {
- return getErrReturnObject().setErrMsg("存在非新建状态数据,无法执行删除操作。").toString();
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "删除");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_in("sa_orderid", sa_orderids.toArray());
- sqlList.add(sqlFactory.getSQL());
- //订单删除原因
- DataExtend.createDeleteReasonSql(this, "sa_order", sa_orderids.toJavaList(Long.class), content.getStringValue("deletereason"));
- //操作记录
- for (Object obj : sa_orderids) {
- Long sa_orderid = Long.valueOf(obj.toString());
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "删除", "工具借用单删除").getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "交期回复", apiversion = R.ID20230114152602.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String delivery() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- // if (!rows.get(0).getString("status").equals("新建")) {
- // return getErrReturnObject().setErrMsg("非新建状态无法交期回复").toString();
- // }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "交期回复");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期回复", "工具借用单:交期回复" + sa_orderid).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "确认交期,操作交期待确认的", apiversion = R.ID20230129154102.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String confirmDeliveryDate() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("订单不存在").toString();
- }
- //交期待确认
- String status = rows.get(0).getString("status");
- if (!status.equals("交期待确认")) {
- return getErrReturnObject().setErrMsg("只能操作交期待确认的订单").toString();
- }
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "确认交期");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期确认", "工具借用单交期确认").getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "撤回交期回复", apiversion = R.ID20230114152702.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String unDelivery() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- ArrayList<String> sqlList = new ArrayList<>();
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("交期回复")) {
- return getErrReturnObject().setErrMsg("非交期回复状态无法撤回").toString();
- }
- SQLFactory sqlFactory = new SQLFactory(this, "撤回交期回复");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "撤回交期回复", "工具借用单:撤回交期回复" + sa_orderid).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "提交", apiversion = R.ID20230114160002.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String submit() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- ArrayList<String> sqlList = new ArrayList<>();
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- Row row = rows.get(0);
- BigDecimal amount = getAmount(sa_orderid);
- Rows freefreightamountRows = dbConnect.runSqlQuery("SELECT ifnull(freefreightamount,0) freefreightamount from sys_enterprise WHERE sys_enterpriseid= 1 and siteid ='yostest2'");
- BigDecimal freefreightamount = freefreightamountRows.get(0).getBigDecimal("freefreightamount");
- String freightstatus = row.getString("freightstatus");
- if (freightstatus.isEmpty()) {
- if (freefreightamount.compareTo(BigDecimal.ZERO) == -1) {
- freightstatus = "到付";
- }
- if (freefreightamount.compareTo(BigDecimal.ZERO) == 0) {
- freightstatus = "预付";
- }
- if (freefreightamount.compareTo(BigDecimal.ZERO) == 1) {
- if (amount.compareTo(freefreightamount) == 1) {
- freightstatus = "预付";
- } else {
- freightstatus = "到付";
- }
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "提交");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("freightstatus", freightstatus);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "提交", "工具借用单:提交" + sa_orderid).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "审核", apiversion = R.ID20230114161402.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String check() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- String reviewtype = content.getString("reviewtype");
- Rows rows = getOrderRows(this, sa_orderid);
- ArrayList<String> sqlList = new ArrayList<>();
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("提交") && !rows.get(0).getString("status").equals("交期确认")) {
- return getErrReturnObject().setErrMsg("非提交,交期确认状态无法审核").toString();
- }
- Row row = rows.get(0);
- Long sa_accountclassid = row.getLong("sa_accountclassid");
- if (sa_accountclassid <= 0) {
- return getErrReturnObject().setErrMsg("请选择支付账号").toString();
- }
- //验证结算企业
- Long pay_enterpriseid = row.getLong("pay_enterpriseid");
- if (pay_enterpriseid <= 0) {
- return getErrReturnObject().setErrMsg("请选择结算企业").toString();
- }
- String sonum = row.getString("sonum");
- SQLFactory sqlFactory = new SQLFactory(this, "审核");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("reviewtype", reviewtype);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- BigDecimal amount = getAmount(sa_orderid);
- CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "押金收入凭证", "由" + sonum + "工具借用单审核时自动产生");
- JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true, false);
- sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
- Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "审核", "工具借用单:审核" + sa_orderid).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- Accountbalance.remindSend(this, pay_enterpriseid, sa_cashbillid);
- if (Parameter.get("system.erp_dockswitch").equalsIgnoreCase("true")) {
- UploadDataToERP uploadDataToERP = new UploadDataToERP(this, sa_orderid, "");
- boolean issuccess = uploadDataToERP.upload();
- if (!issuccess) {
- unCheck();
- return getErrReturnObject().setErrMsg("上传ERP失败,当前单据将自动反审核,请检查!").toString();
- } else {
- Long sys_enterpriseid = row.getLong("sys_enterpriseid");
- sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
- sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
- }
- } else {
- Long sys_enterpriseid = row.getLong("sys_enterpriseid");
- sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
- sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
- }
- return getSucReturnObject().toString();
- }
- public void sendMsg(String content, Long sa_orderid, Long sys_enterpriseid) throws YosException {
- ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid).toArrayList("userid", new ArrayList<>());
- Remind remind = new Remind(this);
- remind.setTitle("工具借用单");
- remind.setContent(content);
- remind.setType("应用");
- remind.setObjectid(sa_orderid);
- remind.setObjectname("sa_order");
- remind.setTouserid(userList);
- remind.createSys_message();
- }
- @API(title = "反审核", apiversion = R.ID20230114161502.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String unCheck() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- ArrayList<String> sqlList = new ArrayList<>();
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("审核")) {
- return getErrReturnObject().setErrMsg("非审核状态无法反审核").toString();
- }
- Row row = rows.get(0);
- Long sa_accountclassid = row.getLong("sa_accountclassid");
- if (sa_accountclassid <= 0) {
- return getErrReturnObject().setErrMsg("请选择支付账号").toString();
- }
- //验证结算企业
- Long pay_enterpriseid = row.getLong("pay_enterpriseid");
- if (pay_enterpriseid <= 0) {
- return getErrReturnObject().setErrMsg("请选择结算企业").toString();
- }
- String sonum = row.getString("sonum");
- SQLFactory sqlFactory = new SQLFactory(this, "反审核");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- BigDecimal amount = getAmount(sa_orderid);
- CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, "押金收入凭证", "由" + sonum + "工具借用反单审核时自动产生");
- JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true, false);
- sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
- Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反审核", "工具借用单:反审核" + sa_orderid).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- Accountbalance.remindSend(this, pay_enterpriseid, sa_cashbillid);
- return getSucReturnObject().toString();
- }
- @API(title = "退回", apiversion = R.ID20230116085902.v1.class)
- @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
- public String back() throws YosException {
- Long sa_orderid = content.getLong("sa_orderid");
- Rows rows = getOrderRows(this, sa_orderid);
- ArrayList<String> sqlList = new ArrayList<>();
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- SQLFactory sqlFactory = new SQLFactory(this, "退回");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_orderid", sa_orderid);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "退回", "工具借用单:退回" + sa_orderid).getSQL());
- //订单退回原因
- ArrayList<Long> sa_orderids = new ArrayList<>();
- sa_orderids.add(sa_orderid);
- DataExtend.createBackReasonSql(this, "sa_order", sa_orderids, content.getStringValue("backreason"));
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- public CashbillEntity getCashbillEntity(BigDecimal amount, Long ownerid, String source, String remarks) throws YosException {
- CashbillEntity entity = new CashbillEntity();
- entity.setAmount(amount);
- entity.setOwnerid(ownerid);
- entity.setOwnertable("sa_order");
- entity.setSource(source);
- entity.setRemarks(remarks);
- return entity;
- }
- /**
- * 获取价格(折扣)
- *
- * @param sa_orderid
- * @return
- * @throws YosException
- */
- public BigDecimal getAmount(Long sa_orderid) throws YosException {
- Rows rows = dbConnect.runSqlQuery("SELECT ifnull(sum(amount),0) amount from sa_orderitems WHERE sa_orderid=" + sa_orderid + " AND siteid = '" + siteid + "'");
- return rows.get(0).getBigDecimal("amount");
- }
- }
|