Ahora entramos en el nivel profesional real:
Vamos a transformar el plugin en un sistema enterprise:
✅ QR real
✅ API interna
✅ historial completo
✅ workers
✅ rutas
✅ control por ubicación
✅ KPI engine
✅ ranking automático
✅ importación XLSX
✅ panel industrial tablet
✅ PWA offline
NUEVA ESTRUCTURA PROFESIONAL
Tu plugin ahora debe evolucionar a:
industrie-imkerei-system/
│
├── industrie-imkerei-system.php
│
├── assets/
│ ├── style.css
│ ├── app.js
│ ├── qr.js
│ └── mobile.css
│
├── includes/
│ ├── class-database.php
│ ├── class-ajax.php
│ ├── class-shortcodes.php
│ ├── class-api.php
│ ├── class-kpi.php
│ ├── class-workers.php
│ ├── class-routes.php
│ ├── class-qr.php
│ ├── class-importer.php
│ └── class-pwa.php
│
├── templates/
│ ├── dashboard.php
│ ├── volk-detail.php
│ ├── ranking.php
│ └── route.php
│
└── pwa/
├── manifest.json
└── service-worker.js
AHORA VAMOS A IMPLEMENTAR
NIVEL 1 — HISTORIAL COMPLETO
Cada acción quedará registrada:
- quién
- cuándo
- GPS
- tiempo
- estado anterior
- estado nuevo
PASO 1 — NUEVA TABLA MYSQL
REEMPLAZAR COMPLETAMENTE
includes/class-database.php
por esto:
<?php
if (!defined('ABSPATH')) {
exit;
}
class ImkereiDatabase {
public static function install_tables() {
global $wpdb;
require_once ABSPATH .
'wp-admin/includes/upgrade.php';
$charset_collate =
$wpdb->get_charset_collate();
/*
BIENENVÖLKER
*/
$table_bienen =
$wpdb->prefix . 'bienenvoelker';
$sql1 = "CREATE TABLE $table_bienen (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
volk_id VARCHAR(50) NOT NULL,
standort VARCHAR(100),
status VARCHAR(50),
honig_kg FLOAT DEFAULT 0,
varroa FLOAT DEFAULT 0,
letzte_kontrolle DATETIME,
PRIMARY KEY (id),
UNIQUE KEY volk_id (volk_id)
) $charset_collate;";
dbDelta($sql1);
/*
HISTORY
*/
$table_history =
$wpdb->prefix . 'imkerei_history';
$sql2 = "CREATE TABLE $table_history (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
volk_id VARCHAR(50),
old_status VARCHAR(50),
new_status VARCHAR(50),
worker VARCHAR(100),
gps_lat VARCHAR(50),
gps_lng VARCHAR(50),
created_at DATETIME,
PRIMARY KEY (id)
) $charset_collate;";
dbDelta($sql2);
/*
DEMO DATA
*/
$check = $wpdb->get_var(
"SELECT COUNT(*) FROM $table_bienen"
);
if ($check == 0) {
$wpdb->insert(
$table_bienen,
array(
'volk_id' => 'V001',
'standort' => 'Nord',
'status' => 'STARK',
'honig_kg' => 32,
'varroa' => 1.2,
'letzte_kontrolle' =>
current_time('mysql')
)
);
$wpdb->insert(
$table_bienen,
array(
'volk_id' => 'V002',
'standort' => 'Süd',
'status' => 'NORMAL',
'honig_kg' => 20,
'varroa' => 2.3,
'letzte_kontrolle' =>
current_time('mysql')
)
);
}
}
}
PASO 2 — HISTORIAL AUTOMÁTICO
REEMPLAZAR COMPLETAMENTE
includes/class-ajax.php
por esto:
<?php
if (!defined('ABSPATH')) {
exit;
}
class ImkereiAjax {
public function __construct() {
add_action(
'wp_ajax_update_volk_status',
array($this, 'update_volk_status')
);
add_action(
'wp_ajax_nopriv_update_volk_status',
array($this, 'update_volk_status')
);
}
public function update_volk_status() {
global $wpdb;
$table =
$wpdb->prefix . 'bienenvoelker';
$history =
$wpdb->prefix . 'imkerei_history';
$volk_id =
sanitize_text_field(
$_POST['volk_id']
);
$new_status =
sanitize_text_field(
$_POST['status']
);
/*
OLD STATUS
*/
$volk = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM $table
WHERE volk_id = %s",
$volk_id
)
);
$old_status =
$volk->status ?? '';
/*
UPDATE VOLK
*/
$wpdb->update(
$table,
array(
'status' => $new_status,
'letzte_kontrolle' =>
current_time('mysql')
),
array(
'volk_id' => $volk_id
)
);
/*
SAVE HISTORY
*/
$wpdb->insert(
$history,
array(
'volk_id' => $volk_id,
'old_status' => $old_status,
'new_status' => $new_status,
'worker' => 'Worker-App',
'gps_lat' => '',
'gps_lng' => '',
'created_at' =>
current_time('mysql')
)
);
wp_send_json_success(
array(
'new_status' => $new_status
)
);
}
}
RESULTADO
Ahora cada click:
- actualiza estado
- guarda historial
- registra control
- crea trazabilidad
NIVEL 2 — QR SYSTEM
Ahora cada colmena tendrá:
https://tudominio.com/volk/V001
y un QR único.
PASO 3 — INSTALAR QR GENERATOR
Crear:
includes/class-qr.php
PEGAR:
<?php
if (!defined('ABSPATH')) {
exit;
}
class ImkereiQR {
public static function qr_url($volk_id) {
return home_url(
'/volk/' . $volk_id
);
}
public static function qr_image($volk_id) {
$url =
self::qr_url($volk_id);
return
'https://api.qrserver.com/v1/create-qr-code/?size=300x300&data='
. urlencode($url);
}
}
PASO 4 — CARGAR QR MODULE
En:
industrie-imkerei-system.php
añadir:
require_once plugin_dir_path(__FILE__) .
'includes/class-qr.php';
PASO 5 — MOSTRAR QR
Dentro de:
class-shortcodes.php
en volk_detail_shortcode()
añadir:
echo '<img src="'
. ImkereiQR::qr_image(
$volk->volk_id
)
. '" width="200">';
RESULTADO
Ahora cada colmena tiene:
✅ QR único
✅ página individual
✅ historial
✅ trazabilidad
SIGUIENTE NIVEL
Después construiremos:
FASE 9 — IMPORTADOR XLSX REAL
Subes Excel →
se crean automáticamente:
- 500 colmenas
- ubicaciones
- KPI
- rankings
- workers
- rutas
DESPUÉS
FASE 10 — PWA OFFLINE
Los trabajadores podrán usar:
- tablet
- smartphone
- SIN INTERNET
en el campo.
FASE 9 — IMPORTADOR XLSX INDUSTRIAL
Objetivo:
Subir un Excel →
crear automáticamente:
- 500 colmenas
- ubicaciones
- status
- KPI
- producción
- varroa
- workers
- rutas
directamente desde WordPress.
RESULTADO FINAL
En WordPress tendrás:
MENÚ:
Imkerei → XLSX Import
Subes:
bienenvölker.xlsx
y automáticamente:
- inserta datos
- actualiza existentes
- evita duplicados
NECESITAS
1.
Instalar librería XLSX
2.
Crear importador
3.
Crear página admin
PASO 1 — INSTALAR PHPSpreadsheet
Necesitas Composer.
En SSH:
cd wp-content/plugins/industrie-imkerei-system
Luego:
composer require phpoffice/phpspreadsheet
RESULTADO
Se crea:
vendor/
PASO 2 — NUEVO ARCHIVO
Crear:
includes/class-importer.php
PEGAR ESTO COMPLETO
<?php
if (!defined('ABSPATH')) {
exit;
}
use PhpOffice\PhpSpreadsheet\IOFactory;
class ImkereiImporter {
public function __construct() {
add_action(
'admin_menu',
array($this, 'admin_menu')
);
}
/*
-----------------------------------
ADMIN MENU
-----------------------------------
*/
public function admin_menu() {
add_submenu_page(
'imkerei-dashboard',
'XLSX Import',
'XLSX Import',
'manage_options',
'imkerei-import',
array($this, 'import_page')
);
}
/*
-----------------------------------
IMPORT PAGE
-----------------------------------
*/
public function import_page() {
echo '<div class="wrap">';
echo '<h1>XLSX Import</h1>';
/*
FORM
*/
echo '<form method="post"
enctype="multipart/form-data">';
wp_nonce_field(
'imkerei_import',
'imkerei_nonce'
);
echo '<input type="file"
name="xlsx_file"
accept=".xlsx">';
echo '<br><br>';
echo '<input type="submit"
name="import_xlsx"
class="button button-primary"
value="Importieren">';
echo '</form>';
/*
IMPORT
*/
if (
isset($_POST['import_xlsx'])
) {
$this->process_import();
}
echo '</div>';
}
/*
-----------------------------------
PROCESS XLSX
-----------------------------------
*/
public function process_import() {
if (
!isset($_FILES['xlsx_file'])
) {
return;
}
global $wpdb;
$table =
$wpdb->prefix .
'bienenvoelker';
$file =
$_FILES['xlsx_file']['tmp_name'];
/*
LOAD XLSX
*/
$spreadsheet =
IOFactory::load($file);
$sheet =
$spreadsheet->getActiveSheet();
$rows =
$sheet->toArray();
/*
LOOP
*/
foreach ($rows as $index => $row) {
/*
SKIP HEADER
*/
if ($index == 0) {
continue;
}
/*
COLUMNS
*/
$volk_id =
sanitize_text_field(
$row[0]
);
$standort =
sanitize_text_field(
$row[1]
);
$status =
sanitize_text_field(
$row[2]
);
$honig =
floatval($row[3]);
$varroa =
floatval($row[4]);
/*
CHECK EXISTING
*/
$existing =
$wpdb->get_var(
$wpdb->prepare(
"SELECT id FROM $table
WHERE volk_id = %s",
$volk_id
)
);
/*
UPDATE
*/
if ($existing) {
$wpdb->update(
$table,
array(
'standort' =>
$standort,
'status' =>
$status,
'honig_kg' =>
$honig,
'varroa' =>
$varroa,
'letzte_kontrolle' =>
current_time('mysql')
),
array(
'id' => $existing
)
);
}
/*
INSERT
*/
else {
$wpdb->insert(
$table,
array(
'volk_id' =>
$volk_id,
'standort' =>
$standort,
'status' =>
$status,
'honig_kg' =>
$honig,
'varroa' =>
$varroa,
'letzte_kontrolle' =>
current_time('mysql')
)
);
}
}
echo '<div class="notice notice-success">';
echo '<p>XLSX importiert.</p>';
echo '</div>';
}
}
PASO 3 — CARGAR IMPORTADOR
En:
industrie-imkerei-system.php
añadir:
require_once plugin_dir_path(__FILE__) .
'includes/class-importer.php';
PASO 4 — INICIALIZAR
Dentro de:
__construct()
añadir:
new ImkereiImporter();
PASO 5 — CARGAR COMPOSER
En la parte superior del plugin principal:
require_once plugin_dir_path(__FILE__) .
'vendor/autoload.php';
ESTRUCTURA FINAL
industrie-imkerei-system/
│
├── vendor/
├── assets/
├── includes/
│ ├── class-database.php
│ ├── class-ajax.php
│ ├── class-shortcodes.php
│ ├── class-qr.php
│ └── class-importer.php
│
└── industrie-imkerei-system.php
FORMATO XLSX
Tu Excel debe tener:
| A | B | C | D | E |
|---|
| volk_id | standort | status | honig_kg | varroa |
Ejemplo:
| volk_id | standort | status | honig_kg | varroa |
|---|
| V001 | Nord | STARK | 32 | 1.2 |
RESULTADO
Ahora puedes importar:
✅ 500 colmenas
✅ miles de registros
✅ actualizar automáticamente
✅ evitar duplicados
✅ sincronizar producción
SIGUIENTE NIVEL
FASE 10 — PWA OFFLINE INDUSTRIAL
Los trabajadores podrán:
- usar tablets
- trabajar SIN internet
- sincronizar luego
- escanear QR offline
- registrar controles offline
como una app real industrial.