private static GenericAddress GetEmailAddress(InvoiceAddressModel address)
        {
            var genericAddress = address != null
                ? new GenericAddress
            {
                City           = address.City ?? string.Empty,
                Country        = address.Country ?? string.Empty,
                CountyDistrict = address.County ?? string.Empty,
                Line1          = address.Address1 ?? string.Empty,
                Line2          = address.Address2 ?? string.Empty,
                Line3          = string.Empty,
                Line4          = string.Empty,
                State          = address.State ?? string.Empty,
                Zip            = address.PostalCode ?? string.Empty
            }
                : new GenericAddress
            {
                City           = string.Empty,
                Country        = string.Empty,
                CountyDistrict = string.Empty,
                Line1          = string.Empty,
                Line2          = string.Empty,
                Line3          = string.Empty,
                Line4          = string.Empty,
                State          = string.Empty,
                Zip            = string.Empty
            };

            return(genericAddress);
        }
 private static bool IsAddressValid(InvoiceAddressModel address)
 {
     if (!HLConfigManager.Configurations.DOConfiguration.AddrerssVelidationInvoice)
     {
         return(true);
     }
     else
     {
         return(!(address == null || string.IsNullOrEmpty(address.Address1) || string.IsNullOrEmpty(address.City) || string.IsNullOrEmpty(address.PostalCode)));
     }
 }
 public MemberInvoiceAddress ConvertToMemberInvoiceAddress(InvoiceAddressModel address)
 {
     return(new MemberInvoiceAddress
     {
         Address01 = address.Address1,
         Address02 = address.Address2,
         City = address.City,
         County = address.County,
         CountryCode = address.Country,
         PostalCode = address.PostalCode,
         State = address.State
     });
 }
 public Address_V01 ConvertToAddress(InvoiceAddressModel invoiceAddress, string countryCode)
 {
     return(new Address_V01
     {
         City = invoiceAddress.City,
         Country = countryCode,
         CountyDistrict = invoiceAddress.County,
         Line1 = invoiceAddress.Address1,
         Line2 = invoiceAddress.Address2,
         PostalCode = invoiceAddress.PostalCode,
         StateProvinceTerritory = invoiceAddress.State
     });
 }
Esempio n. 5
0
 public virtual ServiceProvider.OrderSvc.Address GetAddressFromInvoice(InvoiceAddressModel address)
 {
     return(new ServiceProvider.OrderSvc.Address_V01
     {
         City = address.City,
         CountyDistrict = address.County,
         PostalCode = address.PostalCode,
         Line1 = address.Address1,
         Line2 = address.Address2,
         Country = address.Country,
         StateProvinceTerritory = address.State
     });
 }
        private static InvoiceAddressModel ConvertToAddressViewModel(Address_V03 addressList)
        {
            var Address = addressList as ContactAddress;

            if (Address == null)
            {
                return(null);
            }
            var address = new InvoiceAddressModel()
            {
                Id = Address.AddressId != null?int.Parse(Address.AddressId) : 0,
                         Address1   = (!string.IsNullOrEmpty(Address.Line2)) ? string.Concat((Address.Line1 ?? string.Empty).Trim(), " ", (Address.Line2 ?? string.Empty).Trim()) : Address.Line1,
                         Address2   = Address.Line2,
                         City       = Address.City,
                         State      = Address.StateProvinceTerritory,
                         Country    = Address.Country,
                         PostalCode = Address.PostalCode
            };

            return(address);
        }
Esempio n. 7
0
 public bool ValidateAddress(InvoiceAddressModel address, string countryCode, out Address_V01 avsOutAddress)
 {
     throw new System.NotImplementedException();
 }
        private InvoiceModel getFromForm()
        {
            string       errorsproduct = string.Empty;
            InvoiceModel invoice       = new InvoiceModel();

            invoice.Number = Convert.ToString(tbNumerFaktury.Text);

            if (cbTypFaktury.SelectedItem == "Oryginal")
            {
                invoice.Type = 9;
            }
            if (cbTypFaktury.SelectedItem == "Kopia")
            {
                invoice.Type = 31;
            }
            if (cbTypFaktury.SelectedItem == "Duplikat")
            {
                invoice.Type = 7;
            }

            invoice.SaleDate     = dtpDataSprzedazy.Value;
            invoice.PaymentDate  = dtpTerminPlatnosci.Value;
            invoice.ProviderName = labelNazwaFirmy.Text;
            invoice.ProviderNip  = labelNipFirmy.Text;
            invoice.BuyerName    = tbNabywcaNazwaFirmy.Text;
            invoice.BuyerNip     = tbNabywcaNip.Text;
            invoice.DeliveryName = tbMDostawyNazwaFirmy.Text;

            InvoiceAddressModel ProvAdr = new InvoiceAddressModel();

            ProvAdr.City        = labelMiasto.Text;
            ProvAdr.Street      = labelUlica.Text;
            ProvAdr.Number      = labelNumer.Text;
            ProvAdr.PostCode    = labelKodPocztowy.Text;
            ProvAdr.CountryCode = labelKraj.Text;


            InvoiceAddressModel BuyerAdr = new InvoiceAddressModel();

            BuyerAdr.City        = tbNabywcaMiasto.Text;
            BuyerAdr.Street      = tbNabywcaUlica.Text;
            BuyerAdr.Number      = tbNabywcaNumer.Text;
            BuyerAdr.PostCode    = tbNabywcaKodPocztowy.Text;
            BuyerAdr.CountryCode = tbNabywcaKraj.Text;

            List <ValidationResult> results3 = new List <ValidationResult>();

            if (Validator.TryValidateObject(BuyerAdr, new ValidationContext(BuyerAdr, null, null), results3))
            {
            }
            else
            {
                errorsproduct += String.Join("\n", results3) + "\n";
            }


            InvoiceAddressModel DelivAdr = new InvoiceAddressModel();

            DelivAdr.City        = tbMDostawyMiasto.Text;
            DelivAdr.Street      = tbMDostawyUlica.Text;
            DelivAdr.Number      = tbMDostawyNumer.Text;
            DelivAdr.PostCode    = tbMDostawyKodPocztowy.Text;
            DelivAdr.CountryCode = tbMDostawyKraj.Text;

            invoice.ProviderAddress = ProvAdr;
            invoice.BuyerAddress    = BuyerAdr;
            invoice.DeliveryAddress = DelivAdr;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                InvoiceProductModel prod = new InvoiceProductModel();
                prod.ItemNumber    = 11111;
                prod.Number        = Convert.ToString(Convert.ToInt16(i + 1));
                prod.Name          = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
                prod.Type          = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);
                prod.QuantityType  = 47;
                prod.Quantity      = Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
                prod.SumAmountType = "66";                                                                      ////o co chodzi?
                prod.SumAmountNet  = Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value);
                prod.UnitPriceNet  = Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);
                prod.Tax           = Convert.ToInt16(Tax);
                List <ValidationResult> results2 = new List <ValidationResult>();
                if (Validator.TryValidateObject(prod, new ValidationContext(prod, null, null), results2))
                {
                    invoice.Products.Add(prod);
                }
                else
                {
                    errorsproduct += String.Join("\n", results2) + "\n";
                }
            }

            invoice.ProductQuntity = dataGridView1.Rows.Count;


            float suma = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                suma += Convert.ToSingle(dataGridView1.Rows[i].Cells[5].Value);
            }
            invoice.AmountGross = suma;

            suma = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                suma += Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value);
            }
            invoice.AmountNet = suma;

            float sumaNetto  = 0;
            float sumaBrutto = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                sumaNetto  += Convert.ToSingle(dataGridView1.Rows[i].Cells[4].Value);
                sumaBrutto += Convert.ToSingle(dataGridView1.Rows[i].Cells[5].Value);
            }
            invoice.AmountTax = sumaBrutto - sumaNetto;

            invoice.Tax = Convert.ToInt16(Tax);

            List <ValidationResult> results = new List <ValidationResult>();

            if (Validator.TryValidateObject(invoice, new ValidationContext(invoice, null, null), results))
            {
            }
            else
            {
                errorsproduct += String.Join("\n", results);
            }
            if (!string.IsNullOrEmpty(errorsproduct))
            {
                MessageBox.Show(errorsproduct);
                return(null);
            }
            else
            {
                return(invoice);
            }
        }
        public InvoiceModel XmlDecode(string str)
        {
            InvoiceModel        invoice = new InvoiceModel();
            InvoiceAddressModel address;
            InvoiceProductModel product;

            XDocument xml = XDocument.Parse(str);

            foreach (XAttribute attr in xml.Root.Attributes())
            {
                switch (attr.Name.LocalName.ToString())
                {
                case "nr":
                    invoice.Number = attr.Value.ToString();
                    break;

                case "type":
                    switch (attr.Value.ToString())
                    {
                    case "orginal":
                        invoice.Type = (Int16)InvoiceModel.Types.Orginal;
                        break;

                    case "kopia":
                        invoice.Type = (Int16)InvoiceModel.Types.Copy;
                        break;

                    case "duplikat":
                        invoice.Type = (Int16)InvoiceModel.Types.Duplicate;
                        break;
                    }
                    break;
                }
            }

            address = new InvoiceAddressModel();
            foreach (XElement el in xml.Descendants("sprzedawca").Elements())
            {
                switch (el.Name.LocalName.ToString())
                {
                case "nip":
                    invoice.ProviderNip = el.Value.ToString();
                    break;

                case "nazwa":
                    invoice.ProviderName = el.Value.ToString();
                    break;

                case "ulica":
                    address.Street = el.Value.ToString();
                    break;

                case "nrlokalu":
                    address.Number = el.Value.ToString();
                    break;

                case "kodpocztowy":
                    address.PostCode = el.Value.ToString();
                    break;

                case "miasto":
                    address.City = el.Value.ToString();
                    break;

                case "kraj":
                    address.CountryCode = el.Value.ToString();
                    break;
                }
            }
            invoice.ProviderAddress = address;

            address = new InvoiceAddressModel();
            foreach (XElement el in xml.Descendants("klient").Elements())
            {
                switch (el.Name.LocalName.ToString())
                {
                case "nip":
                    invoice.BuyerNip = el.Value.ToString();
                    break;

                case "nazwa":
                    invoice.BuyerName = el.Value.ToString();
                    break;

                case "ulica":
                    address.Street = el.Value.ToString();
                    break;

                case "nrlokalu":
                    address.Number = el.Value.ToString();
                    break;

                case "kodpocztowy":
                    address.PostCode = el.Value.ToString();
                    break;

                case "miasto":
                    address.City = el.Value.ToString();
                    break;

                case "kraj":
                    address.CountryCode = el.Value.ToString();
                    break;
                }
            }
            invoice.BuyerAddress = address;


            address = new InvoiceAddressModel();
            foreach (XElement el in xml.Descendants("dostawca").Elements())
            {
                switch (el.Name.LocalName.ToString())
                {
                case "nazwa":
                    invoice.DeliveryName = el.Value.ToString();
                    break;

                case "ulica":
                    address.Street = el.Value.ToString();
                    break;

                case "nrlokalu":
                    address.Number = el.Value.ToString();
                    break;

                case "kodpocztowy":
                    address.PostCode = el.Value.ToString();
                    break;

                case "miasto":
                    address.City = el.Value.ToString();
                    break;

                case "kraj":
                    address.CountryCode = el.Value.ToString();
                    break;
                }
            }
            invoice.DeliveryAddress = address;
            XElement items = xml.Descendants("pozycje").First();

            invoice.ProductQuntity = int.Parse(items.Attribute("liczbapozycji").Value.ToString());

            foreach (XElement item in items.Elements())
            {
                product = new InvoiceProductModel();
                foreach (XElement el in item.Elements())
                {
                    string value = el.Value.ToString();
                    switch (el.Name.LocalName.ToString())
                    {
                    case "nazwa":
                        product.Name = value;
                        break;

                    case "ilosc":
                        product.Quantity     = int.Parse(value);
                        product.QuantityType = Int16.Parse(el.Attribute("jednostka").Value.ToString());
                        break;

                    case "podatekvat":
                        product.Tax = Int16.Parse(value);
                        break;

                    case "cenanetto":
                        product.SumAmountNet = float.Parse(value);
                        break;
                    }
                }
                invoice.Products.Add(product);
            }

            return(invoice);
        }
        public InvoiceModel EdiDecode(string strEdi)
        {
            InvoiceModel invoice = new InvoiceModel();

            string[] segments = Edi.ParseToSegmets(strEdi);

            int nSegments = segments.Length;

            // ustawiam czy odczytywane dane należą do dostwcy czy nabywcy, lub czy są to dane dostwy
            // 0 - dostawca, 1 - nabywca, 2 - dane do dostwy
            int who = 0;

            string[]            arguments;
            string[]            parameters;
            InvoiceAddressModel address;
            int productIndex = -1;
            InvoiceProductModel        product;
            List <InvoiceProductModel> products = new List <InvoiceProductModel>();
            bool details = false;

            for (int i = 0; i < nSegments; i++)
            {
                if (i == 23)
                {
                }
                segments[i] = segments[i].Trim();
                if (String.IsNullOrEmpty(segments[i]))
                {
                    continue;
                }
                arguments = Edi.ParseToArguments(segments[i]);

                switch (arguments[0])
                {
                case "UNH":
                    parameters = Edi.ParseToParameters(arguments[2]);
                    if (parameters[0] != "INVOIC")
                    {
                        return(null);
                    }
                    break;

                case "BGM":
                    if (arguments[1] == "380")
                    {
                        invoice.Number = arguments[2];
                        invoice.Type   = Int16.Parse(arguments[3]);
                    }
                    break;

                case "DTM":
                    DateTime date;
                    parameters = Edi.ParseToParameters(arguments[1]);
                    if (parameters[2] == "102")
                    {
                        date = DateTime.ParseExact(parameters[1], "yyyyMMdd", null);
                    }
                    else
                    {
                        date = DateTime.Parse(parameters[1]);
                    }
                    switch (parameters[0])
                    {
                    case "137":
                        invoice.SaleDate = date;
                        break;

                    case "13":
                        invoice.PaymentDate = date;
                        break;
                    }
                    break;

                case "NAD":
                    address             = new InvoiceAddressModel();
                    parameters          = Edi.ParseToParameters(arguments[5]);
                    address.Street      = parameters[0];
                    address.City        = arguments[6];
                    address.PostCode    = arguments[8];
                    address.CountryCode = arguments[9];

                    switch (arguments[1])
                    {
                    case "SU":
                        //dane dostawcy
                        who                     = 0;
                        parameters              = Edi.ParseToParameters(arguments[4]);
                        invoice.ProviderName    = parameters[0];
                        invoice.ProviderAddress = address;
                        break;

                    case "BY":
                        //dane nabywcy
                        who                  = 1;
                        parameters           = Edi.ParseToParameters(arguments[4]);
                        invoice.BuyerName    = parameters[0];
                        invoice.BuyerAddress = address;
                        break;

                    case "DP":
                        //dane do dostawy
                        who                     = 2;
                        parameters              = Edi.ParseToParameters(arguments[4]);
                        invoice.DeliveryName    = parameters[0];
                        invoice.DeliveryAddress = address;
                        break;
                    }
                    break;

                case "RFF":
                    parameters = Edi.ParseToParameters(arguments[1]);
                    if (parameters[0] == "VA")
                    {
                        switch (who)
                        {
                        case 0:
                            //nip dostawcy
                            invoice.ProviderNip = parameters[1];
                            break;

                        case 1:
                            //nip nabywcy
                            invoice.BuyerNip = parameters[1];
                            break;
                        }
                    }
                    break;

                case "PAT":
                    details = true;
                    break;

                case "LIN":
                    productIndex++;
                    product            = new InvoiceProductModel();
                    product.ItemNumber = Int16.Parse(arguments[1]);
                    parameters         = Edi.ParseToParameters(arguments[3]);
                    product.Number     = parameters[0];
                    products.Insert(productIndex, product);
                    break;

                case "IMD":
                    product      = products[productIndex];
                    product.Name = arguments[2];
                    parameters   = Edi.ParseToParameters(arguments[3]);
                    product.Type = parameters[0];
                    break;

                case "QTY":
                    product              = products[productIndex];
                    parameters           = Edi.ParseToParameters(arguments[1]);
                    product.QuantityType = Int16.Parse(parameters[0]);
                    product.Quantity     = int.Parse(parameters[1]);
                    break;

                case "MOA":
                    parameters = Edi.ParseToParameters(arguments[1]);
                    if (details)
                    {
                        switch (parameters[0])
                        {
                        case "66":
                        case "35E":
                            product = products[productIndex];
                            product.SumAmountType = parameters[0];
                            product.SumAmountNet  = float.Parse(parameters[1]);
                            break;
                        }
                    }
                    else
                    {
                        float amount = float.Parse(parameters[1]);
                        switch (parameters[0])
                        {
                        case "77":
                            invoice.AmountGross = amount;
                            break;

                        case "79":
                            invoice.AmountNet = amount;
                            break;

                        case "124":
                            invoice.AmountTax = amount;
                            break;
                        }
                    }
                    break;

                case "PRI":
                    parameters = Edi.ParseToParameters(arguments[1]);
                    if (parameters[0] == "AAA")
                    {
                        product = products[productIndex];
                        product.UnitPriceNet = float.Parse(parameters[1]);
                    }
                    break;

                case "TAX":
                    if (arguments[1] == "7" && arguments[2] == "VAT")
                    {
                        parameters = Edi.ParseToParameters(arguments[5]);
                        if (details)
                        {
                            product     = products[productIndex];
                            product.Tax = Int16.Parse(parameters[3]);
                        }
                        else
                        {
                            invoice.Tax = Int16.Parse(parameters[3]);
                        }
                    }
                    break;

                case "UNS":
                    if (arguments[1] == "S")
                    {
                        invoice.Products = products;
                        details          = false;
                    }
                    break;

                case "CNT":
                    parameters             = Edi.ParseToParameters(arguments[1]);
                    invoice.ProductQuntity = int.Parse(parameters[0]);
                    break;
                }
            }

            return(invoice);
        }