diff --git a/src/docs/forms/aktrabot.py b/src/docs/forms/aktrabot.py index dcb9477..a36eb29 100644 --- a/src/docs/forms/aktrabot.py +++ b/src/docs/forms/aktrabot.py @@ -26,7 +26,6 @@ class AktRabotForm(BaseModelForm): 'doc_text': _textarea, 'nds_method': forms.RadioSelect() } - # nds_method = forms.ChoiceField(widget=forms.RadioSelect()) class AktRabotAdminForm(AktRabotForm): diff --git a/src/dokumentor/static/css/style.css b/src/dokumentor/static/css/style.css index 185ae9a..2e1c362 100644 --- a/src/dokumentor/static/css/style.css +++ b/src/dokumentor/static/css/style.css @@ -487,8 +487,8 @@ a.delete { vertical-align: top; } .doc-form table.doc-list {border-collapse:collapse;position:relative;} .doc-form table.doc-list td {border:4px solid #fff;} .doc-form table.doc-list .itogo-td {background:#313942;height:30px;font-size:20px;color:#fff;padding:5px 10px;border-bottom:2px solid #313942;border-top:2px solid #313942;} -.doc-form table.doc-list .itogo-td1 {} -.doc-form table.doc-list .itogo-td2 {} +.doc-form table.doc-list .itogo-nds-td {height:30px;font-size:20px;color:#313942;padding:5px 10px;} + .doc-form table.doc-list .add-row {position:absolute;} .doc-form table.doc-list .add-row:hover {text-decoration:none;} @@ -831,3 +831,28 @@ input[type=number] { font-size: 13px; color: #498dd0; } + +.nds-method { + margin-top: 38px; + margin-left: 10px; +} + +#id_nds_method li { + display: inline-block; +} + +#id_nds_method label { + font-size: 16px; + font-style: normal; + cursor: pointer; +} + +#itogo { + display: block; +} + +#decryption { + font-size:11px; + display:none; + margin-top: 5px; +} diff --git a/src/dokumentor/static/js/formset-events.js b/src/dokumentor/static/js/formset-events.js index 556da47..56ad9a6 100644 --- a/src/dokumentor/static/js/formset-events.js +++ b/src/dokumentor/static/js/formset-events.js @@ -1,4 +1,5 @@ $(function() { + var nds = ''; var fix_float_input = function (e) { var el = $(this); @@ -9,6 +10,7 @@ $(function() { var calc_summa = function (e) { console.log('calc_summa'); + console.log($('#id_nds_method input:checked').val()); var el = $(this); var qty = parseFloat(el.closest('tr.row').find('td.qty input').val()); @@ -26,9 +28,29 @@ $(function() { }; var calc_itogo_nds = function() { - $('#itogo_nds_text').html('НДС ' + $('#id_nds_value option:selected').text()); - var nds = parseFloat($('#id_nds_value').val()) * parseFloat($('#itogo').html()) / 100; - $('#itogo_nds').html(nds.toFixed(2)); + var itogo_sum = 0; + $('#tbl_items').find('.total_price input:visible').each(function() { + var itogo_sum_row = $(this).val() ? parseFloat($(this).val()) : 0; + itogo_sum += itogo_sum_row; + }); + + if ($('#id_nds_value').val() && $('#itogo').html()) { + + console.log('----','NDS %',$('#id_nds_value').val()); + console.log('----','Total %',$('#itogo').html()); + console.log('----','Metod %', parseInt($('#id_nds_method input:checked').val())); + + if (parseInt($('#id_nds_method input:checked').val())) { + nds = parseFloat($('#id_nds_value').val()) * parseFloat(itogo_sum) / 100; + } else { + nds = (parseFloat(itogo_sum) / (100 + parseFloat($('#id_nds_value').val()))) * parseFloat($('#id_nds_value').val()); + } + // console.log(nds.toFixed(2)) + $('#totalNds').html(nds.toFixed(2)); + } else { + $('#totalNds').html(''); + } + }; window.calc_itogo = function (e) { @@ -38,7 +60,17 @@ $(function() { itogo_sum += itogo_sum_row; }); if (itogo_sum) { - $('#itogo').html(itogo_sum.toFixed(2)); + if (parseInt($('#id_nds_method input:checked').val())) { + console.log('add'); + nds = parseFloat($('#id_nds_value').val()) * parseFloat(itogo_sum) / 100; + $('#itogo').html(parseFloat(itogo_sum.toFixed(2)) + parseFloat(nds.toFixed(2))); + } else { + nds = (parseFloat(itogo_sum) / (100 + parseFloat($('#id_nds_value').val()))) * parseFloat($('#id_nds_value').val()); + var totalWithoutNds = parseFloat(itogo_sum.toFixed(2)) - parseFloat(nds).toFixed(2); + $('#decryption').html(totalWithoutNds + ' + НДС'); + $('#itogo').html(itogo_sum.toFixed(2)); + } + } else { $('#itogo').html(''); } @@ -64,7 +96,25 @@ $(function() { $("#tbl_items tr.row td.price input").blur(window.calc_itogo); $("#tbl_items tr.row td.total_price input").blur(window.calc_itogo); - $('#id_nds_value').change(calc_itogo_nds); + $('#id_nds_value').on('change', function(){ + + calc_itogo_nds(); + calc_itogo(); + if (!parseInt($('#id_nds_method input:checked').val())) { + $('#decryption').show(); + } else { + $('#decryption').hide(); + } + }); + $('#id_nds_method').on('change', function () { + console.log('id_nds_method change'); + calc_itogo(); + if (!parseInt($('#id_nds_method input:checked').val())) { + $('#decryption').show(); + } else { + $('#decryption').hide(); + } + }); }; window.set_events(); diff --git a/src/dokumentor/templates/docs/aktrabot/form.html b/src/dokumentor/templates/docs/aktrabot/form.html index c297e5d..7e37182 100644 --- a/src/dokumentor/templates/docs/aktrabot/form.html +++ b/src/dokumentor/templates/docs/aktrabot/form.html @@ -18,7 +18,7 @@
{% include 'docs/parts/form_field.html' with field=form.nds_value id="nds_value" classes="left" label="НДС" no_clear_after="True" %} - {% include 'docs/parts/form_field.html' with field=form.nds_method id="nds_method" classes="left nds-method" no_clear_after="True" %} + {% include 'docs/parts/form_field.html' with field=form.nds_method id="nds_method" classes="left nds-method hidden" no_clear_after="True" %} {% if formset %} {% include 'docs/parts/form_tbl_items.html' %} diff --git a/src/dokumentor/templates/docs/parts/form_tbl_items.html b/src/dokumentor/templates/docs/parts/form_tbl_items.html index af210db..76263cd 100644 --- a/src/dokumentor/templates/docs/parts/form_tbl_items.html +++ b/src/dokumentor/templates/docs/parts/form_tbl_items.html @@ -30,11 +30,22 @@ {% endfor %} + + + + НДС + + + + Итого - + + + + diff --git a/src/dokumentor/templates/docs/stub_js.html b/src/dokumentor/templates/docs/stub_js.html index 8f7d6c3..fe3f8e1 100644 --- a/src/dokumentor/templates/docs/stub_js.html +++ b/src/dokumentor/templates/docs/stub_js.html @@ -106,6 +106,22 @@ }); + // block nds method + $('#id_nds_value').on('change',function () { + + console.log($('#id_nds_value').val()); + + if ($('#id_nds_value').val() > 0) { + $('#nds_method').show(); + $('#blockTotalNds').show(); + + } else { + $('#nds_method').hide(); + $('#decryption').hide(); + $('#blockTotalNds').hide(); + } + }); + $('#id_invoice').on('change', function() { @@ -114,7 +130,7 @@ //console.log(invoice_id); if (invoice_id) { - // TODO: needed preloader or remade function + // TODO: needed loader or remade function $.each($('.row_tbl_items'), function(index, item){ $(item).find('a.delete-row').trigger('click');