public async Task PullInvoiceHandler(string?query, EFormatType format, DirectoryInfo output) { var fInvoiceActions = await _service.GetNewPostInvoiceAction(); if (!Directory.Exists(output.FullName)) { Directory.CreateDirectory(output.FullName); } foreach (var fInvoiceAction in fInvoiceActions) { var(fPurchaseInvoice, fOriginalFileData) = await _service.PullInvoice(fInvoiceAction); var fFilePath = Path.Combine(output.FullName, fPurchaseInvoice.Id.ToString()); var fExtension = _utilities.GetExtension(format); var fHasResult = await _utilities.HandleOutput(format, fPurchaseInvoice, new FileInfo(fFilePath + fExtension), query); if (fHasResult) { File.WriteAllBytes(fFilePath + ".pdf", fOriginalFileData); } } }
private async Task CheckConnection(string query, EFormatType format, FileInfo?output) { var apiKey = _credentialService.GetApiKey(); try { //Check ApiKey if (string.IsNullOrWhiteSpace(apiKey)) { _logger.LogError( "Please contact Blue10 to receive an API key for your account and use the 'credentials set' command to update your credentials"); return; } //Get Me test var me = await _blue10.GetMeAsync();//.GetAwaiter().GetResult(); await _utilities.HandleOutput(format, me, output, query); } catch (Blue10ApiException apie) when(apie.Message.Contains("authentication required")) { _logger.LogError($"Your API : \"{apiKey}\" key is invalid, please contact Blue10 to receive a valid API Key and use the 'credentials set' command to update your credentials"); } catch (Blue10ApiException apie) { _logger.LogError(apie.Message); } catch (Exception e) { _logger.LogError(e.Message); } }
private async Task CreateVendorHandler( CreateVendorInput pComplexType) { var fCreateVendor = new Vendor { Name = pComplexType.Name ?? pComplexType.AdministrationCode, VatNumber = string.Empty, CountryCode = pComplexType.Country, Iban = pComplexType.Iban.ToList(), CurrencyCode = pComplexType.Currency, VendorCustomerCode = string.Empty, DefaultLedgerCode = pComplexType.Ledger, DefaultVatCode = pComplexType.Vat, DefaultVatScenarioCode = string.Empty, DefaultPaymentTermCode = pComplexType.Payment, Blocked = false, Id = Guid.Empty, AdministrationCode = pComplexType.AdministrationCode, IdCompany = pComplexType.CompanyId }; var fResult = await _vendorService.CreateOrUpdate(fCreateVendor); //var fResult = await _vendorService.CreateOrUpdate(fCreateVendor); if (fResult.Object is null) { _logger.LogWarning($"Creating vendor failed with following error(s): {fResult.ErrorMessage}"); return; } await _utilities.HandleOutput(pComplexType.Format, fResult.Object, pComplexType.Output); }
private async Task ImportVatCodesHandler( FileInfo input, EFormatType inputformat, FileInfo?output, EFormatType outputformat) { var fSyncFilePath = input.FullName; var fVatCodeList = File.ReadAllText(fSyncFilePath); var fVatCodes = _utilities.ReadAs <VatCode>(inputformat, fVatCodeList); if (fVatCodes is null) { return; } var fSuccessList = new List <VatCode>(); var fFailedList = new List <VatCode>(); var fCount = 1; var fTotalVATCodes = fVatCodes.Count; foreach (var fVatCode in fVatCodes) { var fResult = await _vatCodeService.CreateOrUpdate(fVatCode); if (fResult.Object == null) { fFailedList.Add(fVatCode); _logger.LogWarning($"{fCount}/{fTotalVATCodes}: Failed syncing VATCode '{fVatCode.Name}' - {fResult.ErrorMessage}"); } else { fSuccessList.Add(fResult.Object); Console.WriteLine($"{fCount}/{fTotalVATCodes} Successfully synced VATCode '{fVatCode.Name}'"); } fCount++; } Console.WriteLine($"{fSuccessList.Count}/{fTotalVATCodes} VATCodes have been successfully imported"); await _utilities.HandleOutput(outputformat, fSuccessList, output); if (output != null) { await _utilities.HandleOutputToFilePath(outputformat, fFailedList, $"{output?.Directory?.FullName}/failed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); await _utilities.HandleOutputToFilePath(outputformat, fSuccessList, $"{output?.Directory?.FullName}/succeed_{output?.Name ?? "NO_FILE_PATH_PROVIDED"}"); } }
public async Task SignInvoiceHandler(Guid invoiceId, string ledgerEntryCode, EFormatType format, FileInfo?output) { var fInvoiceActions = await _service.GetNewPostInvoiceAction(); var fTargetInvoiceAction = fInvoiceActions.FirstOrDefault(x => x.PurchaseInvoice.Id == invoiceId); if (fTargetInvoiceAction == null) { _logger.LogError($"Invoice with id {invoiceId} does not exist, is not ready to be posted or has already been signed off"); return; } var fResult = await _service.SignInvoice(fTargetInvoiceAction, ledgerEntryCode); if (fResult != null) { await _utilities.HandleOutput(format, fResult, output); } else { _logger.LogError($"Failed to sign-off invoice with id {invoiceId}"); } }
public async Task PeekInvoiceHandler(string?query, EFormatType format, FileInfo?output) { var resultObject = await _service.PeekInvoices(); await _utilities.HandleOutput(format, resultObject, output, query); }
private async Task ListCompaniesHandler(string query, EFormatType format, FileInfo?output) { var resultObject = await _service.ListCompanies(); await _utilities.HandleOutput(format, resultObject, output, query); }
private async Task ListVendorsHandler(string companyid, string?query, EFormatType format, FileInfo?output) { var resultObject = await _vendorService.List(companyid); await _utilities.HandleOutput(format, resultObject, output, query); }