Last active
January 24, 2017 10:38
-
-
Save regularlabs/755f0f4e36f66961d54391862e206b38 to your computer and use it in GitHub Desktop.
Userscript: Acumulus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Acumulus | |
// @author Peter van Westen | |
// @namespace Acumulus | |
// @include https://www.sielsystems.nl/acumulus/* | |
// @grant none | |
// @version 1.0 | |
// @description Acumulus | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js | |
// ==/UserScript== | |
improveLayout(); | |
function improveLayout() { | |
var url = window.location.toString(); | |
if (url.indexOf('overzicht_aangifte_btw.php') > 0) { | |
overzichtAangifteBtw(); | |
} | |
if (url.indexOf('listimportregels.php') > 0) { | |
listImportRegels(); | |
} | |
if (url.indexOf('verwerk_importregel.php') > 0) { | |
verwerkImportRegel(); | |
} | |
} | |
function listImportRegels() { | |
$('.div_title').css('margin', '0'); | |
$('#Sectie1').css('height', Math.min($(window).height() - 100)); | |
} | |
function verwerkImportRegel() { | |
$('#sc1').css('font-size', '1.2em'); | |
$('#tabcontentcontainer').css('height', '390px'); | |
$('input[type="radio"').css('margin', '10px 5px'); | |
var html = $('#sc1').html(); | |
html = html | |
.replace(/(<input.*?name="(.*?)" value="(.*?)")(.*?>)/g, '$1 id="$2_$3" onclick="open_boeking();" $4<label for="$2_$3">') | |
.replace(/<br>/g, '</label><br>') + '<br>'; | |
$('#sc1').html(html); | |
} | |
function overzichtAangifteBtw() { | |
roundTaxDeclarationNumbers(); | |
} | |
function roundTaxDeclarationNumbers() { | |
if (!$(".div_title_this:contains('Aangifte omzetbelasting (btw)')").length) { | |
return; | |
} | |
$('table.table_list').first().find('tr').each(function() { | |
var $title_row = $(this); | |
if (!$title_row.find('td.td_field').length) { | |
return; | |
} | |
var $data_row = $title_row.next(); | |
if (!$data_row.length) { | |
return; | |
} | |
var $title_cell = $data_row.find('td.td_list2').first(); | |
var $value_cell = $title_cell.next(); | |
if (!$value_cell.length || $value_cell.html().trim() === '') { | |
return; | |
} | |
var title = $title_row.find('td.td_field').first().html(); | |
var rounding = getRoundings(title); | |
$title_cell.html(title); | |
$value_cell.html(roundNumber($value_cell.html(), rounding[0], rounding[2])); | |
var $tax_cell = $value_cell.next(); | |
if ($tax_cell.length && $value_cell.html().trim() !== '') { | |
$tax_cell.html(roundNumber($tax_cell.html(), rounding[1], rounding[2])); | |
} | |
$title_row.remove(); | |
}); | |
$("td.td_list2").each(function() { | |
var $value_cell = $(this).next(); | |
if (!$value_cell.length || $value_cell.html().trim() === '') { | |
return; | |
} | |
if ($(this).html().indexOf('Aftrek KOR') > -1) { | |
$value_cell.html(roundNumber($value_cell.html(), 'up')); | |
return; | |
} | |
if ($(this).html().indexOf('Te betalen') > -1 || $(this).html().indexOf('Te ontvangen') > -1) { | |
$value_cell.html(roundNumber($value_cell.html())); | |
return; | |
} | |
}); | |
} | |
function getRoundings(string) { | |
var match = string.match(/Rubriek ([a-z0-9]+)/); | |
if (!match) { | |
return ['', '']; | |
} | |
var section = match[1]; | |
switch (section) { | |
case '4b': | |
return ['', 'up', true]; | |
case '5a': | |
return ['down', '', false]; | |
case '5b': | |
return ['up', '', true]; | |
case '5c': | |
return ['down', '', false]; | |
} | |
return ['', 'down', true]; | |
} | |
function roundNumber(string, rounding, keep_bold) { | |
var parts = string.match(/(\s*(?:<.*?>\s*)*)([0-9\.]+)((?:\s*<\/.*?>)*)\s*/); | |
if (!parts) { | |
return string; | |
} | |
var number = parts[2].trim(); | |
if (!isNumber(number)) { | |
return string; | |
} | |
number = parseInt(number); | |
if (!number) { | |
return '0'; | |
} | |
if (rounding == 'down') { | |
number = number - 0.5; | |
} | |
if (rounding == 'up') { | |
number = number + 0.5; | |
} | |
number = Math.round(number); | |
if (!keep_bold) { | |
return number; | |
} | |
return parts[1] + number + parts[3]; | |
} | |
function isNumber(number) { | |
if (number === '') { | |
return false; | |
} | |
return Number(number) == number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment