Browse Source

历史称重记录没有批号的,按先进先出分配存货批次和数量

master
wugang 7 years ago
parent
commit
c8f176dcee
4 changed files with 251 additions and 3 deletions
  1. +1
    -1
      B3_QiLianMuGe.Web/B3_QiLianMuGe.Web.csproj
  2. +1
    -1
      B3_QiLianMuGe.Web/PluginClass.cs
  3. +2
    -1
      B3_QiLianMuGe/B3_QiLianMuGe.csproj
  4. +247
    -0
      B3_QiLianMuGe/Utils/CreateInOutStoreBillIOC.cs

+ 1
- 1
B3_QiLianMuGe.Web/B3_QiLianMuGe.Web.csproj View File

@ -138,7 +138,7 @@
<ProjectReference Include="..\B3_QiLianMuGe\B3_QiLianMuGe.csproj">
<Project>{19FBD9C0-0959-41C9-9698-FFB2AD98CDD3}</Project>
<Name>B3_QiLianMuGe</Name>
</ProjectReference>
<Private>False</Private></ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.


+ 1
- 1
B3_QiLianMuGe.Web/PluginClass.cs View File

@ -8,7 +8,7 @@ namespace BWP.B3_QiLianMuGe.Web
{
public void OnInit()
{
GlobalFlags.On(B3SaleConsts.Flags.IsBinXi);
GlobalFlags.On(B3SaleConsts.Flags.BillDoCheckUnCheckGoodsBatch);
}
}
}

+ 2
- 1
B3_QiLianMuGe/B3_QiLianMuGe.csproj View File

@ -126,11 +126,12 @@
<Link>Customer_version.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\CreateInOutStoreBillIOC.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="BL\" />
<Folder Include="BO\" />
<Folder Include="Utils\" />
<Folder Include="TypeIOCs\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.


+ 247
- 0
B3_QiLianMuGe/Utils/CreateInOutStoreBillIOC.cs View File

