|
|
|
|
@ -1,13 +1,14 @@ |
|
|
|
|
{# заглушка js #} |
|
|
|
|
<script type="text/javascript"> |
|
|
|
|
$(document).ready(function() { |
|
|
|
|
|
|
|
|
|
$('tr.plat_form').formset({ |
|
|
|
|
prefix: '{{ pformset.prefix }}', |
|
|
|
|
formCssClass: 'plat_dynamic-form', |
|
|
|
|
formCssClass: 'plat_dynamic-form' |
|
|
|
|
}); |
|
|
|
|
$('tr.row_tbl_items').formset({ |
|
|
|
|
prefix: '{{ formset.prefix }}', |
|
|
|
|
formCssClass: 'dynamic-form', |
|
|
|
|
formCssClass: 'dynamic-form' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// units |
|
|
|
|
@ -27,7 +28,6 @@ |
|
|
|
|
name_input.css('color', 'red') |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// country |
|
|
|
|
$('body').on('selectChoice change', '.country_name input', function(e, choice, autocomplete) { |
|
|
|
|
var name_input = $(this); |
|
|
|
|
@ -61,66 +61,93 @@ |
|
|
|
|
// отрабатываем изменение в блоке добавления контрагента |
|
|
|
|
// как я понимаю основной блок на поиск и вывод "инвойсов" для автодобавления контрагента |
|
|
|
|
client_block.on('change', function() { |
|
|
|
|
|
|
|
|
|
{# console.log('change');#} |
|
|
|
|
|
|
|
|
|
check_vis(add_block); |
|
|
|
|
var client_id = $(this).val(); |
|
|
|
|
$.get('/my/docs/ajax_get_invoices/' + client_id, function(data) { |
|
|
|
|
var select = $('#id_invoice'); |
|
|
|
|
if(select.prop) { |
|
|
|
|
var options = select.prop('options'); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
var options = select.attr('options'); |
|
|
|
|
} |
|
|
|
|
$('option', select).remove(); |
|
|
|
|
options[options.length] = new Option('-------', ''); |
|
|
|
|
|
|
|
|
|
$.each(data, function(val, text) { |
|
|
|
|
options[options.length] = new Option(text, val); |
|
|
|
|
}); |
|
|
|
|
select.prop('selectedIndex', 0); |
|
|
|
|
}) |
|
|
|
|
if (client_id) { |
|
|
|
|
$.get('/my/docs/ajax_get_invoices/' + client_id, function(data) { |
|
|
|
|
if($('*').is('#id_invoice')) { |
|
|
|
|
|
|
|
|
|
$.isEmptyObject(data) ? displayInvoiceBlock(false): displayInvoiceBlock(true); |
|
|
|
|
|
|
|
|
|
var select = $('#id_invoice'); |
|
|
|
|
|
|
|
|
|
if(select.prop) { |
|
|
|
|
var options = select.prop('options'); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
var options = select.attr('options'); |
|
|
|
|
} |
|
|
|
|
$('option', select).remove(); |
|
|
|
|
|
|
|
|
|
options[options.length] = new Option('-------', ''); |
|
|
|
|
|
|
|
|
|
$.each(data, function(val, text) { |
|
|
|
|
options[options.length] = new Option(text, val); |
|
|
|
|
}); |
|
|
|
|
select.prop('selectedIndex', 0); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
displayInvoiceBlock(false); |
|
|
|
|
// TODO: need confirm delete records |
|
|
|
|
|
|
|
|
|
confirmChangeDataPromise(getTableInputs()).then(function (answer) { |
|
|
|
|
if (answer) { |
|
|
|
|
updateTable(); |
|
|
|
|
} |
|
|
|
|
}) ; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('#id_invoice').on('change', function() { |
|
|
|
|
|
|
|
|
|
var invoice_id = $(this).val(); |
|
|
|
|
$.each($('.row_tbl_items'), function(index, item){ |
|
|
|
|
$(item).find('a.delete-row').trigger('click'); |
|
|
|
|
}); |
|
|
|
|
$.get('/my/docs/ajax_get_client_by_invoice/' + invoice_id, function(data) { |
|
|
|
|
add_block.hide(); // прячем кнопку добавить |
|
|
|
|
var client = data[0]; |
|
|
|
|
$('#id_client_text').hide(); |
|
|
|
|
$('#id_client-deck').html( |
|
|
|
|
'<span class="div hilight" data-value='+ data[0] + |
|
|
|
|
'><span class="remove div" style="display: inline;">X</span>' + data[1] + '</span>'); |
|
|
|
|
|
|
|
|
|
$('#id_client').html('<option selected="selected" value="'+ data[0] +'"></option>'); |
|
|
|
|
{# console.log(invoice_id);#} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
if (invoice_id) { |
|
|
|
|
// TODO: needed preloader or remade function |
|
|
|
|
|
|
|
|
|
$.get('/my/docs/ajax_get_tbl_items/' + invoice_id, function(data) { |
|
|
|
|
//console.log('==================='); |
|
|
|
|
var items = JSON.parse(data); |
|
|
|
|
$.each(items, function(index, item){ |
|
|
|
|
var name = item['fields']['name']; |
|
|
|
|
var units = item['fields']['units']; |
|
|
|
|
var qty = item['fields']['qty']; |
|
|
|
|
var price = item['fields']['price']; |
|
|
|
|
var total_price = item['fields']['total_price']; |
|
|
|
|
$('#tbl_items a.add-row').trigger('click'); |
|
|
|
|
var $last_row = $('.row_tbl_items:visible').last(); |
|
|
|
|
$last_row.find('.name input').val(name); |
|
|
|
|
$last_row.find('.units input').val(units); |
|
|
|
|
$last_row.find('.qty input').val(qty); |
|
|
|
|
$last_row.find('.price input').val(price); |
|
|
|
|
$last_row.find('.total_price input').val(total_price); |
|
|
|
|
$.get('/my/docs/ajax_get_pair/Measure/name/code/' + units + '/', function(data){ |
|
|
|
|
if (data['val']) { |
|
|
|
|
$last_row.find('.units_kod input').val(data['val']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
$.each($('.row_tbl_items'), function(index, item){ |
|
|
|
|
$(item).find('a.delete-row').trigger('click'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$.get('/my/docs/ajax_get_tbl_items/' + invoice_id, function(data) { |
|
|
|
|
{# console.log('===================');#} |
|
|
|
|
var items = JSON.parse(data); |
|
|
|
|
{# console.log(items);#} |
|
|
|
|
|
|
|
|
|
$.each(items, function(index, item){ |
|
|
|
|
var name = item['fields']['name']; |
|
|
|
|
var units = item['fields']['units']; |
|
|
|
|
var qty = item['fields']['qty']; |
|
|
|
|
var price = item['fields']['price']; |
|
|
|
|
var total_price = item['fields']['total_price']; |
|
|
|
|
$('#tbl_items a.add-row').trigger('click'); |
|
|
|
|
var $last_row = $('.row_tbl_items:visible').last(); |
|
|
|
|
$last_row.find('.name input').val(name); |
|
|
|
|
$last_row.find('.units input').val(units); |
|
|
|
|
$last_row.find('.qty input').val(qty); |
|
|
|
|
$last_row.find('.price input').val(price); |
|
|
|
|
$last_row.find('.total_price input').val(total_price); |
|
|
|
|
// TODO: need ajax function on backend |
|
|
|
|
$.get('/my/docs/ajax_get_pair/Measure/name/code/' + units + '/', function(data){ |
|
|
|
|
if (data['val']) { |
|
|
|
|
$last_row.find('.units_kod input').val(data['val']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
updateTable(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var toggle_sender = function(client_type) { |
|
|
|
|
@ -144,10 +171,99 @@ |
|
|
|
|
} else { |
|
|
|
|
$('#fix_block').hide(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$('#id_fixes').change(function(){ |
|
|
|
|
$('#fix_block').toggle(); |
|
|
|
|
$('#id_fix_doc_num').val('11'); |
|
|
|
|
$('#id_fix_doc_date').val(''); |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function displayInvoiceBlock(visibly) { |
|
|
|
|
var invoiceBlock = $('#invoice'); |
|
|
|
|
|
|
|
|
|
if ($('*').has(invoiceBlock)) { |
|
|
|
|
(visibly) ? invoiceBlock.removeClass('hidden'): invoiceBlock.addClass('hidden'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clearTableRow(tblItems) { |
|
|
|
|
$.each(tblItems, function(index, item){ |
|
|
|
|
$(item).find('.name input').val(''); |
|
|
|
|
$(item).find('.units input').val(''); |
|
|
|
|
$(item).find('.qty input').val(''); |
|
|
|
|
$(item).find('.price input').val(''); |
|
|
|
|
$(item).find('.total_price input').val(''); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getTableInputs() { |
|
|
|
|
return $('#tbl_items input:not(:hidden)').toArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function deleteTableRow(tblItems) { |
|
|
|
|
$.each (tblItems, function(index, item){ |
|
|
|
|
$(item).find('a.delete-row').trigger('click'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function updateTable() { |
|
|
|
|
var tblItems = $('.row_tbl_items'); |
|
|
|
|
|
|
|
|
|
if (tblItems.length < 2) { |
|
|
|
|
clearTableRow(tblItems); |
|
|
|
|
$('#tbl_items a.add-row').trigger('click'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (tblItems.length === 2) { |
|
|
|
|
clearTableRow(tblItems); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (tblItems.length > 2) { |
|
|
|
|
var firstAndSecondTblItems = tblItems.splice(0, 2); |
|
|
|
|
clearTableRow(firstAndSecondTblItems); |
|
|
|
|
deleteTableRow(tblItems); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: to common function |
|
|
|
|
function confirmChangeDataPromise(inputArray) { |
|
|
|
|
var dlg_msg = $('#dialog-message'); |
|
|
|
|
var emptyInput = true; |
|
|
|
|
var defer = $.Deferred(); |
|
|
|
|
|
|
|
|
|
for (var i = inputArray.length - 1; i >= 0; --i) { |
|
|
|
|
|
|
|
|
|
if (inputArray[i].value) { |
|
|
|
|
emptyInput = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!emptyInput) { |
|
|
|
|
dlg_msg.dialog({ |
|
|
|
|
title: 'Удалить данные', |
|
|
|
|
buttons: |
|
|
|
|
{'Да': |
|
|
|
|
function(){ |
|
|
|
|
defer.resolve(true); |
|
|
|
|
$(this).dialog('close'); |
|
|
|
|
}, 'Нет': |
|
|
|
|
function(){ |
|
|
|
|
defer.resolve(false); |
|
|
|
|
$(this).dialog('close'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}).html('Имеются уже заполненные данные, удалить их?'); |
|
|
|
|
dlg_msg.dialog('open'); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
defer.resolve(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return defer.promise(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
|