001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * Created on Jul 12, 2004
018: *
019: */
020: package org.kuali.module.pdp.bo;
021:
022: import java.io.Serializable;
023: import java.math.BigDecimal;
024: import java.sql.Timestamp;
025: import java.util.ArrayList;
026: import java.util.Calendar;
027: import java.util.Date;
028: import java.util.List;
029:
030: import org.apache.commons.lang.builder.EqualsBuilder;
031: import org.apache.commons.lang.builder.HashCodeBuilder;
032: import org.apache.commons.lang.builder.ToStringBuilder;
033: import org.apache.ojb.broker.PersistenceBroker;
034: import org.apache.ojb.broker.PersistenceBrokerAware;
035: import org.apache.ojb.broker.PersistenceBrokerException;
036:
037: /**
038: * @author delyea
039: * @hibernate.class table="PDP.PDP_PMT_DTL_T"
040: */
041:
042: public class PaymentDetail implements Serializable,
043: PersistenceBrokerAware {
044: private static BigDecimal zero = new BigDecimal(0);
045:
046: private Integer id; // PMT_DTL_ID
047: private String invoiceNbr; // INV_NBR
048: private Timestamp invoiceDate; // INV_DT
049: private String purchaseOrderNbr; // PO_NBR
050: private String custPaymentDocNbr; // CUST_PMT_DOC_NBR
051: private String financialDocumentTypeCode; // FDOC_TYP_CD
052: private String requisitionNbr; // REQS_NBR
053: private String organizationDocNbr; // ORG_DOC_NBR
054: private BigDecimal origInvoiceAmount; // ORIG_INV_AMT
055: private BigDecimal netPaymentAmount; // NET_PMT_AMT
056: private BigDecimal invTotDiscountAmount; // INV_TOT_DSCT_AMT
057: private BigDecimal invTotShipAmount; // INV_TOT_SHP_AMT
058: private BigDecimal invTotOtherDebitAmount; // INV_TOT_OTHR_DEBIT_AMT
059: private BigDecimal invTotOtherCreditAmount; // INV_TOT_OTHR_CRDT_AMT
060: private Timestamp lastUpdate; // LST_UPDT_TS
061: private Integer version; // VER_NBR
062: private Boolean primaryCancelledPayment; // PDP_PRM_PMT_CNCL_IND
063: private Timestamp lastDisbursementActionDate;
064:
065: private List accountDetail = new ArrayList();
066: private List notes = new ArrayList();
067:
068: private Integer paymentGroupId;
069: private PaymentGroup paymentGroup;
070:
071: public PaymentDetail() {
072: super ();
073: }
074:
075: private boolean isDetailAmountProvided() {
076: return (origInvoiceAmount != null)
077: || (invTotDiscountAmount != null)
078: || (invTotShipAmount != null)
079: || (invTotOtherDebitAmount != null)
080: || (invTotOtherCreditAmount != null);
081: }
082:
083: public BigDecimal getCalculatedPaymentAmount() {
084: BigDecimal orig_invoice_amt = origInvoiceAmount == null ? zero
085: : origInvoiceAmount;
086: BigDecimal invoice_tot_discount_amt = invTotDiscountAmount == null ? zero
087: : invTotDiscountAmount;
088: BigDecimal invoice_tot_ship_amt = invTotShipAmount == null ? zero
089: : invTotShipAmount;
090: BigDecimal invoice_tot_other_debits = invTotOtherDebitAmount == null ? zero
091: : invTotOtherDebitAmount;
092: BigDecimal invoice_tot_other_credits = invTotOtherCreditAmount == null ? zero
093: : invTotOtherCreditAmount;
094:
095: BigDecimal t = orig_invoice_amt
096: .subtract(invoice_tot_discount_amt);
097: t = t.add(invoice_tot_ship_amt);
098: t = t.add(invoice_tot_other_debits);
099: t = t.subtract(invoice_tot_other_credits);
100:
101: return t;
102: }
103:
104: public boolean isDisbursementActionAllowed() {
105: if (paymentGroup.getDisbursementDate() == null) {
106: if ("EXTR"
107: .equals(paymentGroup.getPaymentStatus().getCode())) {
108: return false;
109: }
110: return true;
111: }
112: Calendar c = Calendar.getInstance();
113: c.setTime(paymentGroup.getDisbursementDate());
114: c.set(Calendar.HOUR, 11);
115: c.set(Calendar.MINUTE, 59);
116: c.set(Calendar.SECOND, 59);
117: c.set(Calendar.MILLISECOND, 59);
118: c.set(Calendar.AM_PM, Calendar.PM);
119: Timestamp disbursementDate = new Timestamp(c.getTimeInMillis());
120: // date is equal to or after lastActionDate Allowed
121: return ((disbursementDate
122: .compareTo(this .lastDisbursementActionDate)) >= 0);
123: }
124:
125: public Timestamp getLastDisbursementActionDate() {
126: return lastDisbursementActionDate;
127: }
128:
129: public void setLastDisbursementActionDate(
130: Timestamp lastDisbursementActionDate) {
131: this .lastDisbursementActionDate = lastDisbursementActionDate;
132: }
133:
134: public Timestamp getInvoiceDate() {
135: return invoiceDate;
136: }
137:
138: public void setInvoiceDate(Timestamp invoiceDate) {
139: this .invoiceDate = invoiceDate;
140: }
141:
142: /**
143: * @hibernate.set name="accountDetail"
144: * @hibernate.collection-key column="pmt_dtl_id"
145: * @hibernate.collection-one-to-many class="edu.iu.uis.pdp.bo.PaymentAccountDetail"
146: */
147: public List getAccountDetail() {
148: return accountDetail;
149: }
150:
151: public void setAccountDetail(List ad) {
152: accountDetail = ad;
153: }
154:
155: public void addAccountDetail(PaymentAccountDetail pad) {
156: pad.setPaymentDetail(this );
157: accountDetail.add(pad);
158: }
159:
160: public void deleteAccountDetail(PaymentAccountDetail pad) {
161: accountDetail.remove(pad);
162: }
163:
164: public List getNotes() {
165: return notes;
166: }
167:
168: public void setNotes(List n) {
169: notes = n;
170: }
171:
172: public void addNote(PaymentNoteText pnt) {
173: pnt.setPaymentDetail(this );
174: notes.add(pnt);
175: }
176:
177: public void deleteNote(PaymentNoteText pnt) {
178: notes.remove(pnt);
179: }
180:
181: /**
182: * @hibernate.id column="PMT_DTL_ID" generator-class="sequence"
183: * @hibernate.generator-param name="sequence" value="PDP.PDP_PMT_DTL_ID_SEQ"
184: * @return
185: */
186: public Integer getId() {
187: return id;
188: }
189:
190: /**
191: * @return
192: * @hibernate.version column="VER_NBR" not-null="true"
193: */
194: public Integer getVersion() {
195: return version;
196: }
197:
198: /**
199: * @return
200: * @hibernate.property column="LST_UPDT_TS" length="7"
201: */
202: public Timestamp getLastUpdate() {
203: return lastUpdate;
204: }
205:
206: /**
207: * @return
208: * @hibernate.property column="CUST_PMT_DOC_NBR" length="9"
209: */
210: public String getCustPaymentDocNbr() {
211: return custPaymentDocNbr;
212: }
213:
214: /**
215: * @return
216: * @hibernate.property column="INV_NBR" length="14"
217: */
218: public String getInvoiceNbr() {
219: return invoiceNbr;
220: }
221:
222: /**
223: * @return
224: * @hibernate.property column="INV_TOT_DSCT_AMT" length="14"
225: */
226: public BigDecimal getInvTotDiscountAmount() {
227: return invTotDiscountAmount;
228: }
229:
230: /**
231: * @return
232: * @hibernate.property column="INV_TOT_OTHR_CRDT_AMT" length="14"
233: */
234: public BigDecimal getInvTotOtherCreditAmount() {
235: return invTotOtherCreditAmount;
236: }
237:
238: /**
239: * @return
240: * @hibernate.property column="INV_TOT_OTHR_DEBIT_AMT" length="14"
241: */
242: public BigDecimal getInvTotOtherDebitAmount() {
243: return invTotOtherDebitAmount;
244: }
245:
246: /**
247: * @return
248: * @hibernate.property column="INV_TOT_SHP_AMT" length="14"
249: */
250: public BigDecimal getInvTotShipAmount() {
251: return invTotShipAmount;
252: }
253:
254: /**
255: * @return
256: * @hibernate.property column="NET_PMT_AMT" length="14"
257: */
258: public BigDecimal getNetPaymentAmount() {
259: return netPaymentAmount;
260: }
261:
262: /**
263: * @return
264: * @hibernate.property column="ORG_DOC_NBR" length="10"
265: */
266: public String getOrganizationDocNbr() {
267: return organizationDocNbr;
268: }
269:
270: /**
271: * @return
272: * @hibernate.property column="ORIG_INV_AMT" length="14"
273: */
274: public BigDecimal getOrigInvoiceAmount() {
275: return origInvoiceAmount;
276: }
277:
278: /**
279: * @return
280: * @hibernate.property column="PO_NBR" length="9"
281: */
282: public String getPurchaseOrderNbr() {
283: return purchaseOrderNbr;
284: }
285:
286: /**
287: * @return
288: * @hibernate.property column="REQS_NBR" length=8"
289: */
290: public String getRequisitionNbr() {
291: return requisitionNbr;
292: }
293:
294: /**
295: * @return Returns the paymentGroup.
296: */
297: public PaymentGroup getPaymentGroup() {
298: return paymentGroup;
299: }
300:
301: /**
302: * @param string
303: */
304: public void setCustPaymentDocNbr(String string) {
305: custPaymentDocNbr = string;
306: }
307:
308: /**
309: * @param integer
310: */
311: public void setId(Integer integer) {
312: id = integer;
313: }
314:
315: /**
316: * @param string
317: */
318: public void setInvoiceNbr(String string) {
319: invoiceNbr = string;
320: }
321:
322: /**
323: * @param decimal
324: */
325: public void setInvTotDiscountAmount(BigDecimal decimal) {
326: invTotDiscountAmount = decimal;
327: }
328:
329: /**
330: * @param decimal
331: */
332: public void setInvTotOtherCreditAmount(BigDecimal decimal) {
333: invTotOtherCreditAmount = decimal;
334: }
335:
336: /**
337: * @param decimal
338: */
339: public void setInvTotOtherDebitAmount(BigDecimal decimal) {
340: invTotOtherDebitAmount = decimal;
341: }
342:
343: /**
344: * @param decimal
345: */
346: public void setInvTotShipAmount(BigDecimal decimal) {
347: invTotShipAmount = decimal;
348: }
349:
350: /**
351: * @param timestamp
352: */
353: public void setLastUpdate(Timestamp timestamp) {
354: lastUpdate = timestamp;
355: }
356:
357: /**
358: * @param decimal
359: */
360: public void setNetPaymentAmount(BigDecimal decimal) {
361: netPaymentAmount = decimal;
362: }
363:
364: /**
365: * @param string
366: */
367: public void setOrganizationDocNbr(String string) {
368: organizationDocNbr = string;
369: }
370:
371: /**
372: * @param decimal
373: */
374: public void setOrigInvoiceAmount(BigDecimal decimal) {
375: origInvoiceAmount = decimal;
376: }
377:
378: /**
379: * @param string
380: */
381: public void setPurchaseOrderNbr(String string) {
382: purchaseOrderNbr = string;
383: }
384:
385: /**
386: * @param string
387: */
388: public void setRequisitionNbr(String string) {
389: requisitionNbr = string;
390: }
391:
392: /**
393: * @param integer
394: */
395: public void setVersion(Integer integer) {
396: version = integer;
397: }
398:
399: /**
400: * @return Returns the financialDocumentTypeCode.
401: */
402: public String getFinancialDocumentTypeCode() {
403: return financialDocumentTypeCode;
404: }
405:
406: /**
407: * @param financialDocumentTypeCode The financialDocumentTypeCode to set.
408: */
409: public void setFinancialDocumentTypeCode(
410: String financialDocumentTypeCode) {
411: this .financialDocumentTypeCode = financialDocumentTypeCode;
412: }
413:
414: /**
415: * @return Returns the primaryCancelledPayment.
416: */
417: public Boolean getPrimaryCancelledPayment() {
418: return primaryCancelledPayment;
419: }
420:
421: /**
422: * @param primaryCancelledPayment The primaryCancelledPayment to set.
423: */
424: public void setPrimaryCancelledPayment(
425: Boolean primaryCancelledPayment) {
426: this .primaryCancelledPayment = primaryCancelledPayment;
427: }
428:
429: /**
430: * @param paymentGroup The paymentGroup to set.
431: */
432: public void setPaymentGroup(PaymentGroup paymentGroup) {
433: this .paymentGroup = paymentGroup;
434: }
435:
436: public boolean equals(Object obj) {
437: if (!(obj instanceof PaymentDetail)) {
438: return false;
439: }
440: PaymentDetail o = (PaymentDetail) obj;
441: return new EqualsBuilder().append(id, o.getId()).isEquals();
442: }
443:
444: public int hashCode() {
445: return new HashCodeBuilder(61, 67).append(id).toHashCode();
446: }
447:
448: public String toString() {
449: return new ToStringBuilder(this ).append("id", this .id)
450: .toString();
451: }
452:
453: public void beforeInsert(PersistenceBroker broker)
454: throws PersistenceBrokerException {
455: lastUpdate = new Timestamp((new Date()).getTime());
456: }
457:
458: public void afterInsert(PersistenceBroker broker)
459: throws PersistenceBrokerException {
460:
461: }
462:
463: public void beforeUpdate(PersistenceBroker broker)
464: throws PersistenceBrokerException {
465: lastUpdate = new Timestamp((new Date()).getTime());
466: }
467:
468: public void afterUpdate(PersistenceBroker broker)
469: throws PersistenceBrokerException {
470:
471: }
472:
473: public void beforeDelete(PersistenceBroker broker)
474: throws PersistenceBrokerException {
475:
476: }
477:
478: public void afterDelete(PersistenceBroker broker)
479: throws PersistenceBrokerException {
480:
481: }
482:
483: public void afterLookup(PersistenceBroker broker)
484: throws PersistenceBrokerException {
485:
486: }
487: }
|