Skip to content

Commit

Permalink
Added reports for vendor in their portal #431
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Nov 13, 2023
1 parent 658d63a commit 8d18b15
Show file tree
Hide file tree
Showing 39 changed files with 1,888 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public virtual IEnumerable<DefaultPermission> GetDefaultPermissions()
StandardPermission.ManageOrders,
StandardPermission.ManageVendorReviews,
StandardPermission.ManageShipments,
StandardPermission.ManageMerchandiseReturns
StandardPermission.ManageMerchandiseReturns,
StandardPermission.ManageReports
}
},
new DefaultPermission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface ICustomerReportService
/// Get best customers
/// </summary>
/// <param name="storeId">Store ident</param>
/// <param name="vendorId">Vendor ident</param>
/// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
/// <param name="os">Order status; null to load all records</param>
Expand All @@ -23,8 +24,8 @@ public interface ICustomerReportService
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
/// <returns>Report</returns>
IPagedList<BestCustomerReportLine> GetBestCustomersReport(string storeId, DateTime? createdFromUtc,
DateTime? createdToUtc, int? os, PaymentStatus? ps, ShippingStatus? ss, int orderBy,
IPagedList<BestCustomerReportLine> GetBestCustomersReport(string storeId = "", string vendorId = "", DateTime? createdFromUtc = null,
DateTime? createdToUtc = null, int? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, int orderBy = 0,
int pageIndex = 0, int pageSize = 214748364);

/// Gets a report of customers registered in the last days
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public interface IOrderReportService
/// Get "order by country" report
/// </summary>
/// <param name="storeId">Store identifier; "" to load all records</param>
/// <param name="vendorId">Vendor identifier; "" to load all records</param>
/// <param name="os">Order status</param>
/// <param name="ps">Payment status</param>
/// <param name="ss">Shipping status</param>
/// <param name="startTimeUtc">Start date</param>
/// <param name="endTimeUtc">End date</param>
/// <returns>Result</returns>
Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId = "", int? os = null,
Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId = "",
string vendorId = "", int? os = null,
PaymentStatus? ps = null, ShippingStatus? ss = null,
DateTime? startTimeUtc = null, DateTime? endTimeUtc = null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class MigrationUpdateResourceString : IMigration
{
public int Priority => 0;
public DbVersion Version => new(2, 2);
public Guid Identity => new("FA844964-DB84-457C-B517-E0EF521AE44B");
public Guid Identity => new("97287FAC-ECF6-462E-9ED0-586C26151A4F");
public string Name => "Update resource string for english language 2.2";

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public CustomerReportService(IRepository<Customer> customerRepository,
/// Get best customers
/// </summary>
/// <param name="storeId">Store ident</param>
/// <param name="vendorId">Vendor ident</param>
/// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
/// <param name="os">Order status; null to load all records</param>
Expand All @@ -61,8 +62,8 @@ public CustomerReportService(IRepository<Customer> customerRepository,
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
/// <returns>Report</returns>
public virtual IPagedList<BestCustomerReportLine> GetBestCustomersReport(string storeId, DateTime? createdFromUtc,
DateTime? createdToUtc, int? os, PaymentStatus? ps, ShippingStatus? ss, int orderBy,
public virtual IPagedList<BestCustomerReportLine> GetBestCustomersReport(string storeId = "", string vendorId = "", DateTime? createdFromUtc = null,
DateTime? createdToUtc = null, int? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, int orderBy = 0,
int pageIndex = 0, int pageSize = 214748364)
{

Expand All @@ -83,37 +84,57 @@ public virtual IPagedList<BestCustomerReportLine> GetBestCustomersReport(string
if (!string.IsNullOrEmpty(storeId))
query = query.Where(o => o.StoreId == storeId);

var query2 = from co in query
group co by co.CustomerId into g
select new
{
CustomerId = g.Key,
OrderTotal = g.Sum(x => x.OrderTotal / x.CurrencyRate),
OrderCount = g.Count()
};
switch (orderBy)
if (string.IsNullOrEmpty(vendorId))
{
case 1:
var query2 = from co in query
group co by co.CustomerId into g
select new
{
query2 = query2.OrderByDescending(x => x.OrderTotal);
}
break;
case 2:
{
query2 = query2.OrderByDescending(x => x.OrderCount);
}
break;
default:
throw new ArgumentException("Wrong orderBy parameter", "orderBy");
CustomerId = g.Key,
OrderTotal = g.Sum(x => x.OrderTotal / x.CurrencyRate),
OrderCount = g.Count()
};
query2 = orderBy switch {
1 => query2.OrderByDescending(x => x.OrderTotal),
2 => query2.OrderByDescending(x => x.OrderCount),
_ => throw new ArgumentException("Wrong orderBy parameter", "orderBy")
};

var tmp = new PagedList<dynamic>(query2, pageIndex, pageSize);
return new PagedList<BestCustomerReportLine>(tmp.Select(x => new BestCustomerReportLine {
CustomerId = x.CustomerId,
OrderTotal = x.OrderTotal,
OrderCount = x.OrderCount
}), tmp.PageIndex, tmp.PageSize, tmp.TotalCount);
}

var tmp = new PagedList<dynamic>(query2, pageIndex, pageSize);
return new PagedList<BestCustomerReportLine>(tmp.Select(x => new BestCustomerReportLine {

var vendorQuery = from p in query
from item in p.OrderItems
select new { VendorId = item.VendorId, CustomerId = p.CustomerId, OrderCode = p.Code, Quantity = item.Quantity, PriceInclTax = item.PriceInclTax, Rate = p.Rate };

vendorQuery = vendorQuery.Where(x => x.VendorId == vendorId);

var vendorQueryGroup = from co in vendorQuery
group co by co.CustomerId into g
select new
{
CustomerId = g.Key,
OrderTotal = g.Sum(x => x.PriceInclTax / x.Rate),
OrderCount = g.Count()
};
vendorQueryGroup = orderBy switch {
1 => vendorQueryGroup.OrderByDescending(x => x.OrderTotal),
2 => vendorQueryGroup.OrderByDescending(x => x.OrderCount),
_ => throw new ArgumentException("Wrong orderBy parameter", "orderBy")
};

var vendorReport = new PagedList<dynamic>(vendorQueryGroup, pageIndex, pageSize);
return new PagedList<BestCustomerReportLine>(vendorReport.Select(x => new BestCustomerReportLine {
CustomerId = x.CustomerId,
OrderTotal = x.OrderTotal,
OrderCount = x.OrderCount
}),
tmp.PageIndex, tmp.PageSize, tmp.TotalCount);
}), vendorReport.PageIndex, vendorReport.PageSize, vendorReport.TotalCount);

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ public OrderReportService(IRepository<Order> orderRepository,
/// Get "order by country" report
/// </summary>
/// <param name="storeId">Store identifier</param>
/// <param name="vendorId">Vendor identifier</param>
/// <param name="os">Order status</param>
/// <param name="ps">Payment status</param>
/// <param name="ss">Shipping status</param>
/// <param name="startTimeUtc">Start date</param>
/// <param name="endTimeUtc">End date</param>
/// <returns>Result</returns>
public virtual async Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId, int? os,
public virtual async Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId, string vendorId, int? os,
PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc)
{
var query = from p in _orderRepository.Table
Expand All @@ -79,23 +80,57 @@ public virtual async Task<IList<OrderByCountryReportLine>> GetCountryReport(stri
if (endTimeUtc.HasValue)
query = query.Where(o => endTimeUtc.Value >= o.CreatedOnUtc);

var report = (from oq in query
group oq by oq.BillingAddress.CountryId into result
select new
{
CountryId = result.Key,
TotalOrders = result.Count(),
SumOrders = result.Sum(o => o.OrderTotal / o.CurrencyRate)
}
)
.OrderByDescending(x => x.SumOrders)
.Select(r => new OrderByCountryReportLine {
CountryId = r.CountryId,
TotalOrders = r.TotalOrders,
SumOrders = r.SumOrders
});

return await Task.FromResult(report.ToList());
if (!string.IsNullOrEmpty(vendorId))
{
query = query
.Where(o => o.OrderItems
.Any(orderItem => orderItem.VendorId == vendorId));
}

if (string.IsNullOrEmpty(vendorId))
{
var report = (from oq in query
group oq by oq.BillingAddress.CountryId
into result
select new {
CountryId = result.Key,
TotalOrders = result.Count(),
SumOrders = result.Sum(o => o.OrderTotal / o.CurrencyRate)
}
)
.OrderByDescending(x => x.SumOrders)
.Select(r => new OrderByCountryReportLine {
CountryId = r.CountryId,
TotalOrders = r.TotalOrders,
SumOrders = r.SumOrders
});

return await Task.FromResult(report.ToList());
}

var vendorQuery = from p in query
from item in p.OrderItems
select new { VendorId = item.VendorId, OrderCode = p.Code, CountryId = p.BillingAddress.CountryId, Quantity = item.Quantity, PriceInclTax = item.PriceInclTax, Rate = p.Rate };

vendorQuery = vendorQuery.Where(x => x.VendorId == vendorId);

var vendorReport = (from oq in vendorQuery
group oq by oq.CountryId
into result
select new {
CountryId = result.Key,
TotalOrders = result.Count(),
SumOrders = result.Sum(y => y.PriceInclTax / y.Rate)
}
)
.OrderByDescending(x => x.SumOrders)
.Select(r => new OrderByCountryReportLine {
CountryId = r.CountryId,
TotalOrders = r.TotalOrders,
SumOrders = r.SumOrders
});
return await Task.FromResult(vendorReport.ToList());

}


Expand Down
12 changes: 10 additions & 2 deletions src/Web/Grand.Web.Admin/Services/CustomerReportViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ public virtual async Task<IList<RegisteredCustomerReportLineModel>> GetReportReg
PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;
ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)model.ShippingStatusId : null;

var items = _customerReportService.GetBestCustomersReport(model.StoreId, startDateValue, endDateValue,
orderStatus, paymentStatus, shippingStatus, 2, pageIndex - 1, pageSize);
var items = _customerReportService.GetBestCustomersReport(
storeId: model.StoreId,
createdFromUtc: startDateValue,
createdToUtc: endDateValue,
os: orderStatus,
ps: paymentStatus,
ss: shippingStatus,
orderBy: 2,
pageIndex: pageIndex - 1,
pageSize: pageSize);

var report = new List<BestCustomerReportLineModel>();
foreach (var x in items)
Expand Down
55 changes: 55 additions & 0 deletions src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Home/Statistics.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@{
//page title
ViewBag.Title = Loc["Vendor.Dashboard.Statistics"];
}

<div class="page-bar" style="height:43px;">
<div class="page-toolbar">
<div id="dashboard-report-range" class="pull-right btn btn-sm">
<i class="icon-calendar"></i>&nbsp;
<span class="thin uppercase">@DateTime.Now.ToLocalTime().ToString(CultureInfo.InvariantCulture)</span>&nbsp;
</div>
</div>
</div>
<div class="content-header">
<h3 class="page-title">
<i class="icon-bulb"></i>
@Loc["Vendor.Dashboard"]
<small>@Loc["Vendor.Dashboard.Statistics"]</small>
</h3>
</div>

<div class="content">
<vc:vendor-widget widget-zone="vendor_dashboard_statistics_before" />
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<div class="x_panel">
<div class="x_title">
<div class="caption level-caption">
<span class="caption-subject font-dark bold uppercase">@Loc["Vendor.Reports.BestSellers.ByQuantity"]</span>
</div>
</div>
<div class="x_content">
<vc:vendor-bestsellers-brief-report-by-quantity></vc:vendor-bestsellers-brief-report-by-quantity>
</div>
</div>
</div>
<div class="col-md-6">
<div class="x_panel">
<div class="x_title">
<div class="caption level-caption">
<span class="caption-subject font-dark bold uppercase">@Loc["Vendor.Reports.BestSellers.ByAmount"]</span>
</div>
</div>
<div class="x_content">
<vc:vendor-bestsellers-brief-report-by-amount></vc:vendor-bestsellers-brief-report-by-amount>
</div>
</div>
</div>
</div>
</div>
</div>
<vc:vendor-widget widget-zone="vendor_dashboard_statistics_after" />
</div>
Loading

0 comments on commit 8d18b15

Please sign in to comment.