first commit

This commit is contained in:
2026-01-22 11:06:19 +07:00
commit c877faf5a0
168 changed files with 19843 additions and 0 deletions
+525
View File
@@ -0,0 +1,525 @@
/*******************************************************************
App. Name : INVENTORY AND SALES SYSTEMS
Module : /apps/js/iss/pos.js
Desc. : JS - Transaksi Penjualan / Kasir POS
Created By : Siau Pheng ([email protected]).
Created Date : August 5th, 2012.
Last Modified : January 21st, 2026.
(c) 2012 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var POSJS = {
PHP: '',
KODE: '',
POLE_DISP: null,
POLE_CONF: {},
loading: function(){
FoniaJS.AutoComplete('#Nama_Produk', this.PHP, ['data=auto-produk','No_Jual'], {'selectFunc': POSJS.Produk_Comp, 'keyFunc': POSJS.Produk_Key, 'breakValue': ['*9']});
$('#Nama_Produk').click(() => $('#Nama_Produk').select());
$('#POS_Qty').on({
keyup: (e) => {
(13 == e.which) && $('#Nama_Produk').focus();
},
click: () => $('#POS_Qty').select()
});
this.data_query('master');
//POLE DISPLAY
this.data_query('pole-config');
},
proses_oc: function(){
var cetak = new cPRINTERPOS(FoniaJS.WEB_PATH+'apps/php/repo/nota.php');
cetak.add_param("data", "opencash");
cetak.exec();
$('#Nama_Produk').focus();
},
proses_print: function(oc){
var _no_jual = $('#No_Cetak').val();
var cetak = new cPRINTERPOS(FoniaJS.WEB_PATH+'apps/php/repo/nota.php');
cetak.add_param("data", "nota-pos");
cetak.add_param("Nomor_Cetak", _no_jual);
cetak.add_param("Open_Cash", oc);
cetak.exec();
},
proses_cancel: function(){
if ($('#Total_Item').val()==0) {
FoniaJS.showInfo('Tidak ada item barang !');
return;
}
FoniaJS.showConfirm('Konfirmasi', 'Apakah Anda yakin ingin membatalkan ?<br>Semua item transaksi nota ini akan dihapus !', () => this.data_query('master','cancel'), 'danger');
},
nota_brow: function(){
var _isi = new String('<div class="row mb-1"><div class="col"><div class="input-group"><input class="form-control" id="Cari_Nota" placeholder="Kunci Pencarian" type="text"><button class="btn btn-info shadow-none" type="button" id="butSearch">Cari</button><button class="btn btn-secondary shadow-none" type="button" id="butAll">Semua</button></div></div></div><div id="divBrowNota">&nbsp;</div>');
this.winBNota = FoniaJS.showWindow('BNota', 'Daftar Transaksi', _isi, 900, '', () => {
$('#winBNota')
.find('#Cari_Nota').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('brow-nota');
}).end()
.find('#butSearch').click((e) => {
this.data_query('brow-nota');
}).end()
.find('#butAll').click(() => {
$('#winBNota').find('#Cari_Nota').val('');
this.data_query('brow-nota');
});
this.data_query('brow-nota');
});
},
nota_print: function(acell){
FoniaJS.closeWindow(this.winBNota);
FoniaJS.showConfirm('Konfirmasi', 'Yakin ingin cetak ulang Nota "'+acell[0]+'" ?', () => {
$('#No_Cetak').val(acell[0]);
this.proses_print(0);
}, 'info');
},
nota_select: function(acell){
FoniaJS.closeWindow(this.winBNota);
FoniaJS.showAuth(() => {
$('#No_Jual').val(acell[0]);
this.data_query('master', 'edit');
}, this, 'EDIT POS : '+acell[0]);
},
nota_delete: function(acell){
FoniaJS.closeWindow(this.winBNota);
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus Nota "'+acell[0]+'" ?', () => {
FoniaJS.showAuth(() => {
$('#No_Jual').val(acell[0]);
this.data_query('master', 'delete');
}, this, 'DELETE '+acell[0]);
}, 'danger');
},
pending_brow: function(){
this.winBPend = FoniaJS.showWindow('BPend', 'Daftar Transaksi Pending', '<div id="divBrowPending">&nbsp;</div>', 900, '', () => this.data_query('brow-pending'));
},
pending_select: function(acell){
$('#No_Jual').val(acell[0]);
FoniaJS.closeWindow(this.winBPend);
this.data_query('master', 'pending-edit');
},
pending_delete: function(acell){
FoniaJS.closeWindow(this.winBPend);
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus Transaksi Pending "'+acell[0]+'" ?', () => {
$('#No_Jual').val(acell[0]);
this.data_query('master', 'pending-delete');
}, 'danger');
},
produk_add: function(){
new Request({
url: this.PHP,
sendParam: ['data=info_produk'],
onSuccess: (txt) => {
this.winBarang = FoniaJS.showWindow('Barang', 'Penambahan Item Barang', txt, 600, [{},{i:'butBatal'},{i:'butSimpan',v:'Simpan',c:'success'}], () => {
$('#winBarang')
.find('#butSimpan').click(() => this.produk_simpan()).end()
.find('#butBatal').click(() => $('#Nama_Produk').focus()).end()
.find('#Kode_Barcode').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Nama_Barang');
}).end()
.find('#Nama_Barang').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Grup_InvID');
}).end()
.find('#Grup_InvID').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#StokID');
}).end()
.find('#StokID').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Harga_Jual');
});
FoniaJS.setFocus('#Kode_Barcode');
});
}
}).send();
},
produk_simpan: function(){
new Request.JSON({
url: this.PHP,
sendParam: ['data=simpan_produk','Kode_Barcode','Nama_Barang','Grup_InvID','StokID','Harga_Jual'],
onSuccess: (ajson) => {
if (ajson.msg) FoniaJS.showInfo(ajson.msg);
FoniaJS.closeWindow(this.winBarang);
$('#Nama_Produk').val('').focus();
}
}).send();
},
produk_brow: function(){
var _isi = new String('<div class="row mb-1"><div class="col"><div class="input-group"><input class="form-control" id="Cari_Produk" placeholder="Kunci Pencarian" type="text"><button class="btn btn-info shadow-none" type="button" id="butSearch">Cari</button><button class="btn btn-secondary shadow-none" type="button" id="butAll">Semua</button></div></div></div><div id="divBrowProduk">&nbsp;</div>');
this.winBProduk = FoniaJS.showWindow('BProduk', 'Daftar Barang', _isi, 900, '', () => {
$('#winBProduk')
.find('#Cari_Produk').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('brow-produk');
}).end()
.find('#butSearch').click((e) => {
this.data_query('brow-produk');
}).end()
.find('#butAll').click(() => {
$('#winBProduk').find('#Cari_Produk').val('');
this.data_query('brow-produk');
});
this.data_query('brow-produk');
});
},
produk_select: function(acell){
FoniaJS.closeWindow(this.winBProduk);
this.detail_produk('insert', 0, acell[0], acell[1]);
},
detail_produk: function(mode, ID, InvID, SatuanID){
new Request({
url: this.PHP,
sendParam: ['data=detail_produk','mode_detail='+mode,'No_Jual','ID='+ID,'InvID='+InvID,'SatuanID='+SatuanID],
onSuccess: (txt) => {
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', txt, 600, [{},{i:'butBatal'},{i:'butSimpan',v:'Simpan',c:'success'}], () => {
$('#winDetail')
.find('#butSimpan').click(() => this.detail_simpan()).end()
.find('#butBatal').click(() => $('#Nama_Produk').focus()).end()
.find('#Qty').keyup((e) => {
this.Hitung_Detail(1);
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Harga_Diskon');
}).end()
.find('#Harga_Diskon').keyup((e) => {
this.Hitung_Detail(1);
if (13==e.which) {
if (FoniaJS.StrToFloat($('#Qty').val())>0) this.detail_simpan();
}
}).end()
.find('#Persen_Diskon').keyup((e) => {
this.Hitung_Detail(2);
if (13==e.which) {
if (FoniaJS.StrToFloat($('#Qty').val())>0) this.detail_simpan();
}
});
this.Hitung_Detail(1);
FoniaJS.setFocus('#Qty');
});
}
}).send();
},
detail_ubah: function(acell){
if (parseInt(acell[3])==1){
this.detail_lain('update', acell[0]);
} else
this.detail_produk('update', acell[0], acell[1], acell[2]);
},
detail_hapus: function(acell){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=detail','mode_detail=delete','No_Jual','ID='+acell[0]],
onSuccess: () => {
$('#Nama_Produk').focus();
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':'..','a':'L'},{'t':'Total '+$('#Total_Disp').html(),'a':'R'}]);
}
}
}).send();
},
detail_simpan: function(){
if (FoniaJS.StrToFloat($('#Persen_Diskon').val())>=100) {
FoniaJS.showInfo('Nilai Diskon diluar batas !');
return false;
}
new Request.JSONF({
url: this.PHP,
sendParam: ['data=detail','mode_detail','No_Jual','InvID','SatuanID','Qty','Harga_Beli','Harga_Jual','Harga_Diskon','ID','Ket'],
onSuccess: () => {
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':$('#Nama_Lengkap').val(),'a':'L'},{'t':'Total '+$('#Total_Disp').html(),'a':'R'}]);
}
FoniaJS.closeWindow(this.winDetail);
$('#Nama_Produk').val('');
$('#Nama_Produk').focus();
}
}).send();
},
detail_lain: function(mode, ID){
new Request({
url: this.PHP,
sendParam: ['data=detail_lain','mode_detail='+mode,'No_Jual','ID='+ID],
onSuccess: (txt) => {
this.winDetail = FoniaJS.showWindow('Detail', 'Detail Barang', txt, 600, [{},{i:'butBatal'},{i:'butSimpan',v:'Simpan',c:'success'}], () => {
$('#winDetail')
.find('#butSimpan').click(() => this.detail_simpan()).end()
.find('#butBatal').click(() => $('#Nama_Produk').focus()).end()
.find('#Ket').keyup((e) => {
if ('' === e.target.value) return false;
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Qty');
}).end()
.find('#Qty').keyup((e) => {
this.Hitung_Detail(0);
if (-1!==$.inArray(e.which, [13,9])) FoniaJS.setFocus('#Harga_Jual');
}).end()
.find('#Harga_Jual').keyup((e) => {
this.Hitung_Detail(0);
if (13==e.which) {
if (FoniaJS.StrToFloat($('#Qty').val())>0 && FoniaJS.StrToFloat($('#Harga_Jual').val())>0) this.detail_simpan();
}
});
this.Hitung_Detail(0);
FoniaJS.setFocus('#Ket');
});
}
}).send();
},
kasir_show: function(){
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':'Total '+$('#Total_Disp').html(),'a':'C'},{'t':'Tunai / Non Tunai ?','a':'C'}]);
}
if ($('#Total_Item').val()==0) {
FoniaJS.showInfo('Belum ada transaksi !');
return;
}
new Request.JSON({
url: this.PHP,
sendParam: ['data=info_kasir','No_Jual','Total_Nota'],
onSuccess: (adata) => {
this.winKasir = FoniaJS.showWindow('Kasir', 'Informasi Pembayaran', adata.html, 500, '', () => {
$('#butKPend').click(() => this.kasir_pending());
$('#butKBayar').click(() => this.kasir_simpan());
$('#butKBatal').click(() => $('#Nama_Produk').focus());
$('#popTotal_Tunai').keyup((e) => {
if (13 == e.which && parseFloat(e.target.value) == 0){
e.target.value = FoniaJS.FloatToStr($('#Total_Nota').val());
}
if (27 == e.which) {
FoniaJS.closeWindow(this.winKasir);
$('#Nama_Produk').focus();
}
this.kasir_hitung();
if (parseFloat(e.target.value) == 0) return false;
if (13 == e.which) $('#butKBayar').focus();
});
$('#popTotal_Kartu').keyup((e) => {
if (13 == e.which && $('#popKartuID').val() > 0 && parseFloat(e.target.value) == 0){
e.target.value = FoniaJS.FloatToStr($('#Total_Nota').val()-FoniaJS.StrToFloat($('#popTotal_Tunai').val()));
}
if (27 == e.which) {
FoniaJS.closeWindow(this.winKasir);
$('#Nama_Produk').focus();
}
this.kasir_hitung();
if (parseFloat(e.target.value) == 0) return false;
if (13 == e.which) $('#butKBayar').focus();
});
$('#popKartuID').change(() => {
if ($('#popKartuID').val() > 0){
if (parseFloat($('#popTotal_Kartu').val()) == 0) $('#popTotal_Kartu').val(FoniaJS.FloatToStr($('#Total_Nota').val()-FoniaJS.StrToFloat($('#popTotal_Tunai').val())));
$('.ckartu').removeClass('d-none');
} else {
$('#popTotal_Kartu').val('0.00');
$('.ckartu').addClass('d-none');
}
this.kasir_hitung();
FoniaJS.setFocus('#popTotal_Kartu');
});
$('#popTotal_Tunai').val(FoniaJS.FloatToStr($('#Total_Tunai').val()));
$('#popTotal_Kartu').val(FoniaJS.FloatToStr($('#Total_Kartu').val()));
$('#popTotal_Bayar').val($('#Total_Bayar').val());
$('#popKartuID').val($('#KartuID').val()).trigger('change');
$('#popNo_Kartu').val($('#No_Kartu').val());
$('#popNama_Kartu').val($('#Nama_Kartu').val());
$('#Total_Disp').html(adata.Total_Disp);
FoniaJS.setFocus('#popTotal_Tunai');
});
this.Simpan = false;
}
}).send();
},
kasir_hitung: function(){
const totBayar = FoniaJS.StrToFloat($('#popTotal_Tunai').val()) + FoniaJS.StrToFloat($('#popTotal_Kartu').val());
const totSisa = totBayar - FoniaJS.StrToFloat($('#popTotal_Jual').val());
$('#popTotal_Bayar').val(totBayar);
$('#popTotal_Sisa').val(FoniaJS.FloatToStr(totSisa, 2)).removeClass('border-danger border-success').addClass((totSisa < 0) ? 'border-danger' : 'border-success');
},
kasir_simpan: function(){
const totTunai = FoniaJS.StrToFloat($('#popTotal_Tunai').val());
const totKartu = FoniaJS.StrToFloat($('#popTotal_Kartu').val());
const jenKartu = $('#popKartuID').val();
if (jenKartu == 0 && totKartu > 0) {
FoniaJS.showInfo('Silakan pilih Jenis Pembayaran Non Tunai!');
FoniaJS.setFocus('#popKartuID');
return false;
} else if (jenKartu > 0 && totKartu == 0) {
FoniaJS.showInfo('Silakan masukkan Jumlah Pembayaran Non Tunai!');
FoniaJS.setFocus('#popKartuID');
return false;
}
if (FoniaJS.StrToFloat($('#popTotal_Sisa').val())<0) {
FoniaJS.showInfo('Pembayaran Transaksi tidak mencukupi!');
FoniaJS.setFocus('#popTotal_Bayar');
return false;
}
if (this.Simpan==true) {
FoniaJS.showError('Proses pembayaran sedang dilakukan!');
return;
}
this.Simpan = true;
$('#Total_Tunai').val(totTunai);
$('#Total_Kartu').val(totKartu);
$('#Total_Bayar').val($('#popTotal_Bayar').val());
$('#KartuID').val($('#popKartuID').val());
$('#No_Kartu').val($('#popNo_Kartu').val());
$('#Nama_Kartu').val($('#popNama_Kartu').val());
FoniaJS.closeWindow(this.winKasir);
this.data_query('master', 'save');
},
kasir_pending: function(){
FoniaJS.closeWindow(this.winKasir);
this.data_query('master', 'pending-save');
},
data_query: function(tipe, mode){
if (tipe=='master'){
mode = (mode) ? mode : '';
var sparam = ['data=master','mode='+mode,'No_Jual','No_Cetak'];
if (-1 !== mode.search(/save/i)) sparam = ['data=master','mode='+mode,'No_Jual','Tgl_Jual','Total_Tunai','Total_Kartu','Total_Bayar','KartuID','No_Kartu','Nama_Kartu'];
new Request({
url: this.PHP,
sendParam: sparam,
onSuccess: (txt) => {
$('#divPOS2').html(txt);
$('#posPEND').click(() =>this.pending_brow());
$('#posTAMBAH').click(() => this.produk_add());
$('#posBARANG').click(() => this.produk_brow());
$('#posNOTA').click(() => this.nota_brow());
$('#posSIMPAN').click(() => this.kasir_show());
$('#posBATAL').click(() => this.proses_cancel());
FoniaJS.User.Level>1 && $('#posBATAL').hide();
this.data_query('detail');
$('#Nama_Produk').focus();
if (-1!==$.inArray($('#mode').val(), ['print','opencd','saveonly'])){
if ($('#mode').val()=='print') this.proses_print(1);
if ($('#mode').val()=='opencd') this.proses_oc();
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':this.POLE_CONF.END1,'a':'C'},{'t':this.POLE_CONF.END2,'a':'C'}]);
}
} else {
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':this.POLE_CONF.START1,'a':'C'},{'t':this.POLE_CONF.START2,'a':'C'}]);
}
}
}
}).send();
} else if (tipe=='detail'){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=detail','No_Jual']
}).send();
} else if (tipe=='brow-produk'){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=brow-produk','Cari_Produk'],
onSuccess: () => {
FoniaJS.setFocus('#Cari_Produk');
}
}).send();
} else if (tipe=='brow-nota'){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=brow-nota','Cari_Nota'],
onSuccess: () => {
FoniaJS.setFocus('#Cari_Nota');
}
}).send();
} else if (tipe=='brow-pending'){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=brow-pending']
}).send();
} else if (tipe=='pole-config'){
new Request.JSONF({
url: this.PHP,
sendParam: ['data=pole-config'],
onSuccess: (acfg) => {
if (typeof acfg.pole == 'object'){
this.POLE_CONF = acfg.pole;
if (this.POLE_CONF.ENABLE){
this.POLE_DISP = new cPOLEDISPLAY(this.POLE_CONF.PORT);
this.POLE_DISP.Open();
}
}
}
}).send();
}
},
Produk_Comp: function(item){
var _qty = $('#POS_Qty').val();
var adata = item.data.split(':');
//todo: jika stok kosong tidak simpan hanya utk glamore
//if (parseInt(adata[3])>0 || _qty<0){
new Request.JSONF({
url: POSJS.PHP,
sendParam: ['data=detail','mode_detail=insert','No_Jual','InvID='+item.value,'SatuanID='+adata[0],'Qty='+_qty,'Harga_Beli='+adata[1],'Harga_Jual='+adata[2]],
onSuccess: () => {
$('#POS_Qty').val('1.00');
//POLE DISPLAY
if (POSJS.POLE_CONF.ENABLE){
POSJS.POLE_DISP.Send([{'t':item.text,'a':'L'},{'t':'Total '+$('#Total_Disp').html(),'a':'R'}]);
}
}
}).send();
/*} else {
this.winPesan = FoniaJS.showWindow('Pesan', 'Informasi Barang', '<div class="fs-3 text-center text-danger">Barang tidak tersedia atau habis !</div>', 300, [{},{i:'butTutup'}], () => {
$('#winPesan').find('#butTutup').click(() => $('#Nama_Produk').focus()).focus();
});
}*/
$('#Nama_Produk').val('').focus();
},
Produk_Key: function(key, val){
if (val == '*9') {
if (key == 13) POSJS.detail_lain('insert', 0);
} else {
if (key == 13) {
POSJS.kasir_show();
} else if (key == 117) {//f6
POSJS.proses_oc();
} else if (key == 119) {//f8
POSJS.produk_add();
} else if (key == 120) {//f9
POSJS.produk_brow();
}
}
},
onblur_Qty: function(){
if ($('#POS_Qty').val()==0) $('#POS_Qty').val('1.00');
},
Hitung_Detail: function(tipe){
if (tipe==1) $('#Persen_Diskon').val(FoniaJS.FloatToStr((FoniaJS.StrToFloat($('#Harga_Diskon').val())*100) / FoniaJS.StrToFloat($('#Harga_Jual').val()), 2));
if (tipe==2) $('#Harga_Diskon').val(FoniaJS.FloatToStr(FoniaJS.StrToFloat($('#Harga_Jual').val()) * FoniaJS.StrToFloat($('#Persen_Diskon').val()) * 0.01, 2));
$('#Jumlah').val(FoniaJS.FloatToStr(FoniaJS.StrToFloat($('#Qty').val()) * (FoniaJS.StrToFloat($('#Harga_Jual').val()) - FoniaJS.StrToFloat($('#Harga_Diskon').val())), 2));
}
};