Files
crm.e5.pl/modules/EcmReports/javascript/RaportZamowien.js
2024-04-27 09:23:34 +02:00

406 lines
13 KiB
JavaScript

$(document)
.ready(
function() {
$(".rowShowHide").hide();
$(".tablesShowHide").hide();
// Listener odpowiadający za akcje po kliknięciu na przycisk
// "Exportuj do programu Excel"
$("#excelEksport").click(excelExport);
$("#pdfEksport").click(pdfExport);
function pdfExport() {
var url = $(location).attr('href');
url = url + "&toPDF=1&to_pdf=1";
window.location.href = url;
}
$(".showTables")
.bind(
"click",
function() {
if ($(this).attr("class") == "plusStyle showTables") {
// pobieramy następny wiersz tabeli
// którą chcemy pokazac po czym go
// wyswietlamy
var nextTBody = $(this).parent()
.parent().parent().next();
while ($(nextTBody).attr("id") != "stopTables") {
// sprawdzamy czy kategoria
if ($(nextTBody).attr("class") == "tablesorter-infoOnly tablesShowHide") {
$(nextTBody).show();
}
nextTBody = $(nextTBody).next();
}
$(this).html("[-]");
$(this).attr("class",
"plusStyle hideTables");
} else if ($(this).attr("class") == "plusStyle hideTables") {
// pobieramy następny wiersz tabeli
// którą chcemy schowac po czym go
// chowamy
var nextTBody = $(this).parent()
.parent().parent().next();
while ($(nextTBody).attr("id") != "stopTables") {
// tu chowamy wszystko więc nie
// sprawdzamy kategori
$(nextTBody).hide();
var changePlusMinus = $(
nextTBody).children()
.children();
if ($(changePlusMinus[0])
.children("a").attr(
"class") == "hideRows") {
$(changePlusMinus[0])
.children("a")
.attr("class",
"showRows");
$(changePlusMinus[0])
.children("a")
.html("[+]");
}
nextTBody = $(nextTBody).next();
}
$(this).html("[+]");
$(this).attr("class",
"plusStyle showTables");
}
});
$(".showRows")
.bind(
"click",
function() {
if ($(this).attr("class") == "showRows") {
// pobieramy następny wiersz tabeli
// którą chcemy pokazac po czym go
// wyswietlamy
var nextTBody = $(this).parent()
.parent().parent().next();
while ($(nextTBody).attr("id") != "stopRows") {
$(nextTBody).show();
nextTBody = $(nextTBody).next();
}
$(this).html("[-]");
$(this).attr("class", "hideRows");
} else if ($(this).attr("class") == "hideRows") {
// pobieramy następny wiersz tabeli
// którą chcemy schowac po czym go
// chowamy
var nextTBody = $(this).parent()
.parent().parent().next();
while ($(nextTBody).attr("id") != "stopRows") {
$(nextTBody).hide();
nextTBody = $(nextTBody).next();
}
$(this).html("[+]");
$(this).attr("class", "showRows");
}
});
// dodatkowe dane dla kontrahenta
$(".showProducts")
.click(
function() {
if ($(this).attr("class") === "showProducts") {
var parent = $(this).parent();
var children = $(parent).children();
var contractor = $(children[1])
.attr("contractor");
var category = $(this).attr(
"category");
var subcategory = $(this).attr(
"subcategory");
var date_from = $("#date_from")
.attr("value");
var date_to = $("#date_to").attr(
"value");
var type = $(
"#type option:selected")
.attr("value");
var user = $(
"#user option:selected")
.attr("value");
var pdf_type = $(
"#pdf_type option:selected")
.attr("value");
var group_ks = $(
"#group_ks option:selected")
.attr("value");
var Con = {
contractor : contractor,
date_from : date_from,
date_to : date_to,
type : type,
category : category,
subcategory : subcategory,
user : user,
pdf_type : pdf_type,
group_ks : group_ks
};
$(this).attr("class",
"hideProducts");
var ajax_url = "index.php?module=EcmReports&action=ReportSalesByProducts&to_pdf=1";
$
.blockUI({
css : {
border : 'none',
padding : '15px',
backgroundColor : '#000',
'-webkit-border-radius' : '10px',
'-moz-border-radius' : '10px',
opacity : .5,
'font-weight' : 'bold',
'font-size' : '16px',
color : '#fff',
},
message : "Proszę czekać..."
});
$
.ajax({
type : "POST",
url : ajax_url,
dataType : "text",
success : function(data) {
var parparent = $(
parent)
.parent();
parparent
.after("<tr class='productsTable'><td colspan='8'>"
+ data
+ "</td></tr>");
$.unblockUI();
},
data : Con
});
} else if ($(this).attr("class") === "hideProducts") {
var parent = $(this).parent()
.parent();
$(parent).next().remove(
".productsTable");
$(this).attr("class",
"showProducts");
}
});
// dodatkowe dane dla produktu
$(".showContractors")
.click(
function() {
if ($(this).attr("class") === "showContractors") {
var parent = $(this).parent();
var children = $(parent).children();
var date_from = $("#date_from")
.attr("value");
var date_to = $("#date_to").attr(
"value");
var type = $(
"#type option:selected")
.attr("value");
var productid = $(this).data(
"productid");
var pdf_type = $(
"#pdf_type option:selected")
.attr("value");
var group_ks = $(
"#group_ks option:selected")
.attr("value");
var Con = {
date_from : date_from,
date_to : date_to,
type : type,
pdf_type : pdf_type,
group_ks : group_ks,
productid : productid
};
$(this).attr("class",
"hideContractors");
var ajax_url = "index.php?module=EcmReports&action=getContractorsByProduct&to_pdf=1";
$
.blockUI({
css : {
border : 'none',
padding : '15px',
backgroundColor : '#000',
'-webkit-border-radius' : '10px',
'-moz-border-radius' : '10px',
opacity : .5,
'font-weight' : 'bold',
'font-size' : '16px',
color : '#fff',
},
message : "Proszę czekać..."
});
$
.ajax({
type : "POST",
url : ajax_url,
dataType : "text",
success : function(data) {
var parparent = $(
parent)
.parent();
parparent
.after("<tr class='productsTable'><td colspan='8'>"
+ data
+ "</td></tr>");
$.unblockUI();
},
data : Con
});
} else if ($(this).attr("class") === "hideContractors") {
var parent = $(this).parent()
.parent();
$(parent).next().remove(
".productsTable");
$(this).attr("class",
"showContractors");
}
});
function excelExport() {
var url = $(location).attr('href').replace(
"ReportSales", "ReportSalesToExcelFile");
url = url + "&to_pdf=1";
var fileUrl = url.slice(0, url.indexOf("index"))
+ "modules/EcmReports/ExcelFiles/ReportSales.xls";
$.blockUI({
css : {
border : 'none',
padding : '15px',
backgroundColor : '#000',
'-webkit-border-radius' : '10px',
'-moz-border-radius' : '10px',
opacity : .5,
'font-weight' : 'bold',
'font-size' : '16px',
color : '#fff',
},
message : "Trwa generowanie pliku..."
});
$.ajax({
url : url,
success : function(data) {
$.unblockUI();
window.location.href = fileUrl
},
error : function() {
$.unblockUI();
alert('Eksport zakończony niepowodzeniem!');
}
});
}
$.tablesorter.addParser({
// use a unique id
id : 'number',
is : function(s, table, cell) {
// s is the text from the cell
// table is the current table (as a DOM element; not
// jQuery object)
// cell is the current table cell (DOM element)
// return false if you don't want this parser to be
// auto detected
return false;
},
format : function(s, table, cell, cellIndex) {
// s is the text from the cell
// table is the current table (as a DOM element; not
// jQuery object)
// cell is the current table cell (DOM element)
// cellIndex is the current cell's column index
// format your data for normalization
// (i.e. do something to get and/or modify your
// data, then return it)
return $(cell).attr('data-value');
},
// flag for filter widget (true = ALWAYS search parsed
// values; false = search cell text)
parsed : false,
// set the type to either numeric or text (text uses a
// natural sort function
// so it will work for everything, but numeric is faster
// for numbers
type : 'numeric'
});
// assign the sortStart event
$("#myTable thead").click(function() {
// alert($(this).attr("id"));
$(".productsTable").remove();
var minus = $(".hideProducts");
$.each(minus, function() {
$(this).html("[+]");
$(this).attr("class", "showProducts");
});
});
});
function getProductOrders(pid, date,element) {
var params = {
job : 'getProductOrders',
id : pid,
date : date,
type: $('#date_type').val(),
wz: $('#no_wz').is(':checked')
};
$.ajax({
type : "POST",
url : 'index.php?module=EcmReports&action=javahelper&to_pdf=1',
dataType : "json",
async : false,
success : function(data) {
if (data !== undefined) {
var content = "<table><tr><td>Numer zamówienia</td><td>Kontrahent</td><td>Ilość</td><td>Status</td></tr>"
for ( var key in data.items) {
content += '<tr><td><a href="index.php?module=EcmSales&action=DetailView&record=' + data.items[key].id +'" target="_blank">' + data.items[key].document_no +'</a></td><td>' + data.items[key].parent_name +'</td><td style="text-align:right;"><b>' + data.items[key].quantity +'</b></td><td>' + data.items[key].status +'</td></tr>';
}
content += "</table><br>";
content += "<table style='width:100%;'>";
content += '<tr><td style="width:50%;">Stan magazynowy:</td><td style="text-align:right;width:50%;"><b>' + data.stock +'</b></td></tr>';
content += "</table><br><span onclick='$(\"#"+element+"\").tooltip(\"close\");$(\"#"+element+"\").tooltip(\"destroy\");'>Zamknij okno</span>";
$('#'+element).attr("data-content",content);
var tooltip = $( "#"+element ).tooltip({
items: "[data-content]",
disabled: true,
content: function() {
var current = $( this );
if ($(current).attr( "data-content" )!==undefined) {
return $(current).attr( "data-content" );
}
if ( current.is( "[title]" ) ) {
return current.attr( "title" );
}
}}).on('mouseout focusout', function(event) {
event.stopImmediatePropagation();
});
tooltip.tooltip('open');
}
},
data : params
});
$('#'+element).data('status','show');
}