public class DocUtilities
extends java.lang.Object
IDoc
and related classes.
Code that processes objects (like calculating an invoice amount) is concentrated in this class (instead of in the persistent object classes) to make the persistent objects class reducing network bandwidth and increasing code security (by avoiding code traveling with the persistent object).
Some functions require a persistent manager and must be provided before calling them.
Modifier and Type | Field and Description |
---|---|
private static org.sistema.persist.PersistentService |
persistentManager
The manager required to perform queries of persistent objects.
|
Constructor and Description |
---|
DocUtilities() |
Modifier and Type | Method and Description |
---|---|
static int |
compare(IDoc doc,
java.time.ZonedDateTime date)
Compares the date of a document to a zoned time.
|
static int |
count(java.util.Collection<IDoc> docs,
IDocType type)
Counts the number of documents of a given type.
|
static java.util.Collection<IItemPerc> |
getDefaultPercentages(java.util.Date date,
java.lang.String ticket) |
static java.lang.Iterable<IItem> |
getItems(IDocItemized document)
Builds an array with every
IItem on the invoice. |
static java.util.Collection |
getPayments(IDoc document,
java.util.Date closingDate)
Retrieves the payments
|
static java.math.BigDecimal |
getPercentageAmount(IItem item,
java.math.BigDecimal baseAmount,
java.math.BigDecimal runningSum,
java.lang.Integer percentageId) |
static java.lang.Iterable<IItemPerc> |
getPercentages(IDocValued doc,
int typeId) |
static java.util.Collection |
getPercentageTypes(IDocItemized document)
Builds a collection with the percentage types
that are set on an invoice.
|
static java.math.BigDecimal |
getSubtotal(IDocItemized document)
Calculates the subtotal of an invoice based an all it's items value.
|
static java.lang.Boolean |
isDocumentCancelled(IDoc document)
Standard way to determine if a document has been cancelled.
|
private static boolean |
isToBeAdded(java.util.Collection<IDoc> docs,
java.util.Collection<IDocType> filter,
IDoc doc)
Determines whether a given document should be added
to a collection of documents or not.
|
static IItemPerc |
loadPercentage(byte typeId,
int order)
Loads a percentage instance from the persistent service.
|
static IPercType |
loadPercentageType(byte typeId)
Loads a percentage type from the persistent service.
|
static IItemPerc |
readPercentage(IDocItem di,
byte typeId)
Retrieves a percentage of a given type
from the item of a
IDocItem relationship. |
static IItemPerc |
readPercentage(IItem i,
byte typeId,
int order)
Retrieves the percentage of a given type from an item.
|
static java.util.Collection<IDoc> |
readRelatedDocuments(java.util.Collection<IDoc> documents,
java.util.Collection filter)
Builds a collection with documents related to some documents.
|
static java.util.Collection<IDoc> |
readRelatedDocuments(IDocItemized doc,
java.util.Collection<IDocType> typeFilter) |
static java.util.Collection<IDoc> |
readRelatedDocuments(java.lang.Integer docId,
java.util.Collection<IDocItem> docItems,
java.util.Collection<IDocType> typeFilter)
Reads all documents related to each child present
in a collection of
IDocItem relationships. |
static void |
setPersistentManager(org.sistema.persist.PersistentService newManager)
Sets the persistent manager used by functions of this class to perform queries.
|
private static org.sistema.persist.PersistentService persistentManager
public static int compare(IDoc doc, java.time.ZonedDateTime date)
doc
- date
- date
with
doc.getDate()
or doc.getTime()
.public static int count(java.util.Collection<IDoc> docs, IDocType type)
docs
- type
- public static java.lang.Iterable<IItem> getItems(IDocItemized document)
IItem
on the invoice.document
- public static java.util.Collection getPayments(IDoc document, java.util.Date closingDate)
document
- Document to retrieve the payments fromclosingDate
- public static java.math.BigDecimal getPercentageAmount(IItem item, java.math.BigDecimal baseAmount, java.math.BigDecimal runningSum, java.lang.Integer percentageId)
item
- baseAmount
- runningSum
- percentageId
- public static java.util.Collection getPercentageTypes(IDocItemized document)
document
- public static java.lang.Iterable<IItemPerc> getPercentages(IDocValued doc, int typeId)
doc
- typeId
- typeId
or an empty collection when no percentages match.public static java.math.BigDecimal getSubtotal(IDocItemized document)
document
- public static java.util.Collection<IItemPerc> getDefaultPercentages(java.util.Date date, java.lang.String ticket) throws java.lang.Exception
java.lang.Exception
public static java.lang.Boolean isDocumentCancelled(IDoc document)
A document is cancelled when the ATTRIBUTE_STAUS_CANCELLED
has been set.
Using this method (instead of checking the ATTRIBUTE_STATUS field of a document object) makes maintenance easier (just one place to change the logic when required).
document
- DocumentConstants
private static boolean isToBeAdded(java.util.Collection<IDoc> docs, java.util.Collection<IDocType> filter, IDoc doc)
Temporal method until Persistent.equals() is fixed (avoiding the infinite loop that occurs).
docs
- doc
- filter
- true
only when the type of the document is set in the filter collection,
and the document has not been added to the collection.public static IItemPerc loadPercentage(byte typeId, int order) throws java.lang.Exception
typeId
- typeId
.java.lang.Exception
public static IPercType loadPercentageType(byte typeId) throws java.lang.Exception
typeId
- java.lang.Exception
public static IItemPerc readPercentage(IDocItem di, byte typeId) throws java.lang.Exception
IDocItem
relationship.
It if does not exist, a new is loaded from the persistent service.
di
- typeId
- java.lang.Exception
public static IItemPerc readPercentage(IItem i, byte typeId, int order) throws java.lang.Exception
It i
does not contain a percentage of type typeId
a IItemPerce
instance is loaded from the persistent service
and added to the i
.
i
- item from which the percentage is being requestedtypeId
- identifier of the percentage type being requestedorder
- order of the percentage being requestedjava.lang.Exception
public static java.util.Collection<IDoc> readRelatedDocuments(IDocItemized doc, java.util.Collection<IDocType> typeFilter)
doc
- typeFilter
- document types to select, types not included are excludedpublic static java.util.Collection<IDoc> readRelatedDocuments(java.lang.Integer docId, java.util.Collection<IDocItem> docItems, java.util.Collection<IDocType> typeFilter)
IDocItem
relationships.
The related documents of each item are defined as the union of:
IItem.getRelatedDocs()
),IItem.getRelatedDocs()
on each element of IItem.getRelatedItems()
.
docId
- identifier of the document for which related documents are being requested.docItems
- document-item relations of the document.typeFilter
- document types to select, types not included are excludedpublic static java.util.Collection<IDoc> readRelatedDocuments(java.util.Collection<IDoc> documents, java.util.Collection filter)
documents
- Documents for which related documents are being requested.filter
- Relationship types to be included.
Relationship types not included are filtered out.public static void setPersistentManager(org.sistema.persist.PersistentService newManager)
newManager
- The persistent manager.