mas reportes
This commit is contained in:
@@ -36,8 +36,6 @@ class ErroresTimbres(models.Model):
|
|||||||
class Clientes(models.Model):
|
class Clientes(models.Model):
|
||||||
RFC = models.CharField(max_length=13, unique=True)
|
RFC = models.CharField(max_length=13, unique=True)
|
||||||
Nombre = models.CharField(max_length=100)
|
Nombre = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
Activo = models.BooleanField(default=False)
|
Activo = models.BooleanField(default=False)
|
||||||
fecha_baja = models.DateField(blank=True,null=True)
|
fecha_baja = models.DateField(blank=True,null=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render,redirect
|
||||||
|
from django.contrib import messages
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
@@ -157,29 +158,40 @@ class ClientesUpdateView(UserPassesTestMixin,LoginRequiredMixin,UpdateView):
|
|||||||
@sync_to_async(thread_sensitive=False)
|
@sync_to_async(thread_sensitive=False)
|
||||||
def export_Excel(request):
|
def export_Excel(request):
|
||||||
|
|
||||||
RFC = request.GET.get('RFC', '')
|
RFC = request.GET.get('RFC', None)
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
month = today.month
|
month = today.month
|
||||||
year = today.year
|
year = today.year
|
||||||
|
if RFC is not None:
|
||||||
objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month))
|
objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month))
|
||||||
|
else:
|
||||||
|
|
||||||
|
objeto_a_trabajar = Clientes.objects.all()
|
||||||
|
|
||||||
wb = Workbook()
|
wb = Workbook()
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
#contador = 1
|
|
||||||
ws['A1']='UUID'
|
if RFC is not None:
|
||||||
ws['B1']='RFC_Cliente'
|
#Encabezado
|
||||||
|
ws['A1']='RFC_EXPEDIDO'
|
||||||
|
ws['B1']='UUID'
|
||||||
ws['C1']='Fecha'
|
ws['C1']='Fecha'
|
||||||
contador =2
|
for q,qq in enumerate(objeto_a_trabajar,start=2):
|
||||||
|
ws['A' + str(q)] = qq.rfcc
|
||||||
|
ws['B'+ str(q)] = qq.uuid
|
||||||
|
ws['C'+ str(q)] = qq.fecha
|
||||||
|
else:#cuando no es pro RFC y es para contabilizar los timbres del mes de cada cliente
|
||||||
|
ws['A1']='RFC_EXPEDIDO'
|
||||||
|
ws['B1']='Nombre'
|
||||||
|
ws['C1']='Timbres'
|
||||||
|
for q,qq in enumerate(objeto_a_trabajar,start=2):
|
||||||
|
ws['A' + str(q)] = qq.RFC
|
||||||
|
ws['B'+ str(q)] = qq.Nombre
|
||||||
|
ws['C'+ str(q)] = qq.timbres_mes_count
|
||||||
|
|
||||||
for q in objeto_a_trabajar:
|
|
||||||
column = str(contador)
|
|
||||||
ws['A' + column] = q.uuid
|
|
||||||
ws['B'+ column] = q.rfcc
|
|
||||||
ws['C'+ column] = q.fecha
|
|
||||||
contador += 1
|
|
||||||
|
|
||||||
nombre_archivo = f"Timbres_{RFC}_{str(year)}_{str(month)}.xlsx"
|
nombre_archivo = f"Timbres_{RFC if RFC is not None else 'Clientes_MES'}_{str(year)}_{str(month)}.xlsx"
|
||||||
response = HttpResponse(content_type="application/ms-excel")
|
response = HttpResponse(content_type="application/ms-excel")
|
||||||
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
||||||
response["Content-Disposition"] = contenido
|
response["Content-Disposition"] = contenido
|
||||||
|
|||||||
@@ -22,12 +22,15 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
<th>Totales Mes {{fecha|date:"F"}}</th>
|
<th>Totales Mes {{fecha|date:"F"}}</th>
|
||||||
<th>Estado</th>
|
<th>Estado</th>
|
||||||
<th scope="col">actions</th>
|
<th scope="col">actions</th>
|
||||||
|
<th>
|
||||||
|
<a target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}">Excel Todos los clientes X Mes </a>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for obj in lista %}
|
{% for obj in lista %}
|
||||||
<tr class="{% if not obj.Activo %}table-danger{% endif %}">
|
<tr class="{% if not obj.Activo %}table-danger{% endif %}">
|
||||||
<td>
|
<td >
|
||||||
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{obj.Nombre}} </td>
|
<td>{{obj.Nombre}} </td>
|
||||||
@@ -46,7 +49,10 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
<a href="{% url 'timbres_cliente' obj.RFC %}" class="btn btn-info">Ver Timbres</a>
|
<a href="{% url 'timbres_cliente' obj.RFC %}" class="btn btn-info">Ver Timbres</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><a target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}?RFC={{obj.RFC}}">Excel</a></td>
|
<td>
|
||||||
|
<button class="btn btn-outline-info" id ="id_b_{{obj.RFC}}" onclick="aclick(event, '{{obj.RFC}}','{{obj.timbres_mes_count}}')">Excel</button>
|
||||||
|
<a style="display: none;" id="id_a_{{obj.RFC}}" target="_blank" rel="noopener noreferrer" href="{% url 'export_Excel' %}?RFC={{obj.RFC}}">Excel</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -55,11 +61,22 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
|||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
|
function aclick(event,RFC ,cuantos){
|
||||||
|
|
||||||
|
if( parseInt(cuantos)===0){
|
||||||
|
|
||||||
|
alert(`No hay timbres de este mes para el cliente ${RFC}`)
|
||||||
|
}else{
|
||||||
|
document.getElementById(`id_a_${RFC}`).click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table_rfcc.addEventListener('click',(event)=>{
|
table_rfcc.addEventListener('click',(event)=>{
|
||||||
document.getElementById('rfcc').checked= table_rfcc.checked? true:false;
|
document.getElementById('rfcc').checked= table_rfcc.checked? true:false;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock scripts %}
|
{% endblock scripts %}
|
||||||
Reference in New Issue
Block a user