Пример #1
0
 /**
  * Credits a supplier from an <em>act.supplierReturn</em> act.
  *
  * <p>The credit is saved.
  *
  * @param supplierReturn the supplier return act
  * @return the credit corresponding to the return
  * @throws ArchetypeServiceException for any archetype service error
  * @throws IllegalStateException if the return is already associated with a credit
  */
 public FinancialAct creditSupplier(Act supplierReturn) {
   if (isCredited(supplierReturn)) {
     throw new IllegalStateException("The return is already linked to a credit");
   }
   ActBean bean = new ActBean(supplierReturn, service);
   List<IMObject> objects = copy(supplierReturn, RETURN, new ReturnHandler(), new Date(), false);
   FinancialAct credit = (FinancialAct) objects.get(0);
   bean.addNodeRelationship("returnCredit", credit);
   objects.add(supplierReturn);
   service.save(objects);
   return (FinancialAct) objects.get(0);
 }
Пример #2
0
 /**
  * Invoices a supplier from an <em>act.supplierDelivery</em> act.
  *
  * <p>Both the invoice and delivery are saved.
  *
  * @param delivery the supplier delivery act
  * @return the invoice corresponding to the delivery
  * @throws ArchetypeServiceException for any archetype service error
  * @throws IllegalStateException if the delivery is already associated with a charge
  */
 public FinancialAct invoiceSupplier(Act delivery) {
   if (isInvoiced(delivery)) {
     throw new IllegalStateException("The delivery has already been invoiced");
   }
   ActBean bean = new ActBean(delivery, service);
   List<IMObject> objects = copy(delivery, DELIVERY, new DeliveryHandler(), new Date(), false);
   FinancialAct invoice = (FinancialAct) objects.get(0);
   bean.addNodeRelationship("invoice", invoice);
   objects.add(delivery);
   service.save(objects);
   return invoice;
 }
Пример #3
0
 /**
  * Processes an invoice.
  *
  * @param document the document to process
  * @param supplier the supplier submitting the invoice
  * @param stockLocation the stock location
  * @param accountId the supplier account identifier
  */
 public void process(
     InboxDocument document, Party supplier, Party stockLocation, String accountId) {
   InvoiceType invoice = (InvoiceType) document.getContent();
   try {
     Delivery delivery = mapper.map(invoice, supplier, stockLocation, accountId);
     service.save(delivery.getActs());
     notifyListener(delivery.getDelivery());
   } catch (Throwable exception) {
     String invoiceId = (invoice.getID() != null) ? invoice.getID().getValue() : null;
     Message message =
         ESCIAdapterMessages.failedToProcessInvoice(
             invoiceId, supplier, stockLocation, exception.getMessage());
     throw new ESCIAdapterException(message, exception);
   }
 }
Пример #4
0
 /**
  * Copies an order.
  *
  * <p>The copied order will have an <em>IN_PROGRESS</em> status and <em>PENDING</em> delivery
  * status.
  *
  * <p>The copy is saved.
  *
  * @param order the order to copy
  * @param title a title to assign to the copy. May be {@code null}
  * @return the copy of the order
  * @throws ArchetypeServiceException for any archetype service error
  */
 public FinancialAct copyOrder(FinancialAct order, String title) {
   List<IMObject> objects = copy(order, ORDER, new DefaultActCopyHandler(), new Date(), false);
   FinancialAct copy = (FinancialAct) objects.get(0);
   IMObjectBean bean = new IMObjectBean(copy, service);
   bean.setValue("deliveryStatus", DeliveryStatus.PENDING);
   copy.setTitle(title);
   for (IMObject object : objects) {
     if (TypeHelper.isA(object, SupplierArchetypes.ORDER_ITEM)) {
       IMObjectBean itemBean = new IMObjectBean(object, service);
       itemBean.setValue("receivedQuantity", BigDecimal.ZERO);
       itemBean.setValue("cancelledQuantity", BigDecimal.ZERO);
     }
   }
   service.save(objects);
   return copy;
 }
Пример #5
0
 /**
  * Helper to copy an act.
  *
  * @param object the object to copy
  * @param type the expected type of the object
  * @param handler the copy handler
  * @param startTime the start time of the copied object
  * @param save if <tt>true</tt>, save the copied objects
  * @return the copied objects
  */
 private List<IMObject> copy(
     Act object, String type, IMObjectCopyHandler handler, Date startTime, boolean save) {
   if (!TypeHelper.isA(object, type)) {
     throw new IllegalArgumentException(
         "Expected a "
             + type
             + " for argument 'object'"
             + ", but got a"
             + object.getArchetypeId().getShortName());
   }
   IMObjectCopier copier = new IMObjectCopier(handler, service);
   List<IMObject> objects = copier.apply(object);
   Act act = (Act) objects.get(0);
   act.setActivityStartTime(startTime);
   if (save) {
     service.save(objects);
   }
   return objects;
 }