WIP
This commit is contained in:
parent
9a26f51f1c
commit
a7236b950a
|
|
@ -531,8 +531,11 @@ ENDINSTRUCTIONS;
|
||||||
//die(print_r($this->data));
|
//die(print_r($this->data));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->Document->saveAll($this->data)) {
|
if ($this->Document->saveAll($this->data)) {
|
||||||
echo 'SUCCESS'; //this is so stupid
|
echo 'SUCCESS'; //this is so stupid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo 'FAILURE';
|
echo 'FAILURE';
|
||||||
}
|
}
|
||||||
|
|
@ -541,8 +544,7 @@ ENDINSTRUCTIONS;
|
||||||
echo 'FAILURE';
|
echo 'FAILURE';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Convert a Quote to an OrderAcknowledgement.
|
* Convert a Quote to an OrderAcknowledgement.
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,16 @@ class InvoicesController extends AppController {
|
||||||
);
|
);
|
||||||
|
|
||||||
function index() {
|
function index() {
|
||||||
$this->Invoice->recursive = 0;
|
$this->Invoice->recursive = 0;
|
||||||
$this->set('invoices', $this->paginate());
|
$this->set('invoices', $this->paginate());
|
||||||
|
|
||||||
|
/*$q = <<<EOT
|
||||||
|
select i.id, i.document_id, i.job_id, i.issue_date, i.due_date, i.paid, i.payment_received_date, i.amount_invoiced, i.amount_received, i.title, j.id, j.title, e.id, e.title, e.gst, c.id, c.name from invoices i JOIN jobs j, customers c, enquiries e WHERE i.job_id = j.id AND i.customer_id = c.id AND i.enquiry_id = e.id ORDER BY i.id DESC;
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
$results = $this->Invoice->query($q);
|
||||||
|
|
||||||
|
$this->set('invoices', $results);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -91,4 +99,4 @@ class InvoicesController extends AppController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ class LineItemsController extends AppController {
|
||||||
$this->LineItem->create($this->data);
|
$this->LineItem->create($this->data);
|
||||||
|
|
||||||
if ($this->LineItem->save($this->data)) {
|
if ($this->LineItem->save($this->data)) {
|
||||||
echo "SUCCESS";
|
echo "SUCCESS"; // matching on strings rather than HTTP status codes :(
|
||||||
|
$this->updateInvoice($this->data['LineItem']['document_id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "FAILURE";
|
echo "FAILURE";
|
||||||
|
|
||||||
//print_r($this->data);
|
//print_r($this->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ class LineItemsController extends AppController {
|
||||||
|
|
||||||
if ($this->LineItem->save($this->data)) {
|
if ($this->LineItem->save($this->data)) {
|
||||||
echo "SUCCESS";
|
echo "SUCCESS";
|
||||||
|
$this->updateInvoice($this->data['LineItem']['document_id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "FAILURE";
|
echo "FAILURE";
|
||||||
|
|
@ -55,6 +56,7 @@ class LineItemsController extends AppController {
|
||||||
else {
|
else {
|
||||||
if ($this->LineItem->del($id)) {
|
if ($this->LineItem->del($id)) {
|
||||||
echo "SUCCESS";
|
echo "SUCCESS";
|
||||||
|
$this->updateInvoice($this->data['LineItem']['document_id']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
echo "FAILURE";
|
echo "FAILURE";
|
||||||
|
|
@ -107,5 +109,21 @@ class LineItemsController extends AppController {
|
||||||
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
|
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding or editing an Invoice means we need to update the invoiced_amount column
|
||||||
|
// issue #54
|
||||||
|
function updateInvoice($documentID) {
|
||||||
|
// If we've changed a line_item for an invoice, update the invoiced amount
|
||||||
|
// on the invoices table.
|
||||||
|
$document = $this->LineItem->Document->find('first', array('conditions' => array('Document.id' => $documentID), 'recursive'=>1));
|
||||||
|
// For invoices, we need to save the calculated invoice total to implement issue #54.
|
||||||
|
if($document['Document']['type'] == 'invoice') {
|
||||||
|
$enquiry = $this->LineItem->Document->getEnquiry($document);
|
||||||
|
$invoice = $this->LineItem->Document->Invoice->find('first', array('conditions'=>array('Invoice.id'=>$document['Invoice']['id'])));
|
||||||
|
$totals = $this->calculateTotals($document, $enquiry['Enquiry']['gst']);
|
||||||
|
$invoice['Invoice']['amount_invoiced'] = $totals['total'];
|
||||||
|
$this->LineItem->Document->Invoice->save($invoice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
echo $form->input('id');
|
echo $form->input('id');
|
||||||
echo $form->input('issue_date');
|
echo $form->input('issue_date');
|
||||||
echo $form->input('due_date');
|
echo $form->input('due_date');
|
||||||
echo $form->input('title');
|
echo $form->input('title', array('class'=>'disabled', 'readonly'=>'readonly'));
|
||||||
echo $form->input('paid');
|
echo $form->input('paid');
|
||||||
echo $form->input('payment_received_date');
|
echo $form->input('payment_received_date');
|
||||||
echo $form->input('enquiry_id', array('type'=>'hidden'));
|
echo $form->input('enquiry_id', array('type'=>'hidden'));
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,15 @@
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
<th><?php echo $paginator->sort('issue_date');?></th>
|
<th><?php echo $paginator->sort('issue_date');?></th>
|
||||||
<th><?php echo $paginator->sort('due_date');?></th>
|
<th>Date Due</th>
|
||||||
|
<th><?php echo $paginator->sort('paid');?></th>
|
||||||
|
<th>Date Received</th>
|
||||||
<th><?php echo $paginator->sort('Invoice Number');?></th>
|
<th><?php echo $paginator->sort('Invoice Number');?></th>
|
||||||
<th><?php echo $paginator->sort('Job Number');?></th>
|
<th><?php echo $paginator->sort('Job Number');?></th>
|
||||||
<th><?php echo $paginator->sort('enquiry_id');?></th>
|
<th><?php echo $paginator->sort('enquiry_id');?></th>
|
||||||
<th><?php echo $paginator->sort('Customer'); ?></th>
|
<th><?php echo $paginator->sort('Customer'); ?></th>
|
||||||
<th><?php echo $paginator->sort('paid');?></th>
|
|
||||||
<th><?php echo $paginator->sort('payment_received_date');?></th>
|
|
||||||
|
|
||||||
|
|
||||||
<th class="actions"><?php __('Actions');?></th>
|
<th class="actions"><?php __('Actions');?></th>
|
||||||
|
|
@ -35,22 +37,12 @@
|
||||||
<td>
|
<td>
|
||||||
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['issue_date'])); ?>
|
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['issue_date'])); ?>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['due_date'])); ?>
|
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['due_date'])); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<?php echo $invoice['Invoice']['title']; ?>
|
<td>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?php echo $html->link($invoice['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $invoice['Invoice']['job_id'])); ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?php echo $html->link($invoice['Enquiry']['title'], array('controller' => 'enquiries', 'action' => 'view', $invoice['Enquiry']['id'])); ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?php echo $html->link($invoice['Customer']['name'], array('controller'=>'customers', 'action'=>'view', $invoice['Customer']['id'])); ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?php
|
<?php
|
||||||
if($invoice['Invoice']['paid'] == 0) {
|
if($invoice['Invoice']['paid'] == 0) {
|
||||||
echo "UNPAID";
|
echo "UNPAID";
|
||||||
|
|
@ -72,7 +64,20 @@
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
<td>TODO</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $invoice['Invoice']['title']; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $html->link($invoice['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $invoice['Invoice']['job_id'])); ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $html->link($invoice['Enquiry']['title'], array('controller' => 'enquiries', 'action' => 'view', $invoice['Enquiry']['id'])); ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $html->link($invoice['Customer']['name'], array('controller'=>'customers', 'action'=>'view', $invoice['Customer']['id'])); ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<?=$html->link('View', '/documents/view/'.$invoice['Invoice']['document_id']);?>
|
<?=$html->link('View', '/documents/view/'.$invoice['Invoice']['document_id']);?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue