Current functionality:
When a payment is created, you have the option to link it to one or more invoices. The payment-invoice relationship is then set and can not be manually modified by the user.
Desired functionality:
After a payment is created, the user should be able to add/remove links to invoices. From the payment details screen, the user should be able to:
- remove a link to an invoice. The invoice's balance would be increased by the amount that the payment had paid of it. The same thing happens to the payment's balance.
- create a link to an invoice if the payment has any balance left. In that case, the invoice gets paid by the amount left in the payment's balance, just like it is now when a new payment is created.
Technical overview:
Client tier modifications:
- A link 'Pay an invoice with this payment' is displayed only if the payment's balance is != 0. This is to allow an existing payment to be linked to an invoice.
- The list of invoices being paid should be modified to show a link 'Remove' in each row.
- Removal of a link to an invoice prompts a confirmation screen.
- All the above changes apply only to non-customer profiles. In other words, customers can not link/unlink their payments to invoices. :)
Database tier modifications:
- Take a look to the payment database diagram, available in the documentation section of the website. The table that connects the payment and invoice tables is just a map table that holds the ids of the related rows. This table has to be changed by one with an additional column with the amount that the payment has paid of the linked invoice. The name of the table has to change has well, because we reserve the name *_map to tables that are only used to allow for an N to N relationship and therefore only hold two ids. So just replace the name by 'payment_invoice', dropping the map suffix.
- Since now we have a 'new' table, we need a new entity bean to map it as a Java object. This will be an entity bean with CMR that returns one bean for payment and one for invoice. So we'll have something like this for the getters (you can imagine the setters):
Float getAmount();
PaymentEntity getPayment();
InvoiceEntity getInvoice().
- The existing CMR relationship between the payment an invoice tables is being replaced by our new table. So these two entity beans have to be modified.
Server tier modifications:
- Since payment and invoice entity beans have changed, you'll need to update the calls to the changed methods in a few places. Of special interest is PaymentSessionBean.applyPayment(). The compiler will tell you all the places you need to update, you'll have to update them by using the new entity bean.
- Move the code in PaymentSessionBean.applyPayment to PaymentBL, where should have been from the beginning. You still need the method in PaymentSessionBean, but simply forward the call to PaymetBL. Remember, session beans are there only as facades, to expose only some methods to the client tier as for transaction demarcation.
- We need a new method PaymentBL.unapplyPayment. This has to undo what today is done with PaymentSessionBean.applyPayment. This basically is:
- Add to the invoice balance whatever is in payment_invoice.amount
- Add to the payment balance whatever is in payment_invoice.amount
- If the invoice balance is >= 0.01, then set the to_process = 1, which means that this invoice is not considered paid.
- Remove the row in payment_invoice that is now linking the payment and the invoice.
- A new method in the PaymentSessionBean is necessary to follow the facade pattern. It has to set the transaction as Required and just forward the call to PaymentBL.unapplyPayment.
Changes mostly to be done in these files:
view/payment/viewBody.jsp
PaymentSessionBean.java
PaymentBL.java
PaymentEntityBean.java
InvoiceEntityBean.java
PaymentInvoiceEntityBean.java (new file)
init.sql (to show the new database schema)
(com.sapienter.jbilling.client.payment) MaintainAction.java
This task is completed. These were the changes
Task Update
Finished the client tier changes of this task. Going to look closely at the database and server tier tommorow night and will post any questions. Ive actually already done some of the easier pieces of these tiers like changing the scripts and adding the table, but just want to make sure I have a through understanding before I dive into them.
Also just wanted to let you know, we will be going on vacation to new orleans this thursday and wont be back until sunday night. So the next update will be the middle of the following week.
Blake
Blake,
Blake,
I would need this feature to be done soon, so how about we trade tasks? There are two other tasks open that you can take over if you want. I have time now to work on something so I would take this one. If you have completed some of it, send me the files ;)
If you are pretty advanced in this task and have time to finish it, by all means do it. Let me know.
Emiliano Conde
Lead Developer - jbilling
Emiliano Conde
Lead Developer - jBilling
Client tier modifications
I have a question about the client tier modifications. Just want to make sure I have a through understanding before I make them.
"A link 'Pay an invoice with this payment' is displayed only if the payment's balance is != 0. This is to allow an existing payment to be linked to an invoice."
This link should be displayed below the payment information. If its selected should the user should then be presented with a list so that they can choose which invoice to apply this payment? I just assume that a payment could be linked to multiple unpaid or partial paid invoices. If thats the case I would think that we wouldnt even list the invoices with a balance of 0.
The removal is pretty straight forward we just want to give the admin a way to unlink the invoices with a current payment. Ill finish that today.
Blake
Hi Blake, You are right,
Hi Blake,
You are right, the user should be presented with a list of invoices that have balance, so they can choose to which one to apply the payment. This list is already there, but unfortunately not in a re-use friendly way. It is used when creating a new payment, then the user can choose an invoice to apply the payment to. This is a chunk of code in /view/payment/viewBody.jsp (instead of a tile jsp that can be more easily resued). You can copy-paste most of it.
The server side of this list is resuable. The sql code that gets the data is InvoiceSQL.payableByUser which is called in InvoiceBL.getPayableInvoicesByUser
Emiliano Conde
Lead Developer - jbilling
Emiliano Conde
Lead Developer - jBilling
Update
Just finished a project at work I was under a deadline for today. On this task so far Ive updated the init and init dev scripts to reflect the new table and created the new bean. Xdoclet is new to me mso Im sure Ill post some questions tommrow or sunday since I now I have some breathing space. Sorry for the delay in starting this task but Ill wrap it up quickly now that Im out from under the gun :-)
Blake
Update
Just letting you know Im going to start this task today. Had several things going on last week that took most of my time.
Blake
No problem, thanks for the
No problem, thanks for the update. This task can get tricky, because you have to deal with billing business logic. Do not hesitate to ask questions, otherwise frustration will hit! :)
Cheers,
Emiliano Conde
Lead Developer - jbilling
Emiliano Conde
Lead Developer - jBilling
Task
Ill take this one. Looks like fun and Im already somewhat familar with the payments. Ill spend the next few days taking a good look at what all is involved before I actually get started.
Blake