private void GetSalesSummary() { DateTime fromDate = Utilities.GetStartOfMonth(DateTime.Now.AddMonths(-6)); DateTime toDate = Utilities.GetStartOfMonth(DateTime.Now.AddMonths(1)); Query salesSummaryQuery = new Query(new And(new Q(Invoice.Columns.PromoterK, this.CurrentPromoter.K), new Q(Invoice.Columns.CreatedDateTime, QueryOperator.GreaterThanOrEqualTo, fromDate), new Q(Invoice.Columns.CreatedDateTime, QueryOperator.LessThan, toDate))); salesSummaryQuery.Columns = new ColumnSet(Invoice.Columns.PromoterK); salesSummaryQuery.ExtraSelectElements.Add("Amount", "SUM(Price)"); salesSummaryQuery.ExtraSelectElements.Add("Date", "CONVERT(datetime,'1/' + CONVERT(varchar(2),MONTH(CreatedDateTime)) + '/' + CONVERT(varchar(4),Year(CreatedDateTime)))"); salesSummaryQuery.OrderBy = new OrderBy("YEAR(CreatedDateTime) desc, MONTH(CreatedDateTime) desc"); salesSummaryQuery.GroupBy = new GroupBy("MONTH(CreatedDateTime), YEAR(CreatedDateTime), PromoterK"); InvoiceSet invoices = new InvoiceSet(salesSummaryQuery); //toDate = toDate.AddMonths(-1); #region Table SalesSummaryTable.Rows.Clear(); #endregion #region Header Row HtmlTableRow headerRow = new HtmlTableRow(); headerRow.Attributes.Add("class", "dataGridHeader"); SalesSummaryTable.Rows.Add(headerRow); List<HtmlTableCell> headerTableCells = new List<HtmlTableCell>(); headerTableCells.Add(new HtmlTableCell("th")); headerTableCells.Add(new HtmlTableCell("th")); headerTableCells[0].InnerHtml = "Month"; headerTableCells[1].InnerHtml = "<nobr>Amount (ex VAT)</nobr>"; foreach (HtmlTableCell tc in headerTableCells) headerRow.Cells.Add(tc); #endregion #region Data Rows int numberOfMonths = (toDate.Year - fromDate.Year) * 12 + toDate.Month - fromDate.Month; for (int i = 0; i < numberOfMonths; i++) { HtmlTableRow dataRow = new HtmlTableRow(); SalesSummaryTable.Rows.Add(dataRow); if (i % 2 == 1) dataRow.Attributes.Add("class", "dataGridItem"); else dataRow.Attributes.Add("class", "dataGridAltItem"); List<HtmlTableCell> dataTableCells = new List<HtmlTableCell>(); dataTableCells.Add(new HtmlTableCell("td")); dataTableCells.Add(new HtmlTableCell("td")); foreach (HtmlTableCell tc in dataTableCells) dataRow.Cells.Add(tc); dataTableCells[0].InnerHtml = ""; dataTableCells[1].InnerHtml = ""; if (Utilities.GetStartOfMonth(fromDate.AddMonths(i)) == Utilities.GetStartOfMonth(DateTime.Now)) { dataTableCells[0].InnerHtml = "<small>"; dataTableCells[1].InnerHtml = "<small>"; } dataTableCells[0].InnerHtml += fromDate.AddMonths(i).ToString("MMM yyyy"); dataTableCells[1].Align = "right"; invoices.Reset(); bool found = false; foreach (Invoice invoice in invoices) { if (Utilities.GetStartOfMonth((DateTime)invoice.ExtraSelectElements["Date"]) == Utilities.GetStartOfMonth(fromDate.AddMonths(i))) { dataTableCells[1].InnerHtml += Convert.ToDouble(invoice.ExtraSelectElements["Amount"]).ToString("c"); found = true; break; } } if(!found) dataTableCells[1].InnerHtml += "£0.00"; if (Utilities.GetStartOfMonth(fromDate.AddMonths(i)) == Utilities.GetStartOfMonth(DateTime.Now)) { dataTableCells[0].InnerHtml += "</small>"; dataTableCells[1].InnerHtml += "</small>"; } } #endregion }
private bool IsOnPromoterPayPage(InvoiceSet invoices) { invoices.Reset(); foreach (Invoice invoice in invoices) { if (Utilities.GetStartOfDay((DateTime)invoice.ExtraSelectElements["MinDueDate"]) >= DateTime.Today) { if (HttpContext.Current.Request.Url.ToString().IndexOf(invoice.Promoter.UrlApp("invoices", "PayOutstanding", "true")) >= 0) return true; } else { if (HttpContext.Current.Request.Url.ToString().IndexOf(invoice.Promoter.UrlApp("invoices", "PayOutstanding", "true", "Overdue", "true")) >= 0) return true; } } return false; }