Пример #1
0
        private void LocalMenu_OnItemClicked(string ActionType)
        {
            var selectedItem = dgTMPlanningCheckGrid.SelectedItem as TMPlanningCheckLocal;

            switch (ActionType)
            {
            case "Search":
                LoadGrid();
                break;

            case "Create":
                if (selectedItem != null)
                {
                    var debtor = debtors.Get(selectedItem._Debtor);
                    if (debtor != null)
                    {
                        AddDockItem(TabControls.Project, debtor, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Project"), debtor._Name));
                    }
                }
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }
Пример #2
0
        public Tuple <double, double> GetEmplPrice(IList <EmpPayrollCategoryEmployeeClient> empPriceLst,
                                                   SQLTableCache <Uniconta.DataModel.EmpPayrollCategory> empPayrollCatLst,
                                                   SQLTableCache <Uniconta.DataModel.ProjectGroup> projGroupLst,
                                                   Uniconta.DataModel.Employee employee,
                                                   Uniconta.DataModel.Project project,
                                                   DateTime priceDate,
                                                   string payrollCategory = null)
        {
#if !SILVERLIGHT
            if (employee == null)
            {
                return(new Tuple <double, double>(0, 0));
            }

            this.empPriceLst = empPriceLst;
            var projGroup = projGroupLst.Get(project._Group);

            EmpPayrollCategory payrollCat;
            bool isMileagePrice;
            bool invoiceable;
            if (payrollCategory == null)
            {
                payrollCat      = null;
                isMileagePrice  = false;
                invoiceable     = projGroup._Invoiceable;
                payrollCategory = string.Empty;
            }
            else
            {
                payrollCat     = empPayrollCatLst.Get(payrollCategory);
                isMileagePrice = payrollCat._InternalType == InternalType.Mileage;
                invoiceable    = projGroup._Invoiceable && payrollCat._Invoiceable;
            }


            if (empPriceLst != null && empPriceLst.Count > 0 && empPriceLst.Any(s => s._Employee != employee._Number)) // it contains other employees, remove them
            {
                empPriceLst = empPriceLst.Where(s => s._Employee == employee._Number).ToList();
            }

            if (isMileagePrice)
            {
                invoiceable = projGroup._Invoiceable;
            }

            double salesPrice = 0, costPrice = 0;

            if (empPriceLst != null && empPriceLst.Count > 0)
            {
                var defaultPayrollCategory = empPayrollCatLst.Where(s => s._PrCategory == null && s.KeyStr == "Default").FirstOrDefault();

                var prices = PriceMatrix(priceDate, 1, project, payrollCategory);

                if (prices != null && prices._Project == null && prices._DCAccount == null)
                {
                    prices = PriceMatrix(priceDate, 1, project, defaultPayrollCategory?.KeyStr, true) ?? prices;
                }
                else if (prices == null && defaultPayrollCategory != null)
                {
                    prices = PriceMatrix(priceDate, 1, project, defaultPayrollCategory.KeyStr);
                }

                if (prices != null)
                {
                    salesPrice = prices._SalesPrice;
                    costPrice  = prices._CostPrice;
                }
            }

            if (payrollCat != null)
            {
                if (salesPrice == 0)
                {
                    salesPrice = payrollCat._SalesPrice;
                }
                if (costPrice == 0)
                {
                    costPrice = payrollCat._Rate;
                }
            }

            if (!isMileagePrice)  //Always fallback to Employee for cost and sales prices
            {
                if (salesPrice == 0)
                {
                    salesPrice = employee._SalesPrice;
                }
                if (costPrice == 0)
                {
                    costPrice = employee._CostPrice;
                }
            }

            return(new Tuple <double, double>(costPrice, invoiceable ? salesPrice : 0));
#endif
            return(new Tuple <double, double>(0, 0));
        }
Пример #3
0
        public void SetEmplPrice(IEnumerable <TMJournalLineClientLocal> lst,
                                 IList <EmpPayrollCategoryEmployeeClient> empPriceLst,
                                 SQLTableCache <Uniconta.DataModel.EmpPayrollCategory> empPayrollCatLst,
                                 SQLTableCache <Uniconta.ClientTools.DataModel.ProjectClient> projLst,
                                 DateTime startDate,
                                 DateTime endDate,
                                 Uniconta.DataModel.Employee employee,
                                 bool validate = false)
        {
#if !SILVERLIGHT
            bool foundErr;

            this.employee    = employee;
            this.empPriceLst = empPriceLst;
            int dayOfWeekStart = startDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)startDate.DayOfWeek;
            int dayOfWeekEnd   = endDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)endDate.DayOfWeek;

            var defaultPayrollCategory = empPayrollCatLst.Where(s => s._PrCategory == null && s.KeyStr == "Default").FirstOrDefault();

            if (empPriceLst != null && empPriceLst.Any(s => s._Employee != employee._Number)) // it contains other employees, remove them
            {
                empPriceLst = empPriceLst.Where(s => s._Employee == employee._Number).ToList();
            }

            foreach (var trans in lst)
            {
                var isMileageTrans = trans._RegistrationType == RegistrationType.Mileage ? true : false;
                if (isMileageTrans)
                {
                    var projGroup = projGroupList.Get(trans.ProjectRef.Group);
                    if (projGroup != null)
                    {
                        trans._Invoiceable = projGroup._Invoiceable;
                    }
                }

                var payrollCat = empPayrollCatLst.Get(trans._PayrollCategory);
                var Proj       = projLst.Get(trans._Project);

                foundErr = false;
                for (int x = dayOfWeekStart; x <= dayOfWeekEnd; x++)
                {
                    if (trans.GetHoursDayN(x) == 0)
                    {
                        continue;
                    }

                    double salesPrice = 0, costPrice = 0;

                    EmpPayrollCategoryEmployeeClient prices = null;
                    if (empPriceLst != null && empPriceLst.Count > 0)
                    {
                        prices = PriceMatrix(startDate, x, Proj, trans._PayrollCategory);

                        if (prices != null && prices._Project == null && prices._DCAccount == null && !isMileageTrans)
                        {
                            prices = PriceMatrix(startDate, x, Proj, defaultPayrollCategory?.KeyStr, true) ?? prices;
                        }
                        else if (prices == null && defaultPayrollCategory != null && !isMileageTrans)
                        {
                            prices = PriceMatrix(startDate, x, Proj, defaultPayrollCategory.KeyStr);
                        }

                        if (prices != null)
                        {
                            salesPrice = prices._SalesPrice;
                            costPrice  = prices._CostPrice;
                        }
                    }

                    if (payrollCat != null)
                    {
                        if (salesPrice == 0)
                        {
                            salesPrice = payrollCat._SalesPrice;
                        }
                        if (costPrice == 0)
                        {
                            costPrice = payrollCat._Rate;
                        }
                    }

                    if (!isMileageTrans) //Always fallback to Employee for cost and sales prices
                    {
                        if (salesPrice == 0)
                        {
                            salesPrice = employee._SalesPrice;
                        }
                        if (costPrice == 0)
                        {
                            costPrice = employee._CostPrice;
                        }
                    }

                    trans.SetPricesDayN(x, trans._Invoiceable ? salesPrice : 0, costPrice);

                    if (validate && !foundErr)
                    {
                        if (salesPrice == 0 && costPrice == 0)
                        {
                            if (startDate.AddDays(x - 1) >= employee._Hired)
                            {
                                checkErrors.Add(new TMJournalLineError()
                                {
                                    Message = Uniconta.ClientTools.Localization.lookup("NoRatesEmployee"),
                                    RowId   = trans.RowId
                                });

                                trans.ErrorInfo = string.Empty;
                                err             = true;
                                foundErr        = true;
                            }
                        }
                        else
                        {
                            if (!foundErr && salesPrice == 0 && trans._Invoiceable && !isMileageTrans)
                            {
                                checkErrors.Add(new TMJournalLineError()
                                {
                                    Message = string.Format("{0} ({1}: {2})",
                                                            Uniconta.ClientTools.Localization.lookup("NoSalesPrice"),
                                                            Uniconta.ClientTools.Localization.lookup("Date"),
                                                            startDate.AddDays(x - 1).ToString("dd.MM.yyyy")),
                                    RowId = trans.RowId
                                });

                                trans.ErrorInfo = string.Empty;
                                err             = true;
                                foundErr        = true;
                            }
                        }
                    }
                }
            }
#endif
        }
        private async Task IncludeTimeJournals()
        {
            if (!InclTimeJournals || timeTransFound)
            {
                return;
            }

            ProjectClient  proj = null;
            EmployeeClient emp  = null;

            if (master != null)
            {
                emp = master as EmployeeClient;
                if (emp == null)
                {
                    proj = master as ProjectClient;
                }
                if (proj == null)
                {
                    var WIPreport = master as UnicontaClient.Pages.ProjectTransLocalClient;
                    if (WIPreport != null)
                    {
                        proj = WIPreport.ProjectRef;
                    }
                }
            }

            if (timetransLst == null && (master == null || emp != null || proj != null))
            {
                timetransLst         = new List <ProjectTransClient>();
                timeTransFound       = true;
                busyIndicator.IsBusy = true;

                var pairTM = new List <PropValuePair>();

                if (emp != null)
                {
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Employee), typeof(string), emp._Number));
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), emp._TMApproveDate, CompareOperator.GreaterThanOrEqual));
                }
                else if (proj != null)
                {
                    if (projLst == null)
                    {
                        var strb = StringBuilderReuse.Create();
                        strb.Append(proj._Number);
                        foreach (var x in Projects)
                        {
                            if (x._MasterProject == proj._Number)
                            {
                                strb.Append(';').Append(x._Number);
                            }
                        }
                        projLst = strb.ToString();
                        strb.Release();
                    }

                    var projselected = includeSubProject ? projLst : proj._Number;
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Project), typeof(string), projselected));
                    var minApproveDate = Employees.Where(x => x._TMApproveDate != DateTime.MinValue && x._Terminated == DateTime.MinValue).Min(x => x._TMApproveDate as DateTime?) ?? DateTime.MinValue;
                    if (minApproveDate != DateTime.MinValue)
                    {
                        pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), minApproveDate, CompareOperator.GreaterThanOrEqual));
                    }
                }
                else
                {
                    var minApproveDate = Employees.Where(x => x._TMApproveDate != DateTime.MinValue && x._Terminated == DateTime.MinValue).Min(x => x._TMApproveDate as DateTime?) ?? DateTime.MinValue;
                    if (minApproveDate != DateTime.MinValue)
                    {
                        pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), minApproveDate, CompareOperator.GreaterThanOrEqual));
                    }
                }

                var tmJourLines = await api.Query <TMJournalLineClient>(pairTM);

                var tmLines = tmJourLines.Where(s => (s.Project != null &&
                                                      s.PayrollCategory != null &&
                                                      s.Date > Employees.First(z => z._Number == s.Employee)._TMApproveDate)).ToArray();

                var search = new TMJournalLineClient();
                var sort   = new TMJournalEmpDateSort();
                int pos    = 0;
                Array.Sort(tmLines, sort);

                string                     lastEmployee = null;
                string                     lastPayroll  = null;
                string                     lastProject  = null;
                EmpPayrollCategory         payrollCat   = null;
                Uniconta.DataModel.Project project      = null;
                var grpEmpDate = tmLines.GroupBy(x => new { x.Employee, x.Date }).Select(g => new { g.Key.Employee, g.Key.Date, EmployeeTable = Employees.Get(g.Key.Employee) });
                foreach (var rec in grpEmpDate)
                {
                    if (lastEmployee != rec.Employee)
                    {
                        lastEmployee = rec.Employee;
                        await priceLookup.EmployeeChanged(rec.EmployeeTable);
                    }

                    search._Employee = rec.Employee;
                    search._Date     = rec.Date;
                    pos = Array.BinarySearch(tmLines, search, sort);
                    if (pos < 0)
                    {
                        pos = ~pos;
                    }
                    while (pos < tmLines.Length)
                    {
                        var s = tmLines[pos++];
                        if (s._Employee != rec.Employee || s._Date != rec.Date)
                        {
                            break;
                        }

                        if (s.Total != 0)
                        {
                            if (lastPayroll != s._PayrollCategory)
                            {
                                payrollCat  = (Uniconta.DataModel.EmpPayrollCategory)Payrolls?.Get(s._PayrollCategory);
                                lastPayroll = s._PayrollCategory;
                            }

                            var line = new ProjectTransClient();
                            line.IsTimeJournal    = true;
                            line._Project         = s._Project;
                            line._Employee        = s._Employee;
                            line._PayrollCategory = s._PayrollCategory;
                            line._PrCategory      = payrollCat?._PrCategory;
                            line._Task            = s._Task;
                            line._Invoiceable     = s._Invoiceable;
                            line._Date            = s._Date;

                            if (s._RegistrationType == RegistrationType.Hours)
                            {
                                line._Text = s._Text;
                                line._Unit = (byte)ItemUnit.Hours;
                                if (payrollCat != null && (payrollCat._InternalType == Uniconta.DataModel.InternalType.OverTime || payrollCat._InternalType == Uniconta.DataModel.InternalType.FlexTime))
                                {
                                    line._Qty = payrollCat._Factor == 0 ? s.Total : s.Total * payrollCat._Factor;
                                }
                                else
                                {
                                    line._Qty = s.Total;
                                }
                            }
                            else
                            {
                                line._Text = TMJournalLineClient.GetMileageFormattedText(s._Text, s._AddressFrom, s._AddressTo, s._VechicleRegNo);
                                line._Unit = (byte)ItemUnit.km;
                                line._Qty  = s.Total;
                            }

                            s.Day1 = s.Total;
                            s.Day2 = s.Day3 = s.Day4 = s.Day5 = s.Day6 = s.Day7 = 0;
                            await priceLookup.GetEmployeePrice(s);

                            line._CostPrice  = s.GetCostPricesDayN(1);
                            line._SalesPrice = s.GetSalesPricesDayN(1);

                            if (api.CompanyEntity._DimFromProject)
                            {
                                if (lastProject != s._Project)
                                {
                                    project     = (Uniconta.DataModel.Project)Projects.Get(s._Project);
                                    lastProject = s._Project;
                                }

                                line._Dim1 = project._Dim1;
                                line._Dim2 = project._Dim2;
                                line._Dim3 = project._Dim3;
                                line._Dim4 = project._Dim4;
                                line._Dim5 = project._Dim5;
                            }
                            else
                            {
                                line._Dim1 = rec.EmployeeTable._Dim1;
                                line._Dim2 = rec.EmployeeTable._Dim2;
                                line._Dim3 = rec.EmployeeTable._Dim3;
                                line._Dim4 = rec.EmployeeTable._Dim4;
                                line._Dim5 = rec.EmployeeTable._Dim5;
                            }
                            timetransLst.Add(line);
                        }
                    }
                }

                busyIndicator.IsBusy = false;
            }

            if (timetransLst != null)
            {
                var transLst = ((IEnumerable <ProjectTransClient>)dgProjectTransaction.ItemsSource).ToList();
                transLst.AddRange(timetransLst);
                dgProjectTransaction.SetSource(transLst.ToArray());
            }
        }
