Beispiel #1
0
  /**
   * Returns a <tt>ItemType</tt> for a supplier, order item, and product.
   *
   * @param bean the order item
   * @param supplier the supplier
   * @param product the product
   * @param packageUnits the package size unit code. May be <tt>null</tt>
   * @return an <tt>ItemType</tt> corresponding to the supplier and product
   */
  private ItemType getItem(ActBean bean, Party supplier, Product product, String packageUnits) {
    ItemType result = new ItemType();
    ItemIdentificationType buyersId = getItemIdentification(product.getId());
    String reorderCode = bean.getString("reorderCode");
    String reorderDescription = bean.getString("reorderDescription");
    if (!StringUtils.isEmpty(reorderCode)) {
      ItemIdentificationType sellersId = getItemIdentification(reorderCode);
      result.setSellersItemIdentification(sellersId);
    } else {
      throw new ESCIAdapterException(ESCIAdapterMessages.noSupplierOrderCode(supplier, product));
    }
    if (!StringUtils.isEmpty(reorderDescription)) {
      DescriptionType description = UBLHelper.initText(new DescriptionType(), reorderDescription);
      result.getDescription().add(description);
    }
    NameType name = UBLHelper.initName(new NameType(), product.getName());

    result.setBuyersItemIdentification(buyersId);
    result.setName(name);

    BigDecimal packageSize = bean.getBigDecimal("packageSize");
    if (packageSize != null && packageUnits != null) {
      PackQuantityType quantity =
          UBLHelper.initQuantity(new PackQuantityType(), BigDecimal.ONE, packageUnits);
      PackSizeNumericType size = UBLHelper.createPackSizeNumeric(packageSize);
      result.setPackQuantity(quantity);
      result.setPackSizeNumeric(size);
    }

    return result;
  }
Beispiel #2
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;
  }
Beispiel #3
0
 /**
  * Returns a <tt>PriceType</tt> for the specified price and unit code.
  *
  * @param price the price
  * @param unitCode the quantity unit code (UN/CEFACT). May be <tt>null</tt>
  * @param currency the currency
  * @return the corresponding <tt>PriceType</tt> for price and unitCode
  */
 private PriceType getPrice(BigDecimal price, String unitCode, Currency currency) {
   PriceType result = new PriceType();
   PriceAmountType priceAmount = UBLHelper.initAmount(new PriceAmountType(), price, currency);
   result.setPriceAmount(priceAmount);
   result.setBaseQuantity(
       UBLHelper.initQuantity(new BaseQuantityType(), BigDecimal.ONE, unitCode));
   return result;
 }