Subversion Repositories SmartDukaan

Rev

Rev 20199 | Rev 22350 | 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;
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
 
3090 mandeep.dh 459
function createTicket(domId, params) {
3228 mandeep.dh 460
    $.ajax({
461
        type : "POST",
3339 mandeep.dh 462
        url : "/crm/tickets",
3228 mandeep.dh 463
        data : params,
464
        success : function(response) {
465
            $('#' + domId).html(response);
3405 mandeep.dh 466
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 467
        }
468
    });
3090 mandeep.dh 469
}
470
 
4793 amar.kumar 471
function createAgent(params, managerId){
472
	$.ajax({
473
		type : "POST",
474
		url : "/crm/agent!createAgent?managerId="+managerId,
475
		data : params,
476
		success : function(response) {
477
			alert("Agent created with the specified information");
478
			$.colorbox.close();
479
			$('#infopane').html(response);
480
			var agentTable = $('#agents').dataTable({
481
                "aaSorting" : [ [ 1, 'asc' ] ],
482
                "bAutoWidth": false,
483
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 484
                               { "sWidth": "25%" },//Agent Name
485
                               { "sWidth": "30%" },//Email ID
486
                               { "sWidth": "20%" },//Role
4793 amar.kumar 487
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
488
                "iDisplayLength" : 10,
489
                "sDom" : 'T<"clear">lfrtip',
490
                "oTableTools" : {
491
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
492
                },
493
            });
494
		}
495
	});
496
}
497
 
5168 amar.kumar 498
function changeAgentRole(params){
499
	$.ajax({
500
		type : "POST",
501
		url : "/crm/agent!changeAgentRole",
502
		data : params,
503
		success : function(response) {
504
			alert("Agent role changed");
505
			$.colorbox.close();
506
			$('#infopane').html(response);
507
			var agentTable = $('#agents').dataTable({
508
                "aaSorting" : [ [ 1, 'asc' ] ],
509
                "bAutoWidth": false,
510
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 511
                               { "sWidth": "25%" },//Agent Name
512
                               { "sWidth": "30%" },//Email ID
513
                               { "sWidth": "20%" },//Role
5168 amar.kumar 514
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
515
                "iDisplayLength" : 10,
516
                "sDom" : 'T<"clear">lfrtip',
517
                "oTableTools" : {
518
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
519
                },
520
            });
521
		}
522
	});
523
}
524
 
3090 mandeep.dh 525
function createActivity(domId, params) {
3228 mandeep.dh 526
    $.ajax({
527
        type : "POST",
3339 mandeep.dh 528
        url : "/crm/activity",
3228 mandeep.dh 529
        data : params,
530
        success : function(response) {
531
            $('#' + domId).html(response);
3405 mandeep.dh 532
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 533
        }
534
    });
3106 mandeep.dh 535
}
536
 
537
function goToHomePage() {
3228 mandeep.dh 538
    document.location.href = "/crm";
3106 mandeep.dh 539
}
540
 
3422 mandeep.dh 541
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 542
    $.ajax({
543
        type : "GET",
3234 mandeep.dh 544
        url : getURL,
3228 mandeep.dh 545
        success : function(response) {
546
            $('#' + domId).html(response);
3405 mandeep.dh 547
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 548
            if (ticketId != null) {
549
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
550
                ticketTable.css('table-layout', 'fixed');
551
            }
3228 mandeep.dh 552
        }
553
    });
3106 mandeep.dh 554
}
5225 amar.kumar 555
function changeActivityFormValidCriteria(commonDescription) {
556
	if(commonDescription == "") {
557
		$('#description').addClass('required');
558
	} else {
559
		$('#description').removeClass('required');
560
	}
561
}
3137 mandeep.dh 562
 
3422 mandeep.dh 563
function processActivityTypeChange(activityType) {
5203 amar.kumar 564
	if(activityType != "RECEIVED_CALL_FROM_CUSTOMER") {
565
		$('select#common-activity-desc').hide();
5224 amar.kumar 566
		$('#description').addClass('required');
5203 amar.kumar 567
	} else {
568
		$('select#common-activity-desc').show();
569
	}
3269 mandeep.dh 570
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 571
        $.colorbox({
572
            inline : true,
3519 mandeep.dh 573
            width : "775px",
574
            height : "445px",
3228 mandeep.dh 575
            href : "div#mail-div",
576
            onClosed : function() {
3519 mandeep.dh 577
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 578
                $("div#mail-div").hide();
579
                $('select#activity-type').val('OTHER');
580
            }
581
        });
3206 mandeep.dh 582
 
3228 mandeep.dh 583
        $("div#mail-div").show();
3701 mandeep.dh 584
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 585
    }
4020 mandeep.dh 586
    else if (activityType == "ESCALATE_TICKET") {
587
        $.colorbox({
588
            inline : true,
589
            width : "675px",
18308 amit.gupta 590
            height : "560px",
4020 mandeep.dh 591
            href : "div#escalation-div",
592
            onClosed : function() {
593
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
594
                $("div#escalation-div").hide();
595
                $('select#activity-type').val('OTHER');
596
            }
597
        });
598
 
599
        $("div#escalation-div").show();
600
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
601
    }