Пример #5
0
        public List <VatOSSTable> UpdateValues(DebtorInvoiceLines[] listOfDebInvLines)
        {
            var          listOfResults = new List <VatOSSTable>(listOfDebInvLines.Length);
            string       lastVat       = null;
            string       lastVatName   = null;
            GLVat        lastGLVat     = null;
            DebtorClient debtor        = null;

            foreach (var invLine in listOfDebInvLines)
            {
                if (invLine.NetAmount == 0 || invLine._DCAccount == null)
                {
                    continue;
                }

                if (debtor?._Account != invLine._DCAccount)
                {
                    debtor = invLine.Debtor;
                    if (debtor == null || debtor._Country == api.CompanyEntity._CountryId || !Country2Language.IsEU(debtor._Country))
                    {
                        continue;
                    }
                }

                if (invLine._Vat == null)
                {
                    continue;
                }
                if (lastVat != invLine._Vat)
                {
                    lastVat   = invLine._Vat;
                    lastGLVat = glVatCache.Get(lastVat);
                    if (lastGLVat != null)
                    {
                        lastVatName = GetMOSSTypeName(AppEnums.VATMOSSType.ToString((int)lastGLVat._MOSSType));
                    }
                }
                if (lastGLVat == null)
                {
                    continue;
                }

                var vatOSS = new VatOSSTable();
                vatOSS._CompanyId       = api.CompanyId;
                vatOSS._Account         = invLine._DCAccount;
                vatOSS._Date            = invLine._Date;
                vatOSS._InvoiceNumber   = invLine._InvoiceNumber;
                vatOSS._Item            = invLine._Item;
                vatOSS._Vat             = lastVat;
                vatOSS._MOSSType        = lastGLVat._MOSSType;
                vatOSS._MOSSTypeName    = lastVatName;
                vatOSS._VatCountry      = lastGLVat._VatCountry;
                vatOSS._BusinessCountry = lastGLVat._BusinessCountry;
                vatOSS._ShipmentCountry = lastGLVat._ShipmentCountry;
                vatOSS._Id        = lastGLVat._Id;
                vatOSS._Amount    = -invLine.NetAmount;
                vatOSS._VatAmount = lastGLVat.VatAmount(vatOSS._Amount, vatOSS._Date, false, invLine.InvoiceRef._PricesInclVat ? GLVatCalculationMethod.Brutto : GLVatCalculationMethod.Netto);
                listOfResults.Add(vatOSS);
            }

            var search = new VatOSSTable();
            var sort   = new VatOSSTableVatSort();
            int pos    = 0;

            listOfResults.Sort(sort);

            var    glVatLst = glVatCache.OrderBy(s => s._Id);
            string lastId   = null;

            foreach (var glvat in glVatLst)
            {
                if (glvat._TypeSales != CreateVatOSSFile.VATTYPE_MOSS || (glvat._BusinessCountry == CountryCode.Unknown && glvat._ShipmentCountry == CountryCode.Unknown))
                {
                    continue;
                }

                if (lastId == glvat._Id)
                {
                    continue;
                }

                lastId = glvat._Id;

                search._Vat = glvat._Vat;
                pos         = listOfResults.BinarySearch(search, sort);

                if (pos == -1 && vatOSSReportType == 0)
                {
                    var vatOSS = new VatOSSTable();
                    vatOSS._CompanyId      = api.CompanyId;
                    vatOSS._Date           = DefaultFromDate;
                    vatOSS.MOSSType        = CreateVatOSSFile.MOSSTYPE_007;
                    vatOSS._MOSSTypeName   = GetMOSSTypeName(vatOSS.MOSSType);
                    vatOSS.BusinessCountry = glvat._BusinessCountry;
                    vatOSS.ShipmentCountry = glvat._ShipmentCountry;
                    vatOSS.Id = glvat._Id;
                    listOfResults.Add(vatOSS);
                }
            }

            return(listOfResults);
        }
