logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Thursday, October 22, 2020 12:45:41 PM(UTC)
Joe Payne2

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)
I'm trying to add an export feature to the Affiliate Details report /Areas/Admin/Controllers/ReportController.cs just like the Affiliate Sales report.

In the AffiliateDetails view, I copied the same exact button used from AffiliateSales to the ajax form and gave it a new action name 'ExportAffiliateDetails'.

Code:

                                <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>


And then created a new action in the controller:

Code:

        public ActionResult ExportAffiliateDetails(int affiliateId = 0, string startDate = "", string endDate = "")
        {
        }


But clicking the Export button does nothing.

I can hit /Admin/Report/ExportAffiliateDetails and my method fires, so I know the code is recognized.

And Url.Action resolves the button to the correct url as well.

The only difference in my method is the method signature also has 'affiliateId' because I need to know the dropdown choice for the affiliate to export. But, MVC should be passing that value along with startDate and endDate because those parameter names match what is used in the view.

The button just doesn't do anything when clicked. I can't figure out why??

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

shari  
#2 Posted : Friday, October 23, 2020 7:30:01 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 703

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
For AffiliatesSales page, we are handling the Export button click in javascript.

Did you see the javascript code for handling click listener?
Joe Payne2  
#3 Posted : Friday, October 23, 2020 9:14:31 AM(UTC)
Joe Payne2

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)
What????? No I never noticed that.

Ok I've got the button firing, thank you so much.

How do I pull that dropdownlist selected value into the javascript so I can pass it to the action url? using 'var affiliateId = $("#affiliateId").val();' doesn't pull the selected value.

Joe Payne2  
#4 Posted : Friday, October 23, 2020 9:28:52 AM(UTC)
Joe Payne2

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)
AHA ! I figured it out !! (Google is your friend)

You have to assign an ID to the dropdown control first, then you can reference it directly and pull the .val() within the javascript for the button click.

I wrote a line of javascript. That makes me a javascript programmer right?! Yea?!? Pretty sure it does.

Code:

@Html.DropDownList("affiliateId", (SelectList)ViewBag.AffliatesList, new { @class = "form-control", @id="ddlAffiliateId" })


Code:

                var affiliateId = $("#ddlAffiliateId").val();

Joe Payne2  
#5 Posted : Friday, October 23, 2020 10:58:47 AM(UTC)
Joe Payne2

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)
So the AffiliateSales export ends with a 'return AffiliateSales()' which keeps the url the same and downloads the export file to the browser. I want the exact same behavior in the details export I built.

And in my Details export, I end the routine the exact same way, obviously using 'return AffiliateDetails()' instead of 'Return AffiliateSales()' because it's the details page. That way the browser is still on the details report page.

But the behavior is different. MVC is trying to pull in a view for my export action method even though I am doing a 'return AffiliateDetails()'. I can't figure out why because when I walk the code in the debugger, it does return the default view. Which should be 'AffiliateDetails'.

Quote:
The view 'ExportAffiliateDetails' or its master was not found or no view engine supports the searched locations
shari  
#6 Posted : Monday, October 26, 2020 1:46:33 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 703

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
If you can share the complete function code, it will be helpful to find the problem.
Joe Payne2  
#7 Posted : Wednesday, November 11, 2020 7:17:44 AM(UTC)
Joe Payne2

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>
}
shari  
#8 Posted : Wednesday, November 11, 2020 11:29:48 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 703

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
Code:
options.CsvFields = new string[] { "AffiliateName", "ReferralCount", "FormattedConversionRate", "OrderCount", "ProductSubtotal", "OrderTotal", "FormattedCommission" };


Can you please confirm that you have all properties in AffiliateDetailsExportModel with the same names defined in the above list? Also if you can share the implementation of your AffiliateDetailsExportModel class.

After clicking the export link, please look into error logs. The reason it asks for the view and never returns a file for download is that we have handled the exception that is logged in error logs.
thanks 1 user thanked shaharyar for this useful post.
Joe Payne2 on 12/3/2020(UTC)
Joe Payne2  
#9 Posted : Thursday, December 3, 2020 5:58:00 AM(UTC)
Joe Payne2

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)
Sorry for the delay getting back on this one. My forum notifications aren't going out so I didn't realize you had responded.

You are my hero.

I completely missed setting the proper field names in the CsvFields when I copied the code from the summary report. They were still set to the summary model fields. Changing to the details model fields fixed the problem. Thank you!!!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.