Browse Source

采购审计

qianyi
shanji 3 years ago
parent
commit
9786d950e7
  1. 10
      BBWY.Client/Models/FinancialTerminal/ProcurementAudit/AuditShopOrder.cs
  2. 3
      BBWY.Client/Resources/Themes/Generic.xaml
  3. 278
      BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs
  4. 64
      BBWY.Client/Views/FinancialTerminal/ProcurementAudit.xaml

10
BBWY.Client/Models/FinancialTerminal/ProcurementAudit/AuditShopOrder.cs

@ -30,6 +30,11 @@ namespace BBWY.Client.Models
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 支付时间
/// </summary>
public DateTime? PayTime { get; set; }
/// <summary>
/// 联系电话
/// </summary>
@ -44,6 +49,11 @@ namespace BBWY.Client.Models
/// 收货人
/// </summary>
public string ContactName { get; set; }
/// <summary>
/// 商家备注
/// </summary>
public string VenderRemark { get; set; }
/// <summary>
/// 关联的采购单号

3
BBWY.Client/Resources/Themes/Generic.xaml

@ -279,6 +279,9 @@
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="verticalCenterTextBlock" TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="DataGrid">
<Setter Property="AutoGenerateColumns" Value="False"/>

278
BBWY.Client/ViewModels/FinancialTerminal/ProcurementAuditViewModel.cs

@ -9,6 +9,8 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
@ -17,6 +19,12 @@ namespace BBWY.Client.ViewModels
public class ProcurementAuditViewModel : BaseVM, IDenpendency
{
private AuditFile selectAuditFile;
private bool isLoading;
private bool isAudited;
private bool isShowPayBillPanel;
private bool isShowPurchaseOrderPanel;
private bool isShowShopOrderPanel;
private bool onlyException;
public IList<AuditFile> AuditFileList { get; set; }
@ -32,7 +40,69 @@ namespace BBWY.Client.ViewModels
public IList<AuditShopOrder> ShowAuditShopOrderList { get; set; }
public AuditFile SelectAuditFile { get => selectAuditFile; set { Set(ref selectAuditFile, value); } }
public AuditFile SelectAuditFile
{
get => selectAuditFile; set
{
if (Set(ref selectAuditFile, value))
OnSelectAuditFileChanged();
}
}
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
public bool IsAudited { get => isAudited; set { Set(ref isAudited, value); } }
public bool IsShowPayBillPanel
{
get => isShowPayBillPanel; set
{
if (Set(ref isShowPayBillPanel, value))
{
if (value)
{
IsShowPurchaseOrderPanel = false;
IsShowShopOrderPanel = false;
}
}
}
}
public bool IsShowPurchaseOrderPanel
{
get => isShowPurchaseOrderPanel; set
{
if (Set(ref isShowPurchaseOrderPanel, value))
{
if (value)
{
IsShowPayBillPanel = false;
IsShowShopOrderPanel = false;
}
}
}
}
public bool IsShowShopOrderPanel
{
get => isShowShopOrderPanel; set
{
if (Set(ref isShowShopOrderPanel, value))
{
if (value)
{
IsShowPayBillPanel = false;
IsShowPurchaseOrderPanel = false;
}
}
}
}
public bool OnlyException
{
get => onlyException; set
{
if (Set(ref onlyException, value))
OnOnlyExceptionChanged();
}
}
public ICommand AuditCommand { get; set; }
@ -40,16 +110,10 @@ namespace BBWY.Client.ViewModels
public ICommand ImportAliPayBillCommand { get; set; }
public ICommand Import1688PurchaseOrderCommand { get; set; }
public ICommand ImportJDShopOrderCommand { get; set; }
public ProcurementAuditViewModel()
{
AuditFileList = new ObservableCollection<AuditFile>();
@ -64,9 +128,9 @@ namespace BBWY.Client.ViewModels
ImportJDShopOrderCommand = new RelayCommand(ImportJDShopOrder);
AuditFileList = new ObservableCollection<AuditFile>();
AuditPayBillList = new ObservableCollection<AuditPayBill>();
AuditPurchaseOrderList = new ObservableCollection<AuditPurchaseOrder>();
AuditShopOrderList = new ObservableCollection<AuditShopOrder>();
AuditPayBillList = new List<AuditPayBill>();
AuditPurchaseOrderList = new List<AuditPurchaseOrder>();
AuditShopOrderList = new List<AuditShopOrder>();
ShowAuditPayBillList = new ObservableCollection<AuditPayBill>();
ShowAuditPurchaseOrderList = new ObservableCollection<AuditPurchaseOrder>();
ShowAuditShopOrderList = new ObservableCollection<AuditShopOrder>();
@ -79,6 +143,8 @@ namespace BBWY.Client.ViewModels
private void Audit()
{
if (IsLoading)
return;
if (AuditPayBillList.Count() == 0 ||
AuditPurchaseOrderList.Count() == 0 ||
AuditShopOrderList.Count() == 0)
@ -87,18 +153,124 @@ namespace BBWY.Client.ViewModels
return;
}
AuditByPayBill();
AuditByPurchaseOrder();
}
var waitList = new List<EventWaitHandle>()
{
new ManualResetEvent(false),
new ManualResetEvent(false)
};
IsLoading = true;
Task.Factory.StartNew(() =>
{
AuditByPayBill(waitList[0]);
AuditByPurchaseOrder(waitList[1]);
}).ContinueWith(t =>
{
WaitHandle.WaitAll(waitList.ToArray(), -1);
IsLoading = false;
IsAudited = true;
private void AuditByPayBill()
{
App.Current.Dispatcher.BeginInvoke((Action)delegate
{
SelectAuditFile = AuditFileList.FirstOrDefault(f => f.AuditFileType == AuditFileType.);
});
});
}
private void AuditByPurchaseOrder()
private void AuditByPayBill(EventWaitHandle ewh)
{
try
{
foreach (var payBill in AuditPayBillList)
{
#region 匹配采购单
var relationPurchaseOrder = AuditPurchaseOrderList.FirstOrDefault(p => p.PurchaseOrderId == payBill.MerchantOrderNo);
if (relationPurchaseOrder == null)
{
//未通过商户订单号找到采购单,则通过账单金额和日期匹配
relationPurchaseOrder = AuditPurchaseOrderList.FirstOrDefault(p => p.PayAmount == payBill.ExpenditureAmount &&
p.PayTime != null && payBill.PayTime != null &&
Math.Abs((payBill.PayTime.Value - p.PayTime.Value).TotalSeconds) <= 60);
}
if (relationPurchaseOrder == null)
{
payBill.ErrorMessage = "未匹配采购单";
continue;
}
payBill.RelationPurchaseOrderId = relationPurchaseOrder.PurchaseOrderId;
#endregion
#region 匹配销售订单
var relationShopOrder = AuditShopOrderList.FirstOrDefault(o => (!string.IsNullOrEmpty(o.VenderRemark) && o.VenderRemark.Contains(relationPurchaseOrder.PurchaseOrderId)) ||
(o.Phone == relationPurchaseOrder.Phone &&
o.ContactName == relationPurchaseOrder.ContactName &&
o.PayTime != null && relationPurchaseOrder.PayTime != null &&
(relationPurchaseOrder.PayTime.Value - o.PayTime.Value).TotalDays <= 2));
if (relationShopOrder == null)
{
payBill.ErrorMessage = "未匹配销售订单";
continue;
}
payBill.RelationShopOrderId = relationShopOrder.OrderId;
#endregion
}
}
catch (Exception ex)
{
App.Current.Dispatcher.Invoke(() => MessageBox.Show(ex.Message, "账单匹配"));
}
finally
{
ewh.Set();
}
}
private void AuditByPurchaseOrder(EventWaitHandle ewh)
{
try
{
foreach (var purchaseOrder in AuditPurchaseOrderList)
{
#region 匹配账单
var relationPayBill = AuditPayBillList.FirstOrDefault(b => b.MerchantOrderNo == purchaseOrder.PurchaseOrderId);
if (relationPayBill == null)
{
//未通过商户订单号找到采购单,则通过账单金额和日期匹配
relationPayBill = AuditPayBillList.FirstOrDefault(b => purchaseOrder.PayAmount == b.ExpenditureAmount &&
purchaseOrder.PayTime != null && b.PayTime != null &&
Math.Abs((b.PayTime.Value - purchaseOrder.PayTime.Value).TotalSeconds) <= 60);
}
if (relationPayBill == null)
{
purchaseOrder.ErrorMessage = "未匹配支付账单";
continue;
}
purchaseOrder.RelationPayBillNo = relationPayBill.PayBillNo;
#endregion
#region 匹配销售单
var relationShopOrder = AuditShopOrderList.FirstOrDefault(o => (!string.IsNullOrEmpty(o.VenderRemark) && o.VenderRemark.Contains(purchaseOrder.PurchaseOrderId)) ||
(o.Phone == purchaseOrder.Phone &&
o.ContactName == purchaseOrder.ContactName &&
o.PayTime != null && purchaseOrder.PayTime != null &&
(purchaseOrder.PayTime.Value - o.PayTime.Value).TotalDays <= 2));
if (relationShopOrder == null)
{
purchaseOrder.ErrorMessage = "未匹配销售订单";
continue;
}
purchaseOrder.RelationShopOrderId = relationShopOrder.OrderId;
#endregion
}
}
catch (Exception ex)
{
App.Current.Dispatcher.Invoke(() => MessageBox.Show(ex.Message, "采购单匹配"));
}
finally
{
ewh.Set();
}
}
private void ClearAudit()
@ -111,6 +283,11 @@ namespace BBWY.Client.ViewModels
ShowAuditPayBillList.Clear();
ShowAuditPurchaseOrderList.Clear();
ShowAuditShopOrderList.Clear();
IsAudited = false;
IsShowPayBillPanel = false;
IsShowPurchaseOrderPanel = false;
IsShowShopOrderPanel = false;
OnlyException = false;
}
private (string ErrorMessage, string FileName, IList<string> Lines) ImportAuditFile(AuditFileType auditFileType)
@ -145,6 +322,8 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入支付宝账单");
return;
}
if (importResult.Lines == null || importResult.Lines.Count() == 0)
return;
//忽略前5行
/*
#
@ -174,7 +353,10 @@ namespace BBWY.Client.ViewModels
foreach (var line in importResult.Lines)
{
var array = line.CSVstrToArry();
payBillNo = array[0].Replace("\"", string.Empty).Replace("\t", string.Empty).Trim();
var expenditureAmount = decimal.Parse(array[7].FormatString());
if (expenditureAmount == 0) //支出为0的账单不参与审计
continue;
payBillNo = array[0].FormatString();
if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo))
continue;
var payBill = new AuditPayBill()
@ -186,7 +368,7 @@ namespace BBWY.Client.ViewModels
ProductName = array[3].FormatString(),
PayTime = DateTime.Parse(array[4].FormatString()),
OppositeAccount = array[5].FormatString(),
ExpenditureAmount = decimal.Parse(array[7].FormatString())
ExpenditureAmount = Math.Abs(expenditureAmount)
};
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo;
if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP"))
@ -211,6 +393,8 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入1688采购单");
return;
}
if (importResult.Lines == null || importResult.Lines.Count() == 0)
return;
//去掉列名
importResult.Lines.RemoveAt(0);
@ -262,6 +446,8 @@ namespace BBWY.Client.ViewModels
MessageBox.Show(importResult.ErrorMessage, "导入京东销售订单");
return;
}
if (importResult.Lines == null || importResult.Lines.Count() == 0)
return;
//去掉列名
importResult.Lines.RemoveAt(0);
@ -277,9 +463,20 @@ namespace BBWY.Client.ViewModels
var order = new AuditShopOrder()
{
OrderId = orderId,
Platform = Platform.,
BelongFileName = importResult.FileName,
Quantity = int.Parse(array[3].FormatString()),
CreateTime = DateTime.Parse(array[5].FormatString()),
PayAmount = decimal.Parse(array[10].FormatString()),
ContactName = array[14].FormatString(),
Address = array[15].FormatString(),
Phone = array[16].FormatString(),
ProductName = array[2].FormatString(),
VenderRemark = array[27].FormatString()
};
AuditShopOrderList.Add(order);
if (!string.IsNullOrEmpty(array[30]))
order.PayTime = DateTime.Parse(array[30].FormatString());
}
}
catch (Exception ex)
@ -287,5 +484,48 @@ namespace BBWY.Client.ViewModels
MessageBox.Show($"问题销售订单号{orderId} {ex.Message}", "导入京东销售订单");
}
}
/// <summary>
/// 采购审计文件对象改变事件
/// </summary>
private void OnSelectAuditFileChanged()
{
if (SelectAuditFile == null)
return;
if (SelectAuditFile.AuditFileType == AuditFileType.)
{
IsShowPayBillPanel = true;
ShowAuditPayBillList.Clear();
var where = AuditPayBillList.Where(b => b.BelongFileName == SelectAuditFile.FileName);
if (OnlyException)
where = where.Where(b => !string.IsNullOrEmpty(b.ErrorMessage));
var list = where.ToList();
foreach (var b in list)
ShowAuditPayBillList.Add(b);
}
else if (SelectAuditFile.AuditFileType == AuditFileType.)
{
IsShowPurchaseOrderPanel = true;
ShowAuditPurchaseOrderList.Clear();
var where = AuditPurchaseOrderList.Where(p => p.BelongFileName == SelectAuditFile.FileName);
if (OnlyException)
where = where.Where(p => !string.IsNullOrEmpty(p.ErrorMessage));
var list = where.ToList();
foreach (var p in list)
ShowAuditPurchaseOrderList.Add(p);
}
else if (SelectAuditFile.AuditFileType == AuditFileType.)
{
}
}
private void OnOnlyExceptionChanged()
{
if (SelectAuditFile == null || AuditFileList.Count() == 0)
return;
SelectAuditFile = null;
SelectAuditFile = AuditFileList.FirstOrDefault(f => f.AuditFileType == AuditFileType.);
}
}
}

64
BBWY.Client/Views/FinancialTerminal/ProcurementAudit.xaml

@ -19,6 +19,7 @@
<RowDefinition Height="5"/>
<RowDefinition Height="30"/>
<RowDefinition Height="5"/>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="{StaticResource Border.Background}" Padding="5,0">
@ -73,14 +74,21 @@
IsEnabled="False" DisableText="{Binding Content,RelativeSource={RelativeSource Mode=Self}}"/>
</StackPanel>
</Border>
</Grid>
<ListBox ItemsSource="{Binding AuditFileList}"
SelectedItem="{Binding SelectAuditFile,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
ItemContainerStyle="{StaticResource NoBgListBoxItemStyle}"
Grid.Row="4">
Grid.Row="4"
IsEnabled="{Binding IsAudited,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource NoBgListBoxItemStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding AuditFileType}" Value="销售订单">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
@ -107,6 +115,54 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<CheckBox Content="仅显示异常" Grid.Row="6"
IsChecked="{Binding OnlyException,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
FocusVisualStyle="{x:Null}"/>
<DataGrid ItemsSource="{Binding ShowAuditPayBillList}"
Grid.Row="7"
Visibility="{Binding IsShowPayBillPanel,Converter={StaticResource objConverter},ConverterParameter=true:Visible:Collapsed}">
<DataGrid.Columns>
<DataGridTextColumn Header="账单流水号" Width="145" Binding="{Binding PayBillNo}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="账单平台" Width="60" Binding="{Binding PayBillType}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="支付时间" Width="130" Binding="{Binding PayTime,StringFormat=yyyy-MM-dd HH:mm:ss}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="对方账号" Width="100" Binding="{Binding OppositeAccount}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="支出金额" Width="60" Binding="{Binding ExpenditureAmount}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="商户订单号" Width="200" Binding="{Binding SourceMerchantOrderNo}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="归属店铺" Width="100" Binding="{Binding BelongShop}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="关联采购单" Width="140" Binding="{Binding RelationPurchaseOrderId}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="关联销售单" Width="140" Binding="{Binding RelationShopOrderId}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="异常内容" Width="*" Binding="{Binding ErrorMessage}" Foreground="Red" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
</DataGrid.Columns>
</DataGrid>
<DataGrid ItemsSource="{Binding ShowAuditPurchaseOrderList}"
Grid.Row="7"
Visibility="{Binding IsShowPurchaseOrderPanel,Converter={StaticResource objConverter},ConverterParameter=true:Visible:Collapsed}">
<DataGrid.Columns>
<DataGridTextColumn Header="采购单号" Width="145" Binding="{Binding PurchaseOrderId}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="采购平台" Width="60" Binding="{Binding Platform}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="创建时间" Width="130" Binding="{Binding CreateTime,StringFormat=yyyy-MM-dd HH:mm:ss}"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="付款时间" Width="130" Binding="{Binding CreateTime,StringFormat=yyyy-MM-dd HH:mm:ss}"
ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="货品总价" Width="60" Binding="{Binding ProductAmount}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="运费" Width="60" Binding="{Binding Freight}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="联系人" Width="60" Binding="{Binding ContactName}" ElementStyle="{StaticResource middleTextBlock}"/>
<DataGridTextColumn Header="手机号" Width="90" Binding="{Binding Phone}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="收货地址" Width="150" Binding="{Binding Address}"/>
<DataGridTextColumn Header="归属店铺" Width="100" Binding="{Binding BelongShop}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="关联账单" Width="140" Binding="{Binding RelationPayBillNo}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="关联销售单" Width="140" Binding="{Binding RelationShopOrderId}" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
<DataGridTextColumn Header="异常内容" Width="*" Binding="{Binding ErrorMessage}" Foreground="Red" ElementStyle="{StaticResource verticalCenterTextBlock}"/>
</DataGrid.Columns>
</DataGrid>
<DataGrid ItemsSource="{Binding ShowAuditShopOrderList}"
Grid.Row="7"
Visibility="{Binding IsShowShopOrderPanel,Converter={StaticResource objConverter},ConverterParameter=true:Visible:Collapsed}">
</DataGrid>
</Grid>
</Grid>
</Page>

Loading…
Cancel
Save