You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1243 lines
48 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Web;
using System.Web.Configuration;
using System.Web.UI.WebControls;
using DSWeb.Areas.CommMng.Controllers;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.MvcShipping.DB;
using DSWeb.Areas.MvcShipping.Models.Message.VGM;
using DSWeb.Common.DB;
using DSWeb.MvcContainer.DAL.MsOpCtnApply;
using DSWeb.MvcShipping.DAL.DsSendmail;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
//using DSWeb.Dispatch.DAL;
using HcUtility.Comm;
using javax.management.loading;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using User = DSWeb.Common.DB.User;
namespace DSWeb.Areas.CommMng.Models
{
#region TSYSENUMVALUE
/// <summary>
/// This object represents the properties and methods of a TSYSENUMVALUE.
/// </summary>
///
[JsonObject]
public class SysEnumValue
{
private decimal _langId;
private decimal _enumTypeId;
private string _enumValueId = String.Empty;
private string _enumValueName = String.Empty;
private string _enumValueName_2 = String.Empty;
private string _isDefault = String.Empty;
private decimal _dispIndex;
private string _verNo = String.Empty;
private string _enumValueAndName = String.Empty;
#region Public Properties
public decimal LangId
{
get { return _langId; }
set { _langId = value; }
}
public decimal EnumTypeId
{
get { return _enumTypeId; }
set { _enumTypeId = value; }
}
public string EnumValueId
{
get { return _enumValueId; }
set { _enumValueId = value; }
}
public string EnumValueName
{
get { return _enumValueName; }
set { _enumValueName = value; }
}
public string EnumValueName_2
{
get { return _enumValueName_2; }
set { _enumValueName_2 = value; }
}
public string IsDefault
{
get { return _isDefault; }
set { _isDefault = value; }
}
public decimal DispIndex
{
get { return _dispIndex; }
set { _dispIndex = value; }
}
public string VerNo
{
get { return _verNo; }
set { _verNo = value; }
}
public string EnumValueAndName
{
get { return _enumValueAndName; }
set { _enumValueAndName = value; }
}
#endregion
}
#endregion
#region 全泰 账单解析类
public class Bill_detailsItem
{
/// <summary>
/// 单证费
/// </summary>
public string cost_name { get; set; }
/// <summary>
///
/// </summary>
public string cost_unit { get; set; }
/// <summary>
///
/// </summary>
public string cost_price { get; set; }
/// <summary>
///
/// </summary>
public string cost_count { get; set; }
/// <summary>
///
/// </summary>
public string cost_currency { get; set; }
/// <summary>
///
/// </summary>
public string cost_amount { get; set; }
}
public class Bill_Head
{
/// <summary>
/// 提单号
/// </summary>
public string bill_no { get; set; }
/// <summary>
///
/// </summary>
public string bill_date { get; set; }
/// <summary>
/// 正本提单
/// </summary>
public string bill_type { get; set; }
/// <summary>
/// 已出单
/// </summary>
public string bill_status { get; set; }
/// <summary>
///
/// </summary>
public string bill_vessel { get; set; }
/// <summary>
///
/// </summary>
public string bill_voyage { get; set; }
/// <summary>
///
/// </summary>
public string bill_amount_usa { get; set; }
/// <summary>
///
/// </summary>
public string bill_amount_rmb { get; set; }
/// <summary>
///
/// </summary>
public string bill_container_type { get; set; }
/// <summary>
///
/// </summary>
public string bill_container_count { get; set; }
/// <summary>
///
/// </summary>
public string bill_remark { get; set; }
/// <summary>
///
/// </summary>
public List<Bill_detailsItem> bill_details { get; set; }
}
public class DealBillHelper
{
public DealBillHelper() { }
public Bill_Head BillHead { get; set; }
public opseae_md head { get; set; }
public List<op_ctn_md> ctnList { get; set; }
public Int32 CtnNum { get; set; }
public List<ch_fee_md> NewFeeList { get; set; }
private void addfee(ch_fee_md fee) {
if (NewFeeList == null) NewFeeList = new List<ch_fee_md>();
fee.CUSTOMERTYPE = "订舱代理";
fee.INPUTMODE = INPUTMODE;
if (fee.AMOUNT != 0)
{
NewFeeList.Add(fee);
}
}
private void addfee(List<ch_fee_md> feeList)
{
if (feeList != null) {
foreach (var fee in feeList) {
addfee(fee);
}
}
}
public CommonDataContext cdc { get; set; }
public User OP { get; set; }
public DBResult CanMake { get; set; }
const string INPUTMODE = "船公司费用自动导入";
public decimal UsdExchange { get; set; } = 1;
private List<tSysEnumValue_md> { get; set; }
private List<tSysEnumValue_md> { get; set; }
private List<tSysEnumValue_md> { get; set; }
private decimal GetPrice(string BILLFeeName) {
if (.Exists(x => x.EnumValueID == BILLFeeName)) {
return Convert.ToDecimal(.First(x => x.EnumValueID == BILLFeeName).EnumValueName);
}
return 0;
}
private bool ContainsPrice(string BILLFeeName)
{
if (.Exists(x => x.EnumValueID == BILLFeeName))
{
return true;
}
return false;
}
private List<decimal> GetPriceList(string BILLFeeName)
{
var result = new List<decimal>();
if (.Exists(x => x.EnumValueID == BILLFeeName))
{
var feestrList=.First(x => x.EnumValueID == BILLFeeName).EnumValueName.Split(',').ToList();
foreach (var item in feestrList) {
result.Add(Convert.ToDecimal(item));
}
}
return result;
}
private string GetFeeName(string BILLFeeName)
{
if (.Exists(x => x.EnumValueID == BILLFeeName))
{
return .First(x => x.EnumValueID == BILLFeeName).EnumValueName_2;
}
return "";
}
private List<string> GetBillFeeName(string LogicFeeName)
{
//其中 枚举类型.EnumValueName 对应 逻辑上的拆分模块
//EnumValueName_2 对应东胜的费用名称
//EnumValueID 对应报文中的文件名
if (.Exists(x => x.EnumValueName == LogicFeeName))
{
return .Where(x => x.EnumValueName == LogicFeeName).Select(s=>s.EnumValueID).ToList();
}
return new List<string>();
}
private void SetUsd(ref ch_fee_md newfee) {
newfee.CURRENCY = "USD";
newfee.EXCHANGERATE = UsdExchange;
}
public DealBillHelper(string str)
{
BillHead=JsonConvert.DeserializeObject<Bill_Head>(str);
cdc=new CommonDataContext();
CanMake = new DBResult();
var opseaeList = cdc.OP_SEAE.Where(x => x.MBLNO == BillHead.bill_no).ToList();
if (opseaeList == null || opseaeList.Count == 0) {
CanMake.SetErrorInfo("没有找到业务;");
}
if (opseaeList != null && opseaeList.Count > 0)
{
CanMake.OK();
if (opseaeList.Count == 1)
{
head = opseaeList[0];
}
else
{
if (opseaeList.Exists(x => x.MASTERNO == x.BSNO))
{
head = opseaeList.First(x => x.MASTERNO == x.BSNO);
}
else {
CanMake.SetErrorInfo("没有找到主业务;");
}
}
}
if (CanMake.Success)
{
ctnList = cdc.OP_CTN.Where(x => x.BSNO == head.BSNO).ToList();
CtnNum = 0;
if (ctnList != null && ctnList.Count > 0) {
CtnNum = ctnList.Sum(x=>x.CTNNUM==null?0:(Int32)x.CTNNUM);
}
var bsdatestr = ((DateTime)head.BSDATE).ToString("yyyy-MM-dd");
UsdExchange = MsOpCtnApplyDAL.GetUsdExrate(bsdatestr, "USD");
}
//20240528 判断解析业务的先决条件
//必须有 航线 卸货港 箱信息内必须要有 箱型箱量
if (string.IsNullOrWhiteSpace(head.LANE))
{
CanMake.SetErrorInfo("业务没有录入航线;");
}
if (string.IsNullOrWhiteSpace(head.PORTDISCHARGE))
{
CanMake.SetErrorInfo("业务没有录入卸货港;");
}
if (ctnList.Exists(x=>string.IsNullOrWhiteSpace(x.CTNALL) || x.CTNNUM==null||x.CTNNUM==0))
{
CanMake.SetErrorInfo("存在缺少箱型箱量的集装箱信息;");
}
OP = cdc.User.FirstOrDefault(x => x.SHOWNAME == head.OP);
if (OP == null)
{
OP=cdc.User.FirstOrDefault(x => x.SHOWNAME == "系统管理员");
}
= cdc.tSysEnumValue.Where(x => x.EnumTypeID==45).ToList();
= cdc.tSysEnumValue.Where(x => x.EnumTypeID == 46).ToList();
= cdc.tSysEnumValue.Where(x => x.EnumTypeID == 47).ToList();
var currfee = cdc.ch_fee.Where(x => x.BSNO == head.BSNO).ToList();
var nofeeCustList = new List<string> {
"青岛港国际物流","中外运","中创物流"
};
if (currfee.Exists(x => nofeeCustList.Contains(x.CUSTOMERNAME) && x.FEETYPE == 2))
{
CanMake.SetErrorInfo("业务已存在相关结算对象的费用;");
}
}
public DBResult GetFee()
{
var result = new DBResult();
result = Make_();
result = Make_();
result = Make_();
result = Make_();
if (CanMake.Success)
{
cdc.ch_fee.AddRange(NewFeeList);
cdc.SaveChanges();
DoSendSuccessMail();
}
else {
if (!CanMake.Success)
{
//发出提醒邮件
DoSendErrorMail();
return CanMake;
}
}
return result;
}
public DBResult Make_()
{
var result = new DBResult();
result.OK();
/*
*
【单证费】按单票 ,且不区分大小柜子及多少 450/票
【铅封费】按照柜且不区分大小柜子30/柜子 (24年3月份更改此需求从原33改为30从中拆分出信息费用)
【信息费】按照柜且不区分大小柜子3/柜子 (24年3月份新增此需求)
【改单费】按票 400/票 (24年3月份新增此需求)
【船证费】按票 50/票或者 100/票 (24年3月份新增此需求)
规则:
先判断航线;东南亚航线无单证费,其他航线有单证费
在按柜子拆分出【铅封费】和【信息费】之后剩余的费用
若剩余金额等于0则表示没有【改单费】或者【船证费】
若剩余金额等于400 则为【改单费】,
若剩余金额为 50或者100 则为【船证费】,
若剩余金额不等于0或者400或者50 或者100则按票回写(注:直接按票回写单证费就行,不要在拆分 铅封费和信息费等费用了)
*/
var List = GetBillFeeName("码头操作费");
if (!BillHead.bill_details.Exists(x => List.Contains( x.cost_name)))
{
return result;
}
var = 0M;
var = ;
if (BillHead.bill_details.Exists(x => x.cost_name == "单证费"))
{
=Convert.ToDecimal(BillHead.bill_details.FirstOrDefault(x => x.cost_name == "单证费").cost_amount);
= ;
}
else
if (BillHead.bill_details.Exists(x => x.cost_name == "出口码头操作费--THC"))
{
=Convert.ToDecimal(BillHead.bill_details.FirstOrDefault(x => x.cost_name == "出口码头操作费--THC").cost_amount);
= ;
}
else if (BillHead.bill_details.Exists(x => x.cost_name == "出口码头操作费"))
{
=Convert.ToDecimal(BillHead.bill_details.FirstOrDefault(x => x.cost_name == "出口码头操作费").cost_amount);
= ;
}
var List = new List<ch_fee_md>();
void add(ch_fee_md newfee,op_ctn_md ctn)
{
if (List.Exists(x => x.UNIT == ctn.CTNALL && x.FEENAME==newfee.FEENAME))
{
List.First(x => x.UNIT == ctn.CTNALL).QUANTITY += 1;
List.First(x => x.UNIT == ctn.CTNALL).AMOUNT += newfee.AMOUNT;
List.First(x => x.UNIT == ctn.CTNALL).REMARK += ";" + ctn.CNTRNO;
}
else
{
List.Add(newfee);
}
-= (decimal)newfee.AMOUNT;
}
if (ctnList != null && CtnNum > 0)
{
var price = GetPrice("铅封费");
var price = GetPrice("信息费");
if ( < CtnNum * (price + price))
{
foreach (var ctn in ctnList)
{
//var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", 单价 * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "铅封费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//var 信息费 = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "信息费", 信息费price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//SetUsd(ref 铅封费);
//SetUsd(ref 信息费);
add(, ctn);
//add单证费(信息费, ctn);
}
}
else
{
foreach (var ctn in ctnList)
{
//var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", 单价 * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "铅封费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "信息费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//SetUsd(ref 铅封费);
//SetUsd(ref 信息费);
add(, ctn);
add(, ctn);
}
}
addfee(List);
if ( > 0)
{
if (head.LANE != "DNY东南亚航线" && head.LANE != "东南亚航线")
{
var price = GetPrice("单证费");
var feename = GetFeeName("单证费");
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, feename, price, "单票", 1);
addfee(newfee);
-= (decimal)newfee.AMOUNT;
}
var List = GetPriceList("船证费");
var = GetPrice("改单费");
if (List.Contains())
{
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "船证费", , "单票", 1);
addfee();
}
else
if ( == )
{
var _ = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "改单费", , "单票", 1);
addfee(_);
}
else
if ( > 0)
{
var _ = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "单证费", , "单票", 1);
addfee(_);
}
}
else if ( < 0)
{
CanMake.SetErrorInfo($"单证费原值{单证费原值},不足以按规则拆分成相应费用;");
}
}
return result;
}
public DBResult Make_()
{
var result = new DBResult();
result.OK();
/*
2:THC/码头操作费:对应东胜系统【码头操作费】
【THC/码头操作费】按柜子,且区分大小柜子
"规则判断卸货港录入的是不是KAOHSIUNG (“台湾高雄”)
"
《1》卸货港录入的是KAOHSIUNG
"规则20尺的按照661RMB40尺的按照992RMB大冻柜1023RMB40RH小冻柜682RMB20RH
箱型有:(20OT/20FR/20TK/20HT/40HQ/40OT/40OH/40FR/40TK/40HT)
"
《2》卸货港录入的不是KAOHSIUNG 的
"规则20尺的按照620RMB40尺按照930RMB
箱型有:(20OT/20FR/20TK/20HT/40HQ/40OT/40OH/40FR/40TK/40HT)"
*/
var List = GetBillFeeName("码头操作费");
if (!BillHead.bill_details.Exists(x => List.Contains( x.cost_name)) || !(ctnList != null && ctnList.Count > 0))
{
return result;
}
var Amount = Convert.ToDecimal(BillHead.bill_details.Where(x => List.Contains(x.cost_name)).Sum(c=>Convert.ToDecimal(c.cost_amount)));
var _ = Amount;
var List = new List<ch_fee_md>();
void Add(op_ctn_md ctn,decimal price)
{
var ctnnum = ctn.CTNNUM == null ? 0 : (Int32)ctn.CTNNUM;
var amount = price * ctnnum;
if (Amount >= price)
{
if (List.Exists(x => x.UNIT == ctn.CTNALL && x.UNITPRICE==price))
{
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price).QUANTITY += ctnnum;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price).AMOUNT += amount;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price).REMARK += ";"+ ctn.CNTRNO;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price).setTax();
}
else
{
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "码头操作费", amount, ctn.CTNALL, ctnnum, "",ctn.CNTRNO);
List.Add();
}
Amount -= amount;
}
else
{
CanMake.SetErrorInfo($"码头操作费原值{_码头操作费原值},不足以按规则拆分成相应费用;");
}
}
if (ctnList != null && CtnNum > 0)
{
//var 高雄20 = GetPrice("高雄20");
//var 高雄40 = GetPrice("高雄40");
//var 高雄20RH = GetPrice("高雄20RH");
//var 高雄40RH = GetPrice("高雄40RH");
//var ctn20 = GetPrice("20");
//var ctn40 = GetPrice("40");
//var All40RH = GetPrice("40RH");
var price = 0M;
if (.Exists(x=>x.EnumValueName== head.PORTDISCHARGE) )
{
foreach (var ctn in ctnList)
{
//if (ctn.CTNALL == "20RH") {
// 码头操作费Add(ctn, 高雄20RH);
//}else
if (ContainsPrice("高雄" + ctn.CTNALL) )
{
price= GetPrice("高雄" + ctn.CTNALL);
Add(ctn, price);
}
else
if (ctn.SIZE == "40")
{
price=GetPrice("高雄40");
Add(ctn, price);
}
else
if (ctn.SIZE == "20")
{
price = GetPrice("高雄20");
Add(ctn, price);
}
}
}
else
{
foreach (var ctn in ctnList)
{
if (ContainsPrice( ctn.CTNALL))
{
price = GetPrice( ctn.CTNALL);
Add(ctn, price);
}
else
if (ctn.SIZE == "40")
{
price= GetPrice("40");
Add(ctn, price);
}
else
if (ctn.SIZE == "20")
{
price = GetPrice("20");
Add(ctn, price);
}
}
}
if (Amount > 0)
{
List.Clear();
//按规则无法拆分 改为一条
var _ = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "码头操作费", _, "单票", 1);
//SetUsd(ref _码头操作费);
addfee(_);
}
else {
addfee(List);
}
}
return result;
}
public DBResult Make_()
{
var result = new DBResult();
result.OK();
/*
《1》【海运费 】 按柜子回写,且选先判断下航线
欧洲航线和地中海航线有 ENS申报费按票 30美金
美加航线AMS=美国舱单费(按票) 30美金
除以上3个航线外其他航线 无 (AMS或 ENS申报费)
如: 欧洲航线 ,海运费 2030
则:先拆分出: ENS申报费按票 30美金之后 【海运费】(按柜子)均分剩余金额
《2》若整除不开或者不符合规则此票按 按票回写
《3》是否区分大小柜此类属于不符合规则则按票回写"
*/
var List = GetBillFeeName("海运费");
if (!BillHead.bill_details.Exists(x => List.Contains( x.cost_name ) || !(ctnList != null && ctnList.Count > 0)))
{
return result;
}
var Amount = Convert.ToDecimal(BillHead.bill_details.Where(x => List.Contains(x.cost_name)).Sum(c => Convert.ToDecimal(c.cost_amount)));
var Amount = Amount;
var List = new List<ch_fee_md>();
void Add(ch_fee_md newfee,op_ctn_md ctn=null)
{
if (Amount >= newfee.AMOUNT)
{
if (ctn != null)
{
if (List.Exists(x => x.UNIT == ctn.CTNALL && x.UNITPRICE==newfee.UNITPRICE))
{
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == newfee.UNITPRICE).QUANTITY += newfee.QUANTITY;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == newfee.UNITPRICE).AMOUNT += newfee.AMOUNT;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == newfee.UNITPRICE).REMARK += ";" + ctn.CNTRNO;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == newfee.UNITPRICE).setTax();
}
else
{
List.Add(newfee);
}
}
else {
List.Add(newfee);
}
Amount -= (decimal)newfee.AMOUNT;
}
else
{
CanMake.SetErrorInfo($"海运费原值{Amount原值},不足以按规则拆分成相应费用;");
}
}
if (ctnList != null && CtnNum > 0)
{
//1: 欧洲航线和地中海航线有 ENS申报费按票 30美金
//美加航线AMS = 美国舱单费(按票) 30美金
//除以上3个航线外其他航线 无(AMS或 ENS申报费)
var companyname = ConfigurationManager.AppSettings["COMPANYNAME"];
if (companyname == "全泰")
{
var = GetPrice("海运费欧洲航线申报");
var FeeName = GetFeeName("海运费欧洲航线申报");
var = GetPrice("海运费地中海航线申报");
var FeeName = GetFeeName("海运费地中海航线申报");
var = GetPrice("海运费美加航线申报");
var FeeName = GetFeeName("海运费美加航线申报");
if (head.LANE == "欧洲航线")
{
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, FeeName, , "单票", 1);
SetUsd(ref newfee);
Add(newfee);
}
if (head.LANE == "地中海(含北非)")
{
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, FeeName, , "单票", 1);
SetUsd(ref newfee);
Add(newfee);
}
if (head.LANE == "美加航线")
{
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, FeeName, , "单票", 1);
SetUsd(ref newfee);
Add(newfee);
}
}
var = true;
var = Math.Round(Amount/ CtnNum, 2);
if ( * CtnNum != Amount) {
= false;
}
foreach (var ctn in ctnList)
{
if (ctnList.Exists(x => x.SIZE!=ctn.SIZE))
{
= false;
}
}
if ()
{
foreach (var ctn in ctnList)
{
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", *(decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
SetUsd(ref newfee);
Add(newfee,ctn);
}
}
if (!)
{
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", Amount, "单票", 1);
SetUsd(ref newfee);
Add(newfee);
}
}
addfee(List);
return result;
}
public DBResult Make_()
{
var result = new DBResult();
result.OK();
/*
《1》【海运费 】 按柜子回写,且选先判断下航线
欧洲航线和地中海航线有 ENS申报费按票 30美金
美加航线AMS=美国舱单费(按票) 30美金
除以上3个航线外其他航线 无 (AMS或 ENS申报费)
如: 欧洲航线 ,海运费 2030
则:先拆分出: ENS申报费按票 30美金之后 【海运费】(按柜子)均分剩余金额
《2》若整除不开或者不符合规则此票按 按票回写
《3》是否区分大小柜此类属于不符合规则则按票回写"
*/
//2024-718 东南亚航线 没有单证费 没有码头操作费 只有出口码头操作费
var List = GetBillFeeName("出口码头操作费");
if (!BillHead.bill_details.Exists(x => List.Contains( x.cost_name )) || !(ctnList != null && ctnList.Count > 0))
{
return result;
}
var Amount = Convert.ToDecimal(BillHead.bill_details.Where(x => List.Contains(x.cost_name) ).Sum(c => Convert.ToDecimal(c.cost_amount)));
var Amount = Amount;
var List = new List<ch_fee_md>();
void Add(op_ctn_md ctn, decimal price,string FEENAME= "码头操作费")
{
var ctnnum = ctn.CTNNUM == null ? 0 : (Int32)ctn.CTNNUM;
var amount = price * ctnnum;
if (Amount >= price)
{
if (List.Exists(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price && x.FEENAME== FEENAME))
{
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price && x.FEENAME == FEENAME).QUANTITY += ctnnum;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price && x.FEENAME == FEENAME).AMOUNT += amount;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price && x.FEENAME == FEENAME).REMARK += ";" + ctn.CNTRNO;
List.First(x => x.UNIT == ctn.CTNALL && x.UNITPRICE == price && x.FEENAME == FEENAME).setTax();
}
else
{
//var 码头操作费 = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "码头操作费", price, ctn.CTNALL, 1, "", ctn.CNTRNO);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, FEENAME, amount, ctn.CTNALL, ctnnum, "", ctn.CNTRNO);
List.Add();
}
Amount -= amount;
}
else
{
CanMake.SetErrorInfo($"出口码头操作费原值{Amount原值},不足以按规则拆分成相应费用;");
}
}
void Add(ch_fee_md newfee)
{
if (Amount >= newfee.AMOUNT)
{
List.Add(newfee);
Amount -= (decimal)newfee.AMOUNT;
}
else
{
CanMake.SetErrorInfo($"出口码头操作费原值{Amount原值},不足以按规则拆分成相应费用;");
}
}
if (ctnList != null && CtnNum > 0)
{
//4:出口码头操作费--THC:对应东胜系统【码头操作费】
// 目前 船代上的[出口码头操作费--THC]是包含【单证费】和【铅封费】以及【码头操作费】,自动回写到系统需要自动分开
// 注:此规则用于外运网站上的 出口码头操作费--THC
//【单证费】按单票 ,且不区分大小柜子及多少 450 / 票
//【铅封费】按照柜且不区分大小柜子33 / 柜子
//【码头操作费】按照柜,且不区分大小柜子
//规则:先根据航线判断-- - 是否减掉单证费(按票),东南亚航线无单证费;在判断卸货港是不是“台湾高雄”的
//《1》卸货港录入的是KAOHSIUNG
//"规则20尺的按照661RMB40尺的按照992RMB大冻柜1023RMB40RH小冻柜682RMB20RH
//箱型有:(20OT / 20FR / 20TK / 20HT / 40HQ / 40OT / 40OH / 40FR / 40TK / 40HT)
//"
//《2》卸货港录入的不是KAOHSIUNG 的
//"规则20尺的按照620RMB40尺按照930RMB
//箱型有:(20OT / 20FR / 20TK / 20HT / 40HQ / 40OT / 40OH / 40FR / 40TK / 40HT)"
//"例如:船代上 【出口码头操作费--THC】显示为1413RMB的不是东南亚航线则拆成单证费450RMB按票
//铅封费33RMB,码头操作费930"
if (head.LANE != "DNY东南亚航线" && head.LANE != "东南亚航线")
{
var price = GetPrice("单证费");
var feename = GetFeeName("单证费");
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, feename, price, "单票", 1);
Add(newfee);
}
var price = 0M;
if (.Exists(x => x.EnumValueName == head.PORTDISCHARGE))
{
foreach (var ctn in ctnList)
{
//if (ctn.CTNALL == "20RH") {
// 码头操作费Add(ctn, 高雄20RH);
//}else
if (ContainsPrice("高雄" + ctn.CTNALL))
{
price = GetPrice("高雄" + ctn.CTNALL);
Add(ctn, price);
}
else
if (ctn.SIZE == "40")
{
price = GetPrice("高雄40");
Add(ctn, price);
}
else
if (ctn.SIZE == "20")
{
price = GetPrice("高雄20");
Add(ctn, price);
}
}
}
else
{
foreach (var ctn in ctnList)
{
if (ContainsPrice(ctn.CTNALL))
{
price = GetPrice(ctn.CTNALL);
Add(ctn, price);
}
else
if (ctn.SIZE == "40")
{
price = GetPrice("40");
Add(ctn, price);
}
else
if (ctn.SIZE == "20")
{
price = GetPrice("20");
Add(ctn, price);
}
}
}
}
if (Amount > 0) {
//代表存在剩余尾数 先尝试处理铅封费信息费
var price = GetPrice("铅封费");
var price = GetPrice("信息费");
if (Amount < CtnNum * (price + price))
{
foreach (var ctn in ctnList)
{
//var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", 单价 * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "铅封费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//var 信息费 = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "信息费", 信息费price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//SetUsd(ref 铅封费);
//SetUsd(ref 信息费);
Add( ctn, price, "铅封费");
//add单证费(信息费, ctn);
}
}
else
{
foreach (var ctn in ctnList)
{
//var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "海运费", 单价 * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "铅封费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
var = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "信息费", price * (decimal)ctn.CTNNUM, ctn.CTNALL, (decimal)ctn.CTNNUM);
//SetUsd(ref 铅封费);
//SetUsd(ref 信息费);
Add(ctn, price, "铅封费");
Add(ctn, price, "信息费");
}
}
}
if (Amount > 0) {
//var feename = GetFeeName("码头操作费");
var newfee = MsChFeeDAL.getChFee(OP.GID, head.BSNO, head.FORWARDER, 2, "码头操作费", Amount, "单票", 1);
Add(newfee);
}
addfee(List);
return result;
}
public void DoSendErrorMail()
{
//首先判断该业务的 op_logicinfo.propname= 账单解析错误 bsno=head.bsno的值是否存在
//如不存在设置为1 如存在判断其是否大于等于3如大于等于3则不执行
var = BasicDataRefDAL.GetLogicValue_Str("账单解析错误", head.BSNO);
if (string.IsNullOrWhiteSpace())
{
= "1";
BasicDataRefDAL.SaveLogicInfo_Str(head.BSNO, "账单解析错误", );
}
else {
var int = Convert.ToInt32();
if (int >= 3) return;
int++;
BasicDataRefDAL.SaveLogicInfo_Str(head.BSNO, "账单解析错误", int.ToString());
}
//向OP的邮箱发提醒邮件
var user_op = cdc.VW_user.FirstOrDefault(x => x.USERID == OP.GID);
if (user_op == null) return;
var OPEmail = cdc.VW_user.FirstOrDefault(x => x.USERID == OP.GID).EMAIL1;
var email = OPEmail;
var mailbody = $"提单号【{head.MBLNO}】,账单解析写入错误:</br>";
var bodystr = CanMake.Message.Replace(";,", "</br>");
//string toNames = "frank,lee";
mailbody += bodystr;
var mailtopic = $"账单解析出错【{head.MBLNO}】";
var MAILTONAME = "admin@dongshengsoft.com";
var PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTONAME'");
if (PARAMVALUE.PARAMVALUE != "") MAILTONAME = PARAMVALUE.PARAMVALUE;
var MAILTOPASSWORD = "ds!@#)(*";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPASSWORD'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPASSWORD = PARAMVALUE.PARAMVALUE;
var MAILTOSERVER = "smtpcom.263xmail.com";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOSERVER'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOSERVER = PARAMVALUE.PARAMVALUE;
var MAILTOPORT = "465";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPORT'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPORT = PARAMVALUE.PARAMVALUE;
var MAILISSSL = false;
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILISSSL'");
if (PARAMVALUE.PARAMVALUE == "1") MAILISSSL = true;
SendEmail se = new SendEmail(email, MAILTONAME, "", "", mailtopic, mailbody, true);
// SendEmail se = new SendEmail("dev001@dongshengsoft.com", "admin@dongshengsoft.com", "", "", mailtopic, mailbody, false);
//string filePath = filename;
//se.Attachments(filePath);
try
{
se.SetSmtp(MAILTONAME, MAILTOPASSWORD, MAILTOSERVER, Convert.ToInt32(MAILTOPORT), MAILISSSL, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
//
}
catch (Exception e)
{
se.SetSmtp(MAILTONAME, MAILTOPASSWORD, MAILTOSERVER, Convert.ToInt32(MAILTOPORT), MAILISSSL, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
//
}
}
public void DoSendSuccessMail()
{
//向OP的邮箱发提醒邮件
var user_op = cdc.VW_user.FirstOrDefault(x => x.USERID == OP.GID);
if (user_op == null) return;
var OPEmail = cdc.VW_user.FirstOrDefault(x => x.USERID == OP.GID).EMAIL1;
var email = OPEmail;
var mailbody = $"尊敬的{OP.SHOWNAME},您好:</br> 船名:{head.VESSEL},航次:{head.VOYNO},提单号【{head.MBLNO}】的账单解析成功";
var bodystr = CanMake.Message.Replace(";,", "</br>");
//string toNames = "frank,lee";
mailbody += bodystr;
var mailtopic = $"【账单解析成功】:船名:{head.VESSEL},航次:{head.VOYNO},提单号 {head.MBLNO} 账单下载成功";
var MAILTONAME = "admin@dongshengsoft.com";
var PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTONAME'");
if (PARAMVALUE.PARAMVALUE != "") MAILTONAME = PARAMVALUE.PARAMVALUE;
var MAILTOPASSWORD = "ds!@#)(*";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPASSWORD'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPASSWORD = PARAMVALUE.PARAMVALUE;
var MAILTOSERVER = "smtpcom.263xmail.com";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOSERVER'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOSERVER = PARAMVALUE.PARAMVALUE;
var MAILTOPORT = "465";
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILTOPORT'");
if (PARAMVALUE.PARAMVALUE != "") MAILTOPORT = PARAMVALUE.PARAMVALUE;
var MAILISSSL = false;
PARAMVALUE = MsSysParamSetDAL.GetData("PARAMNAME='MAILISSSL'");
if (PARAMVALUE.PARAMVALUE == "1") MAILISSSL = true;
SendEmail se = new SendEmail(email, MAILTONAME, "", "", mailtopic, mailbody, true);
// SendEmail se = new SendEmail("dev001@dongshengsoft.com", "admin@dongshengsoft.com", "", "", mailtopic, mailbody, false);
//string filePath = filename;
//se.Attachments(filePath);
try
{
se.SetSmtp(MAILTONAME, MAILTOPASSWORD, MAILTOSERVER, Convert.ToInt32(MAILTOPORT), MAILISSSL, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
//
}
catch (Exception e)
{
se.SetSmtp(MAILTONAME, MAILTOPASSWORD, MAILTOSERVER, Convert.ToInt32(MAILTOPORT), MAILISSSL, System.Net.Mail.MailPriority.Normal); //必须在所有参数设置完后调用此方法
//
}
}
}
#endregion
}