From 45c017d7d01786f532a545e2140201545cd8cadf Mon Sep 17 00:00:00 2001 From: hanxuntao Date: Wed, 27 Nov 2024 11:58:50 +0800 Subject: [PATCH] 11 --- .../ChRecvapplicationBLEdit.js | 14 +- .../MsRptSaleBalProfitShareDAL.cs | 2 +- .../Viewsjs/MsOpOther/MsOpOtherEdit.js | 2 +- .../Viewsjs/MsRptNoTotal/MsRptNoTotalIndex.js | 4 + .../Controllers/PcHeadEdit_WFSDController.cs | 65 +- .../DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs | 88 +++ .../Viewsjs/MsWlBs/MsPcEdit_ZXIndex.js | 9 - .../TruckMng/Viewsjs/MsWlBs/MsPcHYRDEdit.js | 2 +- .../TruckMng/Viewsjs/MsWlBs/MsPcZXEdit.js | 60 +- JobAutoCreateFee/JobAutoCreateFee.csproj | 1 + JobAutoCreateFee/JobD6CoscoFee.cs | 675 ++++++++++++++++++ JobAutoCreateFee/Model/CreateFee.cs | 2 +- 12 files changed, 815 insertions(+), 109 deletions(-) create mode 100644 JobAutoCreateFee/JobD6CoscoFee.cs diff --git a/DSWeb/Areas/Account/Viewsjs/Chfee_recvapplication/ChRecvapplicationBLEdit.js b/DSWeb/Areas/Account/Viewsjs/Chfee_recvapplication/ChRecvapplicationBLEdit.js index ba80bfc9..34f337ff 100644 --- a/DSWeb/Areas/Account/Viewsjs/Chfee_recvapplication/ChRecvapplicationBLEdit.js +++ b/DSWeb/Areas/Account/Viewsjs/Chfee_recvapplication/ChRecvapplicationBLEdit.js @@ -618,7 +618,17 @@ Ext.extend(Shipping.MsChRecvapplicationBLEdit, Ext.Panel, { header: '开船日期', renderer: Ext.util.Format.dateRenderer('Y-m-d'), width: 100 - }, { + }, { + sortable: true, + dataIndex: 'VESSEL', + header: '船名', + width: 100 + }, { + sortable: true, + dataIndex: 'VOYNO', + header: '航次', + width: 100 + }, { sortable: true, dataIndex: 'BSSOURCE', header: '业务来源', @@ -3787,7 +3797,7 @@ Ext.extend(Shipping.MsChRecvapplicationBLEdit, Ext.Panel, { } if ((bsStatus != 1) && (bsStatus != 6)) { - this.setSaveBtnStatus(false); + _this.setSaveBtnStatus(false); } else { _this.setSaveBtnStatus(canedit); } diff --git a/DSWeb/Areas/MvcShipping/DAL/MsRptSaleBalProfitShare/MsRptSaleBalProfitShareDAL.cs b/DSWeb/Areas/MvcShipping/DAL/MsRptSaleBalProfitShare/MsRptSaleBalProfitShareDAL.cs index 7d2a9078..ac45a04c 100644 --- a/DSWeb/Areas/MvcShipping/DAL/MsRptSaleBalProfitShare/MsRptSaleBalProfitShareDAL.cs +++ b/DSWeb/Areas/MvcShipping/DAL/MsRptSaleBalProfitShare/MsRptSaleBalProfitShareDAL.cs @@ -1215,7 +1215,7 @@ namespace DSWeb.MvcShipping.DAL.MsRptSaleBalProfitShareDAL data.JXXS = Convert.ToDecimal(reader["JXXS"]); if (data.OPTYPE == "普通货") { - data.TiChengJiShu = data.TTLPROFIT - data.OPTC - data.SWTC - data.KOUXI; + data.TiChengJiShu = data.TTLPROFIT - data.OPTC - data.KOUXI; } else { data.TiChengJiShu = data.TTLPROFIT; diff --git a/DSWeb/Areas/MvcShipping/Viewsjs/MsOpOther/MsOpOtherEdit.js b/DSWeb/Areas/MvcShipping/Viewsjs/MsOpOther/MsOpOtherEdit.js index 22d59bf6..127b9627 100644 --- a/DSWeb/Areas/MvcShipping/Viewsjs/MsOpOther/MsOpOtherEdit.js +++ b/DSWeb/Areas/MvcShipping/Viewsjs/MsOpOther/MsOpOtherEdit.js @@ -379,7 +379,7 @@ Ext.extend(Shipping.MsOpOtherEdit, Ext.Panel, { this.comboxBSSOURCEDETAIL = Ext.create('DsExt.ux.RefTableCombox', { fieldLabel: '来源明细', store: this.storeSourceDetail, - //forceSelection: true, +// forceSelection: true, name: 'BSSOURCEDETAIL', valueField: 'SourceDetail', displayField: 'SourceDetail' diff --git a/DSWeb/Areas/MvcShipping/Viewsjs/MsRptNoTotal/MsRptNoTotalIndex.js b/DSWeb/Areas/MvcShipping/Viewsjs/MsRptNoTotal/MsRptNoTotalIndex.js index 9b964caf..650bde6f 100644 --- a/DSWeb/Areas/MvcShipping/Viewsjs/MsRptNoTotal/MsRptNoTotalIndex.js +++ b/DSWeb/Areas/MvcShipping/Viewsjs/MsRptNoTotal/MsRptNoTotalIndex.js @@ -7104,6 +7104,8 @@ Ext.extend(Shipping.MsRptNoTotalIndex, Ext.Panel, { sql = ' EXISTS (select 1 from v_op_gain_sum_ttl WHERE v_op_gain_sum_ttl.BSNO=B.PARENTID AND v_op_gain_sum_ttl.STLTTLCR=v_op_gain_sum_ttl.TTLCR) ' } else if (FEERANGE == '未开票未作收费申请未结算') { sql = ' (isnull(f.INVOICE,0)=0 and isnull(f.SETTLEMENT,0)=0 and isnull(f.ORDERAMOUNT,0)=0) ' + } if (FEERANGE == '已收费申请未结算') { + sql = ' (f.FEETYPE=1 AND isnull(f.ORDERAMOUNT,0)<>0 AND isnull(f.SETTLEMENT,0)=0) ' } } else { @@ -7144,6 +7146,8 @@ Ext.extend(Shipping.MsRptNoTotalIndex, Ext.Panel, { sql = sql + ' and EXISTS (select 1 from v_op_gain_sum_ttl WHERE v_op_gain_sum_ttl.BSNO=B.PARENTID AND v_op_gain_sum_ttl.STLTTLCR=v_op_gain_sum_ttl.TTLCR) ' } else if (FEERANGE == '未开票未作收费申请未结算') { sql = sql +' and (isnull(f.INVOICE,0)=0 and isnull(f.SETTLEMENT,0)=0 and isnull(f.ORDERAMOUNT,0)=0) ' + } else if (FEERANGE == '已收费申请未结算') { + sql = sql + ' (f.FEETYPE=1 AND isnull(f.ORDERAMOUNT,0)<>0 AND isnull(f.SETTLEMENT,0)=0) ' } } } diff --git a/DSWeb/Areas/TruckMng/Controllers/PcHeadEdit_WFSDController.cs b/DSWeb/Areas/TruckMng/Controllers/PcHeadEdit_WFSDController.cs index ccfd41a5..7ffc98f7 100644 --- a/DSWeb/Areas/TruckMng/Controllers/PcHeadEdit_WFSDController.cs +++ b/DSWeb/Areas/TruckMng/Controllers/PcHeadEdit_WFSDController.cs @@ -668,7 +668,7 @@ namespace DSWeb.Areas.TruckMng.Controllers if (result.Success) { result.Message = "生成成功!"; - + MsRptPcHeadEditDAL.CreateHYRDPc(BSNO, CookieConfig.GetCookie_UserId(Request), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request), CookieConfig.GetCookie_OrgCode(Request)); } else { @@ -844,70 +844,7 @@ namespace DSWeb.Areas.TruckMng.Controllers } - public ContentResult CreateHYRDPc(string bsno) - { - - var headData = MsRptPcHeadEditDAL.GetHYRDData("GID='" + bsno + "'"); - if (!string.IsNullOrEmpty(headData.Property)) { - var jsonRespose2 = new JsonResponse { Success = false, Message = "已生成派车,不允许重复生成!" }; - return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; - - } - - var refbillno = headData.BillNo; - - var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", Convert.ToString(Session["COMPANYID"])); - billnoset.BILLTYPE = "0111"; - billnoset.RULEDATETYPE = "业务日期"; - var bsdate = headData.ExpDate; - if (bsdate == "" || bsdate == null) - bsdate = DateTime.Now.ToString("yyyy-MM-dd"); - - headData.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, bsdate, DateTime.Now.ToString("yyyy-MM")); //获取合同号 - - headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request); - - headData.DbOperationType = DbOperationType.DbotIns; - headData.TRANSSTATUS = "新建"; - headData.BsType = ""; - headData.gId= "PC" + Guid.NewGuid().ToString("N").ToUpper(); - headData.PGid = headData.gId; - headData.RefBillNo = refbillno; - headData.LrDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - - //if (!string.IsNullOrEmpty(headData.LrDate)) - //{ - // headData.LrDate = headData.LrDate.Substring(0, 10); - //} - //else - //{ - // var currentTime = System.DateTime.Now; - // headData.LrDate = currentTime.ToString("d"); - //} - - var BSNO = headData.gId; - - var modb = new ModelObjectDB(); - DBResult result = modb.Save(headData); - if (result.Success) - { - result.Message = "生成成功!"; - - } - else { - result.Message = "生成失败"; - } - - var jsonRespose = new JsonResponse - { - Success = result.Success, - Message = result.Message - }; - return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; - - - } public ContentResult CreateHYRDFen(string bsno, string ctnbody) diff --git a/DSWeb/Areas/TruckMng/DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs b/DSWeb/Areas/TruckMng/DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs index 66506e66..b3e22138 100644 --- a/DSWeb/Areas/TruckMng/DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs +++ b/DSWeb/Areas/TruckMng/DAL/MsRptPcHeadEdit/MsRptPcHeadEditDAL.cs @@ -33,6 +33,7 @@ using DSWeb.Areas.MvcShipping.DAL.BookingConfirm; using DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL; using DSWeb.Areas.MvcShipping.Models.Message.VGM; using com.sun.java.swing.plaf.motif.resources; +using System.Web.Mvc; namespace DSWeb.Areas.TruckMng.DAL.MsRptPcHeadEdit @@ -2440,6 +2441,93 @@ namespace DSWeb.Areas.TruckMng.DAL.MsRptPcHeadEdit return result; } + + public static DBResult CreateHYRDPc(string GID,string userid,string usercode,string username,string companyid,string orgcode) + { + var result = new DBResult(); + var FenList = MsRptPcHeadEditDAL.GetHYRDList("t.PGID='" + GID + "' AND t.GID<>'" + GID + "'", userid, usercode, username, companyid, null); + if (FenList == null || FenList.Count == 0) + { + result.Success = false; + return result; + + } + + foreach (var headData in FenList) + { + // var headData = MsRptPcHeadEditDAL.GetHYRDData("GID='" + bsno + "'"); + if (string.IsNullOrEmpty(headData.Property)) + { + // var jsonRespose2 = new JsonResponse { Success = false, Message = "已生成派车,不允许重复生成!" }; + // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; + + //} + + var refbillno = headData.BillNo; + var refGid = headData.gId; + + var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", companyid); + billnoset.BILLTYPE = "0111"; + billnoset.RULEDATETYPE = "业务日期"; + var bsdate = headData.ExpDate; + if (bsdate == "" || bsdate == null) + bsdate = DateTime.Now.ToString("yyyy-MM-dd"); + + headData.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, bsdate, DateTime.Now.ToString("yyyy-MM")); //获取合同号 + + headData.OrgCode = orgcode; + + headData.DbOperationType = DbOperationType.DbotIns; + headData.TRANSSTATUS = "新建"; + headData.BsType = ""; + headData.gId = "PC" + Guid.NewGuid().ToString("N").ToUpper(); + headData.PGid = headData.gId; + headData.RefBillNo = refbillno; + headData.LrDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + headData.ACCDATE = DateTime.Now.ToString("yyyy-MM"); + headData.LrDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + headData.ChangedReson = headData.FactoryAddrSe; + headData.FactoryAddrSe = ""; + headData.DetiNationSe = ""; + + + //if (!string.IsNullOrEmpty(headData.LrDate)) + //{ + // headData.LrDate = headData.LrDate.Substring(0, 10); + //} + //else + //{ + // var currentTime = System.DateTime.Now; + // headData.LrDate = currentTime.ToString("d"); + //} + + var BSNO = headData.gId; + + var modb = new ModelObjectDB(); + result = modb.Save(headData); + if (result.Success) + { + T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); + var blUpBL = "update tMsWlPcHead set Property='" + BSNO + "' where GID='" + refbillno + "'"; + bool blBL = T_ALL_DA.GetExecuteSqlCommand(blUpBL); + + result.Message = "生成成功!"; + + } + else + { + result.Message = "生成失败"; + + } + } + } + + return result; + + + } + + #region 退舱 public static DBResult CancelShippingOrder(string bsno, string type, string op) { diff --git a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcEdit_ZXIndex.js b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcEdit_ZXIndex.js index e1ed7cc1..18b6d2ba 100644 --- a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcEdit_ZXIndex.js +++ b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcEdit_ZXIndex.js @@ -4047,15 +4047,6 @@ Ext.extend(DsTruck.MsPcEditIndex, Ext.Panel, { var sql1 = "SET LANGUAGE 'us_english' SELECT * FROM op_letter WHERE LE_ID = '" + le_id + "'"; var sql2 = "SET LANGUAGE 'us_english' SELECT * FROM tMsWlPcHead WHERE billNo = '" + billNo + "'"; var sql3 = ""; - if (this.oplb == "海运进口") - sql3 = "SET LANGUAGE 'us_english' SELECT * FROM op_seai WHERE BSNO = '" + bsNo + "'"; - else if (this.oplb == "空运进口") - sql3 = "SET LANGUAGE 'us_english' SELECT * FROM op_airi WHERE BSNO = '" + bsNo + "'"; - else if (this.oplb == "空运出口") - sql3 = "SET LANGUAGE 'us_english' SELECT * FROM op_aire WHERE BSNO = '" + bsNo + "'"; - else - sql3 = "SET LANGUAGE 'us_english' SELECT * FROM op_seae WHERE BSNO = '" + bsNo + "'"; - var sql4 = ""; var sql5 = ""; var sql6 = ""; diff --git a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcHYRDEdit.js b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcHYRDEdit.js index 2534f8cd..2c62ce12 100644 --- a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcHYRDEdit.js +++ b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcHYRDEdit.js @@ -713,7 +713,7 @@ Ext.extend(DsTruck.MsPcHYRDEdit, Ext.Panel, { fieldLabel: '押运员', store: this.storeLinkMan, name: 'LinkMan', - valueField: 'DrvCode', + valueField: 'DrvName', displayField: 'DrvName' , listeners: { diff --git a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcZXEdit.js b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcZXEdit.js index fcef3945..fc608944 100644 --- a/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcZXEdit.js +++ b/DSWeb/Areas/TruckMng/Viewsjs/MsWlBs/MsPcZXEdit.js @@ -3712,36 +3712,36 @@ Ext.extend(DsTruck.MsPcHYRDEdit, Ext.Panel, { //var field = _thisPc.formEdit.getForm().findField('ContainerQty'); //field.setValue(ctnnum); - if ((ctnnum != 1) && (bodydatas.length!=0)) { - var jsonBody = ConvertRecordsToJsonAll(bodydatas); - Ext.Msg.wait('正在保存数据, 请稍侯..'); - Ext.Ajax.request({ - waitMsg: '正在保存数据...', - url: '/TruckMng/PcHeadEdit_WFSD/CreateHYRDFen', - scope: this, - params: { - bsno: BSNO, - ctnbody: jsonBody - }, - callback: function (options, success, response) { - if (success) { - Ext.MessageBox.hide(); - var jsonresult = Ext.JSON.decode(response.responseText); - if (jsonresult.Success) { - Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); - } else { - Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); - } - } else { - Ext.Msg.show({ - title: '请重试', - msg: '服务器响应出错', - icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK - }); - } - } - }); - } + //if ((ctnnum != 1) && (bodydatas.length!=0)) { + // var jsonBody = ConvertRecordsToJsonAll(bodydatas); + // Ext.Msg.wait('正在保存数据, 请稍侯..'); + // Ext.Ajax.request({ + // waitMsg: '正在保存数据...', + // url: '/TruckMng/PcHeadEdit_WFSD/CreateHYRDFen', + // scope: this, + // params: { + // bsno: BSNO, + // ctnbody: jsonBody + // }, + // callback: function (options, success, response) { + // if (success) { + // Ext.MessageBox.hide(); + // var jsonresult = Ext.JSON.decode(response.responseText); + // if (jsonresult.Success) { + // Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, buttons: Ext.Msg.OK }); + // } else { + // Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); + // } + // } else { + // Ext.Msg.show({ + // title: '请重试', + // msg: '服务器响应出错', + // icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK + // }); + // } + // } + // }); + //} // Ext.Msg.hide(); diff --git a/JobAutoCreateFee/JobAutoCreateFee.csproj b/JobAutoCreateFee/JobAutoCreateFee.csproj index 2a40e466..9016f97b 100644 --- a/JobAutoCreateFee/JobAutoCreateFee.csproj +++ b/JobAutoCreateFee/JobAutoCreateFee.csproj @@ -69,6 +69,7 @@ + diff --git a/JobAutoCreateFee/JobD6CoscoFee.cs b/JobAutoCreateFee/JobD6CoscoFee.cs new file mode 100644 index 00000000..481abe36 --- /dev/null +++ b/JobAutoCreateFee/JobD6CoscoFee.cs @@ -0,0 +1,675 @@ +using log4net; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Quartz; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Text; +using DSWeb.Common; +using JobAutoCreateFee.Model; +using System.Security.Policy; +using System.Xml.Linq; +using System.Diagnostics.Eventing.Reader; + +namespace JobCreateFee +{ + public class JobD6CoscoFee : IJob + { + private ILog log = LogManager.GetLogger(typeof(JobD6CoscoFee)); + + public void Execute(IJobExecutionContext context) + { + log.Debug($"Execute开始"); + try + { + string connStr = context.JobDetail.JobDataMap.GetString("ConnectString"); + string reqUrl = context.JobDetail.JobDataMap.GetString("CoscoReqFeeUrl"); + + string UserKey = context.JobDetail.JobDataMap.GetString("UserKey"); + string UserSecret = context.JobDetail.JobDataMap.GetString("UserSecret"); + string WebAccount = context.JobDetail.JobDataMap.GetString("WebAccount"); + string WebPassword = context.JobDetail.JobDataMap.GetString("WebPassword"); + + string CompanyCode = context.JobDetail.JobDataMap.GetString("CompanyCode"); + + string BsSql = context.JobDetail.JobDataMap.GetString("BsSql"); + string FEECUSTNAME = context.JobDetail.JobDataMap.GetString("FEECUSTNAME"); + string ENTEROPERATOR = context.JobDetail.JobDataMap.GetString("ENTEROPERATOR"); + string FEESTATUS = context.JobDetail.JobDataMap.GetString("FEESTATUS"); + + + int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout")); + long ts = DataTableToJsonHelper.ConvertDateTimeToInt(DateTime.Now); + + + log.Debug($"获取数据"); + + + using (SqlConnection dbcon = new SqlConnection(connStr)) + { + var strSql = new StringBuilder(); + strSql.Append(BsSql); + + SqlCommand cmd = new SqlCommand(); + cmd.CommandText = strSql.ToString(); + cmd.CommandTimeout = 120000; //要加这一句 + cmd.Connection = dbcon; + SqlDataAdapter adapter = new SqlDataAdapter(cmd); + DataTable table = new DataTable(); + adapter.Fill(table); + var feebacklist = new List(); + if (table.Rows.Count > 0) + { + log.Debug($"数据{table.Rows.Count}条"); + //var FeeTemplateDetailList = GetFeeTemplate(FEECUSTNAME, dbcon); + + + foreach (DataRow row in table.Rows) + { + var MBLNO = row["MBLNO"].ToString(); + var BSNO = row["BSNO"].ToString(); + var ETD = row["ETD"].ToString(); + if (!string.IsNullOrEmpty(MBLNO) && MBLNO.Length > 4) { + MBLNO = MBLNO.Substring(4); + } + + var JsonCoscoFeeSend = new JsonCoscoFeeSend(); + JsonCoscoFeeSend.userKey = UserKey; + JsonCoscoFeeSend.userSecret = UserSecret; + JsonCoscoFeeSend.companyCode = CompanyCode; + JsonCoscoFeeSend.webAccount = WebAccount; + JsonCoscoFeeSend.webPassword = WebPassword; + JsonCoscoFeeSend.bno = MBLNO; + JsonCoscoFeeSend.summaryFlag = false; + var sendstr = JsonConvert.SerializeObject(JsonCoscoFeeSend); + log.Debug($"发送包:{sendstr}"); + //发送请求数据 + string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000); + log.Debug($"数据返回:{rtn}"); + var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { code = "", msg = "" }); + if (objRtn.code=="200") + { + var objreturn= JsonConvert.DeserializeObject(rtn); + + var returnlist = objreturn.data; + if (returnlist != null && returnlist.Count != 0) + { + var feelist = new List(); + var unitlist = GetFeeUnit(BSNO, dbcon); + var isctnnum = 1; + var findunitlist = unitlist.FindAll(x=>x.ISCTN); + if (findunitlist != null && findunitlist.Count >= 2) { + isctnnum = 2; + } + + + string sql = ""; + try + { + + + foreach (var returndata in returnlist) + { + + + if (!GETINVNOISUSE(BSNO, returndata.itemUuid, dbcon)) + { + + + if (Convert.ToDecimal(returndata.totalAmount.Trim())!=0) + { + var price = returndata.totalAmount; + if (price == "") price = "0"; + var curr = returndata.currencyUnit; + if (curr == "CNY") curr = "RMB"; + var FEENAME = GETFEENAME(returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", ""), dbcon, curr); + decimal exrate = 1; + var AMOUNT = returndata.totalAmount; + var COUNT = "1"; + if (curr != "RMB") + { + exrate = GetUsdExrate(dbcon, curr, ETD); + } + price = price.Replace(",", ""); + if (string.IsNullOrEmpty(FEENAME)) + { + var feeback = new feeback(); + feeback.ReceiveId = returndata.bno; + feeback.Success = false; + feeback.Reason = $"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 未匹配"; + feebacklist.Add(feeback); + log.Debug($"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 未匹配"); + } + else + { + bool isadd = false; + + var newfee = new MsChFee(); + newfee.FA_ID = returndata.itemUuid; + newfee.Currency = curr; + newfee.CustomerName = FEECUSTNAME; + newfee.BSNO = BSNO; + newfee.ExChangerate = exrate; + newfee.FeeName = FEENAME; + newfee.Quantity = 1; + newfee.Unit = "票"; + newfee.UnitPrice =Convert.ToDecimal(returndata.totalAmount); + newfee.Amount= Convert.ToDecimal(returndata.totalAmount); + newfee.FeeEName = returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", ""); + feelist.Add(newfee); + isadd = true; + + + + if (!isadd) { + var feeback = new feeback(); + feeback.ReceiveId = returndata.bno; + feeback.Success = false; + feeback.Reason = $"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 金额:{returndata.totalAmount}未匹配添加"; + feebacklist.Add(feeback); + log.Debug($"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 金额:{returndata.totalAmount} 未匹配添加"); + + } + + } + + + } + + + + + + } + + + + + } + + + + + + + } + catch (Exception e) + { + log.Debug($"记录插入错误:{e.Message}" + sql); + + } + try + { + + if (feelist != null && feelist.Count != 0) + { + dbcon.Open(); + foreach (var fee in feelist) + { + sql = "INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME,CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,"; + sql = sql + "EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,CARGO_GID,"; + sql = sql + "TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC,FEEDESCRIPTION,DELIVERYNO,SETTLEMENT,INVOICE,ORDERAMOUNT,ORDERINVOICE,ORDERSETTLEMENT,ORDERINVSETTLEMENT)"; + sql = sql + "VALUES "; + sql = sql + "('" + Guid.NewGuid().ToString() + "','" + fee.BSNO + "',2,'" + fee.FeeName + "','船公司','" + fee.CustomerName + "','" + fee.Unit + "'"; + sql = sql + "," + fee.UnitPrice + "," + fee.Quantity + "," + fee.Amount + ",'" + fee.Currency + "'," + fee.ExChangerate + ",'','',0"; + sql = sql + ",'" + ENTEROPERATOR + "',GETDATE(),0,0,10," + FEESTATUS + ",'',''"; + sql = sql + ",0," + fee.Amount + ",0,0," + fee.UnitPrice + ",'" + ENTEROPERATOR + "',GETDATE(),'',0,0,'COSCO账单回写','RMB','',0,'" + fee.FeeEName + "'"; + sql = sql + ",'" + fee.FA_ID + "',0,0,0,0,0,0)"; + // log.Debug($"更新语句:{sql}"); + SqlCommand cmd2 = new SqlCommand(sql, dbcon); + cmd2.ExecuteNonQuery(); + + } + dbcon.Close(); + } + } + catch (Exception ex) + { + log.Debug($"插入费用出错:{ex.Message+sql}"); + } + + } + + + } + else + { + log.Debug($"数据返回错误:{rtn}"); + } + + + } + + } + + } + + + + + + } + catch (Exception ex) + { + log.Error(ex.Message); + log.Error(ex.StackTrace); + } + } + + static public D7OPSEAE GETBSNO(string MBLNO, SqlConnection dbcon,string BsSql) + { + var OPSEAE = new D7OPSEAE(); + + var strSql = new StringBuilder(); + strSql.Append("SELECT BSNO,BSSTATUS,FEESTATUS,ETD from op_seae where BSNO='" + MBLNO + "' and ISNULL(ISCANCEL,'')<>'1'"); + if (!string.IsNullOrEmpty(BsSql)) + strSql.Append(" and "+BsSql); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + var BSNO = ""; + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + OPSEAE.BSNO = row["BSNO"].ToString(); + OPSEAE.FEESTATUS = Convert.ToBoolean(row["FEESTATUS"].ToString()); + OPSEAE.BSSTATUS = Convert.ToBoolean(row["BSSTATUS"].ToString()); + OPSEAE.ETD = Convert.ToString(row["ETD"].ToString()); + + } + + } + + + return OPSEAE; + } + + static public bool GETINVNOISUSE(string BSNO,string INVNO, SqlConnection dbcon) + { + var result = false; + var strSql = new StringBuilder(); + strSql.Append("SELECT COUNT(1) CT from t_ch_fee where 编号='" + BSNO + "' AND 船公司发票号='" + INVNO + "'"); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + if (Convert.ToInt32(row["CT"].ToString()) != 0) + result = true; + } + + } + + return result; + } + + static public List GetFeeTemplate(string FA_ID, SqlConnection dbcon) + { + + var headList = new List(); + var strSql = new StringBuilder(); + strSql.Append("SELECT GID,TEMPLATEID,FEENAME,CUSTOMERNAME,CLIENT,UNIT"); + strSql.Append(",CURRENCY,UNITPRICE,REMARK,SORT,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,TAXRATE,TAXUNITPRICE,TAX,ACCTAXRATE"); + strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96201 and EnumValueID=code_fee_templatedetail_auto.CLIENT) as CLIENTREF"); + strSql.Append(",(case ISCTN when 1 then '是' else '否' end) as ISCTNREF,ISINVOICE,ISADVANCEDPAY,FEEFRT,SALECORP,FEEDESCRIPTION,UNITPRICEDESCRPTION "); + strSql.Append(" from code_fee_templatedetail_auto WHERE CUSTOMERNAME='" + FA_ID + "'"); + strSql.Append(" order by SORT "); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + var data = new CodeFeeTemplateDetailAuto(); + data.GID = Convert.ToString(row["GID"]); + data.TEMPLATEID = Convert.ToString(row["TEMPLATEID"]); + if (row["UNITPRICE"] != DBNull.Value) + data.UNITPRICE = Convert.ToDecimal(row["UNITPRICE"]); + if (row["EXCHANGERATE"] != DBNull.Value) + data.EXCHANGERATE = Convert.ToDecimal(row["EXCHANGERATE"]); + if (row["TAXRATE"] != DBNull.Value) + data.TAXRATE = Convert.ToDecimal(row["TAXRATE"]); + if (row["TAX"] != DBNull.Value) + data.TAX = Convert.ToDecimal(row["TAX"]); + data.FEENAME = Convert.ToString(row["FEENAME"]); + data.FEEDESCRIPTION = Convert.ToString(row["FEEDESCRIPTION"]); + data.CUSTOMERNAME = Convert.ToString(row["CUSTOMERNAME"]); + if (row["CLIENT"] != DBNull.Value) + data.CLIENT = Convert.ToString(row["CLIENT"]); + data.CLIENTREF = Convert.ToString(row["CLIENTREF"]); + data.UNIT = Convert.ToString(row["UNIT"]); + data.CURRENCY = Convert.ToString(row["CURRENCY"]); + data.REMARK = Convert.ToString(row["REMARK"]); + if (row["SORT"] != DBNull.Value) + data.SORT = Convert.ToInt16(row["SORT"]); + data.FEEFRT = Convert.ToString(row["FEEFRT"]); + data.CREATEUSER = Convert.ToString(row["CREATEUSER"]); + data.CREATETIME = Convert.ToString(row["CREATETIME"]); + if (row["ISCTN"] != DBNull.Value) + data.ISCTN = Convert.ToBoolean(row["ISCTN"]); + data.ISCTNREF = Convert.ToString(row["ISCTNREF"]); + if (row["ISINVOICE"] != DBNull.Value) + data.ISINVOICE = Convert.ToBoolean(row["ISINVOICE"]); + if (row["ISADVANCEDPAY"] != DBNull.Value) + data.ISADVANCEDPAY = Convert.ToBoolean(row["ISADVANCEDPAY"]); + data.SALECORP = Convert.ToString(row["SALECORP"]); + if (row["TAXUNITPRICE"] != DBNull.Value) + data.TAXUNITPRICE = Convert.ToDecimal(row["TAXUNITPRICE"]); + if (row["ACCTAXRATE"] != DBNull.Value) + data.ACCTAXRATE = Convert.ToDecimal(row["ACCTAXRATE"]); + data.UNITPRICEDESCRPTION = Convert.ToString(row["UNITPRICEDESCRPTION"]); + headList.Add(data); + + } + + + } + + return headList; + } + static public List GetFeeUnit(string BSNO, SqlConnection dbcon) + { + decimal TEUNUM; + TEUNUM = 0; + decimal PKGS; + PKGS = 0; + decimal KGS; + KGS = 0; + decimal CBM; + CBM = 0; + decimal NETWEIGHT = 0; + decimal CTNNUM; + CTNNUM = 0; + + var headList = new List(); + var strSql = new StringBuilder(); + strSql.Append("SELECT NO,PKGS,KGS,CBM,NETWEIGHT,CDP,FCDP,CTNALL,CTNNUM,TEU,0 提箱小票数"); + + strSql.Append(",0 超额小票数"); + strSql.Append(",0 不超额小票数 FROM ("); + + strSql.Append("SELECT '1' as NO,件数 PKGS,重量 KGS,尺码 CBM,重量 AS NETWEIGHT,0 CDP,"); + strSql.Append("0 FCDP,"); + strSql.Append("'' as CTNALL,0 AS CTNNUM,0 AS TEU,0 提箱小票数 "); + strSql.Append(",isnull((select sum(数量) from t_op_ctn where 编号=t_op_seae.编号),0) 总箱数 "); + // strSql.Append(",isnull((select sum(ctnrCount) from t_op_txxp_log where 编号=t_op_seae.编号),0)-isnull((select sum(数量) from t_op_ctn where 编号=t_op_seae.编号),0) 超额小票数 "); + + strSql.Append(" from t_op_seae "); + strSql.Append(" where 编号='" + BSNO + "'"); + strSql.Append(") AS T "); + + + strSql.Append(" union "); + strSql.Append("SELECT '2' AS NO,0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,0 AS CDP,0 AS FCDP,"); + strSql.Append("P.表现形式 CTNALL,SUM(P.数量) AS CTNNUM,SUM(P.TEU) AS TEU,0 提箱小票数,0 超额小票数,0 不超额小票数"); + strSql.Append(" from t_op_ctn P "); + strSql.Append(" where p.编号='" + BSNO + "'"); + strSql.Append(" GROUP BY P.表现形式 order by PKGS desc"); + + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + + var isfirst = 0; + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + if (row["NO"].ToString() == "1") + { + var data = new MsFeeUnit(); + data.FEEUNIT = "单票"; + data.FEEQUANTITY = 1; + data.ISCTN = false; + headList.Add(data); + if (!string.IsNullOrEmpty(row["PKGS"].ToString())) + PKGS = Convert.ToDecimal(row["PKGS"].ToString()); + if (!string.IsNullOrEmpty(row["KGS"].ToString())) + KGS = Convert.ToDecimal(row["KGS"].ToString()); + if (!string.IsNullOrEmpty(row["CBM"].ToString())) + CBM = Convert.ToDecimal(row["CBM"].ToString()); + if (!string.IsNullOrEmpty(row["NETWEIGHT"].ToString())) + NETWEIGHT = Convert.ToDecimal(row["NETWEIGHT"].ToString()); + var data2 = new MsFeeUnit(); + data2.FEEUNIT = "重量"; + data2.FEEQUANTITY = KGS; + data2.ISCTN = false; + headList.Add(data2); + var data3 = new MsFeeUnit(); + data3.FEEUNIT = "尺码"; + data3.FEEQUANTITY = CBM; + data3.ISCTN = false; + headList.Add(data3); + var data4 = new MsFeeUnit(); + data4.FEEUNIT = "件数"; + data4.FEEQUANTITY = PKGS; + data4.ISCTN = false; + headList.Add(data4); + var data5 = new MsFeeUnit(); + data5.FEEUNIT = "舱单票数"; + data5.FEEQUANTITY = Convert.ToInt32(row["CDP"].ToString()); + data5.ISCTN = false; + headList.Add(data5); + var data6 = new MsFeeUnit(); + data6.FEEUNIT = "舱单分票"; + data6.FEEQUANTITY = Convert.ToInt32(row["FCDP"].ToString()); + data6.ISCTN = false; + headList.Add(data6); + var txxpdata = new MsFeeUnit(); + txxpdata.FEEUNIT = "提箱小票数"; + txxpdata.FEEQUANTITY = Convert.ToInt32(row["提箱小票数"].ToString()); + txxpdata.ISCTN = false; + headList.Add(txxpdata); + var txxpdata2 = new MsFeeUnit(); + txxpdata2.FEEUNIT = "超额小票数"; + txxpdata2.FEEQUANTITY = Convert.ToInt32(row["超额小票数"].ToString()); + txxpdata2.ISCTN = false; + headList.Add(txxpdata2); + if (Convert.ToInt32(row["不超额小票数"].ToString()) > 0) + { + var txxpdata3 = new MsFeeUnit(); + txxpdata3.FEEUNIT = "不超额小票数"; + txxpdata3.FEEQUANTITY = Convert.ToInt32(row["不超额小票数"].ToString()); + txxpdata3.ISCTN = false; + headList.Add(txxpdata3); + } + else + { + //var txxpdata3 = new MsFeeUnit(); + //txxpdata3.FEEUNIT = "不超额小票数"; + //txxpdata3.FEEQUANTITY = Convert.ToInt32(row["不超额小票数"].ToString()); + //headList.Add(txxpdata3); + + } + } + if (row["CTNALL"].ToString() != "") + { + var ctndata = new MsFeeUnit(); + ctndata.FEEUNIT = row["CTNALL"].ToString(); + if (!string.IsNullOrEmpty(row["CTNNUM"].ToString())) + ctndata.FEEQUANTITY = Convert.ToDecimal(row["CTNNUM"].ToString()); + CTNNUM = CTNNUM + ctndata.FEEQUANTITY; + if (!string.IsNullOrEmpty(row["TEU"].ToString())) + TEUNUM = TEUNUM + Convert.ToDecimal(row["TEU"].ToString()); + ctndata.ISCTN = true; + headList.Add(ctndata); + } + isfirst = 1; + } + var teudata = new MsFeeUnit(); + teudata.FEEUNIT = "TEU"; + teudata.FEEQUANTITY = TEUNUM; + teudata.ISCTN = false; + headList.Add(teudata); + var ctnalldata = new MsFeeUnit(); + ctnalldata.FEEUNIT = "箱数"; + ctnalldata.FEEQUANTITY = CTNNUM; + ctnalldata.FEEQUANTITY = CTNNUM; +.ISCTN = false; + headList.Add(ctnalldata); + + } + + return headList; + } + + + static public string GETUNIT(string UNIT,string CTNALL) + { + var BSNO = UNIT; + if (BSNO == "FIX") BSNO = "单票"; + if (BSNO == "UNI") BSNO = CTNALL; + + return BSNO.Replace("'", "''"); + } + + static public string GETFEENAME(string FEECODE, SqlConnection dbcon, string curr) + { + + var strSql = new StringBuilder(); + strSql.Append("select top 1 [FEENAME] from code_fee_edi where [FEEENAME]='" + FEECODE + "'"); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + var FEENAME = ""; + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + FEENAME = row["FEENAME"].ToString(); + + } + + } + if (string.IsNullOrEmpty(FEENAME)) + { + //if (curr == "USD") + //{ + // FEENAME = "海运费"; + //} else + FEENAME =""; + } + return FEENAME; + } + + + + static public List GetFeeList(string constr, SqlConnection dbcon) { + var feelist = new List(); + var strSql = new StringBuilder(); + strSql.Append("select GID,BSNO from ch_fee where " + constr); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + var fee = new jffee(); + fee.ch_id = row["GID"].ToString(); + fee.bsno = row["BSNO"].ToString(); + feelist.Add(fee); + } + + } + + return feelist; + } + + + static public decimal GetUsdExrate(SqlConnection dbcon,string curr,string ETD) + { + decimal usdexrate = 0; + var startdate = ETD; + if (string.IsNullOrEmpty(startdate)) startdate = DateTime.Now.ToString("yyyy-MM-dd"); + + if (curr == "USD") + { + var strSql = new StringBuilder(); + strSql.Append("select VALUE from currency_exchange where STARTTIME<='"+ startdate + "' and ENDTIME>='"+ startdate + "'"); + strSql.Append(" and CURRENCYID in (select GID from code_currency where CODENAME='"+curr+"') "); + SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon); + DataTable table = new DataTable(); + adapter.Fill(table); + if (table.Rows.Count > 0) + { + foreach (DataRow row in table.Rows) + { + usdexrate = Convert.ToDecimal(row["VALUE"].ToString()); + } + } + } + if (usdexrate == 0) + { + SqlDataAdapter adapter2 = new SqlDataAdapter("select DEFAULTRATE from code_currency where CODENAME='" + curr + "'", dbcon); + DataTable table2 = new DataTable(); + adapter2.Fill(table2); + if (table2.Rows.Count > 0) + { + foreach (DataRow row in table2.Rows) + { + usdexrate = Convert.ToDecimal(row["DEFAULTRATE"].ToString()); + } + } + + + } + + + return usdexrate; + } + + } + + + //public class JsonFeeResponse + //{ + // public string ReceiveId { get; set; } + // public string MBLNO { get; set; } + // public string INVOICE_NO { get; set; } + // public string CANCEL_NO { get; set; } + // public string TOTAL_AMOUNT { get; set; } + // public List DATA { get; set; } + //} + //public class DJYFEE + //{ + // public string FEECODE { get; set; } + // public string AMOUNT { get; set; } + // public string AMOUNT_USD { get; set; } + // public string CURRENCY { get; set; } + // public string CTNALL { get; set; } + // public string TAX { get; set; } + // public string COUNT { get; set; } + // public string UNIT { get; set; } + // public string RATE { get; set; } + + + //} + + + //public class feeback + //{ + // public string ReceiveId { get; set; } + // public bool Success { get; set; } + // public string Reason { get; set; } + + //} + //public class jffee + //{ + // public string ch_id { get; set; } + // public string bsno { get; set; } + + //} + + +} diff --git a/JobAutoCreateFee/Model/CreateFee.cs b/JobAutoCreateFee/Model/CreateFee.cs index 8b85768b..813530dc 100644 --- a/JobAutoCreateFee/Model/CreateFee.cs +++ b/JobAutoCreateFee/Model/CreateFee.cs @@ -46,7 +46,7 @@ namespace JobAutoCreateFee.Model { public string FEEUNIT { get; set; } public decimal FEEQUANTITY { get; set; } - + public bool ISCTN { get; set; } } public class MsClient