Subversion Repositories SmartDukaan

Rev

Rev 22350 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2749 vikas 1
var orderTable;
2
var cartTable;
20199 amit.gupta 3
var RETURN = RETURN || {}
3096 mandeep.dh 4
 
3090 mandeep.dh 5
function loadUserPane(domId, userId) {
3228 mandeep.dh 6
    $.ajax({
7
        type : "GET",
8
        url : "/crm/user-info?userId=" + userId,
9
        success : function(response) {
10
            $('#' + domId).html(response);
11
        }
12
    });
2674 vikas 13
}
18884 amit.gupta 14
aoColumns = {
15
	'return':
18887 amit.gupta 16
	[  { "sWidth": "8%" },
17
	   { "sWidth": "20%" },
18884 amit.gupta 18
	   { "sWidth": "5%" },
19
	   { "sWidth": "10%" },
20
	   { "sWidth": "15%" },
21
	   { "sWidth": "10%" },
18887 amit.gupta 22
	   { "sWidth": "12%" },
23
	   { "sWidth": "10%" },
24
	   { "sWidth": "10%" }],
18884 amit.gupta 25
 
26
 
27
	'delayed':
18887 amit.gupta 28
	[  { "sWidth": "8%" },
18884 amit.gupta 29
	   { "sWidth": "25%" },
30
	   { "sWidth": "5%" },
31
	   { "sWidth": "10%" },
32
	   { "sWidth": "15%" },
33
	   { "sWidth": "8%" },
34
	   { "sWidth": "10%" },
35
	   { "sWidth": "9%" },
18886 amit.gupta 36
	   { "sWidth": "12%" }],
18884 amit.gupta 37
	'codverification':
38
	[  { "sWidth": "8%" },
39
	   { "sWidth": "40%" },
40
	   { "sWidth": "5%" },
41
	   { "sWidth": "10%" },
42
	   { "sWidth": "17%" },
43
	   { "sWidth": "10%" },
18888 amit.gupta 44
	   { "sWidth": "10%" },
45
	   {"bVisible": false}
18886 amit.gupta 46
	],
18884 amit.gupta 47
	'storepickup':
48
	[  { "sWidth": "6%" },
49
	   { "sWidth": "25%" },
50
	   { "sWidth": "5%" },
51
	   { "sWidth": "8%" },
52
	   { "sWidth": "15%" },
53
	   { "sWidth": "8%" },
54
	   { "sWidth": "10%" },
55
	   { "sWidth": "12%" },
56
	   { "sWidth": "4%" },
18886 amit.gupta 57
	   { "sWidth": "7%" }]
18884 amit.gupta 58
};
3228 mandeep.dh 59
function loadOrderPane(domId, userId, orderId) {
60
    $.ajax({
61
        type : "GET",
62
        url : "/crm/user-orders?userId=" + userId,
63
        success : function(response) {
64
            $('#' + domId).html(response);
3499 mandeep.dh 65
            loadOrderInfo("bottom-infopane", orderId);
3228 mandeep.dh 66
            orderTable = $('#user-orders').dataTable({
67
                "aaSorting" : [ [ 1, 'desc' ] ],
4241 anupam.sin 68
              "bAutoWidth": false,
18583 amit.gupta 69
              "aoColumns" : [{ "sWidth": "8%" },//transaction id
70
                             { "sWidth": "7%" },//item desc
4241 anupam.sin 71
                             { "sWidth": "30%" },//item desc
18583 amit.gupta 72
                             { "sWidth": "4%" },//item desc
18308 amit.gupta 73
                             { "sWidth": "14%" },//created
4241 anupam.sin 74
                             { "sWidth": "8%" },//amount
75
                             { "sWidth": "17%" },//status
18308 amit.gupta 76
                             { "sWidth": "11%" }],//mobile no.
3996 mandeep.dh 77
                "fnDrawCallback": function() { truncateText(125); },
4605 anupam.sin 78
                "iDisplayLength" : 10,
3339 mandeep.dh 79
                "sDom" : 'T<"clear">lfrtip',
80
                "oTableTools" : {
81
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
82
                },
3228 mandeep.dh 83
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
84
            });
85
        }
86
    });
2674 vikas 87
}
88
 
6111 anupam.sin 89
function loadRechargeOrderPane(domId, userId, rechargeOrderId) {
90
    $.ajax({
91
        type : "GET",
92
        url : "/crm/recharge-orders?userId=" + userId,
93
        success : function(response) {
94
            $('#' + domId).html(response);
95
            loadRechargeOrderInfo("bottom-infopane", rechargeOrderId);
96
            orderTable = $('#recharge-orders').dataTable({
97
                "aaSorting" : [ [ 1, 'desc' ] ],
98
              "bAutoWidth": false,
99
              "aoColumns" : [{ "sWidth": "16%" },//recharge order id
100
                             { "sWidth": "30%" },//desc
101
                             { "sWidth": "16%" },//created
102
                             { "sWidth": "8%" },//amount
103
                             { "sWidth": "17%" },//status
6982 anupam.sin 104
                             { "sWidth": "13%" }],//mobile no.
105
                "fnDrawCallback": function() { truncateText(180); },
6111 anupam.sin 106
                "iDisplayLength" : 10,
107
                "sDom" : 'T<"clear">lfrtip',
108
                "oTableTools" : {
109
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
110
                },
111
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
112
            });
113
        }
114
    });
115
}
116
 
117
function loadRechargeOrderInfo(domId, rechargeOrderId) {
118
    $.ajax({
119
        type : "GET",
120
        url : "/crm/recharge-order-info?rechargeOrderId=" + rechargeOrderId,
121
        success : function(response) {
122
            $('#' + domId).html(response);
123
 
124
            var trId = 'order-row-' + rechargeOrderId;
125
            if (orderTable != null) {
126
                for ( var index in orderTable.fnGetNodes()) {
127
                    var item = orderTable.fnGetNodes()[index];
128
                    if ($(item).attr('id') == trId) {
129
                        orderTable.fnDisplayRow(item);
130
                        break;
131
                    }
132
                }
133
            }
134
 
135
            $('#recharge-orders tr').removeClass('selected');
6153 anupam.sin 136
            $('#order-row-' + rechargeOrderId).addClass('selected');
6111 anupam.sin 137
        }
138
    });
139
}
140
 
3228 mandeep.dh 141
function loadCartPane(domId, userId, cartId) {
142
    $.ajax({
143
        type : "GET",
144
        url : "/crm/user-cart?userId=" + userId + "&cartId=" + cartId,
145
        success : function(response) {
146
            $('#' + domId).html(response);
147
            cartTable = $('#user-cart').dataTable({
148
                "aaSorting" : [ [ 1, 'desc' ] ],
4241 anupam.sin 149
              "bAutoWidth": false,
150
              "aoColumns" : [{ "sWidth": "32%" },//name
151
                             { "sWidth": "9%" },//quantity
152
                             { "sWidth": "16%" },//actual price
153
                             { "sWidth": "16%" },//discounted price
154
                             { "sWidth": "9%" },//estimate
155
                             { "sWidth": "18%" }],//created on
3228 mandeep.dh 156
                "iDisplayLength" : 10,
3339 mandeep.dh 157
                "sDom" : 'T<"clear">lfrtip',
158
                "oTableTools" : {
159
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
160
                },
3228 mandeep.dh 161
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
162
            });
163
        }
164
    });
2714 vikas 165
}
166
 
