Countries Updated

This commit is contained in:
Karl Cordes 2010-03-11 10:32:00 +11:00
parent a8795ae676
commit 53f2d3fccc
9 changed files with 184 additions and 32 deletions

View file

@ -64,5 +64,43 @@ class CountriesController extends AppController {
} }
} }
function completeCountry() {
$query = strtolower($_GET["term"]);
if($query == null) {
return;
}
App::import('Core', 'Sanitize');
$query = Sanitize::clean($query);
$countries = $this->Country->find('all', array(
'conditions' => array(
'Country.name LIKE' => '%'.$query.'%'
),'fields' => array('Country.name')
));
foreach ($countries as $country) {
$countryid = $country['Country']['id'];
$country_list[] = array('id'=> $countryid, 'label' => $country['Country']['name']);
}
$countries_json = json_encode($country_list);
$this->set('countries_json', $countries_json);
$this->layout = 'ajax';
}
} }
?> ?>

View file

@ -58,7 +58,7 @@ class CustomersController extends AppController {
} }
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list')); $this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('states', $this->Customer->Address->State->find('list')); $this->set('states', $this->Customer->Address->State->find('list'));
$this->set('countries', $this->Customer->Address->Country->find('list')); //$this->set('countries', $this->Customer->Country->find('list', array('order'=>array('Country.name ASC'))));
} }

View file

@ -257,17 +257,73 @@ class QuotesController extends AppController {
} }
}
/**
* Revise an existing quote.
*
* Might make this AJAXy in the future. For now, I just want to make it work
* Process is:
* 1.Check what Quote ID we're revising
* 2. Find that quote
* 3. find the Line Items in this quote
* 4. Make a new Quote.
* 5. Make new copies of the line items referring to that quote
* 6. Make copies of the QuotePages
*
*/
function revise($id) {
if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
}
else {
$quoteid = $id;
$quote = $this->Quote->read(null,$id);
$enquiryid = $quote['Quote']['enquiry_id'];
$number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
$number_of_revisions++;
//debug($quote);
// $this->Quote->create();
$this->data['Quote'] = $quote['Quote'];
$this->data['Quote']['id'] = null;
$this->data['Quote']['created'] = null;
$this->data['Quote']['modified'] = null;
$this->data['Quote']['revision'] = $number_of_revisions;
$this->data['Quote']['enquiry_id'] = $enquiryid;
foreach($quote['LineItem'] as $item) {
$item['id'] = null;
$item['quote_id'] = null;
$this->data['LineItem'][] = $item;
}
foreach($quote['QuotePage'] as $page) {
$page['id'] = null;
$page['quote_id'] = null;
$this->data['QuotePage'][] = $page;
}
//debug($this->data);
if ($this->Quote->saveAll($this->data)) {
$quoteid = $this->Quote->id;
$this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true));
$this->redirect(array('action'=>'view/'.$quoteid));
}
} }
}
} }

View file

@ -76,7 +76,9 @@ class Customer extends AppModel {
var $belongsTo = array('CustomerCategory'=> var $belongsTo = array('CustomerCategory'=>
array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id') array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id'),
'Country' =>
array('className' =>'Country', 'foreignKey' => 'country_id')
); );

31
vendors/xtcpdf.php vendored
View file

@ -388,6 +388,9 @@ ENDPRODUCT;
$subTotal = 0; $subTotal = 0;
$options = 0; //Toggled to 1 when we encounter an Optional product. Stops the totals being printed.
print_r($pageProducts); print_r($pageProducts);
foreach ($pageProducts as $page) { foreach ($pageProducts as $page) {
@ -433,6 +436,9 @@ ENDPRODUCT;
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description']; $fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
if($product[$docType]['option'] == 1) {
$options = 1;
}
$currentX = $this->GetX(); $currentX = $this->GetX();
@ -495,7 +501,7 @@ ENDPRODUCT;
$this->totals($currency, $subTotal, $gst); $this->totals($currency, $subTotal, $gst, $options);
$this->commercialComments($commercialDetails); $this->commercialComments($commercialDetails);
@ -594,7 +600,7 @@ ENDHTMLCONTENTS;
} }
function totals($currency, $subTotal, $gst) { function totals($currency, $subTotal, $gst, $options) {
$itemColwidth = 12; $itemColwidth = 12;
$qtyColwidth = 10; $qtyColwidth = 10;
@ -612,7 +618,14 @@ ENDHTMLCONTENTS;
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
}
else {
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1);
}
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
@ -624,6 +637,10 @@ ENDHTMLCONTENTS;
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
}
else {
if($gst == 1) { if($gst == 1) {
$gstAmount = 0.1*$subTotal; $gstAmount = 0.1*$subTotal;
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
@ -634,6 +651,9 @@ ENDHTMLCONTENTS;
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
} }
}
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
@ -644,6 +664,10 @@ ENDHTMLCONTENTS;
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0); $this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();
if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
}
else {
if($gst == 1) { if($gst == 1) {
$totalPrice = $subTotal * 1.1; $totalPrice = $subTotal * 1.1;
} }
@ -651,6 +675,9 @@ ENDHTMLCONTENTS;
$totalPrice = $subTotal; $totalPrice = $subTotal;
} }
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1); $this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $totalPrice), 1, 'C', 0, 1);
}
$totalHeight += $this->getLastH(); $totalHeight += $this->getLastH();

View file

@ -0,0 +1,6 @@
<?
if(isset($countries_json)) {
echo $countries_json;
}
?>

View file

@ -10,7 +10,10 @@
echo $form->input('name', array('id'=>'customerName')); echo $form->input('name', array('id'=>'customerName'));
echo "<br><br><span class=\"warning\">If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "<br>Do Not Add Duplicates.</span>"; echo "<br><br><span class=\"warning\">If the Customer you are adding appears automatically, it already exists in the ".$html->link('Customers Index', array('action' => 'index')). "<br>Do Not Add Duplicates.</span>";
echo $form->input('abn', array('label'=>'ABN', 'title' => 'The 11-digit Australian Business Number for the new Customer. Spaces or no spaces - it does not matter')); echo $form->input('country_name', array('default'=>'Australia'));
echo $form->input('country_id', array('type'=>'hidden', 'value'=>1));
echo $form->input('abn', array('label'=>'ABN', 'title' => 'The 11-digit Australian Business Number for the new Customer. Spaces or no spaces - it does not matter', 'div'=>array('id'=>'ABN')));
echo $this->element('payment_terms_box'); echo $this->element('payment_terms_box');
echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies')); echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies'));

View file

@ -27,7 +27,8 @@
<td class="actions"> <td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'quotes', 'action'=>'view', $quote['Quote']['id'])); ?> <?php echo $html->link(__('View', true), array('controller'=> 'quotes', 'action'=>'view', $quote['Quote']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=>'quotes', 'action'=>'edit', $quote['Quote']['id'])); ?> <?php echo $html->link(__('Revise', true), array('controller'=>'quotes', 'action'=>'revise', $quote['Quote']['id'])); ?>
</td> </td>
</tr> </tr>

View file

@ -15,4 +15,23 @@ $(function() {
minLength: 1 minLength: 1
}); });
$("#CustomerCountryName").autocomplete({
source: "/countries/completeCountry",
minLength: 2,
select: function(event, ui) {
//alert("You selected " + ui.item.value + " ID:"+ ui.item.id);
$("#CustomerCountryId").val(ui.item.id);
if(ui.item.value == 'Australia') {
$("#ABN").show();
}
else {
$("#ABN").hide();
}
}
});
}); });