1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.purap.fixture;
20
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23
24 import org.kuali.kfs.module.purap.PurapConstants;
25 import org.kuali.kfs.module.purap.util.PurApDateFormatUtils;
26
27 public class ElectronicInvoiceHelperServiceFixture {
28
29 private static String vendorDUNSNumber;
30 private static String poNumber;
31 private static String invoiceDate;
32 private static String itemQty;
33
34 public static String getCorruptedCXML(String vendorDUNS,String poNbr){
35 vendorDUNSNumber = vendorDUNS;
36 poNumber = poNbr;
37
38 return getXMLChunk().concat("TestForCorruptedXML");
39 }
40
41 public static String getCXMLForPaymentDocCreation(String vendorDuns,String poNbr){
42 vendorDUNSNumber = vendorDuns;
43 poNumber = poNbr;
44 itemQty = "1";
45 return getXMLChunk();
46 }
47
48 public static String getCXMLForRejectDocCreation(String vendorDUNS,String poNbr){
49 vendorDUNSNumber = vendorDUNS;
50 poNumber = poNbr;
51 itemQty = "100";
52 return getXMLChunk();
53 }
54
55 private static String getXMLChunk(){
56
57 StringBuffer xmlChunk = new StringBuffer();
58
59 xmlChunk.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
60 xmlChunk.append("<!DOCTYPE cXML SYSTEM \"http://xml.cxml.org/schemas/cXML/1.2.009/InvoiceDetail.dtd\">\n");
61 xmlChunk.append("<cXML payloadID=\"irrelevant\" xml:lang=\"en-US\" timestamp=").
62 append(getCXMLDate(true)).append("\n").
63 append(" version=\"1.2.014\">");
64
65 xmlChunk.append(getHeaderXMLChunk());
66 xmlChunk.append(getRequestXMLChunk());
67
68 xmlChunk.append("</cXML>");
69
70 return xmlChunk.toString();
71 }
72
73 private static StringBuffer getHeaderXMLChunk(){
74
75 StringBuffer header = new StringBuffer();
76
77 header.append("<Header>");
78
79 header.append("<From>");
80 header.append("<Credential domain=\"DUNS\">");
81 header.append("<Identity>" + vendorDUNSNumber + "</Identity>");
82 header.append("</Credential>");
83 header.append("</From>");
84
85 header.append("<To>");
86 header.append("<Credential domain=\"DUNS\">");
87 header.append("<Identity>IU</Identity>");
88 header.append("</Credential>");
89 header.append("</To>");
90
91 header.append("<Sender>");
92 header.append("<Credential domain=\"DUNS\">");
93 header.append("<Identity>" + vendorDUNSNumber + "</Identity>");
94 header.append("<SharedSecret>INDIANA</SharedSecret>");
95 header.append("</Credential>");
96 header.append("<UserAgent/>");
97 header.append("</Sender>");
98
99 header.append("</Header>");
100
101 return header;
102 }
103
104 private static StringBuffer getRequestXMLChunk(){
105
106 StringBuffer request = new StringBuffer();
107
108 request.append("<Request deploymentMode=\"production\">");
109 request.append("<InvoiceDetailRequest>");
110 request.append("<InvoiceDetailRequestHeader invoiceID=\"LDR3496\" purpose=\"standard\" invoiceDate=" + getCXMLDate(true) +">");
111 request.append("<InvoiceDetailHeaderIndicator/>");
112 request.append("<InvoiceDetailLineIndicator/>");
113 request.append("<InvoicePartner>");
114 request.append("<Contact role=\"billTo\">");
115 request.append("<Name xml:lang=\"en\">INDIANA UNIVERSITY-SOUTH BEND LRC</Name>");
116 request.append("<PostalAddress>");
117 request.append("<DeliverTo/>");
118 request.append("<Street>PO BOX 7111</Street><City>SOUTH BEND</City><State>IN</State><PostalCode>466347111</PostalCode>");
119 request.append("<Country isoCountryCode=\"US\">US</Country>");
120 request.append("</PostalAddress>");
121 request.append("</Contact>");
122 request.append("</InvoicePartner>");
123 request.append("<InvoicePartner>");
124 request.append("<Contact role=\"remitTo\" addressID=\"2088891\">");
125 request.append("<Name xml:lang=\"en\">CDW Government, Inc.</Name>");
126 request.append("</Contact>");
127 request.append("</InvoicePartner>");
128 request.append("<InvoiceDetailShipping>");
129 request.append("<Contact role=\"shipFrom\">");
130 request.append("<Name xml:lang=\"en\">CDW Government, Inc.</Name>");
131 request.append("<PostalAddress>");
132 request.append("<DeliverTo/><Street>230 North Milwaukee Avenue</Street><City>Vernon Hills</City><State>IL</State><PostalCode>60061</PostalCode>");
133 request.append("<Country isoCountryCode=\"US\">US</Country>");
134
135 request.append("</PostalAddress></Contact>");
136 request.append("<Contact role=\"shipTo\">");
137 request.append("<Name xml:lang=\"en\">INDIANA UNIVERSITY SOUTH BEND</Name>");
138 request.append("<PostalAddress>");
139 request.append("<DeliverTo/>");
140 request.append("<Street>1825 NORTHSIDE BLVD RM #NS075A</Street><City>SOUTH BEND</City><State>IN</State><PostalCode>466151501</PostalCode>");
141 request.append("<Country isoCountryCode=\"US\">US</Country>");
142
143 request.append("</PostalAddress></Contact></InvoiceDetailShipping>");
144 request.append("<InvoiceDetailPaymentTerm payInNumberOfDays=\"30\" percentageRate=\"0\"/>");
145 request.append("</InvoiceDetailRequestHeader>");
146
147 request.append(getInvoiceOrderXMLChunk());
148 request.append(getInvoiceSummaryXMLChunk());
149
150 request.append("</InvoiceDetailRequest>");
151 request.append("</Request>");
152
153 return request;
154
155 }
156
157 public static StringBuffer getInvoiceOrderXMLChunk(){
158
159 StringBuffer order = new StringBuffer();
160
161 order.append("<InvoiceDetailOrder>");
162 order.append("<InvoiceDetailOrderInfo>");
163 order.append("<OrderReference orderID=\"" + poNumber + "\" orderDate=" + getCXMLDate(false) + "/>");
164 order.append("</InvoiceDetailOrderInfo>");
165 order.append("<InvoiceDetailItem invoiceLineNumber=\"1\" quantity=\"" + itemQty + "\">");
166 order.append("<UnitOfMeasure>BG</UnitOfMeasure>");
167 order.append("<UnitPrice><Money currency=\"USD\">10.00</Money></UnitPrice>");
168 order.append("<InvoiceDetailItemReference lineNumber=\"1\">");
169 order.append("<ItemID><SupplierPartID>1212</SupplierPartID></ItemID>");
170 order.append("<Description xml:lang=\"en\">test</Description><ManufacturerPartID/><ManufacturerName/></InvoiceDetailItemReference>");
171 order.append("<SubtotalAmount><Money currency=\"USD\">10.00</Money></SubtotalAmount>");
172 order.append("</InvoiceDetailItem>");
173 order.append("</InvoiceDetailOrder>");
174
175 return order;
176 }
177
178 public static StringBuffer getInvoiceSummaryXMLChunk(){
179
180 StringBuffer summary = new StringBuffer();
181
182 summary.append("<InvoiceDetailSummary>");
183 summary.append("<SubtotalAmount><Money currency=\"USD\">10</Money></SubtotalAmount>");
184 summary.append("<Tax>");
185 summary.append("<Money currency=\"USD\">0</Money>");
186 summary.append("<Description xml:lang=\"en\">TOTAL TAX</Description>");
187 summary.append("<TaxDetail category=\"sales\" percentageRate=\"0\" purpose=\"tax\">");
188 summary.append("<TaxAmount><Money currency=\"USD\">0.0</Money></TaxAmount>");
189 summary.append("<Description xml:lang=\"en\">Item State and Local Tax</Description>");
190 summary.append("</TaxDetail></Tax>");
191 summary.append("<SpecialHandlingAmount><Money currency=\"USD\">0.00</Money></SpecialHandlingAmount>\n");
192 summary.append("<ShippingAmount><Money currency=\"USD\">0.00</Money></ShippingAmount>");
193 summary.append("<InvoiceDetailDiscount><Money currency=\"USD\">0.00</Money></InvoiceDetailDiscount>");
194
195 summary.append("<NetAmount><Money currency=\"USD\">10.00</Money></NetAmount>");
196 summary.append("<DepositAmount><Money currency=\"USD\">2.00</Money></DepositAmount>");
197 summary.append("<DueAmount><Money currency=\"USD\">10.00</Money></DueAmount>");
198 summary.append("</InvoiceDetailSummary>");
199
200 return summary;
201 }
202
203 private static String getCXMLDate(boolean includeTime){
204
205 StringBuffer dateString = new StringBuffer();
206
207 Date d = new Date();
208 SimpleDateFormat date = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_DATE_FORMAT);
209 SimpleDateFormat time = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.CXML_SIMPLE_TIME_FORMAT);
210
211 dateString.append("\"" + date.format(d)).append("T");
212 if (includeTime){
213 dateString.append(time.format(d)).append("-05:00");
214 }
215
216 dateString.append("\"");
217
218 return dateString.toString();
219
220 }
221 }