Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/admin/faktury.php |
<?php
include('config.php');
require 'fpdf/fpdf.php'; // lub tcpdf
require 'fpdf/src/fpdi.php'; // lub tcpdf
function addPdf($pdf, $filename) {
$pageCount = $pdf->setSourceFile($filename);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$pdf->addPage();
$tplId = $pdf->importPage($pageNo);
$pdf->useTemplate($tplId);
}
}
$title = 'Faktury';
$obj = new Admin();
$servername = "67973.m.tld.pl";
$username = "admin67973_etykiety";
$password = "5BmF1MXif0";
$dbname = "baza67973_etykiety";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (!empty($_POST['pliki_pdf'])) {
$pdf = new FPDI();
foreach ($_POST['pliki_pdf'] as $id_pliku) {
$sql_plikipdf = "SELECT * FROM faktury WHERE id = ".$id_pliku;
$result_plikipdf = $conn->query($sql_plikipdf);
while ($row_plikipdf = $result_plikipdf->fetch_assoc()) {
$pageCount = $pdf->setSourceFile('/home/users/barii/public_html/finansenl.com.pl/wodki/admin/downloads/faktury/'.$row_plikipdf['filename']);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$pdf->AddPage();
$tplId = $pdf->importPage($pageNo);
$pdf->useTemplate($tplId);
}
}
// Dodatkowe operacje związane z formatowaniem itp.
}
// Output finalnego PDF
$nazwa_pliku = time().'.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.$nazwa_pliku.'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
$pdf->Output('D', $nazwa_pliku.'.pdf');
}
if (!empty($_POST['save'])) {
$pdf = new FPDI();
$miesiacRok = $_POST['miesiacRok'];
list($rok, $miesiac) = explode('-', $miesiacRok);
$sql_plikipdf = "SELECT *, faktury.id as id_faktury FROM faktury LEFT JOIN all_sprzedaze ON faktury.checkout_id = all_sprzedaze.formularz WHERE YEAR(all_sprzedaze.data) = $rok AND MONTH(all_sprzedaze.data) = $miesiac ORDER by faktury.numer ASC";
$result_plikipdf = $conn->query($sql_plikipdf);
while ($row_plikipdf = $result_plikipdf->fetch_assoc()) {
$pageCount = $pdf->setSourceFile('/home/users/barii/public_html/finansenl.com.pl/wodki/admin/downloads/faktury/'.$row_plikipdf['filename']);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$pdf->AddPage();
$tplId = $pdf->importPage($pageNo);
$pdf->useTemplate($tplId);
}
}
// Dodatkowe operacje związane z formatowaniem itp.
$nazwa_pliku = 'fvs'.$miesiac.'-'.$rok.'.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.$nazwa_pliku.'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
$mysql->sqlInsertArray('faktury_downloads', ['pobrano' => date('Y-m-d H:i:s'), 'rok' => $rok, 'miesiac' => $miesiac]);
$pdf->Output('D', $nazwa_pliku);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Prolabel Administrator | <?php echo $title;?></title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="the_assets/css/style2.css?v=<?php echo time(); ?>">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
<!-- DataTables -->
<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
<!-- Date Picker -->
<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
<!-- Daterange picker -->
<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
<!-- bootstrap wysihtml5 - text editor -->
<link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet" type="text/css" href="the_assets/css/vendors/datatables.css?ver=<?php echo $version; ?>">
<link rel="stylesheet" type="text/css" href="the_assets/css/vendors/daterange-picker.css?ver=<?php echo $version; ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
.result table tr td h3 {left:0px}
table tr.stat1 td,span.stat1{background:rgba(255,0,0,0.1)}
table tr.stat5 td,span.stat5{background:rgba(255,0,0,0.4)}
table tr.stat2 td,span.stat2{background:rgba(255,0,0,0.1)}
table tr.stat3 td,span.stat3{background:#CCFF99}
table tr.stat4 td,span.stat4{background:#99CC66}
table tr.stat0 td,span.stat0{background:#FFE0E0}
table tr.stat9 td,span.stat9{background:rgba(0,153,0,0.2)}
table tr.stat8 td,span.stat8{background:rgba(255,255,102,0.3)}
table tr.stat10 td,span.stat10{background:#F04000}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
$(document).ready(function() {
$('#modal-platnosc input').keyup(function(){
$('#modal-platnosc .modal-footer').show();
$('#modal-platnosc').find('input').each(function(){
if($(this).prop('required')){
if($(this).val() =='' ) $('#modal-platnosc .modal-footer').hide();
}
});
$('#modal-platnosc input.wynikpayu').val('http://www.fotomagnesy.pl/p.php?imie='+$('#modal-platnosc input.payuimie').val().replace(/\ /g, '+')+'&nazwa='+$('#modal-platnosc input.payunazwa').val().replace(/\ /g, '+')+'&kwota='+$('#modal-platnosc input.payukwota').val()+'&email='+$('#modal-platnosc input.payuemail').val()+'&tel='+$('#modal-platnosc input.payutel').val()+'');
});
});
$(document).on('scroll', function() {
// How far have we scrolled
var scrolltop= $(window).scrollTop();
var offset = $('table.table').offset();
// How high is the table now?
var tableheight = $('table.table').height();
// check to see if the bottom of the table is coming into
// view
console.log($(document).height() + ' / ' + $(window).scrollTop() + ' = ' + Math.round($(window).scrollTop() + $(window).height()));
if ($(document).height() == Math.round($(window).scrollTop() + $(window).height())) {
var iNum = parseInt($('#lazyloadpage').val());
$.ajax({type : 'POST',url : 'wypiszallegro.php?eventtype=<?php echo $_GET['eventtype'];?>&page='+(iNum+100),success : function(data) {$('table.table').append(data);}});
$('#lazyloadpage').val((iNum+100));
}
})
</script>
<script type="text/javascript">
function potwierdz(info){
input_box = confirm(info);
if (input_box == true) {
return true;
}
else {
alert();
return false;
}
}
</script>
<style>#example1_filter label{/*display:block*/} #example1_filter input{width:300px}</style>
<!-- Google Font -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-black sidebar-collapse sidebar-mini">
<div class="wrapper">
<header class="main-header">
<!-- Logo -->
<a href="#" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini" class="sidebar-toggle" data-toggle="push-menu" role="button"><i class="glyphicon glyphicon-menu-hamburger"></i></span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg" class="sidebar-toggle" data-toggle="push-menu" role="button"><i class="glyphicon glyphicon-menu-hamburger"></i></span>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top">
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<?php
$file = '../api/demo/accessToken0';
$file1 = '../api/demo/accessToken1';
$file2 = '../api/demo/accessToken2';
$file3 = '../api/demo/accessToken3';
if(filesize($file)) echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="manyak2 - aktywny token (kliknij aby odłączyć)"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest-rozlacz.php"><i class="fa fa-circle text-green"></i></a></li>';
elseif(filesize($file)=='0') echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="manyak2 - token wygasł '.file_get_contents('last_accessToken0').'"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest.php"><i class="fa fa-circle text-red"></i></a></li>';
if(filesize($file1)) echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="fotomagnesy_pl - aktywny token (kliknij aby odłączyć)"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest1-rozlacz.php"><i class="fa fa-circle text-green"></i></a></li>';
elseif(filesize($file1)=='0') echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="fotomagnesy_pl - token wygasł '.file_get_contents('last_accessToken1').'"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest1.php"><i class="fa fa-circle text-red"></i></a></li>';
if(filesize($file2)) echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="prolabel_pl - aktywny token (kliknij aby odłączyć)"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest2-rozlacz.php"><i class="fa fa-circle text-green"></i></a></li>';
elseif(filesize($file2)=='0') echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="prolabel_pl - token wygasł '.file_get_contents('last_accessToken2').'"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest2.php"><i class="fa fa-circle text-red"></i></a></li>';
if(filesize($file3)) echo '<li data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="fotomagnes_pl - aktywny token (kliknij aby odłączyć)"><a href="http://www.etykietyweselne.pl/api/demo/ApiTest3-rozlacz.php"><i class="fa fa-circle text-green"></i></a></li>';
elseif(filesize($file3)=='0') echo '<li><a href="http://www.etykietyweselne.pl/api/demo/ApiTest3.php" data-toggle="tooltip" data-html="true" title="" data-placement="bottom" data-widget="chat-pane-toggle" data-original-title="fotomagnes_pl - token wygasł '.file_get_contents('last_accessToken3').'"><i class="fa fa-circle text-red"></i></a></li>';
?>
<li>
<a href="classes/sprzedaze.php" target="_blank" class="pobierzdanenowe" ><i class="fa fa-refresh"></i> Pobierz sprzedaże</a>
</li>
</ul>
</div>
</nav>
</header>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<ul class="sidebar-menu tree" data-widget="tree">
<li>
<a href="sprzedaze.php">
<i class="fa fa-th"></i> <span>Wszystkie transakcje</span>
<span class="pull-right-container">
<span class="label bg-gray pull-right" style="margin: -4px;font-size:15px;"></span>
</span>
</a>
</li>
<li>
<a href="sprzedaze_x.php?wysylki">
<i class="fa fa-truck text-blue"></i> <span>Wysyłki</span>
<span class="pull-right-container">
<span class="label bg-blue pull-right" style="margin: -4px;font-size:15px"></span>
</span>
</a>
</li>
<li>
<a href="wiadomosci.php">
<i class="fa fa-file-text-o"></i> <span>Wiadomości automatyczne</span>
</a>
</li>
<li>
<a href="zestawienie.php">
<i class="fa fa-area-chart"></i> <span>Zestawienie sprzedaży</span>
</a>
</li>
<li>
<a href="faktury.php">
<i class="fa fa-file"></i> <span>Faktury</span>
</a>
</li>
<li>
<a href="zwroty.php">
<i class="fa fa-rotate-left"></i> <span>Zwroty</span>
</a>
</li>
<li>
<a href="skladki.php">
<i class="fa fa-images"></i> <span>Składki imienniki</span>
</a>
</li>
<li>
<a href="./skladki/index2.php">
<i class="fa fa-images"></i> <span>Składki </span>
</a>
</li>
</ul>
</section>
<!-- /.sidebar -->
</aside>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1><?php echo $title;?>
<small>Dashboard</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active"><?php echo $title;?></li>
</ol>
</section>
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Lista faktur</h3>
<?php
$sql2 = "SELECT DISTINCT YEAR(data_utworzenia) AS rok, MONTH(data_utworzenia) AS miesiac FROM faktury ORDER BY data_utworzenia DESC";
$result2 = $conn->query($sql2);
// Tablica do przechowywania miesięcy i lat
$miesiaceLata = [];
if ($result2->num_rows > 0) {
while ($row2 = $result2->fetch_assoc()) {
$miesiaceLata[] = $row2;
}
}
?>
</div>
<!-- /.box-header -->
<div class="box-body">
<form action="faktury.php" method="post">
<div class="col-xs-2">
<select class="form-control" name="miesiacRok" id="miesiacRok">
<?php foreach ($miesiaceLata as $data): ?>
<option value="<?php echo $data['rok'] . '-' . str_pad($data['miesiac'], 2, '0', STR_PAD_LEFT); ?>">
<?php echo $data['rok'] . '-' . str_pad($data['miesiac'], 2, '0', STR_PAD_LEFT); ?>
<?php
$row3 = $mysql->sqlQuery("SELECT SUM(kwota_faktury) as count FROM faktury JOIN all_sprzedaze ON faktury.checkout_id = all_sprzedaze.formularz WHERE YEAR(all_sprzedaze.data) = '".$data['rok']."' AND MONTH(all_sprzedaze.data) = '".$data['miesiac']."' ORDER by faktury.numer ASC");
$row55 = $mysql->sqlQuery("SELECT * FROM faktury_downloads WHERE rok = '".$data['rok']."' AND miesiac = '".str_pad($data['miesiac'], 2, '0', STR_PAD_LEFT)."' ORDER by id DESC LIMIT 1");
echo '('.$row3[0]['count'].'zł) ';
echo $row55[0]['pobrano'];
?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-xs-10">
<!-- <button class="btn btn-success" type="submit" name="show" value="1">Wyświetl faktury</button> -->
<button class="btn btn-primary" type="submit" name="save" value="1">Pobierz cały miesiąc</button>
</div>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" and $_POST['show'] == 1) {
$miesiacRok = $_POST['miesiacRok'];
list($rok, $miesiac) = explode('-', $miesiacRok);
$sql = "SELECT *, faktury.id as id_faktury FROM faktury LEFT JOIN all_sprzedaze ON faktury.checkout_id = all_sprzedaze.formularz WHERE YEAR(faktury.data_utworzenia) = $rok AND MONTH(faktury.data_utworzenia) = $miesiac";
} else {
$sql = "SELECT *, faktury.id as id_faktury FROM faktury LEFT JOIN all_sprzedaze ON faktury.checkout_id = all_sprzedaze.formularz ORDER by faktury.id DESC ";
}
$result = $conn->query($sql);
?>
<div class="col-xs-12">
<div style="border:0 !important;border-radius:0px;padding:0px;margin:0 auto;width:100%;" class="ajax">
<?php if ($result->num_rows > 0) { ?>
<form action="faktury.php" method="post" style="margin-bottom: 50px;">
<div class="table-responsive">
<table class="display" id="basicx">
<thead>
<tr>
<th>#</th>
<th>Numer faktury</th>
<th>Kwota</th>
<th>Data wystawienia</th>
<th>Data sprzedaży</th>
<th>E-mail</th>
<th>Login</th>
<th>Akcje</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<!-- Zero Configuration Ends-->
</div>
<div id="bottomBar" style="display: none; position: fixed; bottom: 0; left: 0; width:100%; background-color: #333; color: white; text-align: center; padding: 10px;">
<button type="submit" class="btn btn-primary btn-lg">Połącz i pobierz zaznaczone</button>
</div>
</form>
<?php } else {
echo 'brak wyników';
}
?>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#utworz-fakture-button2').on('click', function() {
// Zbieranie danych z formularza
// Wysyłanie danych za pomocą AJAX
$.ajax({
url: 'https://www.etykietyweselne.pl/admin/classes/fv_ajax.php', // Zmień na odpowiedni URL
type: 'POST',
data: $("#fakturaModal form").serialize() + '&type=updateInvoice',
success: function(response) {
$('#fakturaModal').modal('hide');
$('#fakturaDodano .nazwa_faktury').html(response.numer_faktury);
$('#fakturaDodano .link_do_faktury').attr('href', 'https://www.etykietyweselne.pl/admin/downloads/faktury/'+response.filename);
$('.download-button-item[data-id="'+response.checkout_id+'"]').attr('href', 'https://www.etykietyweselne.pl/admin/downloads/faktury/'+response.filename);
$('#fakturaDodano').modal('show');
console.log('Odpowiedź serwera: ' + response);
},
error: function(xhr, status, error) {
// Obsługa błędów
console.error('Wystąpił błąd: ' + error);
}
});
});
});
$(document).ready(function() {
$('#basicx').on('click', '.utworz-fakture2', function() {
var id = $(this).data('id'); // Pobieranie ID
var konto_id = $(this).data('konto'); // Pobieranie ID
$.ajax({
url: 'https://www.etykietyweselne.pl/admin/classes/fv_ajax.php', // Zmień na rzeczywistą ścieżkę
type: 'POST',
data: { 'id': id, 'konto_id': konto_id, 'id_update': 1 },
success: function(response) {
console.log(response);
//$('#fakturaModal .modal-body').html(response);
$('#fakturaModal #faktura_checkout_id').val(response.id);
$('#fakturaModal #konto_id').val(response.konto_id);
$('#fakturaModal #faktura_nazwa').val(response.nazwa);
$('#fakturaModal #faktura_nip').val(response.nip);
$('#fakturaModal #faktura_ulica').val(response.ulica);
$('#fakturaModal #faktura_miasto').val(response.city);
$('#fakturaModal #produkty').html(response.produkty);
$('#fakturaModal #faktura_zipcode').val(response.zipcode);
$('#fakturaModal #numer_fv').val(response.numer_faktury);
$('#modal-default').modal('hide');
$('#fakturaModal').modal('show');
$('#utworz-fakture-button').hide();
$('#utworz-fakture-button2').show();
},
error: function() {
alert('Wystąpił błąd podczas pobierania danych');
}
});
});
});
</script>
<?php include('_footer5.php');?>
<script>
function toggleBottomBar() {
// Check if any of the checkboxes are checked
if ($('.pdf_checkbox:checked').length > 0) {
$('#bottomBar').show(); // Show the bottomBar if any checkboxes are checked
} else {
$('#bottomBar').hide(); // Hide the bottomBar if none are checked
}
}
// Event handler for change events on checkboxes with class 'pdf_checkbox'
$('#basicx').on('change', '.pdf_checkbox', function() {
toggleBottomBar();
});
</script>