Exemplo n.º 1
0
        /// <summary>
        /// Uloží nezbytné informace o nákupu do databáze, ze kterých je možné
        /// rekonstruovat původní XML. Neukládají se všechny atributy XML, ty, které
        /// je možné vypočítat, se neukládají.
        /// </summary>
        public void SaveXmlBillToDatabase(DateTime time)
        {
            LinqToSqlDataContext db = PASS.GeneralClasses.DatabaseSetup.Database;

            // Vytvořit nový nákup
            Order order = new Order();

            order.paid              = (int)Paid;
            order.staff             = PASS.GeneralClasses.Authentification.AuthUser.Username;
            order.timeOfTransaction = time;
            order.change            = Change;
            // Na účtence je název firmy. Ten se může změnit a proto archivujeme i starší jména.
            Company company = CompanyInfo.GetCompanyInfo();

            order.companyName            = company.name;
            order.companyPhone           = company.phone;
            order.companyPostalCode      = company.postalCode.ToString();
            order.companyWeb             = company.web;
            order.companyCity            = company.city;
            order.companyAdress          = company.adress;
            order.totalShoppingCartPrice = Sum;
            Bill billInfo = BillInfo.GetBillInfo();

            order.billText = billInfo.billText.Trim();

            db.Orders.InsertOnSubmit(order);
            db.SubmitChanges();
            // VAT
            List <VAT> listOfVat    = GetVat();
            decimal?   vatSum       = GetVatSum(listOfVat);
            decimal?   vatSumSingle = GetVatSumSingle(listOfVat);

            order.vatSum       = vatSum;
            order.vatSumSingle = vatSumSingle;
            foreach (VAT singleVat in listOfVat)
            {
                OrderItemsVat vatForDb = new OrderItemsVat();
                vatForDb.vatId            = singleVat.id;
                vatForDb.orderId          = order.id;
                vatForDb.percentageLabel  = singleVat.percentage;
                vatForDb.vatValue         = singleVat.vatValue;
                vatForDb.vatValueProducts = singleVat.vatValueProducts;
                db.OrderItemsVats.InsertOnSubmit(vatForDb);
            }


            db.SubmitChanges();

            // Pro každou položku nákupu vytvořit záznam v DB a přiřadit jí k Orderu
            foreach (ShoppingCartItem item in ShoppingCart)
            {
                OrderItem orderItem = new OrderItem();
                orderItem.name           = item.AddedProduct.name.Trim();
                orderItem.quantity       = (int)item.Quantity;
                orderItem.unit           = item.UnitName.Trim();
                orderItem.unitQuantity   = item.AddedProduct.unitQuantity;
                orderItem.expirationDate = item.AddedProduct.expirationDate;
                orderItem.code           = item.AddedProduct.code;
                orderItem.priceForUnit   = item.AddedProduct.priceForUnit;
                orderItem.totalPrice     = item.TotalPrice;
                orderItem.price          = item.AddedProduct.price;
                orderItem.vatId          = item.AddedProduct.vatId;

                // Přiřadit k orderu
                orderItem.orderId = order.id;
                db.OrderItems.InsertOnSubmit(orderItem);
            }
            db.SubmitChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Vygeneruje z nákupního košíku XML účtenku
        /// </summary>
        public void GenerateXmlFile(string filename, List <ShoppingCartItem> ShoppingCart, DateTime time)
        {
            if (!Directory.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill")))
            {
                Directory.CreateDirectory(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill"));
            }
            using (XmlWriter xmlWriter = XmlWriter.Create(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill", filename)))
            {
                xmlWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"../CashRegister/Bill.xslt\"?>");
                xmlWriter.WriteStartElement("bill");


                foreach (ShoppingCartItem item in ShoppingCart)
                {
                    xmlWriter.WriteStartElement("product");
                    xmlWriter.WriteElementString("name", item.AddedProduct.name.Trim());
                    xmlWriter.WriteElementString("quantity", item.Quantity.ToString());
                    xmlWriter.WriteElementString("unit", item.UnitName.Trim());

                    if (!item.AddedProduct.priceForUnit)
                    {
                        xmlWriter.WriteElementString("unitQuantity", item.AddedProduct.unitQuantity.ToString());
                    }

                    xmlWriter.WriteElementString("expirationDate", ((DateTime)item.AddedProduct.expirationDate).ToString("dd.MM.yyyy"));
                    xmlWriter.WriteElementString("code", item.AddedProduct.code.ToString());
                    xmlWriter.WriteElementString("totalPrice", item.TotalPrice.ToString());
                    xmlWriter.WriteElementString("priceForUnit", item.AddedProduct.priceForUnit.ToString());
                    xmlWriter.WriteElementString("priceForSingleUnit", item.AddedProduct.price.ToString());
                    xmlWriter.WriteElementString("vatType", item.AddedProduct.vatId.ToString());
                    xmlWriter.WriteEndElement();
                }

                xmlWriter.WriteElementString("totalShoppingCartPrice", Sum.ToString());
                xmlWriter.WriteElementString("paid", Paid.ToString());
                xmlWriter.WriteElementString("change", Change.ToString());
                xmlWriter.WriteElementString("staff", PASS.GeneralClasses.Authentification.AuthUser.Username);
                xmlWriter.WriteElementString("time", time.ToShortDateString() + " " + time.ToShortTimeString());


                //DPH se počítá dohromady pro všechny výrobky dané kategorie (A,B,C,D)
                List <VAT> listOfVat    = GetVat();
                decimal?   vatSum       = GetVatSum(listOfVat);
                decimal?   vatSumSingle = GetVatSumSingle(listOfVat);
                xmlWriter.WriteElementString("vatSum", string.Format("{0:0.00}", vatSum));
                xmlWriter.WriteElementString("vatSumSingle", string.Format("{0:0.00}", vatSumSingle));
                foreach (VAT singleVat in listOfVat)
                {
                    xmlWriter.WriteStartElement(singleVat.id.ToString());
                    xmlWriter.WriteAttributeString("percentage", singleVat.percentage);
                    xmlWriter.WriteAttributeString("totalPrice", string.Format("{0:0.00}", singleVat.vatValueProducts));
                    xmlWriter.WriteString(string.Format("{0:0.00}", singleVat.vatValue));
                    xmlWriter.WriteEndElement();
                }

                //Informace do hlavičky
                Company company = CompanyInfo.GetCompanyInfo();
                xmlWriter.WriteElementString("companyName", company.name.Trim()); // Name je vždy vyplněné

                //Další nepovinné údaje, pokud chybí, tak se to do XML nebude přidávat
                if (!string.IsNullOrEmpty(company.adress))
                {
                    xmlWriter.WriteElementString("companyAdress", company.adress.Trim());
                }

                if (!string.IsNullOrEmpty(company.city))
                {
                    xmlWriter.WriteElementString("companyCity", company.city.Trim());
                }

                if (company.postalCode != null)
                {
                    xmlWriter.WriteElementString("companyPostalCode", company.postalCode.ToString());
                }

                if (!string.IsNullOrEmpty(company.phone))
                {
                    xmlWriter.WriteElementString("companyPhone", company.phone.Trim());
                }

                if (!string.IsNullOrEmpty(company.web))
                {
                    xmlWriter.WriteElementString("companyWeb", company.web.Trim());
                }

                Bill billInfo = BillInfo.GetBillInfo();
                if (!string.IsNullOrEmpty(billInfo.billText))
                {
                    xmlWriter.WriteElementString("billText", billInfo.billText.Trim());
                }

                xmlWriter.WriteEndElement();
            }
        }