1 32 33 package com.knowgate.hipergate; 34 35 import java.math.BigDecimal ; 36 import java.util.ListIterator ; 37 38 import java.sql.SQLException ; 39 import java.sql.Statement ; 40 import java.sql.PreparedStatement ; 41 import java.sql.ResultSet ; 42 import java.sql.Timestamp ; 43 44 import com.knowgate.debug.DebugFile; 45 import com.knowgate.jdc.JDCConnection; 46 import com.knowgate.dataobjs.DB; 47 import com.knowgate.dataobjs.DBBind; 48 import com.knowgate.dataobjs.DBPersist; 49 import com.knowgate.dataobjs.DBSubset; 50 import com.knowgate.misc.Gadgets; 51 import com.knowgate.dataobjs.DBColumn; 52 53 58 59 public class Order extends AbstractOrder { 60 61 private Address oShipAddr; 62 private Address oBillAddr; 63 64 66 69 public Order() { 70 super(DB.k_orders, DB.k_order_lines, DB.gu_order, "Order"); 71 oBillAddr=oShipAddr=null; 72 } 73 74 77 public Order(String sOrderId) { 78 super(DB.k_orders, DB.k_order_lines, DB.gu_order, "Order"); 79 put(DB.gu_order, sOrderId); 80 oBillAddr=oShipAddr=null; 81 } 82 83 89 public Order(JDCConnection oConn, String sOrderId) throws SQLException { 90 super(DB.k_orders, DB.k_order_lines, DB.gu_order, "Order"); 91 load(oConn, new Object []{sOrderId}); 92 } 93 94 96 103 public boolean load(JDCConnection oConn, Object [] PKVals) throws SQLException { 104 boolean bRetVal = super.load(oConn, PKVals); 105 if (bRetVal) { 106 if (!isNull(DB.gu_ship_addr)) 107 oShipAddr = new Address(oConn, getString(DB.gu_ship_addr)); 108 if (!isNull(DB.gu_bill_addr)) 109 oShipAddr = new Address(oConn, getString(DB.gu_bill_addr)); 110 else 111 oShipAddr = null; 112 if (!isNull(DB.gu_bill_addr)) 113 oBillAddr = new Address(oConn, getString(DB.gu_bill_addr)); 114 if (!isNull(DB.gu_ship_addr)) 115 oShipAddr = new Address(oConn, getString(DB.gu_ship_addr)); 116 else 117 oBillAddr = null; 118 } 119 return bRetVal; 120 } 122 124 133 public boolean store(JDCConnection oConn) throws SQLException { 134 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 135 136 if (!AllVals.containsKey(DB.gu_order)) 137 put(DB.gu_order, Gadgets.generateUUID()); 138 else 139 replace(DB.dt_modified, dtNow); 140 141 if (!AllVals.containsKey(DB.pg_order)) 142 put(DB.pg_order, DBBind.nextVal(oConn, "seq_" + DB.k_orders)); 143 144 if (!AllVals.containsKey(DB.id_legal)) { 145 PreparedStatement oStmt; 146 ResultSet oRSet; 147 String sLegalId = null; 148 if (AllVals.containsKey(DB.gu_contact)) { 149 oStmt = oConn.prepareStatement("SELECT "+DB.sn_passport+" FROM "+DB.k_contacts+ " WHERE "+DB.gu_contact+"=?", 150 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 151 oStmt.setString(1, getString(DB.gu_contact)); 152 oRSet = oStmt.executeQuery(); 153 if (oRSet.next()) 154 sLegalId = oRSet.getString(1); 155 oRSet.close(); 156 oStmt.close(); 157 } if ((sLegalId==null) && AllVals.containsKey(DB.gu_company)) { 159 oStmt = oConn.prepareStatement("SELECT "+DB.id_legal+" FROM "+DB.k_companies+ " WHERE "+DB.gu_company+"=?", 160 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 161 oStmt.setString(1, getString(DB.gu_company)); 162 oRSet = oStmt.executeQuery(); 163 if (oRSet.next()) 164 sLegalId = oRSet.getString(1); 165 oRSet.close(); 166 oStmt.close(); 167 } 168 if (sLegalId!=null) put(DB.id_legal, sLegalId); 169 } 171 return super.store(oConn); 172 } 174 176 182 public boolean delete (JDCConnection oConn) throws SQLException { 183 boolean bRetVal; 184 Statement oStmt; 185 186 if (DebugFile.trace) { 187 DebugFile.writeln("Begin Order.delete([Connection])"); 188 DebugFile.incIdent(); 189 } 190 191 oStmt = oConn.createStatement(); 192 193 oStmt.executeUpdate("DELETE FROM " + DB.k_x_orders_invoices + " WHERE " + DB.gu_order + "='" + getString(DB.gu_order) + "'"); 194 195 oStmt.executeUpdate("DELETE FROM " + DB.k_x_orders_despatch + " WHERE " + DB.gu_order + "='" + getString(DB.gu_order) + "'"); 196 197 if (DebugFile.trace) 198 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_order_lines + " WHERE " + DB.gu_order + "='" + getStringNull(DB.gu_order,"") + "')"); 199 200 oStmt.executeUpdate("DELETE FROM " + DB.k_order_lines + " WHERE " + DB.gu_order + "='" + getString(DB.gu_order) + "'"); 201 202 oStmt.close(); 203 204 bRetVal = super.delete(oConn); 205 206 if (DebugFile.trace) { 207 DebugFile.decIdent(); 208 DebugFile.writeln("End Order.delete() : " + String.valueOf(bRetVal)); 209 } 210 211 return bRetVal; 212 } 214 216 223 public OrderLine getLine(JDCConnection oConn, int iPgLine) throws SQLException { 224 OrderLine oRetVal = new OrderLine(); 225 if (oRetVal.load(oConn, new Object []{getStringNull(DB.gu_order,null),new Integer (iPgLine)})) 226 return oRetVal; 227 else 228 return null; 229 } 231 233 243 public DBSubset getLines(JDCConnection oConn) throws SQLException { 244 oLines = new DBSubset(DB.k_order_lines, 245 DB.gu_order + "," + DB.pg_line + "," + 246 DB.gu_product + "," + DB.nm_product + "," + 247 DB.pr_sale + "," + DB.nu_quantity + "," + 248 DB.id_unit + "," + DB.pr_total + "," + 249 DB.pct_tax_rate + "," + DB.is_tax_included + "," + 250 DB.tx_promotion + "," + DB.tx_options + "," + DB.gu_item, 251 DB.gu_order + "=? ORDER BY 2", 10); 252 253 oLines.load(oConn, new Object []{getString(DB.gu_order)}); 254 return oLines; 255 } 257 259 267 public DespatchAdvice createDespatchAdvice(JDCConnection oConn, 268 boolean bIncludePrices) throws SQLException { 269 DespatchAdvice oDispatch = new DespatchAdvice(); 270 ListIterator oIter = oDispatch.getTable(oConn).getColumns().listIterator(); 271 if (bIncludePrices) { 272 while (oIter.hasNext()) { 273 String sKey = ((DBColumn) oIter.next()).getName(); 274 if (!isNull(sKey)) oDispatch.put(sKey, get(sKey)); 275 } } else { 277 while (oIter.hasNext()) { 278 String sKey = (String ) oIter.next(); 279 if (!sKey.equalsIgnoreCase(DB.im_subtotal) && !sKey.equalsIgnoreCase(DB.im_taxes) && 280 !sKey.equalsIgnoreCase(DB.im_shipping) && !sKey.equalsIgnoreCase(DB.im_total) && 281 !sKey.equalsIgnoreCase(DB.im_discount)) { 282 if (!isNull(sKey)) oDispatch.put(sKey, get(sKey)); 283 } 284 } } oDispatch.replace(DB.de_despatch, getString(DB.de_order)); 287 oDispatch.replace(DB.gu_despatch, getString(DB.gu_order)); 288 oDispatch.store(oConn); 289 Statement oStmt = oConn.createStatement(); 290 if (bIncludePrices) { 291 oStmt.executeUpdate("INSERT INTO "+DB.k_despatch_lines+" ("+DB.gu_despatch+ ","+ 292 DB.pg_line+","+DB.gu_product+","+DB.nm_product+","+ 293 DB.pr_sale+","+DB.nu_quantity+","+DB.id_unit+","+ 294 DB.pr_total+ ","+DB.pct_tax_rate+","+DB.is_tax_included+","+ 295 DB.tx_promotion+","+DB.tx_options+","+DB.gu_item+") SELECT "+ 296 DB.gu_order+ ","+ DB.pg_line+","+DB.gu_product+","+ 297 DB.nm_product+","+ DB.pr_sale+","+DB.nu_quantity+","+ 298 DB.id_unit+","+DB.pr_total+ ","+DB.pct_tax_rate+","+ 299 DB.is_tax_included+","+ DB.tx_promotion+","+DB.tx_options+","+ 300 DB.gu_item+" FROM "+DB.k_order_lines+ 301 " WHERE "+DB.gu_order+"='"+getString(DB.gu_order)+"'"); 302 } else { 303 oStmt.executeUpdate("INSERT INTO "+DB.k_despatch_lines+" ("+DB.gu_despatch+","+ 304 DB.pg_line+","+DB.nu_quantity+","+DB.id_unit+","+ 305 DB.nm_product+","+DB.gu_product+","+DB.gu_item+","+ 306 DB.tx_promotion+","+DB.tx_options+") SELECT "+DB.gu_order+","+ 307 DB.pg_line+","+DB.nu_quantity+","+DB.id_unit+","+ 308 DB.nm_product+","+DB.gu_product+","+DB.gu_item+","+ 309 DB.tx_promotion+","+DB.tx_options+" FROM "+DB.k_order_lines+ 310 " WHERE "+DB.gu_order+"='"+getString(DB.gu_order)+"'"); 311 } oStmt.close(); 313 return oDispatch; 314 } 316 318 325 public Invoice createInvoice(JDCConnection oConn) throws SQLException { 326 if (DebugFile.trace) { 327 DebugFile.writeln("Begin Order.createInvoice([Connection])"); 328 DebugFile.incIdent(); 329 } 330 String sSQL; 331 Invoice oInvoice = new Invoice(); 332 ListIterator oIter = oInvoice.getTable(oConn).getColumns().listIterator(); 333 while (oIter.hasNext()) { 334 String sKey = ((DBColumn) oIter.next()).getName(); 335 if (!isNull(sKey)) { 336 if (DebugFile.trace) DebugFile.writeln("Invoice.put("+sKey+","+get(sKey)+")"); 337 oInvoice.put(sKey, get(sKey)); 338 } 339 } oInvoice.replace(DB.gu_invoice, getString(DB.gu_order)); 341 oInvoice.store(oConn); 342 Statement oStmt = oConn.createStatement(); 343 sSQL = "INSERT INTO "+DB.k_invoice_lines+" ("+DB.gu_invoice+ ","+ 344 DB.pg_line+","+DB.gu_product+","+DB.nm_product+","+ 345 DB.pr_sale+","+DB.nu_quantity+","+DB.id_unit+","+ 346 DB.pr_total+ ","+DB.pct_tax_rate+","+DB.is_tax_included+","+ 347 DB.tx_promotion+","+DB.tx_options+","+DB.gu_item+") SELECT "+ 348 DB.gu_order+ ","+ DB.pg_line+","+DB.gu_product+","+ 349 DB.nm_product+","+ DB.pr_sale+","+DB.nu_quantity+","+ 350 DB.id_unit+","+DB.pr_total+ ","+DB.pct_tax_rate+","+ 351 DB.is_tax_included+","+ DB.tx_promotion+","+DB.tx_options+","+ 352 DB.gu_item+" FROM "+DB.k_order_lines+ 353 " WHERE "+DB.gu_order+"='"+getString(DB.gu_order)+"'"; 354 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate("+sSQL+")"); 355 oStmt.executeUpdate(sSQL); 356 oStmt.close(); 357 if (DebugFile.trace) { 358 DebugFile.decIdent(); 359 DebugFile.writeln("End Order.createInvoice() : "+oInvoice.getString(DB.gu_invoice)); 360 } 361 return oInvoice; 362 } 364 366 373 public void activate(JDCConnection oConn, String sOrderId) throws SQLException { 374 PreparedStatement oUpdt; 375 376 if (DebugFile.trace) { 377 DebugFile.writeln("Begin Order.activate([Connection], " + sOrderId + ")"); 378 DebugFile.incIdent(); 379 } 380 381 if (DebugFile.trace) 382 DebugFile.writeln("Connection.prepareStatement(UPDATE " + DB.k_orders + " SET " + DB.bo_active + "=0 WHERE " + DB.gu_workarea + "='" + getStringNull(DB.gu_workarea,"null") + "'"); 383 384 oUpdt = oConn.prepareStatement("UPDATE " + DB.k_orders + " SET " + DB.bo_active + "=0 WHERE " + DB.gu_workarea + "=?"); 385 oUpdt.setString(1, getString(DB.gu_workarea)); 386 oUpdt.executeUpdate(); 387 oUpdt.close(); 388 389 if (DebugFile.trace) 390 DebugFile.writeln("Connection.prepareStatement(UPDATE " + DB.k_orders + " SET " + DB.bo_active + "=1 WHERE " + DB.gu_order + "='" + getStringNull(DB.gu_order,"null") + "'"); 391 392 oUpdt = oConn.prepareStatement("UPDATE " + DB.k_orders + " SET " + DB.bo_active + "=1 WHERE " + DB.gu_order + "=?"); 393 oUpdt.setString(1, getString(DB.gu_order)); 394 oUpdt.executeUpdate(); 395 oUpdt.close(); 396 397 if (DebugFile.trace) { 398 DebugFile.decIdent(); 399 DebugFile.writeln("End Order.activate()"); 400 } 401 } 403 405 412 413 public String toXML() throws IllegalStateException { 414 JDCConnection oConn = null; 415 return toXML (oConn, null); 416 } 417 418 420 427 428 public String toXML(String sIdent, String sDelim) throws IllegalStateException { 429 JDCConnection oConn = null; 430 return toXML (oConn, null); 431 } 432 433 435 442 443 public String toXML(String sIdent) throws IllegalStateException { 444 JDCConnection oConn = null; 445 return toXML (oConn, null); 446 } 447 448 450 556 public String toXML(JDCConnection oConn, String sLocale) throws IllegalStateException { 557 558 if (oLines==null) throw new IllegalStateException ("Order.toXML() Invoice lines not loaded"); 559 if (oBuyer==null) throw new IllegalStateException ("Order.toXML() Buyer party not set"); 560 if (oSeller==null) throw new IllegalStateException ("Order.toXML() Seller party not set"); 561 562 if (DebugFile.trace) { 563 DebugFile.writeln("Begin Order.toXML([Connection]"+sLocale+")"); 564 DebugFile.incIdent(); 565 } 566 567 final int iLineCount = oLines.getRowCount(); 568 StringBuffer oBfr = new StringBuffer (); 569 570 oBfr.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 571 oBfr.append("<Order xmlns:cbc=\"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0\" xmlns:cac=\"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-1.0\" xmlns:cur=\"urn:oasis:names:specification:ubl:schema:xsd:CurrencyCode-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"); 572 oBfr.append(" <cac:BuyersID><![CDATA["+getStringNull(DB.id_legal,oBuyer.getStringNull(DB.id_legal,oBuyer.getStringNull(DB.sn_passport,"")))+"]]></cac:BuyersID>\n"); 574 oBfr.append(" <cac:SellerID><![CDATA["+oSeller.getStringNull(DB.id_legal,oSeller.getStringNull(DB.sn_passport,""))+"]]></cac:SellerID>\n"); 575 oBfr.append(" <ID>"+String.valueOf(getInt(DB.pg_order))+"</ID>\n"); 576 oBfr.append(" <GUID>"+getString(DB.gu_order)+"</GUID>\n"); 577 if (isNull(DB.dt_invoiced)) 578 oBfr.append(" <cbc:IssueDate/>\n"); 579 else 580 oBfr.append(" <cbc:IssueDate>"+getDateShort(DB.dt_invoiced)+"</cbc:IssueDate>\n"); 581 oBfr.append(" <cbc:Note><![CDATA["+getStringNull(DB.tx_ship_notes,"")+"]]></cbc:Note>\n"); 582 oBfr.append(" <TransactionCurrencyCode>"+getString(DB.id_currency)+"</TransactionCurrencyCode>\n"); 583 oBfr.append(" <cbc:TotalTaxAmount amountCurrencyCodeListVersionID=\"0.3\" amountCurrencyID=\""+getString(DB.id_currency)+"\">"+getDecimalFormated(DB.im_taxes)+"</cbc:TotalTaxAmount>\n"); 584 oBfr.append(" <cbc:LineExtensionTotalAmount amountCurrencyCodeListVersionID=\"0.3\" amountCurrencyID=\""+getString(DB.id_currency)+"\">"+getDecimalFormated(DB.im_subtotal)+"</cbc:LineExtensionTotalAmount>\n"); 585 oBfr.append(" <LineItemCountNumeric>"+String.valueOf(iLineCount)+"</LineItemCountNumeric>\n"); 586 587 oBfr.append(" <DocumentStatusCode>"+getStringNull(DB.id_status,"")+"</DocumentStatusCode>\n"); 588 oBfr.append(" <LineItemCountNumeric>"+String.valueOf(iLineCount)+"</LineItemCountNumeric>\n"); 589 590 if (DebugFile.trace) DebugFile.writeln("Writting BuyerParty..."); 591 oBfr.append(" <cac:BuyerParty>\n"); 592 oBfr.append(" <cac:Party>\n"); 593 if (oBuyer.isNull(DB.gu_contact)) 594 oBfr.append(" <cac:PartyName><cbc:Name><![CDATA["+oBuyer.getString(DB.nm_legal)+"]]></cbc:Name></cac:PartyName>\n"); 595 else 596 oBfr.append(" <cac:PartyName><cbc:Name><![CDATA["+oBuyer.getStringNull(DB.tx_name,"")+" "+oBuyer.getStringNull(DB.tx_surname,"")+"]]></cbc:Name></cac:PartyName>\n"); 597 oBfr.append(" <cac:Address>\n"); 598 if (oBillAddr==null) { 599 oBfr.append(" <ID/>\n"); 600 oBfr.append(" <cbc:PostBox/>\n"); 601 oBfr.append(" <cbc:StreetName/>\n"); 602 oBfr.append(" <cbc:AdditionalStreetName/>\n"); 603 oBfr.append(" <cbc:BuildingName/>\n"); 604 oBfr.append(" <cbc:BuildingNumber/>\n"); 605 oBfr.append(" <cbc:CityName/>\n"); 606 oBfr.append(" <cbc:PostalZone/>\n"); 607 oBfr.append(" <cbc:CountrySubentity/>\n"); 608 oBfr.append(" <cbc:CountrySubentityCode/>\n"); 609 oBfr.append(" <cbc:AddressLine/>\n"); 610 oBfr.append(" <Country/>\n"); 611 } else { 612 oBfr.append(" <ID>"+oBillAddr.getString(DB.gu_address)+"</ID>\n"); 613 oBfr.append(" <cbc:PostBox>"+oBillAddr.getStringNull(DB.po_box,"")+"</cbc:PostBox>\n"); 614 oBfr.append(" <cbc:StreetName><![CDATA["+oBillAddr.getStringNull(DB.nm_street,"")+"]]></cbc:StreetName>\n"); 615 oBfr.append(" <cbc:AdditionalStreetName><![CDATA["+oBillAddr.getStringNull(DB.tp_street,"")+"]]></cbc:AdditionalStreetName>\n"); 616 oBfr.append(" <cbc:BuildingName><![CDATA["+oBillAddr.getStringNull(DB.tx_addr2,"")+"]]></cbc:BuildingName>\n"); 617 oBfr.append(" <cbc:BuildingNumber><![CDATA["+oBillAddr.getStringNull(DB.nu_street,"")+"]]></cbc:BuildingNumber>\n"); 618 oBfr.append(" <cbc:CityName><![CDATA["+oBillAddr.getStringNull(DB.mn_city,"")+"]]></cbc:CityName>\n"); 619 oBfr.append(" <cbc:PostalZone>"+oBillAddr.getStringNull(DB.zipcode,"")+"</cbc:PostalZone>\n"); 620 oBfr.append(" <cbc:CountrySubentity><![CDATA["+oBillAddr.getStringNull(DB.nm_state,"")+"]]></cbc:CountrySubentity>\n"); 621 oBfr.append(" <cbc:CountrySubentityCode>"+oBillAddr.getStringNull(DB.id_state,"")+"</cbc:CountrySubentityCode>\n"); 622 oBfr.append(" <cbc:AddressLine><![CDATA["+oBillAddr.getStringNull(DB.tx_addr1,"")+"]]></cbc:AddressLine>\n"); 623 oBfr.append(" <Country><![CDATA["+oBillAddr.getStringNull(DB.nm_country,"").trim()+"]]></Country>\n"); 624 } 625 oBfr.append(" </cac:Address>\n"); 626 oBfr.append(" </cac:Party>\n"); 627 oBfr.append(" <cac:AccountsContact>\n"); 628 if (oBillAddr==null) { 629 oBfr.append(" <cbc:Name/>\n"); 630 oBfr.append(" <cbc:Telephone/>\n"); 631 } else { 632 oBfr.append(" <cbc:Name><![CDATA["+oBuyer.getStringNull(DB.contact_person,"")+"]]></cbc:Name>\n"); 633 oBfr.append(" <cbc:Telephone><![CDATA["+oBuyer.getStringNull(DB.direct_phone,oBuyer.getStringNull(DB.work_phone,""))+"]]></cbc:Telephone>\n"); 634 } 635 oBfr.append(" </cac:AccountsContact>\n"); 636 oBfr.append(" </cac:BuyerParty>\n"); 637 if (DebugFile.trace) DebugFile.writeln("Writting SellerParty..."); 638 oBfr.append(" <cac:SellerParty>\n"); 639 oBfr.append(" <cac:Party>\n"); 640 oBfr.append(" <cac:PartyName><cbc:Name><![CDATA["+oSeller.getStringNull(DB.nm_company,oSeller.getStringNull(DB.nm_shop,""))+"]]></cbc:Name></cac:PartyName>\n"); 641 oBfr.append(" <cac:Address>\n"); 642 if (oBillAddr==null) { 643 oBfr.append(" <ID/>\n"); 644 oBfr.append(" <cbc:PostBox/>\n"); 645 oBfr.append(" <cbc:StreetName/>\n"); 646 oBfr.append(" <cbc:AdditionalStreetName/>\n"); 647 oBfr.append(" <cbc:BuildingName/>\n"); 648 oBfr.append(" <cbc:BuildingNumber/>\n"); 649 oBfr.append(" <cbc:CityName/>\n"); 650 oBfr.append(" <cbc:PostalZone/>\n"); 651 oBfr.append(" <cbc:CountrySubentity/>\n"); 652 oBfr.append(" <cbc:CountrySubentityCode/>\n"); 653 oBfr.append(" <cbc:AddressLine/>\n"); 654 oBfr.append(" <Country/>\n"); 655 } else { 656 oBfr.append(" <ID>"+oSeller.getStringNull(DB.gu_shop, oSeller.getStringNull(DB.gu_address, ""))+"</ID>\n"); 657 oBfr.append(" <cbc:StreetName><![CDATA["+oSeller.getStringNull(DB.nm_street,"")+"]]></cbc:StreetName>\n"); 658 oBfr.append(" <cbc:AdditionalStreetName><![CDATA["+oSeller.getStringNull(DB.tp_street,"")+"]]></cbc:AdditionalStreetName>\n"); 659 oBfr.append(" <cbc:BuildingName><![CDATA["+oSeller.getStringNull(DB.tx_addr2,"")+"]]></cbc:BuildingName>\n"); 660 oBfr.append(" <cbc:BuildingNumber><![CDATA["+oSeller.getStringNull(DB.nu_street,"")+"]]></cbc:BuildingNumber>\n"); 661 oBfr.append(" <cbc:CityName><![CDATA["+oSeller.getStringNull(DB.mn_city,"")+"]]></cbc:CityName>\n"); 662 oBfr.append(" <cbc:PostalZone>"+oSeller.getStringNull(DB.zipcode,"")+"</cbc:PostalZone>\n"); 663 oBfr.append(" <cbc:CountrySubentity><![CDATA["+oSeller.getStringNull(DB.nm_state,"")+"]]></cbc:CountrySubentity>\n"); 664 oBfr.append(" <cbc:CountrySubentityCode>"+oSeller.getStringNull(DB.id_state,"")+"</cbc:CountrySubentityCode>\n"); 665 oBfr.append(" <cbc:AddressLine><![CDATA["+oSeller.getStringNull(DB.tx_addr1,"")+"]]></cbc:AddressLine>\n"); 666 oBfr.append(" <Country><![CDATA["+oSeller.getStringNull(DB.nm_country,"").trim()+"]]></Country>\n"); 667 } 668 oBfr.append(" </cac:Address>\n"); 669 oBfr.append(" </cac:Party>\n"); 670 oBfr.append(" <cac:AccountsContact>\n"); 671 oBfr.append(" <cbc:Name><![CDATA["+oSeller.getStringNull(DB.contact_person,"")+"]]></cbc:Name>\n"); 672 oBfr.append(" <cbc:Telephone><![CDATA["+oSeller.getStringNull(DB.direct_phone,oSeller.getStringNull(DB.work_phone,""))+"]]></cbc:Telephone>\n"); 673 oBfr.append(" </cac:AccountsContact>\n"); 674 oBfr.append(" </cac:SellerParty>\n"); 675 if (DebugFile.trace) DebugFile.writeln("Writting Delivery..."); 676 oBfr.append(" <cac:Delivey>\n"); 677 if (!isNull(DB.dt_promised)) 678 oBfr.append(" <cbc:RequestedDeliveyDateTime>"+getDateShort(DB.dt_promised)+"T"+getTime(DB.dt_promised)+"</cbc:RequestedDeliveyDateTime>\n"); 679 if (oShipAddr!=null) { 680 oBfr.append(" <cac:DeliveyAddress>\n"); 681 oBfr.append(" <ID>"+oShipAddr.getString(DB.gu_address)+"</ID>\n"); 682 oBfr.append(" <cbc:StreetName><![CDATA["+oShipAddr.getStringNull(DB.nm_street,"")+"]]></cbc:StreetName>\n"); 683 oBfr.append(" <cbc:AdditionalStreetName><![CDATA["+oShipAddr.getStringNull(DB.tp_street,"")+"]]></cbc:AdditionalStreetName>\n"); 684 oBfr.append(" <cbc:BuildingName><![CDATA["+oShipAddr.getStringNull(DB.tx_addr2,"")+"]]></cbc:BuildingName>\n"); 685 oBfr.append(" <cbc:BuildingNumber><![CDATA["+oShipAddr.getStringNull(DB.nu_street,"")+"]]></cbc:BuildingNumber>\n"); 686 oBfr.append(" <cbc:CityName><![CDATA["+oShipAddr.getStringNull(DB.mn_city,"")+"]]></cbc:CityName>\n"); 687 oBfr.append(" <cbc:PostalZone>"+oShipAddr.getStringNull(DB.zipcode,"")+"</cbc:PostalZone>\n"); 688 oBfr.append(" <cbc:CountrySubentity><![CDATA["+oShipAddr.getStringNull(DB.nm_state,"")+"]]></cbc:CountrySubentity>\n"); 689 oBfr.append(" <cbc:CountrySubentityCode>"+oShipAddr.getStringNull(DB.id_state,"")+"</cbc:CountrySubentityCode>\n"); 690 oBfr.append(" <cbc:AddressLine><![CDATA["+oShipAddr.getStringNull(DB.tx_addr1,"")+"]]></cbc:AddressLine>\n"); 691 oBfr.append(" <Country><![CDATA["+oShipAddr.getStringNull(DB.id_country,"").trim()+"]]></Country>\n"); 692 oBfr.append(" </cac:DeliveyAddress>\n"); 693 } 694 oBfr.append(" </cac:Delivey>\n"); 695 if (oShipAddr!=null) { 696 oBfr.append(" <DestinationCountry>"+oShipAddr.getStringNull(DB.id_country,"").trim()+"</DestinationCountry>\n"); 697 } 698 for (int l=0; l<iLineCount; l++) { 699 if (DebugFile.trace) DebugFile.writeln("Writting OrderLine "+String.valueOf(l+1)+"..."); 700 oBfr.append(" <cac:OrderLine>\n"); 701 oBfr.append(" <ID>"+String.valueOf(l+1)+"</ID>\n"); 702 float fQuantity = oLines.getFloat(DB.nu_quantity,l); 703 if (fQuantity == (long) fQuantity) 704 oBfr.append(" <cbc:DeliveredQuantity>"+String.valueOf((long)fQuantity)+"</cbc:DeliveredQuantity>\n"); 705 else 706 oBfr.append(" <cbc:DeliveredQuantity>"+String.valueOf(fQuantity)+"</cbc:DeliveredQuantity>\n"); 707 oBfr.append(" <cac:Item>\n"); 708 oBfr.append(" <cbc:Description><![CDATA["+oLines.getString(DB.nm_product,l)+"]]></cbc:Description>\n"); 709 oBfr.append(" </cac:Item>\n"); 710 oBfr.append(" </cac:OrderLine>\n"); 711 } 712 oBfr.append(" <cac:PaymentMeans>\n"); 713 oBfr.append(" <PaymentMeansCode>"+getStringNull(DB.tp_billing,"")+"</PaymentMeansCode>\n"); 714 if (isNull(DB.dt_payment)) 715 oBfr.append(" <cbc:DuePaymentDate/>\n"); 716 else 717 oBfr.append(" <cbc:DuePaymentDate>"+getDateShort(DB.dt_payment)+"</cbc:DuePaymentDate>\n"); 718 oBfr.append(" <CardAccount>"+getStringNull(DB.nu_card,"")+"</CardAccount>\n"); 719 oBfr.append(" <PayerFinancialAccount>"+getStringNull(DB.nu_bank,"")+"</PayerFinancialAccount>\n"); 720 721 oBfr.append(" </cac:PaymentMeans>\n"); 722 oBfr.append(" </Order>\n"); 723 724 if (DebugFile.trace) { 725 DebugFile.decIdent(); 726 DebugFile.writeln("End Order.toXML()"); 727 } 728 729 return oBfr.toString(); 730 } 732 733 736 743 public static boolean delete (JDCConnection oConn, String sOrderId) throws SQLException { 744 return new Order(sOrderId).delete(oConn); 745 } 746 747 749 756 public static Order getActiveOrder(JDCConnection oConn, String sWorkAreaId) throws SQLException { 757 Order oRetObj; 758 PreparedStatement oSeek; 759 ResultSet oRSet; 760 String sOrderId; 761 762 if (DebugFile.trace) { 763 DebugFile.writeln("Begin Order.getActiveOrder([Connection], " + sWorkAreaId + ")"); 764 DebugFile.incIdent(); 765 } 766 767 if (DebugFile.trace) 768 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_order + " FROM " + DB.k_orders + " WHERE " + DB.gu_workarea + "=? AND " + DB.bo_active + "=1"); 769 770 oSeek = oConn.prepareStatement("SELECT " + DB.gu_order + " FROM " + DB.k_orders + " WHERE " + DB.gu_workarea + "=? AND " + DB.bo_active + "=1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 771 oSeek.setString(1, sWorkAreaId); 772 oRSet = oSeek.executeQuery(); 773 if ( oRSet.next()) 774 sOrderId = oRSet.getString(1); 775 else 776 sOrderId = null; 777 oRSet.close(); 778 oSeek.close(); 779 780 if (null==sOrderId) { 781 oRetObj = new Order(); 782 oRetObj.put(DB.gu_workarea, sWorkAreaId); 783 oRetObj.put(DB.bo_active, (short)1); 784 oRetObj.put(DB.id_currency, "999"); 785 oRetObj.store(oConn); 786 } 787 else 788 oRetObj = new Order(oConn, sOrderId); 789 790 if (DebugFile.trace) { 791 DebugFile.decIdent(); 792 DebugFile.writeln("End Order.getActiveOrder() " + String.valueOf(oRetObj.getInt(DB.pg_order))); 793 } 794 795 return oRetObj; 796 } 798 801 public static final short ClassId = 41; 802 } 803 | Popular Tags |