diff --git a/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceView.xaml b/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceView.xaml
index a79a1bf..bd62198 100644
--- a/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceView.xaml
+++ b/29WxOrderWpf/Ctrls/PDDInvoice/PDDInvoiceView.xaml
@@ -289,7 +289,21 @@
VerticalContentAlignment="Center"
Text="{Binding TaxNo}" />
-
+
+
+
+
@@ -310,7 +324,7 @@
@@ -322,7 +336,7 @@
-
+
-->
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
+
@@ -443,7 +479,8 @@
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
- IsChecked="{Binding IsSelected}" />
+ IsChecked="{Binding IsSelected}"
+ IsEnabled="{Binding IsSelected}" />
diff --git a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceOrderModel.cs b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceOrderModel.cs
index 0d86986..c431dc8 100644
--- a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceOrderModel.cs
+++ b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceOrderModel.cs
@@ -71,7 +71,7 @@ public class PddBrowserOrderInvoiceViewModel : BindableBaseEx
public int Quantity => order_Goods?.Sum(a => a.goods_number.Value) ?? 0;
/// 发票状态文案:已开票 / 待开票
- public string InvoiceStatusText => IsInvoiced ? "已开票" : "待开票";
+ public string InvoiceStatusText => IsInvoiced ? "已提交申请" : "待开票";
public DateTime OrderTime
diff --git a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs
index d09d0ae..7ab1c22 100644
--- a/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs
+++ b/29WxOrderWpf/Ctrls/PDDInvoice/ViewModels/PDDInvoiceViewModel.cs
@@ -10,6 +10,7 @@ using AllBase.Util;
using CefSharp;
using CefSharp.Handler;
using CefSharp.Wpf;
+using MAX.Core.Helpers;
using NaiBa.Util.Extension;
using Newtonsoft.Json;
using System;
@@ -50,15 +51,23 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
private string _taxNo = "";
private CancellationTokenSource _cancellationTokenSource; public PDDInvoiceViewModel()
{
+
Orders = new ObservableCollection();
Orders.CollectionChanged += Orders_CollectionChanged;
BuyerLoginList = GlobalConfig.PDDBuyerLoginList;
//Orders = new ObservableCollection(_allOrders);
- //_ = InitSampleData();
InitBrowser();
+
+ if (EnvironmentHelper.IsTest)
+ {
+ InvoiceTitle = "嵩县雷神商贸有限责任公司";
+ TaxNo = "91410325MADQERT68E";
+ MaxAmount = 99;
+ _ = InitSampleData();
+ }
}
partial void InitBrowser();
@@ -164,7 +173,38 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
get => _taxNo;
set => SetProperty(ref _taxNo, value, nameof(TaxNo));
}
-
+ ///
+ /// 开始开票总金额
+ ///
+ public decimal AmountTotal
+ {
+ get => GetValue();
+ set => SetValue(value);
+ }
+ ///
+ /// 最大开票金额
+ ///
+ public decimal MaxAmount
+ {
+ get => GetValue();
+ set => SetValue(value);
+ }
+ ///
+ /// 已开票金额
+ ///
+ public decimal InvoicedAmountTotal
+ {
+ get => GetValue();
+ set => SetValue(value);
+ }
+ ///
+ /// 未开票金额
+ ///
+ public decimal UninvoicedAmountTotal
+ {
+ get => GetValue();
+ set => SetValue(value);
+ }
public ICommand SearchCommand => new DelegateCommand(Search);
public ICommand ResetCommand => new DelegateCommand(ResetSearch);
@@ -219,7 +259,11 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
#region 勾选 / 全选 / 反选
-
+ public int SelectedCount
+ {
+ get => GetValue();
+ set => SetValue(value);
+ }
private bool? _isSelectAll;
private bool _isUpdatingSelectAll;
@@ -235,7 +279,13 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
if (_isUpdatingSelectAll) return;
if (value == true)
{
- foreach (var order in Orders) order.IsSelected = true;
+ foreach (var order in Orders)
+ {
+ if (order.IsInvoiced == false)
+ {
+ order.IsSelected = true;
+ }
+ }
}
else if (value == false)
{
@@ -267,6 +317,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
}
int selected = Orders.Count(o => o.IsSelected);
IsSelectAll = selected == 0 ? false : selected == Orders.Count ? true : (bool?)null;
+ SelectedCount = selected;
}
finally
{
@@ -310,9 +361,13 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
BaseMsgWindow.ShowError("请先勾选需要开票的订单");
return;
}
-
+ if (MaxAmount <= 0)
+ {
+ BaseMsgWindow.ShowError("请填写开票总金额");
+ return;
+ }
var confirm = BaseMsgWindow.ShowConfirm(
- $"已勾选 {targets.Count} 个待开票订单,确定开始批量开票吗?\n请确认发票抬头与税号无误。",
+ $"已勾选 {targets.Count} 个待开票订单,确定开始批量开票吗?\n请确认发票抬头与税号无误。\n开票总金额:{MaxAmount}",
"批量开票");
if (confirm.DialogResult != true) return;
@@ -325,6 +380,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
private async Task BatchInvoiceAsync(List targets)
{
IsBatchInvoicing = true;
+ AmountTotal = 0;
int success = 0, fail = 0;
try
{
@@ -334,26 +390,43 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
for (int i = 0; i < targets.Count; i++)
{
+ if (AmountTotal >= MaxAmount)
+ {
+ return;
+ }
var order = targets[i];
BottomMsg = $"正在批量开票:{i}/{targets.Count},当前订单:{order.order_sn}";
ProgressValue = i;
+ bool ok = false;
+ if (EnvironmentHelper.IsTest)
+ {
+ ok = true;
+ await Task.Delay(1000);
+ }
+ else
+ {
+ _currentInvoiceTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+ BrowserDetail.Load($"https://mobile.yangkeduo.com/transac_return_compensation.html?_t_timestamp=transac_modify_invoice&order_sn={order.order_sn}");
- _currentInvoiceTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
- BrowserDetail.Load($"https://mobile.yangkeduo.com/transac_return_compensation.html?_t_timestamp=transac_modify_invoice&order_sn={order.order_sn}");
-
- // 等待页面脚本执行完成(最长 60 秒)
- var done = await Task.WhenAny(_currentInvoiceTcs.Task, Task.Delay(TimeSpan.FromSeconds(60)));
- bool ok = done == _currentInvoiceTcs.Task && _currentInvoiceTcs.Task.Result;
+ // 等待页面脚本执行完成(最长 60 秒)
+ var done = await Task.WhenAny(_currentInvoiceTcs.Task, Task.Delay(TimeSpan.FromSeconds(60)));
+ ok = done == _currentInvoiceTcs.Task && _currentInvoiceTcs.Task.Result;
+ }
if (ok)
{
order.IsInvoiced = true;
+ order.IsSelected = false;
success++;
+ AmountTotal += order.order_amount / 100m;
}
else
{
fail++;
}
ProgressValue = success + fail;
+ BottomMsg = $"正在批量开票:{i}/{targets.Count},当前订单:{order.order_sn}。总金额:{AmountTotal.ToString("N2")}";
+ StatisticsInvoiceAmount();
+ await Task.Delay(1000);
}
}
catch (Exception ex)
@@ -366,11 +439,19 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
_currentInvoiceTcs = null;
ProgressMaximum = targets.Count;
ProgressValue = targets.Count;
- BottomMsg = $"批量开票完成:成功 {success} 个,失败 {fail} 个";
+ BottomMsg = $"批量开票完成:成功 {success} 个,失败 {fail} 个。总金额:{AmountTotal.ToString("N2")}";
IsBatchInvoicing = false;
+ BaseMsgWindow.ShowInfo(BottomMsg);
}
}
-
+ ///
+ /// 统计发票金额
+ ///
+ private void StatisticsInvoiceAmount()
+ {
+ InvoicedAmountTotal = Orders.Where(a => a.IsInvoiced).Sum(a => a.order_amount) / 100m;
+ UninvoicedAmountTotal = Orders.Where(a => a.IsInvoiced == false).Sum(a => a.order_amount) / 100m;
+ }
#endregion
@@ -489,6 +570,8 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
Orders.Add(item);
}
}
+ StatisticsInvoiceAmount();
+
}
#endregion