Subversion Repositories SmartDukaan

Rev

Rev 36668 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
36641 ranu 1
<section class="wrapper">
2
	<div class="row">
3
		<div class="col-lg-12">
4
			<h3 class="page-header"><i class="icon_document_alt"></i> BEAT PLAN — BULK UPLOAD</h3>
5
			<ol class="breadcrumb">
6
				<li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
7
				<li><i class="icon_document_alt"></i>Beat Plan Bulk Upload</li>
8
			</ol>
9
		</div>
10
	</div>
11
 
12
	<div class="row">
13
		<div class="col-lg-8">
14
			<div class="panel panel-default">
15
				<div class="panel-heading">
16
					<strong>Upload Beat Plans CSV</strong>
17
					<a href="${rc.contextPath}/beatPlan/downloadTemplate" class="btn btn-xs btn-info pull-right">Download
18
						Template</a>
19
				</div>
20
				<div class="panel-body">
21
					<p style="margin-bottom:15px;color:#666;">
22
						Upload a CSV file to create beat plans and schedule them on the calendar in one go.<br>
23
						Each row defines one partner visit within a beat. Beats are grouped by <strong>beat_name +
24
						auth_user_id</strong>.
25
					</p>
26
 
27
					<div class="well" style="background:#f9f9f9;">
28
						<strong>CSV Format (one row = one day):</strong>
29
						<table class="table table-bordered table-condensed" style="margin-top:10px;font-size:12px;">
30
							<thead>
31
							<tr style="background:#eee;">
32
								<th>beat_name</th>
33
								<th>auth_user_id</th>
34
								<th>start_date</th>
35
								<th>day_number</th>
36
								<th>partner_codes</th>
37
							</tr>
38
							</thead>
39
							<tbody>
40
							<tr>
41
								<td>Jaipur East Route</td>
42
								<td>280</td>
43
								<td>2026-06-02</td>
44
								<td>1</td>
45
								<td>RJKAI1478,RJBUN1449,RJDEG1443</td>
46
							</tr>
47
							<tr>
48
								<td>Jaipur East Route</td>
49
								<td>280</td>
50
								<td></td>
51
								<td>2</td>
52
								<td>RJALR1362,RJBTR1388</td>
53
							</tr>
54
							<tr>
55
								<td>Jaipur East Route</td>
56
								<td>280</td>
57
								<td></td>
58
								<td>3</td>
59
								<td>RJRSD1518,RJSML356</td>
60
							</tr>
61
							<tr style="border-top:2px solid #ccc;">
62
								<td>Agra Circuit</td>
63
								<td>145</td>
64
								<td>2026-06-05</td>
65
								<td>1</td>
66
								<td>UPAGR101,UPAGR102,UPAGR103</td>
67
							</tr>
68
							</tbody>
69
						</table>
70
						<p style="font-size:11px;color:#888;">
71
							<strong>beat_name</strong>: Name for the beat — <strong>only needed on day 1</strong>. Leave
72
							blank for day 2, 3 etc (auto-uses day 1's name). Extra spaces are normalized
73
							automatically.<br>
74
							<strong>auth_user_id</strong>: ID of the sales user<br>
75
							<strong>start_date</strong>: Start date (YYYY-MM-DD) — <strong>only needed on day 1</strong>.
76
							System auto-calculates day 2, 3 etc skipping holidays. Leave empty for unscheduled beat.<br>
77
							<strong>day_number</strong>: Day within the beat (1, 2, 3...)<br>
78
							<strong>partner_codes</strong>: Comma-separated partner codes for this day (in visit
79
							order)<br><br>
80
							Multiple users &amp; beats in one file — just use different auth_user_id.
81
						</p>
82
					</div>
83
 
84
					<form id="beat-bulk-form" enctype="multipart/form-data" style="margin-top:15px;">
85
						<div class="form-group">
86
							<label>Select CSV File</label>
87
							<input type="file" id="beat-bulk-file" name="file" accept=".csv" class="form-control">
88
						</div>
89
						<div class="checkbox" style="margin-bottom:10px;">
90
							<label><input type="checkbox" id="beat-bulk-include-sundays"> Include Sundays (don't skip
91
								Sundays when scheduling)</label>
92
						</div>
93
						<button type="button" class="btn btn-primary beat-bulk-submit">Upload & Process</button>
94
					</form>
95
 
96
					<div id="beat-bulk-result" style="display:none;margin-top:15px;"></div>
97
				</div>
98
			</div>
99
		</div>
100
	</div>
101
</section>
102
 
103
<script>
104
	$(document).on('click', '.beat-bulk-submit', function () {
105
		var fileInput = document.getElementById('beat-bulk-file');
106
		if (!fileInput.files || !fileInput.files[0]) {
107
			alert('Please select a CSV file');
108
			return;
109
		}
110
 
111
		var formData = new FormData();
112
		formData.append('file', fileInput.files[0]);
113
		formData.append('includeSundays', $('#beat-bulk-include-sundays').is(':checked'));
114
 
115
		var $btn = $(this);
116
			$btn.prop('disabled', true).text('Processing...');
117
 
118
		$.ajax({
119
			url: context + '/beatPlan/bulkUploadProcess',
120
			type: 'POST',
121
			data: formData,
122
			processData: false,
123
			contentType: false,
124
			success: function (response) {
125
					$btn.prop('disabled', false).text('Upload & Process');
126
				var data = response.response || response;
127
				var html = '<div class="alert alert-' + (data.errors > 0 ? 'warning' : 'success') + '">';
128
				html += '<strong>Done!</strong> ' + data.beatsCreated + ' beat(s) created.';
129
				if (data.errors > 0) {
130
					html += ' ' + data.errors + ' error(s).';
131
					html += '<ul style="margin-top:8px;font-size:12px;">';
132
					(data.errorMessages || []).forEach(function (msg) {
133
						html += '<li>' + msg + '</li>';
134
					});
135
					html += '</ul>';
136
				}
137
				html += '</div>';
138
				$('#beat-bulk-result').html(html).show();
139
			},
140
			error: function (xhr) {
141
					$btn.prop('disabled', false).text('Upload & Process');
142
				$('#beat-bulk-result').html('<div class="alert alert-danger">Error: ' + (xhr.responseText || xhr.statusText) + '</div>').show();
143
			}
144
		});
145
	});
146
</script>