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('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

@ -116,7 +116,7 @@ class QuotesController extends AppController {
function pdf($id = null) {
//Configure::write('debug',0);
//Configure::write('debug',0);
if(!$id) {
$this->Session->setFlash(__('Invalid Quote', true));
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
@ -205,7 +205,7 @@ class QuotesController extends AppController {
$quoteid = $this->data['Quote']['id'];
$quote = $this->Quote->findById($quoteid);
//$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
$enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id'])));
@ -253,21 +253,77 @@ class QuotesController extends AppController {
$this->set('products', $quoteProducts);
}
}
/**
* 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'=>
array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id')
array('className' => 'CustomerCategory','foreignKey' => 'customer_category_id'),
'Country' =>
array('className' =>'Country', 'foreignKey' => 'country_id')
);

59
vendors/xtcpdf.php vendored
View file

@ -388,6 +388,9 @@ ENDPRODUCT;
$subTotal = 0;
$options = 0; //Toggled to 1 when we encounter an Optional product. Stops the totals being printed.
print_r($pageProducts);
foreach ($pageProducts as $page) {
@ -424,7 +427,7 @@ ENDPRODUCT;
echo "<h2>$pageNo</h2>";
// print_r($page);
// print_r($page);
//Start Printing Product cells, until we run out of room. Then continue on the next page
@ -433,6 +436,9 @@ ENDPRODUCT;
$fullDesc = "<b>".$product[$docType]['title'].'</b><br>'.$product[$docType]['description'];
if($product[$docType]['option'] == 1) {
$options = 1;
}
$currentX = $this->GetX();
@ -495,7 +501,7 @@ ENDPRODUCT;
$this->totals($currency, $subTotal, $gst);
$this->totals($currency, $subTotal, $gst, $options);
$this->commercialComments($commercialDetails);
@ -586,7 +592,7 @@ ENDHTMLCONTENTS;
function termsAndConditions() {
@ -594,7 +600,7 @@ ENDHTMLCONTENTS;
}
function totals($currency, $subTotal, $gst) {
function totals($currency, $subTotal, $gst, $options) {
$itemColwidth = 12;
$qtyColwidth = 10;
@ -612,7 +618,14 @@ ENDHTMLCONTENTS;
$totalHeight += $this->getLastH();
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH();
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $subTotal), 1, 'C', 0, 1);
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);
}
$totalHeight += $this->getLastH();
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
@ -624,17 +637,24 @@ ENDHTMLCONTENTS;
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH();
if($gst == 1) {
$gstAmount = 0.1*$subTotal;
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
$totalHeight += $this->getLastH();
if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
}
else {
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
$totalHeight += $this->getLastH();
if($gst == 1) {
$gstAmount = 0.1*$subTotal;
$this->MultiCell($totalPricColwidth, 6, $this->formatCurrency($currency['symbol'], $gstAmount), 1 , 'C', 0, 1);
$totalHeight += $this->getLastH();
}
else {
$this->MultiCell($totalPricColwidth, 6, "N/A", 1 , 'C', 0, 1);
$totalHeight += $this->getLastH();
}
}
$this->MultiCell($itemColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH();
$this->MultiCell($qtyColwidth, 6, "", 1, 'C', 0, 0);
@ -644,13 +664,20 @@ ENDHTMLCONTENTS;
$this->MultiCell($unitpriceColwidth, 6, "", 1, 'C', 0, 0);
$totalHeight += $this->getLastH();
if($gst == 1) {
$totalPrice = $subTotal * 1.1;
if($options == 1) {
$this->MultiCell($totalPricColwidth, 6, $currency['symbol']. "TBA", 1, 'C', 0, 1);
}
else {
$totalPrice = $subTotal;
if($gst == 1) {
$totalPrice = $subTotal * 1.1;
}
else {
$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();

View file

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

View file

@ -9,8 +9,11 @@
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 $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 $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies'));

View file

@ -27,7 +27,8 @@
<td class="actions">
<?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>
</tr>

View file

@ -15,4 +15,23 @@ $(function() {
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();
}
}
});
});