|
@@ -1544,12 +1544,14 @@ function urlFetchKontrahenci(page) {
|
|
|
$('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
|
|
$('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
|
|
|
$('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
|
|
$('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
|
|
|
if (data.body.pagination.total_items > 0) {
|
|
if (data.body.pagination.total_items > 0) {
|
|
|
- var btnGraphView = $('<button class="btn btn-primary smad-kontrahenci-graph-button" onClick="graphShowHide(\'kontrahenci\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
|
|
|
|
|
-
|
|
|
|
|
- var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
|
|
|
|
|
|
|
+ var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>');
|
|
|
btnAddAll.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addAllMatchesToReport);
|
|
btnAddAll.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addAllMatchesToReport);
|
|
|
|
|
+
|
|
|
|
|
+ var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
|
|
|
|
|
+ btnAddByReport.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addToReportByPreviousReport);
|
|
|
|
|
+
|
|
|
$('#smad-filter-desc-kontrahenci').append(btnAddAll);
|
|
$('#smad-filter-desc-kontrahenci').append(btnAddAll);
|
|
|
- $('#smad-filter-desc-kontrahenci').append(btnGraphView);
|
|
|
|
|
|
|
+ $('#smad-filter-desc-kontrahenci').append(btnAddByReport);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1688,12 +1690,14 @@ function urlFetchPracownicy(page) {
|
|
|
$('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
|
|
$('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
|
|
|
$('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
|
|
$('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
|
|
|
if (data.body.pagination.total_items > 0) {
|
|
if (data.body.pagination.total_items > 0) {
|
|
|
- var btnGraphView = $('<button class="btn btn-primary smad-pracownicy-graph-button" onClick="graphShowHide(\'pracownicy\')" style="padding:1px 5px; margin-left:12px">GRAF POWIĄZAŃ</button>')
|
|
|
|
|
-
|
|
|
|
|
var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
|
|
var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
|
|
|
btnAddAll.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addAllMatchesToReport);
|
|
btnAddAll.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addAllMatchesToReport);
|
|
|
|
|
+
|
|
|
|
|
+ var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
|
|
|
|
|
+ btnAddByReport.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addToReportByPreviousReport);
|
|
|
|
|
+
|
|
|
$('#smad-filter-desc-pracownicy').append(btnAddAll);
|
|
$('#smad-filter-desc-pracownicy').append(btnAddAll);
|
|
|
- $('#smad-filter-desc-pracownicy').append(btnGraphView);
|
|
|
|
|
|
|
+ $('#smad-filter-desc-pracownicy').append(btnAddByReport);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2611,6 +2615,190 @@ function addAllMatchesToReport(event) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function mock_error__fetchLastReports(id) {
|
|
|
|
|
+ return new Promise(function (resolve) {
|
|
|
|
|
+ throw "Wystąpił błąd, spróbuj ponownie później"
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+function mock__fetchLastReports(id) {
|
|
|
|
|
+ return new Promise(function (resolve) {
|
|
|
|
|
+ var fakeResponse = '{"type":"success","msg":"ostatnie raporty","body":{"items":[{"id":"103","adnotacje":"raport pani x","totalPracownicy":"1","totalKontrahenci":"2"},{"id":"102","adnotacje":"test","totalPracownicy":"1","totalKontrahenci":"1"},{"id":"101","adnotacje":"Zuranski test all 7","totalPracownicy":"1","totalKontrahenci":"9307"},{"id":"100","adnotacje":"kike all 4","totalPracownicy":"5","totalKontrahenci":"9305"},{"id":"99","adnotacje":"test pracownik z KRS bez celu 3","totalPracownicy":"1","totalKontrahenci":"9305"}]}}';
|
|
|
|
|
+ var json = JSON.parse(fakeResponse);
|
|
|
|
|
+ var items = json.body.items;
|
|
|
|
|
+ console.log('items', items)
|
|
|
|
|
+ setTimeout(function () {
|
|
|
|
|
+ console.log('resolve items', items)
|
|
|
|
|
+ resolve(items);
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+function fetchLastReports(id) {
|
|
|
|
|
+ return global.fetch(URL_FETCH_LAST_REPORTS_AJAX, {
|
|
|
|
|
+ credentials: 'same-origin',
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify({ id: id })
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function __parseJSON(response) {
|
|
|
|
|
+ return response.json()
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function (json) {
|
|
|
|
|
+ if ('success' === json.type && json.body && json.body.items) {
|
|
|
|
|
+ if (!json.body.items.length) throw "Brak danych"
|
|
|
|
|
+ return json.body.items;
|
|
|
|
|
+ }
|
|
|
|
|
+ throw "Wystąpił błąd, spróbuj ponownie później.";
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+function fetchPracownicyIdsByReport(id) {
|
|
|
|
|
+ return global.fetch(URL_FETCH_PRACOWNICY_IDS_BY_REPORT_AJAX, {
|
|
|
|
|
+ credentials: 'same-origin',
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify({ id: id })
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function __parseJSON(response) {
|
|
|
|
|
+ return response.json()
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function (json) {
|
|
|
|
|
+ if ('success' === json.type && json.body && json.body.ids) {
|
|
|
|
|
+ if (!json.body.ids.length) throw "Brak danych"
|
|
|
|
|
+ return json.body.ids;
|
|
|
|
|
+ }
|
|
|
|
|
+ throw "Wystąpił błąd, spróbuj ponownie później.";
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+function fetchKontrahenciIdsByReport(id) {
|
|
|
|
|
+ return global.fetch(URL_FETCH_KONTRAHENCI_IDS_BY_REPORT_AJAX, {
|
|
|
|
|
+ credentials: 'same-origin',
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify({ id: id })
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function __parseJSON(response) {
|
|
|
|
|
+ return response.json()
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(function (json) {
|
|
|
|
|
+ if ('success' === json.type && json.body && json.body.ids) {
|
|
|
|
|
+ if (!json.body.ids.length) throw "Brak danych"
|
|
|
|
|
+ return json.body.ids;
|
|
|
|
|
+ }
|
|
|
|
|
+ throw "Wystąpił błąd, spróbuj ponownie później.";
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function addToReportByPreviousReport(event) {
|
|
|
|
|
+ var pageType = (event.data.type) ? event.data.type : '';
|
|
|
|
|
+ switch (pageType) {
|
|
|
|
|
+ case 'pracownicy': break; // OK
|
|
|
|
|
+ case 'kontrahenci': break; // OK
|
|
|
|
|
+ default: throw "Wrong type";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var thisButton = $(this)
|
|
|
|
|
+ thisButton.attr('disabled', true)
|
|
|
|
|
+ thisButton.text( thisButton.text() + '...' )
|
|
|
|
|
+ function this__enableButton() {
|
|
|
|
|
+ thisButton.attr('disabled', false)
|
|
|
|
|
+ var txt = thisButton.text()
|
|
|
|
|
+ thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var lastReportOptions = new Promise(function (resolve) {
|
|
|
|
|
+ fetchLastReports() // TODO: TEST remote `mock__`
|
|
|
|
|
+ .then(function (items) {
|
|
|
|
|
+ var options = {};
|
|
|
|
|
+ items.forEach(function (item) {
|
|
|
|
|
+ var label = "Nr " + item.id + ": " + item.adnotacje + " ";
|
|
|
|
|
+ var total = 0;
|
|
|
|
|
+ switch (pageType) {
|
|
|
|
|
+ case 'pracownicy': total = parseInt(item.totalPracownicy); break;
|
|
|
|
|
+ case 'kontrahenci': total = parseInt(item.totalKontrahenci); break;
|
|
|
|
|
+ }
|
|
|
|
|
+ label += ( total > 0 ? "(" + total + ")" : "brak");
|
|
|
|
|
+ options[item.id] = label;
|
|
|
|
|
+ });
|
|
|
|
|
+ resolve(options);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(function (e) {
|
|
|
|
|
+ swal.showValidationError(''+e)
|
|
|
|
|
+ swal.hideLoading();
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ })
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ swal({
|
|
|
|
|
+ title: "Dodaj " + ('pracownicy' === pageType ? "praconików" : "kontrahentów") + " do analizy",
|
|
|
|
|
+ showCancelButton: true,
|
|
|
|
|
+ cancelButtonText: "Anuluj",
|
|
|
|
|
+ showConfirmButton: true,
|
|
|
|
|
+ confirmButtonText: "Wybierz",
|
|
|
|
|
+ focusCancel: true,
|
|
|
|
|
+ width: 600,
|
|
|
|
|
+ input: 'select',
|
|
|
|
|
+ inputOptions: lastReportOptions,
|
|
|
|
|
+ inputClass: "form-control input-lg",
|
|
|
|
|
+ preConfirm: function (selected) {
|
|
|
|
|
+ var id = parseInt(selected);
|
|
|
|
|
+ swal.showLoading();
|
|
|
|
|
+ if ('pracownicy' === pageType) {
|
|
|
|
|
+ return new Promise(function (resolve) {
|
|
|
|
|
+ fetchPracownicyIdsByReport(id)
|
|
|
|
|
+ .then(function (ids) {
|
|
|
|
|
+ updateListIdBiAuditReaport('PRACOWNICY', ids.map(function (id) {
|
|
|
|
|
+ return parseInt(id)
|
|
|
|
|
+ }))
|
|
|
|
|
+ ids.forEach(function (id) {
|
|
|
|
|
+ jQuery('#body-pracownicy').find('input[name="prID[]"][value="'+id+'"]').each(function (idx, inputNode) {
|
|
|
|
|
+ inputNode.checked = true;
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ updateCountItemCheckedByType('pracownicy');
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" pracowników" })
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(function (e) {
|
|
|
|
|
+ swal.showValidationError(''+e)
|
|
|
|
|
+ swal.hideLoading();
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if ('kontrahenci' === pageType) {
|
|
|
|
|
+ return new Promise(function (resolve) {
|
|
|
|
|
+ fetchKontrahenciIdsByReport(id)
|
|
|
|
|
+ .then(function (ids) {
|
|
|
|
|
+ updateListIdBiAuditReaport('KONTRAHENCI', ids.map(function (id) {
|
|
|
|
|
+ return parseInt(id)
|
|
|
|
|
+ }))
|
|
|
|
|
+ ids.forEach(function (id) {
|
|
|
|
|
+ jQuery('#body-kontrahenci').find('input[name="kontrID[]"][value="'+id+'"]').each(function (idx, inputNode) {
|
|
|
|
|
+ inputNode.checked = true;
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ updateCountItemCheckedByType('kontrahenci');
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" kontrahentów" })
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(function (e) {
|
|
|
|
|
+ swal.showValidationError(''+e)
|
|
|
|
|
+ swal.hideLoading();
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ } else return true;
|
|
|
|
|
+ },
|
|
|
|
|
+ // inputValidator: (value) => {
|
|
|
|
|
+ // return !value && 'Proszę wybrać raport'
|
|
|
|
|
+ // }
|
|
|
|
|
+ // html: '<p>Ostatnie raporty:</p>' + '<ul id="' + uniqHtmlId + '"></ul></p>',
|
|
|
|
|
+ }).then(function (selected) {
|
|
|
|
|
+ this__enableButton();
|
|
|
|
|
+ }).catch(function (e) {
|
|
|
|
|
+ this__enableButton();
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
$(document).ready(function(){
|
|
$(document).ready(function(){
|
|
|
rootChangeForm();
|
|
rootChangeForm();
|
|
|
updateTopCounters();
|
|
updateTopCounters();
|