发票助手增加一些提示和到达开票总金额后停止
This commit is contained in:
1 parent
3281fe7885
commit
0174700269
3 files changed
+148
-28
No files matched your search
@@ -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<PddBrowserOrderInvoiceViewModel>();
|
||||
Orders.CollectionChanged += Orders_CollectionChanged;
|
||||
|
||||
BuyerLoginList = GlobalConfig.PDDBuyerLoginList;
|
||||
//Orders = new ObservableCollection<PDDInvoiceOrderModel>(_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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始开票总金额
|
||||
/// </summary>
|
||||
public decimal AmountTotal
|
||||
{
|
||||
get => GetValue<decimal>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 最大开票金额
|
||||
/// </summary>
|
||||
public decimal MaxAmount
|
||||
{
|
||||
get => GetValue<decimal>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 已开票金额
|
||||
/// </summary>
|
||||
public decimal InvoicedAmountTotal
|
||||
{
|
||||
get => GetValue<decimal>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 未开票金额
|
||||
/// </summary>
|
||||
public decimal UninvoicedAmountTotal
|
||||
{
|
||||
get => GetValue<decimal>();
|
||||
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<int>();
|
||||
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<PddBrowserOrderInvoiceViewModel> 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<bool>(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<bool>(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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统计发票金额
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
|
||||
Reference in new issue
Block a user