Files
siaupheng dcd13bb9df Refactor printing logic across multiple scripts to use method chaining for improved readability and consistency
- Updated Printer and PrinterPos instantiation to use method chaining with addParam instead of add_param.
- Refactored print functions in various modules including opname.js, pos.js, tukar.js, ppobtx.js, prabayar.js, and multiple report scripts.
- Enhanced code clarity and maintainability by standardizing parameter addition for print jobs.
2026-11-02 14:03:32 +07:00

307 lines
12 KiB
JavaScript

/*******************************************************************
PHP Class : /Controller/Ppob/PrabayarController
Description : Transaksi Prabayar PPOB
Created By : Siau Pheng ([email protected]).
Created Date : March 15th, 2017.
Last Modified : September 16th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var PrabayarJS = {
PHP: '',
KODE: '',
POLE_DISP: null,
POLE_CONF: {},
Simpan: false,
KATE_PREFIX: [1,2,3,4],
KATE_TOKEN: [5],
index() {
$('#Cari_PPOB').keydown((e) => {
var key = e.keyCode || e.which || 0;
if (key==13 && e.target.value!='') this.data_query('tabel-tx');
});
$('#butSearch').click((e) => this.data_query('tabel-tx'));
$('#butAll').click(() => {
$('#Cari_PPOB').val('');
this.data_query('tabel-tx');
});
this.data_query('master');
//POLE DISPLAY
this.data_query('pole-config');
},
proses_print(oc, no_cetak) {
new PrinterPos('apps/php/repo/nota.php')
.addParam("data", "ppob-pos")
.addParam("Nomor_Cetak", no_cetak)
.addParam("Open_Cash", oc)
.exec();
},
proses_delete() {
new Request_JSF({
url: this.PHP + '/table_tx',
sendParam: ['mode_detail=delete','No_TX']
}).send();
},
proses_reproc(ft) {
new Request_JSF({
url: this.PHP + '/table_tx',
sendParam: ['mode_detail=reproc','No_TX','FT='+ft]
}).send();
},
proses_cancel() {
FoniaJS.showConfirm('Konfirmasi', 'Apakah Anda yakin ingin membatalkan ?', () => this.data_query('master','cancel'), 'danger');
},
nota_print(acell) {
FoniaJS.showConfirm('Konfirmasi', 'Yakin ingin cetak ulang Nota "'+acell[0]+'" ?', () => {
this.proses_print(0, acell[0]);
}, 'info');
},
nota_delete(acell) {
FoniaJS.showConfirm('Konfirmasi', 'Yakin akan hapus Nota "'+acell[0]+'" ?', () => {
FoniaJS.showAuth(() => {
$('#No_TX').val(acell[0]);
this.proses_delete();
}, this, 'DELETE '+acell[0]);
}, 'danger');
},
nota_reproc(acell) {
FoniaJS.showConfirm('Konfirmasi', 'Yakin proses ulang "'+acell[0]+'" ?', () => {
$('#No_TX').val(acell[0]);
this.proses_reproc();
}, 'warning');
},
nota_detail(acell) {
new Request({
url: this.PHP + '/form_tx',
sendParam: ['No_TX='+acell[0]],
onSuccess: (adata) => {
this.winInfo = FoniaJS.showWindow('Info', 'Informasi Transaksi', adata.html, 'lg');
}
}).send();
},
kasir_show() {
if ($('#Tujuan').val()=='') {
FoniaJS.showInfo('Silahkan masukkan Nomor Tujuan !');
FoniaJS.setFocus('#Tujuan');
return;
}
if ($('#ProdukID').val()==0) {
FoniaJS.showInfo('Silahkan pilih Jenis Produk !');
$('#ProdukID').focus();
return;
}
new Request({
url: this.PHP + '/form_kasir',
sendParam: ['No_TX','Harga_Jual'],
onSuccess: (adata) => {
this.winKasir = FoniaJS.showWindow('Kasir', 'Informasi Pembayaran', adata.html, 'lg', '', () => {
//POLE DISPLAY
if (this.POLE_CONF.ENABLE){
this.POLE_DISP.Send([{'t':'Total '+adata.Total_Disp,'a':'C'},{'t':'Tunai / Non Tunai ?','a':'C'}]);
}
$('#butKBayar').click(() => this.kasir_simpan());
$('#butKBatal').click(() => $('#Tujuan').focus());
$('#popTotal_Tunai').keyup((e) => {
if (13 == e.which && parseFloat(e.target.value) == 0){
e.target.value = FoniaJS.FloatToStr($('#Harga_Jual').val());
}
if (27 == e.which) {
FoniaJS.closeWindow(this.winKasir);
$('#Tujuan').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($('#Harga_Jual').val()-FoniaJS.StrToFloat($('#popTotal_Tunai').val()));
}
if (27 == e.which) {
FoniaJS.closeWindow(this.winKasir);
$('#Tujuan').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($('#Harga_Jual').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() {
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() {
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');
},
data_query(tipe, mode) {
if (tipe=='master'){
mode = (mode) ? mode : '';
var sparam = ['mode='+mode,'No_TX'];
if (-1 !== mode.search(/save/i)) sparam = ['mode='+mode,'Tujuan','No_HP','KateID','OpeID','ProdukID','Total_Tunai','Total_Kartu','Total_Bayar','KartuID','No_Kartu','Nama_Kartu'];
new Request({
url: this.PHP + '/form_master',
sendParam: sparam,
onSuccess: (ajson) => {
$('#divPOS2').html(ajson.html);
$('#ppobSIMPAN').click(() => this.kasir_show());
$('#ppobBATAL').click(() => this.proses_cancel());
this.data_query('tabel-tx');
this.oc_KateID();
$('#Tujuan').on({
keyup: (e) => {
if (e.target.value.length == 4 || 13 == e.which) this.oc_Tujuan();
},
blur: () => this.oc_Tujuan(),
click: () => $('#Tujuan').select()
});
$('#No_HP').click(() => $('#No_HP').select());
$('#KateID').focus();
if (-1!==$.inArray($('#mode').val(), ['reproc'])){
this.proses_reproc(1);
if ($.inArray(parseInt($('#KateID').val()), this.KATE_TOKEN) !== -1) {
if (socket.active) socket.emit('ppob-check', { 'UserID': FoniaJS.User.UID, 'CabID': FoniaJS.User.CabID });
} else {
this.proses_print(1, $('#No_TX').val());
}
//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=='tabel-tx'){
new Request_JSF({
url: this.PHP + '/table_tx',
sendParam: ['Cari_PPOB']
}).send();
} else if (tipe=='pole-config'){
new Request({
url: this.PHP + '/config_pole',
onSuccess: (acfg) => {
if (typeof acfg.pole == 'object'){
this.POLE_CONF = acfg.pole;
if (this.POLE_CONF.ENABLE){
this.POLE_DISP = new PoleDisplay(this.POLE_CONF.PORT);
this.POLE_DISP.Open();
}
}
}
}).send();
}
},
oc_KateID() {
if ($.inArray(parseInt($('#KateID').val()), this.KATE_TOKEN) !== -1) {
$('.rowToken').removeClass('d-none');
$('.rowPulsa').addClass('d-none');
} else {
$('.rowToken').addClass('d-none');
$('.rowPulsa').removeClass('d-none');
}
new Request_JSF({
url: this.PHP + '/option_operator',
sendParam: ['KateID'],
}).send();
},
oc_Tujuan() {
if ($('#Tujuan').val()=='') return false;
if ($.inArray(parseInt($('#KateID').val()), this.KATE_PREFIX) === -1) return false;
new Request_JSF({
url: this.PHP + '/option_operator',
sendParam: ['KateID','Tujuan'],
}).send();
},
oc_OpeID() {
if ($('#OpeID').val()==0) return false;
new Request_JSF({
url: this.PHP + '/option_produk',
sendParam: ['KateID','OpeID'],
}).send();
},
oc_ProdukID() {
const obj = $('#ProdukID');
var harga = $(obj).find(":selected").attr('olabel');
$('#Harga_Jual').val(harga);
}
};