You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Account/Controllers/Chfee_invoiceController.cs

1173 lines
50 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_Invoice;
using DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication;
using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication;
using DSWeb.Areas.Account.Models.Chfee_Invoice;
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 System.IO;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Text;
using System.Data;
using InvokeWebService;
using DSWeb.Areas.Account.Models.RytInvoice;
using System.Xml.Serialization;
using System.Xml;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsInfoClient;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_invoiceController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
public ActionResult BLEdit()
{
return View();
}
public ActionResult AppEdit()
{
return View();
}
public ActionResult BookEdit()
{
return View();
}
public ActionResult BookIndex()
{
return View();
}
public ActionResult DetailView()
{
return View();
}
//
// GET
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
if (sort != null)
{
sort = sort.Replace("OPERATORNAME", "OPERATOR");
sort = sort.Replace("DELOPERATORNAME", "DELETEOPERATOR");
sort = sort.Replace("SALECORP", "SALECORPID");
sort = sort.Replace("INVOICECATEGORYREF", "INVOICECATEGORY");
sort = sort.Replace("INVOICETYPEREF", "INVOICETYPE");
sort = sort.Replace("APPLICANT", "(select top 1 (select ShowName from [user] where GID=ap.applicant) APPLICANT from ch_fee_invoiceapplication ap where invbillno=cm.BILLNO)");
}
var dataList = ChinvoiceDAL.GetDataList(start, limit,condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort);
int count = ChinvoiceDAL.getTotalCount(condition, CookieConfig.GetCookie_UserId(Request), 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 GetDataListStr(int start, int limit, string sort, string condition, int billtype)
{
var dataListStr = ChinvoiceDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition,bool isapp)
{
ChInvoice head = null;
if (handle == "edit" || handle == "copyadd")
{
var list = ChinvoiceDAL.GetDataList(0,1,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 ChInvoice();
}
if (handle == "add")
{
head.OPERATOR = Convert.ToString(Session["USERID"]);
head.OPERATORNAME = Convert.ToString(Session["SHOWNAME"]);
head.CREATEUSER = Convert.ToString(Session["USERID"]);
if (isapp)
{
head.INVOICETYPE = 2;
head.INVOICETYPEREF = "申请发票";
}
else {
head.INVOICETYPE = 1;
head.INVOICETYPEREF = "自由发票";
}
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetDetailList(string condition)
{
var dataList = ChinvoiceDAL.GetDetailList(condition);
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 = ChinvoiceDAL.GetBodyList(condition,sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetTruckBillList(string condition, string sort)
{
var dataList = ChinvoiceDAL.GetTruckBodyList(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 = ChinvoiceDAL.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 = ChinvoiceDAL.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 GetBillDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceDAL.GetAddBillList(start, limit,condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
int count = ChinvoiceDAL.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 GetTruckBillDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceDAL.GetAddTruckBillList(start, limit, condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
int count = ChinvoiceDAL.getAddTruckBillTotalCount(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 = ChinvoiceDAL.GetFeeDetailList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetAddSum(string condition)
{
var dataList = ChinvoiceDAL.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)
{
var headData = JsonConvert.Deserialize<ChInvoice>(data);
var bodyList = JsonConvert.Deserialize<List<ChInvoiceDetail>>(body);
if (opstatus == "add")
{
headData.GID = Guid.NewGuid().ToString();
headData.BILLNO = PubSysDAL.GetBillNo("0308");
headData.COMPANYID = Convert.ToString(Session["COMPANYID"]);
headData.OPERATOR = Convert.ToString(Session["USERID"]);
headData.OPERATETIME = DateTime.Now;
headData.CREATEUSER = Convert.ToString(Session["USERID"]);
headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (headData.INVOICECUSTNAME == "")
{
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,usdbank,usdaccount,TaxNo,Addr,Tel from info_client WHERE SHORTNAME='" + headData.CUSTOMERNAME + "'");
if (dsHSCODE != null)
{
if (dsHSCODE.Tables[0].Rows.Count > 0)
{
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 == "")
{
headData.CUSTBANK = dsHSCODE.Tables[0].Rows[0]["Rmbbank"].ToString();
}
}
}
}
if (!string.IsNullOrEmpty(headData.RECVCURR) && string.IsNullOrEmpty(headData.CUSTBANK) && !string.IsNullOrEmpty(headData.CUSTOMERNAME))
{
var bankList = MsInfoClientDAL.GetBankList("LINKID in (select GID FROM info_client WHERE SHORTNAME='" + headData.CUSTOMERNAME + "')");
if (bankList != null && bankList.Count != 0)
{
foreach (var bank in bankList)
{
if ((bank.CURRENCY == headData.RECVCURR) && (bank.ISINVDEF == "1"))
headData.CUSTBANK = bank.BANKNAME_ACCOUNT;
}
}
}
var isPost = true;
var errorstr = "";
if (headData.INVOICENO != "")
{
var ct = ChinvoiceDAL.GetRdCount("GID<>'" + headData.GID + "' AND INVOICENO='" + headData.INVOICENO + "' and COMPANYID='" + Convert.ToString(Session["COMPANYID"]) + "'");
if (ct != 0)
{
isPost = false;
errorstr = "发票号";
}
}
if (isPost)
{
if (headData.INVOICEMAKETIME == "") headData.INVOICEMAKETIME = null;
if (headData.ETD == "") headData.ETD = null;
headData.CUSTRATENO = headData.CUSTRATENO.Trim();
headData.CUSTBANK = headData.CUSTBANK.Trim();
headData.REMARK = headData.REMARK.Trim();
var BILLNO = headData.BILLNO;
var modb = new ModelObjectDB();
DBResult result = ChinvoiceDAL.SaveInvDetail(headData.GID, bodyList);
if (result.Success == true)
{
result = modb.Save(headData);
ChinvoiceDAL.UpdateInvNoUse(headData.INVOICENO, Convert.ToString(Session["USERID"]),headData.BILLNO);
if (headData.EXCHANGERATE != 0)
{
ChinvoiceDAL.updateFeeTax(headData.BILLNO, headData.EXCHANGERATE);
}
};
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ChinvoiceDAL.GetData(" BILLNO='" + BILLNO + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult AddDetail(string bill, string data, string curr,bool islist,string GID,string invoiceno)
{
var bodyList = JsonConvert.Deserialize<List<BillChfeeDetail>>(data);
var headdata = ChinvoiceDAL.GetData(" BILLNO='" + bill + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
var modb = new ModelObjectDB();
DBResult result = ChinvoiceDAL.AddDetail(bill, bodyList, curr, Convert.ToString(Session["COMPANYID"]), islist, GID,headdata);
if (result.Success) { ChinvoiceDAL.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 bill, string feesql, string storeCurrExrate, bool islist, string GID, bool custgroup = false)
{
var headData = JsonConvert.Deserialize<ChInvoice>(bill);
var exrateList = JsonConvert.Deserialize<List<ChFeeExrate>>(storeCurrExrate);
if ((exrateList == null) || (exrateList.Count == 0))
{
exrateList = ChinvoiceDAL.GetCurrExrateData(headData.CUSTOMERNAME, headData.CURRENCY, feesql, custgroup);
if (exrateList.Count == 0)
{
var modb = new ModelObjectDB();
DBResult result = ChinvoiceDAL.AddBill(headData, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID, Convert.ToString(Session["USERID"]), custgroup);
if (result.Success) { ChinvoiceDAL.p_update_Amount(headData.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();
DBResult result = ChinvoiceDAL.AddBill(headData, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID, Convert.ToString(Session["USERID"]));
if (result.Success) { ChinvoiceDAL.p_update_Amount(headData.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 = ChinvoiceDAL.DelFeeDo(bodyList,GID);
if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//
public ContentResult Delete(string data)
{
var headData = JsonConvert.Deserialize<ChInvoice>(data);
DBResult result;
var isfee = ChinvoiceDAL.GetStCount("PAYBILLNO='" + headData.BILLNO + "'");
if (isfee!=0)
{
var jsonRespose2 = new JsonResponse { Success =false, Message ="已发票结算,不允许删除发票" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
if (headData.INVOICETYPE == 2)
{
var dataList = ChinvoiceapplicationDAL.GetDataListAll("INVBILLNO='"+headData.BILLNO+"'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request),Convert.ToString(Session["COMPANYID"]));
result = ChinvoiceDAL.DelAppList(dataList,headData.BILLNO);
}
else {
var dataList = ChinvoiceDAL.GetBodyList("BILLNO='" + headData.BILLNO + "'");
result = ChinvoiceDAL.DelFeeDo(dataList, headData.GID);
}
if (result.Success == true)
{
var modb = new ModelObjectDB();
modb.Delete(headData);
ChinvoiceDAL.UpdateInvNoCancelUse(headData.INVOICENO);
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.INVOICENO + '(' + 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 DeleteUp(string data)
{
var headData = JsonConvert.Deserialize<ChInvoice>(data);
DBResult result;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
var strCT = T_ALL_DA.GetStrSQL("CT", "select COUNT(*) CT from ch_fee_do_payapplication where PAYBILLNO='" + headData.BILLNO + "'");
if (strCT != "0" && strCT != "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "已发票结算,不允许作废" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
if (headData.INVOICETYPE == 2)
{
var dataList = ChinvoiceapplicationDAL.GetDataListAll("INVBILLNO='" + headData.BILLNO + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
result = ChinvoiceDAL.DelAppList(dataList, headData.BILLNO);
}
else
{
var dataList = ChinvoiceDAL.GetBodyList("BILLNO='" + headData.BILLNO + "'");
result = ChinvoiceDAL.DelFeeDo(dataList,headData.GID);
}
if (result.Success == true)
{
ChinvoiceDAL.UpdateDelete(headData.BILLNO, Convert.ToString(Session["USERID"]));
ChinvoiceDAL.UpdateInvNoDelete(headData.INVOICENO, Convert.ToString(Session["USERID"]));
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CancelDeleteUp(string data)
{
var headData = JsonConvert.Deserialize<ChInvoice>(data);
DBResult result;
result = ChinvoiceDAL.UpdateDelete(headData.BILLNO, Convert.ToString(Session["USERID"]),false);
if (result.Success == true)
{
ChinvoiceDAL.UpdateInvNoDelete(headData.INVOICENO, Convert.ToString(Session["USERID"]),false);
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetInvoiceNo(string condition)
{
var dataList = ChinvoiceDAL.GetInvoiceNo(Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
#region 发票申请添加
public ContentResult AddAppDetail(string bill, string data, string invoiceno, string GID)
{
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.GetDataInvList(" 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 modb = new ModelObjectDB();
DBResult result = ChinvoiceDAL.AddAppDetail(bill, dataList, invoiceno, Convert.ToString(Session["COMPANYID"]), GID);
if (result.Success) { ChinvoiceDAL.p_update_Amount(bill, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.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 DelAppBill(string data, string billno, string GID)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoiceapplication>>(data);
DBResult result = ChinvoiceDAL.DelAppList(bodyList,billno);
if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); }
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 = ChinvoiceDAL.DelInvDetail(bodyList);
if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
//public ContentResult UpdateCustInvHead(string data)
//{
// var headdata = JsonConvert.Deserialize<ChInvoice>(data);
// var result = new DBResult();
// Database db = DatabaseFactory.CreateDatabase();
// using (var conn = db.CreateConnection())
// {
// conn.Open();
// var tran = conn.BeginTransaction();
// try
// {
// var strSql = new StringBuilder();
// strSql.Append("update info_client set CODENAME=CODENAME ");
// if (headdata.INVOICECUSTNAME!="")
// strSql.Append(",BillRises1='"+headdata.INVOICECUSTNAME+"'");
// if (headdata.CUSTRATENO != "")
// strSql.Append(",TaxNo='" + headdata.CUSTRATENO + "'");
// if (headdata.CUSTADDRTEL != "")
// strSql.Append(",BillRises1='" + headdata.CUSTADDRTEL + "'");
// strSql.Append(" where BSNO=@BSNO ");
// tran.Commit();
// }
// catch (Exception)
// {
// tran.Rollback();
// result.Success = false;
// result.Message = "修改出现错误,请重试或联系系统管理员";
// return result;
// }
// }
// result.Success = true;
// result.Message = "修改成功" + result.Message;
// var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//}
#region 锁定和撤销锁定
public ContentResult Lock(string bill)
{
DBResult result = ChinvoiceDAL.Lock(bill, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult UnLock(string bill)
{
DBResult result = ChinvoiceDAL.UnLock(bill, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult LockList(string bills)
{
DBResult result = ChinvoiceDAL.LockList(bills, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult UnLockList(string bills)
{
DBResult result = ChinvoiceDAL.UnLockList(bills, Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
#endregion
public ContentResult ExpInv(string bills)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoice>>(bills);
var path = Server.MapPath("../../EDIFiles/ExportInv");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//
var result = new DBResult();
var filename = "";
filename = ChinvoiceDAL.CreateInvList(bodyList, path);
if (filename != "")
{
//result.Data = "../../EDIFiles/ExportInv/" + filename;
result.Data =filename;
filename = Path.GetFileName(filename);
result.Success = true;
result.Message = filename;
}
else
{
result.Success = false;
result.Message = "无当前匹配的导出文件!";
}
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ExpDZInv(string bills)
{
var bodyList = JsonConvert.Deserialize<List<ChInvoice>>(bills);
var path = Server.MapPath("../../EDIFiles/ExportInv");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//
var result = new DBResult();
var filename = "";
filename = ChinvoiceDAL.CreateDZInvList(bodyList, path, Convert.ToString(Session["COMPANYID"]));
if (filename != "")
{
//result.Data = "../../EDIFiles/ExportInv/" + filename;
result.Data = filename;
filename = Path.GetFileName(filename);
result.Success = true;
result.Message = filename;
}
else
{
result.Success = false;
result.Message = "无当前匹配的导出文件!";
}
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ExpInvForm(string bill)
{
var bodyList = ChinvoiceDAL.GetDataList(0,1,"BILLNO='"+bill+"'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
var path = Server.MapPath("../../EDIFiles/ExportInv");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//
var result = new DBResult();
var filename = "";
filename = ChinvoiceDAL.CreateInvList(bodyList, path);
if (filename != "")
{
result.Data = filename;
filename = Path.GetFileName(filename);
result.Success = true;
result.Message = filename;
}
else
{
result.Success = false;
result.Message = "无当前匹配的导出文件!";
}
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ExpDZInvForm(string bill)
{
var bodyList = ChinvoiceDAL.GetDataList(0, 1, "BILLNO='" + bill + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]));
var path = Server.MapPath("../../EDIFiles/ExportInv");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//
var result = new DBResult();
var filename = "";
filename = ChinvoiceDAL.CreateDZInvList(bodyList, path, Convert.ToString(Session["COMPANYID"]));
if (filename != "")
{
result.Data = filename;
filename = Path.GetFileName(filename);
result.Success = true;
result.Message = filename;
}
else
{
result.Success = false;
result.Message = "无当前匹配的导出文件!";
}
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ExpRYDInv(string gid,string email)
{
var bodyList = ChinvoiceDAL.GetDataList(0, 1,"cm.GID='"+gid+"'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); ;
var path = Server.MapPath("../../EDIFiles/ExportInv");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var error = "";
if (bodyList == null) {
var jsonerror = JsonConvert.Serialize(new { Success = false, Message ="请登录后重试!" });
return new ContentResult() { Content = jsonerror };
}
if (email == "")
{ error = error + "<br />客户邮箱不能为空!"; }
//
var result = new DBResult();
var INVACCOUNT = MsSysParamSetDAL.GetData("PARAMNAME='INVACCOUNT'").PARAMVALUE;
var INVPSW = MsSysParamSetDAL.GetData("PARAMNAME='INVPSW'").PARAMVALUE;
if (INVACCOUNT == "")
{ error = error + "<br />电子发票用户ID不能为空"; }
if (INVPSW == "")
{ error = error + "<br />电子发票用户秘钥不能为空"; }
if (bodyList[0].INVOICECUSTNAME=="")
{ error = error + "<br />发票抬头不能为空"; }
if (bodyList[0].CUSTRATENO == "")
{ error = error + "<br />客户纳税识别号不能为空"; }
if (bodyList[0].CUSTBANK == "")
{ error = error + "<br />客户开户行及账号不能为空"; }
var banklist = bodyList[0].CUSTBANK.Split(' ');
if (banklist.Length!= 2)
{
{ error = error + "<br />客户开户行及账号不完整"; }
}
if (bodyList[0].ACCOUNT == "")
{ error = error + "<br />销货方银行及账号不能为空"; }
var banklist2 = bodyList[0].ACCOUNT.Split('-');
if (banklist.Length != 2)
{
{ error = error + "<br />销货方银行及账号不完整"; }
}
if (bodyList[0].CURRENCY == "")
{ error = error + "<br />发票币别不能为空"; }
if (bodyList[0].AMOUNT ==0)
{ error = error + "<br />开票金额不能为0"; }
if (error != "")
{
var jsonerror = JsonConvert.Serialize(new { Success = false, Message = error });
return new ContentResult() { Content = jsonerror };
}
var filename = "";
filename = ChinvoiceDAL.CreateInvRYORDERTList(bodyList, path,"", INVACCOUNT, INVPSW);
if (filename != "")
{
filename = filename.Replace("<Request xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">","<Request version=\"1.3\">");
ServiceReference1.WebInterFace neworder = new ServiceReference1.WebInterFace();
var returnstr = AES.AesDecrypt(neworder.V1_OP_NewOrder(AES.AesEncrypt(filename)));
//string[] args = new string[1];
//args[0] = AES.AesEncrypt(filename);
//object resultXml = WebServiceHelper.InvokeWebService("http://z23242k066.imwork.net/WebService/WebInterFace.asmx", "V1_OP_NewOrder", args);
//var returnstr = AES.AesDecrypt(resultXml.ToString());
returnstr = returnstr.Replace(" version=\"2.1\"", "").Replace("\0", "").Replace("\r\n", "");
returnstr = returnstr.Substring(39);
returnstr = @"<?xml version=""1.0""?>" + returnstr;
//XmlDocument xobj = new XmlDocument();
//xobj.LoadXml(returnstr);
//returnstr = ChinvoiceDAL.Xml2String(xobj);
StringReader rdr = new StringReader(returnstr.Trim());
XmlSerializer serializer = new XmlSerializer(typeof(Response));
Response xmlDoc = (Response)serializer.Deserialize(rdr);
if (xmlDoc.Head.Code == "000000")
{
// ChinvoiceDAL.UpInvListDZStauts(bodyList,"已发订单");
var Xmlexpenses = xmlDoc.OrderBody.expenses;
List<Xmlexpense> expenses = Xmlexpenses.expenses;
var returninvstr= ChinvoiceDAL.CreateInvRYTList(bodyList, path, "",expenses, INVACCOUNT, INVPSW,email);
returninvstr = returninvstr.Replace("Xmlinvoice", "Request");
returninvstr = returninvstr.Replace("<Request xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">", "<Request version=\"1.3\">");
returnstr = AES.AesDecrypt(neworder.V1_OP_DrawInvoice(AES.AesEncrypt(returninvstr)));
//args[0] = AES.AesEncrypt(returninvstr);
//resultXml = WebServiceHelper.InvokeWebService("http://z23242k066.imwork.net/WebService/WebInterFace.asmx", "V1_OP_DrawInvoice", args);
//returnstr = AES.AesDecrypt(resultXml.ToString());
returnstr = returnstr.Replace(" version=\"2.1\"", "").Replace("\0", "").Replace("\r\n", "");
returnstr = returnstr.Substring(39);
returnstr = @"<?xml version=""1.0""?>" + returnstr;
StringReader rdr2 = new StringReader(returnstr.Trim());
XmlSerializer serializer2 = new XmlSerializer(typeof(Response));
Response xmlDoc2 = (Response)serializer.Deserialize(rdr2);
if (xmlDoc2.Head.Code == "000000")
{
ChinvoiceDAL.UpInvListDZStauts(bodyList, "已开票");
result.Success = true;
result.Message = returnstr;
}
else {
var delorderstr= new StringBuilder();
delorderstr.Append("<?xml version=\"1.0\" encoding=\"utf - 8\"?>");
delorderstr.Append("<Request version=\"1.3\">");
delorderstr.Append("<head>");
delorderstr.Append("<PbAccount>"+ INVACCOUNT + "</PbAccount>");
delorderstr.Append("<PbPassWord>" + INVPSW + "</PbPassWord>");
delorderstr.Append("<ReCode>OP03</ReCode>");
delorderstr.Append("<SerialNo>"+ Guid.NewGuid().ToString() + "</SerialNo>");
delorderstr.Append("<PostTime>"+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</PostTime>");
delorderstr.Append("</head>");
delorderstr.Append("<body>");
delorderstr.Append("<orders>");
delorderstr.Append("<order>");
delorderstr.Append("<order_id>" + xmlDoc.OrderBody.OrderDetail.order_id + "</order_id>");
delorderstr.Append("</order>");
delorderstr.Append("</orders>");
delorderstr.Append("</body>");
delorderstr.Append("</Request>");
returnstr = AES.AesDecrypt(neworder.V1_OP_DeleteOrder(AES.AesEncrypt(delorderstr.ToString())));
result.Success = false;
result.Message = xmlDoc2.Head.Message;
}
}
else {
result.Success = false;
result.Message = xmlDoc.Head.Message;
}
//result.Data = returnstr;
//filename = Path.GetFileName(filename);
}
else
{
result.Success = false;
result.Message = "无当前匹配的导出文件!";
}
//
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpdatePrint(string billno)
{
DBResult result = ChinvoiceDAL.UpdatePrint(billno);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 发票模板
public ContentResult GetRemarksTemplate(string TemplateName)
{
DBResult result = ChinvoiceDAL.GetRemarksTemplate(Convert.ToString(Session["COMPANYID"]), TemplateName);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message,Data=result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveRemarksTemplate(string Template,string TemplateName)
{
DBResult result = ChinvoiceDAL.SaveRemarksTemplate(Template, Convert.ToString(Session["COMPANYID"]), TemplateName);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetRemarksData(string billno, string TemplateName,string invdate="",bool isapp=false)
{
var dataList = ChinvoiceDAL.GetBsList("c.BILLNO='" + billno + "'");
DBResult result = ChinvoiceDAL.GetRemarksData(dataList, Convert.ToString(Session["COMPANYID"]), billno, TemplateName, invdate,isapp);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 发票票册
public ContentResult GetBookDataList(int start, int limit, string sort, string condition)
{
var dataList = ChinvoiceDAL.GetBookDataList(condition, 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 GetBookData(string handle, string condition)
{
ChInvoiceBook head = null;
if (handle == "edit")
{
var list = ChinvoiceDAL.GetBookDataList(condition, Convert.ToString(Session["COMPANYID"]));
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new ChInvoiceBook();
}
if (handle == "add")
{
head.CREATEUSER = Convert.ToString(Session["USERID"]);
head.CREATEUSERREF = Convert.ToString(Session["SHOWNAME"]);
head.COMPANYID = Convert.ToString(Session["COMPANYID"]);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult SaveBook(string opstatus, string data)
{
var headData = JsonConvert.Deserialize<ChInvoiceBook>(data);
if (opstatus == "add")
{
headData.GID = Guid.NewGuid().ToString();
headData.COMPANYID = Convert.ToString(Session["COMPANYID"]);
headData.CREATEUSER = Convert.ToString(Session["USERID"]);
headData.CREATETIME = DateTime.Now.ToString();
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (headData.TYPE == "") headData.TYPE ="0";
var BILLNO = headData.GID;
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = ChinvoiceDAL.GetBookData(" GID='" + BILLNO + "'", Convert.ToString(Session["COMPANYID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteBook(string data)
{
var headData = JsonConvert.Deserialize<ChInvoiceBook>(data);
var isfee = ChinvoiceDAL.GetMakeOutCount(headData.GID);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票册已有开出发票,不允许删除!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
DBResult result;
var modb = new ModelObjectDB();
result = modb.Delete(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult CreateBookitems(string data)
{
var headData = JsonConvert.Deserialize<ChInvoiceBook>(data);
DBResult result = ChinvoiceDAL.CreateBookitems(headData, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult LockBookitems(string data)
{
var headData = JsonConvert.Deserialize<List<ChInvoiceBookdetail>>(data);
DBResult result = ChinvoiceDAL.LockBookitems(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CancelLockBookitems(string data)
{
var headData = JsonConvert.Deserialize<List<ChInvoiceBookdetail>>(data);
DBResult result = ChinvoiceDAL.CancelLockBookitems(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetBookitemsDataList(string condition, string sort)
{
var dataList = ChinvoiceDAL.GetBookitemsDataList(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult DeleteUpBook(string data)
{
var headData = JsonConvert.Deserialize<ChInvoiceBook>(data);
DBResult result;
result = ChinvoiceDAL.DeleteUpBook(headData.GID, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 参照部分
#endregion
}
}