3206 mandeep.dh 602
}
603
 
604
function processInputFormSubmit() {
3228 mandeep.dh 605
    $.ajax({
606
        type : "POST",
607
        url : "/crm/",
608
        success : function(response) {
609
            $.html(response);
3405 mandeep.dh 610
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 611
        }
612
    });
3339 mandeep.dh 613
}
614
 
615
function listActivities(domId, params) {
616
    $.ajax({
617
        type : "GET",
618
        url : "/crm/activity",
619
        data : params,
620
        success : function(response) {
621
            $('#' + domId).html(response);
3405 mandeep.dh 622
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 623
        }
624
    });
625
}
626
 
18345 amit.gupta 627
function truncateText(widthSize, jqueryContainer) {
628
	if(typeof jqueryContainer!="undefined"){
629
	    jqueryContainer.find(".truncated-text").each(function() {
630
	    	$(this).truncate({
631
	            width : $(this).attr('truncatedTextWidth'),
632
	            addtitle : true
633
	        });
634
		})
635
	}else {
636
	    $(".truncated-text").each(function() {
637
	    	$(this).truncate({
638
	            width : $(this).attr('truncatedTextWidth'),
639
	            addtitle : true
640
	        });
641
		})
642
	}
3339 mandeep.dh 643
}
3390 mandeep.dh 644
 
645
function markAsRead(activityId) {
646
    $.ajax({
647
        type : "POST",
648
        url : "/crm/activity!markAsRead?activityId=" + activityId,
649
        success: function(response) {
650
            listActivities('infopane', "creatorId=1");
651
        }
652
    });
653
}
3397 mandeep.dh 654
 
655
function loadAdvancedSearchBox() {
656
    $.colorbox({
657
        inline : true,
658
        width : "535px",
659
        height : "465px",
660
        href : "form#search",
661
        onClosed : function() {
662
            $("form#search").hide();
663
        }
664
    });
665
 
666
    $("form#search").show();
667
}
668
 
669
function processSearchEntityChange(searchEntity) {
670
    if (searchEntity == "Tickets") {
671
        $("#assignee").show();
672
        $("#creator").hide();
4142 mandeep.dh 673
        $("tr#activityTypes").hide();
3397 mandeep.dh 674
    }
675
    else if (searchEntity == "Activities") {
676
        $("#assignee").hide();
677
        $("#creator").show();
4142 mandeep.dh 678
        $("tr#activityTypes").show();
3397 mandeep.dh 679
    }
680
}
3499 mandeep.dh 681
 
682
function increaseTrustLevel(domId, userId, trustLevelDelta) {
683
    $.ajax({
684
        type : "PUT",
685
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
686
        success : function(response) {
687
            $('#' + domId).html(response);
688
        }
689
    });
690
}
691
 
11890 kshitij.so 692
function addPrivateDealUser(domId, userId) {
693
    $.ajax({
694
        type : "PUT",
695
        url : "/crm/user-info!addPrivateDealUser?userId=" + userId,
696
        success : function(response) {
697
            $('#' + domId).html(response);
698
        }
699
    });
700
}
701
 
702
function changePrivateDealUserStatus(domId, userId, state) {
703
    $.ajax({
704
        type : "PUT",
705
        url : "/crm/user-info!changeStatusOfPrivateDealUser?userId=" + userId+ "&isPrivateDealUserActive=" + state,
706
        success : function(response) {
707
            $('#' + domId).html(response);
708
        }
709
    });
710
}
711
 
712
function resetPasswordForPrivateDealUser(domId, userId) {
713
    $.ajax({
714
        type : "PUT",
715
        url : "/crm/user-info!resetPrivateDealUserPassword?userId=" + userId,
716
        success : function(response) {
717
            $('#' + domId).html(response);
718
        },
719
    	error : function() {
720
    		alert("Unable to reset password.");
721
    	}
722
    });
723
}
724
 
19072 manish.sha 725
function displayCancelOrderPopUp(type) {
4241 anupam.sin 726
    	$.colorbox({
727
            inline : true,
728
            width : "650px",
4314 anupam.sin 729
            height : "550px",
4689 anupam.sin 730
            href : "div#cancel-div",
4241 anupam.sin 731
            onClosed : function() {
4689 anupam.sin 732
                CKEDITOR.instances['cancel-body'].destroy(false);
19072 manish.sha 733
                $("div#cancel-div").attr('cancelType','');
4689 anupam.sin 734
                $("div#cancel-div").hide();
4241 anupam.sin 735
            }
736
        });
19072 manish.sha 737
    	$("div#cancel-div").attr('cancelType',type);
4689 anupam.sin 738
        $("div#cancel-div").show();
739
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 740
}
741
 
7393 anupam.sin 742
function displayCancelStoreOrderPopUp() {
743
	$.colorbox({
744
        inline : true,
745
        width : "650px",
746
        height : "550px",
747
        href : "#cancel-store-order-div",
748
        onClosed : function() {
749
            CKEDITOR.instances['cancel-store-order-body'].destroy(false);
750
            $("#cancel-store-order-div").hide();
751
        }
752
    });
753
 
754
    $("#cancel-store-order-div").show();
755
    $('#cancel-store-order-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
756
}
757
 
4241 anupam.sin 758
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 759
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 760
		var cancellationInitiator = $('#cancellationInitiator').val();
761
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
762
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
763
		var cancellationResult = function() {
764
			document.location.href = "/crm?email=&orderId=" + orderId;
765
		}
766
	} else {
767
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
768
						+ "&orderStatus=" + orderStatus + "&" + formData;
769
		var cancellationResult = function(response) {
770
            $('#' + domId).html(response);
771
        }
772
	}
4241 anupam.sin 773
    $.ajax({
774
        type : "POST",
4689 anupam.sin 775
        url : uri,
776
        success : cancellationResult
4241 anupam.sin 777
    });
4681 amar.kumar 778
 
779
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
780
    	var desc = formData.split("&");
781
    	var description = "Order cancelled because of Lower Price Available elsewhere";
782
    	$.ajax({
783
    		type : "POST",
784
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
785
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
786
    		success : function(response){
787
    			alert("Ticket created for Lower Price Available elsewhere");
788
    		}
789
    	});
790
 
791
    }
4241 anupam.sin 792
}
4065 mandeep.dh 793
 
7393 anupam.sin 794
function cancelStoreOrder(domId, ticketId, orderId, orderStatus, formData) {
795
	if ($('#cancellationInitiator').val() != "CUSTOMER" && $('#cancellationInitiator').val() != "INTERNAL") {
796
		alert("Cannot refund");
797
		return false;
798
	} 
799
	var cancellationInitiator = $('#cancellationInitiator').val();
800
	var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
801
					+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
802
	var cancellationResult = function() {
803
		document.location.href = "/crm?email=&orderId=" + orderId;
804
	}
805
 
806
    $.ajax({
807
        type : "POST",
808
        url : uri,
809
        success : cancellationResult
810
    });
811
}
812
 
4241 anupam.sin 813
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 814
    $.ajax({
3546 mandeep.dh 815
        type : "POST",
4241 anupam.sin 816
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
817
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 818
        success : function(response) {
3546 mandeep.dh 819
            $('#' + domId).html(response);
3499 mandeep.dh 820
        }
821
    });
3711 mandeep.dh 822
}
823
 
824
function loadUnreadActivities(domId) {
825
    $.ajax({
826
        type : "GET",
827
        url : "/crm/activity!getUnreadActivities",
828
        success : function(response) {
829
            $('#' + domId).html(response);
830
            var activityTable = createActivityDataTable('activity');
831
        }
832
    });
833
}
4065 mandeep.dh 834
 
835
function refreshSidebar() {
836
    $.ajax({
4142 mandeep.dh 837
        type : "PUT",
838
        url : "/crm",
839
        success : function(response) {
840
            $('#sidebar').html($(response).find('#sidebar').html());
841
        }
842
    });
843
}
844
 
845
function changeAddress(urlParams) {
846
    $.ajax({
4065 mandeep.dh 847
        type : "GET",
848
        url : "/crm",
849
        success : function(response) {
850
            $('#sidebar').html($(response).find('#sidebar').html());
851
        }
852
    });
4267 anupam.sin 853
}
854
 
4681 amar.kumar 855
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 856
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
857
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 858
		$('#cancelReasonBox').show();
859
	} else {
860
		$('#cancelReasonBox').hide();
861
	}
862
}
863
 
4438 anupam.sin 864
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 865
	$.ajax({
866
		type : "GET",
4451 anupam.sin 867
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 868
		success : function(response) {
869
            $('#bottom-infopane').html(response);
870
        }
871
	});
872
}
873
 
4438 anupam.sin 874
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 875
	$.ajax({
876
		type : "GET",
4451 anupam.sin 877
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 878
		success : function(response) {
879
            $('#bottom-infopane').html(response);
880
        }
881
	});
4490 anupam.sin 882
}
883
 
884
function denyDOA(orderId, ticketId) {
885
	$.ajax({
886
		type : "GET",
887
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
888
		success : function(response) {
889
            $('#bottom-infopane').html(response);
890
        }
891
	});
892
}
893
 
894
 
895
function authorizeDOA(orderId, ticketId) {
896
	$.ajax({
897
		type : "GET",
898
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
899
		success : function(response) {
900
            $('#bottom-infopane').html(response);
901
        }
902
	});
903
}
904
 
905
function denyReturn(orderId, ticketId) {
906
	$.ajax({
907
		type : "GET",
908
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
909
		success : function(response) {
910
            $('#bottom-infopane').html(response);
911
        }
912
	});
913
}
914
 
915
 
916
function authorizeReturn(orderId, ticketId) {
917
	$.ajax({
918
		type : "GET",
919
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
920
		success : function(response) {
921
            $('#bottom-infopane').html(response);
922
        }
923
	});
4689 anupam.sin 924
}
925
 
926
function markOrderForCancellation(orderId, formData) {
927
	console.log(typeof(orderId), typeof(formData), orderId, formData);
928
 
929
	$.ajax({
930
		type : "GET",
931
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
932
		success : function(response) {
933
			document.location.href = "/crm?email=&orderId=" + orderId;
934
        }
935
	});
4793 amar.kumar 936
}
937
 
938
function loadAgentCreationForm() {
939
	$.colorbox({
940
        inline : true,
941
        width : "550px",
942
        height : "400px",
943
        href : "div#create-agent-div",
944
        onClosed : function() {
945
            $("div#create-agent-div").hide();
946
        }
947
    });
948
 
949
    $("div#create-agent-div").show();
950
 
951
}
952
 
953
function deactivateAgentPopup() {
954
	$.colorbox({
955
        inline : true,
956
        width : "400px",
957
        height : "150px",
958
        href : "div#deactivate-agent-div",
959
        onClosed : function() {
960
            $("div#deactivate-agent-div").hide();
961
        }
962
    });
963
 
964
    $("div#deactivate-agent-div").show();
965
 
966
}
967
 
968
function changeAgentPasswordPopup(){
969
	$.colorbox({
970
        inline : true,
971
        width  : "350px",
972
        height : "350px",
973
        href   : "div#change-password-div",
974
        onClosed : function() {
975
            $("div#change-password-div").hide();
976
        }
977
    });
978
 
979
    $("div#change-password-div").show();
980
}
981
 
5168 amar.kumar 982
function changeAgentRolePopup(){
983
	$.colorbox({
984
        inline : true,
985
        width  : "375px",
986
        height : "350px",
987
        href   : "div#change-agent-role-div",
988
        onClosed : function() {
989
            $("div#change-agent-role-div").hide();
990
        }
991
    });
4793 amar.kumar 992
 
5168 amar.kumar 993
    $("div#change-agent-role-div").show();
994
}
995
 
4793 amar.kumar 996
function updateAgentPassword(){
997
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
998
		$.ajax({
999
			type : "POST",
1000
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
1001
			success : function(response) {
1002
				alert("Password updated successfully");
1003
				$.colorbox.close();
1004
			}
1005
		});
1006
	}
1007
	else { 
1008
		alert("Passwords not matching");
1009
		return false;
1010
	}
1011
}
1012
 
1013
function validateAgentCreationForm(){
1014
	var formError = false;
1015
	if($('#new-agent-name').val().length == 0) {
1016
		$('#agent-name-error').html("Please enter the name");
1017
		$('#new-agent-name').addClass('agent-form-error');
1018
		formError = true;
1019
	}
1020
	if(($('#new-agent-id').val().length == 0)) {
1021
		$('#agent-email-error').html("Please enter the Email-ID");
1022
		$('#new-agent-id').addClass('agent-form-error');
1023
		formError = true;
1024
	}
1025
	if($('#create-password1').val().length == 0) {
1026
		$('#agent-password1-error').html("Please enter password");
1027
		$('#create-password1').addClass('agent-form-error');
1028
		formError = true;
1029
	} else if($('#create-password2').val().length == 0){
1030
		$('#agent-password2-error').html("Please re enter password");
1031
		$('#create-password2').addClass('agent-form-error');
1032
		formError = true;
1033
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
1034
		$('#agent-password1-error').html("Please make sure you entered same passwords");
1035
		$('#create-password1').addClass('agent-form-error');
1036
		$('#create-password2').addClass('agent-form-error');
1037
		formError = true;
1038
	}
1039
 
1040
	if(formError){
1041
		return false;
1042
	}
1043
	return true;
1044
}
1045
 
1046
function clearAgentCreationForm() {
1047
		$('#agent-name-error').html("");
1048
		$('#new-agent-name').removeClass('agent-form-error');
1049
		$('#agent-email-error').html("");
1050
		$('#new-agent-id').removeClass('agent-form-error');
1051
		$('#agent-password1-error').html("");
1052
		$('#create-password1').removeClass('agent-form-error');
1053
		$('#agent-password2-error').html("");
1054
		$('#create-password2').removeClass('agent-form-error');
1055
		$('#agent-password1-error').html("");
1056
		$('#create-password1').removeClass('agent-form-error');
1057
		$('#create-password2').removeClass('agent-form-error');
1058
}
1059
 
1060
function deactivateAgent(emailId, id) {
1061
	$.ajax({
1062
		type : "POST",
1063
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
7162 kshitij.so 1064
		success : function(response) { 
1065
			alert("Agent deactivated successfully");
4793 amar.kumar 1066
			$.colorbox.close();
1067
			$('#infopane').html(response);
1068
			var agentTable = $('#agents').dataTable({
1069
                "aaSorting" : [ [ 1, 'asc' ] ],
1070
                "bAutoWidth": false,
1071
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 1072
                               { "sWidth": "25%" },//Agent Name
1073
                               { "sWidth": "30%" },//Email ID
1074
                               { "sWidth": "20%" },//Role
4793 amar.kumar 1075
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
1076
                "iDisplayLength" : 10,
1077
                "sDom" : 'T<"clear">lfrtip',
1078
                "oTableTools" : {
1079
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1080
                },
1081
            });
1082
		}
1083
	});
5791 anupam.sin 1084
}
1085
 
