Commit 56e77416 authored by Thomas Huster's avatar Thomas Huster

[21097] add account transactions to invoice, execute stream named query

parent 991b1177
package ch.elexis.core.jpa.entities;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
......@@ -92,7 +91,7 @@ public class Fall extends AbstractEntityWithId
private String versNummer;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fall", cascade = CascadeType.REFRESH)
protected List<Behandlung> consultations = new ArrayList<>();
protected List<Behandlung> consultations;
public String getBetriebsNummer() {
return this.betriebsNummer;
......
package ch.elexis.core.jpa.entities;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
......@@ -37,8 +36,12 @@ import ch.elexis.core.model.InvoiceState;
@NamedQuery(name = "Invoice.number", query = "SELECT i FROM Invoice i WHERE i.deleted = false AND i.number = :number")
@NamedQuery(name = "Invoice.from.to.paid.notempty", query = "SELECT i FROM Invoice i WHERE i.deleted = false "
+ "AND i.invoiceDate >= :from AND i.invoiceDate <= :to AND NOT (i.state = ch.elexis.core.model.InvoiceState.PAID AND i.amount = '0')")
@NamedQuery(name = "Invoice.from.to.paid.notempty.size", query = "SELECT COUNT(i.id) FROM Invoice i WHERE i.deleted = false "
+ "AND i.invoiceDate >= :from AND i.invoiceDate <= :to AND NOT (i.state = ch.elexis.core.model.InvoiceState.PAID AND i.amount = '0')")
@NamedQuery(name = "Invoice.from.to.mandator.paid.notempty", query = "SELECT i FROM Invoice i WHERE i.deleted = false "
+ "AND i.mandator = :mandator AND i.invoiceDate >= :from AND i.invoiceDate <= :to AND NOT (i.state = ch.elexis.core.model.InvoiceState.PAID AND i.amount = '0')")
@NamedQuery(name = "Invoice.from.to.mandator.paid.notempty.size", query = "SELECT COUNT(i.id) FROM Invoice i WHERE i.deleted = false "
+ "AND i.mandator = :mandator AND i.invoiceDate >= :from AND i.invoiceDate <= :to AND NOT (i.state = ch.elexis.core.model.InvoiceState.PAID AND i.amount = '0')")
public class Invoice extends AbstractEntityWithId
implements EntityWithId, EntityWithDeleted, EntityWithExtInfo {
......@@ -91,15 +94,19 @@ public class Invoice extends AbstractEntityWithId
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "rechnungid")
private List<VerrechnetCopy> invoiceBilled = new ArrayList<>();
private List<VerrechnetCopy> invoiceBilled;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "rechnungsid")
private List<Behandlung> encounters = new ArrayList<>();
private List<Behandlung> encounters;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "rechnungsid")
private List<Zahlung> payments = new ArrayList<>();
private List<Zahlung> payments;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "rechnungsid")
private List<AccountTransaction> transactions;
public String getNumber() {
return number;
......@@ -224,4 +231,8 @@ public class Invoice extends AbstractEntityWithId
public List<Zahlung> getPayments(){
return payments;
}
public List<AccountTransaction> getTransactions(){
return transactions;
}
}
......@@ -91,8 +91,7 @@ public class Invoice extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.ent
public List<IEncounter> getEncounters(){
CoreModelServiceHolder.get().refresh(this);
return getEntity().getEncounters().parallelStream().filter(b -> !b.isDeleted())
.map(b -> ModelUtil.getAdapter(b, IEncounter.class, true))
.collect(Collectors.toList());
.map(b -> ModelUtil.getAdapter(b, IEncounter.class, true)).collect(Collectors.toList());
}
@Override
......@@ -199,6 +198,14 @@ public class Invoice extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.ent
.map(p -> ModelUtil.getAdapter(p, IPayment.class, true)).collect(Collectors.toList());
}
@Override
public List<IAccountTransaction> getTransactions(){
CoreModelServiceHolder.get().refresh(this);
return getEntity().getTransactions().parallelStream().filter(p -> !p.isDeleted())
.map(p -> ModelUtil.getAdapter(p, IAccountTransaction.class, true))
.collect(Collectors.toList());
}
@Override
public String getRemark(){
return (String) getExtInfo(ch.elexis.core.jpa.entities.Invoice.REMARK);
......
......@@ -712,9 +712,11 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="demandAmount" eType="ecore:EDataType types.ecore#//Money"
changeable="false"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="remark" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="stateDate" eType="ecore:EDataType types.ecore#//LocalDate"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="payments" upperBound="-1"
eType="#//IPayment" changeable="false"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="stateDate" eType="ecore:EDataType types.ecore#//LocalDate"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="transactions" upperBound="-1"
eType="#//IAccountTransaction" changeable="false"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="IStock" abstract="true" interface="true"
eSuperTypes="#//Identifiable #//Deleteable">
......
......@@ -459,8 +459,9 @@
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//IInvoice/payedAmount"/>
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//IInvoice/demandAmount"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//IInvoice/remark"/>
<genFeatures property="Readonly" notify="false" createChild="false" ecoreFeature="ecore:EReference model.ecore#//IInvoice/payments"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//IInvoice/stateDate"/>
<genFeatures property="Readonly" notify="false" createChild="false" ecoreFeature="ecore:EReference model.ecore#//IInvoice/payments"/>
<genFeatures property="Readonly" notify="false" createChild="false" ecoreFeature="ecore:EReference model.ecore#//IInvoice/transactions"/>
<genOperations ecoreOperation="model.ecore#//IInvoice/addTrace">
<genParameters ecoreParameter="model.ecore#//IInvoice/addTrace/name"/>
<genParameters ecoreParameter="model.ecore#//IInvoice/addTrace/value"/>
......
......@@ -49,7 +49,6 @@ public interface IBillableOptifier<T extends IBillable> {
* is returned. But there is no guarantee that correct validation is performed.
* </p>
* <!-- end-user-doc -->
*
* @model type="ch.elexis.core.types.Result&lt;ch.elexis.core.model.IBilled&gt;"
* @generated
*/
......
......@@ -39,8 +39,9 @@ import java.util.List;
* <li>{@link ch.elexis.core.model.IInvoice#getPayedAmount <em>Payed Amount</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getDemandAmount <em>Demand Amount</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getRemark <em>Remark</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getPayments <em>Payments</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getStateDate <em>State Date</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getPayments <em>Payments</em>}</li>
* <li>{@link ch.elexis.core.model.IInvoice#getTransactions <em>Transactions</em>}</li>
* </ul>
*
* @see ch.elexis.core.model.ModelPackage#getIInvoice()
......@@ -365,6 +366,18 @@ public interface IInvoice extends Identifiable, Deleteable, WithExtInfo {
*/
List<IPayment> getPayments();
/**
* Returns the value of the '<em><b>Transactions</b></em>' reference list.
* The list contents are of type {@link ch.elexis.core.model.IAccountTransaction}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the value of the '<em>Transactions</em>' reference list.
* @see ch.elexis.core.model.ModelPackage#getIInvoice_Transactions()
* @model changeable="false"
* @generated
*/
List<IAccountTransaction> getTransactions();
/**
* Returns the value of the '<em><b>State Date</b></em>' attribute.
* <!-- begin-user-doc -->
......
......@@ -4925,6 +4925,15 @@ public interface ModelPackage extends EPackage {
*/
int IINVOICE__REMARK = IDENTIFIABLE_FEATURE_COUNT + 14;
/**
* The feature id for the '<em><b>State Date</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int IINVOICE__STATE_DATE = IDENTIFIABLE_FEATURE_COUNT + 15;
/**
* The feature id for the '<em><b>Payments</b></em>' reference list.
* <!-- begin-user-doc -->
......@@ -4932,16 +4941,16 @@ public interface ModelPackage extends EPackage {
* @generated
* @ordered
*/
int IINVOICE__PAYMENTS = IDENTIFIABLE_FEATURE_COUNT + 15;
int IINVOICE__PAYMENTS = IDENTIFIABLE_FEATURE_COUNT + 16;
/**
* The feature id for the '<em><b>State Date</b></em>' attribute.
* The feature id for the '<em><b>Transactions</b></em>' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int IINVOICE__STATE_DATE = IDENTIFIABLE_FEATURE_COUNT + 16;
int IINVOICE__TRANSACTIONS = IDENTIFIABLE_FEATURE_COUNT + 17;
/**
* The number of structural features of the '<em>IInvoice</em>' class.
......@@ -4950,7 +4959,7 @@ public interface ModelPackage extends EPackage {
* @generated
* @ordered
*/
int IINVOICE_FEATURE_COUNT = IDENTIFIABLE_FEATURE_COUNT + 17;
int IINVOICE_FEATURE_COUNT = IDENTIFIABLE_FEATURE_COUNT + 18;
/**
* The meta object id for the '{@link ch.elexis.core.model.IStock <em>IStock</em>}' class.
......@@ -9585,6 +9594,17 @@ public interface ModelPackage extends EPackage {
*/
EReference getIInvoice_Payments();
/**
* Returns the meta object for the reference list '{@link ch.elexis.core.model.IInvoice#getTransactions <em>Transactions</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the reference list '<em>Transactions</em>'.
* @see ch.elexis.core.model.IInvoice#getTransactions()
* @see #getIInvoice()
* @generated
*/
EReference getIInvoice_Transactions();
/**
* Returns the meta object for the attribute '{@link ch.elexis.core.model.IInvoice#getStateDate <em>State Date</em>}'.
* <!-- begin-user-doc -->
......@@ -13287,6 +13307,14 @@ public interface ModelPackage extends EPackage {
*/
EReference IINVOICE__PAYMENTS = eINSTANCE.getIInvoice_Payments();
/**
* The meta object literal for the '<em><b>Transactions</b></em>' reference list feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference IINVOICE__TRANSACTIONS = eINSTANCE.getIInvoice_Transactions();
/**
* The meta object literal for the '<em><b>State Date</b></em>' attribute feature.
* <!-- begin-user-doc -->
......
......@@ -3281,7 +3281,17 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
*/
@Override
public EReference getIInvoice_Payments() {
return (EReference)iInvoiceEClass.getEStructuralFeatures().get(14);
return (EReference)iInvoiceEClass.getEStructuralFeatures().get(15);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EReference getIInvoice_Transactions() {
return (EReference)iInvoiceEClass.getEStructuralFeatures().get(16);
}
/**
......@@ -3291,7 +3301,7 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
*/
@Override
public EAttribute getIInvoice_StateDate() {
return (EAttribute)iInvoiceEClass.getEStructuralFeatures().get(15);
return (EAttribute)iInvoiceEClass.getEStructuralFeatures().get(14);
}
/**
......@@ -4963,8 +4973,9 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
createEAttribute(iInvoiceEClass, IINVOICE__PAYED_AMOUNT);
createEAttribute(iInvoiceEClass, IINVOICE__DEMAND_AMOUNT);
createEAttribute(iInvoiceEClass, IINVOICE__REMARK);
createEReference(iInvoiceEClass, IINVOICE__PAYMENTS);
createEAttribute(iInvoiceEClass, IINVOICE__STATE_DATE);
createEReference(iInvoiceEClass, IINVOICE__PAYMENTS);
createEReference(iInvoiceEClass, IINVOICE__TRANSACTIONS);
iStockEClass = createEClass(ISTOCK);
createEAttribute(iStockEClass, ISTOCK__CODE);
......@@ -5796,8 +5807,9 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
initEAttribute(getIInvoice_PayedAmount(), theTypesPackage.getMoney(), "payedAmount", null, 0, 1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getIInvoice_DemandAmount(), theTypesPackage.getMoney(), "demandAmount", null, 0, 1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getIInvoice_Remark(), ecorePackage.getEString(), "remark", null, 0, 1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getIInvoice_Payments(), this.getIPayment(), null, "payments", null, 0, -1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getIInvoice_StateDate(), theTypesPackage.getLocalDate(), "stateDate", null, 0, 1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getIInvoice_Payments(), this.getIPayment(), null, "payments", null, 0, -1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getIInvoice_Transactions(), this.getIAccountTransaction(), null, "transactions", null, 0, -1, IInvoice.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
op = addEOperation(iInvoiceEClass, null, "addTrace", 0, 1, IS_UNIQUE, IS_ORDERED);
addEParameter(op, ecorePackage.getEString(), "name", 0, 1, IS_UNIQUE, IS_ORDERED);
......
......@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
public interface INamedQuery<R> {
/**
......@@ -16,8 +17,17 @@ public interface INamedQuery<R> {
public List<R> executeWithParameters(Map<String, Object> parameters);
/**
* Execute the query and return a single result. If more than one result is
* available, a warning is logged, and the first result is returned.
* Execute the query with the provided parameters and return a stream with the resulting
* objects.
*
* @param parameters
* @return
*/
public Stream<R> executeAsStreamWithParameters(Map<String, Object> parameters);
/**
* Execute the query and return a single result. If more than one result is available, a warning
* is logged, and the first result is returned.
*
* @param parameters
* @return
......
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