Subversion Repositories SmartDukaan

Rev

Rev 27755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26846 tejbeer 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', ".partner-po", function() {
26846 tejbeer 3
		loadCreatePo("main-content");
4
	});
5
 
27755 amit.gupta 6
	$(document).on('click', ".partner-item-detail",
26846 tejbeer 7
			function() {
8
				var fofoId = $('#fofo-users').val();
9
 
10
				var url = "/getPartnerloadContent?fofoId=" + fofoId
11
						+ "&counterSize=" + "TEN_LAC";
12
				doAjaxRequestHandler(context + url, "GET", function(response) {
13
					{
14
					}
15
 
16
					$('.partner-po-container').html(response);
17
				});
18
			});
19
 
27755 amit.gupta 20
	$(document).on("click", ".selectItemQty",
26846 tejbeer 21
			function() {
22
				var catalogId = parseInt($(this).data("catalog-id"));
23
				doGetAjaxRequestHandler(context + "/selectItemColor?catalogId="
24
						+ catalogId, function(response) {
27251 tejbeer 25
 
26846 tejbeer 26
					$('.select-item-container .modal-content').html(response);
27251 tejbeer 27
					$('#select-item-table').find('tr').each(function() {
28
						var selectRow = $(this);
29
						var selectCurrentRow = $(this).closest("tr");
30
						var itemId = selectCurrentRow.find("td:eq(1)").html();
31
						console.log(itemId)
32
						if (itemId != undefined) {
33
							$('#po-table').find('tr').each(function() {
34
								var row = $(this);
35
								var currentRow = $(this).closest("tr");
36
								var item = currentRow.find("td:eq(0)").html();
37
								if (item != undefined) {
38
									console.log(item)
39
									if (item == itemId) {
40
										selectCurrentRow.remove();
41
									}
26846 tejbeer 42
 
27251 tejbeer 43
								}
44
 
45
							});
46
						}
47
 
48
					});
26846 tejbeer 49
				});
50
 
51
			});
27754 amit.gupta 52
	$(document).on('click', ".btnDelete", function() {
26846 tejbeer 53
		console.log("Hello");
54
 
55
		$(this).closest("tr").remove();
56
 
57
	});
58
 
33715 ranu 59
    $(document).on("click", ".submit-item", function (e) {
60
        var seletedIds;
61
        var seletedIdsJson = [];
26846 tejbeer 62
 
33715 ranu 63
        // Get the current total price from the header and convert it to a number
64
        var totalPoPrice = parseFloat($(".totalPoPrice").text().replace(/[^0-9.-]+/g, "")) || 0;
26846 tejbeer 65
 
33715 ranu 66
        $('#select-item-table').find('tr').each(function () {
67
            var row = $(this);
68
            if (row.find('input[type="checkbox"]').is(':checked')) {
69
                var currentRow = $(this).closest("tr");
26846 tejbeer 70
 
33715 ranu 71
                var itemId = currentRow.find("td:eq(1)").html();
72
                var name = currentRow.find("td:eq(2)").html();
73
                var quantity = currentRow.find("td:eq(3) input").val();
74
                var itemPrice = parseFloat(currentRow.find("td:eq(4)").html());
26846 tejbeer 75
 
33715 ranu 76
                if (quantity == "") {
77
                    alert("Select the Quantity");
78
                    return false;
79
                }
26846 tejbeer 80
 
33715 ranu 81
                // Calculate total item price
82
                var totalItemPrice = itemPrice * quantity;
26846 tejbeer 83
 
33715 ranu 84
                // Add to the total PO price
85
                totalPoPrice += totalItemPrice;
26846 tejbeer 86
 
33715 ranu 87
                seletedIds = {
88
                    "itemId": itemId,
89
                    "name": name,
90
                    "qty": quantity,
91
                    "itemPrice": itemPrice
92
                }
93
                seletedIdsJson.push(seletedIds);
94
            }
95
        });
26846 tejbeer 96
 
33715 ranu 97
        console.log(seletedIdsJson);
26846 tejbeer 98
 
33715 ranu 99
        for (let i = 0; i < seletedIdsJson.length; i++) {
100
            let markup = "<tr><td>" +
101
                seletedIdsJson[i].itemId + "</td><td>" +
102
                seletedIdsJson[i].name + "</td><td>" +
103
                seletedIdsJson[i].qty + "</td><td>" +
104
                seletedIdsJson[i].itemPrice + "</td><td>" +
105
                "<button type='button' class='btnDelete'>Delete</button></td></tr>";
106
            $('#po-table > tbody:last-child').append(markup);
107
        }
26846 tejbeer 108
 
33715 ranu 109
        // Update the total price in the header
110
        updateTotalPoPrice(totalPoPrice);
26846 tejbeer 111
 
33715 ranu 112
        $("#selectItem").modal("hide");
113
    });
26846 tejbeer 114
 
33715 ranu 115
// Function to update the total price in the header
116
    function updateTotalPoPrice(newPrice) {
117
        $('.totalPoPrice').text('Total Price: ' + newPrice.toFixed(2));
118
    }
119
 
120
 
121
 
27755 amit.gupta 122
	$(document).on('click', ".confirm_po",
26846 tejbeer 123
			function() {
124
				var jsonObject = {};
125
				var poIdsJSon = [];
126
				var poIds;
127
				var fofoId = $('#fofo-users').val();
128
 
129
				$('#po-table').find('tr').each(function() {
130
					var row = $(this);
131
 
132
					console.log(row);
133
					var currentRow = $(this).closest("tr");
134
 
135
					var itemId = currentRow.find("td:eq(0)").html();
136
					var qty = currentRow.find("td:eq(2)").html();
137
 
138
					console.log(itemId);
139
					if (itemId != undefined) {
140
						poIds = {
141
							"itemId" : itemId,
142
							"qty" : qty
143
 
144
						}
145
						console.log(poIds);
146
						poIdsJSon.push(poIds);
147
					}
148
				});
149
 
150
				console.log(poIdsJSon)
151
				console.log(fofoId)
152
				if (fofoId == null) {
153
					alert("fofoId is required");
154
					return false;
155
				}
156
				if (poIdsJSon.length === 0) {
157
					alert("Atleast one Item selected");
158
					return false;
159
				}
160
 
161
				jsonObject['poIds'] = poIdsJSon;
162
				jsonObject['fofoId'] = fofoId;
163
				console.log(jsonObject)
164
 
165
				if (confirm("Are you sure you want to create po") == true) {
166
 
167
					doPostAjaxRequestWithJsonHandler(context + "/createPo",
168
							JSON.stringify(jsonObject), function(response) {
169
								if (response == 'true') {
170
									alert("successfully create");
171
 
172
									loadCreatePo("main-content");
173
								}
174
							});
175
				}
176
 
177
			});
178
 
179
});
180
 
181
function loadCreatePo(domId) {
182
	doGetAjaxRequestHandler(context + "/partnerPendingOrder",
183
			function(response) {
184
				$('#' + domId).html(response);
185
			});
186
}