/** * 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); }
/** * Determines if an editor has a template product that needs expanding. * * @param editor the editor * @return {@code true} iif the editor has a template product */ private boolean needsTemplateExpansion(IMObjectEditor editor) { if (editor instanceof ActItemEditor) { IMObjectReference product = ((ActItemEditor) editor).getProductRef(); return TypeHelper.isA(product, TEMPLATE); } return false; }
/** * Confirms that the user wants to post the act. * * @param act the act to post * @param callback the callback to handle the posting, if the user confirms it */ @Override protected void confirmPost(Act act, Runnable callback) { if (TypeHelper.isA(act, CustomerAccountArchetypes.INVOICE)) { UndispensedOrderChecker checker = new UndispensedOrderChecker(act); if (checker.hasUndispensedItems()) { checker.confirm(getHelpContext(), callback); } else { super.confirmPost(act, callback); } } else { super.confirmPost(act, callback); } }
/** * Adds the object being edited to the collection, if it doesn't exist. * * <p>The object will be selected. * * @param editor the editor * @return {@code true} if the object was added, otherwise {@code false} */ @Override public boolean addEdited(IMObjectEditor editor) { boolean result = false; if (needsTemplateExpansion(editor)) { Product product = ((ActItemEditor) editor).getProduct(); if (TypeHelper.isA(product, TEMPLATE)) { result = expandTemplate((ActItemEditor) editor, product); } } else { result = super.addEdited(editor); } return result; }
/** * Determines how {@link IMObjectCopier} should treat an object. * * @param object the source object * @param service the archetype service * @return {@code object} if the object shouldn't be copied, {@code null} if it should be * replaced with {@code null}, or a new instance if the object should be copied */ public IMObject getObject(IMObject object, IArchetypeService service) { IMObject result; if (object instanceof Participation) { Participation participant = (Participation) object; if (TypeHelper.isA(participant.getEntity(), TEMPLATE)) { result = null; } else { result = super.getObject(object, service); } } else { result = super.getObject(object, service); } return result; }
/** * Returns the object associated with the reference, defaulting it to the parent if the reference * is unset, and the parent is of the correct archetype. * * @param reference the reference * @param parent the parent object * @param archetypeRange the archetypes that the reference may refer to * @param cache the cache * @return the object, or {@code null} if the reference is set but refers to an invalid object */ private IMObject getObject( IMObjectReference reference, IMObject parent, String[] archetypeRange, IMObjectCache cache) { IMObject result = null; if (reference == null) { if (TypeHelper.isA(parent, archetypeRange)) { result = parent; } } else if (reference.equals(parent.getObjectReference())) { result = parent; } else { result = cache.get(reference); } return result; }
/** * Helper to determine if a node is copyable. * * <p>For charge items, this only copies the <em>quantity</em>, <em>patient</em>, * <em>product</em>, <em>author</em> and <em>clinician<em> nodes. * * @param archetype the archetype descriptor * @param node the node descriptor * @param source if {@code true} the node is the source; otherwise its the target * @return {@code true} if the node is copyable; otherwise {@code false} */ @Override protected boolean isCopyable( ArchetypeDescriptor archetype, NodeDescriptor node, boolean source) { boolean result = super.isCopyable(archetype, node, source); if (result && TypeHelper.isA(archetype, INVOICE_ITEM, CREDIT_ITEM, COUNTER_ITEM)) { String name = node.getName(); result = "quantity".equals(name) || "patient".equals(name) || "product".equals(name) || "author".equals(name) || "clinician".equals(name); } return result; }
/** * 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; }
/** * 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; }
/** * Invoked when a product changes. * * <p>This expands any template products * * @param editor the editor * @param product the product. */ private void onProductChanged(ActItemEditor editor, Product product) { if (TypeHelper.isA(product, ProductArchetypes.TEMPLATE)) { expandTemplate(editor, product); } }