|
|
@ -1,4 +1,5 @@ |
|
|
|
using BBWY.Client.APIServices; |
|
|
|
using BBWY.Client.Extensions; |
|
|
|
using BBWY.Client.Models; |
|
|
|
using BBWY.Common.Models; |
|
|
|
using GalaSoft.MvvmLight.Command; |
|
|
@ -27,9 +28,24 @@ namespace BBWY.Client.ViewModels |
|
|
|
//private bool isShowShopOrderPanel;
|
|
|
|
private bool onlyException; |
|
|
|
private ShopService shopService; |
|
|
|
private PurchaseOrderService purchaseOrderService; |
|
|
|
private Department selectedDepartment; |
|
|
|
private DateTime startDate; |
|
|
|
private DateTime endDate; |
|
|
|
public Department SelectedDepartment |
|
|
|
{ |
|
|
|
get => selectedDepartment; set |
|
|
|
{ |
|
|
|
if (Set(ref selectedDepartment, value)) |
|
|
|
{ |
|
|
|
foreach (var s in value.ShopList) |
|
|
|
s.IsSelected = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Department SelectedDepartment { get => selectedDepartment; set { Set(ref selectedDepartment, value); } } |
|
|
|
public DateTime StartDate { get => startDate; set { Set(ref startDate, value); } } |
|
|
|
public DateTime EndDate { get => endDate; set { Set(ref endDate, value); } } |
|
|
|
|
|
|
|
public IList<AuditFile> AuditFileList { get; set; } |
|
|
|
|
|
|
@ -122,13 +138,14 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
public ICommand ImportJDShopOrderCommand { get; set; } |
|
|
|
|
|
|
|
public ProcurementAuditViewModel(ShopService shopService) |
|
|
|
public ProcurementAuditViewModel(ShopService shopService, PurchaseOrderService purchaseOrderService) |
|
|
|
{ |
|
|
|
AuditFileList = new ObservableCollection<AuditFile>(); |
|
|
|
AuditCommand = new RelayCommand(Audit); |
|
|
|
ClearAuditCommand = new RelayCommand(ClearAudit); |
|
|
|
ImportAliPayBillCommand = new RelayCommand(ImportAliPayBill); |
|
|
|
this.shopService = shopService; |
|
|
|
this.purchaseOrderService = purchaseOrderService; |
|
|
|
|
|
|
|
DepartmentList = new ObservableCollection<Department>(); |
|
|
|
AuditFileList = new ObservableCollection<AuditFile>(); |
|
|
@ -143,6 +160,8 @@ namespace BBWY.Client.ViewModels |
|
|
|
//AuditFileList.Add(new AuditFile() { FileName = "1688采购单20220527.csv", AuditFileType = AuditFileType.采购单 });
|
|
|
|
//AuditFileList.Add(new AuditFile() { FileName = "支付宝账单20220527.csv", AuditFileType = AuditFileType.销售订单 });
|
|
|
|
LoadDepartment(); |
|
|
|
StartDate = DateTime.Now.Date; |
|
|
|
EndDate = DateTime.Now.Date; |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadDepartment() |
|
|
@ -160,6 +179,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
{ |
|
|
|
foreach (var d in response.Data) |
|
|
|
DepartmentList.Add(d); |
|
|
|
SelectedDepartment = DepartmentList[0]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
@ -168,9 +188,7 @@ namespace BBWY.Client.ViewModels |
|
|
|
{ |
|
|
|
if (IsLoading) |
|
|
|
return; |
|
|
|
if (AuditPayBillList.Count() == 0) |
|
|
|
//AuditPurchaseOrderList.Count() == 0 ||
|
|
|
|
//AuditShopOrderList.Count() == 0)
|
|
|
|
if (AuditPayBillList.Count() == 0 || !SelectedDepartment.ShopList.Any(s => s.IsSelected)) |
|
|
|
{ |
|
|
|
MessageBox.Show("审核数据不全", "提示"); |
|
|
|
return; |
|
|
@ -178,13 +196,15 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
var waitList = new List<EventWaitHandle>() |
|
|
|
{ |
|
|
|
new ManualResetEvent(false), |
|
|
|
new ManualResetEvent(false) |
|
|
|
}; |
|
|
|
IsLoading = true; |
|
|
|
var shopList = SelectedDepartment.ShopList.Where(s => s.IsSelected).ToList(); |
|
|
|
var sDate = StartDate; |
|
|
|
var eDate = EndDate; |
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
AuditByPayBill(waitList[0]); |
|
|
|
AuditByPayBill(waitList[0], shopList, sDate, eDate); |
|
|
|
//AuditByPurchaseOrder(waitList[1]);
|
|
|
|
}).ContinueWith(t => |
|
|
|
{ |
|
|
@ -200,57 +220,31 @@ namespace BBWY.Client.ViewModels |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void AuditByPayBill(EventWaitHandle ewh) |
|
|
|
private void AuditByPayBill(EventWaitHandle ewh, IList<SimpleShop> shopList, DateTime startDate, DateTime endDate) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var auditPurchaseOrderResponse = purchaseOrderService.GetAuditPurchaseOrderList(shopList.Select(s => s.Id).ToList(), startDate, endDate); |
|
|
|
if (!auditPurchaseOrderResponse.Success) |
|
|
|
throw new Exception($"获取采购单失败,{auditPurchaseOrderResponse.Msg}"); |
|
|
|
|
|
|
|
|
|
|
|
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 relationPurchaseOrder = auditPurchaseOrderResponse.Data.FirstOrDefault(p => p.PurchaseOrderId == payBill.MerchantOrderNo); |
|
|
|
|
|
|
|
//#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
|
|
|
|
if (relationPurchaseOrder == null) |
|
|
|
{ |
|
|
|
payBill.ErrorMessage = "未匹配采购单"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
payBill.RelationPurchaseOrderId = relationPurchaseOrder.PurchaseOrderId; |
|
|
|
payBill.RelationShopOrderId = relationPurchaseOrder.OrderId; |
|
|
|
payBill.BelongShopId = relationPurchaseOrder.ShopId; |
|
|
|
payBill.BelongShop = shopList.FirstOrDefault(s => s.Id == relationPurchaseOrder.ShopId)?.Name; |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
//var relationShoporderIds = AuditPayBillList.Where(p => !string.IsNullOrEmpty(p.RelationShopOrderId)).Select(p => p.RelationShopOrderId).ToList();
|
|
|
|
//var belongResponse = shopService.GetOrderBelongShop(relationShoporderIds);
|
|
|
|
//if (!belongResponse.Success || belongResponse.Data.Count() == 0)
|
|
|
|
// return;
|
|
|
|
|
|
|
|
//foreach (var payBill in AuditPayBillList)
|
|
|
|
//{
|
|
|
|
// if (string.IsNullOrEmpty(payBill.RelationShopOrderId))
|
|
|
|
// continue;
|
|
|
|
// var belongShop = belongResponse.Data.FirstOrDefault(x => x.OrderIdList.Contains(payBill.RelationShopOrderId));
|
|
|
|
// if (belongShop != null)
|
|
|
|
// payBill.BelongShop = belongShop.ShopName;
|
|
|
|
//}
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
@ -392,8 +386,8 @@ namespace BBWY.Client.ViewModels |
|
|
|
#-----------------------------------------账务明细列表---------------------------------------- |
|
|
|
账务流水号 业务流水号 商户订单号 商品名称 发生时间 对方账号 收入金额(+元) 支出金额(-元) 账户余额(元) 交易渠道 业务类型 备注 |
|
|
|
*/ |
|
|
|
//for (var i = 0; i < 5; i++)
|
|
|
|
// importResult.DataTable.RemoveAt(0);
|
|
|
|
for (var i = 0; i < 5; i++) |
|
|
|
importResult.Lines.RemoveAt(0); |
|
|
|
|
|
|
|
//忽略后4行
|
|
|
|
/* |
|
|
@ -402,44 +396,44 @@ namespace BBWY.Client.ViewModels |
|
|
|
#收入合计:85笔,共43889.26元 |
|
|
|
#导出时间:[2022年05月01日 10:13:45] |
|
|
|
*/ |
|
|
|
//for (var i = 0; i < 4; i++)
|
|
|
|
//{
|
|
|
|
// importResult.Lines.RemoveAt(importResult.Lines.Count() - 1);
|
|
|
|
//}
|
|
|
|
for (var i = 0; i < 4; i++) |
|
|
|
{ |
|
|
|
importResult.Lines.RemoveAt(importResult.Lines.Count() - 1); |
|
|
|
} |
|
|
|
|
|
|
|
var payBillNo = ""; |
|
|
|
try |
|
|
|
{ |
|
|
|
//foreach (var line in importResult.Lines)
|
|
|
|
//{
|
|
|
|
// var array = line.CSVstrToArry();
|
|
|
|
// var sourceMerchantOrderNo = array[2].FormatString();
|
|
|
|
// if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP"))
|
|
|
|
// continue; //暂时不支持此类商户单号
|
|
|
|
foreach (var line in importResult.Lines) |
|
|
|
{ |
|
|
|
var array = line.CSVstrToArry(); |
|
|
|
var sourceMerchantOrderNo = array[2].FormatString(); |
|
|
|
if (!string.IsNullOrEmpty(sourceMerchantOrderNo) && sourceMerchantOrderNo.StartsWith("XP")) |
|
|
|
continue; //暂时不支持此类商户单号
|
|
|
|
|
|
|
|
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() |
|
|
|
{ |
|
|
|
BelongFileName = importResult.FileName, |
|
|
|
PayBillNo = payBillNo, |
|
|
|
PayBillType = PayBillType.AliPay, |
|
|
|
SourceMerchantOrderNo = sourceMerchantOrderNo, |
|
|
|
ProductName = array[3].FormatString(), |
|
|
|
PayTime = DateTime.Parse(array[4].FormatString()), |
|
|
|
OppositeAccount = array[5].FormatString(), |
|
|
|
ExpenditureAmount = Math.Abs(expenditureAmount) |
|
|
|
}; |
|
|
|
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo; |
|
|
|
if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP")) |
|
|
|
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8); |
|
|
|
|
|
|
|
// 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()
|
|
|
|
// {
|
|
|
|
// BelongFileName = importResult.FileName,
|
|
|
|
// PayBillNo = payBillNo,
|
|
|
|
// PayBillType = PayBillType.AliPay,
|
|
|
|
// SourceMerchantOrderNo = sourceMerchantOrderNo,
|
|
|
|
// ProductName = array[3].FormatString(),
|
|
|
|
// PayTime = DateTime.Parse(array[4].FormatString()),
|
|
|
|
// OppositeAccount = array[5].FormatString(),
|
|
|
|
// ExpenditureAmount = Math.Abs(expenditureAmount)
|
|
|
|
// };
|
|
|
|
// payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo;
|
|
|
|
// if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP"))
|
|
|
|
// payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8);
|
|
|
|
|
|
|
|
// AuditPayBillList.Add(payBill);
|
|
|
|
//}
|
|
|
|
AuditPayBillList.Add(payBill); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|