Subversion Repositories SmartDukaan

Rev

Rev 28474 | Rev 28476 | Go to most recent revision | 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>



<div class="row">


        #if(!$inStocksMap.isEmpty())
        <div class="col-lg-8">
                <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> #foreach($catalog in
                                        $catalogItemMap.entrySet())
                                        <th colspan="3">WOD : <span class="wod"></span>, WOS: <span
                                                class="wos"></span>
                                        </th> #end
                                        <th rowspan="3">PO</th>
                                        <th rowspan="3">last Po Entry</th>

                                </tr>

                                <tr>
                                        #foreach($catalog in $catalogItemMap.entrySet())
                                        <th colspan="3">$catalog.getValue().get(0).getBrand()
                                                $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($keyvalue in $customRetailers.entrySet())
                                <tr>
                                        <td>$warehouseMap.get($keyvalue.getValue().getWarehouseId())</td>
                                        <td>$fofoIdPartnerTypeMap.get($keyvalue.getKey())</td>

                                        <td>$customRetailers.get($keyvalue.getKey()).getBusinessName()</td>

                                        #foreach($catalog in $catalogItemMap.entrySet())
                                        #if($inStocksMap.get($keyvalue.getKey()).get($catalog.getKey()))
                                        <td class="instockItem" data-fofoid="$keyvalue.getKey()"
                                                data-toggle="modal" data-target="#inStockItemModel">$inStocksMap.get($keyvalue.getKey()).get($catalog.getKey())</td>
                                        #else
                                        <td>0</td> #end
                                        #if($fofoSalesMap.get($keyvalue.getKey()).get($catalog.getKey()))

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

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

                                        <td><a class="podetails" data-fofoid="$keyvalue.getKey()"
                                                data-datetime="$suggestedPoEntry.get($keyvalue.getKey())"
                                                data-toggle="modal" data-target="#ItemsPo">$suggestedPoEntry.get($keyvalue.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="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() {

                table = $('.partner-planning-details').DataTable({

                        "lengthMenu" : [ 10, 25, 50, 75, 100, 250 ],
                        "pageLength" : 250,
                        "orderCellsTop" : true,
                        "fixedHeader" : true
                });

                datatableSum()

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

                        datatableSum();

                });
        });

        function datatableSum() {
                let wod = [];
                let wos = [];
                table.rows({
                        "search" : "applied"
                }).every(function() {
                        var data = this.data();
                        for (let i = 3; i < data.length - 2; i = i + 3) {
                                j = i / 3
                                if (wod[j] == undefined) {
                                        wod[j] = 0;
                                }
                                if (parseInt(data[i]) > 0) {
                                        wod[j]++;
                                }
                        }

                        for (let h = 3 h < data.length - 2; h = h + 3) {
                                g = h / 3
                                if (wos[g] == undefined) {
                                        wos[g] = parseInt(data[h]);
                                } else {
                                        wos[g] += parseInt(data[h]);
                                }
                        }

                });

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

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

        }

        $('.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',
                        '.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("fofoId 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>