5917 anupam.sin 1086
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 1087
    $.ajax({
1088
        type : "POST",
5917 anupam.sin 1089
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 1090
        success : function(response) {
1091
            $('#' + domId).html(response);
1092
        }
1093
    });
6507 anupam.sin 1094
}
1095
 
1096
function refundRechargeOrder(rechargeOrderId, domId) {
1097
	$.ajax({
1098
        type : "POST",
1099
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
1100
        success : function(response) {
6516 anupam.sin 1101
        	location.reload();
6507 anupam.sin 1102
        },
1103
        error : function() {
1104
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
1105
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
1106
        }
1107
    });
6985 anupam.sin 1108
}
1109
 
7730 anupam.sin 1110
function convertStoreToNormal(orderId) {
1111
	$.ajax({
1112
        type : "POST",
7732 anupam.sin 1113
        url : "/crm/user-order-info!convertStoreToNormal?orderId=" + orderId,
7730 anupam.sin 1114
        success : function() {
1115
        	location.reload();
1116
        },
1117
        error: function() {
1118
        	location.reload();
1119
        }
1120
    });
1121
}
1122
 
6985 anupam.sin 1123
function changeShippingAddress(orderId) {
1124
	$.ajax({
1125
        type : "POST",
1126
        url : "/crm/user-order-info!changeShippingAddress?orderId=" + orderId,
1127
        data : $('#shippingAddressFrm').serialize(),
1128
        success : function(response) {
1129
        	location.reload();
1130
        },
1131
        error : function() {
1132
        	location.reload();
1133
        }
1134
    });
7372 kshitij.so 1135
}
7572 anupam.sin 1136
 
8821 manish.sha 1137
function refundOrderPayment(params) {
1138
	$.ajax({
1139
        type : "POST",
1140
        url : "/crm/user-order-info!refundOrderPayment",
1141
        data : params,
1142
        success : function(response) {
1143
			alert(response);
1144
			location.reload();
1145
        },
1146
        error : function() {
1147
        	alert("Error in refund");
1148
        	location.reload();
1149
        }
1150
    });
1151
}
1152
 
7572 anupam.sin 1153
function loadOrdersByMobile(domId) {
1154
    orderTable = $('#orders-without-user').dataTable({
1155
      "aaSorting" : [ [ 1, 'desc' ] ],
1156
      "bAutoWidth": false,
11890 kshitij.so 1157
      "aoColumns" : [{ "sWidth": "5%" },//order id
1158
                     { "sWidth": "7%" },//Source
1159
                     { "sWidth": "20%" },//item desc
7572 anupam.sin 1160
                     { "sWidth": "16%" },//created
1161
                     { "sWidth": "7%" },//amount
1162
                     { "sWidth": "15%" },//status
11890 kshitij.so 1163
                     { "sWidth": "10%" },//mobile no.
1164
                     { "sWidth": "20%" }],//email
18345 amit.gupta 1165
        "fnDrawCallback": function() { truncateText(125, $(this)); },
7572 anupam.sin 1166
        "iDisplayLength" : 10,
1167
        "sDom" : 'T<"clear">lfrtip',
1168
        "oTableTools" : {
1169
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1170
        },
1171
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1172
    });
9166 manish.sha 1173
}
1174
 
1175
function loadRechargeOrdersByDeviceNo(domId){
1176
	orderTable = $('#recharge-orders').dataTable({
1177
	      "aaSorting" : [ [ 1, 'desc' ] ],
1178
	      "bAutoWidth": false,
9174 manish.sha 1179
	      "aoColumns" : [{ "sWidth": "13%" },//recharge order id
1180
                         { "sWidth": "22%" },//desc
9166 manish.sha 1181
                         { "sWidth": "16%" },//created
1182
                         { "sWidth": "8%" },//amount
1183
                         { "sWidth": "17%" },//status
9174 manish.sha 1184
                         { "sWidth": "10%" },//mobile no.
1185
                         { "sWidth": "14% "}],//email Id
9166 manish.sha 1186
	        "fnDrawCallback": function() { truncateText(125); },
1187
	        "iDisplayLength" : 10,
1188
	        "sDom" : 'T<"clear">lfrtip',
1189
	        "oTableTools" : {
1190
	            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1191
	        },
1192
	        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1193
	    });
19072 manish.sha 1194
}
1195
 
1196
/*function loadReturnTxnsInfo(domId){
1197
	$.ajax({
1198
		type    : "GET",
1199
		url	    : "/crm/return-transaction",
1200
		success : function(response) {
1201
			$('#' + domId).html(response);
1202
		}
1203
	});
1204
}*/
1205
 
1206
function updateTxnStatus(domId, ticketId, transactionId, orderStatus) {
1207
	$.ajax({
1208
        type : "POST",
1209
        url : "/crm/tickets!updateTxnStatus?id=" + ticketId + "&transactionId=" + transactionId
1210
        					+ "&orderStatus=" + orderStatus,
1211
        success : function(response) {
1212
            $('#' + domId).html(response);
1213
        }
1214
    });
1215
}
1216
 
1217
function cancelTxn(domId, ticketId, transactionId, orderStatus, formData) {
1218
 
1219
	var uri = "/crm/tickets!updateTxnStatus?id=" + ticketId + "&transactionId=" + transactionId
1220
					+ "&orderStatus=" + orderStatus + "&" + formData;
1221
	var cancellationResult = function(response) {
1222
        $('#' + domId).html(response);
1223
    }
1224
 
1225
    $.ajax({
1226
        type : "POST",
1227
        url : uri,
1228
        success : cancellationResult
1229
    });
20110 kshitij.so 1230
 
1231
 
1232
}
1233
 
1234
function loadReturnTransactionsView(domId, params) {
1235
    $.ajax({
1236
        type : "GET",
1237
        url : "/crm/return-transactions",
1238
        data : params,
1239
        success : function(response) {
1240
            $('#' + domId).html(response);
1241
        }
1242
    });
1243
}
1244
 
1245
function loadReturnTransactionsDefectiveView(domId, params) {
1246
    $.ajax({
1247
        type : "GET",
1248
        url : "/crm/return-transactions!defectiveView",
1249
        data : params,
1250
        success : function(response) {
1251
            $('#' + domId).html(response);
1252
        }
1253
    });
1254
}
1255
 
1256
 
1257
function loadReturnTransactionsPane(domId, userId, returnType) {
1258
    $.ajax({
1259
        type : "GET",
1260
        url : "/crm/return-transactions!view?userId=" + userId + "&returnType="+returnType,
1261
        success : function(response) {
1262
            $('#' + domId).html(response);
20199 amit.gupta 1263
            RETURN.orderTable = $('#user-orders').dataTable({
20110 kshitij.so 1264
                "aaSorting" : [ [ 1, 'desc' ] ],
1265
                "bAutoWidth": false,
1266
                "fnDrawCallback": function() { truncateText(125); },
1267
                "iDisplayLength" : 10,
1268
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1269
            });
1270
        }
1271
    });
1272
}
1273
 
1274
function storeTblValues()
1275
{
1276
    var tableData = new Array();
20199 amit.gupta 1277
	var counter=-1;
1278
    $(RETURN.orderTable).find('tr').each(function(row, tr){
20179 aman.kumar 1279
    	if($(tr).find('td:eq(3)').find('input').val()!='0'){
20199 amit.gupta 1280
    	counter++;
1281
    	tableData[counter]={
20110 kshitij.so 1282
            "orderId" : $(tr).find('td:eq(0)').text()
1283
            , "returnQty" :$(tr).find('td:eq(3)').find('input').val()
1284
            , "action" : $(tr).find('td:eq(4)').find('select').val()
1285
            , "returnPickupType" : $(tr).find('td:eq(5)').find('select').val()
20179 aman.kumar 1286
        }   
1287
    }
20110 kshitij.so 1288
    }); 
1289
    tableData.shift();
1290
    return tableData;
1291
}
1292
 
1293
function storeTblValues2()
1294
{
1295
    var tableData = new Array();
1296
 
1297
    $('#confirm-return-orders-table tr').each(function(row, tr){
1298
    	tableData[row]={
1299
            "orderId" : $(tr).find('td:eq(0)').text()
1300
            , "returnQty" :$(tr).find('td:eq(1)').text()
1301
            , "action" : $(tr).find('td:eq(2)').find('select').val()
1302
            , "returnPickupType" : $(tr).find('td:eq(3)').find('select').val()
1303
        }    
1304
    }); 
1305
    tableData.shift();
1306
    return tableData;
1307
}
1308
 
1309
function validateReturn(tableData, userId, returnType, domId){
1310
 
1311
	var params = "tableData=" + tableData + "&userId=" + userId + "&returnType=" + returnType;
1312
 
1313
	$.ajax({
1314
        type : "GET",
1315
        url : "/crm/return-transactions!validateReturn",
1316
        data : params,
1317
        success : function(response) {
1318
        	if(new String("false").valueOf() == new String(response.trim()).valueOf()){
1319
        		alert("Data not validated at server end");
1320
			}
1321
			else {
1322
				$('#' + domId).html(response);
1323
				orderTable = $('#confirm-return-orders-table').dataTable({
1324
	                "aaSorting" : [ [ 1, 'desc' ] ],
1325
	                "bAutoWidth": false,
1326
	                "iDisplayLength" : 10,
1327
	                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1328
	            });
1329
 
1330
				addressTable = $('#user-addresses-return-order').dataTable({
1331
	                "aaSorting" : [ [ 1, 'desc' ] ],
1332
	                "bAutoWidth": false,
1333
	                "iDisplayLength" : 10,
1334
	                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1335
	            });
1336
			}
1337
        }
1338
    });
1339
}
1340
 
