|
|
using System;
|
|
|
using System.Data;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using System.Collections;
|
|
|
using DSWeb.MvcShipping.Models.RptWmsSettleListEntity;
|
|
|
using DSWeb.MvcShipping.Models.RptWmsSettleListViewEntity;
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
using DSWeb.EntityDA;
|
|
|
using HcUtility.Comm;
|
|
|
using System.Data.SqlClient;
|
|
|
using HcUtility.Core;
|
|
|
using DSWeb.DataAccess;
|
|
|
using DSWeb.Models;
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
|
|
|
using DSWeb.MvcShipping.Models.WMSRate;
|
|
|
using Quartz.Util;
|
|
|
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.RptWmsSettleDAL
|
|
|
{
|
|
|
public class RptWmsSettleDAL
|
|
|
{
|
|
|
#region Inquery 主表 wms_settle_list
|
|
|
static public List<RptWmsSettleListEntity> GetDataList(string strCondition, string strUserID, string strCompanyID, string usercode, string orgcode, string sort = null)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT GID,(case when ISLOCK=1 then '是' else '' end) as ISLOCK,DUINO,CUSTOMERNAME,CONVERT(char(10), STARTBILLINGDATE, 20) as STARTBILLINGDATE,CONVERT(char(10), ENDBILLINGDATE, 20) as ENDBILLINGDATE,REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,(select top 1 SHOWNAME from [user] where gid=wms_settle_list.CREATEUSER) as CREATEUSER_NAME,(select top 1 SHOWNAME from [user] where gid=wms_settle_list.MAKEOUTUSER) as MAKEOUTUSER_NAME,(select count(distinct BLNO)from wms_settle_detail where duigid=wms_settle_list.GID ) YWCOUNT, (SELECT sum(outfee) from wms_settle_detail where duigid = wms_settle_list.GID)AMOUNT,dbo.[F_WMSSettle_AmountStr](GID) YWSTR from wms_settle_list where CORPID='" + strCompanyID + "' and ISDELETE=0");//CREATEUSER='" + strUserID + "' and
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
//
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else {
|
|
|
strSql.Append(" order by DUINO desc,CREATETIME desc");
|
|
|
}
|
|
|
return SetData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<RptWmsSettleListEntity> SetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<RptWmsSettleListEntity>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
RptWmsSettleListEntity data = new RptWmsSettleListEntity();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);//惟一编号
|
|
|
data.ISLOCK = Convert.ToString(reader["ISLOCK"]);//是否对账
|
|
|
data.DUINO = Convert.ToString(reader["DUINO"]);//对账编号
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);//对账客户
|
|
|
data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]);//开始计费日期
|
|
|
data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]);//结束计费日期
|
|
|
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
|
|
|
data.MAKEOUTUSER = Convert.ToString(reader["MAKEOUTUSER_NAME"]);//重新生成人
|
|
|
if (reader["MAKEOUTTIME"] != DBNull.Value)
|
|
|
data.MAKEOUTTIME = Convert.ToDateTime(reader["MAKEOUTTIME"]);//重新生成时间
|
|
|
|
|
|
data.YWCOUNT = Convert.ToDecimal(reader["YWCOUNT"]);//
|
|
|
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);//
|
|
|
data.YWSTR = Convert.ToString(reader["YWSTR"]);//
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Inquery 仓储结算清单明细临时表([wms_settlement_detail_temp])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<RptWmsSettleDetailEntity> SetFeeData(String strSql)
|
|
|
{
|
|
|
var headList = new List<RptWmsSettleDetailEntity>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
RptWmsSettleDetailEntity data = new RptWmsSettleDetailEntity();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.DUIGID = Convert.ToString(reader["DUIGID"]);
|
|
|
data.DUINO = Convert.ToString(reader["DUINO"]);
|
|
|
data.BLNO = Convert.ToString(reader["BLNO"]);
|
|
|
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
|
|
|
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
|
|
|
data.OUTFEE = Convert.ToDecimal(reader["OUTFEE"]);
|
|
|
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 仓储结算清单计算
|
|
|
|
|
|
private static int CompareDate(string value1, string value2)
|
|
|
{
|
|
|
//将日期字符串转换为日期对象
|
|
|
DateTime t1 = Convert.ToDateTime(value1);
|
|
|
DateTime t2 = Convert.ToDateTime(value2);
|
|
|
//通过DateTIme.Compare()进行比较()
|
|
|
int compNum = DateTime.Compare(t1, t2);
|
|
|
return compNum;
|
|
|
|
|
|
}
|
|
|
|
|
|
private static int DateDiff(string strStart, string strEnd)
|
|
|
{
|
|
|
DateTime dateStart = Convert.ToDateTime(strStart);
|
|
|
DateTime dateEnd = Convert.ToDateTime(strEnd);
|
|
|
DateTime start = Convert.ToDateTime(dateStart.ToShortDateString());
|
|
|
DateTime end = Convert.ToDateTime(dateEnd.ToShortDateString());
|
|
|
TimeSpan sp = end.Subtract(start);
|
|
|
return sp.Days + 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 计算仓储费
|
|
|
/// <summary>
|
|
|
/// 计算仓储费
|
|
|
/// </summary>
|
|
|
/// <param name="sqlTran">事务</param>
|
|
|
/// <param name="strSTARTBILLINGDATE">开始计费日期</param>
|
|
|
/// <param name="strOLDCUSTFEEDATE">上家承担仓储期限</param>
|
|
|
/// <param name="strINBSNO">出库明细关联的入库单wms或wms_in的BSNO</param>
|
|
|
/// <param name="strCUSTOMERNAME">出库主表的客户名称</param>
|
|
|
/// <param name="outnums">出库量</param>
|
|
|
/// <param name="strASSOCIATEDNO">关联wms_out_detail的GID</param>
|
|
|
/// <param name="strFEETYPE">区别费用收、付类型</param>
|
|
|
/// <param name="strUserID">登陆用户GID</param>
|
|
|
/// <param name="strShowName">登陆用户名</param>
|
|
|
/// <param name="sBillno">出库单号或其他单据号</param>
|
|
|
/// <param name="ck_jsfee">是否计算仓储费</param>
|
|
|
/// <param name="ck_jsfee">是否库存</param>
|
|
|
/// <returns></returns>
|
|
|
public static String getWmsRate(string strSTARTBILLINGDATE, string strOLDCUSTFEEDATE, string strINBSNO, string strCUSTOMERNAME, Decimal outnums, string strASSOCIATEDNO, int strFEETYPE, string strUserID, string strShowName, string sBillno, string sOUTGID, bool ck_jsfee, bool isKuCun)
|
|
|
{
|
|
|
string sR = "";
|
|
|
//int iState = 0;
|
|
|
int result = 0;
|
|
|
string Sqlstr = "";
|
|
|
|
|
|
#region 计算仓储费
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
WmsOutDetailDA WmsOutDetailDA = new EntityDA.WmsOutDetailDA();
|
|
|
IList<WmsRateDetail> tempWmsRateDetailDetailEntities = new List<WmsRateDetail>();
|
|
|
int totalfeedays = 0;//总计费区间仓储天数
|
|
|
int feedays = 0;//区间仓储数
|
|
|
int prescale = 0;//总计费区间仓储数
|
|
|
int feeMonth = 0;//区间仓储月数
|
|
|
Decimal sumfee = 0;//总仓储费
|
|
|
string strSTARTBILLINGDATE2 = strSTARTBILLINGDATE;//按区间计费的开始计费日期
|
|
|
|
|
|
#region 删除费率出库明细表的区间仓储费
|
|
|
Sqlstr = "delete from wms_settle_detail_rate where ASSOCIATEDNO = '" + strASSOCIATEDNO.Trim() + "' and FEETYPE=" + strFEETYPE;
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(Sqlstr);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -9;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
if (ck_jsfee)//是否计算仓储费
|
|
|
{
|
|
|
#region 如果入库有免仓储期,则出库时插入费率出库明细表
|
|
|
//按仓储费率计算仓储费
|
|
|
Sqlstr = "SELECT top 1 * FROM wms where GID='" + strINBSNO + "' or gid in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')";
|
|
|
//DataSet dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
DataSet dsrate = T_ALL_DA.GetAllSQL(Sqlstr);
|
|
|
if (dsrate != null)
|
|
|
{
|
|
|
if (dsrate.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
string sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIOD"].ToString().Trim();
|
|
|
if (strFEETYPE == 2)
|
|
|
{
|
|
|
sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIODAP"].ToString().Trim();
|
|
|
}
|
|
|
if (sAP != "0")
|
|
|
{
|
|
|
WmsRateDetail model3 = new WmsRateDetail();
|
|
|
model3.FEEPRICE = 0;
|
|
|
model3.GOODSPFSL = outnums;
|
|
|
model3.OUTFEE = 0;
|
|
|
model3.FEEUNIT = dsrate.Tables[0].Rows[0]["CHARGEUNIT"].ToString().Trim() + "天";
|
|
|
model3.STARTBILLINGDATE = DateTime.Parse(dsrate.Tables[0].Rows[0]["WMSDATE"].ToString().Trim());
|
|
|
DateTime dt = DateTime.Parse(dsrate.Tables[0].Rows[0]["STARTBILLINGDATE"].ToString().Trim()).AddDays(-1);
|
|
|
if (strFEETYPE == 2)
|
|
|
dt = DateTime.Parse(dsrate.Tables[0].Rows[0]["STARTBILLINGDATEAP"].ToString().Trim()).AddDays(-1);
|
|
|
if (DateTime.Parse(strOLDCUSTFEEDATE) < dt)
|
|
|
{
|
|
|
dt = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
model3.ENDBILLINGDATE = dt;
|
|
|
model3.FEESCALE = int.Parse(GetDaysCount("day", model3.STARTBILLINGDATE.ToString().Trim(), dt.ToString().Trim()).ToString());
|
|
|
model3.FEEGRADE = 0;
|
|
|
model3.REMARK = "";
|
|
|
model3.CREATEUSER = strUserID;
|
|
|
model3.MODIFIEDUSER = strUserID;
|
|
|
model3.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model3.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model3.FEETYPE = strFEETYPE;
|
|
|
model3.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model3);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
feedays = GetDaysCount("day", strSTARTBILLINGDATE, strOLDCUSTFEEDATE.Trim());//WmsOutEntity.DODATE.ToString() 出库-开始计费日期+1
|
|
|
if (feedays > 0)
|
|
|
{
|
|
|
totalfeedays = feedays;
|
|
|
//按仓储费率计算仓储费
|
|
|
Sqlstr = "SELECT GID,FEEGRADE,FEETYPE,FEESCALE,FEEPRICE,ADDPRICE,FEEUNIT,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,REMARK,CREATEUSER,CREATETIME,BSNO,CAPPRICE FROM wms_rate where (BSNO='" + strINBSNO + "' or BSNO in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')) and FEETYPE=" + strFEETYPE + " order by FEEGRADE ";
|
|
|
//dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
dsrate = T_ALL_DA.GetAllSQL(Sqlstr);
|
|
|
if (dsrate != null)
|
|
|
{
|
|
|
if (dsrate.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
int nowscale = 0;//区间计费区间(仓储月数/天数)
|
|
|
Decimal price = 0;//计费单价
|
|
|
Decimal gradefee = 0;//区间仓储费
|
|
|
int nowgrade = 1;
|
|
|
|
|
|
for (int i = 0; i < dsrate.Tables[0].Rows.Count; i++)
|
|
|
{
|
|
|
if (isKuCun)
|
|
|
{
|
|
|
if (DateTime.Parse(strSTARTBILLINGDATE) > DateTime.Parse(dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString()))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
WmsRateDetail model = new WmsRateDetail();
|
|
|
//nowgrade = int.Parse(dsrate.Tables[0].Rows[i]["FEEGRADE"].ToString());//计费等级
|
|
|
nowscale = int.Parse(dsrate.Tables[0].Rows[i]["FEESCALE"].ToString());//计费区间
|
|
|
price = Decimal.Parse(dsrate.Tables[0].Rows[i]["FEEPRICE"].ToString());//计费单价
|
|
|
Decimal ADDPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["ADDPRICE"].ToString());//增值价
|
|
|
Decimal CAPPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["CAPPRICE"].ToString());//
|
|
|
string FEEUNIT = dsrate.Tables[0].Rows[i]["FEEUNIT"].ToString();//计费单位
|
|
|
string ENDBILLINGDATE = dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString();//结束计费日期
|
|
|
//计算区间是按天或按月
|
|
|
string DorM = "day";
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
DorM = "month";
|
|
|
}
|
|
|
#region 按区间计算仓储费
|
|
|
feedays = GetDaysCount(DorM, strSTARTBILLINGDATE2, strOLDCUSTFEEDATE.Trim());//总仓储月数
|
|
|
if (feedays > nowscale) //总仓储月数 > 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
feeMonth = GetDaysCount(DorM, strSTARTBILLINGDATE2, ENDBILLINGDATE.Trim());//i区间仓储月数
|
|
|
if (feeMonth > nowscale)//i区间仓储月数 > 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
int sjMonth = 0;//实际仓储月数
|
|
|
int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数
|
|
|
if (feedays > feeMonth)//总仓储月数 > i区间仓储月数
|
|
|
{
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
if (ADDPRICE <= 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
//sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feedays;//实际仓储月数,如果是最后一条的判断数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
//
|
|
|
#region 增值价>0,则求增值费率
|
|
|
if (ADDPRICE > 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
//int idiv = (int)(sjMonth / nowscale);
|
|
|
//int imod = (int)(sjMonth % nowscale);
|
|
|
int idiv = (int)(sjMonth2 / nowscale);
|
|
|
int imod = (int)(sjMonth2 % nowscale);
|
|
|
Decimal dprice = price;//计费单价
|
|
|
for (int j = 0; j < idiv; j++)//循环求增值费率
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE
|
|
|
{
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE
|
|
|
}
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//nowscale;//累计天数
|
|
|
//
|
|
|
WmsRateDetail model1 = new WmsRateDetail();
|
|
|
model1.FEEPRICE = dprice;
|
|
|
model1.GOODSPFSL = outnums;
|
|
|
model1.FEESCALE = dtDays;// nowscale;
|
|
|
model1.OUTFEE = gradefee;
|
|
|
model1.FEEUNIT = FEEUNIT2;
|
|
|
model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model1.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
// model1.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model1.FEEGRADE = nowgrade;
|
|
|
model1.REMARK = "";
|
|
|
model1.CREATEUSER = strUserID;
|
|
|
model1.MODIFIEDUSER = strUserID;
|
|
|
model1.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model1.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model1.FEETYPE = strFEETYPE;
|
|
|
model1.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model1);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
if (CAPPRICE != 0)
|
|
|
{
|
|
|
if (dprice < CAPPRICE)
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice = CAPPRICE;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
//
|
|
|
if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1);
|
|
|
int dtDays = imod;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE
|
|
|
{
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE
|
|
|
}
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
//dprice += ADDPRICE;
|
|
|
gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//imod;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = dprice;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//imod;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
// model.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;// sjMonth;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//sjMonth;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//sjMonth;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
#endregion
|
|
|
//结束费率区间的循环
|
|
|
if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
}
|
|
|
else//i区间仓储月数 <= 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
int sjMonth = 0;//实际仓储月数
|
|
|
int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数
|
|
|
if (feedays > feeMonth)//总仓储月数 > i区间仓储月数
|
|
|
{
|
|
|
sjMonth = feeMonth;//实际仓储月数
|
|
|
sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
if (ADDPRICE <= 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
sjMonth = feedays;// (feedays - nowscale);//实际仓储月数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数,如果是最后一条的判断数
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
//sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feedays;//实际仓储月数,如果是最后一条的判断数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
//
|
|
|
#region 增值价>0,则求增值费率
|
|
|
if (ADDPRICE > 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
//int idiv = (int)(sjMonth / nowscale);
|
|
|
//int imod = (int)(sjMonth % nowscale);
|
|
|
int idiv = (int)(sjMonth2 / nowscale);
|
|
|
int imod = (int)(sjMonth2 % nowscale);
|
|
|
Decimal dprice = price;//计费单价
|
|
|
for (int j = 0; j < idiv; j++)//循环求增值费率
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//nowscale;//累计天数
|
|
|
//
|
|
|
WmsRateDetail model1 = new WmsRateDetail();
|
|
|
model1.FEEPRICE = dprice;
|
|
|
model1.GOODSPFSL = outnums;
|
|
|
model1.FEESCALE = dtDays;//nowscale;
|
|
|
model1.OUTFEE = gradefee;
|
|
|
model1.FEEUNIT = FEEUNIT2;
|
|
|
model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model1.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
// model1.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model1.FEEGRADE = nowgrade;
|
|
|
model1.REMARK = "";
|
|
|
model1.CREATEUSER = strUserID;
|
|
|
model1.MODIFIEDUSER = strUserID;
|
|
|
model1.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model1.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model1.FEETYPE = strFEETYPE;
|
|
|
model1.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model1);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
if (CAPPRICE != 0)
|
|
|
{
|
|
|
if (dprice < CAPPRICE)
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice = CAPPRICE;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
//
|
|
|
if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1);
|
|
|
int dtDays = imod;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
//dprice += ADDPRICE;
|
|
|
gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//imod;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = dprice;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//imod;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
// model.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
int dtDays = sjMonth;//nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;//sjMonth;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//sjMonth;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//sjMonth;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
#endregion
|
|
|
//结束费率区间的循环
|
|
|
if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
int dtDays = feedays;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;//feedays;//出库量*计费单价*仓储区间(//仓储天数-上一个计费区间(0))
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//feedays;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//feedays;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(strOLDCUSTFEEDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//仓储费率没有设定
|
|
|
//sqlTran.Rollback();
|
|
|
//result = -2;
|
|
|
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
|
|
|
//Clearh();
|
|
|
//return result;
|
|
|
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
//
|
|
|
|
|
|
#region 按区间计算仓储费,插入费率出库明细表
|
|
|
if (tempWmsRateDetailDetailEntities != null)//是否有要入库的仓储费
|
|
|
{
|
|
|
if (tempWmsRateDetailDetailEntities.Count > 0)
|
|
|
{
|
|
|
foreach (WmsRateDetail model2 in tempWmsRateDetailDetailEntities)
|
|
|
{
|
|
|
Sqlstr = String.Format("insert into wms_settle_detail_rate(GID,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER,WMSOUTGID)"
|
|
|
+ " values(newid(),'{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
|
|
|
, model2.FEEPRICE, model2.GOODSPFSL, model2.OUTFEE, model2.REMARK, model2.CREATEUSER, model2.ASSOCIATEDNO, model2.CUSTOMERNAME, model2.FEETYPE, model2.FEEGRADE, model2.STARTBILLINGDATE, model2.ENDBILLINGDATE, model2.FEESCALE, model2.FEEUNIT, model2.MODIFIEDUSER, model2.WMSOUTGID);
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
//if (iState != 1)
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(Sqlstr);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -1;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
//
|
|
|
string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('添加出库明细的费率明细信息','INSERT 插入操作','" + strShowName + " 添加 费率明细信息 出库单号:" + sBillno.Trim() + " ','" + model2.MODIFIEDUSER.ToString() + "')";
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, str0, null);
|
|
|
//if (iState != 1)
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(str0);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -1;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tempWmsRateDetailDetailEntities = null;
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
#endregion
|
|
|
sR = sumfee.ToString() + "," + totalfeedays.ToString();
|
|
|
return sR;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 仓储费临时表--指定时间段内仓储费
|
|
|
|
|
|
public static String getWMSRateInternal(string strSTARTBILLINGDATE, string strENDBILLINGDATE, string strINBSNO,
|
|
|
string strCUSTOMERNAME, Decimal outnums, string strASSOCIATEDNO, int strFEETYPE, string strUserID,
|
|
|
string strShowName, string sBillno, string sOUTGID, bool ck_jsfee, bool isKuCun)
|
|
|
{
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
string sR = "";
|
|
|
|
|
|
|
|
|
int feedays = 0;//区间仓储数
|
|
|
|
|
|
Decimal sumfee = 0;//总仓储费
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{//根据出库GID查询出库费用,有多少出库明细就产生多少出库费用
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from wms_settle_detail_rate_detail_tmp ");
|
|
|
strSql.Append(" where ASSOCIATEDNO = '"+ strASSOCIATEDNO + "' AND FEETYPE = '"+strFEETYPE+"' ");
|
|
|
strSql.Append(" order by FEEGRADE desc ");
|
|
|
|
|
|
|
|
|
|
|
|
List<WmsRateDetail> wmsRateList = new List<WmsRateDetail>();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
|
|
|
int existVal = 0;
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
|
|
|
|
|
|
string strStart = reader["STARTBILLINGDATE"].ToString();
|
|
|
string strEnd = reader["ENDBILLINGDATE"].ToString();
|
|
|
|
|
|
#region 公共信息
|
|
|
|
|
|
WmsRateDetail wmsRateDetail = new WmsRateDetail();
|
|
|
wmsRateDetail.GID = reader["GID"].ToString();
|
|
|
wmsRateDetail.FEEPRICE = Convert.ToDecimal(reader["FEEPRICE"].ToString());
|
|
|
wmsRateDetail.GOODSPFSL = Convert.ToDecimal(reader["GOODSPFSL"].ToString());
|
|
|
|
|
|
wmsRateDetail.OUTFEE = Convert.ToDecimal(reader["OUTFEE"].ToString());
|
|
|
wmsRateDetail.REMARK = reader["REMARK"].ToString();
|
|
|
wmsRateDetail.CREATEUSER = reader["CREATEUSER"].ToString();
|
|
|
|
|
|
wmsRateDetail.CREATETIME = Convert.ToDateTime(reader["CREATETIME"].ToString());
|
|
|
wmsRateDetail.ASSOCIATEDNO = reader["ASSOCIATEDNO"].ToString();
|
|
|
wmsRateDetail.CUSTOMERNAME = reader["CUSTOMERNAME"].ToString();
|
|
|
|
|
|
wmsRateDetail.FEETYPE = Convert.ToInt16(reader["FEETYPE"].ToString());
|
|
|
wmsRateDetail.FEEGRADE = Convert.ToInt16(reader["FEEGRADE"].ToString());
|
|
|
wmsRateDetail.STARTBILLINGDATE = Convert.ToDateTime(reader["STARTBILLINGDATE"].ToString());
|
|
|
|
|
|
|
|
|
wmsRateDetail.ENDBILLINGDATE = Convert.ToDateTime(reader["ENDBILLINGDATE"].ToString());
|
|
|
wmsRateDetail.FEESCALE = Convert.ToInt16(reader["FEESCALE"].ToString());
|
|
|
wmsRateDetail.FEEUNIT = reader["FEEUNIT"].ToString();
|
|
|
|
|
|
wmsRateDetail.MODIFIEDUSER = reader["MODIFIEDUSER"].ToString();
|
|
|
wmsRateDetail.WMSOUTGID = reader["WMSOUTGID"].ToString();
|
|
|
|
|
|
#endregion
|
|
|
if (CompareDate(strSTARTBILLINGDATE,strEnd) > 0)
|
|
|
{
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
else if ((CompareDate(strSTARTBILLINGDATE, strEnd) <= 0) &&
|
|
|
(CompareDate(strSTARTBILLINGDATE, strStart) >= 0))
|
|
|
{
|
|
|
//重新计算
|
|
|
wmsRateDetail.STARTBILLINGDATE = Convert.ToDateTime(strSTARTBILLINGDATE);
|
|
|
wmsRateDetail.FEESCALE = int.Parse(GetDaysCount("day", strSTARTBILLINGDATE.ToString().Trim(), reader["ENDBILLINGDATE"].ToString().Trim()).ToString());
|
|
|
// wmsRateDetail.FEESCALE = DateDiff(strStart.ToString().Trim(),
|
|
|
// reader["ENDBILLINGDATE"].ToString().Trim());
|
|
|
wmsRateDetail.OUTFEE =
|
|
|
wmsRateDetail.FEESCALE * wmsRateDetail.GOODSPFSL * wmsRateDetail.FEEPRICE;
|
|
|
}
|
|
|
else if ((CompareDate(strSTARTBILLINGDATE, strEnd) <= 0) &&
|
|
|
(CompareDate(strSTARTBILLINGDATE, strStart) <= 0))
|
|
|
{
|
|
|
wmsRateDetail.FEESCALE = int.Parse(GetDaysCount("day", strStart.ToString().Trim(), strEnd.ToString().Trim()).ToString());
|
|
|
//wmsRateDetail.FEESCALE = DateDiff(reader["STARTBILLINGDATE"].ToString().Trim(),
|
|
|
// reader["ENDBILLINGDATE"].ToString().Trim());
|
|
|
wmsRateDetail.OUTFEE =
|
|
|
wmsRateDetail.FEESCALE * wmsRateDetail.GOODSPFSL * wmsRateDetail.FEEPRICE;
|
|
|
|
|
|
}
|
|
|
|
|
|
wmsRateList.Add(wmsRateDetail);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
#region 清除 wms_settle_detail_tmp数据
|
|
|
StringBuilder strDelTmp = new StringBuilder();
|
|
|
strDelTmp.Append("delete from wms_settle_detail_rate_detail_tmp");
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strDelTmp.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 插入wms_rate_detail
|
|
|
|
|
|
foreach (var settle in wmsRateList)
|
|
|
{
|
|
|
StringBuilder strAdd = new StringBuilder();
|
|
|
|
|
|
sumfee += settle.OUTFEE;
|
|
|
feedays += settle.FEESCALE;
|
|
|
|
|
|
strAdd.Append(@"insert into wms_settle_detail_rate(GID,FEEPRICE,GOODSPFSL,OUTFEE,");
|
|
|
strAdd.Append(@"REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,");
|
|
|
strAdd.Append(@"FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER,WMSOUTGID)");
|
|
|
|
|
|
|
|
|
strAdd.Append(@" VALUES(");
|
|
|
strAdd.Append("'" + settle.GID + "',");
|
|
|
strAdd.Append("'" + settle.FEEPRICE + "',");
|
|
|
strAdd.Append("'" + settle.GOODSPFSL + "',");
|
|
|
strAdd.Append("'" + settle.OUTFEE + "',");
|
|
|
strAdd.Append("'" + settle.REMARK + "',");
|
|
|
strAdd.Append("'" + settle.CREATEUSER + "',");
|
|
|
strAdd.Append("'" + settle.CREATETIME + "',");
|
|
|
strAdd.Append("'" + settle.ASSOCIATEDNO + "',");
|
|
|
strAdd.Append("'" + settle.CUSTOMERNAME + "',");
|
|
|
strAdd.Append("'" + settle.FEETYPE + "',");
|
|
|
strAdd.Append("'" + settle.FEEGRADE + "',");
|
|
|
strAdd.Append("'" + settle.STARTBILLINGDATE + "',");
|
|
|
strAdd.Append("'" + settle.ENDBILLINGDATE + "',");
|
|
|
strAdd.Append("'" + settle.FEESCALE + "',");
|
|
|
strAdd.Append("'" + settle.FEEUNIT + "',");
|
|
|
strAdd.Append("'" + settle.MODIFIEDUSER + "',");
|
|
|
strAdd.Append("'" + settle.WMSOUTGID + "'");
|
|
|
strAdd.Append(")");
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strAdd.ToString(), null);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
|
|
|
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
|
|
|
sqlTran.Rollback();
|
|
|
|
|
|
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
sR = sumfee.ToString() + "," + feedays.ToString();
|
|
|
return sR;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 复制出库单中的出库费用到仓储对账表的费用
|
|
|
public static DBResult copyWmsRate(string SettleDetailGID,string WMSOUTGID,int FeeType)
|
|
|
{
|
|
|
|
|
|
DBResult result = new DBResult();
|
|
|
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
|
|
|
StringBuilder strAdd = new StringBuilder();
|
|
|
strAdd.Append(@"insert into wms_settle_detail_rate(GID,FEEPRICE,GOODSPFSL,OUTFEE,");
|
|
|
strAdd.Append(@"REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,");
|
|
|
strAdd.Append(@"FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER,WMSOUTGID)");
|
|
|
|
|
|
|
|
|
|
|
|
strAdd.Append(@" select ");
|
|
|
strAdd.Append("GID,");
|
|
|
strAdd.Append("FEEPRICE,");
|
|
|
strAdd.Append("GOODSPFSL,");
|
|
|
strAdd.Append("OUTFEE,");
|
|
|
strAdd.Append("REMARK,");
|
|
|
strAdd.Append("CREATEUSER,");
|
|
|
strAdd.Append("CREATETIME,");
|
|
|
strAdd.Append("'" + SettleDetailGID + "',");
|
|
|
strAdd.Append("CUSTOMERNAME,");
|
|
|
strAdd.Append("FEETYPE,");
|
|
|
strAdd.Append("FEEGRADE,");
|
|
|
strAdd.Append("STARTBILLINGDATE,");
|
|
|
strAdd.Append("ENDBILLINGDATE ,");
|
|
|
strAdd.Append("FEESCALE ,");
|
|
|
strAdd.Append("FEEUNIT ,");
|
|
|
strAdd.Append("MODIFIEDUSER,");
|
|
|
strAdd.Append("WMSOUTGID ");
|
|
|
|
|
|
strAdd.Append(" from wms_rate_detail where WMSOUTGID='" + WMSOUTGID + "' and FEETYPE='" + FeeType + "'");
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strAdd.ToString(), null);
|
|
|
sqlTran.Commit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "操作出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "操作成功!";
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 计算仓储费--临时表
|
|
|
/// <summary>
|
|
|
/// 计算仓储费
|
|
|
/// </summary>
|
|
|
/// <param name="sqlTran">事务</param>
|
|
|
/// <param name="strSTARTBILLINGDATE">开始计费日期</param>
|
|
|
/// <param name="strOLDCUSTFEEDATE">上家承担仓储期限</param>
|
|
|
/// <param name="strINBSNO">出库明细关联的入库单wms或wms_in的BSNO</param>
|
|
|
/// <param name="strCUSTOMERNAME">出库主表的客户名称</param>
|
|
|
/// <param name="outnums">出库量</param>
|
|
|
/// <param name="strASSOCIATEDNO">关联wms_out_detail的GID</param>
|
|
|
/// <param name="strFEETYPE">区别费用收、付类型</param>
|
|
|
/// <param name="strUserID">登陆用户GID</param>
|
|
|
/// <param name="strShowName">登陆用户名</param>
|
|
|
/// <param name="sBillno">出库单号或其他单据号</param>
|
|
|
/// <param name="ck_jsfee">是否计算仓储费</param>
|
|
|
/// <param name="ck_jsfee">是否库存</param>
|
|
|
/// <returns></returns>
|
|
|
public static String getWmsRateTmp(string strSTARTBILLINGDATE, string strOLDCUSTFEEDATE, string strINBSNO, string strCUSTOMERNAME, Decimal outnums, string strASSOCIATEDNO, int strFEETYPE, string strUserID, string strShowName, string sBillno, string sOUTGID, bool ck_jsfee, bool isKuCun)
|
|
|
{
|
|
|
string sR = "";
|
|
|
//int iState = 0;
|
|
|
int result = 0;
|
|
|
string Sqlstr = "";
|
|
|
|
|
|
#region 计算仓储费
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
WmsOutDetailDA WmsOutDetailDA = new EntityDA.WmsOutDetailDA();
|
|
|
IList<WmsRateDetail> tempWmsRateDetailDetailEntities = new List<WmsRateDetail>();
|
|
|
int totalfeedays = 0;//总计费区间仓储天数
|
|
|
int feedays = 0;//区间仓储数
|
|
|
int prescale = 0;//总计费区间仓储数
|
|
|
int feeMonth = 0;//区间仓储月数
|
|
|
Decimal sumfee = 0;//总仓储费
|
|
|
string strSTARTBILLINGDATE2 = strSTARTBILLINGDATE;//按区间计费的开始计费日期
|
|
|
|
|
|
#region 删除费率出库明细表的区间仓储费
|
|
|
Sqlstr = "delete from wms_settle_detail_rate_detail_tmp where ASSOCIATEDNO = '" + strASSOCIATEDNO.Trim() + "' and FEETYPE=" + strFEETYPE;
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(Sqlstr);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -9;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
if (ck_jsfee)//是否计算仓储费
|
|
|
{
|
|
|
#region 如果入库有免仓储期,则出库时插入费率出库明细表
|
|
|
//按仓储费率计算仓储费
|
|
|
Sqlstr = "SELECT top 1 * FROM wms where GID='" + strINBSNO + "' or gid in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')";
|
|
|
//DataSet dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
DataSet dsrate = T_ALL_DA.GetAllSQL(Sqlstr);
|
|
|
if (dsrate != null)
|
|
|
{
|
|
|
if (dsrate.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
string sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIOD"].ToString().Trim();
|
|
|
if (strFEETYPE == 2)
|
|
|
{
|
|
|
sAP = dsrate.Tables[0].Rows[0]["FREESTORAGEPERIODAP"].ToString().Trim();
|
|
|
}
|
|
|
if (sAP != "0")
|
|
|
{
|
|
|
WmsRateDetail model3 = new WmsRateDetail();
|
|
|
model3.FEEPRICE = 0;
|
|
|
model3.GOODSPFSL = outnums;
|
|
|
model3.OUTFEE = 0;
|
|
|
model3.FEEUNIT = dsrate.Tables[0].Rows[0]["CHARGEUNIT"].ToString().Trim() + "天";
|
|
|
model3.STARTBILLINGDATE = DateTime.Parse(dsrate.Tables[0].Rows[0]["WMSDATE"].ToString().Trim());
|
|
|
DateTime dt = DateTime.Parse(dsrate.Tables[0].Rows[0]["STARTBILLINGDATE"].ToString().Trim()).AddDays(-1);
|
|
|
if (strFEETYPE == 2)
|
|
|
dt = DateTime.Parse(dsrate.Tables[0].Rows[0]["STARTBILLINGDATEAP"].ToString().Trim()).AddDays(-1);
|
|
|
if (DateTime.Parse(strOLDCUSTFEEDATE) < dt)
|
|
|
{
|
|
|
dt = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
model3.ENDBILLINGDATE = dt;
|
|
|
model3.FEESCALE = int.Parse(GetDaysCount("day", model3.STARTBILLINGDATE.ToString().Trim(), dt.ToString().Trim()).ToString());
|
|
|
model3.FEEGRADE = 0;
|
|
|
model3.REMARK = "";
|
|
|
model3.CREATEUSER = strUserID;
|
|
|
model3.MODIFIEDUSER = strUserID;
|
|
|
model3.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model3.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model3.FEETYPE = strFEETYPE;
|
|
|
model3.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model3);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
feedays = GetDaysCount("day", strSTARTBILLINGDATE, strOLDCUSTFEEDATE.Trim());//WmsOutEntity.DODATE.ToString() 出库-开始计费日期+1
|
|
|
if (feedays > 0)
|
|
|
{
|
|
|
totalfeedays = feedays;
|
|
|
//按仓储费率计算仓储费
|
|
|
Sqlstr = "SELECT GID,FEEGRADE,FEETYPE,FEESCALE,FEEPRICE,ADDPRICE,FEEUNIT,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,REMARK,CREATEUSER,CREATETIME,BSNO,CAPPRICE FROM wms_rate where (BSNO='" + strINBSNO + "' or BSNO in (select ASSOCIATEDNO from wms_in where gid='" + strINBSNO + "')) and FEETYPE=" + strFEETYPE + " order by FEEGRADE ";
|
|
|
//dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
dsrate = T_ALL_DA.GetAllSQL(Sqlstr);
|
|
|
if (dsrate != null)
|
|
|
{
|
|
|
if (dsrate.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
int nowscale = 0;//区间计费区间(仓储月数/天数)
|
|
|
Decimal price = 0;//计费单价
|
|
|
Decimal gradefee = 0;//区间仓储费
|
|
|
int nowgrade = 1;
|
|
|
|
|
|
for (int i = 0; i < dsrate.Tables[0].Rows.Count; i++)
|
|
|
{
|
|
|
if (isKuCun)
|
|
|
{
|
|
|
if (DateTime.Parse(strSTARTBILLINGDATE) > DateTime.Parse(dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString()))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
WmsRateDetail model = new WmsRateDetail();
|
|
|
//nowgrade = int.Parse(dsrate.Tables[0].Rows[i]["FEEGRADE"].ToString());//计费等级
|
|
|
nowscale = int.Parse(dsrate.Tables[0].Rows[i]["FEESCALE"].ToString());//计费区间
|
|
|
price = Decimal.Parse(dsrate.Tables[0].Rows[i]["FEEPRICE"].ToString());//计费单价
|
|
|
Decimal ADDPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["ADDPRICE"].ToString());//增值价
|
|
|
Decimal CAPPRICE = Decimal.Parse(dsrate.Tables[0].Rows[i]["CAPPRICE"].ToString());//
|
|
|
string FEEUNIT = dsrate.Tables[0].Rows[i]["FEEUNIT"].ToString();//计费单位
|
|
|
string ENDBILLINGDATE = dsrate.Tables[0].Rows[i]["ENDBILLINGDATE"].ToString();//结束计费日期
|
|
|
//计算区间是按天或按月
|
|
|
string DorM = "day";
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
DorM = "month";
|
|
|
}
|
|
|
#region 按区间计算仓储费
|
|
|
feedays = GetDaysCount(DorM, strSTARTBILLINGDATE2, strOLDCUSTFEEDATE.Trim());//总仓储月数
|
|
|
if (feedays > nowscale) //总仓储月数 > 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
feeMonth = GetDaysCount(DorM, strSTARTBILLINGDATE2, ENDBILLINGDATE.Trim());//i区间仓储月数
|
|
|
if (feeMonth > nowscale)//i区间仓储月数 > 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
int sjMonth = 0;//实际仓储月数
|
|
|
int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数
|
|
|
if (feedays > feeMonth)//总仓储月数 > i区间仓储月数
|
|
|
{
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
if (ADDPRICE <= 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
//sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feedays;//实际仓储月数,如果是最后一条的判断数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
//
|
|
|
#region 增值价>0,则求增值费率
|
|
|
if (ADDPRICE > 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
//int idiv = (int)(sjMonth / nowscale);
|
|
|
//int imod = (int)(sjMonth % nowscale);
|
|
|
int idiv = (int)(sjMonth2 / nowscale);
|
|
|
int imod = (int)(sjMonth2 % nowscale);
|
|
|
Decimal dprice = price;//计费单价
|
|
|
for (int j = 0; j < idiv; j++)//循环求增值费率
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE
|
|
|
{
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE
|
|
|
}
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//nowscale;//累计天数
|
|
|
//
|
|
|
WmsRateDetail model1 = new WmsRateDetail();
|
|
|
model1.FEEPRICE = dprice;
|
|
|
model1.GOODSPFSL = outnums;
|
|
|
model1.FEESCALE = dtDays;// nowscale;
|
|
|
model1.OUTFEE = gradefee;
|
|
|
model1.FEEUNIT = FEEUNIT2;
|
|
|
model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model1.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
// model1.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model1.FEEGRADE = nowgrade;
|
|
|
model1.REMARK = "";
|
|
|
model1.CREATEUSER = strUserID;
|
|
|
model1.MODIFIEDUSER = strUserID;
|
|
|
model1.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model1.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model1.FEETYPE = strFEETYPE;
|
|
|
model1.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model1);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
if (CAPPRICE != 0)
|
|
|
{
|
|
|
if (dprice < CAPPRICE)
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice = CAPPRICE;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
//
|
|
|
if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1);
|
|
|
int dtDays = imod;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(ENDBILLINGDATE))//strOLDCUSTFEEDATE
|
|
|
{
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count && dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);//strOLDCUSTFEEDATE
|
|
|
}
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
//dprice += ADDPRICE;
|
|
|
gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//imod;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = dprice;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//imod;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
// model.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;// sjMonth;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//sjMonth;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//sjMonth;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
#endregion
|
|
|
//结束费率区间的循环
|
|
|
if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
}
|
|
|
else//i区间仓储月数 <= 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
int sjMonth = 0;//实际仓储月数
|
|
|
int sjMonth2 = 0;//实际仓储月数,如果是最后一条的判断数
|
|
|
if (feedays > feeMonth)//总仓储月数 > i区间仓储月数
|
|
|
{
|
|
|
sjMonth = feeMonth;//实际仓储月数
|
|
|
sjMonth2 = feeMonth;//实际仓储月数,如果是最后一条的判断数
|
|
|
if ((i + 1) == dsrate.Tables[0].Rows.Count)//即最后一条时,以后的时间都按最后一条取值
|
|
|
{
|
|
|
if (ADDPRICE <= 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
sjMonth = feedays;// (feedays - nowscale);//实际仓储月数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
sjMonth2 = feedays;// (feedays - nowscale);//实际仓储月数,如果是最后一条的判断数
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
//sjMonth = feedays;//(feedays - nowscale);//实际仓储月数
|
|
|
sjMonth = nowscale;// feeMonth;// (feeMonth - nowscale);//实际仓储月数
|
|
|
sjMonth2 = feedays;//实际仓储月数,如果是最后一条的判断数
|
|
|
ENDBILLINGDATE = strOLDCUSTFEEDATE;
|
|
|
}
|
|
|
//
|
|
|
#region 增值价>0,则求增值费率
|
|
|
if (ADDPRICE > 0)//增值价>0,则求增值费率
|
|
|
{
|
|
|
//int idiv = (int)(sjMonth / nowscale);
|
|
|
//int imod = (int)(sjMonth % nowscale);
|
|
|
int idiv = (int)(sjMonth2 / nowscale);
|
|
|
int imod = (int)(sjMonth2 % nowscale);
|
|
|
Decimal dprice = price;//计费单价
|
|
|
for (int j = 0; j < idiv; j++)//循环求增值费率
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
int dtDays = sjMonth;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * dprice * dtDays;// nowscale;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//nowscale;//累计天数
|
|
|
//
|
|
|
WmsRateDetail model1 = new WmsRateDetail();
|
|
|
model1.FEEPRICE = dprice;
|
|
|
model1.GOODSPFSL = outnums;
|
|
|
model1.FEESCALE = dtDays;//nowscale;
|
|
|
model1.OUTFEE = gradefee;
|
|
|
model1.FEEUNIT = FEEUNIT2;
|
|
|
model1.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model1.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model1.ENDBILLINGDATE = model1.STARTBILLINGDATE.AddDays(nowscale - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model1.STARTBILLINGDATE.AddMonths(nowscale).AddDays(-1);
|
|
|
// model1.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model1.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model1.FEEGRADE = nowgrade;
|
|
|
model1.REMARK = "";
|
|
|
model1.CREATEUSER = strUserID;
|
|
|
model1.MODIFIEDUSER = strUserID;
|
|
|
model1.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model1.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model1.FEETYPE = strFEETYPE;
|
|
|
model1.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model1);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
if (CAPPRICE != 0)
|
|
|
{
|
|
|
if (dprice < CAPPRICE)
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice = CAPPRICE;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dprice += ADDPRICE;
|
|
|
}
|
|
|
strSTARTBILLINGDATE2 = (model1.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
//
|
|
|
if (imod > 0)//增值费率余数大于0,则实际仓储月份等于imod
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddDays(imod - 1);
|
|
|
int dtDays = imod;// nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
dtENDBILLINGDATE = dtSTARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
if (dtENDBILLINGDATE > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
{
|
|
|
dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
}
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
//dprice += ADDPRICE;
|
|
|
gradefee = outnums * dprice * dtDays;// imod;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//imod;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = dprice;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//imod;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = dtENDBILLINGDATE;
|
|
|
//model.ENDBILLINGDATE = model.STARTBILLINGDATE.AddDays(imod - 1);
|
|
|
//if (FEEUNIT.IndexOf("月") > -1)
|
|
|
//{
|
|
|
// DateTime dt = model.STARTBILLINGDATE.AddMonths(imod).AddDays(-1);
|
|
|
// model.ENDBILLINGDATE = dt;
|
|
|
// if (dt > DateTime.Parse(strOLDCUSTFEEDATE))
|
|
|
// {
|
|
|
// model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
// }
|
|
|
//}
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (model.ENDBILLINGDATE.AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
int dtDays = sjMonth;//nowscale;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;//sjMonth;//出库量*计费单价*实际仓储月数
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//sjMonth;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//sjMonth;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(ENDBILLINGDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(ENDBILLINGDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
}
|
|
|
#endregion
|
|
|
//结束费率区间的循环
|
|
|
if (feedays <= feeMonth)//总仓储月数 <= i区间仓储月数
|
|
|
{
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else//总仓储月数 <= 区间计费区间(仓储月数/天数)
|
|
|
{
|
|
|
//--- BEGIN --- 如果是月则计算开始和结束日期之间的天数
|
|
|
DateTime dtSTARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
DateTime dtENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
int dtDays = feedays;
|
|
|
|
|
|
string FEEUNIT2 = FEEUNIT;
|
|
|
if (FEEUNIT.IndexOf("月") > -1)
|
|
|
{
|
|
|
FEEUNIT2 = FEEUNIT.Trim().Substring(0, 1) + "天";
|
|
|
dtDays = GetDaysCount("day", dtSTARTBILLINGDATE.ToString().Trim(), dtENDBILLINGDATE.ToString().Trim());//按月的区间天数
|
|
|
}
|
|
|
//--- END ---
|
|
|
|
|
|
gradefee = outnums * price * dtDays;//feedays;//出库量*计费单价*仓储区间(//仓储天数-上一个计费区间(0))
|
|
|
sumfee += gradefee;
|
|
|
prescale += dtDays;//feedays;//累计天数
|
|
|
//
|
|
|
model.FEEPRICE = price;
|
|
|
model.GOODSPFSL = outnums;
|
|
|
model.FEESCALE = dtDays;//feedays;
|
|
|
model.OUTFEE = gradefee;
|
|
|
model.FEEUNIT = FEEUNIT2;
|
|
|
model.STARTBILLINGDATE = DateTime.Parse(strSTARTBILLINGDATE2);
|
|
|
model.ENDBILLINGDATE = DateTime.Parse(strOLDCUSTFEEDATE);
|
|
|
model.FEEGRADE = nowgrade;
|
|
|
model.REMARK = "";
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.MODIFIEDUSER = strUserID;
|
|
|
model.ASSOCIATEDNO = strASSOCIATEDNO;
|
|
|
model.CUSTOMERNAME = strCUSTOMERNAME;
|
|
|
model.FEETYPE = strFEETYPE;
|
|
|
model.WMSOUTGID = sOUTGID;
|
|
|
tempWmsRateDetailDetailEntities.Add(model);
|
|
|
//
|
|
|
nowgrade++;
|
|
|
strSTARTBILLINGDATE2 = (DateTime.Parse(strOLDCUSTFEEDATE).AddDays(1)).ToString();//按区间计费的开始计费日期
|
|
|
break;//结束费率区间的循环
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//仓储费率没有设定
|
|
|
//sqlTran.Rollback();
|
|
|
//result = -2;
|
|
|
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
|
|
|
//Clearh();
|
|
|
//return result;
|
|
|
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
//
|
|
|
|
|
|
#region 按区间计算仓储费,插入费率出库明细表
|
|
|
if (tempWmsRateDetailDetailEntities != null)//是否有要入库的仓储费
|
|
|
{
|
|
|
if (tempWmsRateDetailDetailEntities.Count > 0)
|
|
|
{
|
|
|
foreach (WmsRateDetail model2 in tempWmsRateDetailDetailEntities)
|
|
|
{
|
|
|
Sqlstr = String.Format("insert into wms_settle_detail_rate_detail_tmp(GID,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,CREATEUSER,CREATETIME,ASSOCIATEDNO,CUSTOMERNAME,FEETYPE,FEEGRADE,STARTBILLINGDATE,ENDBILLINGDATE,FEESCALE,FEEUNIT,MODIFIEDUSER,WMSOUTGID)"
|
|
|
+ " values(newid(),'{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
|
|
|
, model2.FEEPRICE, model2.GOODSPFSL, model2.OUTFEE, model2.REMARK, model2.CREATEUSER, model2.ASSOCIATEDNO, model2.CUSTOMERNAME, model2.FEETYPE, model2.FEEGRADE, model2.STARTBILLINGDATE, model2.ENDBILLINGDATE, model2.FEESCALE, model2.FEEUNIT, model2.MODIFIEDUSER, model2.WMSOUTGID);
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
|
|
|
//if (iState != 1)
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(Sqlstr);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -1;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
//
|
|
|
string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('添加出库明细的费率明细信息','INSERT 插入操作','" + strShowName + " 添加 费率明细信息 出库单号:" + sBillno.Trim() + " ','" + model2.MODIFIEDUSER.ToString() + "')";
|
|
|
//iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, str0, null);
|
|
|
//if (iState != 1)
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(str0);
|
|
|
if (!bl)
|
|
|
{
|
|
|
result = -1;
|
|
|
//sqlTran.Rollback();
|
|
|
//Clearh();
|
|
|
return result.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tempWmsRateDetailDetailEntities = null;
|
|
|
totalfeedays = 0;
|
|
|
feedays = 0;
|
|
|
sumfee = 0;
|
|
|
}
|
|
|
#endregion
|
|
|
sR = sumfee.ToString() + "," + totalfeedays.ToString();
|
|
|
return sR;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 计算仓储时间差 +1
|
|
|
/// <summary>
|
|
|
/// 计算仓储时间差 +1
|
|
|
/// </summary>
|
|
|
public static int GetDaysCount(string ymd, string indate, string outdate)
|
|
|
{
|
|
|
string strSql = String.Format(" select datediff({0},'{1}','{2}') ", ymd, indate, outdate);
|
|
|
if (ymd == "day")
|
|
|
{
|
|
|
strSql = String.Format(" select datediff({0},'{1}','{2}')+1 ", ymd, indate, outdate);
|
|
|
}
|
|
|
object obj = SqlHelper.GetSingle(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
|
|
|
if (obj == null)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (ymd == "month")
|
|
|
{
|
|
|
int inum = int.Parse(obj.ToString());
|
|
|
DateTime dt = DateTime.Parse(indate).AddMonths(inum).AddDays(-1);
|
|
|
if (DateTime.Parse(outdate) > dt)
|
|
|
{
|
|
|
inum = inum + 1;
|
|
|
return Convert.ToInt32(inum);
|
|
|
}
|
|
|
}
|
|
|
return Convert.ToInt32(obj);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="strCondition"></param>
|
|
|
/// <param name="strCondition2"></param>
|
|
|
/// <param name="strCondition3"></param>
|
|
|
/// <param name="strCondition4"></param>
|
|
|
/// <param name="strSTARTBILLINGDATE"></param>
|
|
|
/// <param name="strENDBILLINGDATE"></param>
|
|
|
/// <param name="strFeeType"></param>
|
|
|
/// <param name="strUserID"></param>
|
|
|
/// <param name="strShowName"></param>
|
|
|
/// <param name="strCompanyID"></param>
|
|
|
/// <param name="orgcode"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
static public List<RptWmsSettleDetailEntity> GetFeeDataList(string strCondition, string strCondition2,
|
|
|
string strCondition3, string strCondition4, string strSTARTBILLINGDATE, string strENDBILLINGDATE,string strFeeType,
|
|
|
string strUserID, string strShowName, string strCompanyID, string orgcode, string sort)
|
|
|
{
|
|
|
|
|
|
Boolean bFlag = true;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{//根据出库GID查询出库费用,有多少出库明细就产生多少出库费用
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("select * from VW_WMS_SETTLE ");
|
|
|
strSql.Append("where (( " + strCondition2);
|
|
|
strSql.Append(" ) or ( " + strCondition4 + "))");
|
|
|
strSql.Append(" and " + strCondition3);
|
|
|
|
|
|
List<RptWmsSettleDetailEntity> wmsSettleList = new List<RptWmsSettleDetailEntity>();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
int i = 0;
|
|
|
int existVal = 0;
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
#region 公共信息,不需要判断
|
|
|
|
|
|
RptWmsSettleDetailEntity wmsSettle = new RptWmsSettleDetailEntity();
|
|
|
wmsSettle.GID = Guid.NewGuid().ToString();
|
|
|
wmsSettle.BLNO = reader["BLNO"].ToString();
|
|
|
wmsSettle.STORAGENAME = reader["STORAGENAME"].ToString();
|
|
|
wmsSettle.CUSTOMNO = reader["CUSTNO"].ToString();
|
|
|
wmsSettle.CONTRACTNO = reader["CONTRACTNO"].ToString();
|
|
|
|
|
|
wmsSettle.WMSNO = reader["WMSNO"].ToString();
|
|
|
wmsSettle.GID_LINK = reader["NID"].ToString();
|
|
|
wmsSettle.OUTBSNO = "";
|
|
|
if (!string.IsNullOrEmpty(reader["BSNO_OUT"].ToString()))
|
|
|
wmsSettle.OUTBSNO = reader["BSNO_OUT"].ToString();
|
|
|
wmsSettle.GOODSNAME = reader["GOODSNAME"].ToString();
|
|
|
wmsSettle.GOODSMODEL = reader["GOODSMODEL"].ToString();
|
|
|
wmsSettle.GOODSSTANDARD = reader["GOODSSTANDARD"].ToString();
|
|
|
|
|
|
wmsSettle.GOODSRKSL = Convert.ToDecimal(reader["GOODSRKSL"].ToString()); //入库量
|
|
|
wmsSettle.GOODSPFSL = Convert.ToDecimal(reader["GOODSPFSL_OUT"].ToString());
|
|
|
wmsSettle.GOODSSTOCK = Convert.ToDecimal(reader["GOODSSTOCK"].ToString());
|
|
|
|
|
|
wmsSettle.GOODSPACK = Convert.ToDecimal(reader["GOODSPACK"].ToString()); //入库件数
|
|
|
wmsSettle.GOODSPACKPFSL = Convert.ToDecimal(reader["GOODSPACKPFSL_OUT"].ToString());
|
|
|
wmsSettle.GOODSPACKSTOCK = Convert.ToDecimal(reader["GOODSPACKSTOCK"].ToString());
|
|
|
|
|
|
wmsSettle.WMSDATE = reader["WMSDATE"].ToString();
|
|
|
wmsSettle.FEETYPE = Convert.ToInt16(strFeeType);
|
|
|
wmsSettle.DODATE = reader["DODATE_OUT"].ToString();
|
|
|
|
|
|
wmsSettle.ENDBILLINGDATE_OUT = reader["DODATE_OUT"].ToString();
|
|
|
wmsSettle.STARTBILLINGDATE_OUT = reader["STARTBILLINGDATE"].ToString();
|
|
|
wmsSettle.CUSTOMERNAME = reader["CUSTOMERNAME"].ToString();
|
|
|
if (wmsSettle.FEETYPE == 2)
|
|
|
{
|
|
|
wmsSettle.STARTBILLINGDATE_OUT = reader["STARTBILLINGDATEAP"].ToString();
|
|
|
wmsSettle.CUSTOMERNAME = reader["TRUCKNAME"].ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wmsSettle.OUTFEE = -1;
|
|
|
wmsSettle.WMSGID = reader["WMSGID"].ToString();
|
|
|
#endregion
|
|
|
|
|
|
decimal tmpGOODSPFSL = 0;
|
|
|
#region 开始统计日期之前已经出库,不统计
|
|
|
if ((wmsSettle.OUTBSNO != "") &&
|
|
|
CompareDate(strSTARTBILLINGDATE,wmsSettle.ENDBILLINGDATE_OUT ) >= 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 在统计日期时间段内有出库单
|
|
|
if ((wmsSettle.OUTBSNO != "") && CompareDate(strENDBILLINGDATE, wmsSettle.ENDBILLINGDATE_OUT) >= 0)
|
|
|
{
|
|
|
wmsSettle.ENDBILLINGDATE = wmsSettle.ENDBILLINGDATE_OUT;
|
|
|
|
|
|
if (CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) <= 0)
|
|
|
{
|
|
|
wmsSettle.LINENUM = 3;
|
|
|
//入库出库正好落在统计日期区间内,仓储费不必计算,直接用出库费用
|
|
|
wmsSettle.STARTBILLINGDATE = wmsSettle.STARTBILLINGDATE_OUT;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
wmsSettle.OUTFEE = Convert.ToDecimal(reader["GOODSOUTFEE_OUT"].ToString());//应收
|
|
|
if (wmsSettle.FEETYPE == 2)
|
|
|
wmsSettle.OUTFEE = Convert.ToDecimal(reader["GOODSOUTFEEAP_OUT"].ToString());//应付
|
|
|
}
|
|
|
else if (CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) > 0)
|
|
|
{
|
|
|
wmsSettle.LINENUM = 6;
|
|
|
//入库计费日期早于统计日期的开始日期
|
|
|
wmsSettle.STARTBILLINGDATE = strSTARTBILLINGDATE;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
tmpGOODSPFSL = wmsSettle.GOODSPFSL;
|
|
|
//计算仓储费
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 在统计日期时间段内没有出库单,但是之后有出库单,重新计算仓储费
|
|
|
if ((wmsSettle.OUTBSNO != "") && CompareDate(strENDBILLINGDATE, wmsSettle.ENDBILLINGDATE_OUT) < 0)
|
|
|
{
|
|
|
|
|
|
wmsSettle.ENDBILLINGDATE = strENDBILLINGDATE;
|
|
|
if (CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) <= 0)
|
|
|
{
|
|
|
//入库计费日期晚于统计日期的开始日期
|
|
|
wmsSettle.LINENUM = 4;
|
|
|
wmsSettle.STARTBILLINGDATE = wmsSettle.STARTBILLINGDATE_OUT;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
tmpGOODSPFSL = wmsSettle.GOODSPFSL;
|
|
|
//计算仓储费
|
|
|
|
|
|
|
|
|
}
|
|
|
else if (CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) > 0)
|
|
|
{
|
|
|
//入库计费日期早于统计日期的开始日期
|
|
|
wmsSettle.LINENUM = 5 ;
|
|
|
wmsSettle.STARTBILLINGDATE = strSTARTBILLINGDATE;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
tmpGOODSPFSL = wmsSettle.GOODSPFSL;
|
|
|
//计算仓储费
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 统计日期时间段内没有出库,之前出库的不用算,之后也没有出库
|
|
|
if ((wmsSettle.OUTBSNO == "") && CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) <= 0)
|
|
|
{
|
|
|
wmsSettle.LINENUM = 1;
|
|
|
//入库计费日期晚于统计日期的开始日期
|
|
|
wmsSettle.ENDBILLINGDATE = strENDBILLINGDATE;
|
|
|
wmsSettle.STARTBILLINGDATE = wmsSettle.STARTBILLINGDATE_OUT;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
tmpGOODSPFSL = wmsSettle.GOODSSTOCK;
|
|
|
//计算仓储费
|
|
|
//wmsSettle.OUTFEE = Convert.ToDecimal(reader["GOODSOUTFEE_OUT"].ToString());//应收
|
|
|
|
|
|
}
|
|
|
else if ((wmsSettle.OUTBSNO == "") && CompareDate(strSTARTBILLINGDATE, wmsSettle.STARTBILLINGDATE_OUT) > 0)
|
|
|
{
|
|
|
wmsSettle.LINENUM = 2;
|
|
|
//入库计费日期早于统计日期的开始日期
|
|
|
wmsSettle.ENDBILLINGDATE = strENDBILLINGDATE;
|
|
|
wmsSettle.STARTBILLINGDATE = strSTARTBILLINGDATE;
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
tmpGOODSPFSL = wmsSettle.GOODSSTOCK;
|
|
|
//计算仓储费
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 计算仓储费
|
|
|
|
|
|
|
|
|
|
|
|
if (wmsSettle.LINENUM == 1 || wmsSettle.LINENUM == 4)
|
|
|
{
|
|
|
string getstr = getWmsRate(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE, wmsSettle.WMSGID, wmsSettle.CUSTOMERNAME, tmpGOODSPFSL, wmsSettle.GID, wmsSettle.FEETYPE, strUserID, strShowName, wmsSettle.WMSGID, wmsSettle.WMSGID, true, false);
|
|
|
|
|
|
string[] strls = getstr.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
wmsSettle.OUTFEE = Decimal.Parse(strls[0].ToString());
|
|
|
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
|
|
|
}
|
|
|
else if (wmsSettle.LINENUM == 2 || wmsSettle.LINENUM == 5 || wmsSettle.LINENUM == 6)
|
|
|
{
|
|
|
getWmsRateTmp(wmsSettle.STARTBILLINGDATE_OUT, wmsSettle.ENDBILLINGDATE, wmsSettle.WMSGID, wmsSettle.CUSTOMERNAME, tmpGOODSPFSL, wmsSettle.GID, wmsSettle.FEETYPE, strUserID, strShowName, wmsSettle.WMSGID, wmsSettle.WMSGID, true, false);
|
|
|
string getstrInternal = getWMSRateInternal(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE, wmsSettle.WMSGID, wmsSettle.CUSTOMERNAME, tmpGOODSPFSL, wmsSettle.GID, wmsSettle.FEETYPE, strUserID, strShowName, wmsSettle.WMSGID, wmsSettle.WMSGID, true, false);
|
|
|
string[] strlsInternal = getstrInternal.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
wmsSettle.OUTFEE = Decimal.Parse(strlsInternal[0].ToString());
|
|
|
wmsSettle.FEEDAYS = DateDiff(wmsSettle.STARTBILLINGDATE, wmsSettle.ENDBILLINGDATE);
|
|
|
|
|
|
}
|
|
|
else if (wmsSettle.LINENUM == 3)
|
|
|
{
|
|
|
copyWmsRate(wmsSettle.GID, wmsSettle.GID_LINK, wmsSettle.FEETYPE);
|
|
|
}
|
|
|
|
|
|
|
|
|
wmsSettleList.Add(wmsSettle);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
#region 统计日期之后出库和未出库合并
|
|
|
|
|
|
#endregion
|
|
|
#region 清除 wms_settle_detail_tmp数据
|
|
|
StringBuilder strDelTmp = new StringBuilder();
|
|
|
strDelTmp.Append("delete from wms_settle_detail_tmp") ;
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strDelTmp.ToString(), null);
|
|
|
#endregion
|
|
|
foreach (var settle in wmsSettleList)
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
sb.Append(@"insert into[wms_settle_detail_tmp]([GID],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],");
|
|
|
sb.Append(@"[STORAGENAME], [GOODSNAME],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE],[ENDBILLINGDATE],");
|
|
|
sb.Append(@"[GOODSPACK],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSPFSL],[GOODSSTOCK],");
|
|
|
sb.Append(@"[REMARK_OUT],[FEETYPE],[FEEDAYS],[OUTFEE],");
|
|
|
sb.Append(@"[CREATEUSER],[CREATETIME],[CORPID],[GID_LINK],[LINENUM])");
|
|
|
|
|
|
sb.Append(@" VALUES(");
|
|
|
sb.Append("'" + settle.GID + "',");//GID
|
|
|
sb.Append("'" + settle.BLNO + "',");//BSNO
|
|
|
sb.Append("'" + settle.CUSTOMNO + "', ");//备案清单号
|
|
|
sb.Append("'" + settle.CONTRACTNO + "',");//合同号
|
|
|
sb.Append("'" + settle.WMSNO + "',");//入库单号
|
|
|
sb.Append("'" + settle.OUTBSNO + "',");//出库单号
|
|
|
sb.Append("'" + settle.CUSTOMERNAME + "',");//客户名称
|
|
|
sb.Append("'" + settle.STORAGENAME + "',");//仓库名称
|
|
|
sb.Append("'" + settle.GOODSNAME + "',");//品名
|
|
|
sb.Append("'" + settle.WMSDATE + "',");//入库日期
|
|
|
sb.Append("'" + settle.DODATE + "',");//出库日期
|
|
|
sb.Append("'" + settle.WMSDAYS + "',");//
|
|
|
sb.Append("'" + settle.STARTBILLINGDATE + "',");//开始计费日期
|
|
|
sb.Append("'" + settle.ENDBILLINGDATE + "',");//结束计费日期
|
|
|
sb.Append("'" + settle.GOODSPACK + "',");//入库件数
|
|
|
sb.Append("'" + settle.GOODSPACKPFSL + "',");//出库件数
|
|
|
sb.Append("'" + settle.GOODSPACKSTOCK + "',");//库存件数
|
|
|
sb.Append("'" + settle.GOODSRKSL + "',");//入库量
|
|
|
sb.Append("'" + settle.GOODSPFSL + "',");//出库量
|
|
|
sb.Append("'" + settle.GOODSSTOCK + "',");//库存量
|
|
|
|
|
|
sb.Append("'" + settle.REMARK_OUT + "',");//备注
|
|
|
sb.Append("'" + settle.FEETYPE + "',");//收付类型
|
|
|
sb.Append("'" + settle.FEEDAYS + "',");//计费天数
|
|
|
sb.Append("'" + settle.OUTFEE + "',");//仓储费
|
|
|
sb.Append("'" + strUserID + "',");//用户ID
|
|
|
sb.Append("'" + DateTime.Now.ToString() + "',");//当前时间
|
|
|
sb.Append("'" + strCompanyID + "',");//单位名称
|
|
|
sb.Append("'" +settle.GID_LINK + "',");//出库GID或者入库GID
|
|
|
sb.Append("'" + settle.LINENUM + "'");//LINENUM
|
|
|
|
|
|
sb.Append(")");
|
|
|
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sb.ToString(), null);
|
|
|
|
|
|
}
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
|
|
|
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
|
|
|
sqlTran.Rollback();
|
|
|
bFlag = false;
|
|
|
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#region 从【仓储结算明细临时表[wms_settlement_detail_temp]】中提取数据列表,并返回js页面
|
|
|
//按提单号合计出一部分数据
|
|
|
StringBuilder strSql2 = new StringBuilder();
|
|
|
strSql2.Append("select s.BLNO,GID,DUIGID,DUINO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME,OUTBSNO,t.OUTFEE");
|
|
|
strSql2.Append(" from( ");
|
|
|
strSql2.Append(" select *, row_number() over(partition by[BLNO] order by[GID]) as group_idx ");
|
|
|
strSql2.Append(" from [wms_settle_detail_tmp]");
|
|
|
strSql2.Append(" ) s");
|
|
|
strSql2.Append(" inner join ");
|
|
|
strSql2.Append(" (select BLNO,sum(outfee) as OUTFEE ");
|
|
|
strSql2.Append(" from wms_settle_detail_tmp ");
|
|
|
strSql2.Append(" group by BLNO) t on t.BLNO= s.blno ");
|
|
|
strSql2.Append(" where s.group_idx = 1 and s.CREATEUSER='" + strUserID + "' and s.CORPID='" + strCompanyID + "'");
|
|
|
if (!bFlag)
|
|
|
strSql2.Append(" and 1<0 ");
|
|
|
|
|
|
|
|
|
return SetFeeData(strSql2.ToString());
|
|
|
#endregion
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 保存
|
|
|
public static DBResult Save(RptWmsSettleListEntity model, string condition, string strUserID, string strCompanyID)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
if (model == null)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
List<ModelObjectBase> dataList = new List<ModelObjectBase>();
|
|
|
dataList.Add(model);
|
|
|
//
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 保存主表wms_settle_list
|
|
|
String strSql = "insert into wms_settle_list(GID,DUINO,CUSTOMERNAME,{0}{2}REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME) values (@GID,@DUINO,@CUSTOMERNAME,{1}{3}@REMARK,@CORPID,@CREATEUSER,getdate(),@ISMAKEOUT,@MAKEOUTUSER,getdate())";
|
|
|
SqlParameter[] parameters = {
|
|
|
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@DUINO", SqlDbType.VarChar,100) ,
|
|
|
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20) ,
|
|
|
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
|
|
|
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@ISMAKEOUT", SqlDbType.Bit,1) ,
|
|
|
new SqlParameter("@MAKEOUTUSER", SqlDbType.VarChar,36)
|
|
|
|
|
|
};
|
|
|
parameters[0].Value = model.GID;
|
|
|
parameters[1].Value = model.DUINO;
|
|
|
parameters[2].Value = model.CUSTOMERNAME;
|
|
|
parameters[3].Value = model.REMARK;
|
|
|
parameters[4].Value = strCompanyID;
|
|
|
parameters[5].Value = strUserID;
|
|
|
parameters[6].Value = false;
|
|
|
parameters[7].Value = strUserID;
|
|
|
|
|
|
|
|
|
//操作时间
|
|
|
string strSTARTBILLINGDATE = model.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.STARTBILLINGDATE.ToString() + "',";
|
|
|
string strSTARTBILLINGDATE_name = model.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "STARTBILLINGDATE,";
|
|
|
//
|
|
|
string strENDBILLINGDATE = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ENDBILLINGDATE.ToString() + "',";
|
|
|
string strENDBILLINGDATE_name = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "ENDBILLINGDATE,";
|
|
|
//
|
|
|
strSql = String.Format(strSql, strSTARTBILLINGDATE_name, strSTARTBILLINGDATE, strENDBILLINGDATE_name, strENDBILLINGDATE);
|
|
|
//
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), parameters);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存明细表[wms_settle_detail_tmp]
|
|
|
strSql = "insert into wms_settle_detail([GID],[DUIGID],[DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
|
|
|
+ "select [GID],'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as [DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],getdate(),[ISMAKEOUT],[MAKEOUTUSER],getdate(),[CORPID],[LINENUM],[GID_LINK]"
|
|
|
+ " from [wms_settle_detail_tmp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "'" + condition;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存入库GID到关联表
|
|
|
strSql = "insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
|
|
|
+ "select newid() as GID,'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as DUINO,GID_LINK as LINKGID,'wms' as TABLENAME," + strSTARTBILLINGDATE + strENDBILLINGDATE + "CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and (LINENUM=1 or LINENUM=5) " + condition + " group by LINENUM,GID_LINK,CREATEUSER,CORPID";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存出库GID到关联表
|
|
|
strSql = "insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
|
|
|
+ "select newid() as GID,'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as DUINO,GID_LINK as LINKGID,'wms_out' as TABLENAME," + strSTARTBILLINGDATE + strENDBILLINGDATE + "CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and (LINENUM=2 or LINENUM=3 or LINENUM=4) " + condition + " group by LINENUM,GID_LINK,CREATEUSER,CORPID";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存ch_fee的GID到关联表
|
|
|
strSql = "insert into wms_settlement_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
|
|
|
+ "select newid() as GID,'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as DUINO,GID as LINKGID,'ch_fee' as TABLENAME," + strSTARTBILLINGDATE + strENDBILLINGDATE + "'" + strUserID + "' as CREATEUSER,getdate() from ch_fee where isnull(WMSOUTBSNO,'') in (select GID_LINK from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and (LINENUM=2 or LINENUM=3 or LINENUM=4) " + condition + ") and (FEESTATUS<>9 or FEESTATUS<>8)";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 保存
|
|
|
public static DBResult Save(string opstatus, string data, string condition, string strUserID, string strCompanyID)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string strSql = "select CUSTOMERNAME from [wms_settle_detail_tmp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "'" + condition + " group by CUSTOMERNAME";
|
|
|
DataSet ds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSql, null);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|
|
{
|
|
|
string condition2 = " and CUSTOMERNAME='" + dr["CUSTOMERNAME"].ToString().Trim() + "'";
|
|
|
//
|
|
|
#region 保存主表wms_settle_list
|
|
|
var model = JsonConvert.Deserialize<RptWmsSettleListEntity>(data);
|
|
|
if (opstatus == "add")
|
|
|
{
|
|
|
model.GID = "WMSD" + Guid.NewGuid().ToString().Replace("-", "");
|
|
|
model.DUINO = PubSysDAL.GetBillNo("0302");//生成编号
|
|
|
model.CUSTOMERNAME = dr["CUSTOMERNAME"].ToString().Trim();
|
|
|
model.CREATEUSER = strUserID;
|
|
|
model.CREATETIME = DateTime.Now;
|
|
|
model.DbOperationType = DbOperationType.DbotIns;
|
|
|
}
|
|
|
else if (opstatus == "edit")
|
|
|
{
|
|
|
model.DbOperationType = DbOperationType.DbotUpd;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
model.DbOperationType = DbOperationType.DbotDel;
|
|
|
}
|
|
|
//
|
|
|
if (model == null)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
List<ModelObjectBase> dataList = new List<ModelObjectBase>();
|
|
|
dataList.Add(model);
|
|
|
//
|
|
|
strSql = "insert into wms_settle_list(GID,DUINO,CUSTOMERNAME,{0}{2}REMARK,CORPID,CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME) values (@GID,@DUINO,@CUSTOMERNAME,{1}{3}@REMARK,@CORPID,@CREATEUSER,getdate(),@ISMAKEOUT,@MAKEOUTUSER,getdate())";
|
|
|
SqlParameter[] parameters = {
|
|
|
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@DUINO", SqlDbType.VarChar,100) ,
|
|
|
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20) ,
|
|
|
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
|
|
|
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
|
|
|
new SqlParameter("@ISMAKEOUT", SqlDbType.Bit,1) ,
|
|
|
new SqlParameter("@MAKEOUTUSER", SqlDbType.VarChar,36)
|
|
|
};
|
|
|
parameters[0].Value = model.GID;
|
|
|
parameters[1].Value = model.DUINO;
|
|
|
parameters[2].Value = model.CUSTOMERNAME;
|
|
|
parameters[3].Value = model.REMARK;
|
|
|
parameters[4].Value = strCompanyID;
|
|
|
parameters[5].Value = strUserID;
|
|
|
parameters[6].Value = false;
|
|
|
parameters[7].Value = strUserID;
|
|
|
|
|
|
//操作时间
|
|
|
string strSTARTBILLINGDATE = model.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.STARTBILLINGDATE.ToString() + "',";
|
|
|
string strSTARTBILLINGDATE_name = model.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "STARTBILLINGDATE,";
|
|
|
//
|
|
|
string strENDBILLINGDATE = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ENDBILLINGDATE.ToString() + "',";
|
|
|
string strENDBILLINGDATE_name = model.ENDBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "ENDBILLINGDATE,";
|
|
|
//
|
|
|
strSql = String.Format(strSql, strSTARTBILLINGDATE_name, strSTARTBILLINGDATE, strENDBILLINGDATE_name, strENDBILLINGDATE);
|
|
|
//
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), parameters);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存明细表[wms_settle_detail]
|
|
|
strSql = "insert into wms_settle_detail([GID],[DUIGID],[DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],[CREATETIME],[ISMAKEOUT],[MAKEOUTUSER],[MAKEOUTTIME],[CORPID],[LINENUM],[GID_LINK]) "
|
|
|
+ "select [GID],'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as [DUINO],[BLNO],[CUSTOMNO],[CONTRACTNO],[WMSNO],[OUTBSNO],[CUSTOMERNAME],[STORAGENAME],[GOODSNAME],[GOODSMODEL],[GOODSSTANDARD],[GOODSGRADE],[WMSDATE],[DODATE],[WMSDAYS],[STARTBILLINGDATE_OUT],[ENDBILLINGDATE_OUT],[GOODSOUTFEE],[GOODSPACK],[GOODSPACKACTUAL],[GOODSPACKPFSL],[GOODSPACKSTOCK],[GOODSRKSL],[GOODSRKSLACTUAL],[GOODSPFSL],[GOODSSTOCK],[CHARGEUNIT],[REMARK_OUT],[FEETYPE],[FEEGRADE],[FEESCALE],[FEEPRICE],[STARTBILLINGDATE],[ENDBILLINGDATE],[FEEDAYS],[OUTFEE],[ARFEE],[CREATEUSER],getdate(),[ISMAKEOUT],[MAKEOUTUSER],getdate(),[CORPID],[LINENUM],[GID_LINK]"
|
|
|
+ " from [wms_settle_detail_tmp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "'" ;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
/*
|
|
|
#region 保存入库GID到关联表
|
|
|
strSql = "insert into wms_settle_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
|
|
|
+ "select newid() as GID,'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as DUINO,GID_LINK as LINKGID,'wms' as TABLENAME," + strSTARTBILLINGDATE + strENDBILLINGDATE + "CREATEUSER,getdate() from [wms_settle_detail_tmp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and (LINENUM=1 or LINENUM=2) group by LINENUM,GID_LINK,CREATEUSER,CORPID";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 保存出库GID到关联表
|
|
|
strSql = "insert into wms_settle_date([GID],[DUIGID],[DUINO],[LINKGID],[TABLENAME],[STARTBILLINGDATE],[ENDBILLINGDATE],[CREATEUSER],[CREATETIME]) "
|
|
|
+ "select newid() as GID,'" + model.GID.ToString().Trim() + "' as DUIGID,'" + model.DUINO.ToString().Trim() + "' as DUINO,GID_LINK as LINKGID,'wms_out' as TABLENAME," + strSTARTBILLINGDATE + strENDBILLINGDATE + "CREATEUSER,getdate() from [wms_settlement_detail_temp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "' and (LINENUM=3 or LINENUM=4 or LINENUM=5 or LINENUM=6) group by LINENUM,GID_LINK,CREATEUSER,CORPID";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
|
result.Message = "保存成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Inquery 仓储结算清单明细临时表([wms_settlement_detail_temp])根据提单号查询
|
|
|
static public List<RptWmsSettleDetailEntity> GetMblnoDetailList(string strCondition, string strUserID, string strCompanyID, string sort = null)
|
|
|
{
|
|
|
string strSql2 = "SELECT GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,OUTBSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,dbo.trimdate(WMSDATE) as WMSDATE,dbo.trimdate(DODATE) as DODATE,WMSDAYS,dbo.trimdate(STARTBILLINGDATE_OUT) as STARTBILLINGDATE_OUT,dbo.trimdate(ENDBILLINGDATE_OUT) as ENDBILLINGDATE_OUT,GOODSOUTFEE,GOODSPACK,GOODSPACKACTUAL,GOODSPACKPFSL,GOODSPACKSTOCK,GOODSRKSL,GOODSRKSLACTUAL,GOODSPFSL,GOODSSTOCK,CHARGEUNIT,REMARK_OUT,FEETYPE,FEEGRADE,FEESCALE,FEEPRICE,dbo.trimdate(STARTBILLINGDATE) as STARTBILLINGDATE,dbo.trimdate(ENDBILLINGDATE) as ENDBILLINGDATE,FEEDAYS,OUTFEE,[ARFEE],CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,CORPID,LINENUM,GID_LINK FROM [wms_settle_detail_tmp] where CREATEUSER='" + strUserID + "' and CORPID='" + strCompanyID + "'" + strCondition;
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql2 += " order by " + sortstring;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql2 += " order by CUSTOMERNAME,BLNO,WMSNO,LINENUM,OUTBSNO,STARTBILLINGDATE,FEEGRADE";
|
|
|
}
|
|
|
return SetMblnoDetailData(strSql2);
|
|
|
}
|
|
|
|
|
|
private static List<RptWmsSettleDetailEntity> SetMblnoDetailData(String strSql)
|
|
|
{
|
|
|
var headList = new List<RptWmsSettleDetailEntity>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
RptWmsSettleDetailEntity data = new RptWmsSettleDetailEntity();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.WMSNO = Convert.ToString(reader["WMSNO"]);
|
|
|
data.OUTBSNO = Convert.ToString(reader["OUTBSNO"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.STORAGENAME = Convert.ToString(reader["STORAGENAME"]);
|
|
|
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
|
|
|
data.GOODSMODEL = Convert.ToString(reader["GOODSMODEL"]);
|
|
|
data.GOODSSTANDARD = Convert.ToString(reader["GOODSSTANDARD"]);
|
|
|
data.GOODSGRADE = Convert.ToString(reader["GOODSGRADE"]);
|
|
|
data.WMSDATE = Convert.ToString(reader["WMSDATE"]);
|
|
|
data.DODATE = Convert.ToString(reader["DODATE"]);
|
|
|
data.WMSDAYS = Convert.ToInt32(reader["WMSDAYS"]);
|
|
|
data.STARTBILLINGDATE_OUT = Convert.ToString(reader["STARTBILLINGDATE_OUT"]);
|
|
|
data.ENDBILLINGDATE_OUT = Convert.ToString(reader["ENDBILLINGDATE_OUT"]);
|
|
|
data.GOODSOUTFEE = Convert.ToDecimal(reader["GOODSOUTFEE"]);
|
|
|
data.GOODSPACK = Convert.ToDecimal(reader["GOODSPACK"]);
|
|
|
data.GOODSPACKACTUAL = Convert.ToDecimal(reader["GOODSPACKACTUAL"]);
|
|
|
data.GOODSPACKPFSL = Convert.ToDecimal(reader["GOODSPACKPFSL"]);
|
|
|
data.GOODSPACKSTOCK = Convert.ToDecimal(reader["GOODSPACKSTOCK"]);
|
|
|
data.GOODSRKSL = Convert.ToDecimal(reader["GOODSRKSL"]);
|
|
|
data.GOODSRKSLACTUAL = Convert.ToDecimal(reader["GOODSRKSLACTUAL"]);
|
|
|
data.GOODSPFSL = Convert.ToDecimal(reader["GOODSPFSL"]);
|
|
|
data.GOODSSTOCK = Convert.ToDecimal(reader["GOODSSTOCK"]);
|
|
|
data.CHARGEUNIT = Convert.ToString(reader["CHARGEUNIT"]);
|
|
|
data.REMARK_OUT = Convert.ToString(reader["REMARK_OUT"]);
|
|
|
data.FEETYPE = Convert.ToInt32(reader["FEETYPE"]);
|
|
|
data.FEEGRADE = Convert.ToInt32(reader["FEEGRADE"]);
|
|
|
data.FEESCALE = Convert.ToInt32(reader["FEESCALE"]);
|
|
|
data.FEEPRICE = Convert.ToDecimal(reader["FEEPRICE"]);
|
|
|
data.STARTBILLINGDATE = Convert.ToString(reader["STARTBILLINGDATE"]);
|
|
|
data.ENDBILLINGDATE = Convert.ToString(reader["ENDBILLINGDATE"]);
|
|
|
data.FEEDAYS = Convert.ToInt32(reader["FEEDAYS"]);
|
|
|
data.OUTFEE = Convert.ToDecimal(reader["OUTFEE"]);
|
|
|
data.ARFEE = Convert.ToDecimal(reader["ARFEE"]);
|
|
|
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
|
|
|
if (reader["CREATETIME"] != DBNull.Value)
|
|
|
data.MAKEOUTTIME = Convert.ToDateTime(reader["CREATETIME"]);
|
|
|
data.ISMAKEOUT = Convert.ToBoolean(reader["ISMAKEOUT"]);
|
|
|
data.MAKEOUTUSER = Convert.ToString(reader["MAKEOUTUSER"]);
|
|
|
if (reader["MAKEOUTTIME"] != DBNull.Value)
|
|
|
data.MAKEOUTTIME = Convert.ToDateTime(reader["MAKEOUTTIME"]);
|
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
|
data.LINENUM = Convert.ToInt32(reader["LINENUM"]);
|
|
|
data.GID_LINK = Convert.ToString(reader["GID_LINK"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Inquery 仓储结算清单明细表(wms_settle_detail)根据提单号查询
|
|
|
static public List<RptWmsSettleDetailEntity> GetMblnoDetailListEdit(string strCondition, string strUserID, string strCompanyID, string sort = null)
|
|
|
{
|
|
|
string strSql2 = "SELECT GID,BLNO,CUSTOMNO,CONTRACTNO,WMSNO,OUTBSNO,CUSTOMERNAME,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSSTANDARD,GOODSGRADE,dbo.trimdate(WMSDATE) as WMSDATE,dbo.trimdate(DODATE) as DODATE,WMSDAYS,dbo.trimdate(STARTBILLINGDATE_OUT) as STARTBILLINGDATE_OUT,dbo.trimdate(ENDBILLINGDATE_OUT) as ENDBILLINGDATE_OUT,GOODSOUTFEE,GOODSPACK,GOODSPACKACTUAL,GOODSPACKPFSL,GOODSPACKSTOCK,GOODSRKSL,GOODSRKSLACTUAL,GOODSPFSL,GOODSSTOCK,CHARGEUNIT,REMARK_OUT,FEETYPE,FEEGRADE,FEESCALE,FEEPRICE,dbo.trimdate(STARTBILLINGDATE) as STARTBILLINGDATE,dbo.trimdate(ENDBILLINGDATE) as ENDBILLINGDATE,FEEDAYS,OUTFEE,[ARFEE],CREATEUSER,CREATETIME,ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME,CORPID,LINENUM,GID_LINK FROM wms_settle_detail where CORPID='" + strCompanyID + "' and ISDELETE=0" + strCondition;//CREATEUSER='" + strUserID + "' and
|
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql2 += " order by " + sortstring;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql2 += " order by CUSTOMERNAME,BLNO,WMSNO,LINENUM,OUTBSNO,STARTBILLINGDATE,FEEGRADE";
|
|
|
}
|
|
|
return SetMblnoDetailData(strSql2);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Inquery 明细表 wms_settle_detail
|
|
|
static public List<RptWmsSettleDetailEntity> GetDataDetailListEdit(string strCondition, string strUserID, string strCompanyID, string sort = null)
|
|
|
{
|
|
|
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
strSql.Append("select GID,DUIGID,DUINO,CUSTOMNO,CONTRACTNO,CUSTOMERNAME,GOODSNAME,s.BLNO,t.OUTFEE");
|
|
|
strSql.Append(" from( ");
|
|
|
strSql.Append(" select *, row_number() over(partition by[BLNO] order by[GID]) as group_idx ");
|
|
|
strSql.Append(" from [wms_settle_detail] where "+strCondition);
|
|
|
strSql.Append(" ) s");
|
|
|
strSql.Append(" inner join ");
|
|
|
strSql.Append(" (select BLNO,sum(outfee) as OUTFEE ");
|
|
|
strSql.Append(" from wms_settle_detail where " + strCondition);
|
|
|
strSql.Append(" group by BLNO) t on t.BLNO= s.blno ");
|
|
|
strSql.Append(" where s.group_idx = 1 and s.CORPID='" + strCompanyID + "'");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
{
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" order by BLNO,CUSTOMERNAME");
|
|
|
}
|
|
|
return SetFeeData(strSql.ToString());
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取List合计数
|
|
|
//获取List合计数
|
|
|
public static List<RptWmsSettleDetailEntity> GetDataListSum(string tablename, string condition, string strUserID, string strCompanyID, string hjname)
|
|
|
{
|
|
|
string strSql = "SELECT newid() as GID, '" + hjname + "'as CUSTOMERNAME, isnull(sum(OUTFEE),0) as OUTFEE, isnull(sum(ARFEE),0) as ARFEE FROM " + tablename + " where CORPID='" + strCompanyID + "' and ISDELETE=0 " + condition + " group by CREATEUSER,CORPID,DUIGID";//CREATEUSER='" + strUserID + "' and
|
|
|
return SetDataSum(strSql);
|
|
|
}
|
|
|
|
|
|
//实体类
|
|
|
public static List<RptWmsSettleDetailEntity> SetDataSum(String strSql)
|
|
|
{
|
|
|
var headList = new List<RptWmsSettleDetailEntity>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
var data = new RptWmsSettleDetailEntity();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
data.OUTFEE = Convert.ToDecimal(reader["OUTFEE"]);
|
|
|
data.ARFEE = Convert.ToDecimal(reader["ARFEE"]);
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Delete 删除主表
|
|
|
public static DBResult Delete_Main(string gids, string strUserID, string strCompanyID)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
if (gids.Trim() == "")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
gids = "'" + gids.Trim().Replace(",","','") + "'";
|
|
|
//
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 判断【ch_fee】中的费用状态,是否允许删除
|
|
|
string sbool = "0";
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO in (" + gids + ") and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
|
|
|
sbool = T_ALL_DA.GetStrSQL("nums", ls);
|
|
|
if (sbool.Trim() == "0")
|
|
|
{
|
|
|
ls = "select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO in (" + gids + "))";
|
|
|
sbool = T_ALL_DA.GetStrSQL("nums", ls);
|
|
|
if (sbool.Trim() != "0")
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "有“已申请开票、已开发票或已对帐”的费用,不允许删除,请重新操作!";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "有“已申请开票、已开发票、已对帐”的费用,不允许删除,请重新操作!";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
string strError = "";
|
|
|
int iNum = 0;
|
|
|
/*
|
|
|
#region 判断是否有下一个阶段汇总的数据
|
|
|
string strSql = "select *,STARTBILLINGDATE_MAIN=(select top 1 STARTBILLINGDATE from wms_settle_list where gid=wms_settle_detail.DUIGID),ENDBILLINGDATE_MAIN=(select top 1 ENDBILLINGDATE from wms_settle_list where gid=wms_settle_detail.DUIGID) from wms_settle_detail where ISDELETE=0 and DUIGID in (" + gids + ")";
|
|
|
DataSet ds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSql, null);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|
|
{
|
|
|
strSql = "select count(*) from wms_settle_detail where BLNO='" + dr["BLNO"].ToString().Trim() + "' and DUIGID in (select gid from wms_settle_list where STARTBILLINGDATE>'" + dr["ENDBILLINGDATE_MAIN"].ToString().Trim() + "')";
|
|
|
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strSql, null);
|
|
|
if (statusObj != null)
|
|
|
{
|
|
|
iNum = int.Parse(statusObj.ToString().Trim());
|
|
|
}
|
|
|
if (iNum > 0)
|
|
|
{
|
|
|
strError += "、" + dr["BLNO"].ToString().Trim();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (strError.Trim() != "")
|
|
|
{
|
|
|
strError = strError.Trim().Substring(1);
|
|
|
result.Success = false;
|
|
|
result.Message = "提单号" + strError + "已经有下一个阶段汇总的数据,因此不允许删除此账单!";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
*/
|
|
|
#region 把【ch_fee】中WMSOUTBSNO与【仓储结算主表wms_settlement_list】GID关联的数据删除
|
|
|
String strSql = "delete from ch_fee where WMSOUTBSNO in (" + gids + ")";
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算关联表wms_settlement_date】中数据【ISDELETE】设为【1】
|
|
|
strSql = "delete from wms_settle_date where DUIGID in (" + gids + ")";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settlement_detail】中数据【ISDELETE】设为【1】
|
|
|
strSql = "delete from wms_settle_detail where DUIGID in (" + gids + ")";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算主表wms_settlement_list】中数据【ISDELETE】设为【1】
|
|
|
strSql = "delete from wms_settle_list where gid in (" + gids + ")";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "删除数据成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Delete 删除明细表
|
|
|
public static DBResult Delete_Detail(RptWmsSettleDetailEntity model, string DUIGID, string strBLNOs, string strUserID)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
if (model == null)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
List<ModelObjectBase> dataList = new List<ModelObjectBase>();
|
|
|
dataList.Add(model);
|
|
|
//
|
|
|
string strError = "";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
#region 判断是否有下一个阶段汇总的数据
|
|
|
int iNum = 0;
|
|
|
string strSql = "select *,STARTBILLINGDATE_MAIN=(select top 1 STARTBILLINGDATE from wms_settle_list where gid=wms_settle_detail.DUIGID),ENDBILLINGDATE_MAIN=(select top 1 ENDBILLINGDATE from wms_settle_list where gid=wms_settle_detail.DUIGID) from wms_settle_detail where ISDELETE=0 " + strBLNOs;
|
|
|
DataSet ds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSql, null);
|
|
|
if (ds != null)
|
|
|
{
|
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|
|
{
|
|
|
strSql = "select count(*) from wms_settle_detail where BLNO='" + dr["BLNO"].ToString().Trim() + "' and DUIGID in (select gid from wms_settle_list where STARTBILLINGDATE>'" + dr["ENDBILLINGDATE_MAIN"].ToString().Trim() + "')";
|
|
|
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strSql, null);
|
|
|
if (statusObj != null)
|
|
|
{
|
|
|
iNum = int.Parse(statusObj.ToString().Trim());
|
|
|
}
|
|
|
if (iNum > 0)
|
|
|
{
|
|
|
strError += "、" + dr["BLNO"].ToString().Trim();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
*/
|
|
|
#region 把【ch_fee】中与【仓储结算明细表[wms_settle_detail]】中关联的数据删除,因为添加锁定功能,则暂时屏蔽
|
|
|
//string strSql = "delete from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_detail where 1=1 " + DUIGID + strBLNOs + ")";
|
|
|
//int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【删除仓储结算关联表wms_settle_date】中数据【ISDELETE】设为【1】
|
|
|
|
|
|
//strSql = "update wms_settle_list set ISDELETE=1,DELETEUSER='" + strUserID +
|
|
|
// "',DELETETIME=getdate() where 1=1" + DUIGID;
|
|
|
string strSql = "delete from wms_settle_list where 1=1" + DUIGID;
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算关联表wms_settle_date】中数据【ISDELETE】设为【1】
|
|
|
//strSql = "update wms_settle_date set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where 1=1" + DUIGID + " and LINKGID //in (select GID_LINK from wms_settle_detail where ISDELETE=0 " + strBLNOs + ")";
|
|
|
|
|
|
//existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settle_detail】中数据【ISDELETE】设为【1】
|
|
|
//strSql = "update wms_settle_detail set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where 1=1 " + DUIGID + strBLNOs;
|
|
|
strSql = "delete from wms_settle_detail where 1=1 " + DUIGID + strBLNOs;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settle_detail】中数据【ISDELETE】设为【1】
|
|
|
strSql = "delete from wms_settle_detail_tmp where 1=1 " + DUIGID + strBLNOs;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
if (strError.Trim() != "")
|
|
|
{
|
|
|
strError = strError.Trim().Substring(1);
|
|
|
result.Success = false;
|
|
|
result.Message = "删除数据成功,但部分提单号" + strError + "已经有下一个阶段汇总的数据不允许删除!";
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = "删除数据成功";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public static DBResult Delete_Detail_Detail( string GID)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
|
|
|
List<ModelObjectBase> dataList = new List<ModelObjectBase>();
|
|
|
|
|
|
string strError = "";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settle_detail】中数据【ISDELETE】设为【1】
|
|
|
//strSql = "update wms_settle_detail set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where 1=1 " + DUIGID + strBLNOs;
|
|
|
string strSql = $"delete from wms_settle_detail where GID='{GID}'";
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settle_detail】中数据【ISDELETE】设为【1】
|
|
|
strSql = $"delete from wms_settle_detail_tmp where GID='{GID}'";
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "删除出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
if (strError.Trim() != "")
|
|
|
{
|
|
|
strError = strError.Trim().Substring(1);
|
|
|
result.Success = false;
|
|
|
result.Message = "删除数据成功,但部分提单号" + strError + "已经有下一个阶段汇总的数据不允许删除!";
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = true;
|
|
|
result.Message = "删除数据成功";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 费用入账
|
|
|
public static DBResult setislock(string gids, string strUserID, string strCompanyID, string strDEPTNAME)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
if (gids.Trim() == "")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
#region 权限操作范围
|
|
|
RangeDA RangeDA = new EntityDA.RangeDA();
|
|
|
string strRange = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modRptWmsSettlementListIndex");//仓储结算清单列表
|
|
|
if (strRange.Trim().Equals("0"))//全部
|
|
|
{
|
|
|
strRange = "";
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("1"))//分公司
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexCompany(strCompanyID.Trim());
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("2"))//部门
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexDEPT(strCompanyID, strUserID, strDEPTNAME);
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("3"))//个人
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexPerson(strCompanyID, strUserID);
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("4"))//无
|
|
|
{
|
|
|
strRange = " and 1<0";
|
|
|
}
|
|
|
else//空
|
|
|
{
|
|
|
strRange = " and 1<0";
|
|
|
}
|
|
|
#endregion
|
|
|
//
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
gids = "'" + gids.Trim().Replace(",","','") + "'";
|
|
|
|
|
|
#region 从【仓储结算明细临时表wms_settlement_detail】中提取数据,按提单号循环插入ch_Fee,因为添加锁定功能,则暂时屏蔽
|
|
|
string strSql = "insert into ch_fee(GID,BSNO,FEETYPE,FEENAME,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY,AMOUNT,EXCHANGERATE,CURRENCY,COMMISSIONRATE,FEEFRT,REMARK,ISADVANCEDPAY,ENTEROPERATOR,ENTERDATE,FEESTATUS,WMSOUTBSNO,LINENUM,[TAXRATE],[NOTAXAMOUNT],[TAX],[ORDERSETTLEMENT],[TAXUNITPRICE],[ORDERINVSETTLEMENT]) "
|
|
|
+ "select newid() as GID,bsno=(select top 1 bsno from V_op_bill where mblno=[wms_settlement_detail].blno),1,'仓储费',CUSTOMERNAME,'单票',sum(isnull(OUTFEE,0)),1,sum(isnull(OUTFEE,0)),1,'RMB',0,'PP',((select top 1 CONVERT(char(10), STARTBILLINGDATE, 20) AS STARTBILLINGDATE from wms_settlement_detail where blno=wms_settlement_detail.blno and STARTBILLINGDATE is not null and CORPID='" + strCompanyID + "' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in (" + gids + ")" + strRange + " order by STARTBILLINGDATE)+'至'+(select top 1 CONVERT(char(10), ENDBILLINGDATE, 20) AS ENDBILLINGDATE from wms_settlement_detail where blno=wms_settlement_detail.blno and ENDBILLINGDATE is not null and CORPID='" + strCompanyID + "' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in (" + gids + ")" + strRange + " order by ENDBILLINGDATE desc)+'仓储结算清单'+DUINO+'”中的单票仓储费汇总'),0,'" + strUserID + "',getdate(),1,DUIGID,LINENUM=(select top 1 LINENUM=isnull((select top 1 LINENUM from ch_fee where bsno=(select top 1 bsno from v_op_bill where mblno=[wms_settlement_detail].blno) and feetype=1 order by LINENUM desc),0)+1),0,sum(isnull(OUTFEE,0)),0,0,sum(isnull(OUTFEE,0)),0"
|
|
|
+ " from [wms_settlement_detail] where CORPID='" + strCompanyID + "' and ISLOCK=0 and ISDELETE=0 and isnull(OUTFEE,0)<>0 and DUIGID in (" + gids + ")" + strRange + " group by blno,CUSTOMERNAME,CREATEUSER,CORPID,DUINO,DUIGID";//CREATEUSER='" + strUserID + "' and
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settlement_detail】中的指定数据锁定
|
|
|
strSql = "update wms_settlement_detail set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where ISLOCK=0 and DUIGID in (" + gids + ")" + strRange;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算主表wms_settlement_detail_temp】中的指定数据锁定
|
|
|
strSql = "update wms_settlement_list set ISLOCK=1,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where ISLOCK=0 and gid in (" + gids + ")" + strRange;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "操作出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "操作成功!(注意如果用户权限不够,将不予以入账!)";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 取消入账
|
|
|
public static DBResult setnotlock(string gids, string strUserID, string strCompanyID, string strDEPTNAME)
|
|
|
{
|
|
|
DBResult result = new DBResult();
|
|
|
if (gids.Trim() == "")
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "没有输入任何需要修改的数据";
|
|
|
}
|
|
|
#region 权限操作范围
|
|
|
RangeDA RangeDA = new EntityDA.RangeDA();
|
|
|
string strRange = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modRptWmsSettlementListIndex");//仓储结算清单列表
|
|
|
if (strRange.Trim().Equals("0"))//全部
|
|
|
{
|
|
|
strRange = "";
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("1"))//分公司
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexCompany(strCompanyID.Trim());
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("2"))//部门
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexDEPT(strCompanyID, strUserID, strDEPTNAME);
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("3"))//个人
|
|
|
{
|
|
|
strRange = RangeDA.GetRptWmsSettlementListIndexPerson(strCompanyID, strUserID);
|
|
|
}
|
|
|
else if (strRange.Trim().Equals("4"))//无
|
|
|
{
|
|
|
strRange = " and 1<0";
|
|
|
}
|
|
|
else//空
|
|
|
{
|
|
|
strRange = " and 1<0";
|
|
|
}
|
|
|
#endregion
|
|
|
//
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
gids = "'" + gids.Trim().Replace(",", "','") + "'";
|
|
|
|
|
|
#region 判断【ch_fee】中的费用状态,是否允许取消入账
|
|
|
string sbool = "0";
|
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
|
//string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in(" + gids + ") " + strRange + ") and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
|
|
|
string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in(" + gids + ") " + strRange + ") and (ISINVOICE=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or (FEESTATUS<>1 and FEESTATUS<>6))";
|
|
|
sbool = T_ALL_DA.GetStrSQL("nums", ls);
|
|
|
if (sbool.Trim() == "0")
|
|
|
{
|
|
|
ls = "select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in(" + gids + ") " + strRange + "))";
|
|
|
sbool = T_ALL_DA.GetStrSQL("nums", ls);
|
|
|
if (sbool.Trim() != "0")
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "有“已申请开票、已开发票或已对帐”的费用,不允许取消入账,请重新操作!";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "有“已申请开票、已开发票、已对帐”的费用,不允许取消入账,请重新操作!";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 从【仓储结算明细临时表wms_settlement_detail】中提取数据,按提单号循环插入ch_Fee,因为添加锁定功能,则暂时屏蔽
|
|
|
string strSql = "delete from ch_fee where WMSOUTBSNO in (select gid from wms_settlement_list where ISLOCK=1 and gid in(" + gids + ") " + strRange + ")";
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算明细表wms_settlement_detail】中的指定数据锁定
|
|
|
strSql = "update wms_settlement_detail set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where ISLOCK=1 and DUIGID in (" + gids + ")" + strRange;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
#region 把【仓储结算主表wms_settlement_detail_temp】中的指定数据锁定
|
|
|
strSql = "update wms_settlement_list set ISLOCK=0,LOCKUSER='" + strUserID + "',LOCKTIME=getdate() where ISLOCK=1 and gid in (" + gids + ")" + strRange;
|
|
|
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
#endregion
|
|
|
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
sqlTran.Rollback();
|
|
|
result.Success = false;
|
|
|
result.Message = "入账出现错误,请重试或联系系统管理员";
|
|
|
return result;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
SqlHelper.CloseConnection();
|
|
|
sqlTran.Dispose();
|
|
|
}
|
|
|
}
|
|
|
result.Success = true;
|
|
|
result.Message = "入账数据成功";
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
}
|
|
|
}
|