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.
DS7/DSWeb/Areas/Import/Controllers/PortOperateController.cs

493 lines
22 KiB
C#

This file contains ambiguous Unicode 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.Linq;
using System.Web.Mvc;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Import.DAL.XXH;
using DSWeb.Areas.Import.Models.XXH;
using DSWeb.Areas.Import.Models.PortOperate;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.MvcShipping.Controllers;
using DSWeb.MvcShipping.Models.MsOpAmend;
using DSWeb.Areas.Import.DAL.ImportTrade;
using DSWeb.Areas.Import.DAL.Comm;
using DSWeb.Areas.Import.Models.Comm;
using DSWeb.SoftMng.Filter;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class PortOperateController : Controller
{
//
// GET: /Import/create
public ActionResult Index()
{
return View();
}
public ActionResult Index2 ( )
{
return View();
}
//
// GET: /Import/create/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult Edit2 ( )
{//天津誉恒版
return View();
}
// GET/Import/operate/Save
public ContentResult Save(string opstatus, string data,
string Receiptbody, string Receiptdelbody,
string CargoBody, string CargoDelBody,
string AppstateBody, string AppstateDelBody,
string KCBody, string KCDelBody, string chfeebody, string chfeedelbody)
{
var head = JsonConvert.Deserialize<PortOperatemb>(data);
var ReceiptbodyList = JsonConvert.Deserialize<List<Receiptmb>>(Receiptbody);
var ReceiptdelbodyList = JsonConvert.Deserialize<List<Receiptmb>>(Receiptdelbody);
var CargobodyList = JsonConvert.Deserialize<List<Cargomb>>(CargoBody);
var CargodelbodyList = JsonConvert.Deserialize<List<Cargomb>>(CargoDelBody);
var AppstateBodyList = JsonConvert.Deserialize<List<Appstatemb>>(AppstateBody);
var AppstateDelBodyList = JsonConvert.Deserialize<List<Appstatemb>>(AppstateDelBody);
var KCBodyList = JsonConvert.Deserialize<List<KCmb>>(KCBody);
var KCDelBodyList = JsonConvert.Deserialize<List<KCmb>>(KCDelBody);
var chfeeBodyList = JsonConvert.Deserialize<List<DSWeb.Areas.TruckMng.Models.Comm.MsChFee>>(chfeebody);
var chfeeBodyDelList = JsonConvert.Deserialize<List<DSWeb.Areas.TruckMng.Models.Comm.MsChFee>>(chfeedelbody);
if (chfeeBodyList != null)
{
foreach (var _fee in chfeeBodyList)
{
_fee.MODIFIEDTIME = DateTime.Now.ToString();
_fee.MODIFIEDUSER = Session["USERID"].ToString();
}
}
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.ContractNo = PubSysDAL.GetBillNo("0201"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
head.MODIFIEDUSER = Session["SHOWNAME"].ToString();
head.MODIFIEDTIME = System.DateTime.Now.ToString();
DBResult result = modb.Save(head,
ModelObjectConvert<Receiptmb>.ToModelObjectList(ReceiptbodyList),
ModelObjectConvert<Receiptmb>.ToModelObjectList(ReceiptdelbodyList),
ModelObjectConvert<Cargomb>.ToModelObjectList(CargobodyList),
ModelObjectConvert<Cargomb>.ToModelObjectList(CargodelbodyList),
ModelObjectConvert<Appstatemb>.ToModelObjectList(AppstateBodyList),
ModelObjectConvert<Appstatemb>.ToModelObjectList(AppstateDelBodyList),
ModelObjectConvert<KCmb>.ToModelObjectList(KCBodyList),
ModelObjectConvert<KCmb>.ToModelObjectList(KCDelBodyList),
ModelObjectConvert<DSWeb.Areas.TruckMng.Models.Comm.MsChFee>.ToModelObjectList(chfeeBodyList),
ModelObjectConvert<DSWeb.Areas.TruckMng.Models.Comm.MsChFee>.ToModelObjectList(chfeeBodyDelList)
);
BasicDataRefDAL.SaveLog(head, Session["USERID"].ToString(), "进口贸易_港口操作", "保存");
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'", CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveAmend(string ContractNo, string data,string chfeeBody, string chfeeBodyDel)
{
var head = JsonConvert.Deserialize<MsOpAmend>(data);
var chfeeBodyList = JsonConvert.Deserialize<List<MsChFee>>(chfeeBody);
var chfeeBodyDelList = JsonConvert.Deserialize<List<MsChFee>>(chfeeBodyDel);
//var result = new DBResult();
var ParentID = ContractNo;
if (head.ACCDATE!="")
{
head.ACCDATE = head.ACCDATE.Substring(0, 7);
}
var opstatus = "";
if (head.BSNO == "")
{
head.BSNO = PubSysDAL.GetBillNo("0206");
opstatus = "add";
}
else
{ opstatus = "edit"; }
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<MsChFee>.ToModelObjectList(chfeeBodyList),
ModelObjectConvert<MsChFee>.ToModelObjectList(chfeeBodyDelList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ""
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SetPrice ( string _price, string _price_agio, string _price_limit, string _weight, string _BoxCount
, string _Exchangerate, string _Exchangerate_Customs, string _PreProportion
, string CargoBody )
{
var CargobodyList = JsonConvert.Deserialize<List<Cargomb>>(CargoBody);
var result= new DBResult();
foreach (var _c in CargobodyList){
List<Cargomb> list = XXHDAL.GetCargoList("c.id="+_c.cgid);
Cargomb _cargo = list[0];
_cargo.U_weight = Convert.ToString(Convert.ToDecimal(_weight) / Convert.ToDecimal(_cargo.UnitRate));
_cargo.U_PRICE = Convert.ToString(Convert.ToDecimal(_price) * Convert.ToDecimal(_cargo.UnitRate));
Decimal tax_amount =0;
Decimal pay_amount=0;
Decimal amount = 0;
Decimal amount_writeoffs=0;
Decimal Exchangerate = Convert.ToDecimal(_Exchangerate);
Decimal Exchangerate_Customs = Convert.ToDecimal(_Exchangerate_Customs);
Decimal PreProportion = Convert.ToDecimal(_PreProportion);
_cargo.Exchangerate = _Exchangerate;
_cargo.Exchangerate_Customs = _Exchangerate_Customs;
_cargo.PreProportion = _PreProportion;
if (Convert.ToDecimal(_weight) == 0)
_weight = _c.weight;
var price = Convert.ToDecimal(_price);
var price_agio = Convert.ToDecimal(_price_agio);
var price_limit = Convert.ToDecimal(_price_limit);
var baolv = Convert.ToDecimal(_cargo.baolv);
var weight = Convert.ToDecimal(_weight);
var UNIT= _cargo.UnitRef;
if (UNIT!="磅") {
amount=0;
if (price_agio==0){
amount = weight*price ;} //Mul(price_limit,weight,baolv,2)
else {amount = weight*price_agio;} //amount=对国内客户的合同金额
//get_tax_amount 用于向客户收税金的完税价格
//tax_amount 用于向海关交税金的完税价格
if (price_limit != 0 && price_limit > price) {
tax_amount = price_limit*weight*baolv;
if (price_agio!=0 && price_limit>price_agio){//海关限价最高
Decimal get_tax_amount=tax_amount;
}else{Decimal get_tax_amount= price_agio*weight*baolv;}//差价(对国内客户)高于限价
} else {
tax_amount = price*weight*baolv;
if (price_agio!=0 ){
Decimal get_tax_amount=price_agio*weight*baolv;
}else{Decimal get_tax_amount= tax_amount;}//差价(对国内客户)高于限价
}
pay_amount = weight*price;//贸易商价格x重量x单价
_cargo.Amount=Convert.ToString(amount);
_cargo.AMOUNT_WRITEOFFS = Convert.ToString(amount);
_cargo.tax_Amount=Convert.ToString(tax_amount);
_cargo.pay_Amount=Convert.ToString(pay_amount);
}
else{
var U_weight = Convert.ToDecimal(_cargo.U_weight);
var U_PRICE = Convert.ToDecimal(_cargo.U_PRICE);
var UnitRate = Convert.ToDecimal(_cargo.UnitRate);
//var weight = Convert.ToDecimal(_weight);
//var price = Convert.ToDecimal(_cargo.price);
//var price_agio = Convert.ToDecimal(_cargo.price_agio);
//var price_limit = Convert.ToDecimal(_cargo.price_limit);
//var baolv = Convert.ToDecimal(_cargo.baolv);
amount = U_weight*U_PRICE;
amount_writeoffs=weight*price;
UNIT= _cargo.UnitRef;
if ((UNIT=="磅")&&(price_agio==0)) {
if (price_limit != 0 && price_limit > (price)) {
tax_amount = price_limit*weight*baolv;
} else {
tax_amount = U_weight*U_PRICE*baolv;
}
pay_amount = U_weight*U_PRICE;
}else{
if (price_limit != 0 && price_limit > price_agio) {
tax_amount = price_limit*weight*baolv;
} else {
tax_amount = price_agio*weight*baolv;
}
if (price_agio>price)
{
amount = weight*price_agio;
pay_amount = weight*price;
}else{
amount = weight*price;
pay_amount = weight*price;
}
}
_cargo.Amount= Convert.ToString(amount);
_cargo.AMOUNT_WRITEOFFS= Convert.ToString(amount_writeoffs);
_cargo.tax_Amount= Convert.ToString(tax_amount);
_cargo.pay_Amount= Convert.ToString(pay_amount);
amount=Convert.ToDecimal(_cargo.Amount);
tax_amount=Convert.ToDecimal(_cargo.tax_Amount);
pay_amount=Convert.ToDecimal(_cargo.pay_Amount);
}
//if (amount>tax_amount){tax_amount=amount;}//确保tax_amount为给客户显示并使用的完税价格
Decimal tax = Convert.ToDecimal(_cargo.tax);//关税税率
Decimal tax_zz = Convert.ToDecimal(_cargo.tax_zz);//增值税税率
//Exchangerate_Customs = Convert.ToDecimal(_cargo.Exchangerate_Customs);//海关汇率
var HS = _cargo.cicode;
var isChicken = false;
Decimal ChickenTax = 0;
Decimal priceandtax = 0;
Decimal tax_1 = 0;
Decimal tax_zz_1 = 0;
Decimal tax_2 = 0;
Decimal tax_zz_2 = 0;
if (HS == "0207142100" || HS == "0207142200" || HS == "0207142900"|| HS == "02071200") {
isChicken = true;
if (HS == "0207142100") {
ChickenTax = 0.8M;
} else if (HS == "0207142200") {
ChickenTax = 1.0M;
} else if (HS == "0207142900"|| HS == "02071200") {
ChickenTax = 1.3M;
}
}
if (isChicken) {
//Mul(weight,price);
priceandtax = tax_amount*Exchangerate_Customs + weight*ChickenTax;
tax_1 = weight*ChickenTax;
tax_zz_1 = priceandtax*tax_zz;
tax_2 = tax_1;
tax_zz_2 = tax_zz_1;
} else {
priceandtax =tax_amount*(1.0M + tax); //完税价格x(1+关税税率)=含关税价格
//应付的
tax_2 =tax_amount*tax*Exchangerate_Customs; //关税
tax_zz_2 =tax_amount*(1.0M + tax)*tax_zz*Exchangerate_Customs; //decimal(tax_amount * (1.0 + tax) * tax_zz * Exchangerate_Customs,2); //增值税
//向客户收取的
//var weight = Convert.ToDecimal(_cargo.weight);
//var price_agio = Convert.ToDecimal(_cargo.price_agio);
if (price_agio != 0 && price_agio>price_limit){//如果“差价(对国内客户价格)”不为零而且高于限价 关税的完税价格依据差价价格计算
tax_1 = (weight*price_agio*baolv)*tax*Exchangerate_Customs; //应收关税
tax_zz_1 = (weight*price_agio*baolv)*(1.0M + tax)*tax_zz*Exchangerate_Customs;//应收增值税
}else
{
tax_1 = tax_2;
tax_zz_1 = tax_zz_2;
}
}
_cargo.tax_1=Convert.ToString(tax_1);
_cargo.tax_zz_1=Convert.ToString(tax_zz_1);
_cargo.tax_2=Convert.ToString(tax_2);
_cargo.tax_zz_2=Convert.ToString(tax_zz_2);
var prepayments = amount*PreProportion/100;
var balance = amount-prepayments;
_cargo.prepayments = Convert.ToString(prepayments);
_cargo.balance= Convert.ToString(balance);
var pay_prepayments = pay_amount * PreProportion / 100;
var pay_balance = pay_amount - pay_prepayments;
_cargo.pay_prepayments = Convert.ToString(pay_prepayments);
_cargo.pay_balance= Convert.ToString(pay_balance);
var modb = new ModelObjectRepository();
var _cargolist=new List<Cargomb>();
_cargolist.Add(_cargo);
result = modb.SaveComm(
"ContractNo"
, _cargo.ContractNo
, ModelObjectConvert<Cargomb>.ToModelObjectList(_cargolist)
, null);
if (result.Success) {
//生成费用
var FeeList=new List<MsChFee>();
FeeList = MakeFee(_cargo);
var USERID=Session["USERID"].ToString();
var _r = MsChFeeDAL.Audit(0, FeeList, USERID, "True");
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public List<MsChFee> MakeFee(Cargomb _c)
{
if (Convert.ToDecimal(_c.price_agio) == 0) {
_c.price_agio = _c.price;
}
var _count = 0;
var GIDs="";
var field = " (GId,BsNo,FeeStatus,FeeType,FeeName,FeeDescription,CustomerType,CustomerName,Unit,UnitPrice,TaxUnitPrice,Quantity ";
field = field + " ,Amount,NoTaxAmount,Currency,ExChangerate,Reason,Remark,Commissionrate,Settlement,Invoice,OrderAmount,OrderInvoice ";
field = field + " ,Auditoperator,EnterOperator,EnterDate,DebitNo,IsDebit,IsOpen,IsAdvancedpay,IsInvoice,FeeFrt,IsCrmOrderFee,AuditStatus) ";
//应收预付款
if (Convert.ToDecimal(_c.prepayments) > 0)
{
var GID=Guid.NewGuid().ToString();
GIDs="'"+GID+"'";
var _value = " select '" + GID + "',c.ContractNo,0,1,'预付款','','',m.buyer,''," + _c.prepayments + "," + _c.prepayments + ",1";
_value = _value + "," + _c.prepayments + "," + _c.prepayments + ",(select codename from code_currency where gid=c.currid),c.exchangerate,'' ";
_value = _value + ",case (select codename from code_currency where gid=c.currid) when 'RMB' then '' else convert(varchar(50)," + _c.prepayments + ")+(select codename from code_currency where gid=c.currid)+' 汇率'+convert(varchar(50),Exchangerate) end,0,0,0,0,0 ";
_value = _value + ",'','" + Session["USERID"] + "',getdate(),'',0,0,0,0,'PP',0,0 ";
_value = _value + " from Import_Cargo c ";
_value = _value + " left join Import_main m on M.ContractNo=c.ContractNo where c.id= '" + _c.id + "'";
var SQL = " Insert into ch_fee " + field + _value;
_count = ImportSyncDAL.SaveSync(SQL);
}
//应付预付款
if (Convert.ToDecimal(_c.pay_prepayments) > 0)
{
var GID=Guid.NewGuid().ToString();
GIDs=GIDs+",'"+GID+"'";
var _value = " select '" + GID + "',c.ContractNo,0,2,'预付款','','',m.seller,''," + _c.pay_prepayments + "," + _c.pay_prepayments + ",1";
_value = _value + "," + _c.pay_prepayments + "," + _c.pay_prepayments + ",(select codename from code_currency where gid=c.currid),c.exchangerate,'' ";
_value = _value + ",case (select codename from code_currency where gid=c.currid) when 'RMB' then '' else convert(varchar(50)," + _c.prepayments + ")+(select codename from code_currency where gid=c.currid)+' 汇率'+convert(varchar(50),Exchangerate) end,0,0,0,0,0 ";
_value = _value + ",'','" + Session["USERID"] + "',getdate(),'',0,0,0,0,'PP',0,0 ";
_value = _value + " from Import_Cargo c ";
_value = _value + " left join Import_main m on M.ContractNo=c.ContractNo where c.id= '" + _c.id + "'";
var SQL = " Insert into ch_fee " + field + _value;
_count = ImportSyncDAL.SaveSync(SQL);
}
//应收预付款手续费
if (Convert.ToDecimal(_c.prepayments) > 0)
{
var GID=Guid.NewGuid().ToString();
GIDs=GIDs+",'"+GID+"'";
var yfksxf = Convert.ToString(Convert.ToDecimal(_c.prepayments)/1000M);
var _value = " select '" + GID + "',c.ContractNo,0,1,'手续费','','',m.buyer,''," + yfksxf + "," + yfksxf + ",1";
_value = _value + "," + yfksxf + "," + yfksxf + ",(select codename from code_currency where gid=c.currid),c.exchangerate,'' ";
_value = _value + ",'预付款手续费',0,0,0,0,0 ";
_value = _value + ",'','" + Session["USERID"] + "',getdate(),'',0,0,0,0,'PP',0,0 ";
_value = _value + " from Import_Cargo c ";
_value = _value + " left join Import_main m on M.ContractNo=c.ContractNo where c.id= '" + _c.id + "'";
var SQL = " Insert into ch_fee " + field + _value;
_count = ImportSyncDAL.SaveSync(SQL);
}
//应收预付款电汇费
if (Convert.ToDecimal(_c.prepayments) > 0)
{
var GID=Guid.NewGuid().ToString();
GIDs=GIDs+",'"+GID+"'";
var DHF = "150";
var _value = " select '" + GID + "',c.ContractNo,0,1,'电汇费','','',m.buyer,''," + DHF + "," + DHF + ",1";
_value = _value + "," + DHF + "," + DHF + ",'RMB',1,'' ";
_value = _value + ",'预付款电汇费',0,0,0,0,0 ";
_value = _value + ",'','" + Session["USERID"] + "',getdate(),'',0,0,0,0,'PP',0,0 ";
_value = _value + " from Import_Cargo c ";
_value = _value + " left join Import_main m on M.ContractNo=c.ContractNo where c.id= '" + _c.id + "'";
var SQL = " Insert into ch_fee " + field + _value;
_count = ImportSyncDAL.SaveSync(SQL);
}
var FeeList = MsChFeeDAL.GetDataList("GID in(" + GIDs + ")", Session["USERID"].ToString());
return FeeList;
}
#region 参照部分
#endregion
}
}