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.
535 lines
21 KiB
C#
535 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using DSWeb.Areas.TruckMng.Models.Comm;
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
using DSWeb.Areas.Import.DAL.CW;
|
|
using DSWeb.Areas.Import.Models.CWAdvancePayment;
|
|
using DSWeb.TruckMng.Comm.Cookie;
|
|
using DSWeb.TruckMng.Helper;
|
|
using DSWeb.TruckMng.Helper.Repository;
|
|
using DSWeb.Areas.TruckMng.DAL.Comm; //引用chfee的module
|
|
using DSWeb.Areas.Import.Models.CwVouchers;
|
|
using DSWeb.Areas.Import.Models.CwVouitems;
|
|
using DSWeb.Areas.Import.Models.CwDesign;
|
|
using DSWeb.Areas.Import.Models.CWAccitems;
|
|
using DSWeb.Areas.Import.DAL.CwVouchersDAL;
|
|
using HcUtility.Comm;
|
|
using HcUtility.Core;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using System.Text;
|
|
using System.Data;
|
|
using DSWeb.EntityDA;
|
|
|
|
namespace DSWeb.Areas.Import.Controllers
|
|
{
|
|
[JsonRequestBehavior]
|
|
public class ImportAdvancePaymentController : Controller
|
|
{
|
|
//
|
|
// GET: /Import/create
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
//
|
|
// GET: /Import/create/Edit
|
|
public ActionResult Edit()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ContentResult GetDataList_Import(int start, int limit, string sort, string condition)
|
|
{
|
|
var dataList = CWAdvancePaymentDAL.GetDataList_Import(condition);
|
|
|
|
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)
|
|
{
|
|
CWAdvancePayment head = null;
|
|
|
|
if (handle == "edit")
|
|
{
|
|
var list = CWAdvancePaymentDAL.GetDataList(condition, Convert.ToString(Session["USERID"]).Trim());
|
|
if (list.Count > 0)
|
|
head = list[0];
|
|
}
|
|
|
|
if (head == null)
|
|
{
|
|
head = new CWAdvancePayment();
|
|
}
|
|
|
|
var json = JsonConvert.Serialize(
|
|
new { Success = true, Message = "查询成功", data = head });
|
|
return new ContentResult() { Content = json };
|
|
}
|
|
|
|
public ContentResult GetBodyList(string condition)
|
|
{
|
|
var dataList = CWAdvancePaymentDAL.GetBodyList(condition);
|
|
|
|
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)
|
|
{
|
|
var head = JsonConvert.Deserialize<CWAdvancePayment>(data);
|
|
|
|
if (opstatus == "add")
|
|
{
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
head.ModelUIStatus = "I";
|
|
|
|
head.GID = PubSysDAL.GetBillNo("0204");
|
|
|
|
head.LINKGID = head.GID;
|
|
head.BILLNO = head.GID;
|
|
/*自动填写接单审单人id
|
|
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
|
|
headData.UserName = CookieConfig.GetCookie_UserName(Request);
|
|
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
|
|
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
|
|
|
|
//headData.LrDate = DateTime.Now;
|
|
}
|
|
else if (opstatus == "edit")
|
|
{
|
|
head.DbOperationType = DbOperationType.DbotUpd;
|
|
head.ModelUIStatus = "E";
|
|
}
|
|
else
|
|
{
|
|
head.DbOperationType = DbOperationType.DbotDel;
|
|
}
|
|
|
|
var modb = new ModelObjectRepository();
|
|
DBResult result = modb.Save(head);
|
|
|
|
//刷新父窗口上的父节点
|
|
var jsonRespose = new JsonResponse
|
|
{
|
|
Success = result.Success,
|
|
Message = result.Message,
|
|
Data = CWAdvancePaymentDAL.GetData(" GID='" + head.GID + "'", Convert.ToString(Session["USERID"]).Trim())
|
|
};
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
}
|
|
|
|
public ContentResult SaveBody ( string YSYFNO, string Body, string DelBody )
|
|
{
|
|
var head = CWAdvancePaymentDAL.GetData(" billno='" + YSYFNO + "' ", Convert.ToString(Session["USERID"]).Trim());
|
|
|
|
var BodyList = JsonConvert.Deserialize<List<CWAdvancePaymentBody_Edit>>(Body);
|
|
var BodyDelList = JsonConvert.Deserialize<List<CWAdvancePaymentBody_Edit>>(DelBody);
|
|
|
|
var modb = new ModelObjectRepository();
|
|
DBResult result = modb.SaveComm("LINKGID", YSYFNO,
|
|
ModelObjectConvert<CWAdvancePaymentBody_Edit>.ToModelObjectList(BodyList),
|
|
ModelObjectConvert<CWAdvancePaymentBody_Edit>.ToModelObjectList(BodyDelList)
|
|
);
|
|
|
|
//刷新父窗口上的父节点
|
|
var jsonRespose = new JsonResponse
|
|
{
|
|
Success = result.Success,
|
|
Message = result.Message,
|
|
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
|
|
};
|
|
|
|
//重新计算剩余金额
|
|
CWAdvancePaymentDAL.ResetDoamount(YSYFNO);
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
}
|
|
|
|
|
|
public ContentResult Delete(string data, string USERID)
|
|
{
|
|
var head = JsonConvert.Deserialize<CWAdvancePayment>(data);
|
|
|
|
var modb = new ModelObjectDB();
|
|
DBResult result = modb.Delete(head, USERID,true
|
|
, "delete from SalesAdvancePay_state where AD_BILLNO='" + head.BILLNO + "'");
|
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
/* var head = JsonConvert.Deserialize<CWAdvancePayment>(data);
|
|
|
|
var _Bodylist= CWAdvancePaymentDAL.GetBodyList(head.BILLNO);
|
|
if (_Bodylist.Count() > 0)
|
|
{
|
|
var jsonRespose1 = new JsonResponse { Success = false, Message = "此预收已经被核销,不能删除" };
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
|
|
}
|
|
else
|
|
{
|
|
|
|
var _Statelist = ImportSalesDAL.GetSalesStateDataList("AD_BILLNO='" + head.BILLNO + "'");
|
|
if (_Statelist.Count() > 0)
|
|
{
|
|
var jsonRespose1 = new JsonResponse { Success = false, Message = "此预收已经进行认款,不能删除" };
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
|
|
}
|
|
else {
|
|
var modb = new ModelObjectDB();
|
|
DBResult result = modb.Delete(head, USERID, true);
|
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
}
|
|
}*/
|
|
}
|
|
|
|
#region 生成凭证
|
|
public ContentResult CreateVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string data)
|
|
{
|
|
|
|
var modb = new ModelObjectDB();
|
|
DBResult result = CreateDCVoucher(VoucherDate, UsdExrate, User, useRate, data);
|
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
}
|
|
|
|
|
|
public static DBResult CreateDCVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string fdata)
|
|
{
|
|
|
|
var head = JsonConvert.Deserialize<CWAdvancePayment>(fdata);
|
|
var result = new DBResult();
|
|
result.Success = true;
|
|
Decimal amt =0;
|
|
var VouitemsList = new List<CwVouitems>();
|
|
var VouOrdNo = Guid.NewGuid().ToString();
|
|
CwDesign CWDesign = CwVouchersDAL.GetCwDesign();
|
|
if (CWDesign.DR == "" || CWDesign.DR == null || (CWDesign.CR == "" || CWDesign.CR == null) || CWDesign.DRFC == "" || CWDesign.DRFC == null || (CWDesign.CRFC == "" || CWDesign.CRFC == null))
|
|
{
|
|
result.Success = false;
|
|
result.Message = "请先设置帐套信息,才能生成凭证!";
|
|
}
|
|
else
|
|
{
|
|
decimal DebitAmt = Convert.ToDecimal(0.00);
|
|
decimal CreditAmt = Convert.ToDecimal(0.00);
|
|
int itemsno = 1;
|
|
CwVouchers Voucher = new CwVouchers();
|
|
var BankAccitems = CwVouchersDAL.GetCwAccitems(head.BANKACCID);
|
|
if (BankAccitems.ACCID == "" || BankAccitems.ACCID == null)
|
|
{
|
|
result.Success = false;
|
|
result.Message = "单号:银行没有对应的财务科目!";
|
|
}
|
|
|
|
CwVouitems bankdata = new CwVouitems();
|
|
bankdata.ACCID = BankAccitems.ACCID;
|
|
bankdata.ACCNAME = BankAccitems.ACCNAME;
|
|
bankdata.ORDNO = VouOrdNo;
|
|
bankdata.BLNO = head.BILLNO;
|
|
bankdata.EXPLAN = "预收付单号:" + head.BILLNO;
|
|
bankdata.ITEMNO = itemsno;
|
|
bankdata.ISSYS = true;
|
|
|
|
if (BankAccitems.DC == "借")
|
|
{
|
|
bankdata.DC = "D";
|
|
}
|
|
else if (BankAccitems.DC == "贷")
|
|
{
|
|
bankdata.DC = "C";
|
|
}
|
|
|
|
if (head.FEETYPE == "1")
|
|
{
|
|
if (head.CURRENCY== "RMB")
|
|
{
|
|
bankdata.AMTDR = Convert.ToDecimal(head.AMOUNT);
|
|
bankdata.AMTCR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYCR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYDR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYEXRATE = Convert.ToDecimal(1);
|
|
bankdata.FCYNO = "RMB";
|
|
DebitAmt = DebitAmt + Convert.ToDecimal(head.AMOUNT);
|
|
|
|
}
|
|
else
|
|
{
|
|
if (useRate == "1")
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(head.EXCHANGERATE);
|
|
}
|
|
else
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(UsdExrate);
|
|
|
|
};
|
|
|
|
bankdata.AMTDR = Convert.ToDecimal((amt).ToString("0.00"));
|
|
bankdata.AMTCR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYCR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYDR = Convert.ToDecimal(head.AMOUNT);
|
|
bankdata.FCYEXRATE = Convert.ToDecimal(head.EXCHANGERATE);
|
|
bankdata.FCYNO = "USD";
|
|
DebitAmt = DebitAmt + Convert.ToDecimal((amt).ToString("0.00"));
|
|
}
|
|
}
|
|
else if (head.FEETYPE == "2")
|
|
{
|
|
if (head.CURRENCY == "RMB")
|
|
{
|
|
bankdata.AMTDR = Convert.ToDecimal(0.00);
|
|
bankdata.AMTCR = Convert.ToDecimal(head.AMOUNT);
|
|
bankdata.FCYCR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYDR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYEXRATE = Convert.ToDecimal(1);
|
|
bankdata.FCYNO = "RMB";
|
|
CreditAmt = CreditAmt + Convert.ToDecimal(head.AMOUNT);
|
|
|
|
}
|
|
else
|
|
{
|
|
if (useRate == "1")
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(head.EXCHANGERATE);
|
|
}
|
|
else
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(UsdExrate);
|
|
|
|
};
|
|
|
|
bankdata.AMTDR = Convert.ToDecimal(0.00);
|
|
bankdata.AMTCR = Convert.ToDecimal((amt).ToString("0.00"));
|
|
bankdata.FCYCR = Convert.ToDecimal(head.AMOUNT);
|
|
bankdata.FCYDR = Convert.ToDecimal(0.00);
|
|
bankdata.FCYEXRATE = Convert.ToDecimal(head.EXCHANGERATE);
|
|
bankdata.FCYNO = "USD";
|
|
CreditAmt = CreditAmt + Convert.ToDecimal((amt).ToString("0.00"));
|
|
}
|
|
|
|
}
|
|
itemsno = itemsno + 1;
|
|
VouitemsList.Add(bankdata);
|
|
|
|
var custaccid="";
|
|
if (head.FEETYPE == "1")
|
|
{
|
|
if (head.CURRENCY == "RMB")
|
|
{
|
|
custaccid=CWDesign.DR;
|
|
} else {
|
|
custaccid=CWDesign.DRFC;
|
|
|
|
}
|
|
}
|
|
else if (head.FEETYPE == "2")
|
|
{
|
|
if (head.CURRENCY == "RMB")
|
|
{
|
|
custaccid=CWDesign.CR;
|
|
} else {
|
|
custaccid=CWDesign.CRFC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
var Accitems = CwVouchersDAL.GetCwAccitems(custaccid);
|
|
if (Accitems.ACCID == "")
|
|
{
|
|
result.Success = false;
|
|
result.Message = "单号:" + head.BILLNO + "费用项目没有对应的财务科目!";
|
|
}
|
|
|
|
var CustAccid=CwVouchersDAL.GetCustAccID(head.CUSTOMERNAME);
|
|
|
|
CwVouitems data = new CwVouitems();
|
|
|
|
data.ACCID = Accitems.ACCID;
|
|
data.ACCNAME = Accitems.ACCNAME;
|
|
data.ORDNO = VouOrdNo;
|
|
data.BLNO = head.BILLNO;
|
|
data.EXPLAN = Accitems.ACCNAME;
|
|
data.ITEMNO = itemsno;
|
|
data.ISSYS = true;
|
|
if (Accitems.DC == "借")
|
|
{
|
|
data.DC = "D";
|
|
}
|
|
else if (Accitems.DC == "贷")
|
|
{
|
|
data.DC = "C";
|
|
}
|
|
|
|
if (head.FEETYPE == "2")
|
|
{
|
|
if (head.CUSTOMERNAME != "")
|
|
{
|
|
if (CustAccid.FAPCODE == "")
|
|
{
|
|
result.Success = false;
|
|
result.Message = "单号:客户没有设置对应的财务代码!";
|
|
}
|
|
else
|
|
{
|
|
data.CORPID = CustAccid.FAPCODE;
|
|
data.CUSTOMERNAME = head.CUSTOMERNAME;
|
|
}
|
|
}
|
|
|
|
|
|
if (head.CURRENCY == "RMB")
|
|
{
|
|
data.AMTDR = Convert.ToDecimal(head.AMOUNT);
|
|
data.AMTCR = Convert.ToDecimal(0.00);
|
|
data.FCYCR = Convert.ToDecimal(0.00);
|
|
data.FCYDR = Convert.ToDecimal(0.00);
|
|
data.FCYEXRATE = Convert.ToDecimal(1);
|
|
data.FCYNO = "RMB";
|
|
DebitAmt = DebitAmt + Convert.ToDecimal(head.AMOUNT);
|
|
|
|
}
|
|
else
|
|
{
|
|
if (useRate == "1")
|
|
{
|
|
amt=Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(head.EXCHANGERATE);
|
|
}
|
|
else
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(UsdExrate);
|
|
|
|
};
|
|
|
|
data.AMTDR = Convert.ToDecimal((amt).ToString("0.00"));
|
|
data.AMTCR = Convert.ToDecimal(0.00);
|
|
data.FCYCR = Convert.ToDecimal(0.00);
|
|
data.FCYDR = Convert.ToDecimal(head.AMOUNT);
|
|
data.FCYEXRATE = Convert.ToDecimal(head.EXCHANGERATE);
|
|
data.FCYNO = "USD";
|
|
DebitAmt = DebitAmt + Convert.ToDecimal((amt).ToString("0.00"));
|
|
|
|
}
|
|
}
|
|
else if (head.FEETYPE == "1")
|
|
{
|
|
|
|
if (head.CUSTOMERNAME != "")
|
|
{
|
|
if (CustAccid.FARCODE == "")
|
|
{
|
|
result.Success = false;
|
|
result.Message = "单号:客户没有设置对应的财务代码!";
|
|
}
|
|
else
|
|
{
|
|
data.CORPID = CustAccid.FARCODE;
|
|
data.CUSTOMERNAME = head.CUSTOMERNAME;
|
|
}
|
|
}
|
|
|
|
if (head.CURRENCY == "RMB")
|
|
{
|
|
data.AMTDR = Convert.ToDecimal(0.00);
|
|
data.AMTCR = Convert.ToDecimal(head.AMOUNT);
|
|
data.FCYCR = Convert.ToDecimal(0.00);
|
|
data.FCYDR = Convert.ToDecimal(0.00);
|
|
data.FCYEXRATE = Convert.ToDecimal(1);
|
|
data.FCYNO = "RMB";
|
|
CreditAmt = CreditAmt + Convert.ToDecimal(head.AMOUNT);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if (useRate == "1")
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(head.EXCHANGERATE);
|
|
}
|
|
else
|
|
{
|
|
amt = Convert.ToDecimal(head.AMOUNT) * Convert.ToDecimal(UsdExrate);
|
|
|
|
};
|
|
|
|
data.AMTDR = Convert.ToDecimal(0.00);
|
|
data.AMTCR = Convert.ToDecimal((amt).ToString("0.00"));
|
|
data.FCYCR =Convert.ToDecimal(head.AMOUNT);
|
|
data.FCYDR = Convert.ToDecimal(0.00);
|
|
data.FCYEXRATE = Convert.ToDecimal(head.EXCHANGERATE);
|
|
data.FCYNO = "USD";
|
|
CreditAmt = CreditAmt + Convert.ToDecimal((amt).ToString("0.00"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemsno = itemsno + 1;
|
|
VouitemsList.Add(data);
|
|
|
|
|
|
Voucher.ORDNO = VouOrdNo;
|
|
var voudate = Convert.ToDateTime(VoucherDate);
|
|
Voucher.ACCYEAR = voudate.ToString("yyyy");
|
|
Voucher.ACCMONTH = voudate.ToString("MM");
|
|
Voucher.PREPARED = User;
|
|
Voucher.VOUDATE = voudate;
|
|
Voucher.VKNO = CWDesign.TVW;
|
|
Voucher.AMTDR = DebitAmt;
|
|
Voucher.AMTCR = CreditAmt;
|
|
|
|
//帐套设置
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
DataSet dsCwDesign = T_ALL_DA.GetAllSQL("SELECT top 1 * from cw_design");
|
|
if (dsCwDesign == null)
|
|
{
|
|
result.Success = false;
|
|
result.Message = "没有设置账套信息!";
|
|
}
|
|
|
|
Voucher.VOUNO = CwVouchersDAL.getVOUNO(dsCwDesign, Voucher.ACCYEAR, Voucher.ACCMONTH);
|
|
Voucher.VOUALLNO = Voucher.ACCYEAR + Voucher.ACCMONTH + Voucher.VOUNO;
|
|
Voucher.ATTACHS = CWDesign.AFFIXNO;
|
|
Voucher.FCY = "";
|
|
Voucher.QTY = "";//是否含有数量科目="";//varchar="";//(1)
|
|
Voucher.VOUPROP = "";//凭证属性="";//varchar="";//(1)
|
|
Voucher.CHECKED = "";//审核人="";//varchar="";//(10)
|
|
Voucher.ENTERED = "";//记账人="";//varchar="";//(10)
|
|
Voucher.ERRMSG = "";//错误信息="";//varchar="";//(6)
|
|
Voucher.ISDELETE = false;//是否废除="";//bit="";//Y
|
|
Voucher.DELETEUSER = "";//废除操作人="";//Varchar(36)="";//Y
|
|
|
|
|
|
var strSel = " AND BILLNO='"+head.BILLNO+"'";
|
|
if (result.Success)
|
|
{
|
|
result = CwVouchersDAL.InsertVoucher(Voucher, VouitemsList, "ch_fee_advance_payment", Voucher.VOUALLNO, strSel, User);
|
|
}
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 参照部分
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|