added fixJobs to set FKs on job table. Adding jobs now sets these keys properly

This commit is contained in:
Karl Cordes 2011-03-14 12:30:03 +11:00
parent e378a596ec
commit aae41714ab
5 changed files with 77 additions and 8 deletions

View file

@ -66,7 +66,9 @@ class JobsController extends AppController {
$jobLetter = $enquiry['State']['enqform'];
$this->data['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number;
$this->data['Job']['state_id'] = $enquiry['Enquiry']['state_id'];
$this->data['Job']['customer_id'] = $enquiry['Enquiry']['customer_id'];
$this->data['Job']['contact_id'] = $enquiry['Enquiry']['contact_id'];
@ -189,7 +191,22 @@ class JobsController extends AppController {
*
* Will fetch the right ID the same way the Index does, then update each record.
*/
function fixCustomerIDs() {
function fixJobs() {
$jobs = $this->Job->find('all');
foreach($jobs as $job) {
$this->Job->id = $job['Job']['id'];
$this->data = $job;
$this->data['Job']['customer_id'] = $job['Enquiry']['customer_id'];
$this->data['Job']['state_id'] = $job['Enquiry']['state_id'];
$this->data['Job']['contact_id'] = $job['Enquiry']['contact_id'];
$this->Job->save($this->data);
}
$this->set('jobs', $this->Job->find('all'));
}

View file

@ -29,7 +29,15 @@ class Job extends AppModel {
'counterCache' => true
),
'Currency'
'Currency' => array(
'className' => 'Currency',
'foreignKey' => 'currency_id'
),
'Customer' => array(
'className' => 'Customer',
'foreignKey' => 'customer_id'
)
);
var $hasAndBelongsToMany = array(

View file

@ -58,8 +58,8 @@
</td>
<td><?=$poLink?></td>
<td>
<?php echo $html->link($customers[$job['Enquiry']['customer_id']], array('controller'=>'customers',
'action'=>'view', $job['Enquiry']['customer_id'])); ?>
<?php echo $html->link($job['Customer']['name'], array('controller'=>'customers',
'action'=>'view', $job['Job']['customer_id'])); ?>
</td>
<td>
<?php echo $job['Job']['customer_order_number']; ?>

44
views/jobs/fix_jobs.ctp Normal file
View file

@ -0,0 +1,44 @@
<table>
<tr>
<th>id</th>
<th>customer_id</th>
<th>Enq Cust ID</th>
<th>state_id</th>
<th>Enq State ID</th>
<th>contact_id</th>
<th>Enq Contact ID</th>
</tr>
<?
foreach($jobs as $job):
?>
<tr>
<td><?=$job['Job']['id'];?></td>
<td><?=$job['Job']['customer_id'];?></td>
<td><?=$job['Enquiry']['customer_id'];?></td>
<td><?=$job['Job']['state_id']?></td>
<td><?=$job['Enquiry']['state_id']?></td>
<td><?=$job['Job']['contact_id']?></td>
<td><?=$job['Enquiry']['contact_id']?></td>
</tr>
<?
endforeach;?>
</table>
<?
debug($jobs);
?>

View file

@ -61,8 +61,8 @@
</td>
<td><?=$poLink?></td>
<td>
<?php echo $html->link($customers[$job['Enquiry']['customer_id']], array('controller'=>'customers',
'action'=>'view', $job['Enquiry']['customer_id'])); ?>
<?php echo $html->link($job['Customer']['name'], array('controller'=>'customers',
'action'=>'view', $job['Job']['customer_id'])); ?>
</td>
<td>
<?php echo $job['Job']['customer_order_number']; ?>