Initial Commit

parents
**/nbproject/private/
**/nbproject/Makefile-*.mk
**/nbproject/Package-*.bash
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>reporteExcel</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<exec.mainClass>com.mycompany.reporteexcel.panel</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version> <!---->
<type>jar</type>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jdatepicker/jdatepicker -->
<dependency>
<groupId>org.jdatepicker</groupId>
<artifactId>jdatepicker</artifactId>
<version>1.3.4</version>
</dependency>
</dependencies>
<build>
<finalName>EXCEL</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.reporteexcel.panel</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.reporteexcel.panel</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
</project>
\ No newline at end of file
package com.mycompany.reporteexcel;
import java.util.concurrent.TimeUnit;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ApiData {
public JSONObject conseguirDataReporte(int empresa,int razonSocial, int periodo, String fecha, String conceptoPago) {
JSONObject respuesta = new JSONObject();
try {
// Configurar el timeout de 2 minutos (120,000 ms)
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(360, TimeUnit.SECONDS) // Timeout de conexión
.readTimeout(360, TimeUnit.SECONDS) // Timeout de lectura
.writeTimeout(360, TimeUnit.SECONDS) // Timeout de escritura
.build();
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
String razonSocialText = razonSocial == 0 ? "NULL" : String.valueOf(razonSocial);
JSONObject data = new JSONObject();
String sql = "SELECT * FROM caja.func_listar_morosidad_sede(363,1145,NULL,"+periodo+",NULL,NULL,'"+conceptoPago+"',"+razonSocialText+",'FALSE',NULL,'"+fecha+"',NULL,500000,0,1 )";
System.out.println(sql);
data.put("procedure", sql);
data.put("params", new JSONArray());
RequestBody body = RequestBody.create(data.toString(), JSON);
Request request = new Request.Builder()
.url("http://prueba.sacooliveros.edu.pe:8080/formulario-api/api/v1/excel/procedure")
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String responseBodyString = response.body().string();
respuesta = new JSONObject(responseBodyString);
} else {
System.out.println("Error: " + response.code() + " - " + response.message());
String errorResponseBody = response.body() != null ? response.body().string() : "Cuerpo vacío";
System.out.println("Response: " + errorResponseBody);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
} catch (JSONException ex) {
System.out.println("Error : HttpRequest : " + ex.getMessage());
}
return respuesta;
}
}
package com.mycompany.reporteexcel;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.json.JSONArray;
import org.json.JSONObject;
import java.awt.Color;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
public class ExcelService {
public byte[] generateExcel(JSONObject json, int size, JProgressBar progressBar) throws IOException {
ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
XSSFWorkbook workbook = new XSSFWorkbook();
createSheet(workbook, json, size, progressBar);
try {
workbook.write(outByteStream);
workbook.close();
outByteStream.close();
outByteStream.flush();
SwingUtilities.invokeLater(() -> progressBar.setValue(100));
return outByteStream.toByteArray();
} catch (IOException e) {
workbook.close();
outByteStream.close();
outByteStream.flush();
System.out.println(e.getMessage());
SwingUtilities.invokeLater(() -> progressBar.setValue(0));
return null;
}
}
public void createSheet(XSSFWorkbook workbook, JSONObject json, int sizeOfBytes, JProgressBar progressBar) {
if (json.optJSONArray("sheetArray", new JSONArray()).isEmpty()) {
XSSFSheet sheet = workbook.createSheet(json.optString("sheet_name", "no_name"));
buildSheet(workbook, sheet, json, progressBar);
JSONArray identifiers = json.getJSONArray("identifiers");
for (int i = 0; i < identifiers.length(); i++) {
if (json.optBoolean("auto_adjustment", true)) {
findLargerTextByIdentifer(sheet, json.getJSONArray("data"), identifiers);
}
}
for (int j = 0; j < json.optJSONArray("columns_size", new JSONArray()).length(); j++) {
if (json.getJSONArray("columns_size").getInt(j) > 0) {
sheet.setColumnWidth(j, json.getJSONArray("columns_size").getInt(j));
}
}
} else {
JSONArray sheetArray = json.optJSONArray("sheetArray", new JSONArray());
for (int i = 0; i < sheetArray.length(); i++) {
JSONObject jsonObject = sheetArray.getJSONObject(i);
XSSFSheet sheet = workbook.createSheet(jsonObject.optString("sheet_name", "no_name"));
JSONArray identifiers = jsonObject.getJSONArray("identifiers");
for (int j = 0; j < identifiers.length(); j++) {
if (jsonObject.optBoolean("auto_adjustment", true)) {
findLargerTextByIdentifer(sheet, jsonObject.getJSONArray("data"), identifiers);
}
}
buildSheet(workbook, sheet, jsonObject, progressBar);
if (!jsonObject.optBoolean("auto_adjustment", true)) {
for (int k = 0; k < jsonObject.getJSONArray("columns_size").length(); k++) {
sheet.autoSizeColumn(k);
}
}
for (int j = 0; j < jsonObject.optJSONArray("columns_size", new JSONArray()).length(); j++) {
if (jsonObject.getJSONArray("columns_size").getInt(j) > 0) {
sheet.setColumnWidth(j, jsonObject.getJSONArray("columns_size").getInt(j));
}
}
}
}
}
private void findLargerTextByIdentifer(XSSFSheet sheet, JSONArray data, JSONArray identifiers) {
int[] maxLengthByIdentifier = new int[identifiers.length()];
for (int i = 0; i < data.length(); i++) {
JSONObject row_data = data.optJSONObject(i);
for (int j = 0; j < identifiers.length(); j++) {
int length = row_data.optString(identifiers.optString(j, "")).length();
int length2 = row_data.optString(String.valueOf(j), "").length();
if (length > maxLengthByIdentifier[j] || length2 > maxLengthByIdentifier[j]) {
maxLengthByIdentifier[j] = Math.max(length, length2);
}
}
}
for (int i = 0; i < maxLengthByIdentifier.length; i++) {
sheet.setColumnWidth(i, ((maxLengthByIdentifier[i] * 375)));
}
}
public void buildSheet(XSSFWorkbook workbook, XSSFSheet sheet, JSONObject json, JProgressBar progressBar) {
final XSSFCellStyle defaultStyle = createCellStyle(workbook, new JSONObject());
List<String> stylesSaved = new ArrayList<>();
List<XSSFCellStyle> styleObjectsSaved = new ArrayList<>();
XSSFRow row;
XSSFCell cell;
XSSFCellStyle cellStyle;
JSONArray identifiers = json.optJSONArray("identifiers", new JSONArray());
JSONArray data = json.optJSONArray("data", new JSONArray());
JSONArray styles = json.optJSONArray("styles", new JSONArray());
fillStylesArray(styles, workbook, stylesSaved, styleObjectsSaved);
int totalRows = data.length() + (json.has("title") ? 1 : 0); // Total rows including title
int currentRow = 0;
if (json.has("title")) {
row = sheet.createRow(currentRow);
JSONObject titleJson = json.getJSONObject("title");
JSONObject style = titleJson.optJSONObject("style", new JSONObject());
cell = row.createCell(0);
cell.setCellValue(titleJson.optString("text", ""));
if (style.isEmpty()) {
cell.setCellStyle(defaultStyle);
} else {
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle);
} else {
cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
}
}
sheet.addMergedRegion(new CellRangeAddress(currentRow, currentRow, 0, style.getInt("colspan") - 1));
currentRow++;
// Update progress bar
int progress = (int) ((currentRow / (double) totalRows) * 100);
SwingUtilities.invokeLater(() -> progressBar.setValue(progress));
}
for (int i = 0; i < data.length(); i++, currentRow++) {
int index = json.has("title") ? i : i;
row = sheet.createRow(currentRow);
JSONObject row_data = data.optJSONObject(index);
for (int j = 0; j < identifiers.length(); j++) {
cell = row.createCell(j);
JSONArray styleArray = styles.optJSONArray(index, new JSONArray());
JSONObject style = styleArray.optJSONObject(j, new JSONObject());
String value = row_data.optString(identifiers.getString(j), row_data.optString(String.valueOf(j), ""));
if (style.isEmpty()) {
cell.setCellStyle(defaultStyle);
cell.setCellValue(value);
} else {
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
cellStyle = createCellStyle(workbook, style);
cell.setCellStyle(cellStyle);
styleObjectsSaved.add(cellStyle);
cell.setCellValue(value);
} else {
cell.setCellStyle(styleObjectsSaved.get(stylesSaved.indexOf(style.toString())));
cell.setCellValue(value);
}
if (style.has("format")) {
setCellFormat(cell, style.optString("format", "text"), value);
}
if (style.has("colspan")) {
sheet.addMergedRegion(new CellRangeAddress(currentRow, currentRow, j, j + style.optInt("colspan", 0)));
}
}
}
// Update progress bar
int progress = (int) ((currentRow / (double) totalRows) * 100);
SwingUtilities.invokeLater(() -> progressBar.setValue(progress - 1));
}
}
public void setCellFormat(XSSFCell cell, String format, String value) {
switch (format) {
case "number" -> {
cell.setCellType(CellType.NUMERIC);
XSSFCellStyle style = cell.getCellStyle();
DataFormat dataFormat = cell.getSheet().getWorkbook().createDataFormat();
style.setDataFormat(dataFormat.getFormat("0.00"));
cell.setCellStyle(style);
cell.setCellValue(Double.parseDouble(value));
}
case "date" -> {
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(value);
}
case "formula" -> {
cell.setCellType(CellType.FORMULA);
cell.setCellFormula(value);
}
default -> {
cell.setCellType(CellType.STRING);
cell.setCellValue(value);
}
}
}
private XSSFCellStyle createCellStyle(XSSFWorkbook workbook, JSONObject styleJson) {
XSSFColor background = getXSSFColor(styleJson.optString("background", "#ffffff"));
XSSFColor foreground = getXSSFColor(styleJson.optString("foreground", styleJson.optString("color", "#333333")));
boolean bold = styleJson.optBoolean("bold", false);
boolean border = styleJson.optBoolean("border", true);
String align = styleJson.optString("textAlign", "center");
XSSFCellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
style.setAlignment(align.equals("center") ? HorizontalAlignment.CENTER : align.equals("left") ? HorizontalAlignment.LEFT : HorizontalAlignment.RIGHT);
style.setWrapText(styleJson.optBoolean("wrapText", false));
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
if (border) {
style.setBorderColor(BorderSide.BOTTOM, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.TOP, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.LEFT, getXSSFColor("#333333"));
style.setBorderColor(BorderSide.RIGHT, getXSSFColor("#333333"));
} else {
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderColor(BorderSide.BOTTOM, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.TOP, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.LEFT, getXSSFColor("#aaaaaa"));
style.setBorderColor(BorderSide.RIGHT, getXSSFColor("#aaaaaa"));
}
font.setBold(bold);
style.setFont(font);
if (background != null) {
style.setFillForegroundColor(background);
}
if (foreground != null) {
style.getFont().setColor(foreground);
}
return style;
}
public XSSFColor getXSSFColor(String rgb) {
int red = Integer.parseInt(rgb.substring(1, 3), 16);
int green = Integer.parseInt(rgb.substring(3, 5), 16);
int blue = Integer.parseInt(rgb.substring(5, 7), 16);
Color awtColor = new Color(red, green, blue);
XSSFColor xssfColor = new XSSFColor();
xssfColor.setRGB(new byte[]{(byte) awtColor.getRed(), (byte) awtColor.getGreen(), (byte) awtColor.getBlue()});
return xssfColor;
}
public void fillStylesArray(JSONArray styles, XSSFWorkbook workbook, List<String> stylesSaved, List<XSSFCellStyle> styleObjectsSaved) {
for (int i = 0; i < styles.length(); i++) {
JSONArray styleArray = styles.optJSONArray(i, new JSONArray());
for (int j = 0; j < styleArray.length(); j++) {
JSONObject style = styleArray.optJSONObject(j, new JSONObject());
if (!stylesSaved.contains(style.toString())) {
stylesSaved.add(style.toString());
XSSFCellStyle cellStyle = createCellStyle(workbook, style);
styleObjectsSaved.add(cellStyle);
}
}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="1" min="-2" pref="546" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="0" pref="362" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="33" green="33" red="33" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="33" green="33" red="33" type="rgb"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="false"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JToggleButton" name="btnExportar">
<Properties>
<Property name="text" type="java.lang.String" value="EXPORTAR REPORTE"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnExportarActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="370" y="60" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="14" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="RUTA:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="270" width="200" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="findFolder">
<Properties>
<Property name="text" type="java.lang.String" value="SELECCIONAR RUTA"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="findFolderActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="370" y="120" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="txtRuta">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="220" y="270" width="320" height="20"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="mensaje">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="320" width="530" height="20"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JProgressBar" name="progressBar">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="33" green="33" red="33" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.MatteColorBorderInfo">
<MatteColorBorder/>
</Border>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="300" width="530" height="10"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JComboBox" name="razonSocial">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="1">
<StringItem index="0" value="---"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="190" y="60" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="13" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="FECHA DE CORTE"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="190" y="100" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JComboBox" name="periodo">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="13">
<StringItem index="0" value="---"/>
<StringItem index="1" value="2025"/>
<StringItem index="2" value="2024"/>
<StringItem index="3" value="2023"/>
<StringItem index="4" value="2022"/>
<StringItem index="5" value="2021"/>
<StringItem index="6" value="2020"/>
<StringItem index="7" value="2019"/>
<StringItem index="8" value="2018"/>
<StringItem index="9" value="2017"/>
<StringItem index="10" value="2016"/>
<StringItem index="11" value="2015"/>
<StringItem index="12" value="2014"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="120" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="13" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="PERIODO"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="100" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="13" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="TIPO EMPRESA"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="40" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JComboBox" name="empresa">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="3">
<StringItem index="0" value="---"/>
<StringItem index="1" value="FRANQUICIA"/>
<StringItem index="2" value="SEDE"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="empresaActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="60" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="13" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="RAZ&#xd3;N SOCIAL"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="190" y="40" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="txtFecha">
<Properties>
<Property name="columns" type="int" value="10"/>
</Properties>
<Events>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtFechaKeyPressed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTextField(10)"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="190" y="120" width="150" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="13" style="1"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="CONCEPTO DE PAGO"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="170" width="420" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkDiciembre">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Diciembre"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkDiciembreActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="430" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkMatricula">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Matricula"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkMatriculaActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="200" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkFebrero">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Febrero"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkFebreroActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="80" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkMarzo">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Marzo"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkMarzoActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="160" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkAbril">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Abril"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAbrilActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="250" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkMayo">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Mayo"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkMayoActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="330" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkJunio">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Junio"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkJunioActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="430" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkJulio">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Julio"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkJulioActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkAgosto">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Agosto"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAgostoActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="80" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkSetiembre">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Setiembre"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkSetiembreActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="160" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkOctubre">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Octubre"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkOctubreActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="250" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkNoviembre">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Noviembre"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkNoviembreActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="330" y="240" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkEnero">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Enero"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkEneroActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="10" y="220" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Noto Sans" size="10" style="3"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="EJEMPLO: dd/MM/AAAA"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="190" y="160" width="150" height="-1"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
package com.mycompany.reporteexcel;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class panel extends javax.swing.JFrame {
String selectedFolderPath = "";
ApiData api = new ApiData();
ExcelService service = new ExcelService();
private final String[] empresasFranquicia = {
"---", "MARSHAL", "AVANTE", "ESCOBAR", "JOEL JAICO", "PAVENT SCHOLL",
"HERSURA", "ROBERT RIVERA", "SACO OLIVEROS HUAYCAN", "CAJAMARCA",
"OLIVER SCHOOL", "COLEGIO SACO OLIVEROS PRO S.A.C.", "ASOCIACIÓN WESLEY",
"GRUPO EDUCA LIMA S.A.C.", "GAMANSA EDUCADORES SRL", "ASOCIACION EDUCATIVA FAROVI"
};
private final String[] empresasSede = {
"---", "SACO OLIVEROS", "APEIRON", "SISTEMA HELICOIDAL", "SOCIEDAD SACO OLIVEROS S.A.C."
};
public panel() {
initComponents();
setMaxCharacters(txtFecha, 10);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
btnExportar = new javax.swing.JToggleButton();
jLabel1 = new javax.swing.JLabel();
findFolder = new javax.swing.JButton();
txtRuta = new javax.swing.JLabel();
mensaje = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
razonSocial = new javax.swing.JComboBox<>();
jLabel2 = new javax.swing.JLabel();
periodo = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
empresa = new javax.swing.JComboBox<>();
jLabel5 = new javax.swing.JLabel();
txtFecha = new javax.swing.JTextField(10);
jLabel6 = new javax.swing.JLabel();
chkDiciembre = new javax.swing.JCheckBox();
chkMatricula = new javax.swing.JCheckBox();
chkFebrero = new javax.swing.JCheckBox();
chkMarzo = new javax.swing.JCheckBox();
chkAbril = new javax.swing.JCheckBox();
chkMayo = new javax.swing.JCheckBox();
chkJunio = new javax.swing.JCheckBox();
chkJulio = new javax.swing.JCheckBox();
chkAgosto = new javax.swing.JCheckBox();
chkSetiembre = new javax.swing.JCheckBox();
chkOctubre = new javax.swing.JCheckBox();
chkNoviembre = new javax.swing.JCheckBox();
chkEnero = new javax.swing.JCheckBox();
jLabel7 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jPanel1.setBackground(new java.awt.Color(51, 51, 51));
jPanel1.setForeground(new java.awt.Color(51, 51, 51));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
btnExportar.setText("EXPORTAR REPORTE");
btnExportar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnExportarActionPerformed(evt);
}
});
jPanel1.add(btnExportar, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 60, -1, -1));
jLabel1.setFont(new java.awt.Font("Noto Sans", 1, 14)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("RUTA:");
jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 270, 200, -1));
findFolder.setText("SELECCIONAR RUTA");
findFolder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findFolderActionPerformed(evt);
}
});
jPanel1.add(findFolder, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 120, -1, -1));
txtRuta.setForeground(new java.awt.Color(255, 255, 255));
jPanel1.add(txtRuta, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 270, 320, 20));
mensaje.setForeground(new java.awt.Color(255, 0, 0));
mensaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jPanel1.add(mensaje, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, 530, 20));
progressBar.setBackground(new java.awt.Color(51, 51, 51));
progressBar.setForeground(new java.awt.Color(102, 102, 102));
progressBar.setBorder(new javax.swing.border.MatteBorder(null));
jPanel1.add(progressBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, 530, 10));
razonSocial.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "---" }));
jPanel1.add(razonSocial, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 60, 150, -1));
jLabel2.setFont(new java.awt.Font("Noto Sans", 1, 13)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("FECHA DE CORTE");
jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 100, 150, -1));
periodo.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "---", "2025", "2024", "2023", "2022", "2021", "2020", "2019", "2018", "2017", "2016", "2015", "2014" }));
jPanel1.add(periodo, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, 150, -1));
jLabel3.setFont(new java.awt.Font("Noto Sans", 1, 13)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("PERIODO");
jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, 150, -1));
jLabel4.setFont(new java.awt.Font("Noto Sans", 1, 13)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("TIPO EMPRESA");
jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 150, -1));
empresa.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "---", "FRANQUICIA", "SEDE" }));
empresa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
empresaActionPerformed(evt);
}
});
jPanel1.add(empresa, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 150, -1));
jLabel5.setFont(new java.awt.Font("Noto Sans", 1, 13)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("RAZÓN SOCIAL");
jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 40, 150, -1));
txtFecha.setColumns(10);
txtFecha.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtFechaKeyPressed(evt);
}
});
jPanel1.add(txtFecha, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 120, 150, 30));
jLabel6.setFont(new java.awt.Font("Noto Sans", 1, 13)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("CONCEPTO DE PAGO");
jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 420, 30));
chkDiciembre.setForeground(new java.awt.Color(255, 255, 255));
chkDiciembre.setText("Diciembre");
chkDiciembre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkDiciembreActionPerformed(evt);
}
});
jPanel1.add(chkDiciembre, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 240, -1, -1));
chkMatricula.setForeground(new java.awt.Color(255, 255, 255));
chkMatricula.setText("Matricula");
chkMatricula.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkMatriculaActionPerformed(evt);
}
});
jPanel1.add(chkMatricula, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, -1, -1));
chkFebrero.setForeground(new java.awt.Color(255, 255, 255));
chkFebrero.setText("Febrero");
chkFebrero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkFebreroActionPerformed(evt);
}
});
jPanel1.add(chkFebrero, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 220, -1, -1));
chkMarzo.setForeground(new java.awt.Color(255, 255, 255));
chkMarzo.setText("Marzo");
chkMarzo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkMarzoActionPerformed(evt);
}
});
jPanel1.add(chkMarzo, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 220, -1, -1));
chkAbril.setForeground(new java.awt.Color(255, 255, 255));
chkAbril.setText("Abril");
chkAbril.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkAbrilActionPerformed(evt);
}
});
jPanel1.add(chkAbril, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 220, -1, -1));
chkMayo.setForeground(new java.awt.Color(255, 255, 255));
chkMayo.setText("Mayo");
chkMayo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkMayoActionPerformed(evt);
}
});
jPanel1.add(chkMayo, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 220, -1, -1));
chkJunio.setForeground(new java.awt.Color(255, 255, 255));
chkJunio.setText("Junio");
chkJunio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkJunioActionPerformed(evt);
}
});
jPanel1.add(chkJunio, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 220, -1, -1));
chkJulio.setForeground(new java.awt.Color(255, 255, 255));
chkJulio.setText("Julio");
chkJulio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkJulioActionPerformed(evt);
}
});
jPanel1.add(chkJulio, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 240, -1, -1));
chkAgosto.setForeground(new java.awt.Color(255, 255, 255));
chkAgosto.setText("Agosto");
chkAgosto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkAgostoActionPerformed(evt);
}
});
jPanel1.add(chkAgosto, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 240, -1, -1));
chkSetiembre.setForeground(new java.awt.Color(255, 255, 255));
chkSetiembre.setText("Setiembre");
chkSetiembre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkSetiembreActionPerformed(evt);
}
});
jPanel1.add(chkSetiembre, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 240, -1, -1));
chkOctubre.setForeground(new java.awt.Color(255, 255, 255));
chkOctubre.setText("Octubre");
chkOctubre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkOctubreActionPerformed(evt);
}
});
jPanel1.add(chkOctubre, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 240, -1, -1));
chkNoviembre.setForeground(new java.awt.Color(255, 255, 255));
chkNoviembre.setText("Noviembre");
chkNoviembre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkNoviembreActionPerformed(evt);
}
});
jPanel1.add(chkNoviembre, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 240, -1, -1));
chkEnero.setForeground(new java.awt.Color(255, 255, 255));
chkEnero.setText("Enero");
chkEnero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkEneroActionPerformed(evt);
}
});
jPanel1.add(chkEnero, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, -1, -1));
jLabel7.setFont(new java.awt.Font("Noto Sans", 3, 10)); // NOI18N
jLabel7.setForeground(new java.awt.Color(102, 102, 102));
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel7.setText("EJEMPLO: dd/MM/AAAA");
jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 160, 150, -1));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void findFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findFolderActionPerformed
JFileChooser folderChooser = new JFileChooser();
folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Solo permitir carpetas
folderChooser.setDialogTitle("Seleccionar Carpeta");
int returnValue = folderChooser.showOpenDialog(this); // Mostrar diálogo
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFolder = folderChooser.getSelectedFile();
selectedFolderPath = selectedFolder.getAbsolutePath(); // Guardar la ruta
txtRuta.setText(selectedFolderPath);
System.out.println("Carpeta seleccionada: " + selectedFolderPath);
} else {
System.out.println("Selección cancelada");
}
}//GEN-LAST:event_findFolderActionPerformed
private void btnExportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarActionPerformed
String empresaValue = empresa.getSelectedItem().toString();
final int empresaInt;
switch (empresaValue) {
case "FRANQUICIA" ->
empresaInt = 2571;
case "SEDE" ->
empresaInt = 2572;
default ->
empresaInt = 0;
}
String razonSocialValue = razonSocial.getSelectedItem().toString();
final int razonSocialInt;
switch (razonSocialValue) {
case "MARSHAL" ->
razonSocialInt = 5455;
case "AVANTE" ->
razonSocialInt = 5458;
case "ESCOBAR" ->
razonSocialInt = 5459;
case "JOEL JAICO" ->
razonSocialInt = 5461;
case "PAVENT SCHOLL" ->
razonSocialInt = 5463;
case "HERSURA" ->
razonSocialInt = 5464;
case "ROBERT RIVERA" ->
razonSocialInt = 5466;
case "SACO OLIVEROS HUAYCAN" ->
razonSocialInt = 7034;
case "CAJAMARCA" ->
razonSocialInt = 7371;
case "OLIVER SCHOOL" ->
razonSocialInt = 7395;
case "COLEGIO SACO OLIVEROS PRO S.A.C." ->
razonSocialInt = 7435;
case "ASOCIACIÓN WESLEY" ->
razonSocialInt = 7440;
case "GRUPO EDUCA LIMA S.A.C." ->
razonSocialInt = 7449;
case "GAMANSA EDUCADORES SRL" ->
razonSocialInt = 7472;
case "ASOCIACION EDUCATIVA FAROVI" ->
razonSocialInt = 8706;
case "SACO OLIVEROS" ->
razonSocialInt = 1;
case "APEIRON" ->
razonSocialInt = 2;
case "SISTEMA HELICOIDAL" ->
razonSocialInt = 3;
case "SOCIEDAD SACO OLIVEROS S.A.C." ->
razonSocialInt = 6796;
default ->
razonSocialInt = 0;
}
String periodoValue = periodo.getSelectedItem().toString();
final AtomicInteger periodoInt = new AtomicInteger();
if (!"---".equals(periodoValue)) {
periodoInt.set(Integer.parseInt(periodoValue));
} else {
periodoInt.set(2012);
}
periodoInt.set(periodoInt.get() - 2012);
String fecha = txtFecha.getText();
final String conceptoPago = formatConceptoPago(
chkMatricula, chkEnero, chkFebrero, chkMarzo, chkAbril, chkMayo, chkJunio,
chkJulio, chkAgosto, chkSetiembre, chkOctubre, chkNoviembre, chkDiciembre
);
System.out.println("empresaInt " + empresaInt);
System.out.println("razonSocialInt " + razonSocialInt);
System.out.println("periodoInt " + periodoInt);
System.out.println("fecha " + fecha);
System.out.println("conceptoPago " + conceptoPago);
if (periodoInt.get() == 0 || fecha.isEmpty() || "{}".equals(conceptoPago)) {
JOptionPane.showMessageDialog(null, "Periodo, Fecha de corte y Conceptos de Pagos son requeridos.", "Validación Erronea", JOptionPane.ERROR_MESSAGE);
} else if (!isValidDate(fecha)) {
JOptionPane.showMessageDialog(null, "No es una fecha valida", "Validación Erronea", JOptionPane.ERROR_MESSAGE);
} else {
btnExportar.setEnabled(false);
progressBar.setValue(0);
// Crear un hilo para ejecutar la tarea en segundo plano
new Thread(new Runnable() {
@Override
public void run() {
try {
// Verificar la ruta
if (selectedFolderPath == null || selectedFolderPath.isEmpty()) {
selectedFolderPath = Paths.get(System.getProperty("user.home"), "Desktop").toString();
}
// Actualizar la UI con la ruta seleccionada
SwingUtilities.invokeLater(() -> txtRuta.setText(selectedFolderPath));
// Actualizar UI antes de iniciar la tarea
SwingUtilities.invokeLater(() -> {
mensaje.setForeground(Color.WHITE);
mensaje.setText("Obteniendo información...");
});
var obj = api.conseguirDataReporte(empresaInt, razonSocialInt, periodoInt.get(), fecha, conceptoPago);
SwingUtilities.invokeLater(() -> mensaje.setText("Generando Excel..."));
JSONArray identifiers = new JSONArray();
identifiers.put("sede");
identifiers.put("niveles");
identifiers.put("estudiante");
identifiers.put("documento");
identifiers.put("estado");
identifiers.put("fecha_matricula");
identifiers.put("nivel");
identifiers.put("grado");
identifiers.put("turno");
identifiers.put("concepto_pago_nombre");
identifiers.put("plan_total_deuda");
identifiers.put("plan_total_pagado");
identifiers.put("total_neto");
JSONArray data = obj.getJSONArray("data");
// Crear el nuevo objeto con los encabezados
JSONObject headers = new JSONObject();
headers.put("sede", "SEDE:");
headers.put("niveles", "NIVELES:");
headers.put("estudiante", "ESTUDIANTE:");
headers.put("documento", "DOCUMENTO:");
headers.put("estado", "ESTADO:");
headers.put("fecha_matricula", "FECHA MATRÍCULA:");
headers.put("nivel", "NIVEL:");
headers.put("grado", "GRADO:");
headers.put("turno", "TURNO:");
headers.put("concepto_pago_nombre", "CONCEPTO DE PAGO:");
headers.put("plan_total_deuda", "TOTAL DEUDA:");
headers.put("plan_total_pagado", "TOTAL PAGADO:");
headers.put("total_neto", "TOTAL NETO:");
JSONArray newData = new JSONArray();
newData.put(headers);
for (int i = 0; i < data.length(); i++) {
newData.put(data.getJSONObject(i));
}
JSONObject jsonBody = new JSONObject();
jsonBody.put("sheetname", "Test");
jsonBody.put("identifiers", identifiers);
jsonBody.put("data", newData);
byte[] bytes = service.generateExcel(jsonBody, data.length(), progressBar);
File tempFile = new File(selectedFolderPath + "/output.xlsx");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(bytes);
fos.flush();
}
// Actualizar UI cuando se complete la tarea
SwingUtilities.invokeLater(() -> {
mensaje.setForeground(Color.GREEN);
mensaje.setText("Excel Generado Correctamente");
});
} catch (IOException | JSONException ex) {
// Manejar errores y actualizar la UI
SwingUtilities.invokeLater(() -> {
mensaje.setForeground(Color.RED);
mensaje.setText("Error: " + ex.getMessage());
});
Logger.getLogger(panel.class.getName()).log(Level.SEVERE, null, ex);
} finally {
// Habilitar el botón en la UI al finalizar
SwingUtilities.invokeLater(() -> btnExportar.setEnabled(true));
System.gc();
}
}
}).start(); // Iniciar el hilo
}
}//GEN-LAST:event_btnExportarActionPerformed
private void actualizarRazonSocial() {
razonSocial.removeAllItems();
if (empresa.getSelectedIndex() == 2) {
for (String empresa : empresasSede) {
razonSocial.addItem(empresa);
}
} else if (empresa.getSelectedIndex() == 1) {
for (String empresa : empresasFranquicia) {
razonSocial.addItem(empresa);
}
}
}
public String formatConceptoPago(JCheckBox... checkBoxes) {
final int[] values = {13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
final StringBuilder conceptoPago = new StringBuilder("{");
boolean first = true;
for (int i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].isSelected()) {
if (!first) {
conceptoPago.append(",");
}
conceptoPago.append(values[i]);
first = false;
}
}
conceptoPago.append("}");
return conceptoPago.toString();
}
private void chkDiciembreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkDiciembreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkDiciembreActionPerformed
private void chkMatriculaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkMatriculaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkMatriculaActionPerformed
private void chkFebreroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkFebreroActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkFebreroActionPerformed
private void chkMarzoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkMarzoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkMarzoActionPerformed
private void chkAbrilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAbrilActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkAbrilActionPerformed
private void chkMayoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkMayoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkMayoActionPerformed
private void chkJunioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkJunioActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkJunioActionPerformed
private void chkJulioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkJulioActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkJulioActionPerformed
private void chkAgostoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAgostoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkAgostoActionPerformed
private void chkSetiembreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkSetiembreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkSetiembreActionPerformed
private void chkOctubreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkOctubreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkOctubreActionPerformed
private void chkNoviembreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkNoviembreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkNoviembreActionPerformed
private void chkEneroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkEneroActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkEneroActionPerformed
private void txtFechaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFechaKeyPressed
char c = evt.getKeyChar();
// Allow only numbers and backspace
if (!Character.isDigit(c) && c != KeyEvent.VK_BACK_SPACE) {
evt.consume();
return;
}
String text = txtFecha.getText();
// Prevent entering more than 10 characters
if (text.length() >= 10 && c != KeyEvent.VK_BACK_SPACE) {
evt.consume();
return;
}
// Auto-insert '/' at positions 2 and 5
if ((text.length() == 2 || text.length() == 5) && c != KeyEvent.VK_BACK_SPACE) {
txtFecha.setText(text + "/");
}
}//GEN-LAST:event_txtFechaKeyPressed
private void empresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_empresaActionPerformed
actualizarRazonSocial();
}//GEN-LAST:event_empresaActionPerformed
public static void setMaxCharacters(JTextField textField, int maxChars) {
AbstractDocument doc = (AbstractDocument) textField.getDocument();
doc.setDocumentFilter(new DocumentFilter() {
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
if ((fb.getDocument().getLength() + text.length() - length) <= maxChars) {
super.replace(fb, offset, length, text, attrs);
}
}
public void insertString(FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException {
if ((fb.getDocument().getLength() + text.length()) <= maxChars) {
super.insertString(fb, offset, text, attr);
}
}
});
}
private boolean isValidDate(String date) {
// Check if the length is exactly 10 (dd/mm/yyyy)
if (date.length() != 10) {
return false;
}
// Check if the format is dd/mm/yyyy
String[] parts = date.split("/");
if (parts.length != 3) {
return false;
}
String dayStr = parts[0];
String monthStr = parts[1];
String yearStr = parts[2];
// Check if day, month, and year are numeric
if (!dayStr.matches("\\d{2}") || !monthStr.matches("\\d{2}") || !yearStr.matches("\\d{4}")) {
return false;
}
int day = Integer.parseInt(dayStr);
int month = Integer.parseInt(monthStr);
int year = Integer.parseInt(yearStr);
// Check if month is valid (1-12)
if (month < 1 || month > 12) {
return false;
}
// Check if the day is valid for the given month and year
int maxDay = getMaxDaysInMonth(month, year);
if (day < 1 || day > maxDay) {
return false;
}
return true;
}
// Helper method to get max days in a month considering leap years for February
private int getMaxDaysInMonth(int month, int year) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
return (isLeapYear(year)) ? 29 : 28;
default:
return 0; // Invalid month
}
}
// Helper method to check if a year is a leap year
private boolean isLeapYear(int year) {
return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
// Set darker color values
UIManager.put("control", new Color(30, 30, 30));
UIManager.put("info", new Color(40, 40, 40));
UIManager.put("nimbusBase", new Color(10, 10, 20));
UIManager.put("nimbusAlertYellow", new Color(200, 160, 0));
UIManager.put("nimbusDisabledText", new Color(100, 100, 100));
UIManager.put("nimbusFocus", new Color(80, 120, 180));
UIManager.put("nimbusGreen", new Color(130, 150, 40));
UIManager.put("nimbusInfoBlue", new Color(50, 100, 200));
UIManager.put("nimbusLightBackground", new Color(20, 20, 30));
UIManager.put("nimbusOrange", new Color(160, 70, 0));
UIManager.put("nimbusRed", new Color(140, 30, 20));
UIManager.put("nimbusSelectedText", new Color(240, 240, 240));
UIManager.put("nimbusSelectionBackground", new Color(60, 50, 100));
UIManager.put("text", new Color(210, 210, 210));
// Apply the Nimbus look and feel
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new panel().setVisible(true);
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JToggleButton btnExportar;
private javax.swing.JCheckBox chkAbril;
private javax.swing.JCheckBox chkAgosto;
private javax.swing.JCheckBox chkDiciembre;
private javax.swing.JCheckBox chkEnero;
private javax.swing.JCheckBox chkFebrero;
private javax.swing.JCheckBox chkJulio;
private javax.swing.JCheckBox chkJunio;
private javax.swing.JCheckBox chkMarzo;
private javax.swing.JCheckBox chkMatricula;
private javax.swing.JCheckBox chkMayo;
private javax.swing.JCheckBox chkNoviembre;
private javax.swing.JCheckBox chkOctubre;
private javax.swing.JCheckBox chkSetiembre;
private javax.swing.JComboBox<String> empresa;
private javax.swing.JButton findFolder;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel mensaje;
private javax.swing.JComboBox<String> periodo;
private javax.swing.JProgressBar progressBar;
private javax.swing.JComboBox<String> razonSocial;
private javax.swing.JTextField txtFecha;
private javax.swing.JLabel txtRuta;
// End of variables declaration//GEN-END:variables
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment