Subversion Repositories SmartDukaan

Rev

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

<script src="https://cdn.datatables.net/plug-ins/1.10.19/api/sum().js"></script>

<style>
    .table td.text {
        max-width: 150px;
    }

    .table td.text span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
        max-width: 100%;
    }

</style>
<button type="submit" class="btn btn-primary mk_fetch_plan">Download Plan Statement</button>


<div class="row">


    #if(!$inStocksMap.isEmpty())
        <div class="col-lg-12">
            <table
                    class="table table-striped table-advance table-hover partner-planning-details">
                <thead>

                <tr>
                    <th rowspan="3">Warehouse</th>
                    <th rowspan="3">Category</th>
                    <th rowspan="3">Partner Name</th>
                    <th rowspan="3">Terrirory Manager</th>
                    #foreach($catalog in
                        $catalogItemMap.entrySet())
                        <th colspan="3">
                            <span title="Width of Distribution">WOD : <span class="wod"></span></span>,
                            <span title="Total Stock">TS:<span class="ts"></span></span>,
                            <span title="Width of Sales">WOS: <span class="wos"></span></span>,
                            <span title="Total Sale">TSale: <span class="sts"> </span></span>
                        </th>
                    #end
                    <th rowspan="3">PO</th>
                    <th rowspan="3">last Po Entry</th>

                </tr>

                <tr>
                    #foreach($catalog in $catalogItemMap.entrySet())
                        #set($mt = $monitorTypeByCatalogId.get($catalog.getKey()))
                        #if($mt && $mt.name() == "FOCUSED")
                            <th colspan="3" class="monitor-focused" data-catalog-id="$catalog.getKey()" data-monitor-type="focused">$catalog.getValue().get(0).getBrand()
                        #elseif($mt && $mt.name() == "BASE")
                            <th colspan="3" class="monitor-base" data-catalog-id="$catalog.getKey()" data-monitor-type="base">$catalog.getValue().get(0).getBrand()
                        #else
                            <th colspan="3" data-catalog-id="$catalog.getKey()">$catalog.getValue().get(0).getBrand()
                        #end
                                                $catalog.getValue().get(0).getModelName()
                                                $catalog.getValue().get(0).getModelNumber()</th>
                    #end
                </tr>
                <tr>
                    #foreach($catalog in $catalogItemMap.entrySet())
                        <th>Stock</th>
                        <th>Sale</th>
                        <th>SD Stock</th> #end

                </tr>


                </thead>
                <tbody>
                    #foreach($customRetailerEntry in $customRetailers.entrySet())
                    <tr>
                        <td>$warehouseMap.get($customRetailerEntry.getValue().getWarehouseId())</td>
                        <td>$fofoIdPartnerTypeMap.get($customRetailerEntry.getKey())</td>

                        <td class="text"><span
                                title="$customRetailerEntry.getValue().getBusinessName()-$customRetailerEntry.getValue().getCode()">$customRetailerEntry.getValue().getBusinessName()</span>
                        </td>
                        <td class="text"><span
                                title="$salesHeadersMap.get($customRetailerEntry.getKey()).getTerritoryManager()">$salesHeadersMap.get($customRetailerEntry.getKey()).getTerritoryManager()</span>
                        </td>

                        #foreach($catalog in $catalogItemMap.entrySet())
                            #set($inStock=0)
                            #set($pendingIndent=0)
                            #if($inStocksMap.get($customRetailerEntry.getKey()).get($catalog.getKey()))
                                #set($inStock = $inStocksMap.get($customRetailerEntry.getKey()).get($catalog.getKey()))
                            #end
                            #if($pendingIndentMap.get($customRetailerEntry.getKey()).get($catalog.getKey()))
                                #set($pendingIndent = $pendingIndentMap.get($customRetailerEntry.getKey()).get($catalog.getKey()))
                            #end
                            #set($totalStock = $inStock + $pendingIndent)
                            <td class="instockItem" data-fofoid="$customRetailerEntry.getKey()"
                                data-catalogid="$catalog.getKey()" data-toggle="modal"
                                data-target="#inStockQtyModel">
                                $totalStock</td>

                            #if($fofoSalesMap.get($customRetailerEntry.getKey()).get($catalog.getKey()))

                                <td class="inSaleItem"
                                    data-fofoid="$customRetailerEntry.getValue().getFofoId()" data-toggle="modal"
                                    data-target="#inSaleItemModel">$fofoSalesMap.get($customRetailerEntry.getKey()).get($catalog.getKey())</td>
                            #else
                                <td>0</td> #end
                            #if($warehouseStockMap.get($customRetailerEntry.getValue().getWarehouseId()).get($catalog.getKey()))

                                <td class="warehouseStockItem"
                                    data-warehouseid="$customRetailerEntry.getValue().getWarehouseId()"
                                    data-catalogid="$customRetailerEntry.getValue().getWarehouseId()"
                                    data-toggle="modal"
                                    data-target="#warehouseStockItemModel">$warehouseStockMap.get($customRetailerEntry.getValue().getWarehouseId()).get($catalog.getKey())</td>
                            #else
                                <td>0</td> #end #end
                        <td><a class="selctItemQty" data-toggle="modal"
                               data-fofoid="$customRetailerEntry.getKey()" data-target="#selectModelItems">
                            Add to po </a></td> #if($suggestedPoEntry.get($customRetailerEntry))

                        <td><a class="podetails" data-fofoid="$customRetailerEntry.getKey()"
                               data-datetime="$suggestedPoEntry.get($customRetailerEntry.getKey())"
                               data-toggle="modal"
                               data-target="#ItemsPo">$suggestedPoEntry.get($customRetailerEntry.getKey()).format($dateTimeFormatter)</a>
                        </td>
                    #else
                        <td></td> #end

                    </tr>
                    #end

                </tbody>
            </table>
        </div>
    #else

        <div class="col-lg-6">
            <table
                    class="table table-striped table-advance table-hover partner-planning-details">
                <thead>
                <tr>
                    <th>Warehouse</th>
                    <th>Category</th>
                    <th>Partner Name</th>
                    <th>Item</th>
                    <th>Stock</th>
                    <th>Sale</th>
                    <th>Warehouse Stock</th>
                    <th>PO</th>
                    <th>last Po Entry</th>


                </tr>
                </thead>
                <tbody>
                    #foreach($keyvalue in $inStockItemMap.entrySet())
                    <tr>
                        <td>$warehouseMap.get($keyvalue.getValue().getWarehouseId())</td>
                        <td>$fofoIdPartnerTypeMap.get($keyvalue.getKey().getFofoId())</td>

                        <td>$customRetailers.get($keyvalue.getKey().getFofoId()).getBusinessName()</td>
                        <td>$keyvalue.getValue().getBrand()
                                                $keyvalue.getValue().getModelName()
                                                $keyvalue.getValue().getModelNumber()</td>
                        <td>$keyvalue.getValue().getQty()</td>
                        #if($fofoSaleItem.get($keyvalue.getKey()))
                            <td>$fofoSaleItem.get($keyvalue.getKey()).getQty()</td>
                        #else
                            <td>0</td>
                        #end

                        <td>$keyvalue.getValue().getWarehouseQty()</td>
                        <td><a class="selctItemQty" data-toggle="modal"
                               data-fofoid="$keyvalue.getValue().getFofoId()"
                               data-target="#selectModelItems"> Add to po </a></td>
                        #if($suggestedPoEntry.get($keyvalue.getKey().getFofoId()))

                            <td><a class="podetails"
                                   data-fofoid="$keyvalue.getKey().getFofoId()" data-toggle="modal"
                                   data-target="#ItemsPo"
                                   data-datetime="$suggestedPoEntry.get($keyvalue.getValue().getFofoId())">
                                $suggestedPoEntry.get($keyvalue.getKey().getFofoId()).format($dateTimeFormatter)
                            </a></td> #else
                            <td></td> #end

                    </tr>
                    #end

                </tbody>
            </table>
        </div>

    #end
