feat: Enhance user settings with cron URL plan display

- Added a new field to display the cron URL plan in user settings.
- Updated JavaScript to handle the new plan data.

refactor: Unify product model and migrate data

- Migrated product data from `products_data` to `products` table.
- Added new columns to `products` for better data organization.
- Created `products_aggregate` table for storing aggregated product metrics.

chore: Drop deprecated products_data table

- Removed `products_data` table as data is now stored in `products`.

feat: Add merchant URL flags to products

- Introduced flags for tracking merchant URL status in `products` table.
- Normalized product URLs to handle empty or invalid values.

feat: Link campaign alerts to specific products

- Added `product_id` column to `campaign_alerts` table for better tracking.
- Created an index for efficient querying of alerts by product.

chore: Add debug scripts for client data inspection

- Created debug scripts to inspect client data from local and remote databases.
- Included error handling and output formatting for better readability.
This commit is contained in:
2026-02-20 17:50:14 +01:00
parent 0024a25bfb
commit 167ced3573
31 changed files with 5697 additions and 1227 deletions

View File

@@ -12,19 +12,28 @@
<tr>
<th style="width: 60px;">#ID</th>
<th>Nazwa klienta</th>
<th style="width: 120px;">Status</th>
<th>Google Ads Customer ID</th>
<th>Merchant Account ID</th>
<th>Dane od</th>
<th style="width: 160px;">Sync</th>
<th style="width: 160px; text-align: center;">Akcje</th>
<th style="width: 190px;">Sync</th>
<th style="width: 250px; text-align: center;">Akcje</th>
</tr>
</thead>
<tbody>
<?php if ( $this -> clients ): ?>
<?php foreach ( $this -> clients as $client ): ?>
<tr data-id="<?= $client['id']; ?>">
<?php $is_client_active = (int) ( $client['active'] ?? 0 ) === 1; ?>
<tr data-id="<?= $client['id']; ?>" data-active="<?= $is_client_active ? 1 : 0; ?>">
<td class="client-id"><?= $client['id']; ?></td>
<td class="client-name"><?= htmlspecialchars( $client['name'] ); ?></td>
<td data-status-for="<?= $client['id']; ?>">
<?php if ( $is_client_active ): ?>
<span class="text-success"><strong>Aktywny</strong></span>
<?php else: ?>
<span class="text-danger"><strong>Nieaktywny</strong></span>
<?php endif; ?>
</td>
<td>
<?php if ( $client['google_ads_customer_id'] ): ?>
<span class="badge-id"><?= htmlspecialchars( $client['google_ads_customer_id'] ); ?></span>
@@ -48,13 +57,21 @@
</td>
<td class="client-sync" data-sync-id="<?= $client['id']; ?>"><span class="text-muted">—</span></td>
<td class="actions-cell">
<button type="button" class="btn-icon btn-icon-sync" onclick="toggleClientActive(<?= $client['id']; ?>, this)" title="<?= $is_client_active ? 'Dezaktywuj klienta' : 'Aktywuj klienta'; ?>">
<i class="fa-solid <?= $is_client_active ? 'fa-toggle-on' : 'fa-toggle-off'; ?>"></i>
</button>
<?php if ( $client['google_ads_customer_id'] ): ?>
<button type="button" class="btn-icon btn-icon-sync" onclick="syncClient(<?= $client['id']; ?>, 'campaigns', this)" title="Odśwież kampanie">
<button type="button" class="btn-icon btn-icon-sync client-sync-action" onclick="syncClient(<?= $client['id']; ?>, 'campaigns', this)" title="Odswiez kampanie" <?= $is_client_active ? '' : 'disabled'; ?>>
<i class="fa-solid fa-bullhorn"></i>
</button>
<button type="button" class="btn-icon btn-icon-sync" onclick="syncClient(<?= $client['id']; ?>, 'products', this)" title="Odśwież produkty">
<button type="button" class="btn-icon btn-icon-sync client-sync-action" onclick="syncClient(<?= $client['id']; ?>, 'products', this)" title="Odswiez produkty" <?= $is_client_active ? '' : 'disabled'; ?>>
<i class="fa-solid fa-box-open"></i>
</button>
<?php if ( !empty( $client['google_merchant_account_id'] ) ): ?>
<button type="button" class="btn-icon btn-icon-sync client-sync-action" onclick="syncClient(<?= $client['id']; ?>, 'campaigns_product_alerts_merchant', this)" title="Odswiez walidacje Merchant" <?= $is_client_active ? '' : 'disabled'; ?>>
<i class="fa-solid fa-store"></i>
</button>
<?php endif; ?>
<?php endif; ?>
<button type="button" class="btn-icon btn-icon-edit" onclick="editClient(<?= $client['id']; ?>)" title="Edytuj">
<i class="fa-solid fa-pen"></i>
@@ -67,7 +84,7 @@
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="7" class="empty-state">
<td colspan="8" class="empty-state">
<i class="fa-solid fa-building"></i>
<p>Brak klientów. Dodaj pierwszego klienta.</p>
</td>
@@ -92,6 +109,14 @@
<label for="client-name">Nazwa klienta</label>
<input type="text" id="client-name" name="name" class="form-control" required placeholder="np. Firma XYZ" />
</div>
<div class="settings-field">
<label for="client-active">Status klienta</label>
<select id="client-active" name="active" class="form-control">
<option value="1">Aktywny</option>
<option value="0">Nieaktywny</option>
</select>
<small class="text-muted">Nieaktywny klient nie jest synchronizowany.</small>
</div>
<div class="settings-field">
<label for="client-gads-id">Google Ads Customer ID</label>
<input type="text" id="client-gads-id" name="google_ads_customer_id" class="form-control" placeholder="np. 123-456-7890 (opcjonalnie)" />
@@ -121,6 +146,7 @@ function openClientForm()
$( '#client-modal-title' ).text( 'Dodaj klienta' );
$( '#client-id' ).val( '' );
$( '#client-name' ).val( '' );
$( '#client-active' ).val( '1' );
$( '#client-gads-id' ).val( '' );
$( '#client-gmc-id' ).val( '' );
$( '#client-gads-start' ).val( '' );
@@ -138,6 +164,7 @@ function editClient( id )
$( '#client-modal-title' ).text( 'Edytuj klienta' );
$( '#client-id' ).val( data.id );
$( '#client-name' ).val( data.name );
$( '#client-active' ).val( parseInt( data.active, 10 ) === 0 ? '0' : '1' );
$( '#client-gads-id' ).val( data.google_ads_customer_id || '' );
$( '#client-gmc-id' ).val( data.google_merchant_account_id || '' );
$( '#client-gads-start' ).val( data.google_ads_start_date || '' );
@@ -145,6 +172,67 @@ function editClient( id )
} );
}
function updateClientStatusUI( id, active, $btn )
{
var isActive = parseInt( active, 10 ) === 1;
var statusHtml = isActive
? '<span class="text-success"><strong>Aktywny</strong></span>'
: '<span class="text-danger"><strong>Nieaktywny</strong></span>';
$( 'tr[data-id="' + id + '"]' ).attr( 'data-active', isActive ? '1' : '0' );
$( 'td[data-status-for="' + id + '"]' ).html( statusHtml );
if ( $btn && $btn.length )
{
$btn.attr( 'title', isActive ? 'Dezaktywuj klienta' : 'Aktywuj klienta' );
$btn.find( 'i' ).attr( 'class', 'fa-solid ' + ( isActive ? 'fa-toggle-on' : 'fa-toggle-off' ) );
}
$( 'tr[data-id="' + id + '"] .client-sync-action' ).prop( 'disabled', !isActive );
var $syncCell = $( '.client-sync[data-sync-id="' + id + '"]' );
if ( !isActive )
{
$syncCell.html( '<span class="text-muted">nieaktywny</span>' );
}
else
{
loadSyncStatus();
}
}
function toggleClientActive( id, btn )
{
var $row = $( 'tr[data-id="' + id + '"]' );
var currentActive = parseInt( $row.attr( 'data-active' ), 10 ) === 1 ? 1 : 0;
var nextActive = currentActive === 1 ? 0 : 1;
var $btn = $( btn );
var $icon = $btn.find( 'i' );
var originalClass = $icon.attr( 'class' );
$btn.prop( 'disabled', true );
$icon.attr( 'class', 'fa-solid fa-spinner fa-spin' );
$.post( '/clients/set_active', { id: id, active: nextActive }, function( response ) {
var data = JSON.parse( response || '{}' );
$btn.prop( 'disabled', false );
$icon.attr( 'class', originalClass );
if ( data.success )
{
updateClientStatusUI( id, data.active, $btn );
return;
}
$.alert( {
title: 'Blad',
content: data.message || 'Nie udalo sie zmienic statusu klienta.',
type: 'red'
} );
} );
}
function syncClient( id, pipeline, btn )
{
var $btn = $( btn );
@@ -154,7 +242,11 @@ function syncClient( id, pipeline, btn )
$btn.prop( 'disabled', true );
$icon.attr( 'class', 'fa-solid fa-spinner fa-spin' );
var labels = { campaigns: 'kampanii', products: 'produktów' };
var labels = {
campaigns: 'kampanii',
products: 'produktow',
campaigns_product_alerts_merchant: 'walidacji Merchant'
};
$.post( '/clients/force_sync', { id: id, pipeline: pipeline }, function( response )
{
@@ -250,6 +342,13 @@ function loadSyncStatus()
$( '.client-sync' ).each( function()
{
var $cell = $( this );
var isActive = parseInt( $cell.closest( 'tr' ).attr( 'data-active' ), 10 ) === 1;
if ( !isActive )
{
$cell.html( '<span class="text-muted">nieaktywny</span>' );
return;
}
var id = $cell.data( 'sync-id' );
var info = resp.data[ id ];
@@ -262,6 +361,7 @@ function loadSyncStatus()
var html = '<div class="client-sync-bars">';
if ( info.campaigns ) html += renderSyncBar( 'K:', info.campaigns[0], info.campaigns[1] );
if ( info.products ) html += renderSyncBar( 'P:', info.products[0], info.products[1] );
if ( info.merchant ) html += renderSyncBar( 'M:', info.merchant[0], info.merchant[1] );
html += '</div>';
$cell.html( html );
@@ -274,3 +374,4 @@ $( document ).ready( function() {
setInterval( loadSyncStatus, 15000 );
} );
</script>