views:

141

answers:

1

I've built a customer relationship management system in PHP which generates Quotes, Orders and Invoices and I am at a loss on the best way to structure the system.

I currently have one table for each type (quote, order, invoice) and about 20 different pages for displaying the input forms and saving the data back to the database. This is a problem as it is not very efficient and if I need to add anything it takes ages.

Different types of quote need to have different input fields (such as monthly payments, setup fees) and need to be treated differently when inserting this data into the database.

For example, a quote for a website design would need to show an interface for adding products, customer fields, monthly payment, setup fee and would need to create an Account (a row in another table).

But a one off sales that is an upgrade or an upsell would simply need to display the product and custom fields form and merely update the Account.

I have started restructuring it and have so far come up with a factory for quotes and implements the strategy pattern for the different form configurations but I don't know if this is the best way. This would work like this:

// Create a new Quote
$quote = QuoteFactory::get('new_design');
print $quote->buildForm();

// Edit a Quote
$quote = QuoteFactory::getQuoteByID($req->get('quote_id'));
print $quote->buildForm();

// Retrieve a quote
$quote = QuoteFactory::getQuoteByID($req->get('quote_id'));
$quote->getSalesValue();
A: 

It's OK guy's I think the system I am working on is going to cover this. Using a factory to create the quote dependant on type and then the strategy pattern to build the forms for creation and editing.

xenon