Subversion Repositories SmartDukaan

Rev

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

Rev 34009 Rev 34018
Line 1... Line 1...
1
$(document).on('click', '.mk-pur-sale-ratio-panel', function () {
1
$(document).on('click', '.mk-pur-sale-ratio-panel', function () {
2
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio-panel`, function (response) {
2
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio/panel`, function (response) {
3
        $('#main-content').html(response);
3
        $('#main-content').html(response);
4
    });
4
    });
5
});
5
});
6
 
6
 
7
$(document).on('change', 'input[name="endDate"], input[name="startDate"], select[name="brand"]', function () {
7
$(document).on('change', 'input[name="endDate"], input[name="startDate"], select[name="brand"]', function () {
Line 27... Line 27...
27
    if (!supplierId) {
27
    if (!supplierId) {
28
        supplierId = 0;
28
        supplierId = 0;
29
    } else {
29
    } else {
30
        supplierId = supplierId;
30
        supplierId = supplierId;
31
    }
31
    }
32
    doGetAjaxRequestHandler(`${context}/brandSuppliers?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}`, function (response) {
32
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio/brandSuppliers?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}`, function (response) {
33
        if (response.hasOwnProperty('purchaseSaleQuantities') && response.purchaseSaleQuantities.length) {
33
        if (response.hasOwnProperty('purchaseSaleQuantities') && response.purchaseSaleQuantities.length) {
34
            createPurchaseSaleBarChart(response.purchaseSaleQuantities, startDate, endDate, brand, supplierId);
34
            createPurchaseSaleBarChart(response.purchaseSaleQuantities, startDate, endDate, brand, supplierId);
35
        }
35
        }
36
 
-
 
37
        if (response.hasOwnProperty('brandWiseSuppliers') && response.brandWiseSuppliers.length) {
36
        if (response.hasOwnProperty('brandWiseSuppliers') && response.brandWiseSuppliers.length) {
38
            $('.suppliersList').empty();
37
            $('.suppliersList').empty();
39
            $('.suppliersList').append(`<option selected disabled>Select Supplier</option>`);
38
            $('.suppliersList').append(`<option selected disabled>Select Supplier</option>`);
40
            response.brandWiseSuppliers.forEach(function (supplier) {
39
            response.brandWiseSuppliers.forEach(function (supplier) {
41
                $('.suppliersList').append(`<option value="${supplier.supplierId}">${supplier.supplierName}</option>`);
40
                $('.suppliersList').append(`<option value="${supplier.supplierId}">${supplier.supplierName}</option>`);
42
            });
41
            });
43
        }
42
        }
44
 
-
 
45
    });
43
    });
46
});
44
});
47
 
45
 
48
$(document).on('change', 'select[name="supplier"]', function () {
46
$(document).on('change', 'select[name="supplier"]', function () {
49
    let startDate = $('input[name="startDate"]').val();
47
    let startDate = $('input[name="startDate"]').val();
50
    let endDate = $('input[name="endDate"]').val();
48
    let endDate = $('input[name="endDate"]').val();
51
    let brand = $('select[name="brand"]').val();
49
    let brand = $('select[name="brand"]').val();
52
    let supplierId = $(this).val();
50
    let supplierId = $(this).val();
53
    doGetAjaxRequestHandler(`${context}/pur-sale-quantity?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}`, function (response) {
51
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio/data?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}`, function (response) {
54
        if (response.length) {
52
        if (response.length) {
55
            createPurchaseSaleBarChart(response, startDate, endDate, brand, supplierId);
53
            createPurchaseSaleBarChart(response, startDate, endDate, brand, supplierId);
56
        }
54
        }
57
    });
55
    });
58
 
-
 
59
 
-
 
60
});
56
});
61
 
57
 
62
let salesChart, catalogChart;
58
let salesChart, catalogChart;
63
 
59
 
64
Chart.register(ChartDataLabels);
60
Chart.register(ChartDataLabels);
Line 166... Line 162...
166
    });
162
    });
167
 
163
 
168
}
164
}
169
 
165
 
170
function catalogPurchaseSaleChart(startDate, endDate, brand, supplierId, label) {
166
function catalogPurchaseSaleChart(startDate, endDate, brand, supplierId, label) {
171
    //log all parameters
-
 
172
    doGetAjaxRequestHandler(`${context}/catalog-pur-sale-quantity?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}&label=${label}`, function (response) {
167
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio/catalog-quantity?startDate=${startDate}&endDate=${endDate}&brand=${brand}&supplierId=${supplierId}&label=${label}`, function (response) {
173
        createCatalogPurchaseSaleBarChart(response);
168
        createCatalogPurchaseSaleBarChart(response, startDate, endDate, supplierId);
174
    });
169
    });
175
}
170
}
176
 
171
 
-
 
172
function getCatalogAgeDetail(startDate, endDate, supplierId, label) {
-
 
173
    // /catalog-age-detail
-
 
174
    let modelNumber = label;
-
 
175
    doGetAjaxRequestHandler(`${context}/pur-sale-ratio/catalog-age-detail?startDate=${startDate}&endDate=${endDate}&modelNumber=${modelNumber}&supplierId=${supplierId}`, function (response) {
-
 
176
        $('#catalog-age-div #catalogModalBody').html(response);
-
 
177
        $('#catalog-age-div').modal('show');
-
 
178
    });
-
 
179
}
-
 
180
 
177
function createCatalogPurchaseSaleBarChart(response) {
181
function createCatalogPurchaseSaleBarChart(response, startDate, endDate, supplierId) {
178
    let labels = [], totalQuantities = [], soldQuantities = [];
182
    let labels = [], totalQuantities = [], soldQuantities = [];
179
    let filterResponse = response.filter(res => res.sale !== res.purchase);
183
    let filterResponse = response.filter(res => res.sale !== res.purchase);
180
    labels = filterResponse.map(sale => sale.model);
184
    labels = filterResponse.map(sale => sale.model);
181
    totalQuantities = filterResponse.map(sale => sale.purchase);
185
    totalQuantities = filterResponse.map(sale => sale.purchase);
182
    soldQuantities = filterResponse.map(sale => sale.sale);
186
    soldQuantities = filterResponse.map(sale => sale.sale);
Line 276... Line 280...
276
                    },
280
                    },
277
                    align: 'end', // Place labels at the center of the bars
281
                    align: 'end', // Place labels at the center of the bars
278
                    anchor: 'center', // Align labels to the center of each bar pair
282
                    anchor: 'center', // Align labels to the center of each bar pair
279
                    offset: 5, // Adjust positioning for better visibility if needed
283
                    offset: 5, // Adjust positioning for better visibility if needed
280
                },
284
                },
-
 
285
            }, onClick: function (event, activeElements) {
-
 
286
                if (activeElements.length > 0) {
-
 
287
                    const element = activeElements[0]; // Get the clicked element
-
 
288
                    const datasetIndex = element.datasetIndex; // Get the dataset (Sale or Purchase)
-
 
289
                    const dataIndex = element.index; // Get the index of the clicked bar
-
 
290
                    const label = this.data.labels[dataIndex]; // Get the label for the clicked bar
-
 
291
                    const value = this.data.datasets[datasetIndex].data[dataIndex]; // Get the value of the clicked bar
-
 
292
                    getCatalogAgeDetail(startDate, endDate, supplierId, label);
-
 
293
                }
281
            },
294
            },
282
            indexAxis: 'y',
295
            indexAxis: 'y',
283
            scales: {
296
            scales: {
284
                x: {
297
                x: {
285
                    beginAtZero: true,
298
                    beginAtZero: true,