You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
17 KiB
JavaScript

import { _bbData } from "{{PATH}}/assets-js/module-lap-bb.js?v={time}";
import { temp } from "{{PATH}}/assets-js/module-lap-filter2.js?v={time}";
import { xlsx } from "{{PATH}}/assets-js/module-export-xlsx.js?v={time}";
import { Partisipasi } from "{js}module-data-partisipasi.js?v={time}";
globalThis.acc = JSON.parse(_id('acc').innerHTML);
globalThis.shup = JSON.parse(_id('shup').innerHTML);
_id('tahunv').innerHTML = tanggal().normal.split('-')[0];
temp();
const getSimpanan = function () {
return new Promise((resolve, reject) => {
try{
/**
_bbData(function (d) {
resolve(d)
}, function () {
if (_id('app').value == 'acc') {
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value}%" AND acc.app = 'acc'`;
} else if (_id('app').value == 'usp') {
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value}%" AND acc.app = 'usp'`;
} else {
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value}%"`;
}
},function(){
return `
SELECT main, nama_main, dk, kode rek, nama, total FROM bbtahunan WHERE tahun = '${Number(_val('tahun')) - 1}' ${_val('app') == 'acc,usp' ? `` : ` AND app = '${_val('app')}' `} AND nr = 'N'
UNION ALL
`;
})
*/
AuditDevQuery(`call ambil_neraca_akhir(${_id('tahun').value},'${_id('app').value}')`, function(d){
resolve(d)
})
}catch(e){
reject(e)
}
})
}
let loader = function (callback) {
let app = _id('app').value;
let d = _id('report').querySelector('tbody');
d.innerHTML = '';
let nm = '';
let last = '';
d.innerHTML =
`
<tr>
<td colspan="4">Sisa Hasil Usaha (SHU) KPRI Warpeka tahun ${_id('tahun').value} Sebesar <span id="besaran"></span></td>
</tr>
<tr>
<td style="height:10px;" colspan="4"></td>
</tr>
<tr>
<td style="font-weight:bold;" colspan="4">SHU tersebut dialokasikan sebagai berikut :</td>
</tr>
`+
shup.filter(function(c){
if (c.app == _id('app').value){
return c;
}
}).map(function(s, i){
return `
<tr style="border-bottom: 1px solid #777;">
<td width="50px">${i+1}</td>
<td width="200px">${s.nama}</td>
<td width="30px"><span style="display:inline-block;width:50px;text-align:right;margin-right:10px">${s.persen} %</span></td>
<td><span id="tot-shup-${i}" style="margin-left:10px;display:inline-block;"></span></td>
</tr>
`
}).join("")+
`
<tr>
<td style="height:10px;" colspan="4"></td>
</tr>
<tr>
<td style="font-weight:bold;" colspan="4">Pembagian SHU untuk Anggota</td>
</tr>
<tr>
<td colspan="4">1. ${(function(){
let app = _id('app').value;
if(app == 'acc'){
return ` Jumlah Simp. Pokok dan Simp. Wajib `;
}else{
return ` Jumlah Simp. Manasuka dan Simp. Wajib Pinjam `;
}
})()} anggota sebesar <span id="bsimpanan"></span> </td>
</tr>
<tr>
<td colspan="4">maka simpanan anggota per Rp. 1000,- mendapatkan simpanan sebesar :</td>
</tr>
<tr>
<td colspan="4">
<table>
<tr>
<td style="border-bottom: 1px solid #333;"> <span id="hsimpanan"></span> </td>
<td style="vertical-align: bottom;" rowspan="2"> x 1.000</td>
<td style="vertical-align: bottom;" rowspan="2"> = </td>
<td style="vertical-align: bottom;" rowspan="2"> <span id="gsimpanan"></span> </td>
</tr>
<tr>
<td><span id="tsimpanan"></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="height:10px;" colspan="4"></td>
</tr>
<tr>
<td colspan="4">2. ${(function () {
let app = _id('app').value;
if (app == 'acc') {
return ` Jumlah partisipasi anggota di INDUK sebesar `;
} else {
return ` Jumlah partisipasi anggota di USP sebesar `;
}
})()} : <span id="bpartisipasi"></span></td>
</tr>
<tr>
<td colspan="4">maka perolehan bagian per Rp. 1.000,- mendapatkan jasa partisipasi sebesar :</td>
</tr>
<tr>
<td colspan="4">
<table>
<tr>
<td style="border-bottom: 1px solid #333;"><span id="hpartisipasi"></span></td>
<td style="vertical-align: bottom;" rowspan="2"> x 1.000</td>
<td style="vertical-align: bottom;" rowspan="2"> = </td>
<td style="vertical-align: bottom;" rowspan="2"> <span id="gpartisipasi"></span> </td>
</tr>
<tr>
<td><span id="tpartisipasi"></span> </td>
</tr>
</table>
</td>
</tr>
`;
setTimeout(function () {
callback();
})
}
function loadData() {
let ld = cssLoader();
let app = _id('app').value;
Partisipasi(_id('tahun').value, function(response){
let {induk, usp} = response;
AuditDevQuery(`
SELECT ifnull((SELECT ${(function(){
let app = _id('app').value;
if(app === 'usp'){
return 'usp';
}else{
return 'induk';
}
})()} FROM (
SELECT sum(reg) usp, sum(bw+usp1+usp2+usp3+pp+bn+bt) induk FROM (
SELECT
ifnull(IF(b.kodesp = 'BW', bw.jumlah, 0 ),0) bw
, ifnull(IF(b.kodesp = 'REG', b.pokok, 0 ),0) reg
, ifnull(IF(b1.kodesp = 'USP1', b1.pokok, 0 ),0) usp1
, ifnull(IF(b2.kodesp = 'USP2', b2.pokok, 0 ),0) usp2
, ifnull(IF(b3.kodesp = 'USP3', b3.pokok, 0 ),0) usp3
, ifnull(IF(c.bank = 'cash', c.lunas, 0 ),0) bt
, ifnull(IF(c.bank <> 'cash', c.lunas, 0 ),0) bn
, ifnull(d.lunas,0) pp
, '=SUM(C{no}:I{no})' tot
FROM anggota a
LEFT JOIN (
SELECT kodesc kode, 'BW' kodesp, sum(kredit) jumlah FROM totsl WHERE kredit <> 0 GROUP BY kodesc
) bw ON bw.kode = a.kode
LEFT JOIN (
SELECT * FROM (
SELECT kode, kodesp, sum(pokok) pokok FROM (
SELECT kode, kodesp, sum(partisipasi) pokok FROM spartisipasi WHERE tgl LIKE '${_id('tahun').value}%' GROUP BY kode, kodesp
UNION ALL
SELECT mags.kode, m.kodesp, sum(mags.shu) pokok FROM mags
LEFT JOIN mpinjam m ON m.faktur = mags.fkt
WHERE mags.tgl LIKE '${_id('tahun').value}%' AND mags.keterangan NOT LIKE 'Posting: Data Awal%' AND mags.bunga <> 0 GROUP BY kode, kodesp
) a GROUP BY kode, kodesp HAVING kodesp = 'reg'
) a
) b ON b.kode = a.kode
LEFT JOIN (
SELECT * FROM (
SELECT kode, kodesp, sum(pokok) pokok FROM (
SELECT kode, kodesp, sum(partisipasi) pokok FROM spartisipasi WHERE tgl LIKE '${_id('tahun').value}%' GROUP BY kode, kodesp
UNION ALL
SELECT mags.kode, m.kodesp, sum(mags.shu) pokok FROM mags
LEFT JOIN mpinjam m ON m.faktur = mags.fkt
WHERE mags.tgl LIKE '${_id('tahun').value}%' AND mags.keterangan NOT LIKE 'Posting: Data Awal%' AND mags.bunga <> 0 GROUP BY kode, kodesp
) a GROUP BY kode, kodesp HAVING kodesp = 'USP1'
) a
) b1 ON b1.kode = a.kode
LEFT JOIN (
SELECT * FROM (
SELECT kode, kodesp, sum(pokok) pokok FROM (
SELECT kode, kodesp, sum(partisipasi) pokok FROM spartisipasi WHERE tgl LIKE '${_id('tahun').value}%' GROUP BY kode, kodesp
UNION ALL
SELECT mags.kode, m.kodesp, sum(mags.shu) pokok FROM mags
LEFT JOIN mpinjam m ON m.faktur = mags.fkt
WHERE mags.tgl LIKE '${_id('tahun').value}%' AND mags.keterangan NOT LIKE 'Posting: Data Awal%' AND mags.bunga <> 0 GROUP BY kode, kodesp
) a GROUP BY kode, kodesp HAVING kodesp = 'USP2'
) a
) b2 ON b2.kode = a.kode
LEFT JOIN (
SELECT * FROM (
SELECT kode, kodesp, sum(pokok) pokok FROM (
SELECT kode, kodesp, sum(partisipasi) pokok FROM spartisipasi WHERE tgl LIKE '${_id('tahun').value}%' GROUP BY kode, kodesp
UNION ALL
SELECT mags.kode, m.kodesp, sum(mags.shu) pokok FROM mags
LEFT JOIN mpinjam m ON m.faktur = mags.fkt
WHERE mags.tgl LIKE '${_id('tahun').value}%' AND mags.keterangan NOT LIKE 'Posting: Data Awal%' AND mags.bunga <> 0 GROUP BY kode, kodesp
) a GROUP BY kode, kodesp HAVING kodesp = 'USP3'
) a
) b3 ON b3.kode = a.kode
LEFT JOIN (
SELECT
totsl.bank
, totsl.kodesc kode
, totsl.trgl
, sum(ptg.lunas) lunas
FROM ptg
LEFT JOIN totsl ON ptg.fkt = totsl.faktur
WHERE ptg.tgl LIKE '${_id('tahun').value}%' AND totsl.trgl = 'L'
GROUP BY kode, trgl
) c ON c.kode = a.kode
LEFT JOIN (
SELECT
totsl.bank
, totsl.kodesc kode
, totsl.trgl
, sum(ptg.lunas) lunas
FROM ptg
LEFT JOIN totsl ON ptg.fkt = totsl.faktur
WHERE ptg.tgl LIKE '${_id('tahun').value}%' AND totsl.trgl = 'G'
GROUP BY kode, trgl
) d ON d.kode = a.kode
GROUP BY a.kode
) a
) a
),0) total
[;]
SELECT ifnull((
SELECT sum(if(dk = 'd', jumlah, jumlah * -1)) jumlah FROM msimpan ${(function(){
let app = _id('app').value;
if (app == 'acc') {
return ` WHERE tgl LIKE '${_id('tahun').value}%' AND (kodesp = 'SP' OR kodesp = 'SW') `;
} else {
return ` WHERE tgl LIKE '${_id('tahun').value}%' AND (kodesp = 'SM' OR kodesp = 'SWP') `;
}
})()}
),0) total
`, async function(x){
let dataSimp = await getSimpanan();
console.log(dataSimp)
let [partisipasi, simpanan,f] = x;
const totalNilaiSimpanan = app === 'acc' ? (function(){
let [sp] = dataSimp.cond('3111', 'main');
let [sw] = dataSimp.cond('3113', 'main');
sp = sp.total? Number(sp.total):0;
sw = sw.total? Number(sw.total):0;
return sp + sw;
})(): (function(){
let sim = dataSimp.cond('2111', 'main');
console.log(sim);
return sim.sum('total')
})();
if(simpanan != undefined){
_id('bsimpanan').innerHTML = Number(Math.round(totalNilaiSimpanan)).rp(0)
_id('tsimpanan').innerHTML = Number(Math.round(totalNilaiSimpanan)).rp(0)
}
if(partisipasi != undefined){
let [nilaiPatisipasi] = partisipasi
let partisipan = 0;
if(app == 'usp'){
partisipan = Number(usp);
}else{
partisipan = Number(induk);
}
_id('bpartisipasi').innerHTML = Number(Math.round(partisipan)).rp(0)
_id('tpartisipasi').innerHTML = Number(Math.round(partisipan)).rp(0)
}
ld.remove();
_bbData(function (d) {
let shu = acc.cond('L', 'nr');
let dataValue = {};
shu.forEach(function(o){
dataValue[o.kode] = 0;
})
d.forEach(function(j){
if(j.dk == 'K'){
if(dataValue[j.rek] != undefined){
dataValue[j.rek] += j.total.number(2);
}
} else {
if (dataValue[j.rek] != undefined) {
dataValue[j.rek] += j.total.number(2) * -1;
}
}
});
let total = Object.keys(dataValue).map(function(jp){return dataValue[jp]}).sum();
document.getElementById('besaran').innerHTML = 'Rp '+total.currency(0)
let dataNilaiShup = [];
shup.cond(_val('app'), 'app').forEach(function(u,i){
let y = u.persen.number(2);
if (document.getElementById(`tot-shup-${i}`) != undefined){
dataNilaiShup.push(((y / 100) * total) );
document.getElementById(`tot-shup-${i}`).innerHTML = `Rp `+((y /100) * total).currency(0);
}
});
let [simp, pinj] = dataNilaiShup;
_id('hsimpanan').innerHTML = Number(simp).rp(0);
// 01
_id('hpartisipasi').innerHTML = Number(pinj).rp(0);
let [nilaiSimpanan] = simpanan;
let [nilaiPatisipasi] = partisipasi;
let partisipan = 0;
if (app == 'usp') {
partisipan = Number(usp);
} else {
partisipan = Number(induk);
}
let { total:totals } = nilaiSimpanan;
totals = Number(totals) > 0 ? Number(totals) : Number(totals) * -1;
let s01 = Math.round(Number(simp));
_id('gsimpanan').innerHTML = 'Rp ' + Number((s01 * 1000) / Number(Math.round(totalNilaiSimpanan))).currency(8);
let g01 = Math.round(Number(pinj));
let g02 = Number(Math.round(partisipan));
console.log(g01, g02);
_id('gpartisipasi').innerHTML = 'Rp ' + Number(g01 / g02 * 1000 ).currency(8);
}, function () {
if (_id('app').value == 'acc'){
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value }%" AND acc.app = 'acc'`;
} else if (_id('app').value == 'usp'){
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value }%" AND acc.app = 'usp'`;
} else {
return ` WHERE lap_bb.tgl LIKE "${_id('tahun').value }%"`;
}
}, function(){
return `
SELECT main, nama_main, dk, kode rek, nama, total FROM bbtahunan WHERE tahun = '${Number(_val('tahun')) - 1}' ${_val('app') == 'acc,usp' ? `` : ` AND app = '${_val('app')}' `} AND nr = 'N'
UNION ALL
`;
})
})
})
};
const getNode = function (className, doc) {
let nod = document.querySelectorAll('.' + className);
if (doc !== undefined) {
nod = doc.querySelectorAll(className)
}
return Array.from(
nod
);
}
const setUpData = function () {
_id('tahunv').innerHTML = _id('tahun').value;
}
loader(function () {
setTimeout(function () {
loadData();
setUpData()
})
})
_id('play').addEventListener('click', function () {
loader(function () {
setTimeout(function () {
loadData();
setUpData()
})
})
});
_id('print').addEventListener('click', function () {
let layout = {
"p": "a4portrait.css",
"l": "a4landscape.css"
}
$('#report').printThis({
// base: 'https://jasonday.github.io/printThis',
header: null, // prefix to html
footer: null,
importCSS: true,
loadCSS: ["{{PATH}}/" + layout['p'], '{{PATH}}/assets/css/bootstrap.min.css'],
header: false,
});
}, false);
_id('exportExcel').addEventListener('click', function () {
xlsx("#report", 'Laba Rugi');
}, false);