Autosave: 20260805-161402

This commit is contained in:
Flatlogic Bot 2026-08-05 16:12:19 +00:00
parent dea09b02d8
commit e983920c84
7 changed files with 91 additions and 22 deletions

View File

@ -1339,7 +1339,7 @@ require_once 'layout_header.php';
<?php foreach ($storeNavGroups as $groupKey => $group): ?>
<?php $groupConfig = $group['config'] ?? []; ?>
<li class="nav-item">
<a class="nav-link <?php echo $activeStoreGroupKey === $groupKey ? 'active' : ''; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['store' => $groupKey]))); ?>">
<a class="nav-link <?php echo $activeStoreGroupKey === $groupKey ? 'active' : ''; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['view' => $groupKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $groupKey]))); ?>">
<?php echo htmlspecialchars((string) ($groupConfig['label'] ?? strtoupper((string) $groupKey))); ?>
</a>
</li>
@ -1349,9 +1349,9 @@ require_once 'layout_header.php';
<div class="mt-3 p-3 rounded-4 border bg-light">
<div class="small text-uppercase text-muted fw-semibold mb-2">Dentro de <?php echo htmlspecialchars($activeStoreGroupLabel); ?></div>
<div class="d-flex flex-wrap gap-2">
<a class="btn btn-sm <?php echo $storeKey === $activeStoreGroupKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['store' => $activeStoreGroupKey]))); ?>">Pedidos <?php echo htmlspecialchars($activeStoreGroupLabel); ?></a>
<a class="btn btn-sm <?php echo $storeKey === $activeStoreGroupKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['view' => $activeStoreGroupKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $activeStoreGroupKey]))); ?>">Pedidos <?php echo htmlspecialchars($activeStoreGroupLabel); ?></a>
<?php foreach ($activeStoreGroupChildren as $childKey => $childConfig): ?>
<a class="btn btn-sm <?php echo $storeKey === $childKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['store' => $childKey]))); ?>">
<a class="btn btn-sm <?php echo $storeKey === $childKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('call_center_pro.php', array_merge($callCenterParams, ['view' => $childKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $childKey]))); ?>">
<?php echo htmlspecialchars((string) ($childConfig['label'] ?? strtoupper((string) $childKey))); ?>
</a>
<?php endforeach; ?>

View File

@ -39,10 +39,14 @@ $pdo = db();
$user_id = $_SESSION['user_id'];
$user_role = $_SESSION['user_role'] ?? 'Asesor';
// Fetch years for the filter
$years_query = "SELECT DISTINCT YEAR(created_at) as year FROM pedidos WHERE estado = 'COMPLETADO ✅'";
// Fetch years for the filter using the real completion date
$years_query = "SELECT DISTINCT YEAR(fecha_completado) as year FROM pedidos WHERE estado = 'COMPLETADO ✅' AND fecha_completado IS NOT NULL";
if ($user_role === 'Asesor') {
$years_query .= " AND asesor_id = ?";
}
$years_query .= " ORDER BY year DESC";
if ($user_role === 'Asesor') {
$years_stmt = $pdo->prepare($years_query);
$years_stmt->execute([$user_id]);
} else {
@ -54,8 +58,19 @@ $years = $years_stmt->fetchAll(PDO::FETCH_COLUMN);
// Filter logic
$selected_month = $_GET['mes'] ?? '';
$selected_year = $_GET['año'] ?? '';
$selected_day = $_GET['dia'] ?? '';
$search_query = $_GET['q'] ?? '';
if (!empty($selected_day)) {
$selectedDayObject = DateTime::createFromFormat('Y-m-d', $selected_day);
if (!$selectedDayObject || $selectedDayObject->format('Y-m-d') !== $selected_day) {
$selected_day = '';
} else {
$selected_month = '';
$selected_year = '';
}
}
$sql = "SELECT p.*, u.nombre_asesor as asesor_nombre FROM pedidos p LEFT JOIN users u ON p.asesor_id = u.id WHERE p.estado = 'COMPLETADO ✅'";
$params = [];
@ -71,19 +86,34 @@ if (!empty($search_query)) {
$params[] = "%$search_query%";
}
if (!empty($selected_month)) {
$sql .= " AND MONTH(p.created_at) = ?";
$params[] = $selected_month;
}
if (!empty($selected_year)) {
$sql .= " AND YEAR(p.created_at) = ?";
$params[] = $selected_year;
if (!empty($selected_day)) {
$sql .= " AND DATE(p.fecha_completado) = ?";
$params[] = $selected_day;
} else {
if (!empty($selected_month)) {
$sql .= " AND MONTH(p.fecha_completado) = ?";
$params[] = $selected_month;
}
if (!empty($selected_year)) {
$sql .= " AND YEAR(p.fecha_completado) = ?";
$params[] = $selected_year;
}
}
$sql .= " ORDER BY p.fecha_completado DESC";
$sql .= " ORDER BY COALESCE(p.fecha_completado, p.created_at) DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$pedidos = $stmt->fetchAll();
$pedidos_count = count($pedidos);
$selected_day_label = '';
if (!empty($selected_day)) {
try {
$selected_day_label = (new DateTime($selected_day))->format('d/m/Y');
} catch (Exception $e) {
$selected_day_label = $selected_day;
}
}
$months = [
1 => 'Enero', 2 => 'Febrero', 3 => 'Marzo', 4 => 'Abril', 5 => 'Mayo', 6 => 'Junio',
@ -93,6 +123,7 @@ $months = [
?>
<?php
$pageTitle = "Pedidos Completados";
$pageDescription = 'Consulta los pedidos completados y filtra por fecha de completado, búsqueda, día, mes o año.';
include 'layout_header.php';
?>
@ -103,6 +134,10 @@ include 'layout_header.php';
<label for="q" class="form-label">Buscar</label>
<input type="text" name="q" id="q" class="form-control" value="<?php echo htmlspecialchars($_GET['q'] ?? ''); ?>" placeholder="Nombre, DNI o Celular">
</div>
<div class="col-auto">
<label for="dia" class="form-label">Día</label>
<input type="date" name="dia" id="dia" class="form-control" value="<?php echo htmlspecialchars($selected_day); ?>">
</div>
<div class="col-auto">
<label for="mes" class="form-label">Mes</label>
<select name="mes" id="mes" class="form-select">
@ -125,11 +160,24 @@ include 'layout_header.php';
<button type="submit" class="btn btn-info">Filtrar</button>
<a href="completados.php" class="btn btn-secondary">Limpiar</a>
</div>
<div class="col-12">
<small class="text-muted">Los filtros de día, mes y año usan la columna Fecha Completado. Si eliges un día, ese filtro tiene prioridad.</small>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-body py-3 border-bottom">
<strong>Total completados:</strong> <?php echo $pedidos_count; ?>
<span class="text-muted">
<?php if (!empty($selected_day_label)): ?>
pedido<?php echo $pedidos_count === 1 ? '' : 's'; ?> con fecha completada el <?php echo htmlspecialchars($selected_day_label); ?>.
<?php else: ?>
pedido<?php echo $pedidos_count === 1 ? '' : 's'; ?> según el filtro aplicado.
<?php endif; ?>
</span>
</div>
<div class="card-body p-0">
<div class="excel-container cc-pedidos-rotulados-container cc-pedidos-completados-container">
<table id="pedidos-table" class="table table-striped">

View File

@ -56,6 +56,7 @@ if (!$gasto) {
}
$pageTitle = 'Editar Gasto';
$pageDescription = 'Editar registros de inversión general por categoría y periodo.';
include 'layout_header.php';
?>
@ -86,6 +87,7 @@ include 'layout_header.php';
<option value="Publicidad" <?php echo ($gasto['tipo_gasto'] == 'Publicidad') ? 'selected' : ''; ?>>Publicidad</option>
<option value="Inversion de Mercaderia" <?php echo ($gasto['tipo_gasto'] == 'Inversion de Mercaderia') ? 'selected' : ''; ?>>Inversión de Mercadería</option>
<option value="Gastos Personales" <?php echo ($gasto['tipo_gasto'] == 'Gastos Personales') ? 'selected' : ''; ?>>Gastos Personales</option>
<option value="Gastos Administrativos" <?php echo ($gasto['tipo_gasto'] == 'Gastos Administrativos') ? 'selected' : ''; ?>>Gastos Administrativos</option>
</select>
</div>
</div>

View File

@ -236,7 +236,7 @@ $isMainTuaniStore = cc_test_is_tuani_main_store_key($storeKey);
$isTuaniRecuperablesStore = $storeKey === 'tuani_recuperables';
$canShowTuaniLogisticaButton = $isMainTuaniStore || $isTuaniRecuperablesStore;
$viewCardColumnClass = $isTuaniRecuperablesStore ? 'col-md-6 col-xl-2' : 'col-md-6 col-xl-2';
$callCenterDefaultView = $isMainTuaniStore ? cc_test_callcenter_pro_default_view_key($storeKey) : $view;
$callCenterDefaultView = ($isMainTuaniStore || $isTuaniRecuperablesStore) ? cc_test_callcenter_pro_default_view_key($storeKey) : $view;
$viewCards = $isTuaniRecuperablesStore ? [
'pendientes_hoy' => [
@ -1593,7 +1593,7 @@ require_once 'layout_header.php';
<?php foreach ($storeNavGroups as $groupKey => $group): ?>
<?php $groupConfig = $group['config'] ?? []; ?>
<li class="nav-item">
<a class="nav-link <?php echo $activeStoreGroupKey === $groupKey ? 'active' : ''; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $view, 'store' => $groupKey], $persistedAssessorParams))); ?>">
<a class="nav-link <?php echo $activeStoreGroupKey === $groupKey ? 'active' : ''; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $groupKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $groupKey], $persistedAssessorParams))); ?>">
<?php echo htmlspecialchars((string) ($groupConfig['label'] ?? strtoupper((string) $groupKey))); ?>
</a>
</li>
@ -1603,9 +1603,9 @@ require_once 'layout_header.php';
<div class="mt-3 p-3 rounded-4 border bg-light">
<div class="small text-uppercase text-muted fw-semibold mb-2">Dentro de <?php echo htmlspecialchars($activeStoreGroupLabel); ?></div>
<div class="d-flex flex-wrap gap-2">
<a class="btn btn-sm <?php echo $storeKey === $activeStoreGroupKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $view, 'store' => $activeStoreGroupKey], $persistedAssessorParams))); ?>">Pedidos <?php echo htmlspecialchars($activeStoreGroupLabel); ?></a>
<a class="btn btn-sm <?php echo $storeKey === $activeStoreGroupKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $activeStoreGroupKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $activeStoreGroupKey], $persistedAssessorParams))); ?>">Pedidos <?php echo htmlspecialchars($activeStoreGroupLabel); ?></a>
<?php foreach ($activeStoreGroupChildren as $childKey => $childConfig): ?>
<a class="btn btn-sm <?php echo $storeKey === $childKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $view, 'store' => $childKey], $persistedAssessorParams))); ?>">
<a class="btn btn-sm <?php echo $storeKey === $childKey ? 'btn-primary' : 'btn-outline-primary'; ?>" href="<?php echo htmlspecialchars(cc_test_build_url('gestiones_callcenter.php', array_merge(['view' => $childKey === 'tuani_recuperables' ? 'todos' : $view, 'store' => $childKey], $persistedAssessorParams))); ?>">
<?php echo htmlspecialchars((string) ($childConfig['label'] ?? strtoupper((string) $childKey))); ?>
</a>
<?php endforeach; ?>

View File

@ -262,9 +262,23 @@ function cc_test_is_tuani_main_store_key(string $storeKey): bool
return in_array($storeKey, ['flower', 'otra_tienda'], true);
}
function cc_test_is_tuani_recoverables_store_key(string $storeKey): bool
{
$storeKey = trim(mb_strtolower($storeKey));
return $storeKey === 'tuani_recuperables';
}
function cc_test_callcenter_pro_default_view_key(string $storeKey): string
{
return cc_test_is_tuani_main_store_key($storeKey) ? 'ultimos_3_dias' : 'pendientes_hoy';
if (cc_test_is_tuani_main_store_key($storeKey)) {
return 'ultimos_3_dias';
}
if (cc_test_is_tuani_recoverables_store_key($storeKey)) {
return 'todos';
}
return 'pendientes_hoy';
}
if (!function_exists('cc_test_normalize_phone_digits')) {

View File

@ -88,12 +88,14 @@ $gastos = $stmt->fetchAll(PDO::FETCH_ASSOC);
$gastos_por_tipo = [
'Publicidad' => [],
'Inversion de Mercaderia' => [],
'Gastos Personales' => []
'Gastos Personales' => [],
'Gastos Administrativos' => []
];
$totales_por_tipo = [
'Publicidad' => 0,
'Inversion de Mercaderia' => 0,
'Gastos Personales' => 0
'Gastos Personales' => 0,
'Gastos Administrativos' => 0
];
foreach ($gastos as $gasto) {
@ -105,6 +107,7 @@ foreach ($gastos as $gasto) {
}
$pageTitle = 'Inversión General';
$pageDescription = 'Control mensual de inversión, publicidad, mercadería, gastos personales y gastos administrativos.';
include 'layout_header.php';
?>
@ -140,6 +143,7 @@ include 'layout_header.php';
<option value="Publicidad">Publicidad</option>
<option value="Inversion de Mercaderia">Inversión de Mercadería</option>
<option value="Gastos Personales">Gastos Personales</option>
<option value="Gastos Administrativos">Gastos Administrativos</option>
</select>
</div>
</div>
@ -165,7 +169,8 @@ include 'layout_header.php';
$tipos_de_gasto = [
'Publicidad' => 'Gastos de Publicidad',
'Inversion de Mercaderia' => 'Inversión de Mercadería',
'Gastos Personales' => 'Gastos Personales'
'Gastos Personales' => 'Gastos Personales',
'Gastos Administrativos' => 'Gastos Administrativos'
];
?>

View File

@ -57,7 +57,7 @@ if ($currentCallCenterStore !== '') {
if ($currentCallCenterView !== '') {
$callCenterPersistentParams['view'] = $currentCallCenterView;
}
$callCenterProDefaultView = ($currentCallCenterStore !== '' && cc_test_is_tuani_main_store_key($currentCallCenterStore)) ? 'ultimos_3_dias' : '';
$callCenterProDefaultView = ($currentCallCenterStore !== '' && (cc_test_is_tuani_main_store_key($currentCallCenterStore) || cc_test_is_tuani_recoverables_store_key($currentCallCenterStore))) ? cc_test_callcenter_pro_default_view_key($currentCallCenterStore) : '';
$appendCallCenterParams = static function (string $url) use ($callCenterPersistentParams, $callCenterProDefaultView, $isAdmin): string {
if (empty($callCenterPersistentParams)) {
return $url;