From dd4e7eba41fb75f04018a3df19152b0603c06e8e Mon Sep 17 00:00:00 2001 From: j-dimension Date: Wed, 3 Jan 2024 23:21:18 +0100 Subject: [PATCH] recalculate due date when creation date is adjusted. close #2252 --- .../client/editors/files/InvoiceDialog.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java index e9327a0e2..c60a9f2ad 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java @@ -699,6 +699,8 @@ You should also get your employer (if you work as a programmer) or school, import java.awt.event.ActionEvent; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -1837,6 +1839,20 @@ private void cmdConfirmInvoiceNumberActionPerformed(java.awt.event.ActionEvent e private void cmdDateCreatedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDateCreatedActionPerformed MultiCalDialog dlg = new MultiCalDialog(this.dtCreated, EditorsRegistry.getInstance().getMainWindow(), true); dlg.setVisible(true); + + try { + Date paymentDate=df.parse(this.dtCreated.getText()); + int dueInDays=this.invoicePools.get(this.cmbInvoicePool.getSelectedItem().toString()).getPaymentTerm(); + + LocalDateTime localDateTime = paymentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + localDateTime = localDateTime.plusDays(dueInDays); + paymentDate = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + this.dtDue.setText(df.format(paymentDate)); + + } catch (Throwable t) { + log.error("Cannot recalculate due date for creation date " + this.dtCreated.getText()); + } + }//GEN-LAST:event_cmdDateCreatedActionPerformed private void cmdDatePeriodFromActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDatePeriodFromActionPerformed