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

282 lines
10 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: 'saas',
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 s.replace('.', '').replace(',', '.').replace('%', '');
},
// 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");
});
});
// call the tablesorter plugin
$("table").tablesorter({
theme: 'blue',
// initialize zebra striping of the table
widgets: ['zebra','staticRow'],
// change the default striping class names
// updated in v2.1 to use widgetOptions.zebra = ["even", "odd"]
// widgetZebra: { css: [ "normal-row", "alt-row" ] } still works
widgetOptions : {
zebra : [ "normal-row", "alt-row" ]
}
});
});