|
|
|
|
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;
|
|
|
|
|
using DSWeb.MvcShipping.Models.MsCwVouchersGl;
|
|
|
|
|
using DSWeb.MvcShipping.Models.MsCwVouitemsGl;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.Import.Controllers
|
|
|
|
|
{
|
|
|
|
|
[JsonRequestBehavior]
|
|
|
|
|
public class CWAdvancePaymentController : Controller
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// GET: /Import/create
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /Import/create/Edit
|
|
|
|
|
public ActionResult Edit()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentResult GetDataList(int start, int limit, string sort, string condition)
|
|
|
|
|
{
|
|
|
|
|
var dataList = CWAdvancePaymentDAL.GetDataList(condition, Convert.ToString(Session["USERID"]).Trim());
|
|
|
|
|
|
|
|
|
|
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 GetDataListStr(string condition)
|
|
|
|
|
{
|
|
|
|
|
var dataListStr = CWAdvancePaymentDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]).Trim());
|
|
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr });
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
head.BLSTATUS = "新建";
|
|
|
|
|
/*自动填写接单审单人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 Delete(string data, string USERID)
|
|
|
|
|
{
|
|
|
|
|
var head = JsonConvert.Deserialize<CWAdvancePayment>(data);
|
|
|
|
|
|
|
|
|
|
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) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ContentResult LockList(string bills)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DBResult result = CWAdvancePaymentDAL.LockList(bills);
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(result);
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentResult UnLockList(string bills)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DBResult result = CWAdvancePaymentDAL.UnLockList(bills);
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(result);
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 生成凭证
|
|
|
|
|
public ContentResult CreateVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string data)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var modb = new ModelObjectDB();
|
|
|
|
|
DBResult result = CreateGLDCVoucher(VoucherDate, UsdExrate, User, useRate, data, Convert.ToString(Session["USERID"]));
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(User);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DBResult CreateJKDCVoucher(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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DBResult CreateGLDCVoucher(string VoucherDate, string UsdExrate, string User, string useRate, string fdata,string userid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var head = JsonConvert.Deserialize<CWAdvancePayment>(fdata);
|
|
|
|
|
var result = new DBResult();
|
|
|
|
|
result.Success = true;
|
|
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
|
|
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(userid);
|
|
|
|
|
string sSQL = "SELECT top 1 * from cw_design_gl where [STARTGID]='" + strCwSTARTGID + "' and DR<>'' and CR<>'' ";// and CORPID='"+companyid+"'
|
|
|
|
|
DataSet dsCwDesign = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
|
|
if (dsCwDesign == null)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = "请先设置帐套信息!" + result.Message;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
string strBPVW = dsCwDesign.Tables[0].Rows[0]["TVW"].ToString().Trim();
|
|
|
|
|
if (head.FEETYPE=="1"&&(dsCwDesign.Tables[0].Rows[0]["BRTW"].ToString().Trim()!="")) strBPVW = dsCwDesign.Tables[0].Rows[0]["BRTW"].ToString().Trim();//转帐凭证字
|
|
|
|
|
if (head.FEETYPE == "2" && (dsCwDesign.Tables[0].Rows[0]["BPVW"].ToString().Trim() != "")) strBPVW = dsCwDesign.Tables[0].Rows[0]["BPVW"].ToString().Trim();//转帐凭证字
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Decimal amt = 0;
|
|
|
|
|
var VouitemsList = new List<MsCwVouitemsGl>();
|
|
|
|
|
var VouOrdNo = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
decimal DebitAmt = Convert.ToDecimal(0.00);
|
|
|
|
|
decimal CreditAmt = Convert.ToDecimal(0.00);
|
|
|
|
|
int itemsno = 1;
|
|
|
|
|
MsCwVouchersGl Voucher = new MsCwVouchersGl();
|
|
|
|
|
|
|
|
|
|
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + head.BANKACCID + "'";
|
|
|
|
|
DataSet BankAccitems = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
|
|
|
|
|
|
|
if (BankAccitems == null&&BankAccitems.Tables[0].Rows[0]["ACCID"].ToString().Trim() == "" )
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = "单号:银行没有对应的财务科目!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MsCwVouitemsGl bankdata = new MsCwVouitemsGl();
|
|
|
|
|
bankdata.ACCID = BankAccitems.Tables[0].Rows[0]["ACCID"].ToString().Trim();
|
|
|
|
|
bankdata.ACCNAME = BankAccitems.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();
|
|
|
|
|
bankdata.ACCALL = BasicDataRefDAL.setCAGA(BankAccitems.Tables[0].Rows[0]["PACCGID"].ToString(), bankdata.ACCNAME.ToString().Trim());
|
|
|
|
|
bankdata.ORDNO = VouOrdNo;
|
|
|
|
|
bankdata.BLNO = head.BILLNO;
|
|
|
|
|
bankdata.EXPLAN = "预收付单号:" + head.BILLNO;
|
|
|
|
|
bankdata.ITEMNO = itemsno;
|
|
|
|
|
bankdata.ISSYS = true;
|
|
|
|
|
|
|
|
|
|
if (BankAccitems.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
|
|
|
|
|
{
|
|
|
|
|
bankdata.DC = "D";
|
|
|
|
|
}
|
|
|
|
|
else if (BankAccitems.Tables[0].Rows[0]["DC"].ToString().Trim() == "贷")
|
|
|
|
|
{
|
|
|
|
|
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 = dsCwDesign.Tables[0].Rows[0]["DR"].ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
custaccid = dsCwDesign.Tables[0].Rows[0]["DRFC"].ToString().Trim();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (head.FEETYPE == "2")
|
|
|
|
|
{
|
|
|
|
|
if (head.CURRENCY == "RMB")
|
|
|
|
|
{
|
|
|
|
|
custaccid = dsCwDesign.Tables[0].Rows[0]["CR"].ToString().Trim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
custaccid = dsCwDesign.Tables[0].Rows[0]["CRFC"].ToString().Trim();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sSQL = "SELECT top 1 * from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ACCID='" + custaccid + "'";
|
|
|
|
|
DataSet Accitems = T_ALL_DA.GetAllSQL(sSQL);
|
|
|
|
|
if (Accitems == null && Accitems.Tables[0].Rows[0]["ACCID"].ToString().Trim() == "")
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = "单号:" + head.BILLNO + "费用项目没有对应的财务科目!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var CustAccid = CwVouchersDAL.GetCustAccID(head.CUSTOMERNAME);
|
|
|
|
|
|
|
|
|
|
MsCwVouitemsGl data = new MsCwVouitemsGl();
|
|
|
|
|
|
|
|
|
|
data.ACCID = Accitems.Tables[0].Rows[0]["ACCID"].ToString().Trim();
|
|
|
|
|
data.ACCNAME = Accitems.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();
|
|
|
|
|
data.ORDNO = VouOrdNo;
|
|
|
|
|
data.BLNO = head.BILLNO;
|
|
|
|
|
data.EXPLAN = Accitems.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();
|
|
|
|
|
data.ITEMNO = itemsno;
|
|
|
|
|
data.ISSYS = true;
|
|
|
|
|
if (Accitems.Tables[0].Rows[0]["DC"].ToString().Trim()== "借")
|
|
|
|
|
{
|
|
|
|
|
data.DC = "D";
|
|
|
|
|
}
|
|
|
|
|
else if (Accitems.Tables[0].Rows[0]["DC"].ToString().Trim() == "贷")
|
|
|
|
|
{
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
data.ISDEPTACC = Boolean.Parse(Accitems.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
|
|
|
|
|
data.ISEMPLACC = Boolean.Parse(Accitems.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
|
|
|
|
|
data.ISCORPACC = Boolean.Parse(Accitems.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
|
|
|
|
|
data.ISITEMACC = Boolean.Parse(Accitems.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
|
|
|
|
|
data.ACCALL = BasicDataRefDAL.setCAGA(Accitems.Tables[0].Rows[0]["PACCGID"].ToString(), data.ACCNAME.ToString().Trim()) + "▁" + data.CUSTOMERNAME;
|
|
|
|
|
|
|
|
|
|
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.ToString("yyyy-MM-dd");
|
|
|
|
|
Voucher.VKNO = strBPVW;
|
|
|
|
|
Voucher.AMTDR = DebitAmt;
|
|
|
|
|
Voucher.AMTCR = CreditAmt;
|
|
|
|
|
string strVOUNOhj = DSWeb.MvcShipping.DAL.MsBaseInfoDAL.MsBaseInfoDAL.GetCwVOUNO(strBPVW, strCwACCDATE, userid);
|
|
|
|
|
string[] items = strVOUNOhj.Trim().Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
string strVOUNO = items[3].ToString().Trim();
|
|
|
|
|
string cfVOUALLNO = Voucher.VKNO + DateTime.Parse(Voucher.VOUDATE.ToString()).Year.ToString() + Voucher.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
|
|
|
|
|
Voucher.VOUNO = int.Parse(cfVOUALLNO.Substring(cfVOUALLNO.Length - 4)).ToString();
|
|
|
|
|
Voucher.VOUALLNO = cfVOUALLNO.Replace("记", strBPVW);
|
|
|
|
|
Voucher.ATTACHS =1;
|
|
|
|
|
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
|
|
|
|
|
Voucher.STARTGID = strCwSTARTGID;
|
|
|
|
|
Voucher.DbOperationType = DbOperationType.DbotIns;
|
|
|
|
|
Voucher.CREATEUSER =userid;//创建人
|
|
|
|
|
Voucher.CREATETIME = DateTime.Now;//创建时间
|
|
|
|
|
Voucher.MODIFIEDUSER =userid;//最后一次更新操作人
|
|
|
|
|
Voucher.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
|
|
|
|
|
var modb = new ModelObjectDB();
|
|
|
|
|
result = modb.Save(Voucher);
|
|
|
|
|
if (result.Success == true)
|
|
|
|
|
{
|
|
|
|
|
int n = 1;
|
|
|
|
|
foreach (var enumValue in VouitemsList)
|
|
|
|
|
{
|
|
|
|
|
enumValue.GID = Guid.NewGuid().ToString();
|
|
|
|
|
enumValue.ITEMNO = n;
|
|
|
|
|
enumValue.DbOperationType = DbOperationType.DbotIns;
|
|
|
|
|
var modb2 = new ModelObjectDB();
|
|
|
|
|
DBResult result2 = modb2.Save(enumValue);
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
string blSQL = "INSERT INTO [cw_vouno_bs_gl]([GID],[BSTABLENAME],[BSGID],[VOUALLNO],[ORDNO],[STARTGID],[CREATEUSER],[CREATETIME])"
|
|
|
|
|
+ " VALUES(newid(),'ch_fee_advance_payment','" + head.BILLNO + "','" + cfVOUALLNO + "','"+ VouOrdNo + "','" + strCwSTARTGID + "','" + userid + "',getdate())";
|
|
|
|
|
bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
|
|
|
|
|
|
|
|
|
|
blSQL = "update code_fill_serialno set ISDELETE=1,DELETEUSER='" + userid + "',DELETETIME=GETDATE() where TABLENAME='cw_vouchers_gl' and SERIALNO='" + cfVOUALLNO + "' and STARTGID='" + strCwSTARTGID + "'";
|
|
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
|
|
|
|
|
|
|
|
|
|
blSQL = "update ch_fee_advance_payment set ISVOU=1,VOUCHERNO='" + cfVOUALLNO + "' where BILLNO='"+head.BILLNO+"'";
|
|
|
|
|
bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//else {
|
|
|
|
|
// string blSQL = "delete from [cw_vouno_bs_gl] where VOUALLNO='" + cfVOUALLNO + "' and BSTABLENAME='ch_fee_advance_payment' and [STARTGID]='" + strCwSTARTGID + "'";
|
|
|
|
|
// bool bl = T_ALL_DA.GetExecuteSqlCommand(blSQL);
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|