Ejemplo n.º 1
0
        /// <summary>
        /// Hash code for the transaction for equality checks
        /// </summary>
        public override int GetHashCode()
        {
            // Get the hash code for the Date field if it is not null.
            int hashDate = Date == null ? 0 : Date.GetHashCode();

            // Get the hash code for the Description field.
            int hashDescription = Description.GetHashCode();

            // Get the hash code for the UserComments field.
            int hashInvoiceReference = InvoiceReference.GetHashCode();

            // Get the hash code for the Amount field.
            int hashTotal = Total.GetHashCode();

            // Calculate the hash code for the transaction.
            return(hashDate ^ hashDescription ^ hashInvoiceReference ^ hashTotal);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int     id;
            int     customerId;
            decimal amount;

            using (var context = new ApplicationContext())
            {
                Invoice invoice = context.Invoices.First();
                id         = invoice.Id;
                customerId = invoice.CustomerId;
                amount     = invoice.Amount;
            }

            using (var context = new SalesContext())
            {
                Order   order   = context.Orders.First();
                Invoice invoice = order.Invoice;
                Console.WriteLine(invoice);
            }

            using (var context = new BillingContext())
            {
                InvoiceReference invoiceReference = context.Invoices.First();
                Console.WriteLine(invoiceReference);
                context.Invoices.Remove(invoiceReference);
                context.SaveChanges();
                var newInvoiceReference = new InvoiceReference
                {
                    Id         = id,
                    CustomerId = customerId,
                    Amount     = amount
                };
                context.Invoices.Add(newInvoiceReference);
                context.SaveChanges();
            }

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates InvoiceModel from Xml
        /// </summary>
        /// <param name="element"></param>
        /// <param name="count"></param>
        /// <returns>The InvoiceModel</returns>
        private Invoice CreateInvoiceModelFromXml(XElement element, int count)
        {
            if (element == null)
            {
                throw new ArgumentNullException("Element parameter should not be null");
            }

            if (count < 1)
            {
                throw new ArgumentOutOfRangeException("Count parameter is out of range");
            }

            var invoiceData    = element.Element(_nameSpace + _fejlecNode);
            var supplier       = element.Element(_nameSpace + _szamlakibocsatoNode);
            var customer       = element.Element(_nameSpace + _vevoNode);
            var lines          = element.Elements(_nameSpace + _termek_szolgaltatas_tetelekNode);
            var invoiceSummary = element.Element(_nameSpace + _osszesitesNode)?.Element(_nameSpace + _vegosszegNode);

            if (invoiceData == null ||
                supplier == null ||
                customer == null ||
                lines.Any() == false ||
                invoiceSummary == null)
            {
                throw new NullReferenceException("Unable to get node");
            }

            string supplierTaxNumber = supplier.Element(_nameSpace + _adoszamNode)?.Value;
            string supplierAddress   = supplier.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _telepulesNode)?.Value;
            string customerTaxNumber = customer.Element(_nameSpace + _adoszamNode)?.Value;
            string customerAddress   = customer.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _telepulesNode)?.Value;


            var modifiedInvoice = element.Element(_nameSpace + _modosito_szlaNode);

            InvoiceReferenceBase invoiceReference;

            if (modifiedInvoice == null)
            {
                invoiceReference = new InvoiceReference()
                {
                    ModifyWithoutMaster = false
                };
            }
            else
            {
                invoiceReference = new InvoiceReferenceMod
                {
                    OriginalInvoiceNumber = modifiedInvoice.Element(_nameSpace + _eredeti_sorszamNode)?.Value,
                    ModificationIssueDate = invoiceData.Element(_nameSpace + _szladatumNode)?.Value,
                    ModificationTimeStamp = GetModificationTimeStamp(invoiceData.Element(_nameSpace + _szladatumNode)?.Value),
                    ModifyWithoutMaster   = false
                };
            }

            var invoice = new Invoice
            {
                InvoiceExchange = new InvoiceExchange
                {
                    InvoiceReference = invoiceReference,
                    InvoiceHead      = new InvoiceHead
                    {
                        SupplierInfo = new SupplierInfo
                        {
                            SupplierTaxNumber = new SupplierTaxNumber
                            {
                                TaxpayerId = supplierTaxNumber.Split('-')[0],
                                VatCode    = supplierTaxNumber.Split('-')[1],
                                CountyCode = supplierTaxNumber.Split('-')[2]
                            },
                            SupplierName    = supplier.Element(_nameSpace + _nevNode)?.Value,
                            SupplierAddress = new SupplierAddress
                            {
                                SimpleAddress = new SimpleAddress
                                {
                                    CountryCode             = supplierAddress.Split('|')[1],
                                    PostalCode              = supplier.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _iranyitoszamNode)?.Value,
                                    City                    = supplierAddress.Split('|')[0],
                                    AdditionalAddressDetail = supplier.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _kozterulet_neveNode)?.Value
                                }
                            }
                        },
                        CustomerInfo = new CustomerInfo
                        {
                            CustomerTaxNumber = new CustomerTaxNumber
                            {
                                TaxpayerId = customerTaxNumber.Split('-')[0],
                                VatCode    = customerTaxNumber.Split('-')[1],
                                CountyCode = customerTaxNumber.Split('-')[2]
                            },
                            CustomerName    = customer.Element(_nameSpace + _nevNode)?.Value,
                            CustomerAddress = new CustomerAddress
                            {
                                SimpleAddress = new SimpleAddress
                                {
                                    CountryCode             = customerAddress.Split('|')[1],
                                    PostalCode              = customer.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _iranyitoszamNode)?.Value,
                                    City                    = customerAddress.Split('|')[0],
                                    AdditionalAddressDetail = customer.Element(_nameSpace + _cimNode)?.Element(_nameSpace + _kozterulet_neveNode)?.Value
                                }
                            }
                        },
                        InvoiceData = new InvoiceData
                        {
                            InvoiceNumber       = invoiceData.Element(_nameSpace + _szlasorszamNode)?.Value,
                            InvoiceCategory     = "NORMAL",
                            InvoiceIssueDate    = invoiceData.Element(_nameSpace + _szladatumNode)?.Value,
                            InvoiceDeliveryDate = invoiceData.Element(_nameSpace + _teljdatumNode)?.Value,
                            CurrencyCode        = element.Element(_nameSpace + _nem_kotelezoNode)?.Element(_nameSpace + _penznemNode)?.Value,
                            InvoiceAppearance   = _appearance[_random.Next(0, 3)]
                        }
                    },
                    InvoiceLines   = new List <LineBase>(),
                    InvoiceSummary = new InvoiceSummary
                    {
                        SummaryNormal = new SummaryNormal
                        {
                            InvoiceNetAmount = invoiceSummary.Element(_nameSpace + _nettoarosszNode)?.Value,
                            InvoiceVatAmount = invoiceSummary.Element(_nameSpace + _afaertekosszNode)?.Value
                        }
                    }
                }
            };

            foreach (var xElement in lines)
            {
                if (modifiedInvoice == null)
                {
                    invoice.InvoiceExchange.InvoiceLines.Add(new Line
                    {
                        LineNumber        = count.ToString(),
                        LineDescription   = xElement.Element(_nameSpace + _termeknevNode).Value,
                        Quantity          = xElement.Element(_nameSpace + _mennyNode).Value,
                        UnitOfMeasure     = xElement.Element(_nameSpace + _mertekegysNode).Value,
                        UnitPrice         = xElement.Element(_nameSpace + _nettoegysarNode).Value,
                        LineAmountsNormal = new LineAmountsNormal
                        {
                            LineNetAmount = xElement.Element(_nameSpace + _nettoarNode).Value,
                            LineVatRate   = new LineVatRate
                            {
                                VatPercentage = xElement.Element(_nameSpace + _adokulcsNode).Value
                            }
                        }
                    });
                }
                else
                {
                    invoice.InvoiceExchange.InvoiceLines.Add(new LineMod()
                    {
                        LineNumber = count.ToString(),
                        LineModificationReference = new LineModificationReference()
                        {
                            LineOperation = "CREATE"
                        },
                        LineDescription   = xElement.Element(_nameSpace + _termeknevNode).Value,
                        Quantity          = xElement.Element(_nameSpace + _mennyNode).Value,
                        UnitOfMeasure     = xElement.Element(_nameSpace + _mertekegysNode).Value,
                        UnitPrice         = xElement.Element(_nameSpace + _nettoegysarNode).Value,
                        LineAmountsNormal = new LineAmountsNormal
                        {
                            LineNetAmount = xElement.Element(_nameSpace + _nettoarNode).Value,
                            LineVatRate   = new LineVatRate
                            {
                                VatPercentage = xElement.Element(_nameSpace + _adokulcsNode).Value
                            }
                        }
                    });
                }
            }

            return(invoice);
        }