From 3e60f8d45e02a8e8929df62b19fab461e1ac247a Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 6 Jul 2009 03:01:28 +0000 Subject: [PATCH] Implemented ability to add a customer, and fixed the problem with flagging of the primary contact. git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@220 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/customers_controller.php | 5 +++ site/models/customer.php | 3 +- site/views/customers/edit.ctp | 50 +++++++++++++++++++---- site/views/elements/form_table.ctp | 2 +- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index 2f2e58d..e266817 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -6,6 +6,7 @@ class CustomersController extends AppController { array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')), array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')), array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')), + array('name' => 'Add Tenant', 'url' => array('controller' => 'customers', 'action' => 'add')), ); //var $components = array('RequestHandler'); @@ -286,6 +287,9 @@ class CustomersController extends AppController { return; } + $this->data['Customer']['primary_contact_id'] + = $this->data['Contact'][$this->data['Customer']['primary_contact_entry']]['id']; + $this->Customer->create(); if (!$this->Customer->save($this->data, false)) { pr("CUSTOMER SAVE FAILED"); @@ -367,6 +371,7 @@ class CustomersController extends AppController { */ function add() { + $this->edit(); } /************************************************************************** diff --git a/site/models/customer.php b/site/models/customer.php index 6de7d3c..de625c3 100644 --- a/site/models/customer.php +++ b/site/models/customer.php @@ -159,7 +159,8 @@ class Customer extends AppModel { ('contain' => array (// Models 'Contact' => - array(// Models + array('order' => array('Contact.display_name'), + // Models 'ContactPhone', 'ContactEmail', 'ContactAddress', diff --git a/site/views/customers/edit.ctp b/site/views/customers/edit.ctp index 58275ce..a68f595 100644 --- a/site/views/customers/edit.ctp +++ b/site/views/customers/edit.ctp @@ -15,7 +15,7 @@ $this->varstore = compact('contactTypes', 'contacts'); * Javascript */ -function customerContactDiv($obj, $values = null) { +function customerContactDiv($obj, $values = null, $primary = false) { $div = // BEGIN type-div @@ -67,12 +67,31 @@ function customerContactDiv($obj, $values = null) { // BEGIN contact-div '
' . "\n" . */ +/* ' ' . "\n" . */ + $obj->element ('form_table', array('class' => "item contact entry", 'field_prefix' => 'Contact.%{id}.ContactsCustomer', 'fields' => array ( + 'Customer.primary_contact_entry' => array + ('name' => 'Primary Contact', + 'no_prefix' => true, + 'opts' => array + ('type' => 'radio', + 'options' => array('%{id}' => false), + 'value' => ($primary ? '%{id}' : 'bogus-value-to-suppress-hidden-input'), + )), + 'type' => array ('opts' => array ('options' => $obj->varstore['contactTypes'], @@ -171,9 +190,10 @@ function customerContactTypeDiv($obj, $stype, $values = null) { function addContact(flash) { addDiv('contact-entry-id', 'contact', 'contacts', flash, ); } @@ -185,14 +205,26 @@ function customerContactTypeDiv($obj, $stype, $values = null) { data['Contact'] AS $contact): ?> addDiv('contact-entry-id', 'contact', 'contacts', false, data['Customer']['primary_contact_id'] + ), + null, + ' '); ?> ); + + if ($("#contact-entry-id").val() == 1) { + addDiv('contact-entry-id', 'contact', 'contacts', false, + ); + } } function switchContactSource(id, source) { diff --git a/site/views/elements/form_table.ctp b/site/views/elements/form_table.ctp index a7bd801..c3c15bc 100644 --- a/site/views/elements/form_table.ctp +++ b/site/views/elements/form_table.ctp @@ -16,7 +16,7 @@ foreach ($fields AS $field => $config) { if (!isset($config['opts'])) $config['opts'] = null; - if (isset($field_prefix)) + if (isset($field_prefix) && !isset($config['no_prefix'])) $field = $field_prefix . '.' . $field; $config['opts']['label'] = false;