Пример #1
0
 /**
  * Creates a new return item from an order item.
  *
  * <p>The quantity on the return item will default to the order's: <em>receivedQuantity</em>
  *
  * @param orderItem the order item
  * @return a new return item
  * @throws ArchetypeServiceException for any archetype service error
  */
 public FinancialAct createReturnItem(FinancialAct orderItem) {
   List<IMObject> objects =
       copy(
           orderItem,
           ORDER_ITEM,
           new ReturnItemHandler(),
           orderItem.getActivityStartTime(),
           false);
   ActBean order = new ActBean(orderItem, service);
   BigDecimal received = order.getBigDecimal("receivedQuantity");
   FinancialAct item = (FinancialAct) objects.get(0);
   item.setQuantity(received);
   return (FinancialAct) objects.get(0);
 }
Пример #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;
  }
Пример #3
0
 /**
  * Creates a new delivery item from an order item.
  *
  * <p>The quantity on the delivery item will default to the order's:
  *
  * <p><tt>quantity - (receivedQuantity + cancelledQuantity)</tt>
  *
  * @param orderItem the order item
  * @return a new delivery item
  * @throws ArchetypeServiceException for any archetype service error
  */
 public FinancialAct createDeliveryItem(FinancialAct orderItem) {
   List<IMObject> objects =
       copy(
           orderItem,
           ORDER_ITEM,
           new DeliveryItemHandler(),
           orderItem.getActivityStartTime(),
           false);
   ActBean order = new ActBean(orderItem, service);
   BigDecimal quantity = orderItem.getQuantity();
   BigDecimal received = order.getBigDecimal("receivedQuantity");
   BigDecimal cancelled = order.getBigDecimal("cancelledQuantity");
   BigDecimal remaining = quantity.subtract(received.add(cancelled));
   if (remaining.compareTo(BigDecimal.ZERO) < 0) {
     remaining = BigDecimal.ZERO;
   }
   FinancialAct delivery = (FinancialAct) objects.get(0);
   delivery.setQuantity(remaining);
   return delivery;
 }