File size: 77,333 Bytes
7ebd53b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 | <!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Água Sonho Real - Sistema de Cobrança</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3498db',
secondary: '#2980b9',
danger: '#e74c3c',
warning: '#f39c12',
success: '#2ecc71',
dark: '#2c3e50',
}
}
}
}
</script>
<style>
.sidebar {
transition: all 0.3s;
}
@media (max-width: 768px) {
.sidebar {
transform: translateX(-100%);
}
.sidebar.active {
transform: translateX(0);
}
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.alert-pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4);
}
70% {
box-shadow: 0 0 0 10px rgba(231, 76, 60, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(231, 76, 60, 0);
}
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<div class="sidebar bg-dark text-white w-64 fixed h-full z-10">
<div class="p-4 flex items-center space-x-2 border-b border-gray-700">
<i class="fas fa-tint text-2xl text-primary"></i>
<h1 class="text-xl font-bold">Água Sonho Real</h1>
</div>
<nav class="p-4">
<ul class="space-y-2">
<li>
<button onclick="showTab('dashboard')" class="tab-btn w-full text-left p-2 rounded hover:bg-secondary flex items-center space-x-2">
<i class="fas fa-home"></i>
<span>Dashboard</span>
</button>
</li>
<li>
<button onclick="showTab('billing')" class="tab-btn w-full text-left p-2 rounded hover:bg-secondary flex items-center space-x-2">
<i class="fas fa-file-invoice-dollar"></i>
<span>Cobrança</span>
</button>
</li>
<li>
<button onclick="showTab('customers')" class="tab-btn w-full text-left p-2 rounded hover:bg-secondary flex items-center space-x-2">
<i class="fas fa-users"></i>
<span>Clientes</span>
</button>
</li>
<li>
<button onclick="showTab('reports')" class="tab-btn w-full text-left p-2 rounded hover:bg-secondary flex items-center space-x-2">
<i class="fas fa-chart-bar"></i>
<span>Relatórios</span>
</button>
</li>
<li>
<button onclick="showTab('settings')" class="tab-btn w-full text-left p-2 rounded hover:bg-secondary flex items-center space-x-2">
<i class="fas fa-cog"></i>
<span>Configurações</span>
</button>
</li>
</ul>
</nav>
<div class="absolute bottom-0 w-full p-4 border-t border-gray-700">
<button class="w-full bg-primary hover:bg-secondary text-white p-2 rounded flex items-center justify-center space-x-2">
<i class="fas fa-sign-out-alt"></i>
<span>Sair</span>
</button>
</div>
</div>
<!-- Main Content -->
<div class="flex-1 ml-0 md:ml-64 transition-all duration-300">
<!-- Mobile Header -->
<header class="bg-white shadow md:hidden p-4 flex items-center justify-between">
<button id="menu-toggle" class="text-dark">
<i class="fas fa-bars text-xl"></i>
</button>
<h1 class="text-xl font-bold text-dark">Água Sonho Real</h1>
<div class="w-8"></div> <!-- Spacer -->
</header>
<!-- Content -->
<main class="p-4 md:p-6">
<!-- Dashboard Tab -->
<div id="dashboard" class="tab-content active">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-dark">Dashboard</h2>
<div class="text-sm text-gray-500">
<span id="current-date"></span>
</div>
</div>
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
<div class="bg-white p-4 rounded-lg shadow">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500">Clientes Ativos</p>
<h3 class="text-2xl font-bold" id="active-customers">0</h3>
</div>
<div class="bg-primary bg-opacity-10 p-3 rounded-full">
<i class="fas fa-users text-primary text-xl"></i>
</div>
</div>
</div>
<div class="bg-white p-4 rounded-lg shadow">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500">Receita Mensal</p>
<h3 class="text-2xl font-bold" id="monthly-revenue">0 MZN</h3>
</div>
<div class="bg-success bg-opacity-10 p-3 rounded-full">
<i class="fas fa-money-bill-wave text-success text-xl"></i>
</div>
</div>
</div>
<div class="bg-white p-4 rounded-lg shadow">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500">Pagamentos Atrasados</p>
<h3 class="text-2xl font-bold" id="late-payments">0</h3>
</div>
<div class="bg-danger bg-opacity-10 p-3 rounded-full">
<i class="fas fa-exclamation-triangle text-danger text-xl"></i>
</div>
</div>
</div>
<div class="bg-white p-4 rounded-lg shadow">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500">Consumo Médio</p>
<h3 class="text-2xl font-bold" id="avg-consumption">0 m³</h3>
</div>
<div class="bg-secondary bg-opacity-10 p-3 rounded-full">
<i class="fas fa-tint text-secondary text-xl"></i>
</div>
</div>
</div>
</div>
<!-- Alerts -->
<div class="mb-6">
<h3 class="text-lg font-semibold mb-2 text-dark">Alertas de Pagamento</h3>
<div id="alerts-container" class="space-y-2">
<!-- Alerts will be added here dynamically -->
</div>
</div>
<!-- Recent Payments -->
<div class="bg-white rounded-lg shadow overflow-hidden">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark">Últimos Pagamentos</h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cliente</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nº Cliente</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Área</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valor</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
</tr>
</thead>
<tbody id="recent-payments" class="bg-white divide-y divide-gray-200">
<!-- Recent payments will be added here dynamically -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Billing Tab -->
<div id="billing" class="tab-content">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-dark">Cobrança</h2>
<button onclick="showNewBillingModal()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded flex items-center space-x-2">
<i class="fas fa-plus"></i>
<span>Nova Cobrança</span>
</button>
</div>
<div class="bg-white rounded-lg shadow overflow-hidden mb-6">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark">Registrar Pagamento</h3>
</div>
<div class="p-4">
<form id="payment-form" class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label for="customer-search" class="block text-sm font-medium text-gray-700 mb-1">Buscar Cliente</label>
<div class="relative">
<input type="text" id="customer-search" class="w-full p-2 border border-gray-300 rounded" placeholder="Nome ou Nº Cliente">
<div id="search-results" class="absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded shadow-lg hidden"></div>
</div>
</div>
<div>
<label for="consumption" class="block text-sm font-medium text-gray-700 mb-1">Consumo (m³)</label>
<input type="number" id="consumption" min="5" step="0.1" class="w-full p-2 border border-gray-300 rounded" value="5">
</div>
<div>
<label for="amount" class="block text-sm font-medium text-gray-700 mb-1">Valor (MZN)</label>
<input type="number" id="amount" class="w-full p-2 border border-gray-300 rounded" readonly>
</div>
<div class="md:col-span-3">
<button type="button" onclick="calculateAmount()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded mr-2">
Calcular
</button>
<button type="button" onclick="registerPayment()" class="bg-success hover:bg-green-600 text-white px-4 py-2 rounded">
Registrar Pagamento
</button>
</div>
</form>
</div>
</div>
<div class="bg-white rounded-lg shadow overflow-hidden">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold text-dark">Histórico de Cobranças</h3>
<div class="flex space-x-2">
<select id="billing-filter" class="p-2 border border-gray-300 rounded">
<option value="all">Todos</option>
<option value="paid">Pagas</option>
<option value="pending">Pendentes</option>
<option value="overdue">Atrasadas</option>
</select>
<input type="month" id="billing-month" class="p-2 border border-gray-300 rounded">
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nº Cliente</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cliente</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Área</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Consumo</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valor</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
</tr>
</thead>
<tbody id="billing-history" class="bg-white divide-y divide-gray-200">
<!-- Billing history will be added here dynamically -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Customers Tab -->
<div id="customers" class="tab-content">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-dark">Clientes</h2>
<button onclick="showNewCustomerModal()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded flex items-center space-x-2">
<i class="fas fa-plus"></i>
<span>Novo Cliente</span>
</button>
</div>
<div class="bg-white rounded-lg shadow overflow-hidden mb-6">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold text-dark">Lista de Clientes</h3>
<div class="flex space-x-2">
<select id="customer-area-filter" class="p-2 border border-gray-300 rounded">
<option value="all">Todas Áreas</option>
<option value="1">Possulane</option>
<option value="2">Condomínios</option>
</select>
<input type="text" id="customer-search-main" placeholder="Buscar cliente..." class="p-2 border border-gray-300 rounded">
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nº Cliente</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nome</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Área</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Contacto</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Último Pagamento</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
</tr>
</thead>
<tbody id="customers-list" class="bg-white divide-y divide-gray-200">
<!-- Customers list will be added here dynamically -->
</tbody>
</table>
</div>
</div>
</div>
<!-- Reports Tab -->
<div id="reports" class="tab-content">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-dark">Relatórios</h2>
<div class="flex space-x-2">
<button onclick="generatePDFReport()" class="bg-danger hover:bg-red-600 text-white px-4 py-2 rounded flex items-center space-x-2">
<i class="fas fa-file-pdf"></i>
<span>Exportar PDF</span>
</button>
<button onclick="generateExcelReport()" class="bg-success hover:bg-green-600 text-white px-4 py-2 rounded flex items-center space-x-2">
<i class="fas fa-file-excel"></i>
<span>Exportar Excel</span>
</button>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
<div class="bg-white p-4 rounded-lg shadow">
<h3 class="text-lg font-semibold mb-4 text-dark">Filtros do Relatório</h3>
<form id="report-filters" class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Tipo de Relatório</label>
<select id="report-type" class="w-full p-2 border border-gray-300 rounded">
<option value="monthly">Mensal</option>
<option value="quarterly">Trimestral</option>
<option value="annual">Anual</option>
<option value="custom">Personalizado</option>
</select>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="start-date" class="block text-sm font-medium text-gray-700 mb-1">Data Inicial</label>
<input type="date" id="start-date" class="w-full p-2 border border-gray-300 rounded">
</div>
<div>
<label for="end-date" class="block text-sm font-medium text-gray-700 mb-1">Data Final</label>
<input type="date" id="end-date" class="w-full p-2 border border-gray-300 rounded">
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Área</label>
<select id="report-area" class="w-full p-2 border border-gray-300 rounded">
<option value="all">Todas Áreas</option>
<option value="1">Possulane</option>
<option value="2">Condomínios</option>
</select>
</div>
<button type="button" onclick="generateReport()" class="w-full bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
Gerar Relatório
</button>
</form>
</div>
<div class="bg-white p-4 rounded-lg shadow">
<h3 class="text-lg font-semibold mb-4 text-dark">Resumo Financeiro</h3>
<div class="space-y-4">
<div>
<h4 class="font-medium text-gray-700">Receita Total</h4>
<p class="text-2xl font-bold" id="total-revenue">0 MZN</p>
</div>
<div>
<h4 class="font-medium text-gray-700">Pagamentos Pendentes</h4>
<p class="text-2xl font-bold text-danger" id="pending-revenue">0 MZN</p>
</div>
<div>
<h4 class="font-medium text-gray-700">Número de Clientes</h4>
<div class="flex justify-between">
<div>
<p class="text-sm text-gray-500">Possulane</p>
<p class="text-xl font-bold" id="possulane-customers">0</p>
</div>
<div>
<p class="text-sm text-gray-500">Condomínios</p>
<p class="text-xl font-bold" id="condominios-customers">0</p>
</div>
<div>
<p class="text-sm text-gray-500">Total</p>
<p class="text-xl font-bold" id="total-customers">0</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow overflow-hidden">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark">Resultados do Relatório</h3>
</div>
<div class="p-4">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Mês</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Receita (MZN)</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Clientes Ativos</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Pagamentos Atrasados</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Consumo Médio (m³)</th>
</tr>
</thead>
<tbody id="report-results" class="bg-white divide-y divide-gray-200">
<!-- Report results will be added here dynamically -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Settings Tab -->
<div id="settings" class="tab-content">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-dark">Configurações</h2>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div class="bg-white p-4 rounded-lg shadow lg:col-span-2">
<h3 class="text-lg font-semibold mb-4 text-dark">Configurações de Cobrança</h3>
<form id="billing-settings" class="space-y-4">
<div>
<label for="min-consumption" class="block text-sm font-medium text-gray-700 mb-1">Consumo Mínimo (m³)</label>
<input type="number" id="min-consumption" min="1" step="1" class="w-full p-2 border border-gray-300 rounded" value="5">
</div>
<div>
<label for="min-consumption-price" class="block text-sm font-medium text-gray-700 mb-1">Preço Consumo Mínimo (MZN)</label>
<input type="number" id="min-consumption-price" min="1" step="1" class="w-full p-2 border border-gray-300 rounded" value="300">
</div>
<div>
<label for="extra-consumption-price" class="block text-sm font-medium text-gray-700 mb-1">Preço por m³ adicional (MZN)</label>
<input type="number" id="extra-consumption-price" min="1" step="1" class="w-full p-2 border border-gray-300 rounded" value="60">
</div>
<div>
<label for="due-date" class="block text-sm font-medium text-gray-700 mb-1">Dia de Vencimento</label>
<input type="number" id="due-date" min="1" max="31" class="w-full p-2 border border-gray-300 rounded" value="15">
</div>
<div>
<label for="late-fee" class="block text-sm font-medium text-gray-700 mb-1">Multa por Atraso (%)</label>
<input type="number" id="late-fee" min="0" max="100" step="0.1" class="w-full p-2 border border-gray-300 rounded" value="5">
</div>
<button type="button" onclick="saveBillingSettings()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
Salvar Configurações
</button>
</form>
</div>
<div class="bg-white p-4 rounded-lg shadow">
<h3 class="text-lg font-semibold mb-4 text-dark">Configurações de Usuário</h3>
<form id="user-settings" class="space-y-4">
<div>
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">Nome de Usuário</label>
<input type="text" id="username" class="w-full p-2 border border-gray-300 rounded" value="admin">
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="email" class="w-full p-2 border border-gray-300 rounded" value="admin@aguasonhoreal.com">
</div>
<div>
<label for="current-password" class="block text-sm font-medium text-gray-700 mb-1">Senha Atual</label>
<input type="password" id="current-password" class="w-full p-2 border border-gray-300 rounded">
</div>
<div>
<label for="new-password" class="block text-sm font-medium text-gray-700 mb-1">Nova Senha</label>
<input type="password" id="new-password" class="w-full p-2 border border-gray-300 rounded">
</div>
<div>
<label for="confirm-password" class="block text-sm font-medium text-gray-700 mb-1">Confirmar Nova Senha</label>
<input type="password" id="confirm-password" class="w-full p-2 border border-gray-300 rounded">
</div>
<button type="button" onclick="saveUserSettings()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
Salvar Alterações
</button>
</form>
</div>
</div>
</div>
</main>
</div>
</div>
<!-- Modals -->
<!-- New Customer Modal -->
<div id="new-customer-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-lg w-full max-w-md">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark">Novo Cliente</h3>
</div>
<div class="p-4">
<form id="new-customer-form" class="space-y-4">
<div>
<label for="customer-name" class="block text-sm font-medium text-gray-700 mb-1">Nome Completo</label>
<input type="text" id="customer-name" class="w-full p-2 border border-gray-300 rounded" required>
</div>
<div>
<label for="customer-area" class="block text-sm font-medium text-gray-700 mb-1">Área</label>
<select id="customer-area" class="w-full p-2 border border-gray-300 rounded" required>
<option value="1">Possulane</option>
<option value="2">Condomínios</option>
</select>
</div>
<div>
<label for="customer-address" class="block text-sm font-medium text-gray-700 mb-1">Endereço</label>
<input type="text" id="customer-address" class="w-full p-2 border border-gray-300 rounded" required>
</div>
<div>
<label for="customer-phone" class="block text-sm font-medium text-gray-700 mb-1">Telefone</label>
<input type="tel" id="customer-phone" class="w-full p-2 border border-gray-300 rounded" required>
</div>
<div>
<label for="customer-email" class="block text-sm font-medium text-gray-700 mb-1">Email (Opcional)</label>
<input type="email" id="customer-email" class="w-full p-2 border border-gray-300 rounded">
</div>
</form>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="hideModal('new-customer-modal')" class="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100">
Cancelar
</button>
<button onclick="saveNewCustomer()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
Salvar Cliente
</button>
</div>
</div>
</div>
<!-- Customer Details Modal -->
<div id="customer-details-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-lg w-full max-w-md">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold text-dark">Detalhes do Cliente</h3>
<button onclick="hideModal('customer-details-modal')" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-4">
<div class="mb-4">
<h4 class="font-bold text-lg" id="detail-customer-name"></h4>
<p class="text-gray-600" id="detail-customer-number"></p>
</div>
<div class="space-y-3">
<div>
<p class="text-sm text-gray-500">Área</p>
<p id="detail-customer-area"></p>
</div>
<div>
<p class="text-sm text-gray-500">Endereço</p>
<p id="detail-customer-address"></p>
</div>
<div>
<p class="text-sm text-gray-500">Telefone</p>
<p id="detail-customer-phone"></p>
</div>
<div>
<p class="text-sm text-gray-500">Email</p>
<p id="detail-customer-email"></p>
</div>
<div>
<p class="text-sm text-gray-500">Data de Registro</p>
<p id="detail-customer-register-date"></p>
</div>
</div>
</div>
<div class="p-4 border-t">
<h4 class="font-semibold mb-2">Histórico de Pagamentos</h4>
<div class="overflow-y-auto max-h-40">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-2 py-1 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
<th class="px-2 py-1 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Valor</th>
<th class="px-2 py-1 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
</tr>
</thead>
<tbody id="customer-payment-history" class="bg-white divide-y divide-gray-200">
<!-- Payment history will be added here dynamically -->
</tbody>
</table>
</div>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="hideModal('customer-details-modal')" class="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100">
Fechar
</button>
</div>
</div>
</div>
<!-- New Billing Modal -->
<div id="new-billing-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-lg w-full max-w-md">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark">Nova Cobrança</h3>
</div>
<div class="p-4">
<form id="new-billing-form" class="space-y-4">
<div>
<label for="billing-customer" class="block text-sm font-medium text-gray-700 mb-1">Cliente</label>
<select id="billing-customer" class="w-full p-2 border border-gray-300 rounded" required>
<!-- Customer options will be added here dynamically -->
</select>
</div>
<div>
<label for="billing-month" class="block text-sm font-medium text-gray-700 mb-1">Mês de Referência</label>
<input type="month" id="billing-month" class="w-full p-2 border border-gray-300 rounded" required>
</div>
<div>
<label for="billing-consumption" class="block text-sm font-medium text-gray-700 mb-1">Consumo (m³)</label>
<input type="number" id="billing-consumption" min="5" step="0.1" class="w-full p-2 border border-gray-300 rounded" value="5" required>
</div>
<div>
<label for="billing-amount" class="block text-sm font-medium text-gray-700 mb-1">Valor (MZN)</label>
<input type="number" id="billing-amount" class="w-full p-2 border border-gray-300 rounded" readonly>
</div>
<div>
<label for="billing-due-date" class="block text-sm font-medium text-gray-700 mb-1">Data de Vencimento</label>
<input type="date" id="billing-due-date" class="w-full p-2 border border-gray-300 rounded" required>
</div>
</form>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="hideModal('new-billing-modal')" class="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100">
Cancelar
</button>
<button onclick="saveNewBilling()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded">
Salvar Cobrança
</button>
</div>
</div>
</div>
<!-- Payment Receipt Modal -->
<div id="payment-receipt-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-lg w-full max-w-md">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="text-lg font-semibold text-dark">Recibo de Pagamento</h3>
<button onclick="hideModal('payment-receipt-modal')" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-4">
<div class="text-center mb-4">
<h2 class="text-xl font-bold">Água Sonho Real</h2>
<p class="text-sm text-gray-600">Sistema de Cobrança</p>
</div>
<div class="border-b pb-4 mb-4">
<div class="flex justify-between mb-2">
<span class="font-semibold">Nº Recibo:</span>
<span id="receipt-number"></span>
</div>
<div class="flex justify-between mb-2">
<span class="font-semibold">Data:</span>
<span id="receipt-date"></span>
</div>
<div class="flex justify-between">
<span class="font-semibold">Cliente:</span>
<span id="receipt-customer"></span>
</div>
</div>
<div class="mb-4">
<table class="w-full">
<thead>
<tr class="border-b">
<th class="text-left py-2">Descrição</th>
<th class="text-right py-2">Valor</th>
</tr>
</thead>
<tbody>
<tr class="border-b">
<td class="py-2">Consumo de Água</td>
<td class="text-right py-2" id="receipt-water-amount"></td>
</tr>
<tr class="border-b">
<td class="py-2">Multa por Atraso</td>
<td class="text-right py-2" id="receipt-late-fee"></td>
</tr>
<tr class="font-bold">
<td class="py-2">Total</td>
<td class="text-right py-2" id="receipt-total"></td>
</tr>
</tbody>
</table>
</div>
<div class="text-center text-sm text-gray-500">
<p>Obrigado pelo seu pagamento!</p>
<p>Para dúvidas, contacte: +258 84 123 4567</p>
</div>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="printReceipt()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded flex items-center space-x-2">
<i class="fas fa-print"></i>
<span>Imprimir</span>
</button>
<button onclick="hideModal('payment-receipt-modal')" class="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100">
Fechar
</button>
</div>
</div>
</div>
<!-- Confirmation Modal -->
<div id="confirmation-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-lg w-full max-w-md">
<div class="p-4 border-b">
<h3 class="text-lg font-semibold text-dark" id="confirmation-title"></h3>
</div>
<div class="p-4">
<p id="confirmation-message"></p>
</div>
<div class="p-4 border-t flex justify-end space-x-2">
<button onclick="hideModal('confirmation-modal')" class="px-4 py-2 border border-gray-300 rounded text-gray-700 hover:bg-gray-100">
Cancelar
</button>
<button onclick="confirmAction()" class="bg-primary hover:bg-secondary text-white px-4 py-2 rounded" id="confirm-button">
Confirmar
</button>
</div>
</div>
</div>
<script>
// Sample data for demonstration
let customers = [
{ id: 1, number: '1-001', name: 'João Matola', area: '1', areaName: 'Possulane', address: 'Av. Marginal, 123', phone: '841234567', email: 'joao@email.com', registrationDate: '2023-01-15', status: 'active' },
{ id: 2, number: '1-002', name: 'Maria Nhantumbo', area: '1', areaName: 'Possulane', address: 'Rua da Escola, 45', phone: '842345678', email: 'maria@email.com', registrationDate: '2023-02-10', status: 'active' },
{ id: 3, number: '2-001', name: 'Condomínio Flor do Mar', area: '2', areaName: 'Condomínios', address: 'Av. da Praia, 300', phone: '843456789', email: 'flordomar@email.com', registrationDate: '2023-01-05', status: 'active' },
{ id: 4, number: '2-002', name: 'Condomínio Vista Linda', area: '2', areaName: 'Condomínios', address: 'Rua dos Coqueiros, 12', phone: '844567890', email: 'vistalinda@email.com', registrationDate: '2023-03-20', status: 'active' },
];
let bills = [
{ id: 1, customerId: 1, customerNumber: '1-001', customerName: 'João Matola', area: '1', areaName: 'Possulane', consumption: 5, amount: 300, date: '2023-06-15', dueDate: '2023-07-15', paymentDate: '2023-07-10', status: 'paid', lateFee: 0 },
{ id: 2, customerId: 2, customerNumber: '1-002', customerName: 'Maria Nhantumbo', area: '1', areaName: 'Possulane', consumption: 7, amount: 420, date: '2023-06-15', dueDate: '2023-07-15', paymentDate: '2023-07-18', status: 'paid', lateFee: 21 },
{ id: 3, customerId: 3, customerNumber: '2-001', customerName: 'Condomínio Flor do Mar', area: '2', areaName: 'Condomínios', consumption: 15, amount: 900, date: '2023-06-15', dueDate: '2023-07-15', paymentDate: null, status: 'overdue', lateFee: 45 },
{ id: 4, customerId: 4, customerNumber: '2-002', customerName: 'Condomínio Vista Linda', area: '2', areaName: 'Condomínios', consumption: 8, amount: 480, date: '2023-06-15', dueDate: '2023-07-15', paymentDate: null, status: 'pending', lateFee: 0 },
{ id: 5, customerId: 1, customerNumber: '1-001', customerName: 'João Matola', area: '1', areaName: 'Possulane', consumption: 6, amount: 360, date: '2023-05-15', dueDate: '2023-06-15', paymentDate: '2023-06-12', status: 'paid', lateFee: 0 },
{ id: 6, customerId: 2, customerNumber: '1-002', customerName: 'Maria Nhantumbo', area: '1', areaName: 'Possulane', consumption: 5, amount: 300, date: '2023-05-15', dueDate: '2023-06-15', paymentDate: '2023-06-20', status: 'paid', lateFee: 15 },
{ id: 7, customerId: 3, customerNumber: '2-001', customerName: 'Condomínio Flor do Mar', area: '2', areaName: 'Condomínios', consumption: 12, amount: 720, date: '2023-05-15', dueDate: '2023-06-15', paymentDate: '2023-06-10', status: 'paid', lateFee: 0 },
{ id: 8, customerId: 4, customerNumber: '2-002', customerName: 'Condomínio Vista Linda', area: '2', areaName: 'Condomínios', consumption: 7, amount: 420, date: '2023-05-15', dueDate: '2023-06-15', paymentDate: '2023-06-14', status: 'paid', lateFee: 0 },
{ id: 9, customerId: 1, customerNumber: '1-001', customerName: 'João Matola', area: '1', areaName: 'Possulane', consumption: 5, amount: 300, date: '2023-04-15', dueDate: '2023-05-15', paymentDate: '2023-05-10', status: 'paid', lateFee: 0 },
{ id: 10, customerId: 2, customerNumber: '1-002', customerName: 'Maria Nhantumbo', area: '1', areaName: 'Possulane', consumption: 9, amount: 540, date: '2023-04-15', dueDate: '2023-05-15', paymentDate: '2023-05-18', status: 'paid', lateFee: 27 },
];
let settings = {
minConsumption: 5,
minConsumptionPrice: 300,
extraConsumptionPrice: 60,
dueDate: 15,
lateFee: 5
};
// Current action and data for confirmation modal
let currentAction = null;
let currentActionData = null;
// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
// Set current date
const now = new Date();
document.getElementById('current-date').textContent = now.toLocaleDateString('pt-PT', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
// Initialize dashboard
updateDashboard();
loadRecentPayments();
loadAlerts();
// Initialize billing tab
calculateAmount();
loadBillingHistory();
// Initialize customers tab
loadCustomersList();
// Initialize reports tab
updateReportSummary();
// Initialize settings tab
loadSettings();
// Mobile menu toggle
document.getElementById('menu-toggle').addEventListener('click', function() {
document.querySelector('.sidebar').classList.toggle('active');
});
// Customer search functionality
document.getElementById('customer-search').addEventListener('input', function() {
searchCustomers(this.value);
});
// Customer search in customers tab
document.getElementById('customer-search-main').addEventListener('input', function() {
filterCustomers();
});
// Billing filter
document.getElementById('billing-filter').addEventListener('change', function() {
loadBillingHistory();
});
// Billing month filter
document.getElementById('billing-month').addEventListener('change', function() {
loadBillingHistory();
});
// Customer area filter
document.getElementById('customer-area-filter').addEventListener('change', function() {
filterCustomers();
});
});
// Tab navigation
function showTab(tabId) {
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.remove('active');
});
document.getElementById(tabId).classList.add('active');
// Close mobile menu if open
document.querySelector('.sidebar').classList.remove('active');
}
// Modal functions
function showModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
function hideModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
}
function showNewCustomerModal() {
document.getElementById('customer-name').value = '';
document.getElementById('customer-area').value = '1';
document.getElementById('customer-address').value = '';
document.getElementById('customer-phone').value = '';
document.getElementById('customer-email').value = '';
showModal('new-customer-modal');
}
function showNewBillingModal() {
const billingCustomerSelect = document.getElementById('billing-customer');
billingCustomerSelect.innerHTML = '';
customers.forEach(customer => {
const option = document.createElement('option');
option.value = customer.id;
option.textContent = `${customer.number} - ${customer.name}`;
billingCustomerSelect.appendChild(option);
});
const now = new Date();
const currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
document.getElementById('billing-month').value = currentMonth;
document.getElementById('billing-consumption').value = '5';
document.getElementById('billing-amount').value = '300';
// Set due date to the 15th of next month
const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
const dueDate = new Date(nextMonth.getFullYear(), nextMonth.getMonth(), settings.dueDate);
document.getElementById('billing-due-date').value = dueDate.toISOString().split('T')[0];
showModal('new-billing-modal');
}
function showCustomerDetails(customerId) {
const customer = customers.find(c => c.id == customerId);
if (!customer) return;
document.getElementById('detail-customer-name').textContent = customer.name;
document.getElementById('detail-customer-number').textContent = `Nº Cliente: ${customer.number}`;
document.getElementById('detail-customer-area').textContent = customer.areaName;
document.getElementById('detail-customer-address').textContent = customer.address;
document.getElementById('detail-customer-phone').textContent = customer.phone;
document.getElementById('detail-customer-email').textContent = customer.email || 'N/A';
document.getElementById('detail-customer-register-date').textContent = new Date(customer.registrationDate).toLocaleDateString('pt-PT');
// Load payment history
const paymentHistory = bills.filter(bill => bill.customerId == customerId)
.sort((a, b) => new Date(b.date) - new Date(a.date));
const paymentHistoryTable = document.getElementById('customer-payment-history');
paymentHistoryTable.innerHTML = '';
paymentHistory.forEach(bill => {
const row = document.createElement('tr');
const dateCell = document.createElement('td');
dateCell.className = 'px-2 py-1 whitespace-nowrap';
dateCell.textContent = new Date(bill.date).toLocaleDateString('pt-PT');
const amountCell = document.createElement('td');
amountCell.className = 'px-2 py-1 whitespace-nowrap';
amountCell.textContent = `${bill.amount} MZN`;
const statusCell = document.createElement('td');
statusCell.className = 'px-2 py-1 whitespace-nowrap';
const statusBadge = document.createElement('span');
statusBadge.className = 'px-2 py-1 text-xs rounded-full';
if (bill.status === 'paid') {
statusBadge.classList.add('bg-green-100', 'text-green-800');
statusBadge.textContent = 'Pago';
} else if (bill.status === 'overdue') {
statusBadge.classList.add('bg-red-100', 'text-red-800');
statusBadge.textContent = 'Atrasado';
} else {
statusBadge.classList.add('bg-yellow-100', 'text-yellow-800');
statusBadge.textContent = 'Pendente';
}
statusCell.appendChild(statusBadge);
row.appendChild(dateCell);
row.appendChild(amountCell);
row.appendChild(statusCell);
paymentHistoryTable.appendChild(row);
});
showModal('customer-details-modal');
}
function showConfirmationModal(title, message, action, data = null) {
document.getElementById('confirmation-title').textContent = title;
document.getElementById('confirmation-message').textContent = message;
currentAction = action;
currentActionData = data;
showModal('confirmation-modal');
}
function confirmAction() {
if (currentAction === 'deleteCustomer') {
deleteCustomer(currentActionData);
} else if (currentAction === 'deleteBill') {
deleteBill(currentActionData);
}
hideModal('confirmation-modal');
}
// Dashboard functions
function updateDashboard() {
// Active customers
document.getElementById('active-customers').textContent = customers.length;
// Monthly revenue (last month)
const now = new Date();
const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
const lastMonthStr = lastMonth.getFullYear() + '-' + String(lastMonth.getMonth() + 1).padStart(2, '0');
const lastMonthBills = bills.filter(bill => {
const billDate = new Date(bill.date);
const billMonth = billDate.getFullYear() + '-' + String(billDate.getMonth() + 1).padStart(2, '0');
return billMonth === lastMonthStr && bill.status === 'paid';
});
const monthlyRevenue = lastMonthBills.reduce((sum, bill) => sum + bill.amount + bill.lateFee, 0);
document.getElementById('monthly-revenue').textContent = `${monthlyRevenue} MZN`;
// Late payments
const overdueBills = bills.filter(bill => bill.status === 'overdue');
document.getElementById('late-payments').textContent = overdueBills.length;
// Average consumption
const consumptions = bills.map(bill => bill.consumption);
const avgConsumption = consumptions.length > 0 ?
(consumptions.reduce((sum, val) => sum + val, 0) / consumptions.length).toFixed(1) : 0;
document.getElementById('avg-consumption').textContent = `${avgConsumption} m³`;
}
function loadRecentPayments() {
const recentPaymentsTable = document.getElementById('recent-payments');
recentPaymentsTable.innerHTML = '';
// Get last 5 paid bills, sorted by payment date (newest first)
const paidBills = bills.filter(bill => bill.status === 'paid')
.sort((a, b) => new Date(b.paymentDate) - new Date(a.paymentDate))
.slice(0, 5);
paidBills.forEach(bill => {
const row = document.createElement('tr');
const customerCell = document.createElement('td');
customerCell.className = 'px-6 py-4 whitespace-nowrap';
customerCell.textContent = bill.customerName;
const numberCell = document.createElement('td');
numberCell.className = 'px-6 py-4 whitespace-nowrap';
numberCell.textContent = bill.customerNumber;
const areaCell = document.createElement('td');
areaCell.className = 'px-6 py-4 whitespace-nowrap';
areaCell.textContent = bill.areaName;
const amountCell = document.createElement('td');
amountCell.className = 'px-6 py-4 whitespace-nowrap';
amountCell.textContent = `${bill.amount + bill.lateFee} MZN`;
const dateCell = document.createElement('td');
dateCell.className = 'px-6 py-4 whitespace-nowrap';
dateCell.textContent = new Date(bill.paymentDate).toLocaleDateString('pt-PT');
const statusCell = document.createElement('td');
statusCell.className = 'px-6 py-4 whitespace-nowrap';
const statusBadge = document.createElement('span');
statusBadge.className = 'px-2 py-1 text-xs rounded-full bg-green-100 text-green-800';
statusBadge.textContent = 'Pago';
statusCell.appendChild(statusBadge);
row.appendChild(customerCell);
row.appendChild(numberCell);
row.appendChild(areaCell);
row.appendChild(amountCell);
row.appendChild(dateCell);
row.appendChild(statusCell);
recentPaymentsTable.appendChild(row);
});
}
function loadAlerts() {
const alertsContainer = document.getElementById('alerts-container');
alertsContainer.innerHTML = '';
// Get customers with overdue bills (2+ months)
const now = new Date();
const twoMonthsAgo = new Date(now.getFullYear(), now.getMonth() - 2, 1);
const overdueBills = bills.filter(bill => {
if (bill.status !== 'overdue') return false;
const dueDate = new Date(bill.dueDate);
return dueDate < twoMonthsAgo;
});
// Group by customer
const overdueCustomers = {};
overdueBills.forEach(bill => {
if (!overdueCustomers[bill.customerId]) {
overdueCustomers[bill.customerId] = {
customer: customers.find(c => c.id === bill.customerId),
bills: []
};
}
overdueCustomers[bill.customerId].bills.push(bill);
});
// Create alerts
Object.values(overdueCustomers).forEach(customerData => {
const totalDebt = customerData.bills.reduce((sum, bill) => sum + bill.amount + bill.lateFee, 0);
const monthsOverdue = customerData.bills.length;
const alert = document.createElement('div');
alert.className = 'p-3 rounded bg-red-50 border border-red-200 flex justify-between items-center alert-pulse';
const alertContent = document.createElement('div');
const alertTitle = document.createElement('h4');
alertTitle.className = 'font-semibold text-red-800';
alertTitle.textContent = `${customerData.customer.name} (${customerData.customer.number})`;
const alertMessage = document.createElement('p');
alertMessage.className = 'text-sm text-red-600';
alertMessage.textContent = `Dívida de ${totalDebt} MZN (${monthsOverdue} ${monthsOverdue === 1 ? 'mês' : 'meses'} atrasado)`;
alertContent.appendChild(alertTitle);
alertContent.appendChild(alertMessage);
const alertButton = document.createElement('button');
alertButton.className = 'px-3 py-1 bg-red-100 hover:bg-red-200 text-red-800 rounded text-sm';
alertButton.textContent = 'Ver Detalhes';
alertButton.onclick = () => showCustomerDetails(customerData.customer.id);
alert.appendChild(alertContent);
alert.appendChild(alertButton);
alertsContainer.appendChild(alert);
});
// If no alerts, show message
if (alertsContainer.children.length === 0) {
const noAlerts = document.createElement('div');
noAlerts.className = 'p-3 rounded bg-blue-50 border border-blue-200 text-blue-800';
noAlerts.textContent = 'Nenhum alerta de pagamento atrasado.';
alertsContainer.appendChild(noAlerts);
}
}
// Billing functions
function calculateAmount() {
const consumption = parseFloat(document.getElementById('consumption').value) || 5;
const minConsumption = settings.minConsumption;
const minPrice = settings.minConsumptionPrice;
const extraPrice = settings.extraConsumptionPrice;
let amount = minPrice;
if (consumption > minConsumption) {
amount += (consumption - minConsumption) * extraPrice;
}
document.getElementById('amount').value = amount.toFixed(2);
}
function registerPayment() {
const customerSearch = document.getElementById('customer-search').value.trim();
const consumption = parseFloat(document.getElementById('consumption').value) || 5;
const amount = parseFloat(document.getElementById('amount').value) || 300;
if (!customerSearch) {
alert('Por favor, selecione um cliente.');
return;
}
// In a real app, this would save to a database
// For demo, we'll just show a receipt
// Find customer (simplified for demo)
const customer = customers.find(c =>
c.name.toLowerCase().includes(customerSearch.toLowerCase()) ||
c.number.toLowerCase().includes(customerSearch.toLowerCase())
);
if (!customer) {
alert('Cliente não encontrado.');
return;
}
// Generate receipt
document.getElementById('receipt-number').textContent = `REC-${Date.now().toString().slice(-6)}`;
document.getElementById('receipt-date').textContent = new Date().toLocaleDateString('pt-PT');
document.getElementById('receipt-customer').textContent = `${customer.number} - ${customer.name}`;
document.getElementById('receipt-water-amount').textContent = `${amount} MZN`;
document.getElementById('receipt-late-fee').textContent = '0 MZN'; // No late fee for immediate payment
document.getElementById('receipt-total').textContent = `${amount} MZN`;
showModal('payment-receipt-modal');
// Clear form
document.getElementById('customer-search').value = '';
document.getElementById('consumption').value = '5';
document.getElementById('amount').value = '300';
// Add to bills (for demo)
const now = new Date();
const currentMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const dueDate = new Date(now.getFullYear(), now.getMonth(), settings.dueDate);
const newBill = {
id: bills.length + 1,
customerId: customer.id,
customerNumber: customer.number,
customerName: customer.name,
area: customer.area,
areaName: customer.areaName,
consumption: consumption,
amount: amount,
date: currentMonth.toISOString().split('T')[0],
dueDate: dueDate.toISOString().split('T')[0],
paymentDate: now.toISOString().split('T')[0],
status: 'paid',
lateFee: 0
};
bills.push(newBill);
// Update dashboard
updateDashboard();
loadRecentPayments();
loadAlerts();
loadBillingHistory();
}
function searchCustomers(query) {
const resultsContainer = document.getElementById('search-results');
resultsContainer.innerHTML = '';
if (query.length < 2) {
resultsContainer.classList.add('hidden');
return;
}
const filteredCustomers = customers.filter(customer =>
customer.name.toLowerCase().includes(query.toLowerCase()) ||
customer.number.toLowerCase().includes(query.toLowerCase())
);
if (filteredCustomers.length === 0) {
const noResults = document.createElement('div');
noResults.className = 'p-2 text-sm text-gray-500';
noResults.textContent = 'Nenhum cliente encontrado';
resultsContainer.appendChild(noResults);
} else {
filteredCustomers.forEach(customer => {
const resultItem = document.createElement('div');
resultItem.className = 'p-2 hover:bg-gray-100 cursor-pointer';
resultItem.textContent = `${customer.number} - ${customer.name}`;
resultItem.onclick = () => {
document.getElementById('customer-search').value = `${customer.number} - ${customer.name}`;
resultsContainer.classList.add('hidden');
};
resultsContainer.appendChild(resultItem);
});
}
resultsContainer.classList.remove('hidden');
}
function loadBillingHistory() {
const billingHistoryTable = document.getElementById('billing-history');
billingHistoryTable.innerHTML = '';
const filter = document.getElementById('billing-filter').value;
const monthFilter = document.getElementById('billing-month').value;
let filteredBills = [...bills];
// Apply status filter
if (filter === 'paid') {
filteredBills = filteredBills.filter(bill => bill.status === 'paid');
} else if (filter === 'pending') {
filteredBills = filteredBills.filter(bill => bill.status === 'pending');
} else if (filter === 'overdue') {
filteredBills = filteredBills.filter(bill => bill.status === 'overdue');
}
// Apply month filter
if (monthFilter) {
filteredBills = filteredBills.filter(bill => {
const billDate = new Date(bill.date);
const billMonth = billDate.getFullYear() + '-' + String(billDate.getMonth() + 1).padStart(2, '0');
return billMonth === monthFilter;
});
}
// Sort by date (newest first)
filteredBills.sort((a, b) => new Date(b.date) - new Date(a.date));
filteredBills.forEach(bill => {
const row = document.createElement('tr');
const numberCell = document.createElement('td');
numberCell.className = 'px-6 py-4 whitespace-nowrap';
numberCell.textContent = bill.customerNumber;
const customerCell = document.createElement('td');
customerCell.className = 'px-6 py-4 whitespace-nowrap';
customerCell.textContent = bill.customerName;
const areaCell = document.createElement('td');
areaCell.className = 'px-6 py-4 whitespace-nowrap';
areaCell.textContent = bill.areaName;
const consumptionCell = document.createElement('td');
consumptionCell.className = 'px-6 py-4 whitespace-nowrap';
consumptionCell.textContent = `${bill.consumption} m³`;
const amountCell = document.createElement('td');
amountCell.className = 'px-6 py-4 whitespace-nowrap';
amountCell.textContent = `${bill.amount + bill.lateFee} MZN`;
const dateCell = document.createElement('td');
dateCell.className = 'px-6 py-4 whitespace-nowrap';
dateCell.textContent = new Date(bill.date).toLocaleDateString('pt-PT');
const statusCell = document.createElement('td');
statusCell.className = 'px-6 py-4 whitespace-nowrap';
const statusBadge = document.createElement('span');
statusBadge.className = 'px-2 py-1 text-xs rounded-full';
if (bill.status === 'paid') {
statusBadge.classList.add('bg-green-100', 'text-green-800');
statusBadge.textContent = 'Pago';
} else if (bill.status === 'overdue') {
statusBadge.classList.add('bg-red-100', 'text-red-800');
statusBadge.textContent = 'Atrasado';
} else {
statusBadge.classList.add('bg-yellow-100', 'text-yellow-800');
statusBadge.textContent = 'Pendente';
}
statusCell.appendChild(statusBadge);
const actionsCell = document.createElement('td');
actionsCell.className = 'px-6 py-4 whitespace-nowrap text-right text-sm font-medium';
const viewButton = document.createElement('button');
viewButton.className = 'text-primary hover:text-secondary mr-2';
viewButton.innerHTML = '<i class="fas fa-eye"></i>';
viewButton.title = 'Ver Detalhes';
viewButton.onclick = () => viewBillDetails(bill.id);
const editButton = document.createElement('button');
editButton.className = 'text-yellow-600 hover:text-yellow-800 mr-2';
editButton.innerHTML = '<i class="fas fa-edit"></i>';
editButton.title = 'Editar';
editButton.onclick = () => editBill(bill.id);
const deleteButton = document.createElement('button');
deleteButton.className = 'text-red-600 hover:text-red-800';
deleteButton.innerHTML = '<i class="fas fa-trash"></i>';
deleteButton.title = 'Eliminar';
deleteButton.onclick = () => confirmDeleteBill(bill.id);
actionsCell.appendChild(viewButton);
actionsCell.appendChild(editButton);
actionsCell.appendChild(deleteButton);
row.appendChild(numberCell);
row.appendChild(customerCell);
row.appendChild(areaCell);
row.appendChild(consumptionCell);
row.appendChild(amountCell);
row.appendChild(dateCell);
row.appendChild(statusCell);
row.appendChild(actionsCell);
billingHistoryTable.appendChild(row);
});
// If no bills, show message
if (filteredBills.length === 0) {
const emptyRow = document.createElement('tr');
const emptyCell = document.createElement('td');
emptyCell.colSpan = 8;
emptyCell.className = 'px-6 py-4 text-center text-gray-500';
emptyCell.textContent = 'Nenhuma cobrança encontrada';
emptyRow.appendChild(emptyCell);
billingHistoryTable.appendChild(emptyRow);
}
}
function viewBillDetails(billId) {
const bill = bills.find(b => b.id == billId);
if (!bill) return;
// Generate receipt
document.getElementById('receipt-number').textContent = `REC-${bill.id.toString().padStart(6, '0')}`;
document.getElementById('receipt-date').textContent = bill.paymentDate ?
new Date(bill.paymentDate).toLocaleDateString('pt-PT') :
new Date().toLocaleDateString('pt-PT');
const customer = customers.find(c => c.id == bill.customerId);
document.getElementById('receipt-customer').textContent = customer ?
`${customer.number} - ${customer
</html> |