Rank: Advanced Member
Groups: HelpDesk, Developers Joined: 11/9/2018(UTC) Posts: 564
Thanks: 122 times Was thanked: 26 time(s) in 25 post(s)
|
Hi Shari, sorry for the delayed response. A few other projects got in my way. My goal is to add an Export ability to the Affiliate Details report. So I tried copying the button, button javascript and export controller code from the affiliate summary report and adapt it to work with affiliate detail report. The problem I'm having is when the export fires on the detail report, it's not sending the download file to the browser like it does on the summary page. I appreciate you taking the time to help me on this. It feels like I've missed something really small and minor but I cannot figure out what it is. Here is the controller code called by the export button I added to the view: Code:
public ActionResult ExportAffiliateDetails(int affiliateId, string startDate, string endDate)
{
DateTime start = string.IsNullOrEmpty(startDate) ? DateTime.MinValue : DateTime.Parse(startDate);
DateTime end = string.IsNullOrEmpty(endDate) ? DateTime.MinValue : DateTime.Parse(endDate);
start = Misc.GetStartOfDate(start);
end = Misc.GetEndOfDate(end);
var orders = _orderRepo.LoadForAffiliate(affiliateId, start, end, "OrderId ASC");
var orderData = orders.Select(order => new AffiliateDetailsExportModel()
{
OrderNumber = order.OrderNumber,
OrderDate = order.OrderDate.ToString(),
ProductSubTotal = order.ProductSubtotal.LSCurrencyFormat("lc"),
TotalCharges = order.TotalCharges.LSCurrencyFormat("lc"),
OrderCommission = GetCommissionForOrder(order).LSCurrencyFormat("lc"),
StudentName = order.GoogleOrderNumber,
CustomerName = order.BillToLastName + ", " + order.BillToFirstName
}).ToList();
GenericExportManager<AffiliateDetailsExportModel> exportManager = GenericExportManager<AffiliateDetailsExportModel>.Instance;
GenericExportOptions<AffiliateDetailsExportModel> options = new GenericExportOptions<AffiliateDetailsExportModel>();
options.CsvFields = new string[] { "AffiliateName", "ReferralCount", "FormattedConversionRate", "OrderCount", "ProductSubtotal", "OrderTotal", "FormattedCommission" };
options.ExportData = orderData;
options.FileTag = string.Format("SALES_DETAIL_BY_AFFILIATE(ID_{0}_from_{1}_to_{2})", affiliateId, start.ToShortDateString(), end.ToShortDateString());
exportManager.BeginExport(options);
return AffiliateDetails();
}
and here is the modified version of the affiliate details report view: Code:
@{
ViewBag.Title = "Affiliate Details";
ViewBag.PageCaption = "Affiliate Details";
}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Affiliate Details</h5>
</div>
<div class="ibox-content">
@using (Ajax.BeginForm("GetAffiatesDetails", null, new AjaxOptions() { UpdateTargetId = "affiliates-details-container", OnSuccess = "initAbleGrid" }, new { id = "affiliate-details-form" }))
{
<div>
<div class="row">
<div class="col-sm-12 form-inline center">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><label>Affiliate</label></span>
@Html.DropDownList("affiliateId", (SelectList)ViewBag.AffliatesList, new { @class = "form-control", @id="ddlAffiliateId" })
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-inline center">
<br />
<div class="form-group" id="affiliate-details">
<label class="control-label">Show orders from</label>
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input form-control" id="startDate" name="startDate" value="@ViewBag.StartDate" />
<span class="input-group-addon">to</span>
<input type="text" class="input form-control" id="endDate" name="endDate" value="@ViewBag.EndDate" />
<span class="input-group-addon"><a id="generateReport">Report</a></span>
<span class="input-group-addon"><a id="exportReport" data-action="@Url.Action("ExportAffiliateDetails")">Export</a></span>
</div>
</div>
</div>
</div>
</div>
}
<br />
<div id="affiliates-details-container" class="wrapper wrapper-content animated fadeInRight">
@Html.Action("GetAffiatesDetails", new { startDate = ViewBag.StartDate, endDate = ViewBag.EndDate })
</div>
</div>
</div>
</div>
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
$('#affiliate-details .input-daterange').datepicker({
keyboardNavigation: false,
forceParse: false,
dateFormat: 'dd-mm-yy',
autoclose: true
});
$("#affiliateId").on('change', function () { $("#affiliate-details-form").submit() });
$("#generateReport").click(function () { $("#affiliate-details-form").submit() });
$("#exportReport").click(function () {
var start = $("#startDate").val();
var end = $("#endDate").val();
var affiliateId = $("#ddlAffiliateId").val();
var action = $(this).data('action');
window.location.href = action + "?affiliateId=" + affiliateId + "&startDate=" + start + "&endDate=" + end;
});
});
</script>
}
|