mas reportes
This commit is contained in:
@@ -36,8 +36,6 @@ class ErroresTimbres(models.Model):
|
||||
class Clientes(models.Model):
|
||||
RFC = models.CharField(max_length=13, unique=True)
|
||||
Nombre = models.CharField(max_length=100)
|
||||
|
||||
|
||||
Activo = models.BooleanField(default=False)
|
||||
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 JsonResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@@ -157,29 +158,40 @@ class ClientesUpdateView(UserPassesTestMixin,LoginRequiredMixin,UpdateView):
|
||||
@sync_to_async(thread_sensitive=False)
|
||||
def export_Excel(request):
|
||||
|
||||
RFC = request.GET.get('RFC', '')
|
||||
RFC = request.GET.get('RFC', None)
|
||||
|
||||
today = datetime.date.today()
|
||||
month = today.month
|
||||
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))
|
||||
else:
|
||||
|
||||
objeto_a_trabajar = Clientes.objects.all()
|
||||
|
||||
objeto_a_trabajar = Timbres.objects.filter(rfcc=RFC, created_at__year=str(year),created_at__month=str(month))
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
#contador = 1
|
||||
ws['A1']='UUID'
|
||||
ws['B1']='RFC_Cliente'
|
||||
ws['C1']='Fecha'
|
||||
contador =2
|
||||
|
||||
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
|
||||
if RFC is not None:
|
||||
#Encabezado
|
||||
ws['A1']='RFC_EXPEDIDO'
|
||||
ws['B1']='UUID'
|
||||
ws['C1']='Fecha'
|
||||
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
|
||||
|
||||
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")
|
||||
contenido = "attachment; filename = {0}".format(nombre_archivo)
|
||||
response["Content-Disposition"] = contenido
|
||||
|
||||
@@ -22,13 +22,16 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
||||
<th>Totales Mes {{fecha|date:"F"}}</th>
|
||||
<th>Estado</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>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for obj in lista %}
|
||||
<tr class="{% if not obj.Activo %}table-danger{% endif %}">
|
||||
<td>
|
||||
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
||||
<td >
|
||||
<a href="{% url 'update_cliente' obj.pk %}">{{obj.RFC}}</a>
|
||||
</td>
|
||||
<td>{{obj.Nombre}} </td>
|
||||
<td>{{obj.timbres_mes_count}}</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>
|
||||
{% endif %}
|
||||
</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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -55,11 +61,22 @@ Timbres disponibles Comercio Digital: {{saldo.saldo}}
|
||||
|
||||
{% block scripts %}
|
||||
<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)=>{
|
||||
document.getElementById('rfcc').checked= table_rfcc.checked? true:false;
|
||||
})
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock scripts %}
|
||||
Reference in New Issue
Block a user