Skip to content

Commit

Permalink
Merge pull request grandnode#625 from dborovsky/#385-date-ranges
Browse files Browse the repository at this point in the history
#385 range dates for searching returnrequest
  • Loading branch information
PatrykPorabik authored Aug 28, 2019
2 parents acea432 + fc023f3 commit e8f4a43
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Grand.Services/Orders/IReturnRequestService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Grand.Core;
using Grand.Core.Domain.Orders;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -37,12 +38,14 @@ public partial interface IReturnRequestService
/// <param name="customerId">Customer identifier; 0 to load all entries</param>
/// <param name="orderItemId">Order item identifier; 0 to load all entries</param>
/// <param name="rs">Return request status; null to load all entries</param>
/// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
/// <returns>Return requests</returns>
Task<IPagedList<ReturnRequest>> SearchReturnRequests(string storeId = "", string customerId = "",
string orderItemId = "", ReturnRequestStatus? rs = null,
int pageIndex = 0, int pageSize = int.MaxValue);
int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, DateTime? createdToUtc = null);

/// <summary>
/// Delete a return request action
Expand Down
8 changes: 7 additions & 1 deletion Grand.Services/Orders/ReturnRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ public virtual Task<ReturnRequest> GetReturnRequestById(int id)
/// <param name="storeId">Store identifier; 0 to load all entries</param>
/// <param name="customerId">Customer identifier; null to load all entries</param>
/// <param name="orderItemId">Order item identifier; 0 to load all entries</param>
/// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
/// <param name="rs">Return request status; null to load all entries</param>
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
/// <returns>Return requests</returns>
public virtual async Task<IPagedList<ReturnRequest>> SearchReturnRequests(string storeId = "", string customerId = "",
string orderItemId = "", ReturnRequestStatus? rs = null,
int pageIndex = 0, int pageSize = int.MaxValue)
int pageIndex = 0, int pageSize = int.MaxValue, DateTime? createdFromUtc = null, DateTime? createdToUtc = null)
{
var query = _returnRequestRepository.Table;
if (!String.IsNullOrEmpty(storeId))
Expand All @@ -111,6 +113,10 @@ public virtual async Task<IPagedList<ReturnRequest>> SearchReturnRequests(string
}
if (!String.IsNullOrEmpty(orderItemId))
query = query.Where(rr => rr.ReturnRequestItems.Any(x => x.OrderItemId == orderItemId));
if (createdFromUtc.HasValue)
query = query.Where(rr => createdFromUtc.Value <= rr.CreatedOnUtc);
if (createdToUtc.HasValue)
query = query.Where(rr => createdToUtc.Value >= rr.CreatedOnUtc);

query = query.OrderByDescending(rr => rr.CreatedOnUtc).ThenByDescending(rr => rr.Id);
return await PagedList<ReturnRequest>.Create(query, pageIndex, pageSize);
Expand Down
12 changes: 12 additions & 0 deletions Grand.Web/App_Data/Localization/defaultResources.grandres.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15151,6 +15151,18 @@
<LocaleResource Name="Admin.ReturnRequests.List.SearchReturnRequestStatus.Hint">
<Value>Search by a specific return status.</Value>
</LocaleResource>
<LocaleResource Name="Admin.ReturnRequests.List.StartDate">
<Value>Start date</Value>
</LocaleResource>
<LocaleResource Name="Admin.ReturnRequests.List.StartDate.Hint">
<Value>The start date for the search</Value>
</LocaleResource>
<LocaleResource Name="Admin.ReturnRequests.List.EndDate">
<Value>End date</Value>
</LocaleResource>
<LocaleResource Name="Admin.ReturnRequests.List.EndDate.Hint">
<Value>The end date for the search</Value>
</LocaleResource>
<LocaleResource Name="Admin.ReturnRequests.Notified">
<Value>The customer has been notified successfully.</Value>
</LocaleResource>
Expand Down
10 changes: 10 additions & 0 deletions Grand.Web/Areas/Admin/Models/Orders/ReturnReqestListModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Grand.Framework.Mvc.ModelBinding;
using Grand.Framework.Mvc.Models;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Grand.Web.Areas.Admin.Models.Orders
{
Expand All @@ -21,6 +23,14 @@ public ReturnReqestListModel()
[GrandResourceDisplayName("Admin.ReturnRequests.List.GoDirectlyToId")]
public string GoDirectlyToId { get; set; }

[GrandResourceDisplayName("Admin.ReturnRequests.List.StartDate")]
[UIHint("DateNullable")]
public DateTime? StartDate { get; set; }

[GrandResourceDisplayName("Admin.ReturnRequests.List.EndDate")]
[UIHint("DateNullable")]
public DateTime? EndDate { get; set; }

public string StoreId { get; set; }

public IList<SelectListItem> ReturnRequestStatus { get; set; }
Expand Down
15 changes: 14 additions & 1 deletion Grand.Web/Areas/Admin/Services/ReturnRequestViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,20 @@ public virtual async Task<ReturnRequestModel> PrepareReturnRequestModel(ReturnRe
else
customerId = "00000000-0000-0000-0000-000000000000";
}
var returnRequests = await _returnRequestService.SearchReturnRequests(model.StoreId, customerId, "", (model.SearchReturnRequestStatusId >= 0 ? (ReturnRequestStatus?)model.SearchReturnRequestStatusId : null), pageIndex - 1, pageSize);
DateTime? startDateValue = (model.StartDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

DateTime? endDateValue = (model.EndDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone);

var returnRequests = await _returnRequestService.SearchReturnRequests(model.StoreId,
customerId,
"",
(model.SearchReturnRequestStatusId >= 0 ? (ReturnRequestStatus?)model.SearchReturnRequestStatusId : null),
pageIndex - 1,
pageSize,
startDateValue,
endDateValue);
var returnRequestModels = new List<ReturnRequestModel>();
foreach (var rr in returnRequests)
{
Expand Down
14 changes: 14 additions & 0 deletions Grand.Web/Areas/Admin/Views/ReturnRequest/List.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
<admin-input asp-for="SearchCustomerEmail" />
</div>
</div>
<div class="form-group">
<admin-label asp-for="StartDate" class="col-xs-4 col-sm-4 col-md-4 control-label" />
<div class="col-xs-8 col-md-8 col-sm-8">
<admin-input asp-for="StartDate" />
</div>
</div>
<div class="form-group">
<admin-label asp-for="EndDate" class="col-xs-4 col-sm-4 col-md-4 control-label" />
<div class="col-xs-8 col-md-8 col-sm-8">
<admin-input asp-for="EndDate" />
</div>
</div>
<div class="form-group">
<admin-label asp-for="SearchReturnRequestStatusId" />
<div class="col-md-4 col-sm-6">
Expand Down Expand Up @@ -151,6 +163,8 @@
var data = {
SearchReturnRequestStatusId: $('#@Html.FieldIdFor(model => model.SearchReturnRequestStatusId)').val(),
SearchCustomerEmail: $('#@Html.FieldIdFor(model => model.SearchCustomerEmail)').val(),
StartDate: $('#@Html.FieldIdFor(model => model.StartDate)').val(),
EndDate: $('#@Html.FieldIdFor(model => model.EndDate)').val()
};
addAntiForgeryToken(data);
return data;
Expand Down

0 comments on commit e8f4a43

Please sign in to comment.