InMemoryInvoice.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * blueHour: open source accounting
  5.  * http://tidalwave.it/projects/bluehour
  6.  *
  7.  * Copyright (C) 2013 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/bluehour-src
  22.  * git clone https://github.com/tidalwave-it/bluehour-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.accounting.model.impl;

  27. import jakarta.annotation.Nonnull;
  28. // import javax.annotation.concurrent.Immutable;
  29. import java.time.LocalDate;
  30. import java.util.List;
  31. import java.util.concurrent.CopyOnWriteArrayList;
  32. import it.tidalwave.accounting.model.JobEvent;
  33. import it.tidalwave.accounting.model.Project;
  34. import it.tidalwave.accounting.model.spi.InvoiceSpi;
  35. import it.tidalwave.accounting.model.types.Money;
  36. import it.tidalwave.util.As;
  37. import it.tidalwave.util.Finder;
  38. import it.tidalwave.util.Id;
  39. import lombok.EqualsAndHashCode;
  40. import lombok.Getter;
  41. import lombok.ToString;
  42. import lombok.experimental.Delegate;

  43. /***************************************************************************************************************************************************************
  44.  *
  45.  * @author  Fabrizio Giudici
  46.  *
  47.  **************************************************************************************************************************************************************/
  48. /* @Immutable */ @EqualsAndHashCode @ToString(exclude = "as")
  49. public class InMemoryInvoice implements InvoiceSpi
  50.   {
  51.     private static final long serialVersionUID = 1L;

  52.     @Delegate
  53.     private final As as = As.forObject(this);

  54.     @Getter @Nonnull
  55.     private final Id id;

  56.     @Getter
  57.     private final String number;

  58.     @Getter @Nonnull
  59.     private final Project project;

  60.     @Nonnull
  61.     private final List<InMemoryJobEvent> jobEvents; // FIXME: immutablelist

  62.     @Nonnull
  63.     private final LocalDate date;

  64.     @Nonnull
  65.     private final LocalDate dueDate;

  66.     @Getter @Nonnull
  67.     private final Money earnings;

  68.     @Getter @Nonnull
  69.     private final Money tax;

  70.     /***********************************************************************************************************************************************************
  71.      *
  72.      **********************************************************************************************************************************************************/
  73.     public /* FIXME private */ InMemoryInvoice (@Nonnull final Builder builder)
  74.       {
  75.         this.id = builder.getId();
  76.         this.number = builder.getNumber();
  77.         this.project = builder.getProject();
  78.         this.jobEvents = (List<InMemoryJobEvent>)builder.getJobEvents();
  79.         this.date = builder.getDate();
  80.         this.dueDate = builder.getDueDate(); // FIXME: round to the end of the month?
  81.         this.earnings = builder.getEarnings();
  82.         this.tax = builder.getTax();
  83.       }

  84.     /***********************************************************************************************************************************************************
  85.      * {@inheritDoc}
  86.      **********************************************************************************************************************************************************/
  87.     @Override @Nonnull
  88.     public Finder<JobEvent> findJobEvents()
  89.       {
  90.         return Finder.ofSupplier(() -> new CopyOnWriteArrayList<>(jobEvents));
  91.       }

  92.     /***********************************************************************************************************************************************************
  93.      * {@inheritDoc}
  94.      **********************************************************************************************************************************************************/
  95.     @Override @Nonnull
  96.     public Builder toBuilder()
  97.       {
  98.         return new Builder(id, number, project, jobEvents, date, dueDate, earnings, tax, Builder.Callback.DEFAULT);
  99.       }
  100.   }