1调拨入库同一调拨单可多次入

2库存管理页面添加库存为0时库存红色字体
3处方取药同一处方可多次取药
This commit is contained in:
maqiao 2024-03-29 18:21:28 +08:00
parent 2ef1c185e3
commit ff7716f63d
7 changed files with 233 additions and 54 deletions

View File

@ -0,0 +1,41 @@
using DM_Weight.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace DM_Weight.Converter
{
internal class ColorCountConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var total = 0;
bool bInt = int.TryParse(value.ToString(), out var count); if (bInt)
{
if (count <= 0)
{
return "Red";
}
else
{
return "black";
}
}
else
{
return "black";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -119,6 +119,12 @@ namespace DM_Weight.Models
SetProperty(ref _addQuantity, value);
}
}
/// <summary>
/// 调拨入库数量
/// </summary>
private int _invoiceQuantity;
[SugarColumn(IsIgnore =true)]
public int InvoiceQuantity { get=>_invoiceQuantity; set=>SetProperty(ref _invoiceQuantity, value); }
private int _takeQuantity = 0;
@ -136,9 +142,25 @@ namespace DM_Weight.Models
{
throw new ArgumentException("取药数量不能小于0");
}
if(OrderQuantity>0&&value>OrderQuantity)
{
throw new ArgumentException("取药数量不能大于应取数量");
}
SetProperty(ref _takeQuantity, value);
}
}
private int _orderQuantity = 0;
/// <summary>
/// 处方取药数量
/// </summary>
[SugarColumn(IsIgnore =true)]
public int OrderQuantity
{
get => _orderQuantity;
set=>SetProperty(ref _orderQuantity, value);
}
//private string _tipMessage=string.Empty;
//[SugarColumn(IsIgnore = true)]
//public string TipMessage

View File

@ -127,5 +127,10 @@ namespace DM_Weight.Models
///</summary>
[SugarColumn(ColumnName = "use_dosage")]
public string UseDosage { get; set; }
/// <summary>
/// 处方中该药品状态是否已全部取出0未取1已取针对处方可取部分药
/// </summary>
[SugarColumn(ColumnName = "dm_status")]
public int? DMStatus { get;set; }
}
}

View File

@ -291,7 +291,7 @@ namespace DM_Weight.ViewModels
if (SelectedInvoice != null)
{
//先查询有几种药
string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID";
string strSql = @"SELECT sum(Quantity) AS SumQuantity, COUNT(ID) AS CountNum,INVOICE_NO AS InvoiceNo,drug_id AS DrugId,QUANTITY AS quantity,drug_manu_no AS drugManuNo FROM IN_OUT_INVOICE WHERE STATUS=0 AND INVOICE_NO=@INVOICE_NO GROUP BY INVOICE_NO,DRUG_ID";
var invoices = SqlSugarHelper.Db.SqlQueryable<InOutInvoice>(strSql)
.AddParameters(new
@ -354,6 +354,7 @@ namespace DM_Weight.ViewModels
stock.ManuNo = invoicesManuNo[j].DrugManuNo;
stock.EffDate = manuNoList[0].EffDate;
stock.Chnguid = channelLst.Id;
stock.InvoiceQuantity = invoicesManuNo[j].quantity;
stockList.Add(stock);
}
//stock.AddQuantity = invoicesManuNo[j].quantity;
@ -363,6 +364,7 @@ namespace DM_Weight.ViewModels
{
var ret = it.First();
ret.AddQuantity = invoicesManuNo[j].quantity;
ret.InvoiceQuantity = invoicesManuNo[j].quantity;
return ret;
})
.ToList();
@ -390,7 +392,8 @@ namespace DM_Weight.ViewModels
ChannelStocks.Clear();
foreach (ChannelList lst in ChannelLsts)
{
ChannelStocks.AddRange(lst.channelStocks);
ChannelStocks.AddRange(lst.channelStocks.Where(cs => cs.AddQuantity > 9));
}
AddChannels = ChannelStocks.FindAll(it => it.AddQuantity != 0);
@ -414,17 +417,17 @@ namespace DM_Weight.ViewModels
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return;
}
int totalNum = AddChannels.Sum(add => add.AddQuantity);
if (totalNum != SelectedInvoice.Quantity)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "各批次添加数量要与调拨单药品总数一致!",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return;
}
//int totalNum = AddChannels.Sum(add => add.AddQuantity);
//if (totalNum != SelectedInvoice.Quantity)
//{
// AlertMsg alertMsg = new AlertMsg
// {
// Message = "各批次添加数量要与调拨单药品总数一致!",
// Type = MsgType.ERROR,
// };
// _eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
// return;
//}
enumerator.MoveNext();
Status = 1;
OpenOneByOne();
@ -506,18 +509,48 @@ namespace DM_Weight.ViewModels
if (!_isFinishClick)
{
_isFinishClick = true;
List<ChannelStock> record = ChannelStocks.ToList();
List<ChannelStock> record = ChannelStocks;//.ToList();
string InvoiceId = SelectedInvoice.InvoiceNo;
var f = SqlSugarHelper.Db.UseTran(() =>
{
for (int i = 0; i < record.Count; i++)
{
//添加数量不能大于入库单上要加的数量
if (record[i].AddQuantity > record[i].InvoiceQuantity)
{
AlertMsg alertMsg = new AlertMsg
{
Message = "添加数量不能大于调拨单中药品数量!",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return false;
}
//添加数量等于入库单上要加的数量则更新入库单状态
if (record[i].AddQuantity == record[i].InvoiceQuantity)
{
SqlSugarHelper.Db.Updateable(new InOutInvoice()
{
Status = 1,
InvoiceNo = SelectedInvoice.InvoiceNo
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo }).ExecuteCommand();
InvoiceNo = SelectedInvoice.InvoiceNo,
DrugManuNo = record[i].ManuNo,
DrugId = record[i].DrugId
for (int i = 0; i < record.Count; i++)
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand();
}
else
{
//添加数量小于入库单上要加的数量则更新入库单中的数量
SqlSugarHelper.Db.Updateable(new InOutInvoice()
{
quantity= record[i].InvoiceQuantity- record[i].AddQuantity,
InvoiceNo = SelectedInvoice.InvoiceNo,
DrugManuNo = record[i].ManuNo,
DrugId = record[i].DrugId
}).UpdateColumns(it => new { it.Status }).WhereColumns(it => new { it.InvoiceNo, it.DrugId, it.DrugManuNo }).ExecuteCommand();
}
ChannelStock it = record[i];
@ -639,7 +672,7 @@ namespace DM_Weight.ViewModels
.Where(cs => cs.MachineId == singleChannels[i].MachineId)
.Where(cs => cs.DrawerNo == singleChannels[i].DrawerNo)
.Where(cs => cs.ColNo == singleChannels[i].ColNo)
.Where(cs=>cs.Quantity>0)
.Where(cs => cs.Quantity > 0)
.OrderBy(cs => cs.EffDate).ToList();
int totalQuantity = channelStockEffDate.Sum(it => it.Quantity);
@ -664,6 +697,7 @@ namespace DM_Weight.ViewModels
Type = MsgType.SUCCESS,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
RequestData();
}
if (!f.IsSuccess)
{
@ -678,7 +712,6 @@ namespace DM_Weight.ViewModels
_isFinishClick = false;
}
RequestData();
});
}
// 取消按钮

View File

@ -174,6 +174,7 @@ namespace DM_Weight.ViewModels
orderDetails = SqlSugarHelper.Db.Queryable<OrderDetail>()
.Includes<DrugInfo>(od => od.DrugInfo)
.InnerJoin(SqlSugarHelper.Db.Queryable<ChannelStock>().Where(cs => cs.DrawerType == 1).Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"] ?? "DM1")).GroupBy(cs => cs.DrugId), (od, t) => od.DrugId == t.DrugId)
.Where(od=>od.DMStatus==0)
.Where(od => od.OrderNo == OrderInfo.OrderNo)
.ToList();
@ -206,12 +207,14 @@ namespace DM_Weight.ViewModels
ChannelStock stock = HasQChannels[j];
if (TakeQ > stock.Quantity)
{
stock.OrderQuantity= orderDetail.Quantity;
stock.TakeQuantity = stock.Quantity;
channelStocks.Add(stock);
TakeQ -= stock.Quantity;
}
else
{
stock.OrderQuantity = orderDetail.Quantity;
stock.TakeQuantity = TakeQ;
channelStocks.Add(stock);
TakeQ = 0;
@ -220,7 +223,16 @@ namespace DM_Weight.ViewModels
}
else
{
msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】");
//msg.Add($"药品【{orderDetail.DrugInfo.DrugName}】库存不足,应取【{TakeQ}】库存【{total}】");
//数量不够就把全部数量取出
for (int n = 0; n < HasQChannels.Count; n++)
{
ChannelStock stock = HasQChannels[n];
stock.OrderQuantity = TakeQ;
stock.TakeQuantity = stock.Quantity;
channelStocks.Add(stock);
}
}
}
if (msg.Count > 0)
@ -332,17 +344,50 @@ namespace DM_Weight.ViewModels
try
{
SqlSugarHelper.Db.BeginTran();
//如果处方下全部药品都取完则更新orderInfo,order_detail中的dm_status
if (ChannelStocks.Sum(cs => cs.TakeQuantity) == ChannelStocks.Sum(cs => cs.OrderQuantity))
{
logger.Info($"更新OrderInfo:{InvoiceId}");
SqlSugarHelper.Db.Updateable(new OrderInfo()
{
DmStatus = 1,
OrderNo = OrderInfo.OrderNo
}).UpdateColumns(it => new { it.DmStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
DMStatus = 1,
OrderNo = OrderInfo.OrderNo
}).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo }).ExecuteCommand();
}
logger.Info("进入record循环");
for (int i = 0; i < record.Count; i++)
{
ChannelStock it = record[i];
//该药品下的所有取出数量
int alTakeQuantity=record.Where(rd=>rd.DrugId==it.DrugId).Sum(rd=>rd.TakeQuantity);
//处方下某一个药品都取完则更新order_detail
if(it.OrderQuantity==it.TakeQuantity|| it.OrderQuantity == alTakeQuantity)
{
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
DMStatus = 1,
OrderNo = OrderInfo.OrderNo,
DrugId= it.DrugId,
}).UpdateColumns(it => new { it.DMStatus }).WhereColumns(it => new { it.OrderNo,it.DrugId }).ExecuteCommand();
}
else
{
//处方下某一个药品没有取完则更新order_detail中的取药数量应取-已取)
SqlSugarHelper.Db.Updateable(new OrderDetail()
{
Quantity = it.OrderQuantity- alTakeQuantity,
OrderNo = OrderInfo.OrderNo,
DrugId = it.DrugId,
}).UpdateColumns(it => new { it.Quantity }).WhereColumns(it => new { it.OrderNo, it.DrugId }).ExecuteCommand();
}
logger.Info($"更新ChannelStock:{it.Id}");
// 更新数据 库存信息

View File

@ -144,13 +144,6 @@
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTextColumn Width="100"
Header="数量"
IsReadOnly="True"
Binding="{Binding Quantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTextColumn Width="130"
Header="批次"
IsReadOnly="True"
@ -166,12 +159,35 @@
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTextColumn Width="100"
Header="取出数量"
Header="库存数量"
IsReadOnly="True"
Binding="{Binding TakeQuantity}"
Binding="{Binding Quantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTextColumn Width="100"
Header="应取数量"
IsReadOnly="True"
Binding="{Binding OrderQuantity}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
/>
<DataGridTemplateColumn Width="100"
Header="取出数量">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Style="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<TextBox.Text>
<Binding Path="TakeQuantity" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="3">

View File

@ -22,6 +22,7 @@
<convert:DrawerSelectConverter x:Key="DrawerSelectConverter" />
<convert:StatusConverter x:Key="StatusConverter" />-->
<convert:TotalCountConverter x:Key="TotalCountConverter" />
<convert:ColorCountConverter x:Key="ColorCountConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -120,7 +121,9 @@
<!--GroupStyle to group data-->
<!--<DataGrid.GroupStyle>
<GroupStyle>
--><!--Group DataItems into DataGroup--><!--
-->
<!--Group DataItems into DataGroup-->
<!--
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
@ -184,6 +187,20 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!--<DataGridTemplateColumn Header="库存" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding channelStocks}" materialDesign:ListBoxItemAssist.ShowSelection="False" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Quantity}" Foreground="{Binding Path=Quantity,Converter={StaticResource ColorCountConverter} }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>-->
</DataGrid.Columns>
</DataGrid>
<!--<ListView Grid.Row="1"