public async void C21GetVatRegisterDefsTest() { DbConnectionSettings dbConnectionSettings = new DbConnectionSettings("192.168.21.20", "sa", "#sa2015!", "fkf_test_db"); C21DocumentService documentService = new C21DocumentService(dbConnectionSettings, null); var output = await documentService.GetVatRegistersDefs(1); Console.WriteLine($"C21GetVatRegisterDefsTest - Vat register name: {output.rNazwa}"); Assert.True(output != null); var outputNull = await documentService.GetVatRegistersDefs(9999); Assert.True(outputNull == null); }
public async Task <C21DocumentAggregate> PrepareDocumentAggregate( List <AccountingRecord> accountingRecords, TargetDocumentSettings targetDocumentSettings, List <Contractor> contractors, List <DocumentVat> allDocumentVats, List <VatRegister> vatRegisters, C21DocumentService c21DocumentService, Document document, Source source) { C21DocumentAggregate c21DocumentAggregate = new C21DocumentAggregate(); var documentVats = allDocumentVats.Where(v => v.DocumentId == document.DocumentId).ToList(); if (accountingRecords == null) { c21DocumentAggregate.IsPrepared = false; c21DocumentAggregate.Messages.Add(new KeyValuePair <string, string>("Zapisy księgowe", "Brak konfiguracji zapisów księgowych")); return(c21DocumentAggregate); } if (targetDocumentSettings == null) { c21DocumentAggregate.IsPrepared = false; c21DocumentAggregate.Messages.Add(new KeyValuePair <string, string>("Konfiguracja dokumentu", $"Nie skonfigurowano typu dokumentu dla tego źródła danych: {source.Description}")); return(c21DocumentAggregate); } var c21documentId = 1000;//await c21DocumentService.GetNextDocumentId(1000); var year = await c21DocumentService.GetYearId(document.SaleDate); if (year == null) { Console.WriteLine($"Brak roku w FK dla dokumentu z tego okresu."); } var docTypDef = await c21DocumentService.GetDocumentDefinition(targetDocumentSettings.DocumentShortcut, year.rokId); if (docTypDef == null) { Console.WriteLine($"Brak definicji dokumentu w FK dla dokumentu z tego okresu. ({document.DocumentNumber})"); } var vatRegisterDef = await c21DocumentService.GetVatRegistersDefs(docTypDef.rejestr); var contractor = contractors.FirstOrDefault(c => c.ContractorId == document.ContractorId); if (year != null && contractor != null && vatRegisterDef != null) { var street = !string.IsNullOrEmpty(contractor.Street) ? contractor.Street.Replace("UL. ", "").Replace("ul. ", "") : ""; c21DocumentAggregate.Document = new C21Document { id = c21documentId, rokId = year.rokId, skrot = targetDocumentSettings.DocumentShortcut, kontrahent = contractor.ContractorErpPosition, nazwa = document.DocumentNumber, tresc = document.DocumentNumber, datawpr = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day), datadok = document.DocumentDate, dataOper = document.SaleDate, kwota = Convert.ToDouble(document.Gross), sygnatura = string.Empty, kontoplatnosci = string.Empty, atrJpkV7 = document.JpkV7, DaneKh = 0, //contractor.ContractorErpPosition == null ? 1 : 0, kh_nazwa = string.IsNullOrEmpty(contractor.Name) ? "" : contractor.Name.Length <= 150 ? contractor.Name : contractor.Name.Substring(0, 150), kh_ulica = string.IsNullOrEmpty(street) ? "" : street.Length <= 50 ? street : street.Substring(0, 50), kh_dom = contractor.EstateNumber, kh_lokal = contractor.QuartersNumber, kh_nip = contractor.VatId, kh_kodPocztowy = FvpWebAppUtils.TruncateToLength(contractor.PostalCode, 10), kh_miejscowosc = string.IsNullOrEmpty(contractor.City) ? "" : contractor.City.Length <= 50 ? contractor.City : contractor.City.Substring(0, 50), kh_kraj = contractor.CountryCode }; var nextAccountingRecordId = 1000; foreach (var accountingRecord in accountingRecords) { if (GetRecordAmmount(document, accountingRecord) != 0) { c21DocumentAggregate.AccountingRecords.Add(new C21AccountingRecord { id = nextAccountingRecordId, dokId = c21documentId, pozycja = 0, rozbicie = (short)(accountingRecord.RecordOrder - 1), strona = !string.IsNullOrEmpty(accountingRecord.Debit) ? (short)0 : (short)1, kwota = GetRecordAmmount(document, accountingRecord), opis = document.DocumentNumber, synt = GetAccountPart(accountingRecord.Account, 0), poz1 = GetAccountPart(accountingRecord.Account, 1), poz2 = GetAccountPart(accountingRecord.Account, 2), poz3 = GetAccountPart(accountingRecord.Account, 3), poz4 = GetAccountPart(accountingRecord.Account, 4), poz5 = GetAccountPart(accountingRecord.Account, 5), }); } nextAccountingRecordId++; } var nextVatRegisterId = 1000; foreach (var documentVat in documentVats) { var vatRegister = GetVatRegisterIdForVat(GetVatValue(documentVat), vatRegisters); c21DocumentAggregate.VatRegisters.Add(new C21VatRegister { id = nextVatRegisterId, dokId = c21documentId, rejId = vatRegister > 0 ? vatRegister : vatRegisterDef.id, okres = document.SaleDate, Oczek = 0, abc = vatRegisterDef.defAbc, nienaliczany = 0, stawka = GetVatValue(documentVat), netto = Convert.ToDouble(documentVat.NetAmount), brutto = Convert.ToDouble(documentVat.GrossAmount), vat = Convert.ToDouble(documentVat.VatAmount), atrJpkV7 = documentVat.VatTags }); nextVatRegisterId++; } } c21DocumentAggregate.IsPrepared = true; return(c21DocumentAggregate); }