</div>


<div id="inStockItemModel" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>

<div id="inStockQtyModel" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>

<div id="inSaleItemModel" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>

<div id="warehouseStockItemModel" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>


<div id="selectModelItems" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>

<div id="ItemsPo" class="modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content"></div>
    </div>
</div>
<script type="text/javascript">
    var table

    $(document).ready(function () {
        var targetArray = [];


        targetArray = Array.apply(null, Array($catalogItemMap.size())).map(function (_, i) {
            return 3 + (i * 3);
        });
        table = $('.partner-planning-details').DataTable({

            "lengthMenu": [10, 25, 50, 75, 100, 250],
            "scrollX": true,
            "pageLength": 250,
            "orderCellsTop": true,
            "fixedHeader": true,
            "fixedColumns": {
                leftColumns: 4

            },

            "columnDefs": [
                {"targets": targetArray, "orderDataType": "dom-stock-numeric", "type": "number"},
            ]

        });


        datatableSum();

        table.on('search.dt', function () {
            console.log('Currently applied global search: ' + table.search());

            datatableSum();

        });
    });

    function datatableSum() {
        let wod = [];
        let wos = [];
        let sos = [];
        let sts = [];
        table.rows({
            "search": "applied"
        }).every(function () {
            var data = this.data();

            for (let i = 4; i < data.length - 2; i = i + 3) {
                console.log("Iloop");
                console.log(data[i]);
                j = Math.floor(i / 3);
                if (wod[j] == undefined) {
                    wod[j] = 0;
                }
                if (parseInt(data[i]) > 0) {
                    wod[j]++;
                }

                if (sos[j] == undefined) {
                    sos[j] = parseInt(data[i]);
                } else {
                    sos[j] += parseInt(data[i]);

                }
            }

            for (let h = 5; h < data.length - 2; h = h + 3) {
                console.log("Hloop");
                console.log(data[h]);
                g = Math.floor(h / 3)

                if (wos[g] == undefined) {
                    wos[g] = 0;
                }
                if (parseInt(data[h]) > 0) {
                    wos[g]++;
                }

                if (sts[g] == undefined) {
                    sts[g] = parseInt(data[h]);
                } else {
                    sts[g] += parseInt(data[h]);
                }

            }

        });

        console.log(wod);
        console.log(wos);
        console.log(sos);
        console.log(sts);
        for (let m = 1; m < wod.length; m++) {
            let indexNum = m + 4;
            var stockHeader = $(`.partner-planning-details thead tr th:nth-child(${indexNum})`)
            stockHeader.find('.wod').html(wod[m]);
            stockHeader.find('.ts').html(sos[m]);
            stockHeader.find('.wos').html(wos[m]);
            stockHeader.find('.sts').html(sts[m]);
        }

    }

    /*$('.partner-planning-details').on(
            'click',
            '.instockItem',
            function() {
                var fofoId = $(this).data('fofoid');
                var catalogIds = $('.criteria-item-catalogids').val();
                console.log(catalogIds);

                doGetAjaxRequestHandler(context
                        + "/getInStockItembyFofoId?fofoId=" + fofoId
                        + "&catalogItemIds=" + catalogIds, function(response) {
                    console.log(response)
                    $('#inStockItemModel .modal-content').html(response);

                });
            });*/

    $('.partner-planning-details').on(
            'click',
            '.instockItem',
            function () {
                var fofoId = $(this).data('fofoid');
                var catalogId = $(this).data('catalogid');
                console.log(catalogId);

                doGetAjaxRequestHandler(context + "/getInStockItemQty?fofoId="
                        + fofoId + "&catalogItemId=" + catalogId, function (
                        response) {
                    console.log(response)
                    $('#inStockQtyModel .modal-content').html(response);

                });
            });

    $('.partner-planning-details').on(
            'click',
            '.inSaleItem',
            function () {
                var fofoId = $(this).data('fofoid');
                var catalogIds = $('.criteria-item-catalogids').val();
                console.log(catalogIds);

                doGetAjaxRequestHandler(context
                        + "/getSaleItembyCatalogFofoId?fofoId=" + fofoId
                        + "&catalogItemIds=" + catalogIds + "&date="
                        + startDate, function (response) {
                    console.log(response)
                    $('#inSaleItemModel .modal-content').html(response);

                });
            });

    $('.partner-planning-details').on(
            'click',
            '.warehouseStockItem',
            function () {
                var warehouseId = $(this).data('warehouseid');
                var catalogIds = $('.criteria-item-catalogids').val();
                console.log(catalogIds);

                doGetAjaxRequestHandler(context
                        + "/getWarehouseStockItem?warehouseId=" + warehouseId
                        + "&catalogItemIds=" + catalogIds,
                        function (response) {
                            console.log(response)
                            $('#warehouseStockItemModel .modal-content').html(
                                    response);

                        });
            });

    $('.partner-planning-details').on(
            'click',
            '.selctItemQty',
            function () {
                var catalogIds = $('.criteria-item-catalogids').val();
                console.log(catalogIds);
                var fofoId = $(this).data('fofoid');

                doGetAjaxRequestHandler(context
                        + "/selectItemColorByCatalog?catalogIds=" + catalogIds

                        + "&fofoId=" + fofoId, function (response) {
                    console.log(response)
                    $('#selectModelItems .modal-content').html(response);

                });
            });

    $(document).on(
            "click",
            ".submit-item-po",
            function (e) {
                var seletedIds;
                var jsonObject = {};
                var seletedIdsJson = [];
                var fofoId = $(this).data('fofoid');

                $('#select-item').find('tr').each(function () {
                    var row = $(this);

                    console.log(row);
                    if (row.find('input[type="checkbox"]').is(':checked')) {
                        var currentRow = $(this).closest("tr");

                        var itemId = currentRow.find("td:eq(1)").html();
                        var name = currentRow.find("td:eq(2)").html();
                        var quantity = currentRow.find("td:eq(3) input").val();
                        console.log(quantity)
                        if (quantity == "") {
                            alert("Select the Quantity");
                            return false;

                        }

                        seletedIds = {
                            "itemId": itemId,
                            "qty": quantity
                        }
                        seletedIdsJson.push(seletedIds)

                    }

                });

                console.log(fofoId)
                if (fofoId == null) {
                    alert("Partner ID is required");
                    return false;
                }
                if (seletedIdsJson.length === 0) {
                    alert("Atleast one Item selected");
                    return false;
                }
                console.log(seletedIdsJson);

                jsonObject['poIds'] = seletedIdsJson;
                jsonObject['fofoId'] = fofoId;
                console.log(jsonObject)
                if (confirm("Are you sure you want to create po") == true) {

                    doPostAjaxRequestWithJsonHandler(context + "/createPo",
                            JSON.stringify(jsonObject), function (response) {
                                if (response == 'true') {
                                    alert("successfully create");

                                    $("#selectModelItems").modal("hide");
                                    $("button.search-partner-stock").click();
                                }
                            });
                }

            });

    $('.partner-planning-details').on(
            'click',
            '.podetails',
            function () {
                var fofoId = $(this).data('fofoid');
                var datetime = $(this).data('datetime');

                doGetAjaxRequestHandler(context
                        + "/getSuggestedPoDetail?fofoId=" + fofoId
                        + "&datetime=" + datetime, function (response) {
                    console.log(response)
                    $('#ItemsPo .modal-content').html(response);

                });
            });


</script>