Adding Invoices and Jobs to Customer view

This commit is contained in:
Karl Cordes 2011-03-14 11:21:56 +11:00
parent 45ac2e734b
commit 740de15efc
17 changed files with 404 additions and 319 deletions

View file

@ -34,6 +34,8 @@ class CustomersController extends AppController {
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.customer_id' => $id)));
$this->set('contacts', $this->Customer->Contact->find('all', array('conditions' => array('customer_id' => $id), 'order' => 'Contact.last_name ASC')));
$this->set('invoices', $this->Customer->Invoice->find('all', array('conditions'=>array('Invoice.customer_id'=>$id), 'order'=> 'Invoice.id DESC')));
$this->set('jobs', $this->Customer->Job->find('all', array('conditions'=>array('Job.customer_id'=>$id), 'order'=> 'Job.id DESC')));
$statuses = $this->Customer->Enquiry->Status->find('all', array('recursive'=>0));

View file

@ -55,6 +55,12 @@ class EmailAttachmentsController extends AppController {
$contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']);
if($file['EmailAttachment']['type'] == 'text/plain') {
$contents = nl2br($contents, true);
}
$this->set('contents', $contents);
}

View file

@ -488,9 +488,14 @@ class EnquiriesController extends AppController {
'Contact.last_name LIKE' => "%$searchQuery%"));
}
$customerResults = $this->Enquiry->Customer->find('all', array('conditions' => $custConditions, 'recursive'=>0));
$enquiryResults = $this->Enquiry->find('all', array('conditions'=>$enqConditions, 'recursive'=>0));
$contactResults = $this->Enquiry->Contact->find('all', array('conditions'=>$contactConditions, 'recursive'=>0));
$customerFields = array('Customer.id', 'Customer.name');
$enquiryFields = array('Enquiry.id', 'Enquiry.title', 'Customer.name', 'Customer.id');
$contactFields = array('Contact.id', 'Contact.type','Contact.customer_id', 'Contact.first_name','Contact.last_name', 'Customer.name');
$customerResults = $this->Enquiry->Customer->find('all', array('conditions' => $custConditions, 'recursive'=>0, 'fields'=>$customerFields));
$enquiryResults = $this->Enquiry->find('all', array('conditions'=>$enqConditions, 'recursive'=>0, 'fields'=>$enquiryFields));
$contactResults = $this->Enquiry->Contact->find('all', array('conditions'=>$contactConditions, 'recursive'=>0, 'fields'=>$contactFields));
$searchDone = true;

View file