1341
function submitAddressForReturnOrder(params,userId,returnType,tableData,domId) {
1342
 
1343
    $.ajax({
1344
        type : "GET",
1345
        url : "/crm/return-transactions!addNewAddress",
1346
        data : params,
1347
        success : function(response) {
1348
        	if (response.trim()==""){
1349
        		alert("Address added successfully");
1350
        		validateReturn(tableData, userId, returnType, domId)
1351
        	}
1352
        	else{
1353
        		alert(response);
1354
        	}
1355
        }
1356
    });
1357
}
1358
 
1359
function createReturnTransaction(tableData, userId, returnType, addressId, domId) {
1360
	var params = "tableData=" + tableData + "&userId=" + userId + "&returnType=" + returnType +"&addressId=" + addressId;
1361
	$.ajax({
1362
        type : "GET",
1363
        url : "/crm/return-transactions!createReturnTransaction",
1364
        data : params,
1365
        success : function(response) {
1366
        	if(response.trim()==="0"){
1367
        		alert("Problem while creating return transaction.");
1368
        	}
1369
        	else{
1370
        		$('#' + domId).html(response);
1371
        		$('#user-return-orders').dataTable({
1372
                    "aaSorting" : [ [ 1, 'desc' ] ],
1373
                    "bAutoWidth": false,
1374
                    "aoColumns" : [{ "sWidth": "5%" },
1375
                                   { "sWidth": "10%" },
1376
                                   { "sWidth": "20%" },
1377
                                   { "sWidth": "10%" },
1378
                                   { "sWidth": "10%" },
1379
                                   { "sWidth": "20%" },
1380
                                   { "sWidth": "25% "}],
1381
                    "fnDrawCallback": function() { truncateText(125); },
1382
                    "iDisplayLength" : 10,
1383
                    "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1384
                });
1385
        	}
1386
        }
1387
    });
1388
}
1389
 
1390
function viewReturnTransaction(returnTransactionId, domId){
1391
 
1392
	var params = "returnTransactionId=" + returnTransactionId;
1393
 
1394
	$.ajax({
1395
        type : "GET",
1396
        url : "/crm/return-transactions!viewReturnTransaction",
1397
        data : params,
1398
        success : function(response) {
1399
        	$('#' + domId).html(response);
1400
    		$('#user-return-orders').dataTable({
1401
                "aaSorting" : [ [ 1, 'desc' ] ],
1402
                "bAutoWidth": false,
1403
                "aoColumns" : [{ "sWidth": "5%" },
1404
                               { "sWidth": "10%" },
1405
                               { "sWidth": "20%" },
1406
                               { "sWidth": "10%" },
1407
                               { "sWidth": "10%" },
1408
                               { "sWidth": "20%" },
1409
                               { "sWidth": "25% "}],
1410
                "fnDrawCallback": function() { truncateText(125); },
1411
                "iDisplayLength" : 10,
1412
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1413
            });
1414
        }
1415
    });
1416
}
1417
 
1418
function changeStatusForReturnTransaction(returnTransactionId, newReturnTransactionStatus, domId) {
1419
 
1420
	var params = "returnTransactionId=" + returnTransactionId + "&newReturnTransactionStatus=" + newReturnTransactionStatus;
1421
 
1422
    $.ajax({
1423
        type : "GET",
1424
        url : "/crm/return-transactions!changeStatusForReturnTransaction",
1425
        data : params,
1426
        success : function(response) {
1427
        	alert(response);
1428
        	viewReturnTransaction(returnTransactionId, domId);
1429
        }
1430
    });
1431
}
1432
 
1433
function viewReturnOrderInfo(returnOrderId, domId) {
1434
 
1435
	var params = "returnOrderId=" + returnOrderId;
1436
 
1437
	$.ajax({
1438
        type : "GET",
1439
        url : "/crm/return-transactions!getReturnOrderInfoForId",
1440
        data : params,
1441
        success : function(response) {
1442
        	$('#' + domId).html(response);
1443
        }
1444
    });
1445
}
1446
 
1447
function loadReturnPickUpPane(domId, userId){
1448
	$.ajax({
1449
        type : "GET",
1450
        url : "/crm/return-transactions!viewPickUp?userId=" + userId,
1451
        success : function(response) {
1452
            $('#' + domId).html(response);
1453
            $('#user-orders-pickup').dataTable({
1454
                "aaSorting" : [ [ 1, 'desc' ] ],
1455
                "bAutoWidth": false,
1456
                "fnDrawCallback": function() { truncateText(125); },
1457
                "iDisplayLength" : 10,
1458
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1459
            });
1460
        }
1461
    });
1462
}
1463
 
