Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/admin/server_processing.php |
<?php
include ('config.php');
/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simple to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See https://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - https://datatables.net/license_mit
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
// DB table to use
$table = 'all_sprzedaze';
// Table's primary key
$primaryKey = 'id';
function convertDate($data)
{
$czas = strtotime($data);
$teraz = time();
$roznica = $teraz - $czas;
$dzien = 60 * 60 * 24;
$miesiace = [
1 => 'stycznia', 2 => 'lutego', 3 => 'marca',
4 => 'kwietnia', 5 => 'maja', 6 => 'czerwca',
7 => 'lipca', 8 => 'sierpnia', 9 => 'września',
10 => 'października', 11 => 'listopada', 12 => 'grudnia'
];
$dzien = date('j', $czas);
$miesiac = $miesiace[intval(date('n', $czas))];
$rok = date('Y', $czas);
$data_nowa = '<span class="">'.$dzien.' '.$miesiac.' '.$rok.'</span>';
$godzina = '<span class="">'.date('H:i:s', $czas).'</span>';
return "{$data_nowa}<br />{$godzina}";
}
function getDostawa($data) {
global $mysql;
$row = $mysql->sqlRow("dostawa", "all_sprzedaze", "WHERE email = '".$data."'");
$row2 = $mysql->sqlRow("numer", "all_wysylki", "WHERE email = '".$data."'");
if (isset($row['dostawa'])) {
$dostawa = $row['dostawa'];
} else {
$dostawa = '?';
}
if (isset($row2['numer'])) {
$numer_wysylki = $row2['numer'];
} else {
$numer_wysylki = '?';
}
return $dostawa.' '.$numer_wysylki;
}
function convertKonto($data) {
if ($data == 0) {
$status = '<span class="badge badge-primary">manyak2</span>';
} elseif ($data == 1) {
$status = '<span class="badge badge-success">fotomagnesy_pl</span>';
} elseif ($data == 2) {
$status = '<span class="badge badge-secondary">prolabel_pl</span>';
} elseif ($data == 3) {
$status = '<span class="badge badge-dark tag-pills-sm-m">fotomagnes_pl</span>';
} else {
$status = '<span class="badge badge-light badge-sklep-label text-dark">sklep</span>';
}
return $status;
}
function czyWygenerowanaSkladka($row) {
global $mysql;
$count = $mysql->sqlCount("SELECT id from skladki_imienniki WHERE id_zamowienia = '".$row['formularz']."'");
if ($count < 1) {
$count = $mysql->sqlCount("SELECT id from skladki_wzory WHERE id_zamowienia = '".$row['formularz']."'");
}
return $count;
}
function convertStatus($row) {
$return = '<select class="selectpicker" data-live-search="false" data-id="'.$row['id'].'">';
$return .= '<option value="PENDING" data-content="<span class=\'badge label-pending\'>oczekiwanie</span>"';
if ($row['eventid'] == 'PENDING') {
$return .= ' selected';
}
$return .= '>oczekiwanie</option>';
$return .= '<option value="IN_TRANSIT" data-content="<span class=\'badge label-intransit\'>w drodze</span>"';
if ($row['eventid'] == 'IN_TRANSIT') {
$return .= ' selected';
}
$return .= '>w drodze</option>';
$return .= '<option value="RELEASED_FOR_DELIVERY" data-content="<span class=\'badge label-releasedfordelivery\'>w doręczeniu</span>"';
if ($row['eventid'] == 'RELEASED_FOR_DELIVERY') {
$return .= ' selected';
}
$return .= '>w doręczeniu</option>';
$return .= '<option value="AVAILABLE_FOR_PICKUP" data-content="<span class=\'badge label-availableforpickup\'>do odbioru</span>"';
if ($row['eventid'] == 'AVAILABLE_FOR_PICKUP') {
$return .= ' selected';
}
$return .= '>do odbioru</option>';
$return .= '<option value="DELIVERED" data-content="<span class=\'badge label-delivered\'>dostarczono</span>"';
if ($row['eventid'] == 'DELIVERED') {
$return .= ' selected';
}
$return .= '>dostarczono</option>';
$return .= '<option value="RETURNED" data-content="<span class=\'badge label-returned\'>zwrot</span>"';
if ($row['eventid'] == 'RETURNED') {
$return .= ' selected';
}
$return .= '>zwrot</option>';
$return .= '<option value="NADANE" data-content="<span class=\'badge label-issue\'>w nadaniu</span>"';
if ($row['eventid'] == 'NADANE') {
$return .= ' selected';
}
$return .= '>w nadaniu</option>';
$return .= '</select>';
return $return;
}
function convertKwota($row) {
if ($row['czyfv'] > 0) {
$fv = '<span class="badge badge-info">FV</span>';
} else {
$fv = '';
}
if ($row['info'] != '') {
$message_icon = '<span class="badge badge-info2"><i class="fa-regular fa-message"></i></span>';
} else {
$message_icon = '';
}
return '<p class="m-0 font-success f-w-700">'.$row['kwota'].'zł '.$fv.' '.$message_icon .'</p>';
}
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'email', 'dt' => 2 ),
array( 'db' => 'login', 'dt' => 3 ),
array(
'db' => 'data',
'dt' => 1,
'formatter' => function( $d, $row ) {
return convertDate($d);
}
),
array(
'db' => 'cokupil',
'dt' => 2,
'formatter' => function($d, $row) {
// Łączy kolumny 'login' i 'email' z bazy danych
if($row['login'] != 'sklep') {
return '<a href="https://mail.google.com/mail/u/0/#search/'.$row['login'].'" target="gmail"><span class="allegro-login">'.$row['login'] . '</span><br /><span class="allegro-email">' . $row['email'] . '</span></a>';
} else {
return '<a href="https://mail.google.com/mail/u/0/#search/'.$row['email'].'" target="gmail"><span class="allegro-email">' . $row['email'] . '</span></a>';
}
}
),
array(
'db' => 'kontoallegro',
'dt' => 3,
'formatter' => function( $d, $row ) {
return convertKonto($d);
}
),
array( 'db' => 'cokupil', 'dt' => 4 ),
array( 'db' => 'czyfv', 'dt' => 5 ),
array(
'db' => 'kwota',
'dt' => 5,
'formatter' => function( $d, $row ) {
return convertKwota($row);
}
),
array(
'db' => 'eventid',
'dt' => 6,
'formatter' => function( $d, $row ) {
return convertStatus($row);
}
),
array( 'db' => 'numerwysylki', 'dt' => 7 ),
array(
'db' => 'dostawa',
'dt' => 7,
'formatter' => function($d, $row) {
// Łączy kolumny 'login' i 'email' z bazy danych
if($row['czyfv'] > 0) {
$sql5 = "SELECT data_utworzenia FROM faktury WHERE checkout_id = '".$row['formularz']."' LIMIT 1";
$res5 = mysql_query($sql5);
$ile5 = mysql_num_rows($res5);
if ($ile5 > 0 ) {
while ($row5 = mysql_fetch_array($res5)) {
$roww= $row5['data_utworzenia'];
}
}
} else {
$roww = '0';
}
if ($row['numerwysylki'] != '') {
if ($row['dostawa'] == 'Allegro Przesyłka polecona' || $row['dostawa'] == 'Allegro Pocztex Kurier 48' || $row['dostawa'] == 'Allegro Kurier Pocztex' || $row['dostawa'] == 'Allegro MiniPrzesyłka') {
$link_przesylki = 'https://emonitoring.poczta-polska.pl/?numer='.$row['numerwysylki'];
} elseif ($row['dostawa'] == 'Allegro Odbiór w Punkcie UPS' || $row['dostawa'] == 'Allegro Kurier UPS') {
$link_przesylki = 'https://www.ups.com/track?tracknum='.$row['numerwysylki'].'&loc=pl_PL&requester=ST/trackdetails';
} elseif ($row['dostawa'] == 'Allegro One Box, UPS' || $row['dostawa'] == 'Allegro One Punkt, UPS' || $row['dostawa'] == 'Allegro One Box, One Kurier') {
$link_przesylki = 'https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$row['numerwysylki'];
} elseif ($row['dostawa'] == 'Allegro Kurier DPD' ) {
$link_przesylki = 'https://tracktrace.dpd.com.pl/parcelDetails?typ=1&p1='.$row['numerwysylki'];
}
elseif ($row['dostawa'] == 'Allegro One Box, DPD') {
$link_przesylki = 'https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$row['numerwysylki'];
} elseif ($row['dostawa'] == 'Allegro One Box' || $row['dostawa'] == 'Allegro One Punkt' || $row['dostawa'] == 'Allegro One Kurier - dostawa jutro' || $row['dostawa'] == 'Allegro One Punkt, One Kurier' ) {
$link_przesylki = 'https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$row['numerwysylki'];
} else {
$link_przesylki = 'https://twoj.inpost.pl/pl/znajdz-przesylke?parcel='.str_replace('K','',$row['numerwysylki']);
}
if ($row['eventid'] == 'RETURNED') {
return '<button type="button" data-id="'.$row['formularz'].'" class="wykonaj_zwrot btn btn-primary">Wykonaj zwrot</button>';
} else {
return '<span class="dostawa"><a target="_blank" href="'.$link_przesylki.'">'.$row['dostawa'].'<br /><span class="badge badge-primary numerwysylki noclick">' . $row['numerwysylki'] . '</span></a></span><span style="display:none;" class="czyfaktura_utworzona">'.$roww.'</span><span style="display:none;" class="czyfaktura">'.$row['czyfv'].'</span>';
}
} else {
if ($row['eventid'] == 'RETURNED') {
$return = '<button type="button" data-id="'.$row['formularz'].'" class="wykonaj_zwrot btn btn-primary">Wykonaj zwrot</button>';
} else {
$return = '<span class="dostawa">'.$row['dostawa'].'</span><br /><span class="badge badge-primary numerwysylki noclick">' . $row['numerwysylki'] . '</span>';
}
$return .= '<span style="display:none;" class="czyfaktura_utworzona">'.$roww.'</span><span style="display:none;" class="czyfaktura">'.$row['czyfv'].'</span></td>';
return $return;
}
// Łączy kolumny 'login' i 'email' z bazy danych
}
),
array( 'db' => 'formularz', 'dt' => 8 ),
array( 'db' => 'e_id', 'dt' => 9 ),
array( 'db' => 'kontoallegro', 'dt' => 10 ),
array( 'db' => 'info', 'dt' => 11 ),
array(
'db' => 'formularz',
'dt' => 12,
'formatter' => function( $d, $row ) {
return intval(czyWygenerowanaSkladka($row));
}
),
);
$sql_details = array(
'type' => 'Mysql',
'user' => 'admin67973_etykiety',
'pass' => '5BmF1MXif0',
'db' => 'baza67973_etykiety',
'host' => '67973.m.tld.pl'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'ssp.class.php' );
if (isset($_GET['search']['value'])) {
$_GET['search']['value'] = str_replace(' ', '', $_GET['search']['value']);
$_GET['search']['value'] = str_replace('.', '', $_GET['search']['value']);
}
$whereConditions = [];
if (isset($_GET['dateRange']) && !empty($_GET['dateRange'])) {
$dates = explode(' - ', $_GET['dateRange']);
if (count($dates) === 2) {
$startDate = DateTime::createFromFormat('d/m/Y', trim($dates[0]))->format('Y-m-d');
$endDate = DateTime::createFromFormat('d/m/Y', trim($dates[1]))->format('Y-m-d');
if ($startDate === $endDate) {
// If the start date and end date are the same, adjust the query to cover the whole day
$whereConditions[] = "(data >= '$startDate 00:00:00' AND data <= '$endDate 23:59:59')";
} else {
$whereConditions[] = "data BETWEEN '$startDate' AND '$endDate'";
}
}
}
$filter_status = isset($_GET['filter_status']) ? $_GET['filter_status'] : '';
if ($filter_status === 'PENDING') {
$whereConditions[] = "eventid is NULL OR eventid NOT IN ('IN_TRANSIT', 'DELIVERED', 'NADANE' ,'RELEASED_FOR_DELIVERY', 'AVAILABLE_FOR_PICKUP', 'RETURNED')";
} elseif (!empty($filter_status)) {
$whereConditions[] = "eventid = '$filter_status'";
}
$searchValue = isset($_GET['search']['value']) ? $_GET['search']['value'] : '';
if (!empty($searchValue)) {
// Tutaj dodaj warunki filtrowania w zależności od tego, jakie kolumny chcesz przeszukiwać.
// Przykład, jeśli chcesz przeszukiwać kolumnę 'email' i 'login':
$whereConditions[] = "(email LIKE '%$searchValue%' OR login LIKE '%$searchValue%' OR numerwysylki LIKE '%$searchValue%' OR kwota LIKE '%$searchValue%' OR dostawa LIKE '%$searchValue%' OR cokupil LIKE '%$searchValue%')";
}
$whereConditions[] = "dostawa != ''"; // Existing condition to ensure 'dostawa' is not empty
$whereResult = !empty($whereConditions) ? implode(' AND ', $whereConditions) : null;
echo json_encode(
SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, null, $whereResult, 'data DESC')
);