Can now convert Quote to new Job and Order Ack
This commit is contained in:
parent
7d22714d9d
commit
044310acee
|
|
@ -170,7 +170,6 @@ class DocumentsController extends AppController {
|
|||
|
||||
break;
|
||||
case "orderAck":
|
||||
|
||||
$enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid);
|
||||
$this->data['OrderAcknowledgement']['job_id'] = $jobid;
|
||||
$this->data['OrderAcknowledgement']['enquiry_id'] = $enquiryid;
|
||||
|
|
@ -178,7 +177,6 @@ class DocumentsController extends AppController {
|
|||
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
$this->data['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it!
|
||||
$this->data['Document']['type'] = 'orderAck';
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
|
@ -213,6 +211,8 @@ class DocumentsController extends AppController {
|
|||
|
||||
$this->set('document', $document);
|
||||
|
||||
$this->Document->create();
|
||||
|
||||
if(!empty($document['Invoice']['id'])) {
|
||||
echo "WE HAVE AN INVOICE";
|
||||
}
|
||||
|
|
@ -273,11 +273,12 @@ class DocumentsController extends AppController {
|
|||
}
|
||||
}
|
||||
|
||||
$this->set('newDoc', $newDoc);
|
||||
|
||||
$this->set('newDoc', $newDoc);
|
||||
//
|
||||
//print_r($newDoc);
|
||||
if ($this->Document->saveAll($newDoc)) {
|
||||
$newid = $this->Document->id;
|
||||
|
||||
$this->Session->setFlash(__("Revision {$number_of_revisions} created", true));
|
||||
$this->redirect(array('action'=>'view',$newid));
|
||||
} else {
|
||||
|
|
@ -310,7 +311,93 @@ class DocumentsController extends AppController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Convert a Quote to an OrderAcknowledgement.
|
||||
*
|
||||
* Create a new Job for the Enquiry.
|
||||
*
|
||||
* Make a new Document (orderack) with the same LineItems as Quote with Document ID #$id
|
||||
*
|
||||
* @param <int> $id
|
||||
*/
|
||||
function convert_to_oa($id = null) {
|
||||
//$this->layout = 'ajax';
|
||||
if (!$id) {
|
||||
echo 'Invalid Document ID';
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
$originalDoc = $this->Document->find('first', array('conditions' => array('Document.id' => $id)));
|
||||
|
||||
|
||||
|
||||
$enquiry = $this->Document->OrderAcknowledgement->Enquiry->find('first', array('conditions'=>array('Enquiry.id'=>$originalDoc['Quote']['enquiry_id'])));
|
||||
|
||||
$enquiry['Enquiry']['status_id'] = 3; //Job Won, Order Placed
|
||||
|
||||
$this->Document->OrderAcknowledgement->Enquiry->save($enquiry);
|
||||
|
||||
|
||||
|
||||
$job = $this->Document->OrderAcknowledgement->Job->newJob($enquiry); //Only way to know Enquiry ID is if it's a Quote.
|
||||
|
||||
|
||||
if($job == false) {
|
||||
echo 'Error: Unable to create Job';
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
|
||||
$newDoc = array();
|
||||
|
||||
$newDoc['Document']['type'] = 'orderAck';
|
||||
|
||||
$newDoc['OrderAcknowledgement']['job_id'] = $job['Job']['id'];
|
||||
|
||||
$newDoc['OrderAcknowledgement']['enquiry_id'] = $enquiry['Enquiry']['id'];
|
||||
$newDoc['OrderAcknowledgement']['currency_id'] = 2; //Default to AUD.
|
||||
$newDoc['OrderAcknowledgement']['issue_date'] = date('Y-m-d');
|
||||
$newDoc['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
$newDoc['Document']['revision'] = 0; //No revisions for Order Acks. I have decreed it!
|
||||
$newDoc['Document']['type'] = 'orderAck';
|
||||
|
||||
|
||||
|
||||
/** Copy the LineItems from this Document. Applies to all of the Document Types */
|
||||
if(!empty($originalDoc['LineItem'])) {
|
||||
$newDoc['LineItem'] = $originalDoc['LineItem'];
|
||||
foreach($newDoc['LineItem'] as $index => $li) {
|
||||
$newDoc['LineItem'][$index]['id'] = null;
|
||||
$newDoc['LineItem'][$index]['document_id'] = null;
|
||||
$newDoc['LineItem'][$index]['costing_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->Document->saveAll($newDoc)) {
|
||||
$newid = $this->Document->id;
|
||||
$this->Session->setFlash(__("Job {$job['Job']['title']} and Order Acknowledgement created", true));
|
||||
$this->redirect(array('action'=>'view',$newid));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
||||
}
|
||||
$this->Document->saveAll($newDoc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function pdf($id = null) {
|
||||
//Configure::write('debug',0);
|
||||
|
|
@ -414,6 +501,7 @@ class DocumentsController extends AppController {
|
|||
|
||||
$template_name = 'pdf_orderack';
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if($document['Document']['revision'] > 0) {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class EnquiriesController extends AppController {
|
|||
$this->set('principle_emails', $this->Enquiry->Principle->PrincipleContact->findAllByPrincipleId($enquiry['Enquiry']['principle_id']));
|
||||
|
||||
$this->set('jobs', $this->Enquiry->Job->find('all', array('conditions'=>array('Job.enquiry_id'=>$id))));
|
||||
|
||||
$this->set('order_acknowledgements', $this->Enquiry->OrderAcknowledgement->find('all', array('conditions'=>array('OrderAcknowledgement.enquiry_id'=>$id))));
|
||||
|
||||
if($enquiry['Enquiry']['billing_address_id'] != 0) {
|
||||
$this->set('billingaddress', $this->Enquiry->BillingAddress->findById($enquiry['Enquiry']['billing_address_id']));
|
||||
|
|
|
|||
|
|
@ -541,26 +541,10 @@ class JobsController extends AppController {
|
|||
}
|
||||
else {
|
||||
|
||||
$this->Job->create();
|
||||
|
||||
$job_offset = 6141;
|
||||
|
||||
$number_of_jobs = $this->Job->findCount();
|
||||
$new_job_number = $job_offset + $number_of_jobs;
|
||||
|
||||
$enquiry = $this->Job->Enquiry->findById($enquiryID);
|
||||
$monthYearShort = strtoupper(date("My"));
|
||||
|
||||
$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'];
|
||||
$this->data['Job']['enquiry_id'] = $enquiry['Enquiry']['id'];
|
||||
$this->data['Job']['date_order_received'] = date('Y-m-d');
|
||||
|
||||
if ($this->Job->save($this->data)) {
|
||||
$enquiry = $this->Job->Enquiry->find('first', array('conditions'=>array('Enquiry.id'=>$enquiryID)));
|
||||
$result = $this->Job->newJob($enquiry);
|
||||
|
||||
if (is_array($result)) {
|
||||
echo "SUCCESS";
|
||||
}
|
||||
else {
|
||||
|
|
@ -569,6 +553,7 @@ class JobsController extends AppController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function __isNotEmptyDate($date) {
|
||||
if($date == "0000-00-00") {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -193,6 +193,6 @@ class Enquiry extends AppModel {
|
|||
);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ class Job extends AppModel {
|
|||
|
||||
var $name = 'Job';
|
||||
|
||||
|
||||
|
||||
var $validate = array(
|
||||
'title' => array('notempty'),
|
||||
|
||||
'enquiry_id' => array('numeric'),
|
||||
|
||||
/* 'date_order_received' => array('date'),
|
||||
/* 'date_order_received' => array('date'),
|
||||
|
||||
'domestic_freight_paid_by' => array('notempty'),
|
||||
'sale_category' => array('notempty'),
|
||||
|
|
@ -36,7 +36,7 @@ class Job extends AppModel {
|
|||
'foreignKey' => 'currency_id'
|
||||
),
|
||||
|
||||
'Customer' => array(
|
||||
'Customer' => array(
|
||||
'className' => 'Customer',
|
||||
'foreignKey' => 'customer_id'
|
||||
)
|
||||
|
|
@ -59,6 +59,45 @@ class Job extends AppModel {
|
|||
)
|
||||
);
|
||||
|
||||
|
||||
var $hasMany = array(
|
||||
'OrderAcknowledgement' => array(
|
||||
'className' => 'OrderAcknowledgement',
|
||||
'foreign_key' => 'job_id'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
function newJob($enquiry) {
|
||||
|
||||
$this->create();
|
||||
|
||||
$job_offset = 6141;
|
||||
|
||||
$number_of_jobs = $this->findCount();
|
||||
$new_job_number = $job_offset + $number_of_jobs;
|
||||
|
||||
$monthYearShort = strtoupper(date("My"));
|
||||
|
||||
$jobLetter = $enquiry['State']['enqform'];
|
||||
|
||||
$newJob = array();
|
||||
|
||||
$newJob['Job']['title'] = $monthYearShort.$jobLetter."J".$new_job_number;
|
||||
$newJob['Job']['state_id'] = $enquiry['Enquiry']['state_id'];
|
||||
$newJob['Job']['customer_id'] = $enquiry['Enquiry']['customer_id'];
|
||||
$newJob['Job']['contact_id'] = $enquiry['Enquiry']['contact_id'];
|
||||
$newJob['Job']['enquiry_id'] = $enquiry['Enquiry']['id'];
|
||||
$newJob['Job']['date_order_received'] = date('Y-m-d');
|
||||
|
||||
if ($this->save($newJob)) {
|
||||
|
||||
return $this->find('first',array('conditions'=>array('Job.id'=>$this->id)));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -17,6 +17,7 @@ class Product extends AppModel {
|
|||
|
||||
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<? //debug($this->data);?>
|
||||
<? //debug($enquiry);?>
|
||||
<?php // debug($document);?>
|
||||
<?php // debug($job);?>
|
||||
<?php //debug($docType);?>
|
||||
|
||||
<? //debug($invoice); ?>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ echo $form->input('Document.id');
|
|||
<div id="flashMessage" class="message">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="docOperations">
|
||||
<h3>Customer placed an order for this Quote?</h3>
|
||||
<?=$html->link('Convert this Enquiry to a new Job and Generate an Order Acknowledgement', '/documents/convert_to_oa/'.$document['Document']['id'], array('class'=>'actionLink'));?>
|
||||
</div>
|
||||
|
||||
<div class="pages">
|
||||
<?php
|
||||
$first = true;
|
||||
|
|
@ -66,6 +72,13 @@ echo $form->input('Document.id');
|
|||
<div id="contactFirstName" style="display: none;"><?=$enquiry['Contact']['first_name'];?></div>
|
||||
|
||||
|
||||
|
||||
<div id="addJobConfirmation" title="Create New Job and Order Acknowledgment">
|
||||
<span>This will create a new job and an Order Acknowledgement based on this Quote</span><br>
|
||||
<span>The Enquiry will also be marked as "Job Won - Order Placed"</span><br>
|
||||
Continue?
|
||||
</div>
|
||||
|
||||
<? //debug($this->data);?>
|
||||
<? //debug($enquiry);?>
|
||||
<?php //debug($document);?>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
<th><?php echo $paginator->sort('paid');?></th>
|
||||
<th><?php echo $paginator->sort('payment_received_date');?></th>
|
||||
|
||||
<th><?php echo $paginator->sort('user_id');?></th>
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
|
|
@ -68,9 +67,6 @@
|
|||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php echo $html->link($invoice['User']['username'], array('controller' => 'users', 'action' => 'view', $invoice['User']['id'])); ?>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('controller'=>'invoices','action' => 'view', $invoice['Invoice']['id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('controller'=>'invoices', 'action' => 'edit', $invoice['Invoice']['id'])); ?>
|
||||
|
|
|
|||
|
|
@ -161,15 +161,12 @@
|
|||
|
||||
<th>Job Number</th>
|
||||
<th>Customer Order Number</th>
|
||||
|
||||
<th>Date Order Received</th>
|
||||
<th>Date Sheduled Ex-Works</th>
|
||||
<th>Date Scheduled Ex-Works</th>
|
||||
<th>Date Sent to Customer</th>
|
||||
|
||||
<th>Domestic Freight Paid By</th>
|
||||
|
||||
<th>Comments</th>
|
||||
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
|
|
@ -209,9 +206,6 @@
|
|||
<?php echo $job['Job']['domestic_freight_paid_by']; ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php echo $job['Job']['comments']; ?>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('controller'=>'jobs', 'action' => 'view', $job['Job']['id'])); ?>
|
||||
<?php //echo $html->link(__('New Invoice for this Job', true), array('controller'=>'documents', 'action' => 'newDocument/invoice/'.$job['Job']['enquiry_id'].'/'.$job['Job']['id'])); ?>
|
||||
|
|
@ -245,6 +239,28 @@
|
|||
<? endforeach;?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="related">
|
||||
<h3>Order Acknowledgements</h3>
|
||||
<table class="quotetable">
|
||||
<tr>
|
||||
<th>Created</th>
|
||||
<th>Issue Date</th>
|
||||
<th>Job</th>
|
||||
<th class="actions">Actions</th>
|
||||
</tr>
|
||||
<?php foreach ($order_acknowledgements as $oa):?>
|
||||
<tr>
|
||||
<td><?=$oa['OrderAcknowledgement']['created'];?></td>
|
||||
<td><?=$oa['OrderAcknowledgement']['issue_date'];?></td>
|
||||
<td><?=$html->link($oa['Job']['title'], '/jobs/view/'.$oa['Job']['id']);?></td>
|
||||
<td class="actions"><?=$html->link('View', '/documents/view/'.$oa['OrderAcknowledgement']['document_id']);?></td>
|
||||
</tr>
|
||||
|
||||
<? endforeach;?>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="related">
|
||||
<h3><?php __($enquiry['Enquiry']['invoice_count'].' Invoices for this Enquiry');?></h3>
|
||||
<table class="quotetable">
|
||||
|
|
@ -332,6 +348,6 @@
|
|||
<?php //echo $this->element('email_table_ajax', $enquiry, array('cache'=>'+1 day')); ?>
|
||||
</div>
|
||||
|
||||
|
||||
<?php debug($enquiry);?>
|
||||
<?php debug($order_acknowledgements); ?>
|
||||
<?php // debug($jobs);?>
|
||||
<?php //debug($emails); ?>
|
||||
|
|
@ -1621,4 +1621,8 @@ div.pdfGeneratedMessage {
|
|||
|
||||
div.documentDetails {
|
||||
width: 45em
|
||||
}
|
||||
|
||||
div.docOperations {
|
||||
float: right;
|
||||
}
|
||||
|
|
@ -126,6 +126,32 @@ $(function() {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
$( "#addJobConfirmation" ).dialog({
|
||||
autoOpen: false,
|
||||
height: 200,
|
||||
width: 400,
|
||||
modal: true,
|
||||
buttons: {
|
||||
"Continue": function() {
|
||||
|
||||
var documentID = $("#documentID").html();
|
||||
|
||||
$.get('/documents/convert_to_oa/'+documentID, null, function(data) {
|
||||
$( "#QuoteDetails" ).dialog('close');
|
||||
});
|
||||
|
||||
},
|
||||
Cancel: function() {
|
||||
$( this ).dialog( "close" );
|
||||
|
||||
}
|
||||
},
|
||||
close: function() {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$("#pageContentFactory").hide();
|
||||
|
||||
|
|
@ -306,9 +332,8 @@ $(function() {
|
|||
$("#saveInvoiceButton").click(function() {
|
||||
|
||||
|
||||
$('#shippingDetails').ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
|
||||
updateTextFields(); //Update the CKEditor instances.
|
||||
|
||||
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
|
||||
|
||||
|
|
@ -333,16 +358,8 @@ $(function() {
|
|||
$("#saveOAButton").click(function() {
|
||||
|
||||
|
||||
$('#shippingDetails').ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
updateTextFields(); //Update the CKEditor instances.
|
||||
|
||||
$("#DocumentBillTo").ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
$("#DocumentShipTo").ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
|
||||
|
||||
|
||||
|
|
@ -363,6 +380,13 @@ $(function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#createJobAndOA").click(function() {
|
||||
$("#addJobConfirmation").dialog('open');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -401,6 +425,21 @@ $('.generateCommercialComments').live('click', function(event) {
|
|||
|
||||
});
|
||||
|
||||
|
||||
function updateTextFields() {
|
||||
$('#shippingDetails').ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
|
||||
$("#DocumentBillTo").ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
$("#DocumentShipTo").ckeditor(function() {
|
||||
this.updateElement();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function newPage(firstPage) {
|
||||
|
||||
|
||||
|
|
@ -556,4 +595,7 @@ function checkNaN(value) {
|
|||
else {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue