Subversion Repositories SmartDukaan

Rev

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

Rev 35857 Rev 35886
Line 572... Line 572...
572
        $(domId).html(response);
572
        $(domId).html(response);
573
        $(domId).find("#yearmonth").val(yearMonth);
573
        $(domId).find("#yearmonth").val(yearMonth);
574
    });
574
    });
575
}
575
}
576
 
576
 
-
 
577
// ===== Offer Partner & Target Management =====
-
 
578
 
-
 
579
// Manage Partners - open modal
-
 
580
$(document).on('click', 'a.manage_offer_partners', function () {
-
 
581
    let offerId = $(this).closest('tr').data('offerid');
-
 
582
    doGetAjaxRequestHandler(`${context}/offer/partners?offerId=${offerId}`, function (data) {
-
 
583
        $('#offerDescription .modal-content').html(data);
-
 
584
        $("#offerDescription").modal('show');
-
 
585
    });
-
 
586
});
-
 
587
 
-
 
588
// Select All checkbox
-
 
589
$(document).on('change', '#select-all-partners', function () {
-
 
590
    $('.partner-checkbox').prop('checked', $(this).is(':checked'));
-
 
591
});
-
 
592
 
-
 
593
// Remove Selected Partners - show options
-
 
594
$(document).on('click', '.remove-selected-partners', function () {
-
 
595
    let checked = $('.partner-checkbox:checked');
-
 
596
    if (checked.length === 0) {
-
 
597
        alert("Please select at least one partner to remove.");
-
 
598
        return;
-
 
599
    }
-
 
600
    $('#remove-options').show();
-
 
601
});
-
 
602
 
-
 
603
// Cancel remove
-
 
604
$(document).on('click', '.cancel-remove-partners', function () {
-
 
605
    $('#remove-options').hide();
-
 
606
    $('#create-new-offer-checkbox').prop('checked', false);
-
 
607
    $('#custom-targets-section').hide();
-
 
608
});
-
 
609
 
-
 
610
// Toggle custom targets section
-
 
611
$(document).on('change', '#create-new-offer-checkbox', function () {
-
 
612
    if ($(this).is(':checked')) {
-
 
613
        $('#custom-targets-section').show();
-
 
614
    } else {
-
 
615
        $('#custom-targets-section').hide();
-
 
616
    }
-
 
617
});
-
 
618
 
-
 
619
// Confirm Remove Partners
-
 
620
$(document).on('click', '.confirm-remove-partners', function () {
-
 
621
    let offerId = $('#offer-partners-table').data('offerid');
-
 
622
    let fofoIds = [];
-
 
623
    $('.partner-checkbox:checked').each(function () {
-
 
624
        fofoIds.push($(this).val());
-
 
625
    });
-
 
626
    let createNewOffer = $('#create-new-offer-checkbox').is(':checked');
-
 
627
    let targets = [];
-
 
628
    if (createNewOffer) {
-
 
629
        $('.new-offer-target').each(function () {
-
 
630
            targets.push($(this).val());
-
 
631
        });
-
 
632
    }
-
 
633
 
-
 
634
    let url = `${context}/offer/removePartners?offerId=${offerId}&fofoIds=${fofoIds.join(',')}`;
-
 
635
    url += `&createNewOffer=${createNewOffer}`;
-
 
636
    if (createNewOffer && targets.length > 0) {
-
 
637
        url += `&targets=${targets.join(',')}`;
-
 
638
    }
-
 
639
 
-
 
640
    if (confirm("Are you sure you want to remove " + fofoIds.length + " partner(s) from this offer?")) {
-
 
641
        doPostAjaxRequestHandler(url, function (response) {
-
 
642
            let data = typeof response === 'string' ? JSON.parse(response) : response;
-
 
643
            alert(data.message || "Partners removed successfully.");
-
 
644
            $('#offerDescription').modal('hide');
-
 
645
            let yearMonth = data.yearMonth || $("#yearmonth").val() || new Date().toISOString().slice(0, 7);
-
 
646
            loadOfferHistory('#main-content', yearMonth);
-
 
647
        });
-
 
648
    }
-
 
649
});
-
 
650
 
-
 
651
// Add Partners
-
 
652
$(document).on('click', '.add-selected-partners', function () {
-
 
653
    let offerId = $('#offer-partners-table').data('offerid');
-
 
654
    if (!offerId) {
-
 
655
        offerId = $(this).closest('.modal-body').find('[data-offerid]').data('offerid');
-
 
656
    }
-
 
657
    let selectedFofoIds = $('#add-partner-select').val();
-
 
658
    if (!selectedFofoIds || selectedFofoIds.length === 0) {
-
 
659
        alert("Please select at least one partner to add.");
-
 
660
        return;
-
 
661
    }
-
 
662
 
-
 
663
    let url = `${context}/offer/addPartners?offerId=${offerId}&fofoIds=${selectedFofoIds.join(',')}`;
-
 
664
    if (confirm("Add " + selectedFofoIds.length + " partner(s) to Offer #" + offerId + "?")) {
-
 
665
        doPostAjaxRequestHandler(url, function (response) {
-
 
666
            let data = typeof response === 'string' ? JSON.parse(response) : response;
-
 
667
            alert(data.message || "Partners added successfully.");
-
 
668
            // Reload the modal to show updated partner list
-
 
669
            doGetAjaxRequestHandler(`${context}/offer/partners?offerId=${offerId}`, function (modalData) {
-
 
670
                $('#offerDescription .modal-content').html(modalData);
-
 
671
            });
-
 
672
        });
-
 
673
    }
-
 
674
});
-
 
675
 
-
 
676
// Update Offer Targets
-
 
677
$(document).on('click', '.update-offer-targets', function () {
-
 
678
    let offerId = $('#edit-targets-section').data('offerid');
-
 
679
    let targets = [];
-
 
680
    $('.edit-target-value').each(function () {
-
 
681
        targets.push($(this).val());
-
 
682
    });
-
 
683
 
-
 
684
    if (targets.length === 0) {
-
 
685
        alert("No targets to update.");
-
 
686
        return;
-
 
687
    }
-
 
688
 
-
 
689
    let url = `${context}/offer/updateTargets?offerId=${offerId}&targets=${targets.join(',')}`;
-
 
690
    if (confirm("Update targets for Offer #" + offerId + "?")) {
-
 
691
        doPostAjaxRequestHandler(url, function (response) {
-
 
692
            alert("Targets updated for Offer #" + offerId + ".");
-
 
693
            $('#offerDescription').modal('hide');
-
 
694
            let yearMonth = $("#yearmonth").val() || new Date().toISOString().slice(0, 7);
-
 
695
            loadOfferHistory('#main-content', yearMonth);
-
 
696
        });
-
 
697
    }
-
 
698
});
-
 
699