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

89 lines
2.6 KiB

var DOC = new Object;
DOC.form = null;
DOC.platej_type = null;
DOC.commerce = null;
DOC.taxes = null;
DOC.doc_info = null;
DOC.CONSTS = {
'platej_type': {'commerce': 1, 'tax': 2}, // типы платежных поручений
'nds_value': {0: 1, 10: 2, 18: 3} // # ставка НДС
};
$(document).ready(function() {
DOC.form = $('#doc-form');
DOC.platej_type = $('#platej_type select', DOC.form);
DOC.commerce = $('.commerce', DOC.form);
DOC.taxes = $('.taxes', DOC.form);
DOC.doc_info = $('textarea#id_doc_info', DOC.form);
// init
toggle_platej_type();
DOC.platej_type.change(function() {
toggle_platej_type();
});
$('#id_fill_summa', DOC.form).click(function() {
make_summa();
});
});
function toggle_platej_type() {
var ptype = DOC.platej_type.val();
if (ptype == DOC.CONSTS.platej_type.commerce) {
DOC.taxes.hide();
DOC.commerce.show();
}
else if (ptype == DOC.CONSTS.platej_type.tax) {
DOC.commerce.hide();
DOC.taxes.show();
}
}
function make_summa() {
var ptype = DOC.platej_type.val();
var el_doc_total = $('input#id_doc_total', DOC.form);
var el_nds_value = $('select[name=nds_value]', DOC.form);
var doc_total = parseFloat(el_doc_total.val().replace(",", "."));
var nds_value = parseInt(el_nds_value.val().replace(",", "."));
var add_text = '';
/*/
if (isNaN(doc_total))
return true;
// сумма платежа
add_text += ' ' + doc_total.toString().replace(".", ",") + ' руб.';
//*/
add_text += 'Оплата по (счету, договору...) №___ от____ за____';
// добавить в текст ндс
if (ptype == DOC.CONSTS.platej_type.commerce) { // перевод денег
if (!isNaN(doc_total) && !isNaN(nds_value)) {
var nds_rate = 0;
switch (nds_value) {
case DOC.CONSTS.nds_value[0]: nds_rate = 0; break;
case DOC.CONSTS.nds_value[10]: nds_rate = 10; break;
case DOC.CONSTS.nds_value[18]: nds_rate = 18; break;
}
if (nds_rate > 0) {
var nds = calc_nds(doc_total, nds_rate);
add_text += ', в т.ч. НДС (' + nds_rate + '%): ' +
nds.toFixed(2).toString().replace(".", ",") + ' руб.';
}
else {
add_text += ', без НДС';
}
}
}
var doc_info_val = DOC.doc_info.val();
if (doc_info_val)
add_text = '\n' + add_text;
DOC.doc_info.val(doc_info_val + add_text);
return true;
}