View Javadoc
1   /*
2    * MoneyWise: Finance Application
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.moneywise.sheets;
18  
19  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransaction;
23  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
26  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetReader;
27  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetWriter;
28  
29  /**
30   * SheetDataItem extension for Transaction.
31   *
32   * @author Tony Washer
33   */
34  public final class MoneyWiseSheetTransaction
35          extends PrometheusSheetEncrypted<MoneyWiseTransaction> {
36      /**
37       * NamedArea for Transactions.
38       */
39      private static final String AREA_TRANS = MoneyWiseTransaction.LIST_NAME;
40  
41      /**
42       * Date column.
43       */
44      private static final int COL_DATE = COL_KEYSETID + 1;
45  
46      /**
47       * Pair column.
48       */
49      private static final int COL_DIRECTION = COL_DATE + 1;
50  
51      /**
52       * Account column.
53       */
54      private static final int COL_ACCOUNT = COL_DIRECTION + 1;
55  
56      /**
57       * Partner column.
58       */
59      private static final int COL_PARTNER = COL_ACCOUNT + 1;
60  
61      /**
62       * Amount column.
63       */
64      private static final int COL_AMOUNT = COL_PARTNER + 1;
65  
66      /**
67       * Category column.
68       */
69      private static final int COL_CATEGORY = COL_AMOUNT + 1;
70  
71      /**
72       * Reconciled column.
73       */
74      private static final int COL_RECONCILED = COL_CATEGORY + 1;
75  
76      /**
77       * Constructor for loading a spreadsheet.
78       *
79       * @param pReader the spreadsheet reader
80       */
81      MoneyWiseSheetTransaction(final PrometheusSheetReader pReader) {
82          /* Call super constructor */
83          super(pReader, AREA_TRANS);
84  
85          /* Access the Lists */
86          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
87          setDataList(myData.getTransactions());
88      }
89  
90      /**
91       * Constructor for creating a spreadsheet.
92       *
93       * @param pWriter the spreadsheet writer
94       */
95      MoneyWiseSheetTransaction(final PrometheusSheetWriter pWriter) {
96          /* Call super constructor */
97          super(pWriter, AREA_TRANS);
98  
99          /* Access the Transactions list */
100         final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
101         setDataList(myData.getTransactions());
102     }
103 
104     @Override
105     protected PrometheusDataValues loadSecureValues() throws OceanusException {
106         /* Build data values */
107         final PrometheusDataValues myValues = getRowValues(MoneyWiseTransaction.OBJECT_NAME);
108         myValues.addValue(MoneyWiseBasicResource.MONEYWISEDATA_FIELD_DATE, loadDate(COL_DATE));
109         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_DIRECTION, loadBoolean(COL_DIRECTION));
110         myValues.addValue(MoneyWiseBasicDataType.TRANSCATEGORY, loadInteger(COL_CATEGORY));
111         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_ACCOUNT, loadLong(COL_ACCOUNT));
112         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_PARTNER, loadLong(COL_PARTNER));
113         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_AMOUNT, loadBytes(COL_AMOUNT));
114         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_RECONCILED, loadBoolean(COL_RECONCILED));
115 
116         /* Return the values */
117         return myValues;
118     }
119 
120     @Override
121     protected void insertSecureItem(final MoneyWiseTransaction pItem) throws OceanusException {
122         /* Set the fields */
123         super.insertSecureItem(pItem);
124         writeDate(COL_DATE, pItem.getDate());
125         writeBoolean(COL_DIRECTION, pItem.getDirection().isFrom());
126         writeLong(COL_ACCOUNT, pItem.getAccountId());
127         writeLong(COL_PARTNER, pItem.getPartnerId());
128         writeInteger(COL_CATEGORY, pItem.getCategoryId());
129         writeBoolean(COL_RECONCILED, pItem.isReconciled());
130         writeBytes(COL_AMOUNT, pItem.getAmountBytes());
131     }
132 
133     @Override
134     protected int getLastColumn() {
135         /* Return the last column */
136         return COL_RECONCILED;
137     }
138 }