public void refreshSaleInvoices()
        {
            var saleDS         = new DataSet();
            var itemsDataTable = new DataTable("SaleOrders");

            itemsDataTable.Columns.Add("Sale Date");
            itemsDataTable.Columns.Add("Sale Amount");
            itemsDataTable.Columns.Add("Amount Paid");
            itemsDataTable.Columns.Add("Sale Status");
            itemsDataTable.Columns.Add("User Name");

            using (var db = new Model.posdbEntities())
            {
                var query = (from v in db.salesorders
                             orderby v.SaleDate descending
                             select v
                             ).ToList();


                foreach (var item in query)
                {
                    itemsDataTable.Rows.Add(item.SaleDate.Value.ToShortDateString(), item.SaleAmount, item.AmountPaid, item.SaleStatus, item.UserName);
                }

                saleDS.Tables.Add(itemsDataTable);
                SalesInvoices.DataSource = saleDS;
                SalesInvoices.DataMember = "SaleOrders";
                SalesInvoices.Refresh();
            }
        }
示例#2
0
        public bool UpdateSalesInvoice(SalesInvoices Quotation, IList <SalesInvoiceItems> QuotationItemList, ref string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            try
            {
                Salesreturncontext.Entry(Quotation).State = EntityState.Modified;
                Salesreturncontext.SaveChanges();

                foreach (var model in QuotationItemList)
                {
                    if (model.IsDummy == 1)
                    {
                        Salesreturncontext1.Entry(model).State = EntityState.Deleted;
                        Salesreturncontext1.SaveChanges();
                    }
                    else
                    {
                        if (model.Sales_InvoiceItem_Id == 0)
                        {
                            model.Sales_Invoice_Id = Quotation.Sales_Invoice_Id;
                            Salesreturncontext1.SalesInvoiceItems.Add(model);
                            Salesreturncontext1.SaveChanges();
                        }
                        else
                        {
                            Salesreturncontext1.Entry(model).State = EntityState.Modified;
                            Salesreturncontext1.SaveChanges();
                        }
                    }
                }

                return(true);
            }
            //catch (Exception ex)
            //{
            //    ExceptionHandler.LogException(ex);
            //    ErrorMessage = ex.Message;
            //    return false;
            //}
            catch (DbEntityValidationException dbEx)
            {
                var errorList = new List <string>();

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        errorList.Add(String.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                return(false);
            }
        }
示例#3
0
        private decimal GetBalance()
        {
            decimal balance            = 0;
            decimal totalInvoiceAmount = 0;
            decimal totalReceiptAmount = 0;

            totalInvoiceAmount = SalesInvoices.Sum(i => i.SalesInvoiceLines.Sum(l => l.Amount * l.Quantity));
            totalReceiptAmount = SalesReceipts.Sum(r => r.SalesReceiptLines.Sum(l => l.Amount.GetValueOrDefault() * l.Quantity.GetValueOrDefault()));

            balance = totalInvoiceAmount - totalReceiptAmount;

            return(balance);
        }
示例#4
0
        public SalesInvoices GetBillingDocuments(SaftDTO pFilter)
        {
            SalesInvoices salesInvoicesResume = new SalesInvoices();

            try
            {
                bdContext.ComandText = "stp_SAFT_SALES_INVOICES_TOTAL_ENTRIES_DEBITS_CREDITS";
                bdContext.AddParameter("@COMPANY_ID", pFilter.Filial);
                bdContext.AddParameter("@FILE_TYPE", pFilter.FileType);
                bdContext.AddParameter("@DATE_INI", pFilter.DateFrom);
                bdContext.AddParameter("@DATE_TERM", pFilter.DateUntil);
                bdContext.AddParameter("@TRANSACTION_ID", pFilter.SaftID);
                bdContext.AddParameter("@FISCAL_YEAR", pFilter.FiscalYear);

                MySqlDataReader dr = bdContext.ExecuteReader();
                if (dr.Read())
                {
                    salesInvoicesResume = new SalesInvoices
                    {
                        NumberOfEntries = dr[0].ToString(),
                        TotalDebit      = dr[1].ToString() != "" ? dr[1].ToString().Replace(",", ".").Replace("-", string.Empty) : "0.00",
                        TotalCredit     = dr[2].ToString() != "" ? dr[2].ToString().Replace(",", ".").Replace("-", string.Empty) : "0.00"
                    };
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                bdContext.FecharConexao();
            }

            salesInvoicesResume.Invoice = GetSalesInvoiceList(pFilter);

            if (salesInvoicesResume.Invoice.Count == 0)
            {
                salesInvoicesResume = new SalesInvoices
                {
                    NumberOfEntries = "0",
                    TotalDebit      = "0.00",
                    TotalCredit     = "0.00"
                };
            }



            return(salesInvoicesResume);
        }
        public void EditForSalesInvoice()
        {
            this.salesInvoiceListPage = this.Sidenav.NavigateToSalesInvoices();

            var salesInvoice = new SalesInvoices(this.Session).Extent().First;

            salesInvoice.AddOrderAdjustment(new SurchargeAdjustmentBuilder(this.Session).WithAmountDefaults().Build());

            this.Session.Derive();
            this.Session.Commit();

            var before = new OrderAdjustments(this.Session).Extent().ToArray();

            var expected = new SurchargeAdjustmentBuilder(this.Session).WithAmountDefaults().Build();

            var surchargeAdjustment = salesInvoice.OrderAdjustments.First();
            var id = surchargeAdjustment.Id;

            this.Session.Derive();

            var expectedAmount      = expected.Amount;
            var expectedDescription = expected.Description;

            this.salesInvoiceListPage.Table.DefaultAction(salesInvoice);
            var salesInvoiceOverview    = new SalesInvoiceOverviewComponent(this.salesInvoiceListPage.Driver);
            var adjustmentOverviewPanel = salesInvoiceOverview.OrderadjustmentOverviewPanel.Click();

            adjustmentOverviewPanel.Table.DefaultAction(surchargeAdjustment);

            var adjustmentEdit = new OrderAdjustmentEditComponent(this.Driver);

            adjustmentEdit.Amount.Set(expected.Amount.ToString());
            adjustmentEdit.Description.Set(expected.Description);

            this.Session.Rollback();
            adjustmentEdit.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new OrderAdjustments(this.Session).Extent().ToArray();

            var actual = (SurchargeAdjustment)this.Session.Instantiate(id);

            Assert.Equal(after.Length, before.Length);

            Assert.Equal(expectedAmount, actual.Amount);
            Assert.Equal(expectedDescription, actual.Description);
        }
示例#6
0
        public bool AddNewSalesInvoice(SalesInvoices Invoice, IList <SalesInvoiceItems> InvoiceItemList, ref string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            try
            {
                salesinvoicecontext.SalesInvoices.Add(Invoice);

                salesinvoicecontext.SaveChanges();

                int currentId = Invoice.Sales_Invoice_Id;

                for (int i = 0; i < InvoiceItemList.Count; i++)
                {
                    InvoiceItemList[i].Sales_Invoice_Id = currentId;
                    InvoiceItemList[i].BaseDocLink      = "Y";
                }

                salesinvoicecontext.SalesInvoiceItems.AddRange(InvoiceItemList);

                salesinvoicecontext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(ex);
                ErrorMessage = ex.Message;
                return(false);
            }
            //catch (DbEntityValidationException dbEx)
            //{
            //    var errorList = new List<string>();

            //    foreach (var validationErrors in dbEx.EntityValidationErrors)
            //    {
            //        foreach (var validationError in validationErrors.ValidationErrors)
            //        {
            //            errorList.Add(String.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
            //        }
            //    }
            //    return false;
            //}
        }
示例#7
0
        public void CreatePercentageForSalesInvoice()
        {
            this.salesInvoiceListPage = this.Sidenav.NavigateToSalesInvoices();

            var salesInvoice = new SalesInvoices(this.Session).Extent().First;

            var before = new MiscellaneousCharges(this.Session).Extent().ToArray();

            var expected = new MiscellaneousChargeBuilder(this.Session).WithPercentageDefaults().Build();

            salesInvoice.AddOrderAdjustment(expected);

            this.Session.Derive();

            Assert.True(expected.ExistPercentage);
            Assert.True(expected.ExistDescription);

            var expectedPercentage  = expected.Percentage;
            var expectedDescription = expected.Description;

            this.salesInvoiceListPage.Table.DefaultAction(salesInvoice);
            var miscellaneousChargeCreate = new SalesInvoiceOverviewComponent(this.salesInvoiceListPage.Driver).OrderadjustmentOverviewPanel.Click().CreateMiscellaneousCharge();

            miscellaneousChargeCreate
            .Percentage.Set(expectedPercentage.ToString())
            .Description.Set(expectedDescription);

            this.Session.Rollback();
            miscellaneousChargeCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new MiscellaneousCharges(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedPercentage, actual.Percentage);
            Assert.Equal(expectedDescription, actual.Description);
        }
示例#8
0
        public void CreateAmountForSalesInvoice()
        {
            this.salesInvoiceListPage = this.Sidenav.NavigateToSalesInvoices();

            var salesInvoice = new SalesInvoices(this.Session).Extent().First;

            var before = new SurchargeAdjustments(this.Session).Extent().ToArray();

            var expected = new SurchargeAdjustmentBuilder(this.Session).WithAmountDefaults().Build();

            salesInvoice.AddOrderAdjustment(expected);

            this.Session.Derive();

            Assert.True(expected.ExistAmount);
            Assert.True(expected.ExistDescription);

            var expectedAmount      = expected.Amount;
            var expectedDescription = expected.Description;

            this.salesInvoiceListPage.Table.DefaultAction(salesInvoice);
            var surchargeAdjustmentCreate = new SalesInvoiceOverviewComponent(this.salesInvoiceListPage.Driver).OrderadjustmentOverviewPanel.Click().CreateSurchargeAdjustment();

            surchargeAdjustmentCreate
            .Amount.Set(expectedAmount.ToString())
            .Description.Set(expectedDescription);

            this.Session.Rollback();
            surchargeAdjustmentCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new SurchargeAdjustments(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedAmount, actual.Amount);
            Assert.Equal(expectedDescription, actual.Description);
        }
示例#9
0
        public bool UpdateSalesInvoice(SalesInvoices Quotation, IList <SalesInvoiceItems> QuotationItemList, ref string ErrorMessage)
        {
            ErrorMessage = string.Empty;
            try
            {
                salesinvoicecontext.Entry(Quotation).State = EntityState.Modified;
                salesinvoicecontext.SaveChanges();

                foreach (var model in QuotationItemList)
                {
                    if (model.IsDummy == 1)
                    {
                        salesinvoicecontext.Entry(model).State = EntityState.Deleted;
                        salesinvoicecontext.SaveChanges();
                    }
                    else
                    {
                        if (model.Sales_InvoiceItem_Id == 0)
                        {
                            model.Sales_Invoice_Id = Quotation.Sales_Invoice_Id;
                            model.BaseDocLink      = "N";
                            salesinvoicecontext.SalesInvoiceItems.Add(model);
                            salesinvoicecontext.SaveChanges();
                        }
                        else
                        {
                            salesinvoicecontext.Entry(model).State = EntityState.Modified;
                            salesinvoicecontext.SaveChanges();
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(ex);
                ErrorMessage = ex.Message;
                return(false);
            }
        }
示例#10
0
        private int PrintSalesInvoice()
        {
            using (var session = this.databaseService.Database.CreateSession())
            {
                this.logger.LogInformation("Begin");

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                var templateFilePath = "domain/templates/SalesInvoice.odt";
                var templateFileInfo = new FileInfo(templateFilePath);
                var prefix           = string.Empty;
                while (!templateFileInfo.Exists)
                {
                    prefix          += "../";
                    templateFileInfo = new FileInfo(prefix + templateFilePath);
                }

                var invoice  = new SalesInvoices(session).Extent().Last();
                var template = invoice.BilledFrom.SalesInvoiceTemplate;

                using (var memoryStream = new MemoryStream())
                    using (var fileStream = new FileStream(
                               templateFileInfo.FullName,
                               FileMode.Open,
                               FileAccess.Read,
                               FileShare.ReadWrite))
                    {
                        fileStream.CopyTo(memoryStream);
                        template.Media.InData = memoryStream.ToArray();
                    }

                session.Derive();

                var images = new Dictionary <string, byte[]> {
                    { "Logo", session.GetSingleton().LogoImage.MediaContent.Data },
                };

                if (invoice.ExistInvoiceNumber)
                {
                    var barcodeService = session.ServiceProvider.GetRequiredService <IBarcodeService>();
                    var barcode        = barcodeService.Generate(invoice.InvoiceNumber, BarcodeType.CODE_128, 320, 80);
                    images.Add("Barcode", barcode);
                }

                var printModel = new Allors.Domain.Print.SalesInvoiceModel.Model(invoice);
                invoice.RenderPrintDocument(template, printModel, images);

                session.Derive();

                var result = invoice.PrintDocument;

                var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                var outputFile = File.Create(Path.Combine(desktopDir, "salesInvoice.odt"));
                using (var stream = new MemoryStream(result.Media.MediaContent.Data))
                {
                    stream.CopyTo(outputFile);
                }

                this.logger.LogInformation("End");
            }

            return(ExitCode.Success);
        }
示例#11
0
        // Метод для подтверждения заказа.
        public void СonfirmationOfOrder(Order targetOrder)
        {
            // Cоздаем расходную накладную.
            SalesInvoice temp = new SalesInvoice(targetOrder.Portions, targetOrder.Customer, targetOrder.TotalPrice);

            // Извлекаем продукты.
            List <Product> checkProducts = temp.GetProductFromInvoice();

            // Переменная, которую будет использовать для понимания, можем принять заказ или нет.
            bool key = true;

            foreach (Product targetCheckProduct in checkProducts)
            {
                bool find = false;
                foreach (Product productWarehouse in Products)
                {
                    // Находим продукт в списке.
                    if (targetCheckProduct.Equals(productWarehouse))
                    {
                        find = true;
                        // Не хватает? Заказ принять не можем.
                        if (productWarehouse.Amount < targetCheckProduct.Amount)
                        {
                            key = false;
                        }
                        break;
                    }
                }

                // Не нашли продукт? Не можем заказ принять.
                if (find == false)
                {
                    key = false;
                    break;
                }
            }

            if (key == false)
            {
                throw new OrderException("Order cannot be approved!");
            }

            //для отчетов
            targetOrder.DateTime = DateTime.Now;

            // Eсли можем одобрить заказ, то создаем накладную.
            SalesInvoices.Add(temp);

            // Изменяем количество продуктов.
            foreach (Product targetCheckProduct in checkProducts)
            {
                foreach (Product product_warehouse in Products)
                {
                    // Находим продукт в списке.
                    if (targetCheckProduct.Equals(product_warehouse))
                    {
                        // Если продукт заканчивается, то удаляем его.
                        // Сравнение double небезопасно из-за плавающей запятой и представления в памяти,
                        // поэтому применим данный подход.
                        // Ввод Amount до первого числа после запятой, поэтому сравниваем относительно 0.1
                        if (Math.Abs(product_warehouse.Amount - targetCheckProduct.Amount) < 0.1)
                        {
                            Products.Remove(product_warehouse);
                        }

                        // Изменяем количество.
                        product_warehouse.Amount -= targetCheckProduct.Amount;
                        break;
                    }
                }
            }
            targetOrder.Customer.History.Add(targetOrder);

            // Удаляем заказ, т.к. мы его обслужили.
            DeleteOrder(targetOrder);
        }