Commit 1512d1f4 by guanzhenshan

每日销进比增加成品和半成品采购明细导出

parent 340fb341
using System;
using System.Collections.Generic;
using System.Text;
namespace Bailun.DC.Models
{
/// <summary>
/// 采购单详情
/// </summary>
public class dc_base_purchase
{
public int id { get; set; }
public string bailun_sku { get; set; }
public string purchase_id { get; set; }
public string warehouse_code { get; set; }
public string warehouse_name { get; set; }
public string status { get; set; }
public DateTime create_time { get; set; }
public DateTime update_time { get; set; }
public int count { get; set; }
public int has_transfer { get; set; }
public string sku_name { get; set; }
public DateTime? estimated_arrival_time { get; set; }
public int supplier_id { get; set;}
public string supplier_name { get; set; }
public DateTime? confirm_time { get; set; }
public DateTime? pay_time { get; set; }
public int pay_type { get; set; }
public decimal price { get; set; }
public int buy_status { get; set; }
public int transport_type { get; set; }
public int deliver_id { get; set; }
public int parent_id { get; set; }
public int has_delete { get; set; }
public int company_id { get; set; }
}
}
......@@ -153,5 +153,50 @@ namespace Bailun.DC.Services
}
}
/// <summary>
/// 获取采购单的明细
/// </summary>
/// <param name="start">创建开始时间</param>
/// <param name="end">创建结束时间</param>
/// <returns></returns>
public List<dc_base_purchase> ListPurchase(DateTime start, DateTime end)
{
var sql = $@"select t1.* from dc_base_purchase t1
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd")}' and t1.create_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}'";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
return cn.Query<dc_base_purchase>(sql).AsList();
}
}
/// <summary>
/// 获取半成品采购单的明细
/// </summary>
/// <param name="start">创建开始时间</param>
/// <param name="end">创建结束时间</param>
/// <returns></returns>
public List<dc_semi_purchase_info> ListSemiPurchase(DateTime start, DateTime end)
{
var sql = $@"select * from dc_semi_purchase_info t1 where `status`>-1 and deliver_name !='广州哈倪蔓生物科技有限公司' and deliver_name!='广州市花都区花城市象贸易商行-滋柔' and deliver_name!='LEIKESAER INFORMATION SERVICE LIMITED' and t1.create_time>='{start.ToString("yyyy-MM-dd")}' and t1.create_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}'";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
return cn.Query<dc_semi_purchase_info>(sql).AsList();
}
}
}
}
......@@ -1047,6 +1047,9 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 按车间获取半成品的每日销售进销比
/// </summary>
......
......@@ -6,12 +6,22 @@ using Microsoft.AspNetCore.Mvc;
using Bailun.DC.Models;
using Bailun.DC.Services;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Hosting;
namespace Bailun.DC.Web.Areas.Reports.Controllers
{
[Area("Reports")]
public class PurchaseController : Controller
public class PurchaseController : Base.BaseController
{
private readonly IHostingEnvironment _hostingEnvironment;
public PurchaseController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public IActionResult Index()
{
return View();
......@@ -87,5 +97,62 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
return JsonConvert.SerializeObject(new { total = total, rows = list,count_row = countM });
}
/// <summary>
/// 获取采购单的明细
/// </summary>
/// <param name="start">创建开始时间</param>
/// <param name="end">创建结束时间</param>
/// <param name="t">0:成品采购,1:半成品采购</param>
/// <returns></returns>
public ActionResult ExportListPurchase(DateTime start,DateTime end,int t)
{
var _service = new Services.PurchaseServices();
var colNames = new List<string> {"采购单号","Sku","采购数量", "价格", "金额",
"下单时间", "状态"
};
var listVal = new List<string>();
if (t == 0)
{
var obj = _service.ListPurchase(start, end);
foreach (var item in obj)
{
listVal.Add(
item.purchase_id + "|" + item.bailun_sku + "|" + item.count + "|" + item.price + "|" + (item.count * item.price) + "|" +
item.create_time.ToString("yyyy-MM-dd HH:mm:ss") + "|" + item.status
);
}
}
else if (t == 1)
{
var obj = _service.ListSemiPurchase(start, end);
foreach (var item in obj)
{
listVal.Add(
item.purchase_id + "|" + item.bailun_sku + "|" + item.quantity_purchase + "|" + item.unit_price + "|" + (item.quantity_purchase * item.unit_price) + "|" +
item.create_time.ToString("yyyy-MM-dd HH:mm:ss") + "|" + item.status
);
}
}
var guid = Guid.NewGuid().ToString();
var filename = start.ToString("yyyy-MM-dd")+"至"+end.ToString("yyyy-MM-dd")+"的"+(t==0?"成品":"半成品")+"采购单明细";
var filepath = _hostingEnvironment.WebRootPath + "\\Files\\Report\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
ToCSV(listVal, 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
......@@ -37,6 +37,8 @@
<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-success" onclick="exportfinish();">导出成品采购明细</button>
<button type="button" class="btn btn-warning" onclick="exportnofinish();">导出半成品采购明细</button>
</div>
</div>
</form>
......@@ -274,6 +276,41 @@
}
})
}
function exportfinish() {
var start = $('#start').val();
var end = $('#end').val();
if (start == '') {
alert('开始日期不能为空');
return;
}
if (end == '') {
alert('结束日期不能为空');
return;
}
window.open('@Url.Content("~/Reports/Purchase/ExportListPurchase?start=")' + start + '&end=' + end+'&t=0', '_blank');
}
function exportnofinish() {
var start = $('#start').val();
var end = $('#end').val();
if (start == '') {
alert('开始日期不能为空');
return;
}
if (end == '') {
alert('结束日期不能为空');
return;
}
window.open('@Url.Content("~/Reports/Purchase/ExportListPurchase?start=")' + start + '&end=' + end+'&t=1', '_blank');
}
</script>
}
......
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