155 lines
5.7 KiB
C#
155 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using HHWMS.Web.Models;
|
|
using MESTOWMSService;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using ServiceReference1;
|
|
using WalkingTec.Mvvm.Core;
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
using WalkingTec.Mvvm.Mvc;
|
|
|
|
namespace HHWMS.Web.Controllers;
|
|
|
|
[Area("xwms")]
|
|
[ActionDescription("生产工单领料")]
|
|
public class XWMSMFMController : BaseController
|
|
{
|
|
public XWMSMFMController()
|
|
{
|
|
}
|
|
|
|
#region Search
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
return PartialView("Index");
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Search(string address, string zjcode, string materialcode, string gdbill, int gdline = 0, int ms = 0)
|
|
{
|
|
var sql = @"select * from QREQ3.XWMSMFM where 1=1";
|
|
if (!string.IsNullOrEmpty(address))
|
|
{
|
|
sql += $" and MFGFCY_0 = '{address}'";
|
|
}
|
|
if (!string.IsNullOrEmpty(zjcode))
|
|
{
|
|
sql += $" and MFIITMREF_0 like '%{zjcode}%'";
|
|
}
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql += $"and ITMREF_0 like '%{materialcode}%'";
|
|
}
|
|
if (!string.IsNullOrEmpty(gdbill))
|
|
{
|
|
sql += $" and MFGNUM_0 like '%{gdbill}%'";
|
|
}
|
|
if (gdline != 0)
|
|
{
|
|
sql += $" and MFGLIN_0 = '{gdline}'";
|
|
}
|
|
if (ms != 0)
|
|
{
|
|
sql += $" and STOCOD_0 = '{ms}'";
|
|
}
|
|
|
|
var data = OracleHelper.GetDataSet(sql).Tables[0];
|
|
|
|
var list = data.AsEnumerable().Select
|
|
(x => new
|
|
{
|
|
MFGFCY_0 = x.Field<string>("MFGFCY_0"),
|
|
MFGNUM_0 = x.Field<string>("MFGNUM_0"),
|
|
MFGLIN_0 = x.Field<Int64>("MFGLIN_0"),
|
|
PJT_0 = x.Field<string>("PJT_0"),
|
|
OPPEXTNUM_0 = x.Field<string>("OPPEXTNUM_0"),
|
|
MFIITMREF_0 = x.Field<string>("MFIITMREF_0"),
|
|
MFIITMDES1_0 = x.Field<string>("MFIITMDES1_0"),
|
|
MFIITMDES2_0 = x.Field<string>("MFIITMDES2_0"),
|
|
EXTQTY_0 = x.Field<decimal>("EXTQTY_0"),
|
|
BOMSEQ_0 = x.Field<Int32>("BOMSEQ_0"),
|
|
ITMREF_0 = x.Field<string>("ITMREF_0"),
|
|
ITMDES1_0 = x.Field<string>("ITMDES1_0"),
|
|
ITMDES2_0 = x.Field<string>("ITMDES2_0"),
|
|
ITMDES3_0 = x.Field<string>("ITMDES3_0"),
|
|
YITMDES4_0 = x.Field<string>("YITMDES4_0"),
|
|
STOCOD_0 = x.Field<Int16>("STOCOD_0"),
|
|
RETEXTCOE_0 = x.Field<decimal>("RETEXTCOE_0"),
|
|
RETQTY_0 = x.Field<decimal>("RETQTY_0"),
|
|
USEQTY_0 = x.Field<decimal>("USEQTY_0"),
|
|
THISQTYSTU = "",
|
|
WMD_USEQTY_0 = x.Field<decimal>("WMD_USEQTY_0"),
|
|
}
|
|
).ToList();
|
|
return JsonMore(list);
|
|
}
|
|
|
|
#endregion Search
|
|
|
|
[HttpPost]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Create(List<XWMSMFM> data)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
var _unitwork = new UnitWork(Wtm);
|
|
using (var tran = _unitwork.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var shipment = new ShipmentHeader2();
|
|
shipment.WarehouseId = int.Parse(warehouseId);
|
|
shipment.Code = _unitwork.GetSerialNumber("SCC");
|
|
shipment.SourceCode = data.FirstOrDefault().MFGNUM_0;
|
|
shipment.UserDef2 = data.FirstOrDefault().MFGLIN_0.ToString();
|
|
shipment.Type = "SCC";
|
|
shipment.FirstStatus = 0;
|
|
shipment.UserDef1 = data.FirstOrDefault().MFGFCY_0;
|
|
|
|
_unitwork.Add(shipment);
|
|
|
|
var detailList = new List<ShipmentDetail2>();
|
|
foreach (var item in data)
|
|
{
|
|
var detail = new ShipmentDetail2();
|
|
detail.WarehouseId = shipment.WarehouseId;
|
|
detail.ShipmentId = shipment.ID;
|
|
detail.ShipmentCode = shipment.Code;
|
|
detail.SourceCode = item.MFGNUM_0;
|
|
detail.SourceLine = item.MFGLIN_0.ToString();
|
|
detail.MaterialCode = item.ITMREF_0;
|
|
detail.MaterialName = HttpUtility.HtmlDecode(item.ITMDES1_0);
|
|
detail.Lot = HttpUtility.HtmlDecode(item.ITMDES2_0);
|
|
detail.Qty = item.THISQTYSTU;
|
|
detail.Unit = item.BOMSEQ_0.ToString();
|
|
//detail.PurchasQty = item.THISQTYUOM;
|
|
//detail.PurchasUnits = item.UOM_0;
|
|
//detail.InventoryStatus = item.STA_0;
|
|
//detail.Batch = _unitwork.GetSerialNumber("HYB", 5).Remove(3, 2);
|
|
detail.Status = 0;
|
|
detail.CreateTime = DateTime.Now;
|
|
detailList.Add(detail);
|
|
}
|
|
_unitwork.BatchAdd(detailList.ToArray());
|
|
|
|
shipment.TotalLines = detailList.Count;
|
|
shipment.TotalQty = detailList.Sum(x => x.Qty);
|
|
_unitwork.Update(shipment);
|
|
tran.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
return JsonMore(null, 500, ex.Message);
|
|
}
|
|
}
|
|
return JsonMore(null);
|
|
}
|
|
}
|