예제 #1
0
        public static CountryCode?CheckEuropeanVatInformation(string cvr, CountryCode country, bool cvrFound)
        {
            if (string.IsNullOrEmpty(cvr))
            {
                return(null);
            }
            int    countryCode   = (int)country;
            string twolettercode = null;

            if (Char.IsLetter(cvr.FirstOrDefault()) && cvr.Length > 3)
            {
                var cCode = cvr.Substring(0, 2);
                cvr = cvr.Substring(2, cvr.Length - 2);
                CountryISOCode isoCode;
                if (Enum.TryParse(cCode, out isoCode))
                {
                    twolettercode = cCode;
                    countryCode   = (int)isoCode;
                }
            }
            else
            {
                twolettercode = Enum.GetName(typeof(CountryISOCode), countryCode);
            }
            if (twolettercode != null && !cvrFound && Country2Language.IsEU(country))
            {
                var vatInfo = EuropeanVatInformation.Get(twolettercode, cvr);
                if (vatInfo == null)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NotValidVatNo"), Uniconta.ClientTools.Localization.lookup("Warning"));
                    return(null);
                }
            }
            return((CountryCode)countryCode);
        }
예제 #2
0
 public bool PreValidate()
 {
     if (!Country2Language.IsEU(api.CompanyEntity._CountryId))
     {
         UnicontaMessageBox.Show(Localization.lookup("AccountCountryNotEu"), Localization.lookup("Warning"));
         return(false);
     }
     return(true);
 }
        public bool PreValidate()
        {
            if (!Country2Language.IsEU(companyCountryId))
            {
                UnicontaMessageBox.Show(Localization.lookup("AccountCountryNotEu"), Localization.lookup("Warning"));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(companyRegNo))
            {
                UnicontaMessageBox.Show(string.Format(Localization.lookup("MissingOBJ"), Localization.lookup("CompanyRegNo")), Localization.lookup("Warning"));
                return(false);
            }

            return(true);
        }
        public void Validate(IEnumerable <IntrastatClient> intralst, bool compressed, bool onlyValidate)
        {
            var countErr = 0;

            foreach (var intra in intralst)
            {
                var hasErrors = false;
                intra.SystemInfo = null;

                if (compressed && intra.Compressed == false)
                {
                    hasErrors = true;
                    if (intra.SystemInfo == VALIDATE_OK)
                    {
                        intra.SystemInfo = Localization.lookup("CompressPosting");
                    }
                    else
                    {
                        intra.SystemInfo += Environment.NewLine + Localization.lookup("CompressPosting");
                    }
                }

                if (intra.IsTriangularTrade)
                {
                    intra.SystemInfo = Localization.lookup("TriangleTrade");
                    continue;
                }

                if (intra.ItemCode == null)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += string.Format(Localization.lookup("OBJisEmpty"), Localization.lookup("TariffNumber"));
                }
                else
                {
                    intra.ItemCode = Regex.Replace(intra.ItemCode, "[^0-9]", "");
                }

                if (intra.ItemCode != null && intra.ItemCode.Length != 8)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += string.Format(Localization.lookup("InvalidValue"), Localization.lookup("TariffNumber"), intra.ItemCode);
                }

                if (intra.Country == CountryCode.Unknown)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += intra.SystemInfo + Localization.lookup("CountryNotSet");
                }
                if (intra.Country == companyCountryId)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += intra.SystemInfo + Localization.lookup("OwnCountryProblem");
                }
                if (!Country2Language.IsEU(intra.Country))
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += Localization.lookup("NonEUCountry");
                }

                if (intra.CountryOfOrigin == CountryCode.Unknown && intra._CountryOfOriginUNK == IntraUnknownCountry.None)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += string.Format(Localization.lookup("MissingOBJ"), Localization.lookup("CountryOfOrigin"));
                }

                if (intra.InvAmount == 0)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += Localization.lookup("NoValues");
                }

                if (intra.NetWeight == 0 && intra.IntraUnit == 0 && (string.IsNullOrWhiteSpace(intra.ItemCode) || !intra.ItemCode.Contains("99500000")))
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += string.Format(Localization.lookup("MissingOBJ"), Localization.lookup("Weight"));
                }

                if (intra.TransType == null)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += Localization.lookup("EmptyTransferType");
                }

                if (!string.IsNullOrWhiteSpace(intra.TransType) && intra.TransType.Length != 2)
                {
                    hasErrors         = true;
                    intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                    intra.SystemInfo += string.Format(Localization.lookup("InvalidValue"), Localization.lookup("TransferType"), intra.TransType);
                }

                if (intra.ImportOrExport == ImportOrExportIntrastat.Export)
                {
                    if (string.IsNullOrWhiteSpace(intra.fDebtorRegNo))
                    {
                        hasErrors         = true;
                        intra.SystemInfo += intra.SystemInfo != null ? Environment.NewLine : null;
                        intra.SystemInfo += string.Format(Localization.lookup("MissingOBJ"), Localization.lookup("DebtorRegNo"));
                    }
                }

                if (hasErrors)
                {
                    countErr++;
                }
                else
                {
                    intra.SystemInfo = VALIDATE_OK;
                }
            }
        }
예제 #5
0
        List <IntrastatClient> UpdateValues(IntrastatClient[] listIntraStat, ImportOrExportIntrastat importOrExport, double factor)
        {
            if (listIntraStat == null || listIntraStat.Length == 0)
            {
                return(null);
            }

            var intraList      = new List <IntrastatClient>(listIntraStat.Length >> 4); // div 8
            var companyCountry = api.CompanyEntity._CountryId;
            var companyRegNo   = Regex.Replace(api.CompanyEntity._Id ?? string.Empty, "[^0-9]", "");

            foreach (var intraStat in listIntraStat)
            {
                intraStat.ImportOrExport = importOrExport;

                if (intraStat._NetAmount() == 0 || intraStat._Subtotal || intraStat._PartOfBOM || intraStat._DCAccount == null || intraStat._Item == null)
                {
                    continue;
                }

                var item = intraStat.InvItem;
                if (item == null)
                {
                    continue;
                }

                if (item?._ItemType == (byte)ItemType.Service)
                {
                    continue;
                }

                if (importOrExport == ImportOrExportIntrastat.Import)
                {
                    intraStat.Country = intraStat.Creditor.Country;
                }
                else // export
                {
                    var deb = intraStat.Debtor;
                    intraStat.Country = deb._DeliveryCountry == 0 ? deb._Country : deb._DeliveryCountry;
                }

                if (intraStat.Country == companyCountry)
                {
                    continue;
                }

                if (!Country2Language.IsEU(intraStat.Country) && intraStat.Country != CountryCode.Unknown)
                {
                    continue;
                }

                intraStat.DebtorRegNo = intraStat?.Debtor?._LegalIdent;

                var fdebtorCVR = intraStat.DebtorRegNo;
                if (fdebtorCVR != null)
                {
                    long value;
                    if (!long.TryParse(fdebtorCVR, out value))
                    {
                        fdebtorCVR = Regex.Replace(fdebtorCVR, @"[-/ ]", "");
                    }

                    var preCtry  = StringBuilderReuse.Create().Append(fdebtorCVR).Truncate(2).ToStringAndRelease();
                    var pCountry = intraStat.PartnerCountry;
                    if (preCtry != pCountry)
                    {
                        fdebtorCVR = StringBuilderReuse.Create().Append(pCountry).Append(fdebtorCVR).ToStringAndRelease();
                    }

                    intraStat.fDebtorRegNo = fdebtorCVR;
                }
                else
                {
                    intraStat.DebtorRegNo  = IntraHelper.UNKNOWN_CVRNO;
                    intraStat.fDebtorRegNo = IntraHelper.UNKNOWN_CVRNO;
                }


                intraStat.CompanyRegNo = companyRegNo;
                var salesAmount = intraStat._NetAmount() * factor;
                intraStat.TransType = salesAmount < 0 ? "21" : "11";
                intraStat.InvAmount = Math.Abs(salesAmount);

                intraStat.InvoiceQuantity = Math.Abs(intraStat._Qty);
                intraStat.CountryOfOrigin = item._CountryOfOrigin == CountryCode.Unknown ? item.InventoryGroup._CountryOfOrigin : item._CountryOfOrigin;

                intraStat.IntraUnitPerPCS = Math.Abs(item._IntraUnit);
                intraStat.WeightPerPCS    = Math.Abs(item.Weight);
                intraStat.NetWeight       = intraStat.WeightPerPCS * intraStat.InvoiceQuantity;
                intraStat.IntraUnit       = item._IntraUnit * (int)Math.Round(intraStat.InvoiceQuantity, 0);

                switch (item._Unit)
                {
                case ItemUnit.Gram:
                    intraStat.WeightPerPCS /= 1000;
                    intraStat.NetWeight    /= 1000;
                    break;

                case ItemUnit.Milligram:
                    intraStat.WeightPerPCS /= 1000000;
                    intraStat.NetWeight    /= 1000000;
                    break;
                }

                intraStat.Date = intraStat.Date == DateTime.MinValue ? DateTime.Now : intraStat.Date;

                var itmCod = item._TariffNumber ?? item.InventoryGroup?._TariffNumber;
                if (itmCod != null)
                {
                    itmCod             = Regex.Replace(itmCod, "[^0-9]", "");
                    itmCod             = itmCod != null && itmCod.Length > 8 ? itmCod.Substring(0, 8) : itmCod;
                    intraStat.ItemCode = itmCod;
                }

                intraList.Add(intraStat);
            }
            return(intraList);
        }
예제 #6
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);
        }
예제 #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);
        }