diff --git a/.gitignore b/.gitignore
index c72753c9..be3f36d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
-tmp/*
+tmp/logs/*
+tmp/cache/models/*
+tmp/cache/persistent/*
+tmp/cache/views/*
+tmp/sessions/*
+tmp/tests/*
*.tar.gz
diff --git a/controllers/addresses_controller.php b/controllers/addresses_controller.php
index 191cc839..7799b1a1 100755
--- a/controllers/addresses_controller.php
+++ b/controllers/addresses_controller.php
@@ -2,8 +2,8 @@
class AddressesController extends AppController {
var $name = 'Addresses';
- var $helpers = array('Html', 'Form');
-
+ var $helpers = array('Html', 'Form', 'Ajax');
+ var $components = array('RequestHandler');
function index() {
$this->Address->recursive = 0;
$this->set('addresses', $this->paginate());
@@ -41,6 +41,18 @@ class AddressesController extends AppController {
$this->set(compact('customer', 'states', 'countries'));
}
+ function add_another($increment) {
+ $this->set('increment', $increment);
+ $states = $this->Address->State->find('list');
+ $countries = $this->Address->Country->find('list');
+ $this->set('states', $states);
+ $this->set('countries', $countries);
+ }
+ function remove_another($increment) {
+ $this->set('increment', $increment);
+ }
+
+
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Address', true));
@@ -63,16 +75,6 @@ class AddressesController extends AppController {
$this->set(compact('customers','states','countries'));
}
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for Address', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->Address->del($id)) {
- $this->Session->setFlash(__('Address deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- }
}
?>
diff --git a/controllers/contacts_controller.php b/controllers/contacts_controller.php
index f6f77e16..8891f91c 100755
--- a/controllers/contacts_controller.php
+++ b/controllers/contacts_controller.php
@@ -2,8 +2,8 @@
class ContactsController extends AppController {
var $name = 'Contacts';
- var $helpers = array('Html', 'Form');
-
+ var $helpers = array('Html', 'Form', 'Ajax');
+ var $components = array('RequestHandler');
var $paginate = array(
'Contact' => array('order' => array('Contact.customer_id' => 'asc')),
'Enquiry' => array('order' => array('Enquiry.id' => 'asc'))
@@ -37,7 +37,7 @@ class ContactsController extends AppController {
$this->redirect(array('controller'=>'Enquiries', 'action'=>'index'));
}
if (!empty($this->data)) {
- $this->data['Contact']['name'] = $this->data['Contact']['first_name'].' '.$this->data['Contact']['last_name'];
+
$this->Contact->create();
if ($this->Contact->save($this->data)) {
$this->Session->setFlash(__('The Contact has been saved', true));
@@ -51,6 +51,22 @@ class ContactsController extends AppController {
$this->set(compact('customer'));
}
+ function add_another($increment) {
+ $this->set('increment', $increment);
+
+ }
+ function remove_another($increment) {
+ $this->set('increment', $increment);
+ }
+ function add_one($customerid) {
+ $this->set('customerid', $customerid);
+ }
+ function remove_one($customerid) {
+ $contacts = $this->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customerid)));
+ $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0}, {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
+ $this->set('contacts', $contacts);
+ $this->set('customerid', $customerid);
+ }
function edit($id = null) {
if (!$id && empty($this->data)) {
diff --git a/controllers/currencies_controller.php b/controllers/currencies_controller.php
index 4ee38ccb..cff4f706 100755
--- a/controllers/currencies_controller.php
+++ b/controllers/currencies_controller.php
@@ -2,7 +2,8 @@
class CurrenciesController extends AppController {
var $name = 'Currencies';
- var $helpers = array('Html', 'Form');
+ var $helpers = array('Html', 'Form'), 'Ajax';
+ var $components = array('RequestHandler');
function index() {
$this->Currency->recursive = 0;
@@ -59,4 +60,4 @@ class CurrenciesController extends AppController {
}
}
-?>
\ No newline at end of file
+?>
diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php
index 7adfb1d2..fb3f1cb3 100755
--- a/controllers/customers_controller.php
+++ b/controllers/customers_controller.php
@@ -2,8 +2,8 @@
class CustomersController extends AppController {
var $name = 'Customers';
- var $helpers = array('Html', 'Form', 'Time');
-
+ var $helpers = array('Html', 'Form', 'Time', 'Ajax');
+ var $components = array('RequestHandler');
var $paginate = array(
'Customer' => array('order' => array('Customer.name' => 'asc'),
'limit' => 200
@@ -28,8 +28,7 @@ class CustomersController extends AppController {
function add() {
if (!empty($this->data)) {
-
-
+
if($this->Customer->saveAll($this->data, array('validate'=>'first')) ) {
$newcustomerid = $this->Customer->id;
$this->Session->setFlash(__('The Customer has been saved', true));
diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php
index 9c74fde1..37ab0a69 100755
--- a/controllers/enquiries_controller.php
+++ b/controllers/enquiries_controller.php
@@ -42,15 +42,6 @@ class EnquiriesController extends AppController {
function add() {
-
- $states = $this->Enquiry->State->find('list');
- $countries = $this->Enquiry->Country->find('list', array('order'=> 'Country.name asc'));
- $principles = $this->Enquiry->Principle->find('list', array('order' => 'Principle.name asc'));
- $statuses = $this->Enquiry->Status->find('list');
- $users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username')));
- $this->set(compact('users', 'customers', 'states', 'countries', 'principles', 'statuses'));
-
-
if(empty($this->data)) {
$this->set('step', 1);
}
@@ -65,22 +56,71 @@ class EnquiriesController extends AppController {
if(isset($customer)) {
-
/* Check if the customer exists in the database - otherwise send the user back to step 1*/
- if(!$customer) {
- $this->Session->setFlash(__('The customer must already exist in the database. Please try again', true));
- $this->redirect(array('action'=>'add'));
- }
- $this->set('customer', $customer);
- $contacts = $this->Enquiry->Contact->find('list', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
+ if(!$customer) {
+ $this->Session->setFlash(__('The customer must already exist in the database. Please try again', true));
+ $this->redirect(array('action'=>'add'));
+ }
+
+ $this->__showPage2($customer);
+ $this->render();
+
+ }
+
+ if ( (!empty($this->data)) && ($this->data['Enquiry']['finished'] == 'true') ) {
+ /*
+ $this->Enquiry->set($this->data);
+ /* Page to display if Validation Fails
+ if( !($this->Enquiry->validates()) ) {
+ $this->__showPage2($this->data);
+
+ }
+ *
+ else {
+ */
+ $this->Enquiry->create();
+ $enquiryno = $this->__generateEnquiryNumber($this->data);
+ $this->data['Enquiry']['title'] = $enquiryno;
+ $principle = $this->Enquiry->Principle->findById($this->data['Enquiry']['principle_id']);
+ $this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to.
+ Sanitize::clean($this->data);
+ if(isset($this->data['Contact']['new'])) {
+ if($this->data['Contact']['new']) {
+ $this->Enquiry->Contact->save($this->data);
+ $this->data['Enquiry']['contact_id'] = $this->Enquiry->Contact->id;
+ }
+ }
+
+
+ if ($this->Enquiry->save($this->data)) {
+ $id = $this->Enquiry->id;
+ $this->__sendNewEnquiryEmail($id);
+ } else {
+ $this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
+ $this->__showPage2($this->Enquiry->Customer->findById($this->data['Enquiry']['customer_id']));
+ }
+ }
+ }
+
+ /* Internal function to display page 2 of the Add Enquiry Form Wizard
+ * to help make the flow-control logic of the add function clearer.
+ * */
+ function __showPage2($customer) {
+
+ /* Combine the first_name and last_name for the Contact Drop Down Box */
+ $contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
+ $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
+ $states = $this->Enquiry->State->find('list');
+ $countries = $this->Enquiry->Country->find('list', array('order'=> 'Country.name asc'));
+ $principles = $this->Enquiry->Principle->find('list', array('order' => 'Principle.name asc'));
+ $statuses = $this->Enquiry->Status->find('list');
+ $users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username')));
+ $this->set(compact('users', 'customers', 'states', 'countries', 'principles', 'statuses', 'contacts', 'customer'));
$this->set('step',2);
-
- $this->set('contacts', $contacts);
-
$customerAddresses = $this->Enquiry->BillingAddress->find('all', array('conditions'=>array('BillingAddress.customer_id' => $customer['Customer']['id'])));
$this->set('billing_addresses', $customerAddresses);
$this->set('shipping_addresses', $customerAddresses);
-
+ $this->set('errors', $this->Enquiry->invalidFields());
/* Feels like an ugly hack. But it gets the desired effect and it will do for now */
if(isset($customerAddresses[0]['BillingAddress'])) {
@@ -95,62 +135,9 @@ class EnquiriesController extends AppController {
$this->set('billing_addresses_list', 'No Addresses exist for this Customer. Please add one');
$this->set('shipping_addresses_list', 'No Addresses exist for this Customer. Please add one');
}
- $this->render();
-
- }
-
- if ( (!empty($this->data)) && ($this->data['Enquiry']['finished'] == 'true') ) {
- $this->Enquiry->set($this->data);
- if( !($this->Enquiry->validates()) ) {
- $customer = $this->Enquiry->Customer->findByName($this->data['Customer']['name']);
-
- /* Feels like an ugly hack. But it gets the desired effect and it will do for now */
-
- if(isset($customerAddresses[0]['BillingAddress'])) {
- foreach ($customerAddresses as $address) {
- $i = $address['BillingAddress']['id'];
- $billing_address_list[$i] = $address['BillingAddress']['address'].'
'.$address['BillingAddress']['city'].' '.$address['State']['name'].' '.$address['BillingAddress']['postcode'].'
'.up($address['Country']['name']).'
';
- }
- $this->set('billing_addresses_list', $billing_address_list);
- $this->set('shipping_addresses_list', $billing_address_list);
- }
- else {
- $this->set('billing_addresses_list', 'No Addresses exist for this Customer. Please add one');
- $this->set('shipping_addresses_list', 'No Addresses exist for this Customer. Please add one');
- }
-
-
- $this->set('customer', $customer);
- $contacts = $this->Enquiry->Contact->find('list', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
- $this->set('contacts', $contacts);
- $this->set('billing_addresses', $this->Enquiry->BillingAddress->find('list', array('conditions'=>array('BillingAddress.customer_id' => $customer['Customer']['id']))));
- $this->set('shipping_addresses', $this->Enquiry->ShippingAddress->find('list', array('conditions'=>array('ShippingAddress.customer_id' => $customer['Customer']['id']))));
- $this->set('errors', $this->Enquiry->invalidFields());
- $this->set('step',2);
- $this->render();
-
-
- }
- else {
- $this->Enquiry->create();
-
- $enquiryno = $this->__generateEnquiryNumber($this->data);
- $this->data['Enquiry']['title'] = $enquiryno;
- $principle = $this->Enquiry->Principle->findById($this->data['Enquiry']['principle_id']);
- $this->data['Enquiry']['principle_code'] = $principle['Principle']['code']; //Store which principle code this enquiry belongs to.
- Sanitize::clean($this->data);
- }
-
- if ($this->Enquiry->save($this->data)) {
- $id = $this->Enquiry->id;
- $this->__sendNewEnquiryEmail($id);
- } else {
- $this->Session->setFlash(__('The Enquiry could not be saved. Please, try again.', true));
- }
- }
-
}
+
/* Generate Enquiry number and return it as a string */
function __generateEnquiryNumber($data) {
@@ -278,7 +265,7 @@ class EnquiriesController extends AppController {
$this->redirect(array('action'=>'view/'.$id), null, false);
}
else {
- $this->Session->setFlash(__('The Enquiry has been added abut email to the contact has NOT been sent. Something went wrong.', true));
+ $this->Session->setFlash(__('The Enquiry has been added but email to the contact has NOT been sent. Something went wrong.', true));
$this->redirect(array('action'=>'view/'.$id), null, false);
$this->set('smtp-errors', $this->Email->smtpError);
}
@@ -306,7 +293,9 @@ class EnquiriesController extends AppController {
$enquiry = $this->Enquiry->read(null, $id);
$users = $this->Enquiry->User->find('list', array('fields' => array('User.id', 'User.username')));
$customer = $this->Enquiry->Customer->findById($enquiry['Enquiry']['customer_id']);
- $contacts = $this->Enquiry->Contact->find('list', array('conditions' => array('Contact.customer_id' => $enquiry['Enquiry']['customer_id'] )));
+
+ $contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $enquiry['Enquiry']['customer_id'])));
+ $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
$state = $this->Enquiry->State->findById($enquiry['Enquiry']['state_id']);
$country = $this->Enquiry->Country->findById($enquiry['Enquiry']['country_id']);
$principle = $this->Enquiry->Principle->findById($enquiry['Enquiry']['principle_id']);
diff --git a/models/address.php b/models/address.php
index 63d91e1c..d0f698c7 100755
--- a/models/address.php
+++ b/models/address.php
@@ -3,7 +3,45 @@ class Address extends AppModel {
var $name = 'Address';
-
+ var $validate = array(
+ 'address' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please Enter the Addess',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+
+ 'city' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please Enter the City',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+ 'state_id' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please select the State',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+ 'postcode' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please enter the Post Code',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+ 'country_id' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please select the Country',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+ 'type' => array(
+ 'rule' => array('notEmpty'),
+ 'message' => 'Please select the Type of Address',
+ 'required' => true,
+ 'allowEmpty' => false
+ ),
+ );
diff --git a/models/enquiry.php b/models/enquiry.php
index d4f60863..f30fe428 100755
--- a/models/enquiry.php
+++ b/models/enquiry.php
@@ -10,7 +10,11 @@ class Enquiry extends AppModel {
'message' => 'User ID must be selected',
'on' => 'create'
),
-
+ 'title' => array(
+ 'rule' => 'notEmpty',
+ 'required' => true,
+ 'on' => 'create'
+ ),
'customer_id' => array(
'rule' => 'numeric',
'required' => true,
@@ -24,6 +28,7 @@ class Enquiry extends AppModel {
'message' => 'Must choose a Contact for this Enquiry',
'on' => 'create'
),
+
'customer_id' => array(
'rule' => 'numeric',
'required' => true,
@@ -65,7 +70,7 @@ class Enquiry extends AppModel {
'gst' => array(
'rule' => 'numeric',
'required' => true,
- 'message' => 'Must slect whether GST is applicable for this Enquiry',
+ 'message' => 'Must select whether GST is applicable for this Enquiry',
'on' => 'create'
)
);
diff --git a/tmp/.gitignore b/tmp/.gitignore
new file mode 100644
index 00000000..150f68c8
--- /dev/null
+++ b/tmp/.gitignore
@@ -0,0 +1 @@
+*/*
diff --git a/views/addresses/add_another.ctp b/views/addresses/add_another.ctp
new file mode 100644
index 00000000..97354cbd
--- /dev/null
+++ b/views/addresses/add_another.ctp
@@ -0,0 +1,16 @@
+ echo $ajax->link('Remove this', array('controller' => 'addresses', 'action' => 'remove_another', $increment), array('update' => 'addresses'.$increment)); ?>
+ input("Address.$increment.address", array('label' => 'Address', 'title' => 'The Address to be added'));
+ echo $form->input("Address.$increment.city", array('label' => 'City', 'title' => 'Name of the City/Suburb for this Address'));
+ echo $form->input("Address.$increment.state_id", array('value' => $states));
+ echo $form->input("Address.$increment.postcode", array('label' => 'Post Code', 'title' => 'The Post Code for this Address. Eg. 2015 for Alexandria'));
+ echo $form->input("Address.$increment.country_id", array('value' => $countries));
+ echo $form->input("Address.$increment.type", array('label' => 'Address Type (Billing,Shipping or Both)', 'options' => array('Billing','Shipping', 'Both Shipping and Billing', 'Other')));
+
+
+ $next = $increment;
+ $next++;
+ echo $ajax->link('Add another Address to this New Customer', array('controller' => 'addresses', 'action' => 'add_another',$next), array('update'=>'addresses'.$next));
+ ?>
+
| sort('id');?> | -sort('name');?> | sort('address');?> | sort('city');?> | sort('state_id');?> | @@ -30,9 +29,6 @@ foreach ($addresses as $address):- | - - | diff --git a/views/addresses/remove_another.ctp b/views/addresses/remove_another.ctp new file mode 100644 index 00000000..f169671b --- /dev/null +++ b/views/addresses/remove_another.ctp @@ -0,0 +1,6 @@ + + +if($increment == 0) { + echo $ajax->link('Add an Address to this New Customer', array('controller' => 'addresses', 'action' => 'add_another',0), array('update'=>'addresses0')); +} +?> diff --git a/views/contacts/add.ctp b/views/contacts/add.ctp index bb0f14fa..18515e9c 100755 --- a/views/contacts/add.ctp +++ b/views/contacts/add.ctp @@ -4,7 +4,6 @@ input('customer_id'); - echo $form->input('name'); echo $form->input('first_name'); echo $form->input('last_name'); echo $form->input('email'); diff --git a/views/contacts/add_another.ctp b/views/contacts/add_another.ctp new file mode 100644 index 00000000..ca4634a0 --- /dev/null +++ b/views/contacts/add_another.ctp @@ -0,0 +1,19 @@ + + echo $ajax->link('Remove this', array('controller' => 'contacts', 'action' => 'remove_another', $increment), array('update' => 'contacts'.$increment)); + + ?> + + + echo $form->input("Contact.$increment.first_name"); + echo $form->input("Contact.$increment.last_name"); + echo $form->input("Contact.$increment.email"); + echo $form->input("Contact.$increment.phone"); + echo $form->input("Contact.$increment.mobile"); + echo $form->input("Contact.$increment.fax"); + echo $form->input("Contact.$increment.notes"); + + $next = $increment; + $next++; + echo $ajax->link('Add another Contact to this New Customer', array('controller' => 'contacts', 'action' => 'add_another',$next), array('update'=>'contacts'.$next)); + ?> + diff --git a/views/contacts/add_one.ctp b/views/contacts/add_one.ctp new file mode 100644 index 00000000..86bb0273 --- /dev/null +++ b/views/contacts/add_one.ctp @@ -0,0 +1,17 @@ + + + echo $ajax->link('Remove this', array('controller' => 'contacts', 'action' => 'remove_one', $customerid), array('update' => 'contact')); + + ?> + + + echo $form->input("Contact.new", array('type'=>'hidden', 'value' => 'yes')); + echo $form->input("Contact.first_name"); + echo $form->input("Contact.last_name"); + echo $form->input("Contact.email"); + echo $form->input("Contact.phone"); + echo $form->input("Contact.mobile"); + echo $form->input("Contact.fax"); + echo $form->input("Contact.notes"); + echo $form->input("Contact.customer_id", array('type'=>'hidden', 'value' => $customerid)); + ?> diff --git a/views/contacts/index.ctp b/views/contacts/index.ctp index 484771f5..14782ce2 100755 --- a/views/contacts/index.ctp +++ b/views/contacts/index.ctp @@ -10,7 +10,6 @@ echo $paginator->counter(array( | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sort('customer_id');?> | sort('id');?> | -sort('name');?> | sort('first_name');?> | sort('last_name');?> | sort('email');?> | @@ -34,9 +33,7 @@ foreach ($contacts as $contact):- | - - | +diff --git a/views/contacts/remove_another.ctp b/views/contacts/remove_another.ctp new file mode 100644 index 00000000..beb40dea --- /dev/null +++ b/views/contacts/remove_another.ctp @@ -0,0 +1,7 @@ + + +if($increment == 0) { + echo $ajax->link('Add A Contact to this New Customer', array('controller' => 'contacts', 'action' => 'add_another',0), array('update'=>'contacts0')); +} +?> + diff --git a/views/contacts/remove_one.ctp b/views/contacts/remove_one.ctp new file mode 100644 index 00000000..72888d3d --- /dev/null +++ b/views/contacts/remove_one.ctp @@ -0,0 +1,4 @@ + +echo $form->input('contact_id', array('options' => $contacts)); +echo $ajax->link('New Contact', array('controller' => 'contacts', 'action' => 'add_one', $customerid), array('update'=>'contact')); +?> diff --git a/views/customers/add.ctp b/views/customers/add.ctp index f7dcf50c..2a06716c 100755 --- a/views/customers/add.ctp +++ b/views/customers/add.ctp @@ -1,37 +1,40 @@ + + | |||||||||
| + | link($contact['email'], 'mailto:'.$contact['email']);?> | diff --git a/views/elements/enquiry_table.ctp b/views/elements/enquiry_table.ctp index 4f817d49..208fc53c 100644 --- a/views/elements/enquiry_table.ctp +++ b/views/elements/enquiry_table.ctp @@ -88,8 +88,8 @@ foreach ($enquiries as $enquiry): | link($enquiry['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $enquiry['Customer']['id'])); ?> | -- link($enquiry['Contact']['name'], array('controller'=> 'contacts', 'action'=>'view', $enquiry['Contact']['id'])); ?> + | + link($enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'], array('controller'=> 'contacts', 'action'=>'view', $enquiry['Contact']['id'])); ?> |
//BCC address to Con is hardcoded in here. ?>
diff --git a/views/enquiries/add.ctp b/views/enquiries/add.ctp
index a77df2c6..bcafd6d4 100755
--- a/views/enquiries/add.ctp
+++ b/views/enquiries/add.ctp
@@ -1,3 +1,10 @@
+
+
+Tip: You can add a new Contact to an Existing Customer while creating the enquiry. If the Contact you want to assign to the enquiry
+doesn't appear in the drop down list, click 'New Contact'
+
+
+
create('Enquiry');?>
|