feat: Add supplier exports functionality with scheduling and admin management

This commit is contained in:
2026-01-10 15:19:24 +00:00
parent d8146457ea
commit ee43e18b25
5 changed files with 818 additions and 5 deletions

View File

@@ -24,6 +24,11 @@ class Siti_Stock_Admin {
*/
private $notices;
/**
* @var Siti_Stock_Supplier_Exports
*/
private $supplier_exports;
/**
* Cached settings snapshot for rendering.
*
@@ -35,11 +40,13 @@ class Siti_Stock_Admin {
* @param Siti_Stock_Settings $settings Settings repository.
* @param Siti_Stock_Sync_Controller $sync_controller Sync controller.
* @param Siti_Stock_Admin_Notices $notices Notice handler.
* @param Siti_Stock_Supplier_Exports $supplier_exports Supplier exports handler.
*/
public function __construct( Siti_Stock_Settings $settings, Siti_Stock_Sync_Controller $sync_controller, Siti_Stock_Admin_Notices $notices ) {
public function __construct( Siti_Stock_Settings $settings, Siti_Stock_Sync_Controller $sync_controller, Siti_Stock_Admin_Notices $notices, Siti_Stock_Supplier_Exports $supplier_exports ) {
$this->settings = $settings;
$this->sync_controller = $sync_controller;
$this->notices = $notices;
$this->supplier_exports = $supplier_exports;
}
/**
@@ -160,6 +167,15 @@ class Siti_Stock_Admin {
array( $this, 'render_settings_page' ),
'dashicons-products'
);
add_submenu_page(
'siti-stock-plugin',
__( 'Stock updates', 'siti-stock-plugin' ),
__( 'Stock updates', 'siti-stock-plugin' ),
'manage_options',
'siti-stock-plugin-stock-updates',
array( $this, 'render_stock_updates_page' )
);
}
/**
@@ -168,7 +184,12 @@ class Siti_Stock_Admin {
* @param string $hook Hook suffix.
*/
public function enqueue_admin_assets( $hook ) {
if ( 'toplevel_page_siti-stock-plugin' !== $hook ) {
$pages = array(
'toplevel_page_siti-stock-plugin',
'siti-stock-plugin_page_siti-stock-plugin-stock-updates',
);
if ( ! in_array( $hook, $pages, true ) ) {
return;
}
@@ -241,6 +262,112 @@ class Siti_Stock_Admin {
<?php
}
/**
* Render stock updates admin page.
*/
public function render_stock_updates_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$suppliers = $this->supplier_exports->get_supplier_configs();
$admin_email = get_option( 'admin_email' );
?>
<div class="wrap siti-stock-settings">
<h1><?php esc_html_e( 'Stock updates', 'siti-stock-plugin' ); ?></h1>
<p class="description">
<?php esc_html_e( 'Plan automatische e-mails met de bestellingen per leverancier in CSV-formaat.', 'siti-stock-plugin' ); ?>
<?php
if ( $admin_email ) {
printf(
/* translators: %s admin email */
esc_html__( 'E-mails worden verzonden naar %s.', 'siti-stock-plugin' ),
esc_html( $admin_email )
);
}
?>
</p>
<?php if ( empty( $suppliers ) ) : ?>
<p><?php esc_html_e( 'Er zijn momenteel geen leveranciers gevonden.', 'siti-stock-plugin' ); ?></p>
<?php else : ?>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<?php wp_nonce_field( 'siti_stock_save_supplier_schedule' ); ?>
<input type="hidden" name="action" value="siti_stock_save_supplier_schedule" />
<table class="widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e( 'Leverancier', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Tijd (24u)', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Automatisch verzenden', 'siti-stock-plugin' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $suppliers as $key => $config ) : ?>
<tr>
<td><?php echo esc_html( isset( $config['supplier'] ) ? $config['supplier'] : $key ); ?></td>
<td>
<input
type="time"
name="<?php echo esc_attr( 'supplier_exports[' . $key . '][time]' ); ?>"
value="<?php echo esc_attr( isset( $config['time'] ) ? $config['time'] : '09:00' ); ?>"
step="60"
class="regular-text"
/>
</td>
<td>
<label>
<input
type="checkbox"
name="<?php echo esc_attr( 'supplier_exports[' . $key . '][enabled]' ); ?>"
value="1"
<?php checked( ! empty( $config['enabled'] ) ); ?>
/>
<?php esc_html_e( 'Activeer e-mail', 'siti-stock-plugin' ); ?>
</label>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php submit_button( __( 'Instellingen opslaan', 'siti-stock-plugin' ) ); ?>
</form>
<h2><?php esc_html_e( 'Handmatig versturen', 'siti-stock-plugin' ); ?></h2>
<p class="description"><?php esc_html_e( 'Gebruik deze knoppen om direct een export te versturen, ook als de automatische taak uit staat.', 'siti-stock-plugin' ); ?></p>
<table class="widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e( 'Leverancier', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Geplande tijd', 'siti-stock-plugin' ); ?></th>
<th><?php esc_html_e( 'Actie', 'siti-stock-plugin' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $suppliers as $key => $config ) : ?>
<tr>
<td><?php echo esc_html( isset( $config['supplier'] ) ? $config['supplier'] : $key ); ?></td>
<td><?php echo esc_html( isset( $config['time'] ) ? $config['time'] : '00:00' ); ?></td>
<td>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<?php wp_nonce_field( 'siti_stock_send_supplier_export' ); ?>
<input type="hidden" name="action" value="siti_stock_send_supplier_export" />
<input type="hidden" name="supplier_key" value="<?php echo esc_attr( $key ); ?>" />
<?php submit_button( __( 'Verstuur nu', 'siti-stock-plugin' ), 'secondary', 'submit', false ); ?>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<?php
}
/**
* Render a text/password input.
*