Subversion Repositories SmartDukaan

Rev

Rev 35886 | Rev 36052 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35886 Rev 35925
Line 671... Line 671...
671
            });
671
            });
672
        });
672
        });
673
    }
673
    }
674
});
674
});
675
 
675
 
676
// Update Offer Targets
676
// Update Offer Targets & Payouts (per slab)
677
$(document).on('click', '.update-offer-targets', function () {
677
$(document).on('click', '.update-offer-slabs', function () {
678
    let offerId = $('#edit-targets-section').data('offerid');
678
    let offerId = $('#edit-slabs-table').data('offerid');
679
    let targets = [];
679
    let slabs = [];
-
 
680
 
680
    $('.edit-target-value').each(function () {
681
    $('#edit-slabs-table tbody tr').each(function () {
-
 
682
        let $target = $(this).find('.edit-slab-target');
-
 
683
        let $payout = $(this).find('.edit-slab-payout');
-
 
684
        if ($target.length) {
-
 
685
            slabs.push({
-
 
686
                id: parseInt($target.data('slabid')),
681
        targets.push($(this).val());
687
                payoutTarget: parseInt($target.val()),
-
 
688
                payoutValue: parseFloat($payout.val())
-
 
689
            });
-
 
690
        }
682
    });
691
    });
683
 
692
 
684
    if (targets.length === 0) {
693
    if (slabs.length === 0) {
685
        alert("No targets to update.");
694
        alert("No slabs to update.");
686
        return;
695
        return;
687
    }
696
    }
688
 
697
 
689
    let url = `${context}/offer/updateTargets?offerId=${offerId}&targets=${targets.join(',')}`;
698
    if (confirm("Update targets & payouts for Offer #" + offerId + "?")) {
-
 
699
        $.ajax({
-
 
700
            url: context + '/offer/updateSlabs',
-
 
701
            type: 'POST',
-
 
702
            contentType: 'application/json',
690
    if (confirm("Update targets for Offer #" + offerId + "?")) {
703
            data: JSON.stringify({ offerId: offerId, slabs: slabs }),
691
        doPostAjaxRequestHandler(url, function (response) {
704
            success: function (response) {
692
            alert("Targets updated for Offer #" + offerId + ".");
705
                alert("Targets & payouts updated for Offer #" + offerId + ".");
693
            $('#offerDescription').modal('hide');
706
                $('#offerDescription').modal('hide');
694
            let yearMonth = $("#yearmonth").val() || new Date().toISOString().slice(0, 7);
707
                let yearMonth = $("#yearmonth").val() || new Date().toISOString().slice(0, 7);
695
            loadOfferHistory('#main-content', yearMonth);
708
                loadOfferHistory('#main-content', yearMonth);
-
 
709
            },
-
 
710
            error: function (xhr) {
-
 
711
                alert("Failed to update: " + (xhr.responseJSON ? xhr.responseJSON.statusMessage : xhr.statusText));
-
 
712
            }
696
        });
713
        });
697
    }
714
    }
698
});
715
});
699
 
716