Finished implementation of contact edit. This is now saving everything to the database. I hope to now leverage it for a new contact. This checkin includes a bit of code in the sitelink2pmgr script that sets the customer display name. It should have been checked in several revisions ago.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@217 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -177,7 +177,7 @@ CREATE TABLE `pmgr_contact_phones` (
|
|||||||
`ext` VARCHAR(6) DEFAULT NULL,
|
`ext` VARCHAR(6) DEFAULT NULL,
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
KEY `number_key` (`phone`),
|
UNIQUE KEY `number_key` (`phone`, `ext`),
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ CREATE TABLE `pmgr_contact_emails` (
|
|||||||
`email` VARCHAR(128) NOT NULL,
|
`email` VARCHAR(128) NOT NULL,
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
KEY `email_key` (`email`),
|
UNIQUE KEY `email_key` (`email`),
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ CREATE TABLE `pmgr_contact_emails` (
|
|||||||
DROP TABLE IF EXISTS `pmgr_contacts_methods`;
|
DROP TABLE IF EXISTS `pmgr_contacts_methods`;
|
||||||
CREATE TABLE `pmgr_contacts_methods` (
|
CREATE TABLE `pmgr_contacts_methods` (
|
||||||
`contact_id` INT(10) UNSIGNED NOT NULL,
|
`contact_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`method` ENUM('POST',
|
`method` ENUM('ADDRESS',
|
||||||
'PHONE',
|
'PHONE',
|
||||||
'EMAIL')
|
'EMAIL')
|
||||||
NOT NULL,
|
NOT NULL,
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ addRow('contact_addresses',
|
|||||||
addRow('contacts_methods',
|
addRow('contacts_methods',
|
||||||
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
||||||
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
||||||
'method' => 'POST',
|
'method' => 'ADDRESS',
|
||||||
'type' => 'MAIN',
|
'type' => 'MAIN',
|
||||||
'preference' => 'PRIMARY' },
|
'preference' => 'PRIMARY' },
|
||||||
1);
|
1);
|
||||||
@@ -292,7 +292,7 @@ addRow('contact_addresses',
|
|||||||
addRow('contacts_methods',
|
addRow('contacts_methods',
|
||||||
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
||||||
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
||||||
'method' => 'POST',
|
'method' => 'ADDRESS',
|
||||||
'type' => 'HOME',
|
'type' => 'HOME',
|
||||||
'preference' => 'ALTERNATE' },
|
'preference' => 'ALTERNATE' },
|
||||||
1);
|
1);
|
||||||
@@ -306,7 +306,7 @@ addRow('contact_addresses',
|
|||||||
addRow('contacts_methods',
|
addRow('contacts_methods',
|
||||||
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
{ 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'},
|
||||||
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
||||||
'method' => 'POST',
|
'method' => 'ADDRESS',
|
||||||
'type' => 'HOME',
|
'type' => 'HOME',
|
||||||
'preference' => 'ALTERNATE' },
|
'preference' => 'ALTERNATE' },
|
||||||
1);
|
1);
|
||||||
@@ -757,7 +757,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
addRow('contacts_methods',
|
addRow('contacts_methods',
|
||||||
{ 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'},
|
{ 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'},
|
||||||
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
||||||
'method' => 'POST',
|
'method' => 'ADDRESS',
|
||||||
'type' => 'HOME',
|
'type' => 'HOME',
|
||||||
'preference' => 'PRIMARY' },
|
'preference' => 'PRIMARY' },
|
||||||
1);
|
1);
|
||||||
@@ -823,7 +823,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
addRow('contacts_methods',
|
addRow('contacts_methods',
|
||||||
{ 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'},
|
{ 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'},
|
||||||
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'},
|
||||||
'method' => 'POST',
|
'method' => 'ADDRESS',
|
||||||
'type' => 'MAIN',
|
'type' => 'MAIN',
|
||||||
'preference' => 'PRIMARY' },
|
'preference' => 'PRIMARY' },
|
||||||
1);
|
1);
|
||||||
@@ -1536,6 +1536,8 @@ buildTables();
|
|||||||
######################################################################
|
######################################################################
|
||||||
## Security Deposits
|
## Security Deposits
|
||||||
|
|
||||||
|
print(STDERR "Set Lease Security Deposits...\n");
|
||||||
|
|
||||||
$query = "SELECT L.LedgerID, L.UnitID, C.ChargeAmount FROM TenantLedger L INNER JOIN Charges C ON C.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' AND C.ChargeDescription = 'Security Deposit' ORDER BY UnitID";
|
$query = "SELECT L.LedgerID, L.UnitID, C.ChargeAmount FROM TenantLedger L INNER JOIN Charges C ON C.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' AND C.ChargeDescription = 'Security Deposit' ORDER BY UnitID";
|
||||||
|
|
||||||
foreach $row (@{query($sdbh, $query)}) {
|
foreach $row (@{query($sdbh, $query)}) {
|
||||||
@@ -1547,16 +1549,23 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
## Ledger Assignments
|
## Contact Display Names
|
||||||
|
|
||||||
# $query =
|
print(STDERR "Set Contact Display Names...\n");
|
||||||
# "UPDATE pmgr_accounts A, pmgr_ledgers L SET A.ledger_id = L.id" .
|
|
||||||
# " WHERE A.id = L.account_id";
|
$query =
|
||||||
# query($db_handle, $query);
|
"UPDATE pmgr_contacts".
|
||||||
|
" SET display_name =" .
|
||||||
|
" IF(first_name IS NOT NULL AND last_name IS NOT NULL," .
|
||||||
|
" CONCAT(last_name, ', ', first_name)," .
|
||||||
|
" IF(first_name IS NOT NULL, first_name, last_name))";
|
||||||
|
query($db_handle, $query);
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
## Unit Lease Assignments
|
## Unit Lease Assignments
|
||||||
|
|
||||||
|
print(STDERR "Set Current Leases...\n");
|
||||||
|
|
||||||
$query = "UPDATE pmgr_units U, pmgr_leases L
|
$query = "UPDATE pmgr_units U, pmgr_leases L
|
||||||
SET U.`current_lease_id` = L.id
|
SET U.`current_lease_id` = L.id
|
||||||
WHERE L.unit_id = U.id AND L.close_date IS NULL";
|
WHERE L.unit_id = U.id AND L.close_date IS NULL";
|
||||||
|
|||||||
@@ -100,8 +100,61 @@ class ContactsController extends AppController {
|
|||||||
|
|
||||||
function edit($id = null) {
|
function edit($id = null) {
|
||||||
if (isset($this->data)) {
|
if (isset($this->data)) {
|
||||||
pr($this->data);
|
|
||||||
$this->autoRender = false;
|
if (isset($this->params['form']['cancel'])) {
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all associated ContactMethods, as it ensures
|
||||||
|
// any entries deleted by the user actually get deleted
|
||||||
|
// in the system. We'll recreate the needed ones anyway.
|
||||||
|
$this->Contact->ContactsMethod->deleteAll
|
||||||
|
(array('contact_id' => $this->data['Contact']['id']), false);
|
||||||
|
|
||||||
|
// Iterate each type of contact method, adding them into
|
||||||
|
// the database as needed and associating with this contact.
|
||||||
|
foreach (array('phone', 'address', 'email') AS $type) {
|
||||||
|
$class = 'Contact' . ucfirst($type);
|
||||||
|
$enum = strtoupper($type);
|
||||||
|
|
||||||
|
// Nothing to do if this contact method isn't used
|
||||||
|
if (!isset($this->data[$class]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Go through each entry of this contact method
|
||||||
|
foreach ($this->data[$class] AS &$item) {
|
||||||
|
|
||||||
|
// If the user has entered all new data, we need to
|
||||||
|
// save that as a brand new entry.
|
||||||
|
if (isset($item['source']) && $item['source'] === 'new') {
|
||||||
|
unset($item['id']);
|
||||||
|
$I = new $class();
|
||||||
|
$I->create();
|
||||||
|
if (!$I->save($item, false)) {
|
||||||
|
pr("$enum SAVE FAILED");
|
||||||
|
$this->Session->setFlash("$enum SAVE FAILED", true);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$item['id'] = $I->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the ContactsMethod to reflect the appropriate IDs
|
||||||
|
$item['ContactsMethod']['contact_id'] = $this->data['Contact']['id'];
|
||||||
|
$item['ContactsMethod']['method_id'] = $item['id'];
|
||||||
|
$item['ContactsMethod']['method'] = $enum;
|
||||||
|
|
||||||
|
// Save the relationship between contact and phone/email/address
|
||||||
|
$CM = new ContactsMethod();
|
||||||
|
if (!$CM->save($item['ContactsMethod'], false)) {
|
||||||
|
die("ContactsMethod Save FAILED!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now that the work is done, let the user view the updated contact
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
||||||
|
//$this->autoRender = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,16 +177,22 @@ class ContactsController extends AppController {
|
|||||||
|
|
||||||
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
|
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
|
||||||
unset($phone_types[0]);
|
unset($phone_types[0]);
|
||||||
//$phone_types = array_combine($phone_types, array_map('ucfirst', array_map('strtolower', $phone_types)));
|
// REVISIT <AP> 20090705
|
||||||
|
// Use this to have a mixed case enum
|
||||||
|
// array_map('ucfirst', array_map('strtolower', $phone_types))
|
||||||
$phone_types = array_combine($phone_types, $phone_types);
|
$phone_types = array_combine($phone_types, $phone_types);
|
||||||
$this->set(compact('phone_types'));
|
$this->set(compact('phone_types'));
|
||||||
|
|
||||||
$method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods'));
|
$method_types = array_flip($this->Contact->getEnumValues
|
||||||
|
('type',
|
||||||
|
$this->Contact->tablePrefix . 'contacts_methods'));
|
||||||
unset($method_types[0]);
|
unset($method_types[0]);
|
||||||
$method_types = array_combine($method_types, $method_types);
|
$method_types = array_combine($method_types, $method_types);
|
||||||
$this->set(compact('method_types'));
|
$this->set(compact('method_types'));
|
||||||
|
|
||||||
$method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods'));
|
$method_preferences = array_flip($this->Contact->getEnumValues
|
||||||
|
('preference',
|
||||||
|
$this->Contact->tablePrefix . 'contacts_methods'));
|
||||||
unset($method_preferences[0]);
|
unset($method_preferences[0]);
|
||||||
$method_preferences = array_combine($method_preferences, $method_preferences);
|
$method_preferences = array_combine($method_preferences, $method_preferences);
|
||||||
$this->set(compact('method_preferences'));
|
$this->set(compact('method_preferences'));
|
||||||
|
|||||||
@@ -9,13 +9,17 @@ class Contact extends AppModel {
|
|||||||
'id_exp' => array('date')
|
'id_exp' => array('date')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod',
|
||||||
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Customer',
|
'Customer',
|
||||||
'ContactAddress' => array(
|
'ContactAddress' => array(
|
||||||
'joinTable' => 'contacts_methods',
|
'joinTable' => 'contacts_methods',
|
||||||
'associationForeignKey' => 'method_id',
|
'associationForeignKey' => 'method_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'POST'",
|
'conditions' => "method = 'ADDRESS'",
|
||||||
),
|
),
|
||||||
'ContactPhone' => array(
|
'ContactPhone' => array(
|
||||||
'joinTable' => 'contacts_methods',
|
'joinTable' => 'contacts_methods',
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ class ContactAddress extends AppModel {
|
|||||||
'postcode' => array('postal')
|
'postcode' => array('postal')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Contact' => array(
|
'Contact' => array(
|
||||||
'className' => 'Contact',
|
'className' => 'Contact',
|
||||||
@@ -14,7 +21,7 @@ class ContactAddress extends AppModel {
|
|||||||
'foreignKey' => 'method_id',
|
'foreignKey' => 'method_id',
|
||||||
'associationForeignKey' => 'contact_id',
|
'associationForeignKey' => 'contact_id',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
'conditions' => "method = 'POST'",
|
'conditions' => "method = 'ADDRESS'",
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ class ContactPhone extends AppModel {
|
|||||||
'ext' => array('numeric')
|
'ext' => array('numeric')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
'Contact' => array(
|
'Contact' => array(
|
||||||
'className' => 'Contact',
|
'className' => 'Contact',
|
||||||
|
|||||||
25
site/models/contacts_method.php
Normal file
25
site/models/contacts_method.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
class ContactsMethod extends AppModel {
|
||||||
|
var $primaryKey = false;
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'Contact',
|
||||||
|
'ContactAddress' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
'ContactPhone' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
'ContactEmail' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'EMAIL'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -40,7 +40,7 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
|
|||||||
$stype = strtolower($sname);
|
$stype = strtolower($sname);
|
||||||
$div .=
|
$div .=
|
||||||
'<INPUT TYPE="radio" ' . "\n" .
|
'<INPUT TYPE="radio" ' . "\n" .
|
||||||
//' NAME="data[Contact'.ucfirst($type).'][%{id}][source]"' . "\n" .
|
' NAME="data[Contact'.ucfirst($type).'][%{id}][source]"' . "\n" .
|
||||||
' ONCLICK="switchMethodSource(%{id}, '."'{$type}', '{$stype}'".')"' . "\n" .
|
' ONCLICK="switchMethodSource(%{id}, '."'{$type}', '{$stype}'".')"' . "\n" .
|
||||||
' CLASS="'.$type.'-method-%{id}-source" ' . "\n" .
|
' CLASS="'.$type.'-method-%{id}-source" ' . "\n" .
|
||||||
' ID="'.$type.'-method-%{id}-source-'.$stype.'"' . "\n" .
|
' ID="'.$type.'-method-%{id}-source-'.$stype.'"' . "\n" .
|
||||||
@@ -70,24 +70,28 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
|
|||||||
// BEGIN method-div
|
// BEGIN method-div
|
||||||
'<div id="'.$type.'-%{id}-method-div"' . "\n" .
|
'<div id="'.$type.'-%{id}-method-div"' . "\n" .
|
||||||
|
|
||||||
|
/* (isset($values) */
|
||||||
|
/* ? '<input type="hidden" name="data[Contact'.ucfirst($type).'][%{id}][ContactsMethod][id]" value="'.$values['ContactsMethod']['id'].'"/>' . "\n" */
|
||||||
|
/* : '') . */
|
||||||
|
|
||||||
$obj->element
|
$obj->element
|
||||||
('form_table',
|
('form_table',
|
||||||
array('class' => "item contact-{$type} entry",
|
array('class' => "item contact-{$type} entry",
|
||||||
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.Method',
|
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.ContactsMethod',
|
||||||
'fields' => array
|
'fields' => array
|
||||||
|
(
|
||||||
('type' => array
|
'preference' => array
|
||||||
('opts' => array
|
|
||||||
('options' => $obj->varstore['methodTypes'],
|
|
||||||
'selected' => (isset($values) ? $values['ContactsMethod']['type'] : null),
|
|
||||||
)),
|
|
||||||
|
|
||||||
'preferences' => array
|
|
||||||
('opts' => array
|
('opts' => array
|
||||||
('options' => $obj->varstore['methodPreferences'],
|
('options' => $obj->varstore['methodPreferences'],
|
||||||
'selected' => (isset($values) ? $values['ContactsMethod']['preference'] : null),
|
'selected' => (isset($values) ? $values['ContactsMethod']['preference'] : null),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
'type' => array
|
||||||
|
('opts' => array
|
||||||
|
('options' => $obj->varstore['methodTypes'],
|
||||||
|
'selected' => (isset($values) ? $values['ContactsMethod']['type'] : null),
|
||||||
|
)),
|
||||||
|
|
||||||
'comment' => array
|
'comment' => array
|
||||||
('opts' => array
|
('opts' => array
|
||||||
('value' => (isset($values) ? $values['ContactsMethod']['comment'] : null),
|
('value' => (isset($values) ? $values['ContactsMethod']['comment'] : null),
|
||||||
@@ -175,9 +179,6 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($type === 'email') {
|
elseif ($type === 'email') {
|
||||||
/* [email] => abijah@PerkinsHouse.com */
|
|
||||||
/* [comment] => */
|
|
||||||
|
|
||||||
if ($stype === 'existing') {
|
if ($stype === 'existing') {
|
||||||
$fields = array
|
$fields = array
|
||||||
('id' => array('name' => 'Email',
|
('id' => array('name' => 'Email',
|
||||||
@@ -402,6 +403,6 @@ echo($this->element
|
|||||||
; // Alignment
|
; // Alignment
|
||||||
|
|
||||||
echo $form->submit('Update') . "\n";
|
echo $form->submit('Update') . "\n";
|
||||||
echo $form->submit('Cancel') . "\n";
|
echo $form->submit('Cancel', array('name' => 'cancel')) . "\n";
|
||||||
echo $form->end() . "\n";
|
echo $form->end() . "\n";
|
||||||
echo '</div>' . "\n";
|
echo '</div>' . "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user