3499 mandeep.dh 167
function loadOrderInfo(domId, orderId) {
3228 mandeep.dh 168
    $.ajax({
169
        type : "GET",
3499 mandeep.dh 170
        url : "/crm/user-order-info?orderId=" + orderId,
3228 mandeep.dh 171
        success : function(response) {
172
            $('#' + domId).html(response);
3220 mandeep.dh 173
 
3228 mandeep.dh 174
            var trId = 'order-row-' + orderId;
175
            if (orderTable != null) {
176
                for ( var index in orderTable.fnGetNodes()) {
177
                    var item = orderTable.fnGetNodes()[index];
178
                    if ($(item).attr('id') == trId) {
179
                        orderTable.fnDisplayRow(item);
180
                        break;
181
                    }
182
                }
183
            }
3220 mandeep.dh 184
 
7572 anupam.sin 185
            $('#user-orders tr, #orders-without-user tr').removeClass('selected');
3228 mandeep.dh 186
            $('#order-row-' + orderId).addClass('selected');
187
        }
188
    });
2714 vikas 189
}
190
 
3228 mandeep.dh 191
function loadLineInfo(domId, userId, itemId) {
192
    $.ajax({
193
        type : "GET",
194
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
195
        success : function(response) {
196
            $('#' + domId).html(response);
197
            $('#user-cart tr').removeClass('selected');
198
            $('#cart-row-' + itemId).addClass('selected');
199
        }
200
    });
2830 vikas 201
}
202
 
3228 mandeep.dh 203
function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
204
    $.ajax({
205
        type : "GET",
3405 mandeep.dh 206
        url : "/crm/tickets/" + ticketId + "/edit",
3228 mandeep.dh 207
        success : function(response) {
208
            $('#' + domId).html(response);
3206 mandeep.dh 209
 
3228 mandeep.dh 210
            var trId = 'ticket-row-' + ticketId;
211
            if (ticketTable != null) {
212
                for ( var index in ticketTable.fnGetNodes()) {
213
                    var item = ticketTable.fnGetNodes()[index];
214
                    if ($(item).attr('id') == trId) {
215
                        ticketTable.fnDisplayRow(item);
216
                        break;
217
                    }
218
                }
219
            }
3206 mandeep.dh 220
 
3228 mandeep.dh 221
            $('#tickets tr').removeClass('selected');
222
            $('#' + trId).addClass('selected');
223
 
224
            // For tickets accessed from activity page
225
            if (activityId != null) {
3339 mandeep.dh 226
                $('#activity tr').removeClass('selected');
3228 mandeep.dh 227
                $('#activity-row-' + activityId).addClass('selected');
228
            }
18348 amit.gupta 229
            $('#tr-table').dataTable({
230
            	"bAutoWidth": false,
231
          		"bLengthChange": false,
232
	            "bFilter": false,
233
            	"aoColumns" : [{ "sWidth": "8%" },
234
                	           { "sWidth": "8%" },
235
                    	       { "sWidth": "8%" },
19088 manish.sha 236
                        	   { "sWidth": "30%" },
19087 manish.sha 237
                        	   { "sWidth": "10%" },
238
                        	   { "sWidth": "8%" },
19088 manish.sha 239
                        	   { "sWidth": "14%" },
240
                        	   { "sWidth": "14%" }],
18348 amit.gupta 241
 
242
                "iDisplayLength" : 10,
243
                //"fnDrawCallback": function() {truncateText(100);},
18855 amit.gupta 244
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
18348 amit.gupta 245
            });
20021 aman.kumar 246
            if(typeof ordertype!='undefined'){
3546 mandeep.dh 247
            $('#order-table').dataTable({
18884 amit.gupta 248
 
18348 amit.gupta 249
                //"aaSorting" : [ [ 2, 'desc' ] ],
18345 amit.gupta 250
	            "bAutoWidth": false,
18886 amit.gupta 251
	            "aoColumns" : aoColumns[ordertype],
18345 amit.gupta 252
                //"iDisplayLength" : 10,
18348 amit.gupta 253
                "fnDrawCallback": function() {
254
	                $('.mk_transaction').click(function(){
255
 
256
	                });
257
                },
18855 amit.gupta 258
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
18345 amit.gupta 259
            });
3228 mandeep.dh 260
        }
20021 aman.kumar 261
        }
3228 mandeep.dh 262
    });
3090 mandeep.dh 263
}
264
 
3405 mandeep.dh 265
function createTicketDataTable(domId) {
3499 mandeep.dh 266
    var ticketsTable = $('#' + domId).dataTable({
4142 mandeep.dh 267
         "aaSorting" : [ [ 3, 'asc' ] ],
4241 anupam.sin 268
         "bAutoWidth": false,
269
         "aoColumns" : [{ "sWidth": "9%" },//ticket id
270
                        { "sWidth": "16%" },//customer id or Description when orderId is set
271
                        { "sWidth": "21%" },//category id
272
                        { "sWidth": "13%" },//date created
273
                        { "sWidth": "13%" },//date closed
274
                        { "sWidth": "12%" },//assignee
275
                        { "sWidth": "8%" },//status
276
                        { "sWidth": "8%" }],//priority
3546 mandeep.dh 277
        "fnDrawCallback": function() {truncateText(85);},
4605 anupam.sin 278
        "iDisplayLength" : 10,
3339 mandeep.dh 279
        "sDom" : 'T<"clear">lfrtip',
280
        "oTableTools" : {
5203 amar.kumar 281
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
282
            "sExtends": "csv",
283
            "sFieldSeperator": "`"
3339 mandeep.dh 284
        },
285
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
286
    });
3499 mandeep.dh 287
 
288
    return ticketsTable;
3339 mandeep.dh 289
}
290
 
4241 anupam.sin 291
function loadActivityDescription(domId, aActivityId) {
5521 amar.kumar 292
	if($(aActivityId).attr('isRead')=="true") {
293
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + '</pre>');
294
	} else {
295
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + 
296
				'</pre><br/><input type="button" value="Mark as read" activityid="'+ $(aActivityId).attr('activityid') +'" id="mark-as-read">');
297
	}
4241 anupam.sin 298
    $('#activity-table tr').removeClass('selected');
299
    $(aActivityId).parent().parent().addClass('selected');
300
}
301
 
3422 mandeep.dh 302
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 303
    $.ajax({
304
        type : "GET",
3422 mandeep.dh 305
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 306
        success : function(response) {
307
            $('#' + domId).html(response);
3339 mandeep.dh 308
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 309
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 310
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 311
        }
312
    });
3090 mandeep.dh 313
}
314
 
3405 mandeep.dh 315
function createActivityDataTable(domId) {
3499 mandeep.dh 316
    var activityTable = $('#' + domId).dataTable({
3339 mandeep.dh 317
        "aaSorting" : [ [ 4, 'desc' ] ],
4241 anupam.sin 318
     "bAutoWidth": false,
5203 amar.kumar 319
      "aoColumns" : [{ "sWidth": "7%" },//id
320
                     { "sWidth": "18%" },//activity type
321
                     { "sWidth": "11%" },//description
322
                     { "sWidth": "11%" },//timestamp
4241 anupam.sin 323
                     { "sWidth": "12%" },//creator
5203 amar.kumar 324
                     { "sWidth": "6%" },//customer id
325
                     { "sWidth": "7%" },//ticket id
326
                     { "sWidth": "7%" },//ticket status
327
                     { "sWidth": "12%" },//category
328
                     { "sWidth": "9%" }],//contact number
4605 anupam.sin 329
        "iDisplayLength" : 10,
3339 mandeep.dh 330
        "sDom" : 'T<"clear">lfrtip',
3546 mandeep.dh 331
        "fnDrawCallback": function() {truncateText(95);},
3339 mandeep.dh 332
        "oTableTools" : {
5203 amar.kumar 333
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
334
            "sExtends": "csv",
335
            "sFieldSeperator": "`"
3339 mandeep.dh 336
        },
337
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
338
    });
3499 mandeep.dh 339
 
340
    return activityTable;
3339 mandeep.dh 341
}
342
 
