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: package org.kuali.module.pdp.xml;
017:
018: import java.io.Serializable;
019: import java.math.BigDecimal;
020: import java.sql.Timestamp;
021: import java.text.ParseException;
022: import java.text.SimpleDateFormat;
023: import java.util.ArrayList;
024: import java.util.Date;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Locale;
028:
029: import org.kuali.module.pdp.bo.PaymentDetail;
030:
031: public class XmlDetail implements Serializable {
032: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
033: .getLogger(XmlDetail.class);
034:
035: private String source_doc_nbr = null;
036: private String invoice_nbr = null;
037: private String po_nbr = null;
038: private String req_nbr = null;
039: private String org_doc_nbr = null;
040: private String fdoc_typ_cd = null;
041: private Date invoice_date = null;
042: private BigDecimal orig_invoice_amt = null;
043: private BigDecimal net_payment_amt = null;
044: private BigDecimal invoice_tot_discount_amt = null;
045: private BigDecimal invoice_tot_ship_amt = null;
046: private BigDecimal invoice_tot_other_debits = null;
047: private BigDecimal invoice_tot_other_credits = null;
048: private List accounting;
049: private List payment_text;
050:
051: public XmlDetail() {
052: accounting = new ArrayList();
053: payment_text = new ArrayList();
054: }
055:
056: public void setField(String name, String value) {
057: // Don't need to set an empty value
058: if ((value == null) || (value.length() == 0)) {
059: return;
060: }
061:
062: if ("source_doc_nbr".equals(name)) {
063: setSource_doc_nbr(value);
064: } else if ("invoice_nbr".equals(name)) {
065: setInvoice_nbr(value);
066: } else if ("po_nbr".equals(name)) {
067: setPo_nbr(value);
068: } else if ("req_nbr".equals(name)) {
069: setReq_nbr(value);
070: } else if ("org_doc_nbr".equals(name)) {
071: setOrg_doc_nbr(value);
072: } else if ("fdoc_typ_cd".equals(name)) {
073: setFdoc_typ_cd(value);
074: } else if ("invoice_date".equals(name)) {
075: try {
076: SimpleDateFormat sdf = new SimpleDateFormat(
077: "yyyy-MM-dd", Locale.US);
078: setInvoice_date(sdf.parse(value));
079: } catch (ParseException e) {
080: // Don't know what to do
081: }
082: } else if ("orig_invoice_amt".equals(name)) {
083: setOrig_invoice_amt(new BigDecimal(value.trim()));
084: } else if ("net_payment_amt".equals(name)) {
085: setNet_payment_amt(new BigDecimal(value.trim()));
086: } else if ("invoice_tot_discount_amt".equals(name)) {
087: setInvoice_tot_discount_amt(new BigDecimal(value.trim()));
088: } else if ("invoice_tot_ship_amt".equals(name)) {
089: setInvoice_tot_ship_amt(new BigDecimal(value.trim()));
090: } else if ("invoice_tot_other_debits".equals(name)) {
091: setInvoice_tot_other_debits(new BigDecimal(value.trim()));
092: } else if ("invoice_tot_other_credits".equals(name)) {
093: setInvoice_tot_other_credits(new BigDecimal(value.trim()));
094: }
095: }
096:
097: public void updateAmounts() {
098: BigDecimal zero = new BigDecimal(0.00);
099:
100: if (invoice_tot_discount_amt == null) {
101: setInvoice_tot_discount_amt(zero);
102: }
103: if (invoice_tot_ship_amt == null) {
104: setInvoice_tot_ship_amt(zero);
105: }
106: if (invoice_tot_other_debits == null) {
107: setInvoice_tot_other_debits(zero);
108: }
109: if (invoice_tot_other_credits == null) {
110: setInvoice_tot_other_credits(zero);
111: }
112:
113: // Update the total payment amount with the amount
114: // from the accounts if it's not there
115: if (getNet_payment_amt() == null) {
116: setNet_payment_amt(this .getAccountTotal());
117: }
118:
119: if (orig_invoice_amt == null) {
120: BigDecimal amt = net_payment_amt;
121: amt = amt.add(invoice_tot_discount_amt);
122: amt = amt.subtract(invoice_tot_ship_amt);
123: amt = amt.subtract(invoice_tot_other_debits);
124: amt = amt.add(invoice_tot_other_credits);
125: setOrig_invoice_amt(amt);
126: }
127: }
128:
129: public boolean isDetailAmountProvided() {
130: return !((orig_invoice_amt == null)
131: && (invoice_tot_discount_amt == null)
132: && (invoice_tot_ship_amt == null)
133: && (invoice_tot_other_debits == null) && (invoice_tot_other_credits == null));
134: }
135:
136: public BigDecimal getCalculatedPaymentAmount() {
137: BigDecimal zero = new BigDecimal(0.00);
138: BigDecimal orig_invoice_amt = getOrig_invoice_amt() == null ? zero
139: : getOrig_invoice_amt();
140: BigDecimal invoice_tot_discount_amt = getInvoice_tot_discount_amt() == null ? zero
141: : getInvoice_tot_discount_amt();
142: BigDecimal invoice_tot_ship_amt = getInvoice_tot_ship_amt() == null ? zero
143: : getInvoice_tot_ship_amt();
144: BigDecimal invoice_tot_other_debits = getInvoice_tot_other_debits() == null ? zero
145: : getInvoice_tot_other_debits();
146: BigDecimal invoice_tot_other_credits = getInvoice_tot_other_credits() == null ? zero
147: : getInvoice_tot_other_credits();
148:
149: BigDecimal t = orig_invoice_amt
150: .subtract(invoice_tot_discount_amt);
151: t = t.add(invoice_tot_ship_amt);
152: t = t.add(invoice_tot_other_debits);
153: t = t.subtract(invoice_tot_other_credits);
154:
155: return t;
156: }
157:
158: public BigDecimal getAccountTotal() {
159: BigDecimal acctTotal = new BigDecimal(0.00);
160:
161: Iterator i = accounting.iterator();
162: while (i.hasNext()) {
163: XmlAccounting acct = (XmlAccounting) i.next();
164: if (acct.getAmount() != null) {
165: acctTotal = acctTotal.add(acct.getAmount());
166: }
167: }
168:
169: return acctTotal;
170: }
171:
172: public PaymentDetail getPaymentDetail() {
173: PaymentDetail d = new PaymentDetail();
174:
175: d.setCustPaymentDocNbr(source_doc_nbr);
176: d.setInvoiceNbr(invoice_nbr);
177: d.setPurchaseOrderNbr(po_nbr);
178: d.setRequisitionNbr(req_nbr);
179: d.setOrganizationDocNbr(org_doc_nbr);
180: d.setFinancialDocumentTypeCode(fdoc_typ_cd);
181: if (invoice_date != null) {
182: d.setInvoiceDate(new Timestamp(invoice_date.getTime()));
183: } else {
184: d.setInvoiceDate(null);
185: }
186: d.setOrigInvoiceAmount(orig_invoice_amt);
187: d.setNetPaymentAmount(net_payment_amt);
188: d.setInvTotDiscountAmount(invoice_tot_discount_amt);
189: d.setInvTotShipAmount(invoice_tot_ship_amt);
190: d.setInvTotOtherCreditAmount(invoice_tot_other_credits);
191: d.setInvTotOtherDebitAmount(invoice_tot_other_debits);
192: d.setPrimaryCancelledPayment(Boolean.FALSE);
193: return d;
194: }
195:
196: public Date getInvoice_date() {
197: return invoice_date;
198: }
199:
200: public void setInvoice_date(Date invoice_date) {
201: this .invoice_date = invoice_date;
202: }
203:
204: /**
205: * @return Returns the accounting.
206: */
207: public List getAccounting() {
208: return accounting;
209: }
210:
211: public void addAccounting(XmlAccounting a) {
212: accounting.add(a);
213: }
214:
215: /**
216: * @param accounting The accounting to set.
217: */
218: public void setAccounting(List accounting) {
219: this .accounting = accounting;
220: }
221:
222: /**
223: * @return Returns the invoice_nbr.
224: */
225: public String getInvoice_nbr() {
226: return invoice_nbr;
227: }
228:
229: /**
230: * @param invoice_nbr The invoice_nbr to set.
231: */
232: public void setInvoice_nbr(String invoice_nbr) {
233: this .invoice_nbr = invoice_nbr;
234: }
235:
236: /**
237: * @return Returns the invoice_tot_discount_amt.
238: */
239: public BigDecimal getInvoice_tot_discount_amt() {
240: return invoice_tot_discount_amt;
241: }
242:
243: /**
244: * @param invoice_tot_discount_amt The invoice_tot_discount_amt to set.
245: */
246: public void setInvoice_tot_discount_amt(
247: BigDecimal invoice_tot_discount_amt) {
248: this .invoice_tot_discount_amt = invoice_tot_discount_amt;
249: }
250:
251: /**
252: * @return Returns the invoice_tot_other_credits.
253: */
254: public BigDecimal getInvoice_tot_other_credits() {
255: return invoice_tot_other_credits;
256: }
257:
258: /**
259: * @param invoice_tot_other_credits The invoice_tot_other_credits to set.
260: */
261: public void setInvoice_tot_other_credits(
262: BigDecimal invoice_tot_other_credits) {
263: this .invoice_tot_other_credits = invoice_tot_other_credits;
264: }
265:
266: /**
267: * @return Returns the invoice_tot_other_debits.
268: */
269: public BigDecimal getInvoice_tot_other_debits() {
270: return invoice_tot_other_debits;
271: }
272:
273: /**
274: * @param invoice_tot_other_debits The invoice_tot_other_debits to set.
275: */
276: public void setInvoice_tot_other_debits(
277: BigDecimal invoice_tot_other_debits) {
278: this .invoice_tot_other_debits = invoice_tot_other_debits;
279: }
280:
281: /**
282: * @return Returns the invoice_tot_ship_amt.
283: */
284: public BigDecimal getInvoice_tot_ship_amt() {
285: return invoice_tot_ship_amt;
286: }
287:
288: /**
289: * @param invoice_tot_ship_amt The invoice_tot_ship_amt to set.
290: */
291: public void setInvoice_tot_ship_amt(BigDecimal invoice_tot_ship_amt) {
292: this .invoice_tot_ship_amt = invoice_tot_ship_amt;
293: }
294:
295: /**
296: * @return Returns the net_payment_amt.
297: */
298: public BigDecimal getNet_payment_amt() {
299: return net_payment_amt;
300: }
301:
302: /**
303: * @param net_payment_amt The net_payment_amt to set.
304: */
305: public void setNet_payment_amt(BigDecimal net_payment_amt) {
306: this .net_payment_amt = net_payment_amt;
307: }
308:
309: /**
310: * @return Returns the org_doc_nbr.
311: */
312: public String getOrg_doc_nbr() {
313: return org_doc_nbr;
314: }
315:
316: /**
317: * @param org_doc_nbr The org_doc_nbr to set.
318: */
319: public void setOrg_doc_nbr(String org_doc_nbr) {
320: this .org_doc_nbr = org_doc_nbr;
321: }
322:
323: /**
324: * @return Returns the fdoc_typ_cd.
325: */
326: public String getFdoc_typ_cd() {
327: return fdoc_typ_cd;
328: }
329:
330: /**
331: * @param fdoc_typ_cd The fdoc_typ_cd to set.
332: */
333: public void setFdoc_typ_cd(String fdoc_typ_cd) {
334: this .fdoc_typ_cd = fdoc_typ_cd;
335: }
336:
337: /**
338: * @return Returns the orig_invoice_amt.
339: */
340: public BigDecimal getOrig_invoice_amt() {
341: return orig_invoice_amt;
342: }
343:
344: /**
345: * @param orig_invoice_amt The orig_invoice_amt to set.
346: */
347: public void setOrig_invoice_amt(BigDecimal orig_invoice_amt) {
348: this .orig_invoice_amt = orig_invoice_amt;
349: }
350:
351: /**
352: * @return Returns the payment_text.
353: */
354: public List getPayment_text() {
355: return payment_text;
356: }
357:
358: public void addPayment_text(String text) {
359: payment_text.add(text);
360: }
361:
362: /**
363: * @param payment_text The payment_text to set.
364: */
365: public void setPayment_text(List payment_text) {
366: this .payment_text = payment_text;
367: }
368:
369: /**
370: * @return Returns the po_nbr.
371: */
372: public String getPo_nbr() {
373: return po_nbr;
374: }
375:
376: /**
377: * @param po_nbr The po_nbr to set.
378: */
379: public void setPo_nbr(String po_nbr) {
380: this .po_nbr = po_nbr;
381: }
382:
383: /**
384: * @return Returns the req_nbr.
385: */
386: public String getReq_nbr() {
387: return req_nbr;
388: }
389:
390: /**
391: * @param req_nbr The req_nbr to set.
392: */
393: public void setReq_nbr(String req_nbr) {
394: this .req_nbr = req_nbr;
395: }
396:
397: /**
398: * @return Returns the source_doc_nbr.
399: */
400: public String getSource_doc_nbr() {
401: return source_doc_nbr;
402: }
403:
404: /**
405: * @param source_doc_nbr The source_doc_nbr to set.
406: */
407: public void setSource_doc_nbr(String source_doc_nbr) {
408: this.source_doc_nbr = source_doc_nbr;
409: }
410: }
|