1464
function confirmPickup(userId, domId){
1465
	var returnOrderIdsArray = new Array();
1466
	$('#user-orders-pickup tr').each(function(row, tr){
1467
		if($(tr).find('td:eq(6)').find('input').is(":checked")){
1468
    		var returnOrderId = $(tr).find('td:eq(6)').find('input').val();
1469
    		returnOrderIdsArray.push(returnOrderId);
1470
    	} 
1471
    });
1472
 
1473
	if (returnOrderIdsArray.length ==0){
1474
		alert("Please select orders for pickup");
1475
		return false;
1476
	}
1477
 
1478
	var params = "returnOrderIdsForPickUp=" +returnOrderIdsArray;
1479
 
1480
	$.ajax({
1481
        type : "GET",
1482
        url : "/crm/return-transactions!createReturnPickup",
1483
        data : params,
1484
        success : function(response) {
1485
        	$('#' + domId).html(response);
1486
        	$('#user-orders-pickup').dataTable({
1487
                "aaSorting" : [ [ 1, 'desc' ] ],
1488
                "bAutoWidth": false,
1489
                "fnDrawCallback": function() { truncateText(125); },
1490
                "iDisplayLength" : 10,
1491
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1492
            });
1493
        },
1494
        error : function() {
1495
			alert("Unable to create pick up");
1496
		}
1497
    });
1498
 
1499
}
1500
 
1501
function viewReturnPickup(pickupRequestId, domId){
1502
 
1503
	var params = "pickupRequestId=" + pickupRequestId;
1504
 
1505
	$.ajax({
1506
        type : "GET",
1507
        url : "/crm/return-transactions!viewReturnPickup",
1508
        data : params,
1509
        success : function(response) {
1510
        	$('#' + domId).html(response);
1511
        	$('#user-orders-pickup').dataTable({
1512
                "aaSorting" : [ [ 1, 'desc' ] ],
1513
                "bAutoWidth": false,
1514
                "aoColumns" : [{ "sWidth": "10%" },
1515
                               { "sWidth": "10%" },
1516
                               { "sWidth": "10%" },
1517
                               { "sWidth": "25%" },
1518
                               { "sWidth": "10%" },
1519
                               { "sWidth": "10%" },
1520
                               { "sWidth": "25% "}],
1521
                "fnDrawCallback": function() { truncateText(125); },
1522
                "iDisplayLength" : 10,
1523
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1524
            });
1525
        }
1526
    });
1527
}
1528
 
1529
function changeRequestPickupStatus(pickupRequestId, pickupRequestNo, logisticProviderId, pickupStatus, promised_pickup_timestamp, pickedUpAt, domId){
1530
 
1531
	var params = "pickupRequestId=" +pickupRequestId + "&pickupRequestNo=" + pickupRequestNo + "&logisticProviderId=" + logisticProviderId + "&pickupStatus=" +
1532
	pickupStatus + "&promised_pickup_timestamp=" + promised_pickup_timestamp + "&pickedUpAt=" + pickedUpAt;
1533
	$.ajax({
1534
        type : "GET",
1535
        url : "/crm/return-transactions!updateReturnPickup",
1536
        data : params,
1537
        success : function(response) {
1538
        	alert(response);
1539
        	viewReturnPickup(pickupRequestId, domId);
1540
        }
1541
    });
1542
 
1543
}
1544
 
1545
function showAllReturnTransactions(userId, domId){
1546
var params = "userId=" + userId;
1547
 
1548
	$.ajax({
1549
        type : "GET",
1550
        url : "/crm/return-transactions!getReturnTransactionsForUser",
1551
        data : params,
1552
        success : function(response) {
1553
        	$('#' + domId).html(response);
1554
        	$('#all-return-transactions').dataTable({
1555
                "aaSorting" : [ [ 1, 'desc' ] ],
1556
                "bAutoWidth": false,
1557
                "fnDrawCallback": function() { truncateText(125); },
1558
                "iDisplayLength" : 10,
1559
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1560
            });
1561
        }
1562
    });
1563
} 
1564
 
1565
function splitReturnOrder(params){
1566
 
1567
	$.ajax({
1568
        type : "GET",
1569
        url : "/crm/return-transactions!splitReturnOrder",
1570
        data : params,
1571
        success : function(response) {
1572
        	alert(response);
1573
        	location.reload();
1574
        },
1575
        error : function() {
1576
			alert("Unable to split returnorder");
1577
		}
1578
    });
1579
}
1580
 
1581
function showHideRefundDiv(refundType){
1582
	if (refundType === "1"){
1583
		if ($('#chequeDetails').css('display') == 'none') {
1584
			$('#chequeDetails').show();
1585
			$('#couponDetails').hide();
1586
		}
1587
	}
1588
	if (refundType === "3"){
1589
		if ($('#couponDetails').css('display') == 'none') {
1590
			$('#couponDetails').show();
1591
			$('#chequeDetails').hide();
1592
		}
1593
	}
1594
	if (refundType === "4" || refundType === "0"){
1595
		$('#chequeDetails').hide();
1596
		$('#couponDetails').hide();
1597
	}
1598
}
1599
 
21934 amit.gupta 1600
function verifyDoc(userId){
1601
	var gstin = $("#gstin").val();
1602
	params = {gstin:gstin, userId:userId}
1603
	$.ajax({
1604
        type : "GET",
1605
        url : "/crm/verify-doc",
1606
        data : params,
1607
        success : function(response) {
1608
        	alert(response);
1609
        	location.reload();
1610
        },
1611
        error : function() {
1612
			alert("Unable to split returnorder");
1613
		}
1614
    });
1615
}
20110 kshitij.so 1616
//