4793 amar.kumar 343
function loadAgentsInfo(domId) {
344
	$.ajax({
345
		type    : "GET",
346
		url	    : "/crm/agent",
347
		success : function(response) {
348
			$('#' + domId).html(response);
349
 
350
			var agentTable = $('#agents').dataTable({
351
                "aaSorting" : [ [ 1, 'asc' ] ],
352
                "bAutoWidth": false,
353
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 354
                               { "sWidth": "25%" },//Agent Name
355
                               { "sWidth": "30%" },//Email ID
356
                               { "sWidth": "20%" },//Role
4793 amar.kumar 357
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
358
                "iDisplayLength" : 10,
359
                "sDom" : 'T<"clear">lfrtip',
360
                "oTableTools" : {
361
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
362
                },
363
            });
364
		}
365
	});
366
}
367
 
5909 amar.kumar 368
function loadAllOpenTickets(domId) {
369
	$.ajax({
370
		type    : "GET",
371
		url	    : "/crm/tickets!getAllOpenTickets",
372
		success : function(response) {
373
			$('#' + domId).html(response);
374
 
375
			var agentTable = $('#open-tickets').dataTable({
376
                "aaSorting" : [ [ 1, 'asc' ] ],
377
                "bAutoWidth": true,
378
                "iDisplayLength" : 25,
379
                "sDom" : 'T<"clear">lfrtip',
380
                "oTableTools" : {
381
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
382
                },
383
            });
384
		}
385
	});
386
}
387
 
3405 mandeep.dh 388
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 389
    $.ajax({
390
        type : "GET",
3339 mandeep.dh 391
        url : "/crm/tickets/new",
3405 mandeep.dh 392
        data : params,
3339 mandeep.dh 393
        success : function(response) {
394
            $('#' + domId).html(response);
395
        }
396
    });
397
}
398
 
3405 mandeep.dh 399
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 400
    $.ajax({
401
        type : "GET",
402
        url : "/crm/activity/new",
3405 mandeep.dh 403
        data : params,
3339 mandeep.dh 404
        success : function(response) {
405
            $('#' + domId).html(response);
406
        }
407
    });
408
}
409
 
3090 mandeep.dh 410
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 411
    $.ajax({
4782 mandeep.dh 412
        type : "POST",
413
        url : "/crm/tickets!update?id=" + ticketId,
414
        data : params,
3228 mandeep.dh 415
        success : function(response) {
3339 mandeep.dh 416
            var ticketTable = $('table[id$="tickets"]');
417
            if (ticketTable.length == 1) {
418
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
419
                var responseObj = jQuery(response);
3546 mandeep.dh 420
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 421
                responseObj.find('#ticket-row-' + ticketId).children().each(
422
                        function(i, item) {
423
                            var th = responseObj.find('th').eq(i);
424
                            if (th.text() == "Ticket Id") {
425
                                return;
426
                            }
427
 
428
                            var thOld = ticketTable.find('th').filter(
429
                                    function(index) {
430
                                        if ($(this).text() == th.text()) {
431
                                            return true;
432
                                        }
433
 
434
                                        return false;
435
                                    });
436
 
4249 anupam.sin 437
                            if ($(thOld).length != 0) {
3339 mandeep.dh 438
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
439
                            }
440
                        });
441
 
3546 mandeep.dh 442
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 443
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 444
 
445
                var alertString = jQuery.trim(actionMessages);
446
                if (alertString != '') {
447
                    alert(alertString);
448
                }
3339 mandeep.dh 449
            }
450
            else {
451
                loadTicketInfo("bottom-infopane", ticketId, null, null);
452
            }
453
 
3499 mandeep.dh 454
            truncateText(85);
3339 mandeep.dh 455
        }
456
    });
457
}
458
 
22350 ashik.ali 459
function updateAddress(userId){
460
	console.log("updateAddress called")
461
	var line1 = $("#line1").val();
462
	var line2 = $("#line2").val();
463
	var city = $("#city").val();
464
	var pinCode = $("#pinCode").val();
465
	var state = $("#state").val();
466
 
467
	params = {id:userId, line1:line1, line2:line2, city:city, pinCode:pinCode, state:state}
468
 
469
	console.log("params "+JSON.stringify(params));
470
	$.ajax({
471
        type : "POST",
472
        url : "/crm/user-info!updateAddress",
473
        data : params,
474
        success : function(response) {
475
        	alert("Address has updated.");
476
        	$('#infopane').html(response);
477
        },
478
        error : function() {
479
			alert("Unable to update address");
480
		}
481
    });
482
}
483
 
3090 mandeep.dh 484
function createTicket(domId, params) {
3228 mandeep.dh 485
    $.ajax({
486
        type : "POST",
3339 mandeep.dh 487
        url : "/crm/tickets",
3228 mandeep.dh 488
        data : params,
489
        success : function(response) {
490
            $('#' + domId).html(response);
3405 mandeep.dh 491
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 492
        }
493
    });
3090 mandeep.dh 494
}
495
 
4793 amar.kumar 496
function createAgent(params, managerId){
497
	$.ajax({
498
		type : "POST",
499
		url : "/crm/agent!createAgent?managerId="+managerId,
500
		data : params,
501
		success : function(response) {
502
			alert("Agent created with the specified information");
503
			$.colorbox.close();
504
			$('#infopane').html(response);
505
			var agentTable = $('#agents').dataTable({
506
                "aaSorting" : [ [ 1, 'asc' ] ],
507
                "bAutoWidth": false,
508
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 509
                               { "sWidth": "25%" },//Agent Name
510
                               { "sWidth": "30%" },//Email ID
511
                               { "sWidth": "20%" },//Role
4793 amar.kumar 512
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
513
                "iDisplayLength" : 10,
514
                "sDom" : 'T<"clear">lfrtip',
515
                "oTableTools" : {
516
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
517
                },
518
            });
519
		}
520
	});
521
}
522
 
5168 amar.kumar 523
function changeAgentRole(params){
524
	$.ajax({
525
		type : "POST",
526
		url : "/crm/agent!changeAgentRole",
527
		data : params,
528
		success : function(response) {
529
			alert("Agent role changed");
530
			$.colorbox.close();
531
			$('#infopane').html(response);
532
			var agentTable = $('#agents').dataTable({
533
                "aaSorting" : [ [ 1, 'asc' ] ],
534
                "bAutoWidth": false,
535
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 536
                               { "sWidth": "25%" },//Agent Name
537
                               { "sWidth": "30%" },//Email ID
538
                               { "sWidth": "20%" },//Role
5168 amar.kumar 539
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
540
                "iDisplayLength" : 10,
541
                "sDom" : 'T<"clear">lfrtip',
542
                "oTableTools" : {
543
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
544
                },
545
            });
546
		}
547
	});
548
}
549
 
3090 mandeep.dh 550
function createActivity(domId, params) {
3228 mandeep.dh 551
    $.ajax({
552
        type : "POST",
3339 mandeep.dh 553
        url : "/crm/activity",
3228 mandeep.dh 554
        data : params,
555
        success : function(response) {
556
            $('#' + domId).html(response);
3405 mandeep.dh 557
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 558
        }
559
    });
3106 mandeep.dh 560
}
561
 
