Subversion Repositories SmartDukaan

Rev

Rev 37794 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<section class="wrapper">
    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
                <li><i class="icon_document_alt"></i>MARGINS</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-2 scheme-extendAll">
            #if($isAdmin)
                #if($fullAccess)
                    <div class="input-group">
                        <input placeholder="Extend Date Time" id="extendDatetime" name="extendDatetime"
                               type="text"
                               value=""
                               class="form-control">
                        <span class="input-group-btn"> <button class="btn btn-primary submit"
                                                               id="extendDatetime-button"
                                                               type="button">Extend All</button></span>
                    </div>
                #end
            #end
        </div>
        <div class="col-lg-2">
            #if($searchModel > 0)
                <div style="padding:12px">
                    <span> DP - </span><span class="currency">$dp</span>,&nbsp;&nbsp;
                    <span> MOP - </span><span class="currency">$mop</span>
                </div>
            #end
        </div>
        <div class="col-lg-2 form-inline">
            #if(!$isAnalysis)
                <div id="scheme-search" class="form-group">
                    <div class="input-group top_search">
                        <input type="text" class="form-control" id="scheme-search-text"
                               placeholder="Search for schemeID..."
                            #if($searchScheme > 0)
                               value="$searchScheme"
                            #end />
                        <span class="input-group-btn">
                                          <button class="btn btn-primary submit" id="scheme-search-button"
                                      type="button">Go!</button>
                                        </span>
                    </div>
                </div>
            #else
                <div id="analysis-scheme-search" class="form-group">
                    <div class="input-group top_search">
                        <input type="text" class="form-control" id="analysis-scheme-search-text"
                               placeholder="Search for schemeID..."
                            #if($searchScheme > 0)
                               value="$searchScheme"
                            #end />
                        <span class="input-group-btn">
                                          <button class="btn btn-primary submit" data-fofoid="$fofoId"
                                      id="analysis-scheme-search-button"
                                      type="button" data-fofoid="$fofoId">Go!</button>
                                        </span>
                    </div>
                </div>
            #end

        </div>
        <div class="col-lg-1">
            #if($isAdmin)
                <div class="form-group ">
                    <select class="form-control input-sm" id="partner-category" name="partner-category"
                            placeholder="Category">
                        <option disabled>Category</option>
                        <option value="ALL" selected>ALL</option>
                        <option value="NEW">NEW</option>
                        <option value="BRONZE">BRONZE</option>
                        <option value="SILVER">SILVER</option>
                        <option value="GOLD">GOLD</option>
                        <option value="DIAMOND">DIAMOND</option>
                        <option value="PLATINUM">PLATINUM</option>
                    </select>
                </div>
            #end
        </div>
        <div class="form-inline col-lg-4">
            #if(!$isAnalysis)
                <div class="form-group">
                    <div class="input-group">
                        <input type="date" class="form-control schemes-date"
                            #if($date)
                               value="$date"
                            #else

                            #end
                        />
                    </div>
                    <div class="input-group top_search">
                        <input type="text" class="form-control" id="scheme-item-search-text" autocomplete="off"
                               placeholder="Search Model"
                            #if($searchModel > 0)
                               value="$modelName"
                            #end
                        />
                        <span class="input-group-btn">
                        <button class="btn btn-primary submit" id="scheme-item-search-button" type="button">Go!</button>
                    </span>
                    </div>
                </div>
            #else
                <div class="form-group">
                    <div class="input-group">
                        <input type="date" class="form-control analysis-schemes-date"
                            #if($date)
                               value="$date"
                            #else

                            #end
                        />
                    </div>
                    <div class="input-group top_search">
                        <input type="text" class="form-control" id="analysis-scheme-item-search-text" autocomplete="off"
                               placeholder="Search Model"
                            #if($searchModel > 0)
                               value="$modelName"
                            #end
                        />
                        <span class="input-group-btn">
                        <button class="btn btn-primary submit" id="analysis-scheme-item-search-button" type="button"
                                data-fofoid="$fofoId">Go!</button>
                    </span>
                    </div>
                </div>
            #end
        </div>
    </div>
    <div id="schemes-table">
        <div class="row">
            <div class="col-lg-12" style="max-height:400px; overflow-y:auto;">
                <!-- Offer & Scheme Radar: bulk-select schemes and send a WhatsApp
                     digest to all HO users. Handler:
                     OfferRadarNotificationController#sendRadarNotification. -->
                <div class="scheme-radar-bar" style="display:flex; align-items:center; gap:12px; margin-bottom:10px;">
                    <button type="button"
                            id="schemeRadarSendBtn"
                            class="btn btn-primary"
                            data-radar-kind="scheme"
                            disabled>
                        Send WhatsApp Radar (<span id="schemeRadarSelectedCount">0</span>)
                    </button>
                    <span class="text-muted" style="font-size:12px;">
                        Tick any schemes below, then send. Recipients: all HO users with a mobile number.
                    </span>
                </div>
                <table class="table table-striped table-advance table-hover">
                    <tbody>
                    <tr>
                        <th style="width:28px;">
                            <input type="checkbox" id="schemeRadarSelectAll" title="Select all">
                        </th>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Reference</th>
                        <th>Description</th>
                        <th>Type</th>
                        <th>Partner Type</th>
                        <th>Regions</th>
                        <th>Amount</th>
                        <th>Start Date</th>
                        <th>End Date</th>
                        <th>Created On</th>
                        <th>Active</th>
                        <th>Expire</th>
                    </tr>
                        #if($schemes && !$schemes.isEmpty())
                            #foreach( $scheme in $schemes )
                            <tr class="scheme-details" data="$scheme.getId()" style="cursor:pointer;">
                                <td onclick="event.stopPropagation();">
                                    <input type="checkbox"
                                           class="scheme-radar-check"
                                           value="$scheme.getId()"
                                           onclick="event.stopPropagation();">
                                </td>
                                <td>$scheme.getId()</td>
                                <td>$scheme.getName()</td>
                                <td>#if($scheme.getReference())$scheme.getReference()#else-#end</td>
                                <td>$scheme.getDescription()</td>
                                <td>$scheme.getType()</td>
                                <td>$scheme.getPartnerType()</td>
                                <td>$schemeRegionMap.get($scheme.getId())</td>
                                <td>$scheme.getAmountModel()</td>
                                <td>$dateFormatter.format($scheme.getStartDateTime())</td>
                                <td>$dateTimeFormatter.format($scheme.getEndDateTime())</td>
                                <td>$dateTimeFormatter.format($scheme.getCreateTimestamp())</td>
                                #if(($scheme.getActiveTimestamp()) && (!$scheme.getExpireTimestamp()))
                                    <td><i class="fa fa-check" aria-hidden="true"></i></td>
                                #else
                                    <td><i class="fa fa-times" aria-hidden="true"></i></td>
                                #end
                                #if($scheme.getExpireTimestamp())
                                    <td><i class="fa fa-check" aria-hidden="true"></i></td>
                                #else
                                    <td><i class="fa fa-times" aria-hidden="true"></i></td>
                                #end
                            </tr>
                            #end
                        #else
                            $noData
                        #end
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12" id="scheme-details-container" style="background:white;">
            </div>
        </div>
    </div>
    #if($searchModel > 0)
        <div class="col-lg-12">
            <h5>Note</h5>
            <b>Hygiene Payout</b> - This is basis the customer details entered in the system, pls refer to hygiene
            meter
            in your Dashboard.
            <br><b>Tertiary Payout</b> - This is basis the activation of the handset.
            <!--<b>Investment Payout</b> - Investments in stocks should be above 90% for minimum 12 days in a month
            to earn 2%, between 8-11 days will earn 1%, less then 8 days there will be no payout.-->
        </div>
    #end