@ -2,7 +2,7 @@
class InvoicesController extends AppController {
var $name = 'Invoices';
var $helpers = array('Html', 'Form', 'Time');
var $helpers = array('Html', 'Form', 'Time', 'Text','Javascript');
var $paginate = array(
@ -21,7 +21,17 @@ class InvoicesController extends AppController {
$this->Session->setFlash(__('Invalid Invoice.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('invoice', $this->Invoice->read(null, $id));
$invoice = $this->Invoice->read(null, $id);
$this->set('invoice', $invoice);
$emailIDs = array();
foreach($invoice['Email'] as $email) {
$emailIDs[] = $email['id'];
}
$emails = $this->Invoice->Email->find('all', array('conditions'=>array('Email.id'=>$emailIDs)));
$this->set('emails', $emails);
}

View file

@ -2,7 +2,7 @@
class JobsController extends AppController {
var $name = 'Jobs';
var $helpers = array('Html', 'Form');
var $helpers = array('Html', 'Form', 'Text', 'Javascript');
var $components = array('RequestHandler');
@ -27,6 +27,17 @@ class JobsController extends AppController {
}
$job = $this->Job->read(null, $id);
$emailIDs = array();
foreach($job['Email'] as $email) {
$emailIDs[] = $email['id'];
}
$emails = $this->Job->Email->find('all', array('conditions'=>array('Email.id'=>$emailIDs)));
$this->set('emails', $emails);
$this->set('job', $job);
$this->set('customer', $this->Job->Enquiry->Customer->findById($job['Enquiry']['customer_id']));
$this->set('principles', $this->Job->PurchaseOrder->Principle->find('list'));
@ -170,6 +181,15 @@ class JobsController extends AppController {
else {
return false;
}
}
/**
* Need to fix the customer_id which hasn't been set for these 500odd records.
*
* Will fetch the right ID the same way the Index does, then update each record.
*/
function fixCustomerIDs() {
}

View file

@ -70,7 +70,11 @@ class Customer extends AppModel {
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
),
'Invoice' => array('className'=>'Invoice',
'foreignKey' => 'customer_id'),
'Job' => array('className'=>'Job',
'foreignKey' => 'customer_id')
);

View file

@ -118,7 +118,7 @@ class Enquiry extends AppModel {
),*/
'Contact' => array('className' => 'User',
'foreignKey' => 'contact_user_id',
'conditions' => '',
'conditions' => array('Contact.type'=>'contact'),
'fields' => '',
'order' => ''
),

View file

@ -41,5 +41,14 @@ class Invoice extends AppModel {
)
);
var $hasAndBelongsToMany = array(
'Email' => array(
'className' => 'Email',
'joinTable' => 'emails_invoices',
)
);
}
?>

View file

@ -37,6 +37,10 @@ class Job extends AppModel {
'className' => 'PurchaseOrder',
'joinTable' => 'jobs_purchase_orders',
'unique' => true
),
'Email' => array(
'className' => 'Email',
'joinTable' => 'emails_jobs',
)
);

View file

@ -145,22 +145,6 @@
</div>
<div class="related">
<h3><?php __('Addresses');?><?php echo $html->image('x-office-address-book.png'); ?></h3>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Address for this Customer', true), array('controller'=> 'addresses', 'action'=>'add/customerid:'.$customer['Customer']['id']));?><?php echo $html->link($html->image('address-book-new.png'), array('controller'=> 'addresses', 'action'=>'add/customerid:'.$customer['Customer']['id']), null, null, false); ?> </li>
</ul>
</div>
<?php if (!empty($customer['Address'])) {
echo $this->element('address_table', $addresses);
}
else {
echo 'No Addresses for this Customer Yet';
}
?>
</div>
<div class="related">
<h3><?php __('Enquiries');?><?php echo $html->image('folder.png'); ?></h3>
<div class="actions">
@ -179,10 +163,37 @@
</div>
<div class="related">
<?=$this->element('job_table', array('jobs'=>$jobs));?>
</div>
<? debug($customer, true); ?>
<div class="related">
<?=$this->element('invoice_table', array('invoices'=>$invoices));?>
</div>
<?php debug($parent_industry_list); ?>
<div class="related">
<h3><?php __('Addresses');?><?php echo $html->image('x-office-address-book.png'); ?></h3>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Address for this Customer', true), array('controller'=> 'addresses', 'action'=>'add/customerid:'.$customer['Customer']['id']));?><?php echo $html->link($html->image('address-book-new.png'), array('controller'=> 'addresses', 'action'=>'add/customerid:'.$customer['Customer']['id']), null, null, false); ?> </li>
</ul>
</div>
<?php if (!empty($customer['Address'])) {
echo $this->element('address_table', $addresses);
}
else {
echo 'No Addresses for this Customer Yet';
}
?>
</div>
<? debug($jobs); ?>

View file

@ -52,7 +52,6 @@
<?php
//Allowed types to view in the browser.
$allowedTypes = array('text/plain', 'text/html');
$allowedTypes['text/plain'] = 1;
$allowedTypes['text/html'] = 1;
$thisType = $emailAttachment['type'];

View file

@ -1,5 +1,5 @@
<?php echo $javascript->link('email_table'); ?>
<? App::import('Sanitize'); ?>
<?php // if (!empty($emails)):?>
<div id="emailDiv">
@ -9,6 +9,7 @@
<th><?php __('Email Date'); ?></th>
<th><?php __('From'); ?></th>
<th><?php __('Subject'); ?></th>
<th>Action</th>
</tr>
<?php
$i = 0;
@ -33,12 +34,14 @@
}
else {
echo $html->link($email['User']['email'], array('controller'=>'users','action'=>'view', $email['User']['id']));
}
?>
</td>
<td><?php //echo $text->highlight($html->link($email['Email']['subject'], array('controller'=> 'emails', 'action'=>'frame/', $email['Email']['id'])), 'Quotation');
echo $text->highlight($html->link($email['Email']['subject'], '#', array('class'=>'viewLink', 'id'=>$email['Email']['id'])), 'Quotation');
?></td>
echo $text->highlight($html->link(Sanitize::clean($email['Email']['subject']), '#', array('class'=>'viewLink', 'id'=>$email['Email']['id'])), 'Quotation');?>
<span class='viewLink' id="<? echo $email['Email']['id']?>">(<? echo $email['Email']['id']?>)</span>
</td>
</tr>
<?php endforeach; ?>
</table>

View file

@ -189,4 +189,3 @@
echo "<h2>No matching records found :( Try modifying your search terms</h2>";
}
?>

View file

@ -48,15 +48,12 @@
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit Invoice', true), array('action' => 'edit', $invoice['Invoice']['id'])); ?> </li>
<li><?php echo $html->link(__('Delete Invoice', true), array('action' => 'delete', $invoice['Invoice']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $invoice['Invoice']['id'])); ?> </li>
<li><?php echo $html->link(__('List Invoices', true), array('action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New Invoice', true), array('action' => 'add')); ?> </li>
<li><?php echo $html->link(__('List Enquiries', true), array('controller' => 'enquiries', 'action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New Enquiry', true), array('controller' => 'enquiries', 'action' => 'add')); ?> </li>
<li><?php echo $html->link(__('List Users', true), array('controller' => 'users', 'action' => 'index')); ?> </li>
<li><?php echo $html->link(__('New User', true), array('controller' => 'users', 'action' => 'add')); ?> </li>
</ul>
<div class="related">
<h3>
Emails for this Invoice<?php echo $html->image('internet-mail.png'); ?>
</h3>
<?php echo $this->element('email_table_ajax', array('emails' => $emails)); ?>
<?php //echo $this->element('email_table_ajax', $enquiry, array('cache'=>'+1 day')); ?>
</div>

View file

@ -122,4 +122,15 @@ foreach ($job['PurchaseOrder'] as $purchaseOrder):
<?php endif;?>
<div class="related">
<h3>
Emails for this Job<?php echo $html->image('internet-mail.png'); ?>
</h3>
<?php echo $this->element('email_table_ajax', array('emails' => $emails)); ?>
<?php //echo $this->element('email_table_ajax', $enquiry, array('cache'=>'+1 day')); ?>
</div>
<?php debug($job);?>

View file

@ -1260,3 +1260,8 @@ span.addLineItem {
width: 60%;
height: 30em;
}
.viewLink {
cursor: pointer;
}