Implemented edit functionality for customer. Like with contacts, the interface leaves much to be desired, since it's limited in functionality. Namely, you can add a contact, but you can't add contact methods (phone/mail/email). Also, it doesn't use jqGrid to present the selection choices, and so the user is stuck with the fields we've chosen to display, as well as the sort order we've chosen. Enhancement is possible someday, but for now, it gets the job done.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@219 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-06 02:06:23 +00:00
parent 207808d6d5
commit e150237fd8
5 changed files with 379 additions and 1 deletions

View File

@@ -268,6 +268,107 @@ class CustomersController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: edit
* - Edit customer information
*/
function edit($id = null) {
if (isset($this->data)) {
if (isset($this->params['form']['cancel'])) {
if (isset($this->data['Customer']['id']))
$this->redirect(array('action'=>'view', $this->data['Customer']['id']));
else
$this->redirect(array('action'=>'index'));
return;
}
$this->Customer->create();
if (!$this->Customer->save($this->data, false)) {
pr("CUSTOMER SAVE FAILED");
$this->Session->setFlash("CUSTOMER SAVE FAILED", true);
return;
}
$this->data['Customer']['id'] = $this->Customer->id;
// Remove all associated Customer Contacts, as it ensures
// any entries deleted by the user actually get deleted
// in the system. We'll recreate the needed ones anyway.
$this->Customer->ContactsCustomer->deleteAll
(array('customer_id' => $this->data['Customer']['id']), false);
if (!isset($this->data['Contact']))
$this->data['Contact'] = array();
// Go through each entry of this customer method
foreach ($this->data['Contact'] AS &$contact) {
// Check if the user has entered a brand new contact
if (isset($contact['source']) && $contact['source'] === 'new') {
unset($contact['id']);
$I = new Contact();
$I->create();
if (!$I->save($contact, false)) {
pr("CONTACT SAVE FAILED");
$this->Session->setFlash("CONTACT SAVE FAILED", true);
continue;
}
$contact['id'] = $I->id;
}
// Update the ContactsCustomer to reflect the appropriate IDs
$contact['ContactsCustomer']['customer_id'] = $this->data['Customer']['id'];
$contact['ContactsCustomer']['contact_id'] = $contact['id'];
// Save the relationship between customer and contact
$CM = new ContactsCustomer();
if (!$CM->save($contact['ContactsCustomer'], false)) {
die("ContactsCustomer Save FAILED!");
}
}
// Now that the work is done, let the user view the updated customer
//$this->redirect(array('action'=>'view', $this->data['Customer']['id']));
$this->autoRender = false;
return;
}
if ($id) {
$this->data = $this->Customer->details($id);
$title = $this->data['Customer']['name'] . " : Edit";
}
else {
$title = "Enter New Customer";
$this->data = array('Contact' => array(), 'PrimaryContact' => null);
}
$contact_types = array_flip($this->Customer->ContactsCustomer->getEnumValues('type'));
unset($contact_types[0]);
$contact_types = array_combine($contact_types, $contact_types);
$this->set(compact('contact_types'));
$contacts = $this->Customer->Contact->contactList();
$this->set(compact('contacts'));
// Prepare to render.
//pr($this->data);
$this->set(compact('title'));
$this->render('edit');
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: add
* - Add a new customer
*/
function add() {
}
/**************************************************************************
**************************************************************************
**************************************************************************