コード例 #1
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);
        }
コード例 #2
0
        public async void GetVatOSS(DateTime fromDate, DateTime toDate)
        {
            SetDateTime(txtDateFrm, txtDateTo);

            busyIndicator.IsBusy = true;
            List <PropValuePair> propValPair = new List <PropValuePair>();

            if (fromDate != DateTime.MinValue || toDate != DateTime.MinValue)
            {
                string filter;
                if (fromDate != DateTime.MinValue)
                {
                    filter = String.Format("{0:d}..", fromDate);
                }
                else
                {
                    filter = "..";
                }
                if (toDate != DateTime.MinValue)
                {
                    filter += String.Format("{0:d}", toDate);
                }
                var prop = PropValuePair.GenereteWhereElements("Date", typeof(DateTime), filter);
                propValPair.Add(prop);
            }

            if (glVatCache == null)
            {
                glVatCache = await api.LoadCache <Uniconta.DataModel.GLVat>();
            }

            var vatEUList = glVatCache.Where(s => s._TypeSales == CreateVatOSSFile.VATTYPE_MOSS).Select(x => x._Vat).Distinct();

            if (vatEUList != null && vatEUList.Count() > 0)
            {
                var strLst = string.Join(";", vatEUList);
                propValPair.Add(PropValuePair.GenereteWhereElements(nameof(DebtorInvoiceLines.Vat), typeof(string), strLst));
            }
            var listOfDebInvLines = await api.Query <DebtorInvoiceLines>(propValPair);

            List <VatOSSTable> vatOSSlst = new List <VatOSSTable>();

            if (listOfDebInvLines != null && listOfDebInvLines.Length != 0)
            {
                vatOSSlst            = UpdateValues(listOfDebInvLines);
                busyIndicator.IsBusy = false;
            }
            else
            {
                var vatOSS = new VatOSSTable();
                vatOSS._CompanyId    = api.CompanyId;
                vatOSS._Date         = DefaultFromDate;
                vatOSS.MOSSType      = vatOSSReportType == 0 ? CreateVatOSSFile.MOSSTYPE_008 : vatOSSReportType == 1 ? CreateVatOSSFile.MOSSTYPE_021 : CreateVatOSSFile.MOSSTYPE_031;
                vatOSS._MOSSTypeName = GetMOSSTypeName(vatOSS.MOSSType);
                vatOSS.Compressed    = true;
                vatOSSlst.Add(vatOSS);

                busyIndicator.IsBusy = false;
                compressed           = true;
            }

            var sort = new VatOSSTableTypeSort();

            vatOSSlst.Sort(sort);
            dgVatOSSGrid.ItemsSource = vatOSSlst;
            dgVatOSSGrid.Visibility  = Visibility.Visible;
        }