562
function goToHomePage() {
3228 mandeep.dh 563
    document.location.href = "/crm";
3106 mandeep.dh 564
}
565
 
3422 mandeep.dh 566
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 567
    $.ajax({
568
        type : "GET",
3234 mandeep.dh 569
        url : getURL,
3228 mandeep.dh 570
        success : function(response) {
571
            $('#' + domId).html(response);
3405 mandeep.dh 572
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 573
            if (ticketId != null) {
574
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
575
                ticketTable.css('table-layout', 'fixed');
576
            }
3228 mandeep.dh 577
        }
578
    });
3106 mandeep.dh 579
}
5225 amar.kumar 580
function changeActivityFormValidCriteria(commonDescription) {
581
	if(commonDescription == "") {
582
		$('#description').addClass('required');
583
	} else {
584
		$('#description').removeClass('required');
585
	}
586
}
3137 mandeep.dh 587
 
3422 mandeep.dh 588
function processActivityTypeChange(activityType) {
5203 amar.kumar 589
	if(activityType != "RECEIVED_CALL_FROM_CUSTOMER") {
590
		$('select#common-activity-desc').hide();
5224 amar.kumar 591
		$('#description').addClass('required');
5203 amar.kumar 592
	} else {
593
		$('select#common-activity-desc').show();
594
	}
3269 mandeep.dh 595
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 596
        $.colorbox({
597
            inline : true,
3519 mandeep.dh 598
            width : "775px",
599
            height : "445px",
3228 mandeep.dh 600
            href : "div#mail-div",
601
            onClosed : function() {
3519 mandeep.dh 602
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 603
                $("div#mail-div").hide();
604
                $('select#activity-type').val('OTHER');
605
            }
606
        });
3206 mandeep.dh 607
 
3228 mandeep.dh 608
        $("div#mail-div").show();
3701 mandeep.dh 609
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 610
    }
4020 mandeep.dh 611
    else if (activityType == "ESCALATE_TICKET") {
612
        $.colorbox({
613
            inline : true,
614
            width : "675px",
18308 amit.gupta 615
            height : "560px",
4020 mandeep.dh 616
            href : "div#escalation-div",
617
            onClosed : function() {
618
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
619
                $("div#escalation-div").hide();
620
                $('select#activity-type').val('OTHER');
621
            }
622
        });
623
 
624
        $("div#escalation-div").show();
625
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
626
    }
3206 mandeep.dh 627
}
628
 
629
function processInputFormSubmit() {
3228 mandeep.dh 630
    $.ajax({
631
        type : "POST",
632
        url : "/crm/",
633
        success : function(response) {
634
            $.html(response);
3405 mandeep.dh 635
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 636
        }
637
    });
3339 mandeep.dh 638
}
639
 
640
function listActivities(domId, params) {
641
    $.ajax({
642
        type : "GET",
643
        url : "/crm/activity",
644
        data : params,
645
        success : function(response) {
646
            $('#' + domId).html(response);
3405 mandeep.dh 647
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 648
        }
649
    });
650
}
651
 
18345 amit.gupta 652
function truncateText(widthSize, jqueryContainer) {
653
	if(typeof jqueryContainer!="undefined"){
654
	    jqueryContainer.find(".truncated-text").each(function() {
655
	    	$(this).truncate({
656
	            width : $(this).attr('truncatedTextWidth'),
657
	            addtitle : true
658
	        });
659
		})
660
	}else {
661
	    $(".truncated-text").each(function() {
662
	    	$(this).truncate({
663
	            width : $(this).attr('truncatedTextWidth'),
664
	            addtitle : true
665
	        });
666
		})
667
	}
3339 mandeep.dh 668
}
3390 mandeep.dh 669
 
670
function markAsRead(activityId) {
671
    $.ajax({
672
        type : "POST",
673
        url : "/crm/activity!markAsRead?activityId=" + activityId,
674
        success: function(response) {
675
            listActivities('infopane', "creatorId=1");
676
        }
677
    });
678
}
3397 mandeep.dh 679
 
680
function loadAdvancedSearchBox() {
681
    $.colorbox({
682
        inline : true,
683
        width : "535px",
684
        height : "465px",
685
        href : "form#search",
686
        onClosed : function() {
687
            $("form#search").hide();
688
        }
689
    });
690
 
691
    $("form#search").show();
692
}
693
 
694
function processSearchEntityChange(searchEntity) {
695
    if (searchEntity == "Tickets") {
696
        $("#assignee").show();
697
        $("#creator").hide();
4142 mandeep.dh 698
        $("tr#activityTypes").hide();
3397 mandeep.dh 699
    }
700
    else if (searchEntity == "Activities") {
701
        $("#assignee").hide();
702
        $("#creator").show();
4142 mandeep.dh 703
        $("tr#activityTypes").show();
3397 mandeep.dh 704
    }
705
}
3499 mandeep.dh 706
 
707
function increaseTrustLevel(domId, userId, trustLevelDelta) {
708
    $.ajax({
709
        type : "PUT",
710
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
711
        success : function(response) {
712
            $('#' + domId).html(response);
713
        }
714
    });
715
}
716
 
11890 kshitij.so 717
function addPrivateDealUser(domId, userId) {
718
    $.ajax({
719
        type : "PUT",
720
        url : "/crm/user-info!addPrivateDealUser?userId=" + userId,
721
        success : function(response) {
722
            $('#' + domId).html(response);
723
        }
724
    });
725
}
726
 
727
function changePrivateDealUserStatus(domId, userId, state) {
728
    $.ajax({
729
        type : "PUT",
730
        url : "/crm/user-info!changeStatusOfPrivateDealUser?userId=" + userId+ "&isPrivateDealUserActive=" + state,
731
        success : function(response) {
732
            $('#' + domId).html(response);
733
        }
734
    });
735
}
736
 
737
function resetPasswordForPrivateDealUser(domId, userId) {
738
    $.ajax({
739
        type : "PUT",
740
        url : "/crm/user-info!resetPrivateDealUserPassword?userId=" + userId,
741
        success : function(response) {
742
            $('#' + domId).html(response);
743
        },
744
    	error : function() {
745
    		alert("Unable to reset password.");
746
    	}
747
    });
748
}
749
 
19072 manish.sha 750
function displayCancelOrderPopUp(type) {
4241 anupam.sin 751
    	$.colorbox({
752
            inline : true,
753
            width : "650px",
4314 anupam.sin 754
            height : "550px",
4689 anupam.sin 755
            href : "div#cancel-div",
4241 anupam.sin 756
            onClosed : function() {
4689 anupam.sin 757
                CKEDITOR.instances['cancel-body'].destroy(false);
19072 manish.sha 758
                $("div#cancel-div").attr('cancelType','');
4689 anupam.sin 759
                $("div#cancel-div").hide();
4241 anupam.sin 760
            }
761
        });
19072 manish.sha 762
    	$("div#cancel-div").attr('cancelType',type);
4689 anupam.sin 763
        $("div#cancel-div").show();
764
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 765
}
766
 
7393 anupam.sin 767
function displayCancelStoreOrderPopUp() {
768
	$.colorbox({
769
        inline : true,
770
        width : "650px",
771
        height : "550px",
772
        href : "#cancel-store-order-div",
773
        onClosed : function() {
774
            CKEDITOR.instances['cancel-store-order-body'].destroy(false);
775
            $("#cancel-store-order-div").hide();
776
        }
777
    });
778
 
779
    $("#cancel-store-order-div").show();
780
    $('#cancel-store-order-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
781
}
782
 
4241 anupam.sin 783
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 784
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 785
		var cancellationInitiator = $('#cancellationInitiator').val();
786
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
787
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
788
		var cancellationResult = function() {
789
			document.location.href = "/crm?email=&orderId=" + orderId;
790
		}
791
	} else {
792
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
793
						+ "&orderStatus=" + orderStatus + "&" + formData;
794
		var cancellationResult = function(response) {
795
            $('#' + domId).html(response);
796
        }
797
	}
