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

523 lines
23 KiB
C#

This file contains ambiguous Unicode characters!

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

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication;
using DSWeb.Areas.Account.Models.Chfee_do_detail;
using DSWeb.Areas.Account.Models.BillChfeeDetail;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using System.Collections.Generic;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.EntityDA;
using DSWeb.Areas.Account.Models.Chfee_Exrate;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using System.Data;
using DSWeb.MvcShipping.DAL.MsCodeGoodInv;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_invoiceapplicationController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
public ActionResult BLEdit()
{
return View();
}
//付费申请审核
public ActionResult Audit()
{
return View();
}
//
// GET
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceapplicationDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetAuditDataList(int start, int limit, string sort, string condition, string isaudit)
{
var dataList = ChinvoiceapplicationDAL.GetAuditDataList(condition, Convert.ToString(Session["USERID"]), isaudit, Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
ChInvoiceapplication head = null;
if (handle == "edit")
{
var list = ChinvoiceapplicationDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new ChInvoiceapplication();
}
if (handle == "add")
{
head.APPLICANT = CookieConfig.GetCookie_CompanyId(Request);
head.APPLICANTNAME =CookieConfig.GetCookie_UserName(Request);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetDetailList(string condition,string sort)
{
var dataList = ChinvoiceapplicationDAL.GetDetailList(condition,sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBillList(string condition,string sort)
{
var dataList = ChinvoiceapplicationDAL.GetBodyList(condition,sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBillDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceapplicationDAL.GetAddBillList(start, limit,condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
int count = ChinvoiceapplicationDAL.getAddBillTotalCount(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetFeeDetailList(string sort, string condition)
{
var dataList = ChinvoiceapplicationDAL.GetFeeDetailList(condition,sort);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBillSum(string condition)
{
var dataList = ChinvoiceapplicationDAL.GetBodySumList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetFeeDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceapplicationDAL.GetFeeDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetAddSum(string condition)
{
var dataList = ChinvoiceapplicationDAL.GetAddSum(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string body,bool issubmit=false)
{
var headData = JsonConvert.Deserialize<ChInvoiceapplication>(data);
var bodyList = JsonConvert.Deserialize<List<ChInvoiceDetail>>(body);
if (opstatus == "add")
{
headData.GID = Guid.NewGuid().ToString();
//headData.BILLNO = PubSysDAL.GetBillNo("0306");
headData.COMPANYID = CookieConfig.GetCookie_CompanyId(Request);
headData.APPLICANT = CookieConfig.GetCookie_UserId(Request);
// headData.APPLYTIME = DateTime.Now;
headData.ENTERTIME = DateTime.Now;
headData.DbOperationType = DbOperationType.DbotIns;
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='发票申请'", CookieConfig.GetCookie_CompanyId(Request));
if (billnoset.BILLTYPE != "")
headData.BILLNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.APPLYTIME.ToString().Trim(), headData.ENTERTIME.ToString());
else
headData.BILLNO = PubSysDAL.GetBillNo("0306");
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet dsHSCODE = T_ALL_DA.GetAllSQL("SELECT Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION],RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='USD' AND LINKID=info_client.GID) usdbank,usdaccount,TaxNo,Addr,Tel from info_client WHERE SHORTNAME='" + headData.CUSTOMERNAME + "'");
if (dsHSCODE != null)
{
if (dsHSCODE.Tables[0].Rows.Count > 0)
{
if (headData.INVOICECUSTNAME == "")
{
if (dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString() != "")
headData.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString();
else headData.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["DESCRIPTION"].ToString();
}
if (headData.CUSTRATENO == "") headData.CUSTRATENO = dsHSCODE.Tables[0].Rows[0]["TaxNo"].ToString();
if (headData.CUSTADDRTEL == "") {
if (dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString() != "")
headData.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString();
else headData.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["Addr"].ToString() + " " + dsHSCODE.Tables[0].Rows[0]["Tel"].ToString();
}
if (headData.CUSTBANK == "")
{
if (headData.RECVCURR == "USD")
{
headData.CUSTBANK = dsHSCODE.Tables[0].Rows[0]["usdbank"].ToString();
}
else headData.CUSTBANK = dsHSCODE.Tables[0].Rows[0]["rmbbank"].ToString();
}
}
}
var BILLNO = headData.BILLNO;
var GID = headData.GID;
var modb = new ModelObjectDB();
DBResult result = ChinvoiceapplicationDAL.SaveInvDetail(headData.GID,bodyList);
if (result.Success==true){
result= modb.Save(headData);
};
if (result.Success == true) { }
else
{
MsSysBillNoSetDAL.DeleteBsNo(headData.BILLNO);
}
if ((result.Success == true)&&(issubmit==true)) {
result = ChinvoiceapplicationDAL.SubmitAudit("InvAudit", CookieConfig.GetCookie_UserId(Request), headData.BILLNO);
}
// if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(BILLNO, GID); }
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ChinvoiceapplicationDAL.GetData(" BILLNO='" + BILLNO + "'", CookieConfig.GetCookie_UserId(Request), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_CompanyId(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddDetail(string bill, string data, string curr, bool islist, string GID, bool custgroup = false)
{
var bodyList = JsonConvert.Deserialize<List<BillChfeeDetail>>(data);
var headData = ChinvoiceapplicationDAL.GetData(" BILLNO='" + bill + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
var BLCOUNT="0";
var FEENOAUDITCANTSHENINV = MsSysParamSetDAL.GetData("PARAMNAME='FEENOAUDITCANTSHENINV'");
if (FEENOAUDITCANTSHENINV.PARAMVALUE == "1")
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
BLCOUNT = T_ALL_DA.GetStrSQL("BLCOUNT", "select COUNT(*) BLCOUNT from ch_fee where FEETYPE=1 and (FEESTATUS=1 OR FEESTATUS=2 ) and BSNO='" + bodyList[0].BSNO + "'");
}
if (BLCOUNT != "0")
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票存在未审核的应收费用,不允许申请发票!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var modb = new ModelObjectDB();
DBResult result = ChinvoiceapplicationDAL.AddDetail(bill, bodyList, curr, Convert.ToString(Session["COMPANYID"]), islist, GID, headData);
if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(bill, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult AddBill(string billno, string billcust, string billcurr, string feesql, string storeCurrExrate, bool islist, string GID, bool custgroup = false)
{
var exrateList = JsonConvert.Deserialize<List<ChFeeExrate>>(storeCurrExrate);
if (islist) {
var bodylist = ChinvoiceapplicationDAL.GetFeeDetailList(feesql + " and '代理'+FEENAME NOT IN (Select GOODNAME from code_goods_inv) ");
if (bodylist.Count != 0) {
var feenamelist = "";
if (bodylist != null)
{
foreach (var enumValue in bodylist)
{
feenamelist = feenamelist + enumValue.FeeName+",";
}
}
if (feenamelist != "") {
var jsonRespose = new JsonResponse { Success = false, Message = "费用名称:"+feenamelist+"不在发票商品明细中,请先维护发票商品明细!"};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}
if ((exrateList == null) || (exrateList.Count == 0))
{
exrateList = ChinvoiceapplicationDAL.GetCurrExrateData(billcust, billcurr, feesql, custgroup);
if (exrateList.Count == 0)
{
var modb = new ModelObjectDB();
var headData = ChinvoiceapplicationDAL.GetData(" BILLNO='" + billno + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
DBResult result = ChinvoiceapplicationDAL.AddBill(billno, billcust, billcurr, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID,headData, custgroup );
if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(billno, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = true, Message = "查询成功", Data = exrateList.ToList() };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
else
{
var modb = new ModelObjectDB();
var headData = ChinvoiceapplicationDAL.GetData(" BILLNO='" + billno + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
DBResult result = ChinvoiceapplicationDAL.AddBill(billno, billcust, billcurr, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID, headData);
if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(billno, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DelBill(string data, string billno,string GID)
{
var bodyList = JsonConvert.Deserialize<List<Chfee_do_detail>>(data);
DBResult result = ChinvoiceapplicationDAL.DelFeeDo(bodyList,GID);
if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(billno,GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetIsAdd(string data)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoiceapplication>>(data);
var StrGid = "";
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (StrGid == "")
StrGid = "'" + enumValue.GID + "'";
else
StrGid = StrGid + ",'" + enumValue.GID + "'";
}
}
if (StrGid != "")
{
StrGid = "(" + StrGid + ")";
var dataList = ChinvoiceapplicationDAL.GetDataList(" BILLSTATUS=0 and GID IN " + StrGid, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
if (dataList != null && dataList.Count != 0)
{
var jsonRespose = new JsonResponse { Success =true, Message ="可以生成!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = "发票申请已生成发票,请刷新!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = "无需要添加的发票申请!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
//
public ContentResult Delete(string data)
{
var headData = JsonConvert.Deserialize<ChInvoiceapplication>(data);
var dataList = ChinvoiceapplicationDAL.GetBodyList("BILLNO='" + headData.BILLNO + "'");
DBResult result = ChinvoiceapplicationDAL.DelFeeDo(dataList,headData.GID);
if (result.Success == true)
{
var modb = new ModelObjectDB();
modb.Delete(headData);
MsSysBillNoSetDAL.DeleteBsNo(headData.BILLNO);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var blUpSQL = " insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) values(NEWID(),'" + headData.BILLNO + "','删除发票申请','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + headData.BILLNO + '(' + headData.CUSTOMERNAME + ')' + "','" + Convert.ToString(Session["USERID"]) + "')";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelInvDetail(string billno, string body, string GID)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoiceDetail>>(body);
DBResult result = ChinvoiceapplicationDAL.DelInvDetail(bodyList);
if (result.Success) { ChinvoiceapplicationDAL.p_update_Amount(billno, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 提交和撤销审核
public ContentResult SubmitAudit(string bill)
{
//DBResult result = ChinvoiceapplicationDAL.SubmitAudit("InvAudit", Convert.ToString(Session["DEPTGID"]), Convert.ToString(Session["USERID"]), bill);
DBResult result = ChinvoiceapplicationDAL.SubmitAudit("InvAudit", Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBack(string bill)
{
DBResult result = ChinvoiceapplicationDAL.SubmitAuditBack("InvAudit", Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditList(string bills)
{
DBResult result = ChinvoiceapplicationDAL.SubmitAuditList("InvAudit", Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBackList(string bills)
{
DBResult result = ChinvoiceapplicationDAL.SubmitAuditBackList("InvAudit", Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult AuditList(string data, string PAYCOMPANYID)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoiceapplication>>(data);
DBResult result = ChinvoiceapplicationDAL.AuditList(bodyList,PAYCOMPANYID,Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AuditBackList(string data)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoiceapplication>>(data);
DBResult result = ChinvoiceapplicationDAL.AuditBackList(bodyList, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 参照部分
#endregion
}
}