BrightSide Workbench Full Report + Source Code
BillLineTypeListbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.linetype;
20 
21 import java.util.Collection;
22 import java.util.Iterator;
23 import org.turro.financials.db.FinancialsPU;
24 import org.turro.financials.entity.Contract;
25 import org.turro.financials.entity.ContractPreference;
26 import org.turro.financials.entity.Document;
27 import org.turro.financials.entity.LineType;
28 import org.turro.jpa.Dao;
29 
35 
36  public void setData(Contract contract, long lineTypeId, long contractPreferenceId) {
37  if(contract != null) {
38  Document document = new BillDocument(contract);
39  Collection<LineType> types = document.getLineTypes();
40  Iterator<LineType> it = types.iterator();
41  while(it.hasNext()) {
42  long id = it.next().getId();
43  if(!(id == 108L || id == 4L)) {
44  it.remove();
45  }
46  }
47  updateCollection(types);
48  Dao dao = new FinancialsPU();
49  LineType lt = dao.find(LineType.class, lineTypeId == 0L ? 4L : lineTypeId);
50  if(lt != null) {
51  lt.setContractPreference(contractPreferenceId == 0L ?
52  document.getDefaultContractPreference() :
53  dao.find(ContractPreference.class, contractPreferenceId));
54  setObjectValue(lt);
55  }
56  }
57  }
58 
59 }
ContractPreference getDefaultContractPreference()
Definition: Document.java:429
Collection< LineType > getLineTypes()
Definition: Document.java:734
void setContractPreference(ContractPreference contractPreference)
Definition: LineType.java:81
void setData(Contract contract, long lineTypeId, long contractPreferenceId)