예제 #1
0
        public ActionResult Statistics(SaleFilterModel model)
        {
            if (Session["ItemsPerPage"] != null)
            {
                model.ItemsPerPage = (int)Session["ItemsPerPage"];
            }
            PagerData pager = new PagerData()
            {
                ItemsPerPage = model.ItemsPerPage, CurrentPage = model.page
            };
            var result = _salesManager.GetSales(model, null, pager);

            if (Request.IsAjaxRequest())
            {
                return(Json(new { CurrentPage = pager.CurrentPage, TotalPages = pager.TotalPages, Result = result }, JsonRequestBehavior.AllowGet));
            }
            SalesListModel listModel = new SalesListModel()
            {
                Sales  = result,
                Pager  = pager,
                Filter = model
            };

            return(View("Statistics", listModel));
        }
예제 #2
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            if (!UserInfo.IsAdmin)
            {
                ClientHelper.ShowErrorMessage("You are not authorized to delete this record.");
                return;
            }

            if (dataGridView1.SelectedRows.Count > 0)
            {
                int id = (int)dataGridView1.SelectedRows[0].Cells[SaleIdColumn.Name].Value;
                if (this.saleController.ItemHasPaymentOrReturn(id))
                {
                    ClientHelper.ShowErrorMessage("This sale is already paid or has a return item.");
                    return;
                }

                if (ClientHelper.ShowConfirmMessage("Are you sure you want to delete this sale?") == DialogResult.Yes)
                {
                    this.saleController.DeleteSale(id);

                    SaleFilterModel filter = ComposeSearch();
                    LoadSales(filter);
                }
            }
        }
예제 #3
0
        void form_SalesUpdated(object sender, EventArgs e)
        {
            SaleFilterModel filter = ComposeSearch();

            LoadSales(filter);

            dataGridView1.ClearSelection();

            if (selectedId == 0)
            {
                salesViewBindingSource.Position = salesViewBindingSource.Count - 1;
            }
            else
            {
                SalesView item = ((SortableBindingList <SalesView>)salesViewBindingSource.DataSource)
                                 .FirstOrDefault(a => a.Id == selectedId);
                int index = salesViewBindingSource.IndexOf(item);

                salesViewBindingSource.Position = index;
                if (index != -1)
                {
                    dataGridView1.Rows[index].Selected = true;
                }
            }
        }
예제 #4
0
        public SortableBindingList <SaleDisplayModel> FetchARWithSearch(SaleFilterModel filter)
        {
            try
            {
                var query = CreateQuery(filter);

                query = query.Where(a => a.Type == 1 && a.IsPaid == false);

                var result = from a in query.ToList()
                             select new SaleDisplayModel
                {
                    Id            = a.Id,
                    Customer      = a.CompanyName,
                    InvoiceNumber = a.InvoiceNumber,
                    Date          = a.Date.Value,
                    Type          = a.Type.HasValue ? GetSaleType(a.Type.Value) : "-",
                    TotalAmount   = a.TotalAmount.Value,
                    IsPaid        = a.IsPaid.Value,
                    RecordedBy    = a.RecordedBy,
                    //ApprovedBy = a.ApprovedBy.HasValue ? a.ApprovedByUser.Firstname + " " + a.ApprovedByUser.Lastname : "-",
                    IsDeleted = a.IsDeleted.Value
                };

                SortableBindingList <SaleDisplayModel> b = new SortableBindingList <SaleDisplayModel>(result);

                return(b);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
 public IQueryable <SalesView> FetchSalesWithSearchGeneric(SaleFilterModel filter)
 {
     try
     {
         return(this.CreateQuery(filter));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #6
0
        public IEnumerable <SaleViewModel> GetSales(SaleFilterModel filter, Func <IQueryable <SaleDTO>, IOrderedQueryable <SaleDTO> > orderBy = null, PagerData pager = null)
        {
            var exp = PredicateBuilder.True <SaleDTO>();

            if (!string.IsNullOrEmpty(filter.Customer))
            {
                string customer = filter.Customer.ToLower();
                exp = exp.And(s => s.Customer.CustomerName.ToLower().Contains(customer));
            }
            if (!string.IsNullOrEmpty(filter.Manager))
            {
                string manager = filter.Manager.ToLower();
                exp = exp.And(s => s.Manager.LastName.ToLower().Contains(manager));
            }
            if (!string.IsNullOrEmpty(filter.Product))
            {
                string product = filter.Product.ToLower();
                exp = exp.And(s => s.Product.ProductName.ToLower().Contains(product));
            }
            if (filter.StartDate.HasValue)
            {
                DateTime startDate = filter.StartDate.Value;
                exp = exp.And(s => s.SaleDate >= startDate);
            }
            if (filter.EndDate.HasValue)
            {
                DateTime endDate = filter.EndDate.Value;
                exp = exp.And(s => s.SaleDate <= endDate);
            }

            if (orderBy == null)
            {
                orderBy = s => s.OrderBy(o => o.SaleDate);
            }

            var sales = _unitOfWork.Sales.GetAsQueryable(exp, orderBy);

            if (sales != null)
            {
                if (pager != null)
                {
                    int total = sales.Count();
                    int rest  = total % pager.ItemsPerPage;
                    pager.TotalPages = total / pager.ItemsPerPage + (rest > 0 ? 1 : 0);
                    int skip = pager.ItemsPerPage * (pager.CurrentPage - 1);
                    sales = sales.Skip(skip).Take(pager.ItemsPerPage);
                }

                return(sales.ToArray().Select(s => ViewModelFromDTO(s)));
            }

            return(new SaleViewModel[0]);
        }
예제 #7
0
        public SortableBindingList <SalesView> FetchSaleWithSearch(SaleFilterModel filter)
        {
            try
            {
                var query = CreateQuery(filter);

                SortableBindingList <SalesView> b = new SortableBindingList <SalesView>(query);
                return(b);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #8
0
        private void LoadInvoices()
        {
            var dateFrom = DateFromPicker.Value;
            var dateTo   = DateToPicker.Value;

            SaleFilterModel filter = new SaleFilterModel()
            {
                CustomerId = this.CustomerId,
                Paid       = PaidType.NotPaid,
                DateType   = dateFrom == dateTo ? DateSearchType.All : DateSearchType.DateRange,
                DateFrom   = dateFrom,
                DateTo     = dateTo,
                Type       = -1
            };

            var invoices = this.saleController.FetchSaleWithSearch(filter);

            saleDisplayModelBindingSource.DataSource = invoices;
        }
예제 #9
0
        private void LoadSales(SaleFilterModel filter)
        {
            int count = 0;

            long elapsed = ClientHelper.PerformFetch(() =>
            {
                SortableBindingList <SalesView> sales = this.saleController.FetchSaleWithSearch(filter);
                salesViewBindingSource.DataSource     = sales;

                if (salesViewBindingSource.Count == 0)
                {
                    salesDetailViewModelBindingSource.DataSource = null;
                }

                TotalSalesTextbox.Text = sales.Sum(a => a.TotalAmount).Value.ToString("Php #,##0.00");
                count = sales.Count;
            });

            ((MainForm)this.ParentForm).AttachStatus(count, elapsed);
        }
예제 #10
0
        public ActionResult IndexGet(SaleFilterModel model)
        {
            if (model == null || model.page == 0)
            {
                model = new SaleFilterModel()
                {
                    page = 1
                };
                if (Session["ItemsPerPage"] != null)
                {
                    model.ItemsPerPage = (int)Session["ItemsPerPage"];
                }
                else
                {
                    model.ItemsPerPage = MvcApplication.ItemsPerPage;
                }
                return(View(model));
            }

            return(Statistics(model));
        }
        private void LoadSales(SaleFilterModel filter)
        {
            int count = 0;

            long elapsed = ClientHelper.PerformFetch(() =>
            {
                this.sales = this.saleController.FetchSalesWithSearchGeneric(filter);

                var groupedSales = this.sales
                                   .GroupBy(a => a.CompanyName)
                                   .Select(a => new ConsolidatedSalesModel
                {
                    CustomerName = a.Key,
                    TotalAmount  = a.Sum(x => x.TotalAmount)
                })
                                   .OrderBy(a => a.CustomerName);

                this.consolidatedSalesBindingSource.DataSource = groupedSales;
            });

            ((MainForm)this.ParentForm).AttachStatus(count, elapsed);
        }
예제 #12
0
        private SaleFilterModel ComposeSearch()
        {
            SaleFilterModel model = new SaleFilterModel();

            if (CustomerDropdown.SelectedIndex != -1)
            {
                model.CustomerId = (int)CustomerDropdown.SelectedValue;
            }

            if (!string.IsNullOrWhiteSpace(InvoiceTextbox.Text))
            {
                model.InvoiceNumber = InvoiceTextbox.Text.Trim();
            }

            model.Type = TypeDropdown.SelectedIndex;

            if (AmountTypeDropdown.SelectedIndex != -1)
            {
                var amount = !string.IsNullOrWhiteSpace(AmountTextbox.Text) ?
                             decimal.Parse(AmountTextbox.Text) : 0;

                if (AmountTypeDropdown.SelectedIndex == 1)
                {
                    model.AmountType  = NumericSearchType.Equal;
                    model.AmountValue = amount;
                }
                else if (AmountTypeDropdown.SelectedIndex == 2)
                {
                    model.AmountType  = NumericSearchType.GreaterThan;
                    model.AmountValue = amount;
                }
                else if (AmountTypeDropdown.SelectedIndex == 3)
                {
                    model.AmountType  = NumericSearchType.LessThan;
                    model.AmountValue = amount;
                }
            }
            else
            {
                model.AmountType = NumericSearchType.All;
            }

            if (!AllDateRB.Checked)
            {
                model.DateType = DateSearchType.DateRange;
                model.DateTo   = DateToPicker.Value;
                model.DateFrom = DateFromPicker.Value;
            }
            else
            {
                model.DateType = DateSearchType.All;
            }

            if (AllPaidRB.Checked)
            {
                model.Paid = PaidType.None;
            }
            else if (PaidRB.Checked)
            {
                model.Paid = PaidType.Paid;
            }
            else if (UnpaidRB.Checked)
            {
                model.Paid = PaidType.NotPaid;
            }

            model.PR = PRTextbox.Text;
            model.PO = POTextbox.Text;

            return(model);
        }
예제 #13
0
        public void RefreshView()
        {
            SaleFilterModel filter = ComposeSearch();

            LoadSales(filter);
        }
예제 #14
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            SaleFilterModel filter = ComposeSearch();

            LoadSales(filter);
        }
예제 #15
0
        private IQueryable <SalesView> CreateQuery(SaleFilterModel filter)
        {
            db.SalesView.MergeOption = MergeOption.OverwriteChanges;

            var items = db.SalesView
                        .Where(a => a.IsDeleted == false);

            if (filter != null)
            {
                if (filter.CustomerId != 0)
                {
                    items = items.Where(a => a.CustomerId == filter.CustomerId);
                }

                if (!string.IsNullOrWhiteSpace(filter.InvoiceNumber))
                {
                    items = items.Where(a => a.InvoiceNumber.Contains(filter.InvoiceNumber));
                }

                if (filter.AmountType != NumericSearchType.All)
                {
                    if (filter.AmountType == NumericSearchType.Equal)
                    {
                        items = items.Where(a => a.TotalAmount == filter.AmountValue);
                    }
                    else if (filter.AmountType == NumericSearchType.GreaterThan)
                    {
                        items = items.Where(a => a.TotalAmount > filter.AmountValue);
                    }
                    else if (filter.AmountType == NumericSearchType.LessThan)
                    {
                        items = items.Where(a => a.TotalAmount < filter.AmountValue);
                    }
                }

                if (filter.Type != -1)
                {
                    items = items.Where(a => a.Type == filter.Type);
                }

                if (filter.DateType != DateSearchType.All)
                {
                    DateTime dateFrom = filter.DateFrom.Date;
                    DateTime dateTo   = filter.DateTo.AddDays(1).Date;

                    items = items.Where(a => a.Date >= dateFrom && a.Date < dateTo);
                }

                if (filter.Paid != PaidType.None)
                {
                    if (filter.Paid == PaidType.Paid)
                    {
                        items = items.Where(a => a.IsPaid == true);
                    }
                    else if (filter.Paid == PaidType.NotPaid)
                    {
                        items = items.Where(a => a.IsPaid == false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(filter.PR))
                {
                    items = items.Where(a => a.PurchaseRequisitions.Any(b => b.PRNumber.Contains(filter.PR)));
                }

                if (!string.IsNullOrWhiteSpace(filter.PO))
                {
                    items = items.Where(a => a.PurchaseOrders.Any(b => b.PONumber.Contains(filter.PO)));
                }
            }
            else
            {
                items = items.OrderByDescending(a => a.Date);
            }

            return(items);
        }
예제 #16
0
 public ActionResult IndexPost(SaleFilterModel model)
 {
     Session["ItemsPerPage"] = model.ItemsPerPage;
     return(Statistics(model));
 }