Subversion Repositories SmartDukaan

Rev

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

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