add.pt
13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<html metal:use-macro="load: ../base.pt">
<div metal:fill-slot="content">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${request.title}</h3>
</div>
<div class="panel-body">
<form method="post" accept-charset="utf-8" id="myform" class="form-horizontal">
<div class="alert alert-danger" tal:condition="form and form.error and True or False">
<div class="error-msg-lbl">Kesalahan Pengisian Form</div>
<p class="error-msg">${form.errormsg}</p>
</div>
<div class="form-group" tal:repeat="f form">
<div id="item-${f.oid}" style="${f.widget.hidden and 'display:none;' or 'display:block;'}">
<label for="${f.oid}" class="control-label col-md-2 ${f.required and 'required' or ''} " id="req-${f.oid}">${f.title}</label>
<div class="col-md-3">
${structure:f.serialize()}
<p id="error-${f.oid}" class="help-block" tal:condition="f.error"
tal:repeat="error f.error.messages()">
${error}</p>
</div>
</div>
</div>
<hr/>
<div class="form-group">
<div class="col-md-4 col-md-offset-2">
<button type="submit" class="btn btn-primary" id="simpan" name="simpan"><i class="fa fa-fw fa-save"></i> Simpan</button>
<button type="submit" class="btn btn-warning" id="batal" name="batal"><i class="fa fa-fw fa-undo"></i> Tutup</button>
</div>
</div>
</form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<span style="margin-right: 20px;"><strong>Rincian Produk</strong></span>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="det-tambah" data-toggle="modal" data-target="#bkuModal">Tambah</button>
<button type="button" class="btn btn-success" id="det-edit">Edit</button>
</div>
</div>
<div class="panel-body">
<table id="table1" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th>Kode</th>
<th>Rekening</th>
<th>Produk</th>
<th>Qty</th>
<th>Harga</th>
<th>Jumlah</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div id="bkuModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Pilihan Produk</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<label class="control-label col-md-4">Produk :</label>
<div class="col-md-6">
<input type="hidden" id="produk_id">
<input type="text" id="produk_nm" class="form-control">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Kode :</label>
<div class="col-md-6">
<label id="produk_kode" class="form-control"></label>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Rekening :</label>
<div class="col-md-6">
<label id="produk_rekening" class="form-control"></label>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Harga :</label>
<div class="col-md-6">
<label id="produk_harga" class="form-control"></label>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">QTY :</label>
<div class="col-md-6">
<input type="text" id="produk_qty" class="form-control">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="btn_ok_modal"> OK </button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<div metal:fill-slot="scripts">
<script>
var dataDummy = [], idList = [], totalNilai = 0, mID = 0, editMode = false;
var oTable;
function sudahAda(id, current = 0) {
var ada = false;
if (idList.length > 0) {
for (var i = 0; i < idList.length; i++) {
if (current > 0) {
if (idList[i] == id && id != current) {
ada = true;
break;
}
} else {
if (idList[i] == id) {
ada = true;
break;
}
}
}
}
return ada;
}
function addDetail(simpan = false) {
if (simpan) {
var produkId = $('#produk_id').val();
if (sudahAda(produkId)) {
alert('Produk sudah ada di rincian produk');
return false;
}
var d = {
produk_id: produkId,
produk_nm: $('#produk_nm').val(),
produk_kode: $('#produk_kode').text(),
produk_rekening: $('#produk_rekening').text(),
produk_harga: $('#produk_harga').text(),
produk_qty: $('#produk_qty').val(),
produk_total: parseFloat($('#produk_harga').text()) * parseInt($('#produk_qty').val()),
};
if (parseInt(d['produk_qty']) <= 0) {
alert('Jumlah produk harus lebih dari 0');
return false;
}
dataDummy.push(d);
oTable.row.add(d).draw();
idList.push(produkId);
return true;
} else {
$('#produk_id').val(0);
$('#produk_nm').val('');
$('#produk_kode').text('');
$('#produk_rekening').text('');
$('#produk_harga').text(0);
$('#produk_qty').val(0);
}
}
function editDetail(simpan = false) {
var index = -1;
var n = dataDummy.length;
for (var i = 0; i < n; i++) {
if (dataDummy[i]['produk_id'] == mID) {
index = i;
break;
}
}
if (index < 0) {return false;}
if (simpan) {
var produkId = $('#produk_id').val();
var current = dataDummy[index]['produk_id'];
if (sudahAda(produkId, current)) {
alert('Produk sudah ada di rincian produk');
return false;
}
var d = {
produk_id: produkId,
produk_nm: $('#produk_nm').val(),
produk_kode: $('#produk_kode').text(),
produk_rekening: $('#produk_rekening').text(),
produk_harga: $('#produk_harga').text(),
produk_qty: $('#produk_qty').val(),
produk_total: parseFloat($('#produk_harga').text()) * parseInt($('#produk_qty').val()),
};
if (parseInt(d['produk_qty']) <= 0) {
alert('Jumlah produk harus lebih dari 0');
return false;
}
indexList = idList.indexOf(dataDummy[index]['produk_id']);
idList[indexList] = produkId;
dataDummy[index] = d;
oTable.rows().remove();
for (var i = 0; i < n; i++) {
oTable.row.add(dataDummy[i]).draw();
}
return true;
} else {
$('#produk_id').val(dataDummy[index]['produk_id']);
$('#produk_nm').val(dataDummy[index]['produk_nm']);
$('#produk_kode').text(dataDummy[index]['produk_kode']);
$('#produk_rekening').text(dataDummy[index]['produk_rekening']);
$('#produk_harga').text(dataDummy[index]['produk_harga']);
$('#produk_qty').val(dataDummy[index]['produk_qty']);
return true;
}
}
$(document).ready(function () {
var oldDetail = $('#bku_det').val();
idList = [];
if (oldDetail != '') {
dataDummy = JSON.parse(oldDetail);
for (var i = 0; i < dataDummy.length; i++) {
idList.push(dataDummy[i]['produk_id']);
}
}
////////////////////////////////////////////////////////////////////////
$('#partner_nm').typeahead({
"hint" : true,
"highlight": true,
"minLength": 1,
"remote" : "/partner/vendor/act?term=%QUERY",
},{
"name" : 'partner_nm',
"displayKey": 'value',
});
$('#partner_nm').bind('typeahead:selected', function(obj, datum, name) {
$('#partner_id').val(datum.id);
});
$('#bank_nm').typeahead({
"hint" : true,
"highlight": true,
"minLength": 1,
"remote" : "/departemen/bank/hon/act?term=%QUERY",
},{
"name" : 'bank_nm',
"displayKey": 'value',
});
$('#bank_nm').bind('typeahead:selected', function(obj, datum, name) {
console.log(datum);
$('#bank_id').val(datum.id);
$('#bank_kd').val(datum.kode);
});
$('#bank_kd').prop('readonly',true);
$('#produk_nm').typeahead({
"hint" : true,
"highlight": true,
"minLength": 1,
"remote" : "/bku/produk/hon/act?term=%QUERY",
},{
"name" : 'produk_nm',
"displayKey": 'value',
});
$('#produk_nm').bind('typeahead:selected', function(obj, datum, name) {
console.log(datum);
$('#produk_id').val(datum.id);
$('#produk_kode').text(datum.produk_kd);
$('#produk_harga').text(datum.produk_harga);
$('#produk_rekening').text(datum.rekening_kd);
});
////////////////////////////////////////////////////////////////////////
$('#tanggal').datepicker({
changeMonth: true,
changeYear: true,
format:'dd-mm-yyyy'
});
oTable = $('#table1').DataTable({
data : dataDummy,
scrollCollapse: true,
sort : false,
info : false,
filter : false,
autoWidth : false,
paginate : true,
paginationType: "full_numbers",
bLengthChange : false,
"destroy" : true,
"language" : {
"search" : "Cari: ",
"paginate" :{
"first" : "Awal ",
"last" : "Akhir ",
"previous": "Mundur ",
"next" : "Maju ",
},
"lengthMenu": " _MENU_ baris "
},
columns: [
{ data: "produk_kode" },
{ data: "produk_rekening" },
{ data: "produk_nm" },
{ data: "produk_qty", render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
{ data: "produk_harga", render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
{ data: "produk_total", render: $.fn.dataTable.render.number( ',', '.', 0, '' ) },
],
});
$('#table1 tbody').on('click', 'tr', function () {
oTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
mID = oTable.row( this ).data().produk_id;
});
$('#det-tambah').on('click', function() {
editMode = false;
addDetail();
});
$('#det-edit').on('click', function() {
if (!mID || mID == undefined || dataDummy.length < 1) {
alert('Silahkan pilih rincian produk yang akan dikoreksi')
return;
}
editMode = true;
if (editDetail()) {
$('#bkuModal').modal('show');
} else {
alert('Data tidak dapat dikoreksi')
}
});
$('#btn_ok_modal').on('click', function(){
if (editMode) {
if (editDetail(true)) {
$('#bkuModal').modal('hide');
editMode = false;
}
} else {
if (addDetail(true)) {
$('#bkuModal').modal('hide');
}
editMode = false;
}
});
$('#myform').on('submit', function() {
$('#bku_det').val(JSON.stringify(dataDummy));
return true;
});
totalNilai = parseFloat($('#nilai').val());
});
</script>
</div>
</html>