4241 anupam.sin 798
    $.ajax({
799
        type : "POST",
4689 anupam.sin 800
        url : uri,
801
        success : cancellationResult
4241 anupam.sin 802
    });
4681 amar.kumar 803
 
804
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
805
    	var desc = formData.split("&");
806
    	var description = "Order cancelled because of Lower Price Available elsewhere";
807
    	$.ajax({
808
    		type : "POST",
809
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
810
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
811
    		success : function(response){
812
    			alert("Ticket created for Lower Price Available elsewhere");
813
    		}
814
    	});
815
 
816
    }
4241 anupam.sin 817
}
4065 mandeep.dh 818
 
7393 anupam.sin 819
function cancelStoreOrder(domId, ticketId, orderId, orderStatus, formData) {
820
	if ($('#cancellationInitiator').val() != "CUSTOMER" && $('#cancellationInitiator').val() != "INTERNAL") {
821
		alert("Cannot refund");
822
		return false;
823
	} 
824
	var cancellationInitiator = $('#cancellationInitiator').val();
825
	var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
826
					+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
827
	var cancellationResult = function() {
828
		document.location.href = "/crm?email=&orderId=" + orderId;
829
	}
830
 
831
    $.ajax({
832
        type : "POST",
833
        url : uri,
834
        success : cancellationResult
835
    });
836
}
837
 
4241 anupam.sin 838
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 839
    $.ajax({
3546 mandeep.dh 840
        type : "POST",
4241 anupam.sin 841
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
842
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 843
        success : function(response) {
3546 mandeep.dh 844
            $('#' + domId).html(response);
3499 mandeep.dh 845
        }
846
    });
3711 mandeep.dh 847
}
848
 
849
function loadUnreadActivities(domId) {
850
    $.ajax({
851
        type : "GET",
852
        url : "/crm/activity!getUnreadActivities",
853
        success : function(response) {
854
            $('#' + domId).html(response);
855
            var activityTable = createActivityDataTable('activity');
856
        }
857
    });
858
}
4065 mandeep.dh 859
 
860
function refreshSidebar() {
861
    $.ajax({
4142 mandeep.dh 862
        type : "PUT",
863
        url : "/crm",
864
        success : function(response) {
865
            $('#sidebar').html($(response).find('#sidebar').html());
866
        }
867
    });
868
}
869
 
870
function changeAddress(urlParams) {
871
    $.ajax({
4065 mandeep.dh 872
        type : "GET",
873
        url : "/crm",
874
        success : function(response) {
875
            $('#sidebar').html($(response).find('#sidebar').html());
876
        }
877
    });
4267 anupam.sin 878
}
879
 
4681 amar.kumar 880
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 881
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
882
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 883
		$('#cancelReasonBox').show();
884
	} else {
885
		$('#cancelReasonBox').hide();
886
	}
887
}
888
 
4438 anupam.sin 889
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 890
	$.ajax({
891
		type : "GET",
4451 anupam.sin 892
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 893
		success : function(response) {
894
            $('#bottom-infopane').html(response);
895
        }
896
	});
897
}
898
 
4438 anupam.sin 899
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 900
	$.ajax({
901
		type : "GET",
4451 anupam.sin 902
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 903
		success : function(response) {
904
            $('#bottom-infopane').html(response);
905
        }
906
	});
4490 anupam.sin 907
}
908
 
909
function denyDOA(orderId, ticketId) {
910
	$.ajax({
911
		type : "GET",
912
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
913
		success : function(response) {
914
            $('#bottom-infopane').html(response);
915
        }
916
	});
917
}
918
 
919
 
920
function authorizeDOA(orderId, ticketId) {
921
	$.ajax({
922
		type : "GET",
923
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
924
		success : function(response) {
925
            $('#bottom-infopane').html(response);
926
        }
927
	});
928
}
929
 
930
function denyReturn(orderId, ticketId) {
931
	$.ajax({
932
		type : "GET",
933
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
934
		success : function(response) {
935
            $('#bottom-infopane').html(response);
936
        }
937
	});
938
}
939
 
940
 
941
function authorizeReturn(orderId, ticketId) {
942
	$.ajax({
943
		type : "GET",
944
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
945
		success : function(response) {
946
            $('#bottom-infopane').html(response);
947
        }
948
	});
4689 anupam.sin 949
}
950
 
951
function markOrderForCancellation(orderId, formData) {
952
	console.log(typeof(orderId), typeof(formData), orderId, formData);
953
 
954
	$.ajax({
955
		type : "GET",
956
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
957
		success : function(response) {
958
			document.location.href = "/crm?email=&orderId=" + orderId;
959
        }
960
	});
4793 amar.kumar 961
}
962
 
963
function loadAgentCreationForm() {
964
	$.colorbox({
965
        inline : true,
966
        width : "550px",
967
        height : "400px",
968
        href : "div#create-agent-div",
969
        onClosed : function() {
970
            $("div#create-agent-div").hide();
971
        }
972
    });
973
 
974
    $("div#create-agent-div").show();
975
 
976
}
977
 
978
function deactivateAgentPopup() {
979
	$.colorbox({
980
        inline : true,
981
        width : "400px",
982
        height : "150px",
983
        href : "div#deactivate-agent-div",
984
        onClosed : function() {
985
            $("div#deactivate-agent-div").hide();
986
        }
987
    });
988
 
989
    $("div#deactivate-agent-div").show();
990
 
991
}
992
 
993
function changeAgentPasswordPopup(){
994
	$.colorbox({
995
        inline : true,
996
        width  : "350px",
997
        height : "350px",
998
        href   : "div#change-password-div",
999
        onClosed : function() {
1000
            $("div#change-password-div").hide();
1001
        }
1002
    });
1003
 
1004
    $("div#change-password-div").show();
1005
}
1006
 
5168 amar.kumar 1007
function changeAgentRolePopup(){
1008
	$.colorbox({
1009
        inline : true,
1010
        width  : "375px",
1011
        height : "350px",
1012
        href   : "div#change-agent-role-div",
1013
        onClosed : function() {
1014
            $("div#change-agent-role-div").hide();
1015
        }
1016
    });
4793 amar.kumar 1017
 
5168 amar.kumar 1018
    $("div#change-agent-role-div").show();
1019
}
1020
 
4793 amar.kumar 1021
function updateAgentPassword(){
1022
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
1023
		$.ajax({
1024
			type : "POST",
1025
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
1026
			success : function(response) {
1027
				alert("Password updated successfully");
1028
				$.colorbox.close();
1029
			}
1030
		});
1031
	}
1032
	else { 
1033
		alert("Passwords not matching");
1034
		return false;
1035
	}
1036
}
1037
 
1038
function validateAgentCreationForm(){
1039
	var formError = false;
1040
	if($('#new-agent-name').val().length == 0) {
1041
		$('#agent-name-error').html("Please enter the name");
1042
		$('#new-agent-name').addClass('agent-form-error');
1043
		formError = true;
1044
	}
1045
	if(($('#new-agent-id').val().length == 0)) {
1046
		$('#agent-email-error').html("Please enter the Email-ID");
1047
		$('#new-agent-id').addClass('agent-form-error');
1048
		formError = true;
1049
	}
1050
	if($('#create-password1').val().length == 0) {
1051
		$('#agent-password1-error').html("Please enter password");
1052
		$('#create-password1').addClass('agent-form-error');
1053
		formError = true;
1054
	} else if($('#create-password2').val().length == 0){
1055
		$('#agent-password2-error').html("Please re enter password");
1056
		$('#create-password2').addClass('agent-form-error');
1057
		formError = true;
1058
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
1059
		$('#agent-password1-error').html("Please make sure you entered same passwords");
1060
		$('#create-password1').addClass('agent-form-error');
1061
		$('#create-password2').addClass('agent-form-error');
1062
		formError = true;
1063
	}
1064
 
1065
	if(formError){
1066
		return false;
1067
	}
1068
	return true;
1069
}
1070
 
1071
function clearAgentCreationForm() {
1072
		$('#agent-name-error').html("");
1073
		$('#new-agent-name').removeClass('agent-form-error');
1074
		$('#agent-email-error').html("");
1075
		$('#new-agent-id').removeClass('agent-form-error');
1076
		$('#agent-password1-error').html("");
1077
		$('#create-password1').removeClass('agent-form-error');
1078
		$('#agent-password2-error').html("");
1079
		$('#create-password2').removeClass('agent-form-error');
1080
		$('#agent-password1-error').html("");
1081
		$('#create-password1').removeClass('agent-form-error');
1082
		$('#create-password2').removeClass('agent-form-error');
1083
}
1084
 
1085
function deactivateAgent(emailId, id) {
1086
	$.ajax({
1087
		type : "POST",
1088
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
7162 kshitij.so 1089
		success : function(response) { 
1090
			alert("Agent deactivated successfully");
4793 amar.kumar 1091
			$.colorbox.close();
1092
			$('#infopane').html(response);
1093
			var agentTable = $('#agents').dataTable({
1094
                "aaSorting" : [ [ 1, 'asc' ] ],
1095
                "bAutoWidth": false,
1096
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 1097
                               { "sWidth": "25%" },//Agent Name
1098
                               { "sWidth": "30%" },//Email ID
1099
                               { "sWidth": "20%" },//Role
4793 amar.kumar 1100
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
1101
                "iDisplayLength" : 10,
1102
                "sDom" : 'T<"clear">lfrtip',
1103
                "oTableTools" : {
1104
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1105
                },
1106
            });
1107
		}
1108
	});
5791 anupam.sin 1109
}
1110
 
5917 anupam.sin 1111
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 1112
    $.ajax({
1113
        type : "POST",
5917 anupam.sin 1114
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 1115
        success : function(response) {
1116
            $('#' + domId).html(response);
1117
        }
1118
    });
6507 anupam.sin 1119
}
1120
 
1121
function refundRechargeOrder(rechargeOrderId, domId) {
1122
	$.ajax({
1123
        type : "POST",
1124
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
1125
        success : function(response) {
6516 anupam.sin 1126
        	location.reload();
6507 anupam.sin 1127
        },
1128
        error : function() {
1129
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
1130
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
1131
        }
1132
    });
6985 anupam.sin 1133
}
1134
 
7730 anupam.sin 1135
function convertStoreToNormal(orderId) {
1136
	$.ajax({
1137
        type : "POST",
7732 anupam.sin 1138
        url : "/crm/user-order-info!convertStoreToNormal?orderId=" + orderId,
7730 anupam.sin 1139
        success : function() {
1140
        	location.reload();
1141
        },
1142
        error: function() {
1143
        	location.reload();
1144
        }
1145
    });
1146
}
1147
 
6985 anupam.sin 1148
function changeShippingAddress(orderId) {
1149
	$.ajax({
1150
        type : "POST",
1151
        url : "/crm/user-order-info!changeShippingAddress?orderId=" + orderId,
1152
        data : $('#shippingAddressFrm').serialize(),
1153
        success : function(response) {
1154
        	location.reload();
1155
        },
1156
        error : function() {
1157
        	location.reload();
1158
        }
1159
    });
7372 kshitij.so 1160
}
7572 anupam.sin 1161
 
8821 manish.sha 1162
function refundOrderPayment(params) {
1163
	$.ajax({
1164
        type : "POST",
1165
        url : "/crm/user-order-info!refundOrderPayment",
1166
        data : params,
1167
        success : function(response) {
1168
			alert(response);
1169
			location.reload();
1170
        },
1171
        error : function() {
1172
        	alert("Error in refund");
1173
        	location.reload();
1174
        }
1175
    });
1176
}
1177
 
7572 anupam.sin 1178
function loadOrdersByMobile(domId) {
1179
    orderTable = $('#orders-without-user').dataTable({
1180
      "aaSorting" : [ [ 1, 'desc' ] ],
1181
      "bAutoWidth": false,
11890 kshitij.so 1182
      "aoColumns" : [{ "sWidth": "5%" },//order id
1183
                     { "sWidth": "7%" },//Source
1184
                     { "sWidth": "20%" },//item desc
7572 anupam.sin 1185
                     { "sWidth": "16%" },//created
1186
                     { "sWidth": "7%" },//amount
1187
                     { "sWidth": "15%" },//status
11890 kshitij.so 1188
                     { "sWidth": "10%" },//mobile no.
1189
                     { "sWidth": "20%" }],//email
18345 amit.gupta 1190
        "fnDrawCallback": function() { truncateText(125, $(this)); },
7572 anupam.sin 1191
        "iDisplayLength" : 10,
1192
        "sDom" : 'T<"clear">lfrtip',
1193
        "oTableTools" : {
1194
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1195
        },
1196
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1197
    });
9166 manish.sha 1198
}
1199
 
1200
function loadRechargeOrdersByDeviceNo(domId){
1201
	orderTable = $('#recharge-orders').dataTable({
1202
	      "aaSorting" : [ [ 1, 'desc' ] ],
1203
	      "bAutoWidth": false,
9174 manish.sha 1204
	      "aoColumns" : [{ "sWidth": "13%" },//recharge order id
1205
                         { "sWidth": "22%" },//desc
9166 manish.sha 1206
                         { "sWidth": "16%" },//created
1207
                         { "sWidth": "8%" },//amount
1208
                         { "sWidth": "17%" },//status
9174 manish.sha 1209
                         { "sWidth": "10%" },//mobile no.
1210
                         { "sWidth": "14% "}],//email Id
9166 manish.sha 1211
	        "fnDrawCallback": function() { truncateText(125); },
1212
	        "iDisplayLength" : 10,
1213
	        "sDom" : 'T<"clear">lfrtip',
1214
	        "oTableTools" : {
1215
	            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1216
	        },
1217
	        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1218
	    });
19072 manish.sha 1219
}
1220
 
1221
/*function loadReturnTxnsInfo(domId){
1222
	$.ajax({
1223
		type    : "GET",
1224
		url	    : "/crm/return-transaction",
1225
		success : function(response) {
1226
			$('#' + domId).html(response);
1227
		}
1228
	});
1229
}*/
1230
 
1231
function updateTxnStatus(domId, ticketId, transactionId, orderStatus) {
1232
	$.ajax({
1233
        type : "POST",
1234
        url : "/crm/tickets!updateTxnStatus?id=" + ticketId + "&transactionId=" + transactionId
1235
        					+ "&orderStatus=" + orderStatus,
1236
        success : function(response) {
1237
            $('#' + domId).html(response);
1238
        }
1239
    });
1240
}
1241
 
1242
function cancelTxn(domId, ticketId, transactionId, orderStatus, formData) {
1243
 
1244
	var uri = "/crm/tickets!updateTxnStatus?id=" + ticketId + "&transactionId=" + transactionId
1245
					+ "&orderStatus=" + orderStatus + "&" + formData;
1246
	var cancellationResult = function(response) {
1247
        $('#' + domId).html(response);
1248
    }
1249
 
1250
    $.ajax({
1251
        type : "POST",
1252
        url : uri,
1253
        success : cancellationResult
1254
    });
20110 kshitij.so 1255
 
1256
 
1257
}
1258
 
1259
function loadReturnTransactionsView(domId, params) {
1260
    $.ajax({
1261
        type : "GET",
1262
        url : "/crm/return-transactions",
1263
        data : params,
1264
        success : function(response) {
1265
            $('#' + domId).html(response);
1266
        }
1267
    });
1268
}
1269
 
1270
function loadReturnTransactionsDefectiveView(domId, params) {
1271
    $.ajax({
1272
        type : "GET",
1273
        url : "/crm/return-transactions!defectiveView",
1274
        data : params,
1275
        success : function(response) {
1276
            $('#' + domId).html(response);
1277
        }
1278
    });
1279
}
1280
 
1281
 
1282
function loadReturnTransactionsPane(domId, userId, returnType) {
1283
    $.ajax({
1284
        type : "GET",
1285
        url : "/crm/return-transactions!view?userId=" + userId + "&returnType="+returnType,
1286
        success : function(response) {
1287
            $('#' + domId).html(response);
20199 amit.gupta 1288
            RETURN.orderTable = $('#user-orders').dataTable({
20110 kshitij.so 1289
                "aaSorting" : [ [ 1, 'desc' ] ],
1290
                "bAutoWidth": false,
1291
                "fnDrawCallback": function() { truncateText(125); },
1292
                "iDisplayLength" : 10,
1293
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1294
            });
1295
        }
1296
    });
1297
}
1298
 
1299
function storeTblValues()
1300
{
1301
    var tableData = new Array();
20199 amit.gupta 1302
	var counter=-1;
1303
    $(RETURN.orderTable).find('tr').each(function(row, tr){
20179 aman.kumar 1304
    	if($(tr).find('td:eq(3)').find('input').val()!='0'){
20199 amit.gupta 1305
    	counter++;
1306
    	tableData[counter]={
20110 kshitij.so 1307
            "orderId" : $(tr).find('td:eq(0)').text()
1308
            , "returnQty" :$(tr).find('td:eq(3)').find('input').val()
1309
            , "action" : $(tr).find('td:eq(4)').find('select').val()
1310
            , "returnPickupType" : $(tr).find('td:eq(5)').find('select').val()
20179 aman.kumar 1311
        }   
1312
    }
20110 kshitij.so 1313
    }); 
1314
    tableData.shift();
1315
    return tableData;
1316
}
1317
 
1318
function storeTblValues2()
1319
{
1320
    var tableData = new Array();
1321
 
1322
    $('#confirm-return-orders-table tr').each(function(row, tr){
1323
    	tableData[row]={
1324
            "orderId" : $(tr).find('td:eq(0)').text()
1325
            , "returnQty" :$(tr).find('td:eq(1)').text()
1326
            , "action" : $(tr).find('td:eq(2)').find('select').val()
1327
            , "returnPickupType" : $(tr).find('td:eq(3)').find('select').val()
1328
        }    
1329
    }); 
1330
    tableData.shift();
1331
    return tableData;
1332
}
1333
 
1334
function validateReturn(tableData, userId, returnType, domId){
1335
 
1336
	var params = "tableData=" + tableData + "&userId=" + userId + "&returnType=" + returnType;
1337
 
1338
	$.ajax({
1339
        type : "GET",
1340
        url : "/crm/return-transactions!validateReturn",
1341
        data : params,
1342
        success : function(response) {
1343
        	if(new String("false").valueOf() == new String(response.trim()).valueOf()){
1344
        		alert("Data not validated at server end");
1345
			}
1346
			else {
1347
				$('#' + domId).html(response);
1348
				orderTable = $('#confirm-return-orders-table').dataTable({
1349
	                "aaSorting" : [ [ 1, 'desc' ] ],
1350
	                "bAutoWidth": false,
1351
	                "iDisplayLength" : 10,
1352
	                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1353
	            });
1354
 
1355
				addressTable = $('#user-addresses-return-order').dataTable({
1356
	                "aaSorting" : [ [ 1, 'desc' ] ],
1357
	                "bAutoWidth": false,
1358
	                "iDisplayLength" : 10,
1359
	                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1360
	            });
1361
			}
1362
        }
1363
    });
1364
}
1365
 
1366
function submitAddressForReturnOrder(params,userId,returnType,tableData,domId) {
1367
 
1368
    $.ajax({
1369
        type : "GET",
1370
        url : "/crm/return-transactions!addNewAddress",
1371
        data : params,
1372
        success : function(response) {
1373
        	if (response.trim()==""){
1374
        		alert("Address added successfully");
1375
        		validateReturn(tableData, userId, returnType, domId)
1376
        	}
1377
        	else{
1378
        		alert(response);
1379
        	}
1380
        }
1381
    });
1382
}
1383
 
1384
function createReturnTransaction(tableData, userId, returnType, addressId, domId) {
1385
	var params = "tableData=" + tableData + "&userId=" + userId + "&returnType=" + returnType +"&addressId=" + addressId;
1386
	$.ajax({
1387
        type : "GET",
1388
        url : "/crm/return-transactions!createReturnTransaction",
1389
        data : params,
1390
        success : function(response) {
1391
        	if(response.trim()==="0"){
1392
        		alert("Problem while creating return transaction.");
1393
        	}
1394
        	else{
1395
        		$('#' + domId).html(response);
1396
        		$('#user-return-orders').dataTable({
1397
                    "aaSorting" : [ [ 1, 'desc' ] ],
1398
                    "bAutoWidth": false,
1399
                    "aoColumns" : [{ "sWidth": "5%" },
1400
                                   { "sWidth": "10%" },
1401
                                   { "sWidth": "20%" },
1402
                                   { "sWidth": "10%" },
1403
                                   { "sWidth": "10%" },
1404
                                   { "sWidth": "20%" },
1405
                                   { "sWidth": "25% "}],
1406
                    "fnDrawCallback": function() { truncateText(125); },
1407
                    "iDisplayLength" : 10,
1408
                    "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1409
                });
1410
        	}
1411
        }
1412
    });
1413
}
1414
 
1415
function viewReturnTransaction(returnTransactionId, domId){
1416
 
1417
	var params = "returnTransactionId=" + returnTransactionId;
1418
 
1419
	$.ajax({
1420
        type : "GET",
1421
        url : "/crm/return-transactions!viewReturnTransaction",
1422
        data : params,
1423
        success : function(response) {
1424
        	$('#' + domId).html(response);
1425
    		$('#user-return-orders').dataTable({
1426
                "aaSorting" : [ [ 1, 'desc' ] ],
1427
                "bAutoWidth": false,
1428
                "aoColumns" : [{ "sWidth": "5%" },
1429
                               { "sWidth": "10%" },
1430
                               { "sWidth": "20%" },
1431
                               { "sWidth": "10%" },
1432
                               { "sWidth": "10%" },
1433
                               { "sWidth": "20%" },
1434
                               { "sWidth": "25% "}],
1435
                "fnDrawCallback": function() { truncateText(125); },
1436
                "iDisplayLength" : 10,
1437
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1438
            });
1439
        }
1440
    });
1441
}
1442
 
