Ejemplo n.º 1
0
  /**
   * Returns an <tt>OrderLineType</tt> for an <em>act.supplierOrderItem</em>.
   *
   * @param act the order item to map
   * @param supplier the supplier
   * @param currency the currency that amounts are expressed in
   * @return a new <tt>OrderLineType</tt> corresponding to the act
   */
  private OrderLineType getOrderLine(Act act, Party supplier, Currency currency) {
    ActBean bean = factory.createActBean(act);
    Product product = (Product) bean.getNodeParticipant("product");

    OrderLineType orderLine = new OrderLineType();
    LineItemType lineItem = new LineItemType();

    String packageUnits = bean.getString("packageUnits");
    String unitCode = getUnitCode(packageUnits);

    ItemType item = getItem(bean, supplier, product, unitCode);
    lineItem.setItem(item);
    orderLine.setLineItem(lineItem);

    IDType id = UBLHelper.createID(act.getId());
    QuantityType quantity =
        UBLHelper.initQuantity(new QuantityType(), bean.getBigDecimal("quantity"), unitCode);
    LineExtensionAmountType lineAmount =
        UBLHelper.initAmount(new LineExtensionAmountType(), bean.getBigDecimal("total"), currency);
    TotalTaxAmountType taxAmount =
        UBLHelper.initAmount(new TotalTaxAmountType(), bean.getBigDecimal("tax"), currency);
    PriceType price = getPrice(bean.getBigDecimal("unitPrice"), unitCode, currency);

    lineItem.setID(id);
    lineItem.setQuantity(quantity);
    lineItem.setLineExtensionAmount(lineAmount);
    lineItem.setTotalTaxAmount(taxAmount);
    lineItem.setPrice(price);

    return orderLine;
  }
Ejemplo n.º 2
0
  /**
   * Maps an <em>act.supplierOrder</em> to an UBL order.
   *
   * @param order the <em>act.supplierOrder</em> to map
   * @return the corresponding UBL order
   * @throws ESCIAdapterException for mapping errors
   * @throws ArchetypeServiceException for any archetype service error
   */
  public Order map(FinancialAct order) {
    Order result = new Order();
    Currency currency = getCurrency();

    UBLVersionIDType version = UBLHelper.initID(new UBLVersionIDType(), "2.0");
    IDType id = UBLHelper.createID(order.getId());
    CopyIndicatorType copyIndicator = getCopyIndicatorType(false);

    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTime(order.getActivityStartTime());
    IssueDateType issueDate = UBLHelper.createIssueDate(startTime, datatypeFactory);
    IssueTimeType issueTime = UBLHelper.createIssueTime(startTime, datatypeFactory);

    ActBean bean = factory.createActBean(order);
    Entity author = bean.getNodeParticipant("author");
    Party stockLocation = (Party) bean.getNodeParticipant("stockLocation");
    Party location = getLocation(stockLocation);

    Party supplier = (Party) bean.getNodeParticipant("supplier");
    EntityRelationship supplierStockLocation =
        supplierRules.getSupplierStockLocation(supplier, stockLocation);
    if (supplierStockLocation == null) {
      throw new ESCIAdapterException(
          ESCIAdapterMessages.ESCINotConfigured(supplier, stockLocation));
    }
    String contactName = (author != null) ? author.getName() : null;
    CustomerPartyType customerParty =
        getCustomer(contactName, location, stockLocation, supplierStockLocation);
    SupplierPartyType supplierParty = getSupplier(supplier);

    TaxTotalType taxTotal = getTaxTotal(order, currency);
    MonetaryTotalType total = getMonetaryTotal(order, currency);

    result.setUBLVersionID(version);
    result.setID(id);
    result.setCopyIndicator(copyIndicator);
    result.setIssueDate(issueDate);
    result.setIssueTime(issueTime);
    result.setBuyerCustomerParty(customerParty);
    result.setSellerSupplierParty(supplierParty);
    result.getTaxTotal().add(taxTotal);
    result.setAnticipatedMonetaryTotal(total);

    for (Act item : bean.getNodeActs("items")) {
      OrderLineType line = getOrderLine(item, supplier, currency);
      result.getOrderLine().add(line);
    }
    return result;
  }
Ejemplo n.º 3
0
 /**
  * Returns an <tt>ItemIdentificationType</tt> for the given identifier.
  *
  * @param id the identifier
  * @return a new <tt>ItemIdentificationType</tt>
  */
 private ItemIdentificationType getItemIdentification(String id) {
   ItemIdentificationType result = new ItemIdentificationType();
   result.setID(UBLHelper.createID(id));
   return result;
 }