Commit 476f545b by guanzhenshan

增加导出会计凭证功能

parent 2055af13
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.Report
{
/// <summary>
/// 平台的凭证对应配置
/// </summary>
public class mPlatformAccountingSetting
{
/// <summary>
/// 平台类型
/// </summary>
public string platform_type { get; set; }
/// <summary>
/// 凭证ID
/// </summary>
public string cert_id { get; set; }
/// <summary>
/// 制单人
/// </summary>
public string creator { get; set; }
/// <summary>
/// 科目编码
/// </summary>
public string subject_no { get; set; }
/// <summary>
/// 客户编码
/// </summary>
public string customer_no { get; set; }
/// <summary>
/// 站点
/// </summary>
public string website { get; set; }
/// <summary>
/// 币种
/// </summary>
public string currency { get; set; }
/// <summary>
/// 币种名称
/// </summary>
public string currencyname { get; set; }
}
/// <summary>
/// 财务分类科目编码对应配置
/// </summary>
public class mFinanceCategorySubjectNo
{
/// <summary>
/// 财务分类名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 科目编码
/// </summary>
public string subject_no { get; set; }
}
/// <summary>
/// 获取资金系统每月的汇率
/// </summary>
public class mFundExchangRate
{
public string currency { get; set; }
public decimal? exchange_rate { get; set; }
}
public class FundExchangRate_Response
{
public int code { get; set; }
public string msg { get; set; }
public int count { get; set; }
public List<mFundExchangRate> data { get; set; }
}
}
...@@ -5,6 +5,7 @@ using System.Data; ...@@ -5,6 +5,7 @@ using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bailun.DC.Models; using Bailun.DC.Models;
using Bailun.DC.Models.Report;
using Bailun.ServiceFabric.Authorize; using Bailun.ServiceFabric.Authorize;
using Bailun.ServiceFabric.Core.Extension; using Bailun.ServiceFabric.Core.Extension;
using Bailun.ServiceFabric.Core.Extension.HttpContext; using Bailun.ServiceFabric.Core.Extension.HttpContext;
...@@ -10160,7 +10161,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -10160,7 +10161,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
website = "", website = "",
financecategoryname = "", financecategoryname = "",
amount = list.Sum(a => a.amount), amount = list.Sum(a => a.amount),
month = list.FirstOrDefault().month, month = list.FirstOrDefault()?.month,
}); });
...@@ -10242,7 +10243,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -10242,7 +10243,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
} }
var guid = Guid.NewGuid().ToString(); var guid = Guid.NewGuid().ToString();
var filename = month+" OMS发货收入" + DateTime.Now.ToString("yyyyMMddHHmmss"); var filename = month+$" {(type == 1? "OMS":"FBA")}发货收入" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(list, colNames, guid, filepath); ToCSV(list, colNames, guid, filepath);
...@@ -10266,6 +10267,246 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers ...@@ -10266,6 +10267,246 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
} }
/// <summary>
/// 导出发货数据会计凭证
/// </summary>
/// <param name="month">月份</param>
/// <param name="type">1:自发货,2:FBA</param>
/// <returns></returns>
public ActionResult ExportShippingIncomingCertficate(string month,int type)
{
var result = new List<dc_month_shipping_incoming>();
var obj = new Services.FinanceReportServices().ListMonthShippingIncoming(month, type == 2);
//组装数据
obj = obj.OrderBy(a => a.platform_type).ToList();
var groupPlatform = obj.GroupBy(a => a.platform_type);
foreach (var item in groupPlatform)
{
var platform = item.Key;
var groupWebSite = item.GroupBy(a => a.website);
foreach (var website in groupWebSite)
{
var groupCurrency = website.GroupBy(a => a.currency);
foreach (var c in groupCurrency)
{
result.Add(new dc_month_shipping_incoming
{
platform_type = platform,
currency = c.Key,
financecategoryname = "",
amount = website.Sum(a => a.amount),
month = website.FirstOrDefault().month,
website = website.Key,
});
foreach (var o in c)
{
result.Add(new dc_month_shipping_incoming
{
platform_type = platform,
currency = c.Key,
financecategoryname = o.financecategoryname,
amount = o.amount,
month = o.month,
website = website.Key
});
}
}
}
}
var listPlatformSettings = new List<mPlatformAccountingSetting>
{
new mPlatformAccountingSetting{ platform_type="Aliexpress",cert_id="700",creator = "张滢萍",subject_no="1122",customer_no="02054",currency="USD",currencyname="美元",website="Global"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="701",creator = "张滢萍",subject_no="1122",customer_no="06006",currency="PHP",currencyname="菲律宾比索",website="PH"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="702",creator = "张滢萍",subject_no="1122",customer_no="06007",currency="MYR",currencyname="马来西亚-林吉特",website="MY"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="703",creator = "张滢萍",subject_no="1122",customer_no="06008",currency="THB",currencyname="泰铢",website="TH"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="704",creator = "张滢萍",subject_no="1122",customer_no="06009",currency="SGD",currencyname="新加坡元",website="SG"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="705",creator = "张滢萍",subject_no="1122",customer_no="06010",currency="IDR",currencyname="印尼卢比",website="ID"},
new mPlatformAccountingSetting{ platform_type="Lazada",cert_id="706",creator = "张滢萍",subject_no="1122",customer_no="06011",currency="VND",currencyname="越南盾",website="VN"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="707",creator = "张滢萍",subject_no="1122",customer_no="01104",currency="USD",currencyname="美元",website="US"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="708",creator = "张滢萍",subject_no="1122",customer_no="01107",currency="GBP",currencyname="英镑",website="UK"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="709",creator = "张滢萍",subject_no="1122",customer_no="01108",currency="EUR",currencyname="欧元",website="DE"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="710",creator = "张滢萍",subject_no="1122",customer_no="01109",currency="EUR",currencyname="欧元",website="ES"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="711",creator = "张滢萍",subject_no="1122",customer_no="01110",currency="EUR",currencyname="欧元",website="FR"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="712",creator = "张滢萍",subject_no="1122",customer_no="01111",currency="EUR",currencyname="欧元",website="IT"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="713",creator = "张滢萍",subject_no="1122",customer_no="01112",currency="EUR",currencyname="欧元",website="NL"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="714",creator = "张滢萍",subject_no="1122",customer_no="01115",currency="SEK",currencyname="瑞士克朗",website="SE"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="715",creator = "张滢萍",subject_no="1122",customer_no="01113",currency="JPY",currencyname="日元",website="JP"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="716",creator = "张滢萍",subject_no="1122",customer_no="01106",currency="AUD",currencyname="澳元",website="AU"},
new mPlatformAccountingSetting{ platform_type="Amazon",cert_id="717",creator = "张滢萍",subject_no="1122",customer_no="01105",currency="CAD",currencyname="加元",website="CA"},
new mPlatformAccountingSetting{ platform_type="DHgate",cert_id="718",creator = "赵娟",subject_no="1122",customer_no="09006",currency="USD",currencyname="美元",website="Global"},
new mPlatformAccountingSetting{ platform_type="JD",cert_id="719",creator = "赵娟",subject_no="1122",customer_no="29001",currency="THB",currencyname="泰铢",website="Global"},
new mPlatformAccountingSetting{ platform_type="Joom",cert_id="720",creator = "赵娟",subject_no="1122",customer_no="19033",currency="USD",currencyname="美元",website="Global"},
new mPlatformAccountingSetting{ platform_type="OpenSky",cert_id="722",creator = "赵娟",subject_no="1122",customer_no="20001",currency="USD",currencyname="美元",website="Global"},
new mPlatformAccountingSetting{ platform_type="PriceMinister",cert_id="723",creator = "赵娟",subject_no="1122",customer_no="16009",currency="EUR",currencyname="欧元",website="Global"},
new mPlatformAccountingSetting{ platform_type="Sears",cert_id="724",creator = "赵娟",subject_no="1122",customer_no="22001",currency="USD",currencyname="美元",website="US"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="725",creator = "赵娟",subject_no="1122",customer_no="17032",currency="IDR",currencyname="印尼卢比",website="ID"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="726",creator = "赵娟",subject_no="1122",customer_no="17032",currency="MYR",currencyname="马来西亚-林吉特",website="ID"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="727",creator = "赵娟",subject_no="1122",customer_no="17032",currency="PHP",currencyname="菲律宾比索",website="PH"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="728",creator = "赵娟",subject_no="1122",customer_no="17032",currency="SGD",currencyname="新加坡元",website="SG"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="729",creator = "赵娟",subject_no="1122",customer_no="17032",currency="THB",currencyname="泰铢",website="TH"},
new mPlatformAccountingSetting{ platform_type="Shopee",cert_id="730",creator = "赵娟",subject_no="1122",customer_no="17032",currency="VND",currencyname="越南盾",website="Global"},
new mPlatformAccountingSetting{ platform_type="Shopify",cert_id="731",creator = "赵娟",subject_no="2203",customer_no="28003",currency="USD",currencyname="美元",website="Global"},
new mPlatformAccountingSetting{ platform_type="Walmart",cert_id="732",creator = "赵娟",subject_no="1122",customer_no="18006",currency="USD",currencyname="美元",website="US"},
new mPlatformAccountingSetting{ platform_type="MARKETING",cert_id="733",creator = "赵娟",subject_no="1122",customer_no="14001",currency="CNY",currencyname="人民币",website="Global"},
new mPlatformAccountingSetting{ platform_type="MARKETING",cert_id="734",creator = "赵娟",subject_no="1122",customer_no="14001",currency="USD",currencyname="美元",website="US"},
new mPlatformAccountingSetting{ platform_type="Wish",cert_id="735",creator = "赵娟",subject_no="1122",customer_no="5021",currency="CNY",currencyname="人民币",website="Global"},
//new mPlatformAccountingSetting{ platform_type="Ebay",cert_id="736",creator = "赵娟",subject_no="1122",customer_no="030j4",currency="GBP",currencyname="英镑",website="UK"},
new mPlatformAccountingSetting{ platform_type="Ebay",cert_id="737",creator = "赵娟",subject_no="2203",customer_no="030j3",currency="AUD",currencyname="澳元",website=""},
new mPlatformAccountingSetting{ platform_type="Ebay",cert_id="738",creator = "赵娟",subject_no="2203",customer_no="030j3",currency="EUR",currencyname="欧元",website=""},
new mPlatformAccountingSetting{ platform_type="Ebay",cert_id="739",creator = "赵娟",subject_no="2203",customer_no="030j3",currency="GBP",currencyname="英镑",website=""},
new mPlatformAccountingSetting{ platform_type="Ebay",cert_id="740",creator = "赵娟",subject_no="2203",customer_no="030j3",currency="USD",currencyname="美元",website=""},
};
var listFinanceCategory = new List<mFinanceCategorySubjectNo> {
new mFinanceCategorySubjectNo{name="精油类",subject_no="60010101"},
new mFinanceCategorySubjectNo{name="服装类",subject_no="60010106"},
new mFinanceCategorySubjectNo{name="电子产品类",subject_no="60010102"},
new mFinanceCategorySubjectNo{name="美容美甲类",subject_no="60010104"},
new mFinanceCategorySubjectNo{name="家居用品类",subject_no="60010103"},
};
var colNames = new List<string> { "凭证ID", "会计年", "会计期间", "制单日期", "凭证类别",
"凭证号", "制单人", "所附单据数", "备注1", "备注2",
"科目编码", "摘要", "结算方式编码","票据号", "票据日期",
"币种名称","汇率","单价","借方数量","贷方数量",
"原币借方","原币贷方","借方金额","贷方金额","部门编码",
"职员编码","客户编码","供应商编码","项目大类编码","项目编码",
"业务员"
};
var listRate = GetFundCurrencyRate(month);
if(listRate.Count==0)
{
return Json(new {
success=false,
msg = "从资金系统获取汇率失败"
});
}
var day = DateTime.Parse(month + "-01");
var list = new List<string>();
foreach (var item in result)
{
var ID = "";
var Month = day.Month;
var Year = day.Year;
var Date = day.AddMonths(1).AddDays(-1).ToString("yyyy.MM.dd");
var Creator1 = "";
var SubjectNo = "";
var CustomerNo = "";
var currencyName = "";
decimal rate = 0;
var setting = listPlatformSettings.Where(a => a.platform_type == item.platform_type && a.website == item.website && a.currency == item.currency).FirstOrDefault();
if(setting==null && item.platform_type=="Ebay")
{
setting = listPlatformSettings.Where(a => a.platform_type == item.platform_type && a.currency == item.currency).FirstOrDefault();
}
if(setting!=null)
{
ID = setting.cert_id;
Creator1 = setting.creator;
SubjectNo = setting.subject_no;
CustomerNo = setting.customer_no;
currencyName = setting.currencyname;
}
var exchangeRate = listRate.Where(a => a.currency == currencyName).FirstOrDefault();
if(exchangeRate!=null)
{
rate = exchangeRate.exchange_rate??0;
}
//判断是否合计
if (string.IsNullOrEmpty(item.financecategoryname))
{
list.Add($@"{ID}|{Year}|{Month}|{Date}|记|
{ID}|{Creator1}||||
{SubjectNo}|{item.platform_type}平台发货确认收入||||
{currencyName}|||||
{item.amount}||{item.amount*rate}|||
||#{CustomerNo}|||
"
);
}
else
{
var subjectSetting = listFinanceCategory.Where(a => a.name == item.financecategoryname).FirstOrDefault();
if(subjectSetting !=null)
{
SubjectNo = subjectSetting.subject_no;
}
list.Add($@"{ID}|{Year}|{Month}|{Date}|记|
{ID}|{Creator1}||||
{SubjectNo}|{item.platform_type}平台发货确认收入||||
{currencyName}|||||
|{item.amount}||{item.amount*rate}||
||||#{CustomerNo}|
"
);
}
}
var guid = Guid.NewGuid().ToString();
var filename = month + $" {(type == 1 ? "OMS" : "FBA")}发货收入凭证" + DateTime.Now.ToString("yyyyMMddHHmmss");
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(list, colNames, guid, filepath);
var ms = new System.IO.MemoryStream();
using (var f = new System.IO.FileStream(filepath + guid + ".csv", System.IO.FileMode.Open))
{
f.CopyTo(ms);
}
ms.Position = 0;
return File(ms, "text/csv", filename + ".csv");
}
/// <summary>
/// 获取资金系统的每月汇率
/// </summary>
/// <param name="month"></param>
/// <returns></returns>
private List<mFundExchangRate> GetFundCurrencyRate(string month)
{
var result = Common.HttpHelper.NetHelper.Request("http://fund.bailuntec.com/api/GetExchangeRate?month=" + month);
var json = JsonConvert.DeserializeObject<FundExchangRate_Response>(result);
if(json.msg=="成功")
{
return json.data;
}
else
{
return new List<mFundExchangRate>();
}
}
#endregion #endregion
......
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
<label>&nbsp;</label> <label>&nbsp;</label>
<button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button> <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
<button type="button" class="btn btn-danger" onclick="exportxls();">导出</button> <button type="button" class="btn btn-danger" onclick="exportxls();">导出</button>
@if (ViewBag.type == 1)
{
<button type="button" class="btn btn-danger" onclick="exportCert();">导出凭证</button>
}
</div> </div>
</div> </div>
</form> </form>
...@@ -176,6 +181,16 @@ ...@@ -176,6 +181,16 @@
window.open('@Url.Content("~/Reports/Finance/ExportShippingIncoming?month=")' + mon+'&type=@(ViewBag.type)', '_blank'); window.open('@Url.Content("~/Reports/Finance/ExportShippingIncoming?month=")' + mon+'&type=@(ViewBag.type)', '_blank');
} }
function exportCert() {
var mon = $('#month').val();
if (mon == '') {
alert('请选择月份');
return;
}
window.open('@Url.Content("~/Reports/Finance/ExportShippingIncomingCertficate?month=")' + mon+'&type=@(ViewBag.type)', '_blank');
}
function clearHtml(s) { function clearHtml(s) {
// 去除 富文本格式 // 去除 富文本格式
s = s.replace(/(\n)/g, ""); s = s.replace(/(\n)/g, "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment