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/ImportSyncController.cs

558 lines
22 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.Import.Models.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Import.DAL.ImportTrade;
using DSWeb.Areas.Import.Models.ImportTrade;
using DSWeb.Areas.Import.DAL.XXH;
using DSWeb.Areas.Import.Models.XXH;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using DSWeb.Areas.Import.DAL.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.Areas.CommMng.Models;
////应对新的单据管理模块
using DSWeb.MvcShipping.Controllers;
using DSWeb.MvcShipping.DAL.MsOpReceiptDAL;
using DSWeb.MvcShipping.Models.MsOpReceipt;
using DSWeb.MvcShipping.Models.MsOpAmend;
using System.Text;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.Models.MsOpSeaeBill;
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.Areas.RptMng.Comm;
using Microsoft.Office.Interop.Excel;
using DSWeb.MvcShipping.Models.MsOpApply;
using DSWeb.MvcShipping.DAL.MsOpApplyDAL;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class ImportSyncController : Controller
{
//
// GET: /Import/XXH
public ActionResult Index()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = ImportSyncDAL.GetSyncList(condition, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetSync(string ContractNo, string Local_Contractno)
{
var dataList = ImportSyncDAL.GetSync(ContractNo, Local_Contractno);
var list = dataList;
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetSync_Local ( string Local_Contractno )
{
var dataList = ImportSyncDAL.GetSync_Local(Local_Contractno);
var list = dataList;
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetSyncData_Local ( string Local_Contractno )
{
ImportUploadmb head = null;
var list = ImportSyncDAL.GetSync_Local(Local_Contractno);
if (list.Count > 0)
head = list[0];
if (head == null)
{
head = new ImportUploadmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetHTH()
{
var dataList = ImportTradeDAL.GetHTH();
var list = dataList;
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetChFee_Pub ( string BSNO )
{
var dataList = ImportSyncDAL.GetChFee_Pub(BSNO);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetChFee_Local ( string BSNO )
{
var dataList = ImportSyncDAL.GetChFee_Local(BSNO);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetCargoPubList ( string ContractNo )
{
var dataList = ImportSyncDAL.GetCargoList_Pub(ContractNo);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetCargoLocalList ( string ContractNo )
{
var dataList = ImportSyncDAL.GetCargoList_Local(ContractNo);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveSync ( string SQL )
{
var _count = 0;
_count = ImportSyncDAL.SaveSync(SQL);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = _count, data = _count });
return new ContentResult() { Content = json };
}
#region 用于在生成业务的同时分商品生成费用
public ContentResult MakeFee ( string ContractNo )
{
var _count = 0;
var _r = DoMakeFee(ContractNo);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = _count, data = _count });
return new ContentResult() { Content = json };
}
private DBResult DoMakeFee ( string ContractNo )
{
var CargoList = ImportTradeDAL.GetCargoList(" c.ContractNo='" + ContractNo + "' ");
var _import = XXHDAL.GetData_ALL(" M.ContractNo=(select local_contractno from import_main_public where contractno='" + ContractNo + "') ", CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(Request));
var companyname = _import.companyname;
decimal prepayments = 0;
decimal balance = 0;
decimal weight = 0;
var ChfeeList = new List<MsChFee>();
var USERID = Convert.ToString(Session["USERID"]);
var enterdate = DateTime.Now;
foreach (var _C in CargoList)
{
prepayments = prepayments + Convert.ToDecimal(_C.prepayments);
balance = balance + Convert.ToDecimal(_C.balance);
weight = weight + Convert.ToDecimal(_C.weight);
//预付款
if (Convert.ToDecimal(_C.prepayments) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = _C.ContractNo;
data.UnitPrice = Convert.ToDecimal(_C.prepayments);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(_C.prepayments);
//data.NoTaxAmount = Convert.ToDecimal(_C.prepayments);
data.FeeName = "预付款";
var CURRList = BasicDataRefDAL.GetcurrRefList("gid='" + _C.currid + "'");
var CURR = CURRList[0].codename;
data.Currency = CURR;
data.ExChangerate = Convert.ToDecimal(_C.Exchangerate);
data.CARGO_GID = _C.GID;
data.Remark = CURR + _C.prepayments;
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = _C.ContractNo;
data2.UnitPrice = Convert.ToDecimal(_C.prepayments);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(_C.prepayments);
//data.NoTaxAmount = Convert.ToDecimal(_C.prepayments);
data2.FeeName = "预付款";
//var CURRList = BasicDataRefDAL.GetcurrRefList("gid='" + _C.currid + "'");
//var CURR = CURRList[0].codename;
data2.Currency = CURR;
data2.ExChangerate = Convert.ToDecimal(_C.Exchangerate);
data2.CARGO_GID = _C.GID;
data2.Remark = CURR + _C.prepayments;
data2.FeeType = 2;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//尾款
if (Convert.ToDecimal(_C.balance) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = _C.ContractNo;
data.UnitPrice = Convert.ToDecimal(_C.balance);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(_C.balance);
//data.NoTaxAmount = Convert.ToDecimal(_C.balance);
data.FeeName = "尾款";
var CURRList = BasicDataRefDAL.GetcurrRefList("gid='" + _C.currid + "'");
var CURR = CURRList[0].codename;
data.Currency = CURR;
data.ExChangerate = Convert.ToDecimal(_C.Exchangerate);
data.CARGO_GID = _C.GID;
data.Remark = CURR + _C.balance;
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = _C.ContractNo;
data2.UnitPrice = Convert.ToDecimal(_C.balance);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(_C.balance);
//data.NoTaxAmount = Convert.ToDecimal(_C.balance);
data2.FeeName = "尾款";
data2.Currency = CURR;
data2.ExChangerate = Convert.ToDecimal(_C.Exchangerate);
data2.CARGO_GID = _C.GID;
data2.Remark = CURR + _C.balance;
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//关税
if (Convert.ToDecimal(_C.tax_1) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = _C.ContractNo;
data.UnitPrice = Convert.ToDecimal(_C.tax_1);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(_C.tax_1);
data.CARGO_GID = _C.GID;
data.FeeName = "关税";
data.Currency = "RMB";
data.ExChangerate = 1;
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = _C.ContractNo;
data2.UnitPrice = Convert.ToDecimal(_C.tax_1);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(_C.tax_1);
data.CARGO_GID = _C.GID;
data2.FeeName = "关税";
data2.Currency = "RMB";
data2.ExChangerate = 2;
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//增殖税
if (Convert.ToDecimal(_C.tax_zz_1) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = _C.ContractNo;
data.UnitPrice = Convert.ToDecimal(_C.tax_zz_1);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(_C.tax_zz_1);
data.CARGO_GID = _C.GID;
data.FeeName = "增值税";
data.Currency = "RMB";
data.ExChangerate = 1;
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = _C.ContractNo;
data2.UnitPrice = Convert.ToDecimal(_C.tax_zz_1);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(_C.tax_zz_1);
data.CARGO_GID = _C.GID;
data2.FeeName = "增值税";
data2.Currency = "RMB";
data2.ExChangerate = 2;
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
}
//预付款手续费
if (Convert.ToDecimal(prepayments) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = Convert.ToDecimal(prepayments);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(prepayments);
data.FeeName = "手续费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.Remark = "预付款手续费";
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = ContractNo;
data2.UnitPrice = Convert.ToDecimal(prepayments);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(prepayments);
data2.FeeName = "手续费";
data2.Currency = "RMB";
data2.ExChangerate = 1;
data2.CARGO_GID = "";
data2.Remark = "预付款手续费";
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//尾款
if (Convert.ToDecimal(balance) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = Convert.ToDecimal(balance);
data.Quantity = 1;
data.Amount = Convert.ToDecimal(balance);
data.FeeName = "手续费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.Remark = "尾款手续费";
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = ContractNo;
data2.UnitPrice = Convert.ToDecimal(balance);
data2.Quantity = 1;
data2.Amount = Convert.ToDecimal(balance);
data2.FeeName = "手续费";
data2.Currency = "RMB";
data2.ExChangerate = 1;
data2.CARGO_GID = "";
data2.Remark = "尾款手续费";
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//预付款电汇费
if (Convert.ToDecimal(prepayments) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = 150;
data.Quantity = 1;
data.Amount = 150;
data.FeeName = "电汇费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.Remark = "预付款电汇费";
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = ContractNo;
data2.UnitPrice = 150;
data2.Quantity = 1;
data2.Amount = 150;
data2.FeeName = "电汇费";
data2.Currency = "RMB";
data2.ExChangerate = 1;
data2.CARGO_GID = "";
data2.Remark = "预付款电汇费";
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
//尾款
if (Convert.ToDecimal(balance) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = 150;
data.Quantity = 1;
data.Amount = 150;
data.FeeName = "电汇费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.Remark = "尾款电汇费";
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
var data2 = new MsChFee();
data2.GId = Guid.NewGuid().ToString();
data2.BsNo = ContractNo;
data2.UnitPrice = 150;
data2.Quantity = 1;
data2.Amount = 150;
data2.FeeName = "电汇费";
data2.Currency = "RMB";
data2.ExChangerate = 1;
data2.CARGO_GID = "";
data2.Remark = "尾款电汇费";
data2.FeeType = 2;
data2.EnteroPerator = USERID;
data2.EnterDate = DateTime.Now;
ChfeeList.Add(data2);
}
if (Convert.ToDecimal(weight) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = 350;
data.Quantity = weight;
data.Amount = 350 * weight;
data.FeeName = "代理费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.FeeType = 2;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
}
if (Convert.ToDecimal(weight) > 0)
{
var data = new MsChFee();
data.GId = Guid.NewGuid().ToString();
data.BsNo = ContractNo;
data.UnitPrice = 400;
data.Quantity = weight;
data.Amount = 400 * weight;
data.FeeName = "代理费";
data.Currency = "RMB";
data.ExChangerate = 1;
data.CARGO_GID = "";
data.FeeType = 1;
data.EnteroPerator = USERID;
data.EnterDate = DateTime.Now;
ChfeeList.Add(data);
}
foreach (var _d in ChfeeList)
{
_d.FeeStatus = 1;
_d.DbOperationType = DbOperationType.DbotIns;
}
var modb = new ModelObjectRepository();
var result = modb.SaveHead(
ModelObjectConvert<MsChFee>.ToModelObjectList(ChfeeList)
);
return result;
}
#endregion
#region 参照部分
#endregion
#region 根据BSNO判断是否已存在费用
public ContentResult CheckHasFeeWithBSNO ( string bsno )
{
bool rst = ImportSyncDAL.CheckHasFeeWithBSNO(bsno);
var json = JsonConvert.Serialize(new { Success = rst });
return new ContentResult() { Content = json };
}
#endregion
}
}