Commit 78505142 by guanzhenshan

增加采购下单明细导出

parent 0838e9c0
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models.ExportServices
{
/// <summary>
/// 采购下单明细
/// </summary>
public class mPurchase
{
public string purchase_id { get; set; }
public string bailun_sku { get; set; }
public string warehouse_code { get; set; }
public string warehouse_name { get; set; }
public int count { get; set; }
public decimal price { get; set; }
public decimal amount { get; set; }
public DateTime create_time { get; set; }
}
}
......@@ -100,5 +100,39 @@ namespace Bailun.DC.Services
}
#endregion
#region 采购下单
/// <summary>
/// 获取采购下单明细
/// </summary>
/// <param name="start">创建开始时间</param>
/// <param name="end">创建结束时间</param>
/// <param name="companyid">公司id</param>
/// <returns></returns>
public List<mPurchase> ListPurchase(DateTime start, DateTime end, int companyid)
{
var sql = $@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,t1.count count,(t1.count*t1.price) amount,t1.price,t1.purchase_id,t1.create_time from dc_base_purchase t1
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}'
";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<mPurchase>(sql, null, null, true, 2 * 60).AsList();
return obj;
}
}
#endregion
}
}
......@@ -52,8 +52,7 @@ namespace Bailun.DC.SkuDailyPurchaseAndSales
//成品
//先保存采购的
var sql = $@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t2.unit_price) amount from dc_base_purchase t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
var sql = $@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t1.price) amount from dc_base_purchase t1
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
group by t1.warehouse_code,t1.bailun_sku";
......
......@@ -2,20 +2,60 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
namespace Bailun.DC.Web.Areas.ExportFile.Controllers
{
[Area("ExportFile")]
public class PurchaseController : Controller
public class PurchaseController : Base.BaseController
{
public IActionResult Index()
private readonly IHostingEnvironment _hostingEnvironment;
public PurchaseController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
/// <summary>
/// 导出采购下单明细
/// </summary>
/// <param name="companyid">公司id</param>
/// <param name="start">下单开始时间</param>
/// <param name="end">下单结束时间</param>
/// <returns></returns>
public ActionResult ExportPurchase(int companyid, DateTime start, DateTime end)
{
return View();
var _service = new Services.ExportServices();
var obj = _service.ListPurchase(start, end, companyid);
var colNames = new List<string> {"采购入库单号","Sku","仓库编码", "仓库名称", "下单数量",
"下单金额","采购价","下单时间" };
var list = new List<string>();
foreach (var item in obj)
{
list.Add(item.purchase_id + "|" + item.bailun_sku + "|" + item.warehouse_code + "|" + item.warehouse_name + "|" + item.count + "|" +
item.amount + "|" + item.price + "|" + item.create_time);
}
var guid = Guid.NewGuid().ToString();
var filename = "采购下单明细" + start.ToString("yyyy-MM-dd") + "至" + end.ToString("yyyy-MM-dd");
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");
}
}
}
\ No newline at end of file
......@@ -4613,18 +4613,22 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
{
if (s.Length > 0)
{
var tempArr = s.Split("\"");
s = tempArr[0];
for (var i = 1; i < tempArr.Length-1; i++)
if (tempArr.Length > 0)
{
if (tempArr[i - 1].Substring(tempArr[i - 1].Length - 1, 1) == "," && (tempArr[i + 1] == "" || tempArr[i + 1].Substring(0, 1) == ","))
s = tempArr[0];
for (var i = 1; i < tempArr.Length - 1; i++)
{
tempArr[i] = tempArr[i].Replace(",", "||");
if ((tempArr[i - 1]==""|| tempArr[i - 1].Substring(tempArr[i - 1].Length - 1, 1) == ",") && (tempArr[i + 1] == "" || tempArr[i + 1].Substring(0, 1) == ",") && tempArr[i].Length>1)
{
tempArr[i] = tempArr[i].Replace(",", "||");
}
s += tempArr[i];
}
s += tempArr[i];
s += tempArr[tempArr.Length - 1];
}
s += tempArr[tempArr.Length - 1];
var arr = s.Split(',');
if (arr.Length > 1)
{
......
......@@ -53,6 +53,7 @@
<div class="form-group">
<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-warning" onclick="exportlistpurchase()">导出采购下单明细</button>
<button type="button" class="btn btn-success" onclick="exportlistputin();">导出入库明细</button>
<button type="button" class="btn btn-success" onclick="exportlistshipping();">导出发货明细</button>
</div>
......@@ -255,6 +256,12 @@
}
}
function exportlistpurchase() {
if (confirm('确定要导出采购下单明细吗?')) {
window.open('@Url.Content("~/ExportFile/Purchase/ExportPurchase")' + '?' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
}
}
function showleft() {
var c = $('#leftcontain').css('display');
if (c == 'none') {
......
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