</section>
<script type="text/javascript">

    if ($searchModel > 0) {
        currentItem = $searchModel;
    }
    $('input[name="extendDatetime"]').daterangepicker(getSingleDatePicker());

    getEntityAheadOptions($("#scheme-item-search-text"), function (selectedItem) {
        currentItem = selectedItem.catalogId_i;
    });
    getEntityAheadOptions($("#analysis-scheme-item-search-text"), function (selectedItem) {
        currentItem = selectedItem.catalogId_i;
    });

    $(document).ready(function () {
        console.log('$partnerType')
        $('#partner-category').val('$partnerType');

        // ── Scheme Radar bulk-send wiring ─────────────────────────────
        // Same shape as the offer_history version; POST payload only carries
        // schemeIds because this table has no offers. Row click is a
        // pre-existing scheme-details drill-down, so the checkbox cell and the
        // input itself stopPropagation to avoid opening the drill on tick.
        // jQuery locals are renamed off the conventional $-prefix so Velocity
        // never sees a $ident.method() shape and tries to parse it.
        var schemeSelectAll = $("#schemeRadarSelectAll");
        var schemeBtn = $("#schemeRadarSendBtn");
        var schemeCount = $("#schemeRadarSelectedCount");

        function selectedSchemeIds() {
            var ids = [];
            $(".scheme-radar-check:checked").each(function () {
                var v = parseInt(this.value, 10);
                if (!isNaN(v)) ids.push(v);
            });
            return ids;
        }

        function refreshSchemeRadarUi() {
            var ids = selectedSchemeIds();
            schemeCount.text(ids.length);
            schemeBtn.prop("disabled", ids.length === 0);
            var total = $(".scheme-radar-check").length;
            var picked = ids.length;
            schemeSelectAll.prop("indeterminate", picked > 0 && picked < total);
            schemeSelectAll.prop("checked", picked > 0 && picked === total);
        }

        schemeSelectAll.on("change", function (e) {
            e.stopPropagation();
            $(".scheme-radar-check").prop("checked", this.checked);
            refreshSchemeRadarUi();
        });
        $(document).on("change", ".scheme-radar-check", function (e) {
            e.stopPropagation();
            refreshSchemeRadarUi();
        });

        schemeBtn.on("click", function () {
            var ids = selectedSchemeIds();
            if (ids.length === 0) return;
            if (!confirm("Send WhatsApp Radar digest for " + ids.length + " scheme(s) to all HO users?")) return;

            var schemeSelf = $(this);
            schemeSelf.prop("disabled", true).text("Sending…");
            $.ajax({
                url: "/offerRadar/sendNotification",
                method: "POST",
                contentType: "application/json",
                data: JSON.stringify({offerIds: [], schemeIds: ids})
            }).done(function (resp) {
                var r = (resp && resp.response) || resp || {};
                alert("Sent to " + (r.sent || 0) + " user(s). Skipped: " + (r.skipped || 0)
                        + ", Failed: " + (r.failed || 0)
                        + "\nRegion: " + (r.regionSummary || "-")
                        + " | Offers added: " + (r.offersAdded || 0)
                        + " | Schemes added: " + (r.schemesAdded || 0)
                        + " | Revisions: " + (r.revisions || 0)
                        + " | Ending soon: " + (r.endingSoon || 0));
            }).fail(function (xhr) {
                var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
                alert("Radar send failed: " + msg);
            }).always(function () {
                schemeSelf.html('Send WhatsApp Radar (<span id="schemeRadarSelectedCount">' + ids.length + '</span>)');
                refreshSchemeRadarUi();
            });
        });

        refreshSchemeRadarUi();
    });
</script>