149 lines
5.4 KiB
C#
149 lines
5.4 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 XWMSSOHController : BaseController
|
|
{
|
|
|
|
public XWMSSOHController()
|
|
{
|
|
}
|
|
|
|
#region Search
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Index()
|
|
{
|
|
return PartialView("Index");
|
|
}
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
public ActionResult Search(string address, string billno, string cust, string materialcode)
|
|
{
|
|
var sql = @"select * from QRE.XWMSSOH where 1=1";
|
|
if (!string.IsNullOrEmpty(address))
|
|
{
|
|
sql += $" and SALFCY_0 = '{address}'";
|
|
}
|
|
if (!string.IsNullOrEmpty(billno))
|
|
{
|
|
sql += $" and SOHNUM_0 like '%{billno}%'";
|
|
}
|
|
if (!string.IsNullOrEmpty(cust))
|
|
{
|
|
sql += $" and BPCNAM_0 like '%{cust}%'";
|
|
}
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql += $"and ITMREF_0 like '%{materialcode}%'";
|
|
}
|
|
|
|
var data = OracleHelper.GetDataSet(sql).Tables[0];
|
|
|
|
var list = data.AsEnumerable().Select
|
|
(x => new
|
|
{
|
|
SALFCY_0 = x.Field<string>("SALFCY_0"),
|
|
ORDDAT_0 = x.Field<DateTime>("ORDDAT_0").ToShortDateString(),
|
|
BPCORD_0 = x.Field<string>("BPCORD_0"),
|
|
BPCNAM_0 = x.Field<string>("BPCNAM_0"),
|
|
SOHNUM_0 = x.Field<string>("SOHNUM_0"),
|
|
SOPLIN_0 = x.Field<Int64>("SOPLIN_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"),
|
|
QTY_0 = x.Field<decimal>("QTY_0"),
|
|
NODLQTY_0 = x.Field<decimal>("NODLQTY_0"),
|
|
THISQTYSTU = "",
|
|
STU_0 = x.Field<string>("STU_0"),
|
|
BPAADD_0 = x.Field<string>("BPAADD_0")
|
|
}
|
|
).ToList();
|
|
return JsonMore(list);
|
|
}
|
|
|
|
#endregion Search
|
|
|
|
[HttpPost]
|
|
[FixConnection(CsName = "hangyong")]
|
|
public ActionResult Create(List<XWMSSOH> data)
|
|
{
|
|
var warehouseId = Wtm.LoginUserInfo.Groups.FirstOrDefault().GroupCode;
|
|
var _unitwork = new UnitWork(Wtm);
|
|
var dc = Wtm.CreateDC(cskey: "hangyong");
|
|
using (var tran = dc.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
var shipment = new ShipmentHeader2();
|
|
shipment.WarehouseId = int.Parse(warehouseId);
|
|
shipment.Code = _unitwork.GetSerialNumber("XSC");
|
|
shipment.Type = "XSC";
|
|
shipment.SourceCode = data.FirstOrDefault().SOHNUM_0;
|
|
shipment.ShipTo = data.FirstOrDefault().BPCORD_0;
|
|
shipment.FirstStatus = 0;
|
|
shipment.LastStatus = 0;
|
|
shipment.AppointmentTime = data.FirstOrDefault().ORDDAT_0;
|
|
shipment.UserDef1 = $"{data.FirstOrDefault().SALFCY_0} {data.FirstOrDefault().BPAADD_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.SOHNUM_0;
|
|
detail.SourceLine = item.SOPLIN_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.STU_0;
|
|
detail.SupplierCode = shipment.ShipTo;
|
|
detail.SupplierName = item.BPCNAM_0;
|
|
//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);
|
|
}
|
|
}
|