| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- package openapi.restcontroller.wechatapp.tinvoiceapply;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import openapi.base.Controller;
- import openapi.base.SQLFactory;
- import openapi.base.data.Row;
- import openapi.base.data.Rows;
- import openapi.base.data.db.DBConnect;
- import p2.pao.PaoRemote;
- import p2.pao.PaoSetRemote;
- import tinvoiceapply.tinvoiceapply;
- import org.apache.commons.lang.StringUtils;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- public class Tinvoiceapply_saler extends Controller {
- public Tinvoiceapply_saler(JSONObject content) {
- super(content);
- }
- public String queryInvoiceApplyList() {
- String[] sortmsg = {"case when t1.fstatus='新建'then 1 when t1.fstatus='提交'then 2 when t1.fstatus='审核'then 3 else 4 end,t1.createdate desc "};
- String sort = "case when t1.fstatus='新建'then 1 when t1.fstatus='提交'then 2 when t1.fstatus='审核'then 3 else 4 end,t1.createdate desc ";
- if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
- sort = content.getString("sort");
- }
- String where = " 1=1 ";
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + " and (t3.fagentname like'%" + whereObject.getString("condition") + "%' or t3.fagentshortname like'%" + whereObject.getString("condition") + "%' or t1.finvoicename like'%" + whereObject.getString("condition") + "%' " +
- "or exists(select tinvoicebillid from tinvoicebill where siteid=t1.siteid and tinvoiceapplyid=t1.tinvoiceapplyid and (invoicecode like'%" + whereObject.getString("condition") + "%' or invoiceno like'%" + whereObject.getString("condition") +
- "%')))";
- }
- if (whereObject.containsKey("fbegdate") && !"".equals(whereObject.getString("fbegdate"))) {
- where = where + " and t1.checkdate >='" + whereObject.getString("fbegdate") + "'";
- }
- if (whereObject.containsKey("fenddate") && !"".equals(whereObject.getString("fenddate"))) {
- where = where + " and t1.checkdate <='" + whereObject.getString("fenddate") + "'";
- }
- if (whereObject.containsKey("fstatus") && !"".equals(whereObject.getString("fstatus"))) {
- where = where + " and t1.fstatus ='" + whereObject.getString("fstatus") + "'";
- }
- }
- DBConnect connect = new DBConnect();
- SQLFactory a = new SQLFactory(this, "下级业务员查询");
- a.addParameter("hrid", hrid);
- a.addParameter("siteid", siteid);
- Rows hridRows = connect.runSqlQuery(a.getSQL());
- String hridinwhere = hridRows.getInWhere("hrid");
- SQLFactory factory = new SQLFactory(this, "经销商发票列表查询_业务员", pageSize, pageNumber, sort);
- factory.addParameter("siteid", siteid);
- factory.addParameter_SQL("hrid", hridinwhere);
- factory.addParameter_SQL("where", where);
- Rows rows = connect.runSqlQuery(factory.getSQL());
- return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
- }
- /**
- * 发票详情查询
- *
- * @return
- */
- public String queryInvoiceApplyMain() {
- long tinvoiceapplyid = content.getLong("tinvoiceapplyid");
- SQLFactory factory = new SQLFactory(this, "经销商发票详情查询");
- factory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
- factory.addParameter("siteid", siteid);
- DBConnect connect = new DBConnect();
- Rows rows = connect.runSqlQuery(factory.getSQL());
- for (Row row : rows) {
- SQLFactory orderFactory = new SQLFactory(this, "经销商发票详情查询_订单行");
- orderFactory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
- orderFactory.addParameter("siteid", siteid);
- row.put("orderdetails", connect.runSqlQuery(orderFactory.getSQL()));
- SQLFactory invoiceFactory = new SQLFactory(this, "经销商发票详情查询_发票");
- invoiceFactory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
- invoiceFactory.addParameter("siteid", siteid);
- row.put("invoices", connect.runSqlQuery(invoiceFactory.getSQL()));
- }
- return getReturnObject_suc(rows, false).toString();
- }
- /**
- * 发票新增修改
- *
- * @return
- */
- public String insertorModify() {
- long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
- String fagentnum = content.getString("fagentnum");//新建为0
- DBConnect connect = new DBConnect();
- Rows rows = connect.runSqlQuery("select * from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
- if (!rows.isEmpty() && !"新建".equals(rows.get(0).getString("fstatus"))) {
- return getReturnObject_err("当前状态不可修改").toString();
- }
- String finvoicename = content.getString("finvoicename");//开票单位
- String finvoiceaddress = content.getString("finvoiceaddress");//开票单位地址
- String finvoicetaxnumber = content.getString("finvoicetaxnumber");//开票单位税号
- String fnotes = nullToStr(content.getString("fnotes"));//备注
- JSONArray orderdetailsArray = content.getJSONArray("orderdetails");
- PaoSetRemote tinvoiceapplySet = null;
- try {
- tinvoiceapplySet = getP2ServerPaoSet("tinvoiceapply", hrid, "siteid='" + siteid + "' and tinvoiceapplyid='" + tinvoiceapplyid + "'");
- tinvoiceapplySet.setApp("INVOICEAPP");
- PaoRemote tinvoiceapply = null;
- if (tinvoiceapplyid <= 0 || tinvoiceapplySet.isEmpty()) {
- tinvoiceapply = tinvoiceapplySet.addAtEnd();
- tinvoiceapply.setValue("fagentnum", fagentnum, 11L);
- content.put("tinvoiceapplyid", tinvoiceapply.getUniqueIDValue());
- } else {
- tinvoiceapply = tinvoiceapplySet.getPao(0);
- }
- tinvoiceapply.setValue("finvoicename", finvoicename, 11L);
- tinvoiceapply.setValue("finvoiceaddress", finvoiceaddress, 11L);
- tinvoiceapply.setValue("finvoicetaxnumber", finvoicetaxnumber, 2L);
- tinvoiceapply.setValue("fnotes", fnotes, 11L);
- PaoSetRemote tinvoiceapplyorderset = tinvoiceapply.getPaoSet("tinvoiceapplyorder");
- HashMap<String, PaoRemote> tinvoiceapplyordermap = getPaoMap(tinvoiceapplyorderset, "saorderdetailid");
- ArrayList<String> donotdeleteid = new ArrayList<>();
- for (Object o : orderdetailsArray) {
- JSONObject orderdetailObject = (JSONObject) o;
- String saorderid = orderdetailObject.getString("saorderid");
- String saorderdetailid = orderdetailObject.getString("saorderdetailid");
- double finvoiceqty = orderdetailObject.getDouble("finvoiceqty");//开票数量
- double finvoiceamount = orderdetailObject.getDouble("finvoiceamount");//开票金额
- PaoRemote detailPao = null;
- if (tinvoiceapplyordermap.containsKey(saorderdetailid)) {
- detailPao = tinvoiceapplyordermap.get(saorderdetailid);
- } else {
- /**
- * 如果id不为0表示该订单行本身不存在,需要增加行
- */
- detailPao = tinvoiceapplyorderset.addAtEnd();
- detailPao.setValue("siteid", siteid, 11L);
- detailPao.setValue("tinvoiceapplyid", tinvoiceapply.getUniqueIDValue(), 11L);
- detailPao.setValue("saorderid", saorderid, 2L);
- detailPao.setValue("saorderdetailid", saorderdetailid, 2L);
- }
- if (detailPao != null) {
- detailPao.setValue("finvoiceqty", finvoiceqty, 2L);
- detailPao.setValue("finvoiceamount", finvoiceamount, 2L);
- }
- donotdeleteid.add(saorderdetailid);
- }
- /**
- * 删除多余的行
- */
- for (String id : tinvoiceapplyordermap.keySet()) {
- if (!donotdeleteid.contains(id)) {
- if (!tinvoiceapplyordermap.get(id).isModified()) {
- tinvoiceapplyordermap.get(id).delete();
- }
- }
- }
- tinvoiceapplySet.save();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- tinvoiceapplySet.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return queryInvoiceApplyMain();
- }
- public String invoiceApplysubmit() {
- long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
- PaoSetRemote tinvoiceapplySet = null;
- try {
- tinvoiceapplySet = getP2ServerPaoSet("tinvoiceapply", hrid, "siteid='" + siteid + "' and tinvoiceapplyid='" + tinvoiceapplyid + "'");
- tinvoiceapplySet.setApp("INVOICEAPP");
- tinvoiceapply tinvoiceapply = (tinvoiceapply) tinvoiceapplySet.getPao(0);
- tinvoiceapply.submitvalidate(true);
- tinvoiceapply.submit(true);
- tinvoiceapplySet.save();
- } catch (Exception e) {
- return getReturnObject_err(e.getMessage()).toString();
- } finally {
- try {
- tinvoiceapplySet.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return getReturnObject_suc().toString();
- }
- public String invoiceApplydelete() {
- long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
- DBConnect connect = new DBConnect();
- Rows rows = connect.runSqlQuery("select * from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
- if (rows.isEmpty() || !"新建".equals(rows.get(0).getString("fstatus"))) {
- return getReturnObject_err("非新建状态下不可删除").toString();
- }
- String status = connect.runSqlUpdate("delete from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
- if ("true".equals(status)) {
- return getReturnObject_suc().toString();
- } else {
- return getReturnObject_err("删除失败!").toString();
- }
- }
- /**
- * 开票经销商选择
- *
- * @return
- */
- public String queryInvoiceAgent() {
- DBConnect connect = new DBConnect();
- SQLFactory a = new SQLFactory(this, "下级业务员查询");
- a.addParameter("hrid", hrid);
- a.addParameter("siteid", siteid);
- Rows hridRows = connect.runSqlQuery(a.getSQL());
- String hridinwhere = hridRows.getInWhere("hrid");
- SQLFactory factory = new SQLFactory(this, "开票经销商选择查询_业务员");
- factory.addParameter("siteid", siteid);
- factory.addParameter_SQL("hrid", hridinwhere);
- Rows rows = connect.runSqlQuery(factory.getSQL());
- return getReturnObject_suc(rows, true).toString();
- }
- /**
- * 开票单位选择
- *
- * @return
- */
- public String queryInvoiceName() {
- String fagentnum = content.getString("fagentnum");
- DBConnect connect = new DBConnect();
- Rows rows = connect.runSqlQuery("select * from tinvoiceapply_taxview where siteid='" + siteid + "' and fpayagentnum='" + fagentnum + "'");
- return getReturnObject_suc(rows, false).toString();
- }
- /**
- * 开票订单行选择
- *
- * @return
- */
- public String querySaorderDetail() {
- long tinvoiceapplyid = content.getLong("tinvoiceapplyid");
- String fbegdate = content.getString("fbegdate");
- String fenddate = content.getString("fenddate");
- String fprojectname = content.getString("fprojectname");
- String fagentnum = content.getString("fagentnum");
- String fsonum = content.getString("fsonum");
- String condition = content.getString("condition");
- String where = "1=1";
- if (!"".equals(fbegdate)) {
- where = where + " and sdate.closedate1>='" + fbegdate + "'";
- }
- if (!"".equals(fenddate)) {
- where = where + " and sdate.closedate1<='" + fenddate + "'";
- }
- if (!"".equals(fprojectname)) {
- where = where + " and tp.fprojectname like'%" + fprojectname + "%'";
- }
- if (!"".equals(fsonum)) {
- where = where + " and t1.fsonum like'%" + fsonum + "%'";
- }
- if (!"".equals(condition)) {
- where = where + " and (tp.fprojectname like'%" + condition + "%' or t1.fsonum like'%" + condition + "%')";
- }
- DBConnect connect = new DBConnect();
- Rows tagentsRows = connect.runSqlQuery("select *from tagents where siteid='" + siteid + "' and fagentnum='" + fagentnum + "'");
- boolean fcheckordermakeinv = tagentsRows.get(0).getBoolean("fcheckordermakeinv");
- SQLFactory factory = new SQLFactory(this, fcheckordermakeinv ? "开票订单行选择查询_审核订单" : "开票订单行选择查询");
- factory.addParameter("siteid", siteid);
- factory.addParameter("fagentnum", fagentnum);
- factory.addParameter_SQL("where", where);
- factory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
- Rows rows = connect.runSqlQuery(factory.getSQL());
- return getReturnObject_suc(rows, false).toString();
- }
- }
|