1443
function changeStatusForReturnTransaction(returnTransactionId, newReturnTransactionStatus, domId) {
1444
 
1445
	var params = "returnTransactionId=" + returnTransactionId + "&newReturnTransactionStatus=" + newReturnTransactionStatus;
1446
 
1447
    $.ajax({
1448
        type : "GET",
1449
        url : "/crm/return-transactions!changeStatusForReturnTransaction",
1450
        data : params,
1451
        success : function(response) {
1452
        	alert(response);
1453
        	viewReturnTransaction(returnTransactionId, domId);
1454
        }
1455
    });
1456
}
1457
 
1458
function viewReturnOrderInfo(returnOrderId, domId) {
1459
 
1460
	var params = "returnOrderId=" + returnOrderId;
1461
 
1462
	$.ajax({
1463
        type : "GET",
1464
        url : "/crm/return-transactions!getReturnOrderInfoForId",
1465
        data : params,
1466
        success : function(response) {
1467
        	$('#' + domId).html(response);
1468
        }
1469
    });
1470
}
1471
 
1472
function loadReturnPickUpPane(domId, userId){
1473
	$.ajax({
1474
        type : "GET",
1475
        url : "/crm/return-transactions!viewPickUp?userId=" + userId,
1476
        success : function(response) {
1477
            $('#' + domId).html(response);
1478
            $('#user-orders-pickup').dataTable({
1479
                "aaSorting" : [ [ 1, 'desc' ] ],
1480
                "bAutoWidth": false,
1481
                "fnDrawCallback": function() { truncateText(125); },
1482
                "iDisplayLength" : 10,
1483
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1484
            });
1485
        }
1486
    });
1487
}
1488
 
1489
function confirmPickup(userId, domId){
1490
	var returnOrderIdsArray = new Array();
1491
	$('#user-orders-pickup tr').each(function(row, tr){
1492
		if($(tr).find('td:eq(6)').find('input').is(":checked")){
1493
    		var returnOrderId = $(tr).find('td:eq(6)').find('input').val();
1494
    		returnOrderIdsArray.push(returnOrderId);
1495
    	} 
1496
    });
1497
 
1498
	if (returnOrderIdsArray.length ==0){
1499
		alert("Please select orders for pickup");
1500
		return false;
1501
	}
1502
 
1503
	var params = "returnOrderIdsForPickUp=" +returnOrderIdsArray;
1504
 
1505
	$.ajax({
1506
        type : "GET",
1507
        url : "/crm/return-transactions!createReturnPickup",
1508
        data : params,
1509
        success : function(response) {
1510
        	$('#' + domId).html(response);
1511
        	$('#user-orders-pickup').dataTable({
1512
                "aaSorting" : [ [ 1, 'desc' ] ],
1513
                "bAutoWidth": false,
1514
                "fnDrawCallback": function() { truncateText(125); },
1515
                "iDisplayLength" : 10,
1516
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1517
            });
1518
        },
1519
        error : function() {
1520
			alert("Unable to create pick up");
1521
		}
1522
    });
1523
 
1524
}
1525
 
1526
function viewReturnPickup(pickupRequestId, domId){
1527
 
1528
	var params = "pickupRequestId=" + pickupRequestId;
1529
 
1530
	$.ajax({
1531
        type : "GET",
1532
        url : "/crm/return-transactions!viewReturnPickup",
1533
        data : params,
1534
        success : function(response) {
1535
        	$('#' + domId).html(response);
1536
        	$('#user-orders-pickup').dataTable({
1537
                "aaSorting" : [ [ 1, 'desc' ] ],
1538
                "bAutoWidth": false,
1539
                "aoColumns" : [{ "sWidth": "10%" },
1540
                               { "sWidth": "10%" },
1541
                               { "sWidth": "10%" },
1542
                               { "sWidth": "25%" },
1543
                               { "sWidth": "10%" },
1544
                               { "sWidth": "10%" },
1545
                               { "sWidth": "25% "}],
1546
                "fnDrawCallback": function() { truncateText(125); },
1547
                "iDisplayLength" : 10,
1548
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1549
            });
1550
        }
1551
    });
1552
}
1553
 
1554
function changeRequestPickupStatus(pickupRequestId, pickupRequestNo, logisticProviderId, pickupStatus, promised_pickup_timestamp, pickedUpAt, domId){
1555
 
1556
	var params = "pickupRequestId=" +pickupRequestId + "&pickupRequestNo=" + pickupRequestNo + "&logisticProviderId=" + logisticProviderId + "&pickupStatus=" +
1557
	pickupStatus + "&promised_pickup_timestamp=" + promised_pickup_timestamp + "&pickedUpAt=" + pickedUpAt;
1558
	$.ajax({
1559
        type : "GET",
1560
        url : "/crm/return-transactions!updateReturnPickup",
1561
        data : params,
1562
        success : function(response) {
1563
        	alert(response);
1564
        	viewReturnPickup(pickupRequestId, domId);
1565
        }
1566
    });
1567
 
1568
}
1569
 
1570
function showAllReturnTransactions(userId, domId){
1571
var params = "userId=" + userId;
1572
 
1573
	$.ajax({
1574
        type : "GET",
1575
        url : "/crm/return-transactions!getReturnTransactionsForUser",
1576
        data : params,
1577
        success : function(response) {
1578
        	$('#' + domId).html(response);
1579
        	$('#all-return-transactions').dataTable({
1580
                "aaSorting" : [ [ 1, 'desc' ] ],
1581
                "bAutoWidth": false,
1582
                "fnDrawCallback": function() { truncateText(125); },
1583
                "iDisplayLength" : 10,
1584
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1585
            });
1586
        }
1587
    });
1588
} 
1589
 
1590
function splitReturnOrder(params){
1591
 
1592
	$.ajax({
1593
        type : "GET",
1594
        url : "/crm/return-transactions!splitReturnOrder",
1595
        data : params,
1596
        success : function(response) {
1597
        	alert(response);
1598
        	location.reload();
1599
        },
1600
        error : function() {
1601
			alert("Unable to split returnorder");
1602
		}
1603
    });
1604
}
1605
 
1606
function showHideRefundDiv(refundType){
1607
	if (refundType === "1"){
1608
		if ($('#chequeDetails').css('display') == 'none') {
1609
			$('#chequeDetails').show();
1610
			$('#couponDetails').hide();
1611
		}
1612
	}
1613
	if (refundType === "3"){
1614
		if ($('#couponDetails').css('display') == 'none') {
1615
			$('#couponDetails').show();
1616
			$('#chequeDetails').hide();
1617
		}
1618
	}
1619
	if (refundType === "4" || refundType === "0"){
1620
		$('#chequeDetails').hide();
1621
		$('#couponDetails').hide();
1622
	}
1623
}
1624
 
21934 amit.gupta 1625
function verifyDoc(userId){
1626
	var gstin = $("#gstin").val();
1627
	params = {gstin:gstin, userId:userId}
1628
	$.ajax({
1629
        type : "GET",
22363 ashik.ali 1630
        url : "/crm/user-info!verifyRetailer",
21934 amit.gupta 1631
        data : params,
1632
        success : function(response) {
22363 ashik.ali 1633
        	alert("Retailer has been verified");
1634
        	$('#infopane').html(response);
21934 amit.gupta 1635
        },
1636
        error : function() {
22363 ashik.ali 1637
			alert("Unable to verify retailer");
21934 amit.gupta 1638
		}
1639
    });
1640
}
20110 kshitij.so 1641
//