Documents controller revising quotes OK
This commit is contained in:
parent
87b56d5666
commit
a92eb939a4
|
|
@ -102,6 +102,22 @@ class AppController extends Controller {
|
|||
|
||||
}
|
||||
|
||||
function unset_keys($array, $keys) {
|
||||
foreach($keys as $key ) {
|
||||
$array[$key] = null;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
function unset_multiple_keys($array, $keys) {
|
||||
foreach($array as $index => $item) {
|
||||
$array[$index]['id'] = null;
|
||||
$array[$index]['document_id'] = null;
|
||||
$array[$index]['costing_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,24 @@ class DocumentsController extends AppController {
|
|||
|
||||
$this->set('currency', $this->Document->getCurrency($document));
|
||||
$this->set('enquiry', $this->Document->getEnquiry($document));
|
||||
|
||||
|
||||
|
||||
switch($docType) {
|
||||
case 'quote':
|
||||
$docTypeElement = 'document_quote_view';
|
||||
break;
|
||||
case 'invoice':
|
||||
$docTypeElement = 'document_invoice_view';
|
||||
break;
|
||||
|
||||
case 'purchaseOrder':
|
||||
$docTypeElement = 'document_purchase_order_view';
|
||||
break;
|
||||
}
|
||||
|
||||
$this->set('docTypeElement', $docTypeElement);
|
||||
|
||||
// $this->set('principles', $this->Document->LineItem->Product->Principle->find('list'));
|
||||
}
|
||||
|
||||
|
|
@ -72,41 +90,6 @@ class DocumentsController extends AppController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Quote, along with its associated Document and the first two pages.
|
||||
* @param int $id - the Enquiry ID that this quote belongs to.
|
||||
*/
|
||||
function newQuote($id = null) {
|
||||
$enquiryid = $id;
|
||||
$this->Document->create();
|
||||
|
||||
$enquiry = $this->Document->Quote->Enquiry->findById($id);
|
||||
|
||||
$this->data['Document']['enquiry_id'] = $enquiryid;
|
||||
|
||||
$this->data['Quote']['enquiry_id'] = $enquiryid;
|
||||
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
||||
$this->data['Quote']['revision'] = $number_of_revisions;
|
||||
$this->data['Quote']['date_issued'] = date('Y-m-d');
|
||||
$this->data['Quote']['currency_id'] = 2; //All new Quotes default to AUD.
|
||||
|
||||
|
||||
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
$this->data['Document']['enquiry_id'] = $enquiryid;
|
||||
$this->data['Document']['type'] = 'quote';
|
||||
|
||||
if ($this->Document->saveAll($this->data)) {
|
||||
$newid = $this->Document->id;
|
||||
|
||||
$this->Session->setFlash(__('The Document has been saved', true));
|
||||
$this->redirect(array('action'=>'view',$newid));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a New Document
|
||||
|
|
@ -115,8 +98,8 @@ class DocumentsController extends AppController {
|
|||
* @param <type> $type
|
||||
* @param <type> $id
|
||||
*/
|
||||
function newDocument($type = null, $id = null) {
|
||||
if(!$type|| !$id) {
|
||||
function newDocument($type = null, $enquiryid = null, $jobid = 0) {
|
||||
if(!$type) {
|
||||
$this->Session->setFlash('Invalid Doc Type or ID');
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +108,7 @@ class DocumentsController extends AppController {
|
|||
switch($type) {
|
||||
case "quote":
|
||||
|
||||
$enquiryid = $id;
|
||||
$enquiry = $this->Document->Quote->Enquiry->findById($id);
|
||||
$enquiry = $this->Document->Quote->Enquiry->findById($enquiryid);
|
||||
|
||||
if(!$enquiry) {
|
||||
$this->Session->setFlash('Invalid Enquiry ID');
|
||||
|
|
@ -134,7 +116,6 @@ class DocumentsController extends AppController {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->data['Document']['enquiry_id'] = $enquiryid;
|
||||
|
||||
$this->data['Quote']['enquiry_id'] = $enquiryid;
|
||||
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
||||
|
|
@ -143,14 +124,48 @@ class DocumentsController extends AppController {
|
|||
$this->data['Quote']['currency_id'] = 2; //All new Quotes default to AUD.
|
||||
|
||||
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
$this->data['Document']['enquiry_id'] = $enquiryid;
|
||||
|
||||
$this->data['Document']['type'] = 'quote';
|
||||
break;
|
||||
case "invoice":
|
||||
|
||||
$invoice_number_offset = 4436; //What Invoice number we are up to. Starting at 4500 due to the data loss.
|
||||
|
||||
$number_of_invoices = $this->Document->Invoice->findCount();
|
||||
|
||||
$enquiry = $this->Document->Invoice->Enquiry->read(null, $enquiryid);
|
||||
if(!$enquiry) {
|
||||
$this->Session->setFlash('Invalid Enquiry ID');
|
||||
$this->redirect(array('action'=>'index'));
|
||||
return;
|
||||
}
|
||||
|
||||
$newInvoiceNumber = $invoice_number_offset + $number_of_invoices;
|
||||
$this->data['Invoice']['enquiry_id'] = $enquiryid;
|
||||
$this->data['Invoice']['title'] = "CMCIN".$newInvoiceNumber;
|
||||
$this->data['Invoice']['job_id'] = $jobid;
|
||||
$this->data['Invoice']['customer_id'] = $enquiry['Enquiry']['customer_id'];
|
||||
|
||||
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
//$number_of_revisions = $this->Document->Invoice->findCount('Invoice.enquiry_id ='. $enquiryid);
|
||||
$this->data['Document']['revision'] = 0; //No revisions for Invoices. I have decreed it!
|
||||
$this->data['Document']['type'] = 'invoice';
|
||||
|
||||
$this->data['Invoice']['issue_date'] = date('Y-m-d'); //Argh. Quote model uses 'date_issed'.
|
||||
|
||||
$this->data['Document']['currency_id'] = 2; //All new Invoices default to AUD.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case "purchaseOrder":
|
||||
break;
|
||||
case "orderAck":
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
|
@ -189,7 +204,40 @@ class DocumentsController extends AppController {
|
|||
echo "WE HAVE AN INVOICE";
|
||||
}
|
||||
else if (!empty($document['Quote']['id'])) {
|
||||
echo "WE ARE REVISING A QUOTE";
|
||||
|
||||
//First setup the Date and default valid until date. (30 days from today).
|
||||
|
||||
$today_date = date("Y-m-d");
|
||||
$valid_until = date("Y-m-d", strtotime("+30 days"));
|
||||
|
||||
$newDoc = array();
|
||||
|
||||
|
||||
$newDoc['Quote'] = $this->unset_keys($document['Quote'], array('id','created'));
|
||||
|
||||
$newDoc['Quote']['date_issued'] = $today_date;
|
||||
$newDoc['Quote']['days_valid'] = 30;
|
||||
$newDoc['Quote']['valid_until'] = $valid_until;
|
||||
|
||||
$enquiryid = $document['Quote']['enquiry_id'];
|
||||
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
||||
$newDoc['Document']['revision'] = $number_of_revisions;
|
||||
$newDoc['Document']['type'] = 'quote';
|
||||
|
||||
|
||||
$newDoc['DocPage'] = $document['DocPage'];
|
||||
|
||||
foreach($newDoc['DocPage'] as $index => $li) {
|
||||
$newDoc['DocPage'][$index]['id'] = null;
|
||||
$newDoc['DocPage'][$index]['document_id'] = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if (!empty($document['PurchaseOrder']['id'])) {
|
||||
|
|
@ -201,9 +249,29 @@ class DocumentsController extends AppController {
|
|||
echo "WE ARE REVISING An ORDER ACK";
|
||||
}
|
||||
|
||||
|
||||
/** Copy the LineItems from this Document. Applies to all of the Document Types */
|
||||
if(!empty($document['LineItem'])) {
|
||||
$newDoc['LineItem'] = $document['LineItem'];
|
||||
foreach($newDoc['LineItem'] as $index => $li) {
|
||||
$newDoc['LineItem'][$index]['id'] = null;
|
||||
$newDoc['LineItem'][$index]['document_id'] = null;
|
||||
$newDoc['LineItem'][$index]['costing_id'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set('newDoc', $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 {
|
||||
$this->Session->setFlash(__('The Document could not be saved. Please, try again.', true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Quote, along with its associated Document and the first two pages.
|
||||
|
|
@ -369,8 +437,8 @@ class DocumentsController extends AppController {
|
|||
|
||||
//If this is a quote, set the filename
|
||||
//@TODO FIX THIS FOR OTHER DOCTYPES
|
||||
if($document['Quote']['revision'] > 0) {
|
||||
$filename = $enquiry['Enquiry']['title'].'rev'.$document['Quote']['revision'].'.pdf';
|
||||
if($document['Document']['revision'] > 0) {
|
||||
$filename = $enquiry['Enquiry']['title'].'_'.$document['Document']['revision'].'.pdf';
|
||||
}
|
||||
else {
|
||||
$filename = $enquiry['Enquiry']['title'].'.pdf';
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class InvoicesController extends AppController {
|
|||
|
||||
}
|
||||
|
||||
function edit($id = null) {
|
||||
/* function edit($id = null) {
|
||||
if (!$id && empty($this->data)) {
|
||||
$this->Session->setFlash(__('Invalid Invoice', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
|
@ -107,7 +107,7 @@ class InvoicesController extends AppController {
|
|||
$users = $this->Invoice->User->find('list');
|
||||
$jobs = $this->Invoice->Job->find('list', array('conditions'=>array('Job.enquiry_id'=>$invoice['Invoice']['enquiry_id'])));
|
||||
$this->set(compact('users', 'jobs'));
|
||||
}
|
||||
}*/
|
||||
|
||||
/*function delete($id = null) {
|
||||
if (!$id) {
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class JobsController extends AppController {
|
|||
$this->set('gst_options', $this->gst_options());
|
||||
|
||||
$this->set('totals', $this->getTotals($jobs));
|
||||
print_r($totals);
|
||||
// print_r($totals);
|
||||
//print_r($jobs);
|
||||
}
|
||||
|
||||
|
|
@ -558,6 +558,7 @@ class JobsController extends AppController {
|
|||
$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)) {
|
||||
echo "SUCCESS";
|
||||
|
|
|
|||
|
|
@ -95,6 +95,11 @@ class UsersController extends AppController {
|
|||
$this->set('emails', $emails);
|
||||
/ */
|
||||
|
||||
/** $this->render() is a better approach than I used in View Document. Keeps the views out of Elements and in the right directory.
|
||||
*
|
||||
Will refactor at some point in the future. Maybe.
|
||||
*
|
||||
*/
|
||||
|
||||
switch ($user['User']['type']) {
|
||||
case 'contact':
|
||||
|
|
|
|||
|
|
@ -19,11 +19,7 @@ class Invoice extends AppModel {
|
|||
'Enquiry' => array(
|
||||
'className' => 'Enquiry',
|
||||
'foreignKey' => 'enquiry_id',
|
||||
'counterCache'=>true
|
||||
),
|
||||
'User' => array(
|
||||
'className' => 'User',
|
||||
'foreignKey' => 'user_id',
|
||||
'counterCache'=> true
|
||||
),
|
||||
'Customer' => array(
|
||||
'className' => 'Customer',
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ $your_reference = 'Enquiry on '.date('j M Y');
|
|||
$issue_date = $document['Quote']['date_issued'];
|
||||
|
||||
$pdfdoc->docRef = $enquiryNumber;
|
||||
if($document['Quote']['revision'] > 0) {
|
||||
$enquiryNumber = $enquiryNumber.'.'.$document['Quote']['revision'];
|
||||
if($document['Document']['revision'] > 0) {
|
||||
$enquiryNumber = $enquiryNumber.'.'.$document['Document']['revision'];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ echo $javascript->link('document_add_edit');
|
|||
|
||||
?>
|
||||
|
||||
<h2><?=$docTypeFullName?>: <?=$html->link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?> <?
|
||||
<h2><?=$docTypeFullName?>: <?=$html->link($enquiry['Enquiry']['title'], array('controller'=>'enquiries','action'=>'view',$enquiry['Enquiry']['id']));?>
|
||||
<?
|
||||
if($document['Document']['revision'] > 0) {
|
||||
echo "Revision {$document['Document']['revision']} ";
|
||||
}
|
||||
|
|
@ -18,20 +19,7 @@ echo $javascript->link('document_add_edit');
|
|||
<?=$this->element('pdf_created_message'); ?>
|
||||
|
||||
<?
|
||||
|
||||
switch($docType) {
|
||||
case 'quote':
|
||||
echo $this->element('document_quote_view');
|
||||
break;
|
||||
case 'invoice':
|
||||
echo $this->element('document_invoice_view');
|
||||
break;
|
||||
|
||||
case 'purchaseOrder':
|
||||
echo 'Purchase OOOOORDER!!';
|
||||
|
||||
break;
|
||||
}
|
||||
echo $this->element($docTypeElement);
|
||||
?>
|
||||
|
||||
<button class="addLineItem">Add Line Item</button>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php if (!empty($quotes)):?>
|
||||
<table cellpadding = "0" cellspacing = "0" class="quotetable">
|
||||
<?php if (!empty($quotes)):?>
|
||||
<table cellpadding = "0" cellspacing = "0" class="quotetable">
|
||||
<tr>
|
||||
<th><?php __('Revision'); ?></th>
|
||||
<th><?php __('Sale Currency'); ?></th>
|
||||
|
|
@ -34,12 +34,10 @@
|
|||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('New Quote', true), array('controller'=> 'documents', 'action'=>'newDocument/quote/'.$enquiry['Enquiry']['id']));?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="addQuote" id="<?=$enquiry['Enquiry']['id'];?>">New Quote</button>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@
|
|||
|
||||
}?>
|
||||
</h3>
|
||||
<button>New Quote</button>
|
||||
|
||||
<? echo $this->element('quote_table', $quotes);
|
||||
?>
|
||||
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
|
||||
|
||||
<div class="related">
|
||||
<h3>Jobs for this Enquiry</h3>
|
||||
<h3>Jobs from this Enquiry</h3>
|
||||
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
|
|
@ -168,8 +168,7 @@
|
|||
<th>Date Sent to Customer</th>
|
||||
|
||||
<th>Domestic Freight Paid By</th>
|
||||
<th>Sale Category</th>
|
||||
<th>Shipment Category</th>
|
||||
|
||||
<th>Comments</th>
|
||||
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
|
|
@ -210,18 +209,13 @@
|
|||
<td>
|
||||
<?php echo $job['Job']['domestic_freight_paid_by']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $job['Job']['sale_category']; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $job['Job']['shipment_category']; ?>
|
||||
</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'])); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -229,7 +223,7 @@
|
|||
|
||||
</div>
|
||||
<div class="actions">
|
||||
<?=$javascript->link('add_job');?>
|
||||
<?=$javascript->link('view_enquiry');?>
|
||||
<ul>
|
||||
<li><button class="addJob" id="<?=$enquiry['Enquiry']['id'];?>">New Job</button></li>
|
||||
</ul>
|
||||
|
|
@ -259,7 +253,7 @@
|
|||
<th>Customer</th>
|
||||
<th>Paid / Unpaid</th>
|
||||
<th>Payment Received Date</th>
|
||||
<th>User</th>
|
||||
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
|
|
@ -307,11 +301,9 @@
|
|||
|
||||
?>
|
||||
|
||||
<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(__('View', true), array('controller'=>'documents', 'action' => 'view', $invoice['Invoice']['document_id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('controller'=>'invoices','action' => 'edit', $invoice['Invoice']['id'])); ?>
|
||||
|
||||
</td>
|
||||
|
|
@ -343,5 +335,5 @@
|
|||
</div>
|
||||
|
||||
|
||||
<?php // debug($enquiry);?>
|
||||
<?php debug($enquiry);?>
|
||||
<?php //debug($emails); ?>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
<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
|
||||
|
|
@ -73,9 +73,7 @@
|
|||
|
||||
</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('action' => 'view', $invoice['Invoice']['id'])); ?>
|
||||
<?php echo $html->link(__('Edit', true), array('action' => 'edit', $invoice['Invoice']['id'])); ?>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
|
||||
<div class="users view">
|
||||
<h2><?php __('Contact: '.$user['User']['username'] );?></h2>
|
||||
<h2><?php __('Contact: '.$user['User']['first_name'].' '.$user['User']['last_name'] );?></h2>
|
||||
|
||||
<? if(isset($customer)):?>
|
||||
<h3>Customer: <?=$html->link($customer['Customer']['name'], '/customers/view/'.$customer['Customer']['id']);?></h3>
|
||||
|
|
|
|||
|
|
@ -50,4 +50,14 @@ $(function() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
//Quote code below
|
||||
|
||||
|
||||
$(".addQuote").click(function() {
|
||||
window.location = '/documents/newDocument/quote/'+$( this ).attr('id');
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue