Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #81

Merged
merged 5 commits into from
Apr 14, 2024
Merged

Dev #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Mapp.Application.Interfaces;
using Mapp.Common;
using WindowsInput.Native;

namespace Mapp.BusinessLogic.AutoComplete;
Expand All @@ -13,21 +14,24 @@ public interface IAutoKeyboardInputHelper : IDisposable

public class AutoKeyboardInputHelper : IAutoKeyboardInputHelper
{
private readonly IAutocompleteConfiguration _autocompleteConfiguration;
private readonly ISettingsWrapper _settingsWrapper;
private IInputSimulator _inputSim;
private IKeyboardHook _keyboardHook;
private bool _isCommandPressed;

public AutoKeyboardInputHelper(IAutocompleteConfiguration autocompleteConfiguration, IKeyboardHook keyboardHook, IInputSimulator inputSimulator)
public AutoKeyboardInputHelper(ISettingsWrapper settingsWrapper, IKeyboardHook keyboardHook, IInputSimulator inputSimulator)
{
_autocompleteConfiguration = autocompleteConfiguration;
_settingsWrapper = settingsWrapper;
_inputSim = inputSimulator;
_keyboardHook = keyboardHook; // TODO replace by https://www.nuget.org/packages/MouseKeyHook/

#if RELEASE
_keyboardHook.KeyDown += keyboardHook_KeyDown;
_keyboardHook.KeyUp += keyboardHook_KeyUp;

//Installing the Keyboard Hooks
_keyboardHook.Install();
#endif
}

public void Dispose()
Expand All @@ -48,7 +52,7 @@ private void keyboardHook_KeyDown(object sender, VKeys key)
if (key == VKeys.F4 && _isCommandPressed) /*&& elapsedTime.Seconds > 2*/
{
//_lastAutoinputTime = DateTime.Now;
_inputSim.TextEntry($"RR{_autocompleteConfiguration.TrackingCode}CZ");
_inputSim.TextEntry($"RR{_settingsWrapper.TrackingCode}CZ");
_inputSim.KeyPress(VirtualKeyCode.TAB);
Task.Delay(TimeSpan.FromMilliseconds(50));
_inputSim.TextEntry(DateTime.Now.ToString("dd.MM.yyyy"));
Expand All @@ -70,13 +74,3 @@ private void keyboardHook_KeyUp(object sender, VKeys key)
}
}
}

public interface IAutocompleteConfiguration
{
public string TrackingCode { get; set; }
}

public class AutocompleteConfiguration : IAutocompleteConfiguration
{
public string TrackingCode { get; set; }
}
24 changes: 13 additions & 11 deletions Mapp.BusinessLogic.Invoices/Invoices/InvoiceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ namespace Mapp.BusinessLogic.Invoices
{
public interface IInvoiceConverter
{
IAutocompleteData AutocompleteData { get; }
IEnumerable<Invoice> LoadAmazonReports(IEnumerable<string> reportsFileNames, InvoiceConversionContext conversionContext);

void ProcessInvoices(IEnumerable<Invoice> invoices, string fileName);
}

public class InvoiceConverter : IInvoiceConverter
{
public readonly IAutocompleteData _autocompleteData;
public IAutocompleteData AutocompleteData { get; }
private readonly ICurrencyConverter _currencyConverter;
private readonly IInvoicesXmlManager _invoicesXmlManager;
private readonly IAutocompleteDataLoader _autocompleteDataLoader;
Expand All @@ -34,14 +35,15 @@ public InvoiceConverter(
IAutocompleteDataLoader autocompleteDataLoader,
IDialogService dialogService)
{
_autocompleteData = autocompleteDataLoader.LoadSettings(); // TODO rewove!!
_currencyConverter = currencyConverter;
_invoicesXmlManager = invoicesXmlManager;
_autocompleteDataLoader = autocompleteDataLoader;
_dialogService = dialogService;
autocompleteDataLoader.LoadSettings();

_rates = csvLoader.LoadFixedCurrencyRates(); // TODO make it possible to choose from settings
_vatPercentage = csvLoader.LoadCountryVatRates(); // TODO make it possible to choose from settings

AutocompleteData = _autocompleteDataLoader.LoadSettings();
}

public IEnumerable<Invoice> LoadAmazonReports(IEnumerable<string> reportsFileNames, InvoiceConversionContext conversionContext)
Expand Down Expand Up @@ -148,9 +150,9 @@ private Invoice ProcessInvoiceLine(IReadOnlyDictionary<string, string> valuesFro

invoiceProduct.PackQuantityMultiplier = 1;
if (!string.IsNullOrEmpty(invoiceProduct.AmazonSku) &&
_autocompleteData.PackQuantitySku.ContainsKey(invoiceProduct.AmazonSku))
AutocompleteData.PackQuantitySku.ContainsKey(invoiceProduct.AmazonSku))
{
invoiceProduct.PackQuantityMultiplier = uint.Parse(_autocompleteData.PackQuantitySku[invoiceProduct.AmazonSku]);
invoiceProduct.PackQuantityMultiplier = uint.Parse(AutocompleteData.PackQuantitySku[invoiceProduct.AmazonSku]);
}
invoiceItems.Add(invoiceItemProduct);

Expand Down Expand Up @@ -229,7 +231,7 @@ private InvoiceItemBase FillInvoiceItem(InvoiceItemBase invoiceItem, string name

public void ProcessInvoices(IEnumerable<Invoice> invoices, string fileName)
{
_autocompleteDataLoader.SaveSettings(_autocompleteData);
_autocompleteDataLoader.SaveSettings(AutocompleteData);
_invoicesXmlManager.SerializeXmlInvoice(fileName, invoices);
}

Expand All @@ -243,7 +245,7 @@ private string GetCustomsDeclarationBySkuOnlyForNonEu(string sku, InvoiceVatClas
if (IsNonEuCountryByClassification(classification))
{
return GetAutocompleteOrEmpty(
_autocompleteData.CustomsDeclarationBySku,
AutocompleteData.CustomsDeclarationBySku,
sku,
string.Empty);
}
Expand All @@ -254,7 +256,7 @@ private string GetSavedShippingType(string sku, ClientInfo clientInfo, InvoiceVa
{
string defaultShippingName = "Shipping";

if (_autocompleteData.DefaultShippingByPartnerCountry.TryGetValue(clientInfo.Address.Country, out string countryDefaultShipping))
if (AutocompleteData.DefaultShippingByPartnerCountry.TryGetValue(clientInfo.Address.Country, out string countryDefaultShipping))
{
defaultShippingName = countryDefaultShipping;
}
Expand All @@ -266,22 +268,22 @@ private string GetSavedShippingType(string sku, ClientInfo clientInfo, InvoiceVa

// only for non-EU
return GetAutocompleteOrEmpty( // TODO ПРОБЛЕМА в том что при агригации шипиногов их названия будут стираться
_autocompleteData.ShippingNameBySku,
AutocompleteData.ShippingNameBySku,
sku,
defaultShippingName);
}

private string GetSavedItemCodeBySku(string sku)
{
return GetAutocompleteOrEmpty(
_autocompleteData.PohodaProdCodeBySku,
AutocompleteData.PohodaProdCodeBySku,
sku);
}

private string GetSavedWarehouseBySku(string sku)
{
return GetAutocompleteOrEmpty(
_autocompleteData.ProdWarehouseSectionBySku,
AutocompleteData.ProdWarehouseSectionBySku,
sku);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ namespace Mapp.BusinessLogic.StockQuantity;

public interface IStockQuantityUpdater
{
Task<IEnumerable<StockData>> ConvertWarehouseData();
IReadOnlyList<StockDataXmlSourceDefinition> SourceDefinitions { get; }
Task<IEnumerable<StockData>> ConvertWarehouseData(IReadOnlyList<StockDataXmlSourceDefinition> sources);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ public class StockQuantityUpdater : IStockQuantityUpdater
{
private readonly IJsonManager _jsonManager;
private readonly IDialogService _dialogService;
private readonly IEnumerable<StockDataXmlSourceDefinition> _sourceDefinitions;
public IReadOnlyList<StockDataXmlSourceDefinition> SourceDefinitions { get; }

public StockQuantityUpdater(IJsonManager jsonManager, IDialogService dialogService)
{
_jsonManager = jsonManager;
_dialogService = dialogService;
_sourceDefinitions = _jsonManager.LoadStockQuantityUpdaterConfigs();
SourceDefinitions = _jsonManager.LoadStockQuantityUpdaterConfigs();
}

public async Task<IEnumerable<StockData>> ConvertWarehouseData()
public async Task<IEnumerable<StockData>> ConvertWarehouseData(IReadOnlyList<StockDataXmlSourceDefinition> sources)
{
var httpClient = new HttpClient();

var stockDataTotal = new List<StockData>();

Dictionary<string, int> statistics = new Dictionary<string, int>();

foreach (var source in _sourceDefinitions)
foreach (var source in sources)
{
var stream = await (await httpClient.GetAsync(source.Url)).Content.ReadAsStreamAsync();
var stockData = ExtractStockData(stream, source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ public string TimeSeparatorOverride
get { return _timeSeparatorOverride; }
set
{
_timeSeparatorOverride = value;
if (_dataCultureInfo != null)
{
_dataCultureInfo.DateTimeFormat.TimeSeparator = TimeSeparatorOverride;
_dataCultureInfo.DateTimeFormat.TimeSeparator = _timeSeparatorOverride;
}

_timeSeparatorOverride = value;
}
}

public string NumericFormatSourceCultureName { get; set; }

private CultureInfo _dataCultureInfo;

public CultureInfo DateCultureInfo
Expand All @@ -45,7 +46,12 @@ public CultureInfo DateCultureInfo
if (_timeSeparatorOverride != null)
{
_dataCultureInfo.DateTimeFormat.TimeSeparator = _timeSeparatorOverride;
}
}
if (NumericFormatSourceCultureName != null)
{
var numbericCultureInfo = new CultureInfo(NumericFormatSourceCultureName);
_dataCultureInfo.NumberFormat = numbericCultureInfo.NumberFormat;
}
}
return _dataCultureInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public IEnumerable<Transaction> ReadTransactionsFromMultipleFiles(IEnumerable<st

private IEnumerable<MarketPlaceTransactionsConfig> GetAvailableMarketplaceConfigs()
{
// TODO load only once
var mapperConfiguration = new MapperConfiguration(cfg => {
cfg.CreateMap<MarketPlaceTransactionsConfigData, MarketPlaceTransactionsConfig>();
});
Expand Down Expand Up @@ -110,7 +109,7 @@ private IEnumerable<Transaction> ReadTransactions(string fileName)
}
var validLines = lines.Skip(linesToSkip).ToList();

var transactionsDict = new Dictionary<string, string[]>();
var transactionsDict = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
for (int columnIndex = 0; columnIndex < validLines[0].Length; ++columnIndex)
{
string columnNameKey = validLines[0][columnIndex].Trim(); //tolower?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011300424FIO
0750000002001353908000000000000000000000000000000000000026992951669712700000000000000000000000000408-0091951-6697127000124050224
07500000020013539080000000000000000000000000000000000001062710000000000000000000000000000000000000000000000000000000000124170224
0750000002001353908000000000000000000000000000000000000026992290539393600000000000000000000000000408-2472290-5393936000124230224
0750000002001353908000000000000000000000000000000000000062002070906676300000000000000000000000000405-7042070-9066763000124260224
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011300424FIO
07500000020013539020000000000000000000000000000000000007206310000000000000000000000000000000000000000000000000000000000124061120
0750000002001353902000000000000000000000000000000000001577872514164104100000000000000000000000000702-5224514-1641041000124151120
0750000002001353902000000000000000000000000000000000002077052965988102600000000000000000000000000702-3444965-9881026000124151120
07500000020013539020000000000000000000000000000000000000352510000000000000000000000000000000000000000000000000000000000124201120
0750000002001353902000000000000000000000000000000000002077052704294262500000000000000000000000000702-1622704-2942625000124241120
0750000002001353902000000000000000000000000000000000002077052827234343700000000000000000000000000701-7796827-2343437000124241120
0750000002001353902000000000000000000000000000000000001178982984649067200000000000000000000000000701-0090984-6490672000124261120
0750000002001353902000000000000000000000000000000000001195005698303945400000000000000000000000000702-1407698-3039454000124010224
0750000002001353902000000000000000000000000000000000002195002542046746800000000000000000000000000702-6059542-0467468000124010224
0750000002001353902000000000000000000000000000000000001195002372825940600000000000000000000000000702-7039372-8259406000124060224
0750000002001353902000000000000000000000000000000000001595002681949946300000000000000000000000000701-6390681-9499463000124060224
0750000002001353902000000000000000000000000000000000001195002238817546900000000000000000000000000702-1008238-8175469000124080224
0750000002001353902000000000000000000000000000000000000950002051013140100000000000000000000000000701-0997051-0131401000124080224
0750000002001353902000000000000000000000000000000000000950002051013140100000000000000000000000000701-0997051-0131401000124080224
0750000002001353902000000000000000000000000000000000001195002897697466900000000000000000000000000702-3416897-6974669000124110224
07500000020013539020000000000000000000000000000000000057319010000000000000000000000000000000000000000000000000000000000124120224
0750000002001353902000000000000000000000000000000000001425002173601460200000000000000000000000000702-5970173-6014602000124130224
0750000002001353902000000000000000000000000000000000001400002497863463800000000000000000000000000701-7451497-8634638000124190224
0750000002001353902000000000000000000000000000000000000975002395548026400000000000000000000000000701-5926395-5480264000124220224
0750000002001353902000000000000000000000000000000000000995002579507706300000000000000000000000000702-3541579-5077063000124250224
0750000002001353902000000000000000000000000000000000002845002605247383000000000000000000000000000701-2609605-2473830000124250224
07500000020013539020000000000000000000000000000000000091086110000000000000000000000000000000000000000000000000000000000124260224
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011300424FIO
07500000020013539130000000000000000000000000000000000005200021514960562000000000000000000000000002151496056200000000000124090224
07500000020013539130000000000000000000000000000000000002790021514960562000000000000000000000000002151496056200000000000124230224
07500000020013539130000000000000000000000000000000000004420011607040132000000000000000000000000002160704013200000000000124270224
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0740000002001353907Czech Goods s.r.o. 01111900000013280900+00000016514842+000000461730770000000494070190011300424FIO
07500000020013539140000000000000000000000000000000000000640910000000000000000000000000000000000000000000000000000000000124060224
0750000002001353914000000000000000000000000000000000000064222095799586500000000000000000000000000249-5935095-7995865000124110224
0750000002001353914000000000000000000000000000000000000073382804361340400000000000000000000000000249-3345804-3613404000124140224
0750000002001353914000000000000000000000000000000000000022932565422781400000000000000000000000000249-5071565-4227814000124150224
07500000020013539140000000000000000000000000000000000001414510000000000000000000000000000000000000000000000000000000000124200224
Loading
Loading