|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
|
|
using DSWeb.MvcShipping.Comm.Cookie;
|
|
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
|
|
using DSWeb.Areas.RptMng.Comm;
|
|
|
|
|
using HcUtility.Comm;
|
|
|
|
|
using HcUtility.Core;
|
|
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
|
|
using DSWeb.EntityDA;
|
|
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
|
using DSWeb.Areas.Account.Models.BSNOLB;
|
|
|
|
|
using DSWeb.Areas.Account.Models.MsOpBill;
|
|
|
|
|
using DSWeb.MvcShipping.Models.MonthDataSet;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.Account.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 月末结账
|
|
|
|
|
/// </summary>
|
|
|
|
|
[JsonRequestBehavior]
|
|
|
|
|
public class Account_MonthLockController : Controller
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// GET:
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult FeeLockIndex()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Chfee_lockDetail()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET:
|
|
|
|
|
|
|
|
|
|
public ContentResult BsListData(int start, int limit, string condition,string sort,string type,string printstr)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
var strDa ="CORPID='"+Convert.ToString(Session["COMPANYID"])+"'";
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strDa))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
|
|
{
|
|
|
|
|
condition = condition + " and " + strDa;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
condition = strDa;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT B.BSNO, B.OPLB, B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS,B.FEESTATUS,B.SALE, B.OP, B.DOC");
|
|
|
|
|
strSql.Append(",case B.BSSTATUS when 1 then '已锁定' else '未锁定' end as BSSTATUSREF");
|
|
|
|
|
strSql.Append(",case B.FEESTATUS when 1 then '已锁定' else '未锁定' end as FEESTATUSREF");
|
|
|
|
|
strSql.Append(",case B.ETD when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.ETD,23) end as ETD");
|
|
|
|
|
strSql.Append(",case B.OPDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.OPDATE,23) end as OPDATE,B.ENTERP");
|
|
|
|
|
strSql.Append(",case B.CUSTOMDATE when '1900-01-01 00:00:00.000' then '' else CONVERT(varchar(100), B.CUSTOMDATE,23) end as CUSTOMDATE");
|
|
|
|
|
strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.NETWEIGHT,B.KGS,B.TEU,B.CNTRTOTAL,B.CORPID");
|
|
|
|
|
strSql.Append(",B.CNTR1,B.CNTR2,B.CNTR3,B.CNTR4,B.CNTR5,B.CNTR6,B.CNTR7,B.CNTR8,B.CNTR9,B.CNTR10,B.OTCNTR,B.TRADETYPE,B.GOODSNAME,B.FEESTATUS");
|
|
|
|
|
strSql.Append(",G.RMBDR,G.RMBCR,G.STLRMBDR,G.STLRMBCR,G.USDDR,G.USDCR,G.STLUSDDR,G.STLUSDCR,G.OTDR,G.OTCR,G.STLOTDR,G.STLOTCR,G.TTLDR,G.TTLCR,G.STLTTLDR,G.STLTTLCR");
|
|
|
|
|
strSql.Append(",G.USDDR-G.USDCR AS USDPROFIT,G.RMBDR-G.RMBCR AS RMBPROFIT,G.OTDR-G.OTCR AS OTPROFIT,G.TTLDR-G.TTLCR AS TTLPROFIT ");
|
|
|
|
|
strSql.Append(", (CASE WHEN (G.TTLCR)= 0 THEN '无法计算' ELSE ltrim(str((G.TTLDR-G.TTLCR) / (G.TTLCR) * 100, 10, 2)) + '%' END) AS PROFITRATE");
|
|
|
|
|
strSql.Append(" FROM V_OP_BILL B ");
|
|
|
|
|
strSql.Append("LEFT JOIN v_op_gain_sum G ON (G.BSNO=B.BSNO) ");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" Where " + condition);
|
|
|
|
|
}
|
|
|
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
|
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" order by " + sortstring);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
strSql.Append(" order by B.CUSTOMERNAME,B.OPLB,B.CREATETIME DESC");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var jsonRespose = new JsonResponse
|
|
|
|
|
{
|
|
|
|
|
Success = true,
|
|
|
|
|
Message = "完成",
|
|
|
|
|
Data = strSql.ToString()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var dbparams = new List<CustomDbParamter>();
|
|
|
|
|
|
|
|
|
|
var paramps_sSQL = new CustomDbParamter();
|
|
|
|
|
paramps_sSQL.ParameterName = "@sSQL";
|
|
|
|
|
paramps_sSQL.DbType = DbType.String;
|
|
|
|
|
paramps_sSQL.Direction = ParameterDirection.Input;
|
|
|
|
|
paramps_sSQL.Value = strSql.ToString();
|
|
|
|
|
dbparams.Add(paramps_sSQL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
|
|
|
|
|
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetRangDAStr(string tb,string type, string userid, string usercode, string companyid)
|
|
|
|
|
{
|
|
|
|
|
string str = "";
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
|
|
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
|
|
//strSql.Append(" where [NAME]='modBlockBSSTATUS' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
|
|
|
|
if (type == "BS")
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where [NAME]='modBlockBSSTATUS' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
}
|
|
|
|
|
else if (type == "FEE")
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where [NAME]='modBlockFEESTATUS' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
|
|
string operaterange = "4";
|
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
if (visiblerange == "4")
|
|
|
|
|
{
|
|
|
|
|
str = "1=2";
|
|
|
|
|
}
|
|
|
|
|
else if (visiblerange == "3")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "')";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (visiblerange == "2")
|
|
|
|
|
{
|
|
|
|
|
if (tb == "index")
|
|
|
|
|
{
|
|
|
|
|
var rangeDa = new RangeDA();
|
|
|
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
|
|
|
var userstr = new StringBuilder();
|
|
|
|
|
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
|
|
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
|
|
{
|
|
|
|
|
str = "";
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (str == "")
|
|
|
|
|
{
|
|
|
|
|
str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
str =str+ ")";
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
str = " UPPER(B.Corpid)='" + companyid + "'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (visiblerange == "1")
|
|
|
|
|
{
|
|
|
|
|
str = " UPPER(B.Corpid)='" + companyid + "'";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public List<MsOpBill> GetFeeDataList(string strCondition,string userid,string username,string companyid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var rangstr = GetRangDAStr("index","FEE",userid,username,companyid);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{
|
|
|
|
|
strCondition = strCondition + " and " + rangstr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strCondition = rangstr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
|
|
strSql.Append("BSNO,OPLB,OPLBNAME,ACCDATE,MBLNO,HBLNO,CUSTNO");
|
|
|
|
|
strSql.Append(",CUSTOMERNAME");
|
|
|
|
|
strSql.Append(",VESSEL,VOYNO,ETD,PORTLOAD");
|
|
|
|
|
strSql.Append(",PORTDISCHARGE,INPUTBY,OP,CUSTSERVICE");
|
|
|
|
|
strSql.Append(",DOC,SALE,BSSTATUS,FEESTATUS");
|
|
|
|
|
strSql.Append(" from v_op_bill b ");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strSql.Append(" order by BsNo");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SetFeeData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<MsOpBill> SetFeeData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<MsOpBill>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
MsOpBill data = new MsOpBill();
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
|
|
if (reader["ETD"] != DBNull.Value)
|
|
|
|
|
data.ETD = Convert.ToString(reader["ETD"]);
|
|
|
|
|
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
|
|
|
|
|
data.OPLB = Convert.ToString(reader["OPLB"]);
|
|
|
|
|
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
|
|
|
|
|
data.MBLNO = Convert.ToString(reader["MBLNO"]);
|
|
|
|
|
data.HBLNO = Convert.ToString(reader["HBLNO"]);
|
|
|
|
|
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
|
|
|
|
|
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
|
|
|
|
|
data.VESSEL = Convert.ToString(reader["VESSEL"]);
|
|
|
|
|
data.VOYNO = Convert.ToString(reader["VOYNO"]);
|
|
|
|
|
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
|
|
|
|
|
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
|
|
|
|
|
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
|
|
|
|
|
data.OP = Convert.ToString(reader["OP"]);
|
|
|
|
|
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
|
|
|
|
|
data.DOC = Convert.ToString(reader["DOC"]);
|
|
|
|
|
data.SALE = Convert.ToString(reader["SALE"]);
|
|
|
|
|
|
|
|
|
|
data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]);
|
|
|
|
|
data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 应月末结账期间
|
|
|
|
|
|
|
|
|
|
public ContentResult GetMonthsData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var dataList = GetMonthList(Convert.ToString(Session["COMPANYID"]));
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(
|
|
|
|
|
new { Success = true, Message = "查询成功", data = dataList });
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public MonthDataSet GetMonthList(string companyid)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT TOP 1 PERIOD,PYEAR,PMONTH,CLOSED from sys_Period");
|
|
|
|
|
strSql.Append(" Where COMPANYID='" + companyid + "'");
|
|
|
|
|
strSql.Append(" ORDER BY PERIOD DESC ");
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
var evList = new List<MonthDataSet>();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
var evData = new MonthDataSet();
|
|
|
|
|
var period = Convert.ToString(reader["PERIOD"]);
|
|
|
|
|
DateTime dt = DateTime.ParseExact(period+"-01", "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
|
|
|
|
|
dt = dt.AddMonths(1);
|
|
|
|
|
evData.MONTHNAME = dt.ToString("yyyy-MM");
|
|
|
|
|
evList.Add(evData);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (evList.Count > 0)
|
|
|
|
|
return evList[0];
|
|
|
|
|
var evData2 =new MonthDataSet();
|
|
|
|
|
evData2.MONTHNAME="2014-01";
|
|
|
|
|
return evData2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DBResult MonthClose(string monthdate, string companyid)
|
|
|
|
|
{
|
|
|
|
|
var result = new DBResult();
|
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (var conn = db.CreateConnection())
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cmdInsert =
|
|
|
|
|
db.GetSqlStringCommand(
|
|
|
|
|
@"insert into sys_Period (PERIOD,PYEAR,PMONTH,CLOSED,COMPANYID)
|
|
|
|
|
values (@PERIOD,@PYEAR,@PMONTH,@CLOSED,@COMPANYID) ");
|
|
|
|
|
|
|
|
|
|
var cmdDelete =
|
|
|
|
|
db.GetSqlStringCommand(
|
|
|
|
|
@"delete from sys_Period where period=@period and companyid=@companyid");
|
|
|
|
|
cmdDelete.Parameters.Clear();
|
|
|
|
|
db.AddInParameter(cmdDelete, "@period", DbType.String,monthdate);
|
|
|
|
|
db.AddInParameter(cmdDelete, "@companyid", DbType.String, companyid);
|
|
|
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmdInsert.Parameters.Clear();
|
|
|
|
|
db.AddInParameter(cmdInsert, "@PERIOD", DbType.String, monthdate);
|
|
|
|
|
//db.AddInParameter(cmdInsert, "@PYEAR", DbType.Int16, );
|
|
|
|
|
//db.AddInParameter(cmdInsert, "@PMONTH", DbType.Int16,);
|
|
|
|
|
db.AddInParameter(cmdInsert, "@CLOSED", DbType.String, "T");
|
|
|
|
|
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
|
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = new DBResult();
|
|
|
|
|
result.Success = true;
|
|
|
|
|
result.Message = "成功";
|
|
|
|
|
tran.Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
tran.Rollback();
|
|
|
|
|
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
|
|
result.Message = "保存成功";
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|