WIP
This commit is contained in:
parent
9a26f51f1c
commit
a7236b950a
|
|
@ -533,6 +533,9 @@ ENDINSTRUCTIONS;
|
|||
|
||||
if ($this->Document->saveAll($this->data)) {
|
||||
echo 'SUCCESS'; //this is so stupid
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
echo 'FAILURE';
|
||||
}
|
||||
|
|
@ -542,7 +545,6 @@ ENDINSTRUCTIONS;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Convert a Quote to an OrderAcknowledgement.
|
||||
|
|
|
|||
|
|
@ -12,8 +12,16 @@ class InvoicesController extends AppController {
|
|||
);
|
||||
|
||||
function index() {
|
||||
$this->Invoice->recursive = 0;
|
||||
$this->Invoice->recursive = 0;
|
||||
$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);*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ class LineItemsController extends AppController {
|
|||
$this->LineItem->create($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 {
|
||||
echo "FAILURE";
|
||||
|
||||
//print_r($this->data);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ class LineItemsController extends AppController {
|
|||
|
||||
if ($this->LineItem->save($this->data)) {
|
||||
echo "SUCCESS";
|
||||
$this->updateInvoice($this->data['LineItem']['document_id']);
|
||||
}
|
||||
else {
|
||||
echo "FAILURE";
|
||||
|
|
@ -55,6 +56,7 @@ class LineItemsController extends AppController {
|
|||
else {
|
||||
if ($this->LineItem->del($id)) {
|
||||
echo "SUCCESS";
|
||||
$this->updateInvoice($this->data['LineItem']['document_id']);
|
||||
}
|
||||
else {
|
||||
echo "FAILURE";
|
||||
|
|
@ -107,5 +109,21 @@ class LineItemsController extends AppController {
|
|||
$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('issue_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('payment_received_date');
|
||||
echo $form->input('enquiry_id', array('type'=>'hidden'));
|
||||
|
|
|
|||
|
|
@ -10,13 +10,15 @@
|
|||
<tr>
|
||||
|
||||
<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('Job Number');?></th>
|
||||
<th><?php echo $paginator->sort('enquiry_id');?></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>
|
||||
|
|
@ -35,22 +37,12 @@
|
|||
<td>
|
||||
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['issue_date'])); ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php echo date('j M Y',$time->toUnix($invoice['Invoice']['due_date'])); ?>
|
||||
</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>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
if($invoice['Invoice']['paid'] == 0) {
|
||||
echo "UNPAID";
|
||||
|
|
@ -72,6 +64,19 @@
|
|||
?>
|
||||
|
||||
</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">
|
||||
|
|
|
|||
Loading…
Reference in a new issue