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.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
21  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
22  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
23  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseTransaction;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataValues;
25  import io.github.tonywasher.joceanus.prometheus.sheets.PrometheusSheetEncrypted;
26  
27  /**
28   * SheetDataItem extension for Transaction.
29   *
30   * @author Tony Washer
31   */
32  public final class MoneyWiseSheetTransaction
33          extends PrometheusSheetEncrypted<MoneyWiseTransaction> {
34      /**
35       * NamedArea for Transactions.
36       */
37      private static final String AREA_TRANS = MoneyWiseTransaction.LIST_NAME;
38  
39      /**
40       * Date column.
41       */
42      private static final int COL_DATE = COL_KEYSETID + 1;
43  
44      /**
45       * Pair column.
46       */
47      private static final int COL_DIRECTION = COL_DATE + 1;
48  
49      /**
50       * Account column.
51       */
52      private static final int COL_ACCOUNT = COL_DIRECTION + 1;
53  
54      /**
55       * Partner column.
56       */
57      private static final int COL_PARTNER = COL_ACCOUNT + 1;
58  
59      /**
60       * Amount column.
61       */
62      private static final int COL_AMOUNT = COL_PARTNER + 1;
63  
64      /**
65       * Category column.
66       */
67      private static final int COL_CATEGORY = COL_AMOUNT + 1;
68  
69      /**
70       * Reconciled column.
71       */
72      private static final int COL_RECONCILED = COL_CATEGORY + 1;
73  
74      /**
75       * Constructor for loading a spreadsheet.
76       *
77       * @param pReader the spreadsheet reader
78       */
79      MoneyWiseSheetTransaction(final MoneyWiseReader pReader) {
80          /* Call super constructor */
81          super(pReader, AREA_TRANS);
82  
83          /* Access the Lists */
84          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pReader.getData();
85          setDataList(myData.getTransactions());
86      }
87  
88      /**
89       * Constructor for creating a spreadsheet.
90       *
91       * @param pWriter the spreadsheet writer
92       */
93      MoneyWiseSheetTransaction(final MoneyWiseWriter pWriter) {
94          /* Call super constructor */
95          super(pWriter, AREA_TRANS);
96  
97          /* Access the Transactions list */
98          final MoneyWiseDataSet myData = (MoneyWiseDataSet) pWriter.getData();
99          setDataList(myData.getTransactions());
100     }
101 
102     @Override
103     protected PrometheusDataValues loadSecureValues() throws OceanusException {
104         /* Build data values */
105         final PrometheusDataValues myValues = getRowValues(MoneyWiseTransaction.OBJECT_NAME);
106         myValues.addValue(MoneyWiseBasicResource.MONEYWISEDATA_FIELD_DATE, loadDate(COL_DATE));
107         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_DIRECTION, loadBoolean(COL_DIRECTION));
108         myValues.addValue(MoneyWiseBasicDataType.TRANSCATEGORY, loadInteger(COL_CATEGORY));
109         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_ACCOUNT, loadLong(COL_ACCOUNT));
110         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_PARTNER, loadLong(COL_PARTNER));
111         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_AMOUNT, loadBytes(COL_AMOUNT));
112         myValues.addValue(MoneyWiseBasicResource.TRANSACTION_RECONCILED, loadBoolean(COL_RECONCILED));
113 
114         /* Return the values */
115         return myValues;
116     }
117 
118     @Override
119     protected void insertSecureItem(final MoneyWiseTransaction pItem) throws OceanusException {
120         /* Set the fields */
121         super.insertSecureItem(pItem);
122         writeDate(COL_DATE, pItem.getDate());
123         writeBoolean(COL_DIRECTION, pItem.getDirection().isFrom());
124         writeLong(COL_ACCOUNT, pItem.getAccountId());
125         writeLong(COL_PARTNER, pItem.getPartnerId());
126         writeInteger(COL_CATEGORY, pItem.getCategoryId());
127         writeBoolean(COL_RECONCILED, pItem.isReconciled());
128         writeBytes(COL_AMOUNT, pItem.getAmountBytes());
129     }
130 
131     @Override
132     protected int getLastColumn() {
133         /* Return the last column */
134         return COL_RECONCILED;
135     }
136 }