示例#1
0
 /**
  * Invoked when posting of an act is complete.
  *
  * <p>This prompts to pay the account, and pops up a dialog to print the act.
  *
  * @param act the act
  */
 @Override
 protected void onPosted(final FinancialAct act) {
   HelpContext help = getHelpContext().subtopic("post");
   Tasks tasks = new Tasks(help);
   TaskContext context = new DefaultTaskContext(getContext(), help);
   context.addObject(act);
   String shortName = act.getArchetypeId().getShortName();
   BigDecimal total = act.getTotal();
   if (TypeHelper.isA(act, INVOICE, COUNTER)) {
     PaymentWorkflow payment = new PaymentWorkflow(total, getContext(), help);
     payment.setRequired(false);
     tasks.addTask(payment);
     // need to reload the act as it may be changed via the payment
     // workflow as part of the CustomerAccountRules
     tasks.addTask(new ReloadTask(shortName));
     tasks.addTaskListener(
         new DefaultTaskListener() {
           public void taskEvent(TaskEvent event) {
             // force a refresh so the summary updates
             onRefresh(act);
           }
         });
   }
   PrintActTask print = new PrintActTask(shortName, getMailContext());
   print.setRequired(false);
   print.setEnableSkip(false);
   tasks.addTask(print);
   tasks.start(context);
 }
示例#2
0
  /**
   * Returns a <tt>MonetaryTotalType</tt> for an order.
   *
   * @param order the order
   * @param currency the currency
   * @return the corresponding <tt>MonetaryTotalType</tt>
   */
  private MonetaryTotalType getMonetaryTotal(FinancialAct order, Currency currency) {
    BigDecimal payableAmount = order.getTotal();
    BigDecimal lineExtensionAmount = payableAmount.subtract(order.getTaxAmount());

    MonetaryTotalType result = new MonetaryTotalType();
    result.setLineExtensionAmount(
        UBLHelper.initAmount(new LineExtensionAmountType(), lineExtensionAmount, currency));
    result.setPayableAmount(UBLHelper.initAmount(new PayableAmountType(), payableAmount, currency));
    return result;
  }
示例#3
0
 /**
  * Helper to create a new act, setting the total, adding a customer and clinician participation
  * and setting the status.
  *
  * @param shortName the act short name
  * @param amount the act total
  * @param customer the customer
  * @param clinician the clinician. May be {@code null}
  * @param status the status
  * @return a new act
  */
 private static FinancialAct createAct(
     String shortName, BigDecimal amount, Party customer, User clinician, String status) {
   FinancialAct act = (FinancialAct) create(shortName);
   act.setStatus(status);
   ActBean bean = new ActBean(act);
   bean.setValue("amount", amount);
   bean.addNodeParticipation("customer", customer);
   if (clinician != null) {
     bean.addNodeParticipation("clinician", clinician);
   }
   return act;
 }
示例#4
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);
 }
示例#5
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;
  }
示例#6
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;
 }
示例#7
0
 /**
  * Creates a new supplier act item.
  *
  * @param shortName the act short name
  * @param product the product
  * @param quantity the quantity
  * @param packageSize the package size
  * @param packageUnits the package units
  * @param unitPrice the unit price
  * @param listPrice the list price
  * @return a new act
  */
 protected static FinancialAct createItem(
     String shortName,
     Product product,
     BigDecimal quantity,
     int packageSize,
     String packageUnits,
     BigDecimal unitPrice,
     BigDecimal listPrice) {
   FinancialAct item = (FinancialAct) create(shortName);
   ActBean bean = new ActBean(item);
   bean.addParticipation(StockArchetypes.STOCK_PARTICIPATION, product);
   item.setQuantity(quantity);
   bean.setValue("packageSize", packageSize);
   bean.setValue("packageUnits", packageUnits);
   bean.setValue("unitPrice", unitPrice);
   bean.setValue("listPrice", listPrice);
   ArchetypeServiceHelper.getArchetypeService().deriveValues(item);
   return item;
 }
示例#8
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;
 }
示例#9
0
 /**
  * Helper to create a POSTED <em>act.supplierOrder</em> and corresponding
  * <em>act.supplierOrderItem</em>.
  *
  * @param amount the act total
  * @param supplier the supplier
  * @param stockLocation the stockLocation
  * @param product the product
  * @return a list containing the invoice act and its item
  */
 public static List<FinancialAct> createOrder(
     BigDecimal amount, Party supplier, Party stockLocation, Product product) {
   FinancialAct act = (FinancialAct) create(SupplierArchetypes.ORDER);
   act.setStatus(OrderStatus.POSTED);
   FinancialAct item =
       createItem(
           SupplierArchetypes.ORDER_ITEM,
           product,
           BigDecimal.ONE,
           1,
           PACKAGE_UNITS,
           amount,
           amount);
   ActBean bean = new ActBean(act);
   bean.addNodeParticipation("supplier", supplier);
   bean.addNodeParticipation("stockLocation", stockLocation);
   bean.addRelationship(SupplierArchetypes.ORDER_ITEM_RELATIONSHIP, item);
   bean.setValue("amount", item.getTotal());
   return Arrays.asList(act, item);
 }
 /**
  * Save any edits.
  *
  * <p>This links the adjustment to the <em>act.tillBalance</em> and forces a recalculation, if one
  * is present.
  *
  * @return {@code true} if the save was successful
  */
 @Override
 protected boolean doSave() {
   boolean result;
   if (currentBalance != null && !TillBalanceStatus.CLEARED.equals(currentBalance.getStatus())) {
     ActBean bean = new ActBean(currentBalance);
     bean.addNodeRelationship("items", (Act) getObject());
     bean.save();
     result = super.doSave();
     if (result) {
       // need to update the balance after the adjustment is saved
       TillRules rules = ServiceHelper.getBean(TillRules.class);
       rules.updateBalance(currentBalance);
     }
   } else {
     result = super.doSave();
   }
   return result;
 }
 /**
  * Validates the object.
  *
  * @param validator the validator
  * @return {@code true} if the object and its descendants are valid otherwise {@code false}
  */
 @Override
 protected boolean doValidation(Validator validator) {
   boolean result = super.doValidation(validator);
   if (result) {
     FinancialAct balance = (FinancialAct) getParent();
     if (balance != null) {
       currentBalance = IMObjectHelper.reload(balance); // make sure we have the latest instance
       if (currentBalance == null) {
         ErrorDialog.show(
             Messages.format("imobject.noexist", DescriptorHelper.getDisplayName(balance)));
         result = false;
       } else if (TillBalanceStatus.CLEARED.equals(currentBalance.getStatus())) {
         ErrorDialog.show(Messages.get("till.adjustment.error.clearedBalance"));
         result = false;
       }
     }
   }
   return result;
 }
示例#12
0
 /**
  * Returns a <tt>TaxTotalType</tt> for an order.
  *
  * @param order the order
  * @param currency the currency
  * @return the corresponding <tt>TaxTotalType</tt>
  */
 private TaxTotalType getTaxTotal(FinancialAct order, Currency currency) {
   TaxTotalType result = new TaxTotalType();
   result.setTaxAmount(UBLHelper.initAmount(new TaxAmountType(), order.getTaxAmount(), currency));
   return result;
 }