@ -0,0 +1,247 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BWP.B3Frameworks;
using BWP.B3Frameworks.BO.NamedValueTemplate;
using BWP.B3Frameworks.Utils;
using BWP.B3Sale.BL;
using BWP.B3Sale.BO;
using BWP.B3Sale.Utils;
using BWP.B3UnitedInfos.BO;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.Utils;
using TSingSoft.WebPluginFramework;
namespace B3_QiLianMuGe.Utils
{
[TypeIOC(typeof(SaleOutStoreBL), typeof(SaleOutStoreBL.ICreateInOutStoreBill))]
public class CreateInOutStoreBillIOC : SaleOutStoreBL.ICreateInOutStoreBill
{
public void Invoke(IDmoSession session, SaleOutStore saleOutStore, InOutStoreBill target, ref bool flag)
{
SetInOutStoreBillDetailByWeightInfos(session, saleOutStore, target);
if (target.Details.Count > 0)
flag = true;
else
flag = false;
}
/// <summary>
/// 处理扫条码按条码的生产批次对应的存货批次出库
/// </summary>
/// <param name="dmo"></param>
/// <param name="target"></param>
private void SetInOutStoreBillDetailByWeightInfos(IDmoSession Session,SaleOutStore dmo, InOutStoreBill target)
{
var query = new DQueryDom(new JoinAlias(typeof(WeightingInfor)));
query.Columns.Add(DQSelectColumn.Field("DetailID"));
query.Columns.Add(DQSelectColumn.Field("Goods_ID"));
query.Columns.Add(DQSelectColumn.Field("Product_Batch"));
query.Columns.Add(DQSelectColumn.Sum("MainUnitNum"));
query.Columns.Add(DQSelectColumn.Sum("SecondNumber"));
query.Where.Conditions.Add(DQCondition.EQ("BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))));
query.Where.Conditions.Add(DQCondition.EQ("BillID", dmo.ID));
query.GroupBy.Expressions.Add(DQExpression.Field("DetailID"));
query.GroupBy.Expressions.Add(DQExpression.Field("Goods_ID"));
query.GroupBy.Expressions.Add(DQExpression.Field("Product_Batch"));
var tuples = query.EExecuteList<long, long?, string, Money<decimal>?, Money<decimal>?>(Session);
if (tuples.Count() > 0)
{
var results = tuples.Where(x => string.IsNullOrEmpty(x.Item3) && x.Item4 > 0);
foreach (var result in results)
{
var oDetails = dmo.Details.Where(x => x.ID == result.Item1);
if (oDetails.Count() > 0)
{
var detail = oDetails.First();
detail.UnitNum = result.Item4;
detail.Number = result.Item4;
detail.SecondNumber = result.Item5;
detail.GoodsBatch_ID = null;
var dic = new Dictionary<long, List<TmpData>>();
var outDetails = AddDetailByPdAndBatchNo(Session, dmo, detail, dic);
foreach (var item in outDetails)
{
var targetDetail = new InOutStoreBill_Detail();
target.Details.Add(targetDetail);
var details = dmo.Details.Where(x => x.ID == detail.ID);
SaleOutStore_Detail outDetail = null;
if (details.Count() > 0)
{
outDetail = details.First();
}
if (dmo.BusinessProperty == B3Sale业务属性.)
targetDetail.Store_ID = dmo.Store_ID ?? 0;
else
{
if (outDetail != null)
targetDetail.Store_ID = outDetail.Store_ID ?? 0;
}
targetDetail.Goods_ID = item.SaleGoods_ID;
targetDetail.Number = item.Number.Value;
targetDetail.SecondNumber = item.SecondNumber;
targetDetail.GoodsBatch_ID = item.GoodsBatch_ID;
if (outDetail != null)
{
targetDetail.CargoSpace_ID = item.CargoSpace_ID;
targetDetail.Price = item.Price;
targetDetail.Money = item.Price * item.Number;
targetDetail.BrandItem_ID = item.BrandItem_ID;
}
}
}
}
foreach (var detail in tuples.Where(x => !string.IsNullOrEmpty(x.Item3)))
{
if (detail.Item4 == null || detail.Item4 == 0)
{
continue;
}
var targetDetail = new InOutStoreBill_Detail();
target.Details.Add(targetDetail);
var details = dmo.Details.Where(x => x.ID == detail.Item1);
SaleOutStore_Detail outDetail = null;
if (details.Count() > 0)
{
outDetail = details.First();
}
if (dmo.BusinessProperty == B3Sale业务属性.)
targetDetail.Store_ID = dmo.Store_ID ?? 0;
else
{
if (outDetail != null)
targetDetail.Store_ID = outDetail.Store_ID ?? 0;
}
targetDetail.Goods_ID = detail.Item2.Value;
targetDetail.Number = detail.Item4 ?? 0;
targetDetail.SecondNumber = detail.Item5 ?? 0;
var tuple = SaleUtil.GetGoodsBatch(DomainContext.Current.ID, detail.Item3, detail.Item2.Value);
if (tuple != null)
targetDetail.GoodsBatch_ID = tuple.Item1;
if (outDetail != null)
{
targetDetail.CargoSpace_ID = outDetail.CargoSpace_ID;
targetDetail.Price = outDetail.Price;
targetDetail.Money = outDetail.Price * targetDetail.Number;
targetDetail.BrandItem_ID = outDetail.BrandItem_ID;
}
}
}
}
static List<SaleOutStore_Detail> AddDetailByPdAndBatchNo(IDmoSession session, SaleOutStore saleOutStore, SaleOutStore_Detail outStoreDetail, Dictionary<long, List<TmpData>> dic)
{
if (!dic.ContainsKey(outStoreDetail.SaleGoods_ID))
{
dic.Add(outStoreDetail.SaleGoods_ID, GetStoreDetailInfor(session, saleOutStore.Store_ID, outStoreDetail.SaleGoods_ID));
}
var list = dic[outStoreDetail.SaleGoods_ID];
var theNum = outStoreDetail.Number ?? 0;//需要转的数量
var theSecNum = outStoreDetail.SecondNumber ?? 0;//需要转的辅数量
var num = theNum;
var details = new List<SaleOutStore_Detail>();
foreach (var unionView in list)
{
if (num <= 0)
break;
if (unionView.Number <= 0)
continue;
Money<decimal> thisNum;//当前明细分配数量
Money<decimal> thisSecNum;//当前明细分配辅数量
if (unionView.Number >= num)
{
thisNum = num;
}
else
{
thisNum = unionView.Number;
}
if (unionView.SecondNumber >= theSecNum)
{
thisSecNum = theSecNum;
}
else
{
thisSecNum = unionView.SecondNumber;
}
var outDetail = new SaleOutStore_Detail();
DmoUtil.CopyDmoFields(outStoreDetail, outDetail, "UnitNum", "Number", "SecondNumber", "Money", "RebateMoney");
outDetail.Price = outStoreDetail.Price;
outDetail.ProductionDate = unionView.ProductionDate;
outDetail.GoodsBatch_ID = unionView.GoodsBatch_ID;
outDetail.Number = thisNum;
if (outDetail.RightRatio != 0)
outDetail.UnitNum = outDetail.Number / outDetail.RightRatio * outDetail.LeftRatio;
if (outDetail.Goods_UnitConvertDirection == . || outDetail.Goods_UnitConvertDirection == .)
{
outDetail.SecondNumber = outDetail.Number / outDetail.RightRatio * outDetail.LeftRatio;
thisSecNum = outDetail.SecondNumber ?? 0;
}
else
{
outDetail.SecondNumber = thisSecNum;
}
outDetail.HiddenNumber = outDetail.Number;
outDetail.HiddenUnitNum = outDetail.UnitNum;
outDetail.HiddenSecondNumber = outDetail.SecondNumber;
details.Add(outDetail);
num -= thisNum;
theSecNum -= thisSecNum;
unionView.Number -= thisNum;
unionView.SecondNumber -= thisSecNum;
}
if (num != 0)
throw new Exception(string.Format("{0}可用库存还差{1},不允许出库,审核失败", outStoreDetail.Goods_Name, num));
var lastDetail = details.LastOrDefault();
if (lastDetail != null)
{
lastDetail.Money = (lastDetail.Money ?? 0m) + (outStoreDetail.Money ?? 0) - details.Sum(x => (x.Money ?? 0).Value);
lastDetail.SecondNumber = (lastDetail.SecondNumber ?? 0m) + (outStoreDetail.SecondNumber ?? 0) - details.Sum(x => (x.SecondNumber ?? 0).Value);
}
return details;
}
static List<TmpData> GetStoreDetailInfor(IDmoSession session, long? store_ID, long? saleGoods_ID)
{
var dom1 = new DQueryDom(new JoinAlias(typeof(StoreDetail)));
dom1.Columns.Add(DQSelectColumn.Field("GoodsBatch_ProductionDate"));
dom1.Columns.Add(DQSelectColumn.Field("GoodsBatch_ID"));
dom1.Columns.Add(DQSelectColumn.Field("Number"));
dom1.Columns.Add(DQSelectColumn.Field("SecondNumber"));
dom1.Where.Conditions.Add(DQCondition.EQ("Goods_ID", saleGoods_ID));
dom1.Where.Conditions.Add(DQCondition.EQ("Store_ID", store_ID));
dom1.Where.Conditions.Add(DQCondition.GreaterThan(DQExpression.Field("Number"), DQExpression.Value(0)));
dom1.OrderBy.Expressions.Add(DQOrderByExpression.Create("GoodsBatch_ProductionDate"));
dom1.OrderBy.Expressions.Add(DQOrderByExpression.Create("GoodsBatch_ID"));
var list = new List<TmpData>();
using (var reader = session.ExecuteReader(dom1))
{
while (reader.Read())
{
var tmp = new TmpData();
tmp.ProductionDate = (DateTime?)reader[0];
tmp.GoodsBatch_ID = (long?)reader[1];
tmp.Number = (Money<decimal>?)reader[2] ?? 0;
tmp.SecondNumber = (Money<decimal>?)reader[3] ?? 0;
list.Add(tmp);
}
}
return list;
}
class TmpData
{
public long? GoodsBatch_ID { get; set; }
public DateTime? ProductionDate { get; set; }
public Money<decimal> Number { get; set; }
public Money<decimal> SecondNumber { get; set; }
}
}
}

Loading…
Cancel
Save