2010-01-30 23:57:51 -08:00
|
|
|
<?php
|
|
|
|
|
class LineItemsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'LineItems';
|
2011-05-24 02:11:07 -07:00
|
|
|
var $helpers = array('Html', 'Form', 'Javascript', 'Number');
|
2010-02-22 19:49:19 -08:00
|
|
|
|
|
|
|
|
var $components = array('RequestHandler');
|
2010-01-30 23:57:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
function ajax_add() {
|
2011-05-16 21:30:23 -07:00
|
|
|
$this->layout = 'ajax';
|
2011-05-19 00:05:01 -07:00
|
|
|
if(!empty($this->data)) {
|
|
|
|
|
$this->LineItem->create($this->data);
|
2010-02-22 19:49:19 -08:00
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
if ($this->LineItem->save($this->data)) {
|
2011-05-19 00:05:01 -07:00
|
|
|
echo "SUCCESS";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "FAILURE";
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
//print_r($this->data);
|
2011-05-19 00:05:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "NO-DATA";
|
|
|
|
|
}
|
2010-02-22 19:49:19 -08:00
|
|
|
|
2010-01-30 23:57:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
function ajax_edit() {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
if(!empty($this->data)) {
|
|
|
|
|
|
|
|
|
|
if ($this->LineItem->save($this->data)) {
|
|
|
|
|
echo "SUCCESS";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "FAILURE";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "NO-DATA";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ajax_delete($id = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
if($id == null) {
|
|
|
|
|
echo "FAILURE";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ($this->LineItem->del($id)) {
|
|
|
|
|
echo "SUCCESS";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "FAILURE";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-15 01:26:22 -07:00
|
|
|
/**
|
|
|
|
|
* Get the products table with prices (for quotes, invoices etc)
|
|
|
|
|
* @param <type> $documentID
|
|
|
|
|
*/
|
2011-05-19 00:05:01 -07:00
|
|
|
function getTable($documentID = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
if($documentID == null) {
|
|
|
|
|
echo "INVALID DOCUMENT ID";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$document = $this->LineItem->Document->find('first',array('conditions'=>array('Document.id'=>$documentID)));
|
|
|
|
|
$this->set('document',$document);
|
2010-01-30 23:57:51 -08:00
|
|
|
|
2011-05-24 02:11:07 -07:00
|
|
|
$enquiry = $this->LineItem->Document->getEnquiry($document);
|
2011-06-15 01:26:22 -07:00
|
|
|
$this->set('enquiry', $enquiry);
|
2011-05-24 02:11:07 -07:00
|
|
|
$gst = $this->LineItem->Document->gstApplies($enquiry);
|
|
|
|
|
$this->set('gst',$gst);
|
|
|
|
|
|
|
|
|
|
$this->set('totals', $this->calculateTotals($document, $gst));
|
|
|
|
|
|
|
|
|
|
$currency = $this->LineItem->Document->getCurrency($document);
|
|
|
|
|
$this->set('currencyCode', $currency['Currency']['iso4217']);
|
|
|
|
|
$this->set('currencySymbol', $currency['Currency']['symbol']);
|
2011-05-19 00:05:01 -07:00
|
|
|
}
|
2010-01-30 23:57:51 -08:00
|
|
|
}
|
2011-05-24 02:11:07 -07:00
|
|
|
|
|
|
|
|
function edit($id = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
$this->data = $this->LineItem->read(null,$id);
|
|
|
|
|
$this->set('yesNo', array(0=>'No', 1=>'Yes'));
|
|
|
|
|
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
|
2010-01-30 23:57:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 00:05:01 -07:00
|
|
|
function add($documentID = null) {
|
2011-05-24 02:11:07 -07:00
|
|
|
$this->layout = 'ajax';
|
2011-05-19 00:05:01 -07:00
|
|
|
$document = $this->LineItem->Document->read(null, $documentID);
|
|
|
|
|
$this->set('document', $document);
|
2011-05-24 02:11:07 -07:00
|
|
|
$this->set('yesNo', array(0=>'No', 1=>'Yes'));
|
2011-05-19 00:05:01 -07:00
|
|
|
$this->set('principles', $this->LineItem->Product->Principle->find('list'));
|
2010-02-24 22:12:27 -08:00
|
|
|
}
|
|
|
|
|
|
2010-01-30 23:57:51 -08:00
|
|
|
}
|
|
|
|
|
?>
|