Пример #6
0
        private void UpdatePrices()
        {
            var cwUpdateBjt = new CwCreateUpdateBudget(api, 1);

#if !SILVERLIGHT
            cwUpdateBjt.DialogTableId = 2000000073;
#endif

            cwUpdateBjt.Closed += async delegate
            {
                if (cwUpdateBjt.DialogResult == true)
                {
                    DateTime dFromDateUpd   = CwCreateUpdateBudget.FromDate;
                    DateTime dToDateUpd     = CwCreateUpdateBudget.ToDate;
                    string   dEmplNumber    = CwCreateUpdateBudget.Employee;
                    string   dProject       = CwCreateUpdateBudget.Project;
                    string   dBudgetGroup   = CwCreateUpdateBudget.Group;
                    string   dBudgetComment = CwCreateUpdateBudget.Comment;

                    if (string.IsNullOrEmpty(CwCreateUpdateBudget.Group))
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("BudgetGroup")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    if (dFromDateUpd == DateTime.MinValue)
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("FromDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    if (dToDateUpd == DateTime.MinValue)
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("ToDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    var master = new List <UnicontaBaseEntity>();
                    ProjectBudgetGroup budgetGrp = budgetGroupCache.Get(dBudgetGroup);

                    if (budgetGrp._Blocked)
                    {
                        UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("IsBlockedOBJ"), Uniconta.ClientTools.Localization.lookup("Budget")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    master.Add(budgetGrp);

                    busyIndicator.IsBusy = true;


                    if (!string.IsNullOrEmpty(dEmplNumber))
                    {
                        master.Add(employeeCache.Get(dEmplNumber));
                    }

                    if (!string.IsNullOrEmpty(dProject))
                    {
                        master.Add(projectCache.Get(dProject));
                    }

                    List <PropValuePair> pairTrans = new List <PropValuePair>();
                    pairTrans.Add(PropValuePair.GenereteWhereElements(nameof(ProjectBudgetLineClient._Date), typeof(DateTime), String.Format("{0:d}..{1:d}", dFromDateUpd, dToDateUpd)));

                    var empPriceLst = await api.Query <EmpPayrollCategoryEmployeeClient>(master, pairTrans);

                    var budgetLineLst = await api.Query <ProjectBudgetLineClient>(master, pairTrans);

                    var cntUpdate = 0;
                    var tmHelper  = new TMJournalLineHelper(api);
                    foreach (var rec in budgetLineLst)
                    {
                        cntUpdate++;
                        var prices = tmHelper.GetEmplPrice(empPriceLst, payrollCache, projGroupCache, employeeCache?.Get(rec._Employee), projectCache.Get(rec._Project), rec._Date, rec._PayrollCategory);
                        rec._CostPrice  = prices.Item1;
                        rec._SalesPrice = prices.Item2;
                        rec._Text       = string.Concat("(", TMJournalLineHelper.GetTimeStamp(), ") ", Uniconta.ClientTools.Localization.lookup("PriceUpdate"));
                    }

                    ErrorCodes res;
                    if (cntUpdate > 0)
                    {
                        res = await api.Update(budgetLineLst);
                    }

                    busyIndicator.IsBusy = false;

                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cntUpdate, string.Empty), Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK);
                }
            };
            cwUpdateBjt.Show();
        }
Пример #7
0
        public List <EUSaleWithoutVAT> UpdateValues(DebtorInvoiceLines[] listOfDebInvLines)
        {
            var listOfResults    = new List <EUSaleWithoutVAT>(listOfDebInvLines.Length);
            var companyCountryId = api.CompanyEntity._CountryId;

            bool         triangularTrade = false;
            string       lastVat         = null;
            DebtorClient debtor          = null;
            string       debtorCVR       = null;
            bool         DebtorOk        = false;

            foreach (var invLine in listOfDebInvLines)
            {
                var netAmount = invLine.NetAmount;
                if (netAmount == 0 || invLine._DCAccount == null)
                {
                    continue;
                }

                if (debtor?._Account != invLine._DCAccount)
                {
                    debtor = invLine.Debtor;
                    if (debtor == null || debtor._Country == companyCountryId || !Country2Language.IsEU(debtor._Country))
                    {
                        DebtorOk = false;
                        continue;
                    }

                    DebtorOk  = true;
                    debtorCVR = debtor._LegalIdent;
                    if (debtorCVR != null)
                    {
                        long value;
                        if (!long.TryParse(debtorCVR, out value))
                        {
                            debtorCVR = Regex.Replace(debtorCVR, @"[-/ ]", "");
                        }

                        if (char.IsLetter(debtorCVR[0]) && char.IsLetter(debtorCVR[1]))
                        {
                            debtorCVR = debtorCVR.Substring(2);
                        }
                    }
                }

                if (!DebtorOk)
                {
                    continue;
                }

                if (lastVat != invLine._Vat)
                {
                    lastVat         = invLine._Vat;
                    triangularTrade = glVatCache.Get(lastVat)?._TypeSales == "s7";
                }

                var invoice = new EUSaleWithoutVAT();
                invoice._CompanyId         = api.CompanyId;
                invoice.CompanyRegNo       = companyRegNo;
                invoice.RecordType         = "2";
                invoice.ReferenceNumber    = "X";
                invoice._Account           = invLine._DCAccount;
                invoice._Date              = invLine._Date;
                invoice._InvoiceNumber     = invLine._InvoiceNumber;
                invoice._Item              = invLine._Item;
                invoice._Vat               = lastVat;
                invoice._Amount            = -netAmount;
                invoice._IsTriangularTrade = triangularTrade;
                invoice._DebtorRegNoFile   = debtorCVR;

                if (invLine._Item != null)
                {
                    invoice._ItemOrService = invLine.InvItem._ItemType == 1 ? ItemOrServiceType.Service : ItemOrServiceType.Item;
                }

                sumOfAmount += invoice._Amount;
                listOfResults.Add(invoice);
            }
            ;

            return(listOfResults);
        }