Added address selection to POs.

This commit is contained in:
Karl Cordes 2013-04-13 20:01:47 +10:00
parent 52bc47658b
commit 9485f80428
5 changed files with 812 additions and 768 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,178 +1,178 @@
<?php
class Document extends AppModel {
var $name = 'Document';
var $name = 'Document';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
);
var $hasMany = array(
var $hasMany = array(
'LineItem' => array(
'className' => 'LineItem',
'foreignKey' => 'document_id',
'order' => 'LineItem.item_number ASC'
),
'LineItem' => array(
'className' => 'LineItem',
'foreignKey' => 'document_id',
'order' => 'LineItem.item_number ASC'
),
'DocPage' => array(
'className'=> 'DocPage',
'foreignKey' => 'document_id',
'order' => 'DocPage.page_number ASC'
),
'DocPage' => array(
'className'=> 'DocPage',
'foreignKey' => 'document_id',
'order' => 'DocPage.page_number ASC'
),
'DocumentAttachment' => array(
'className'=> 'DocumentAttachment',
'foreignKey' => 'document_id',
'order' => 'DocumentAttachment.id ASC'
),
'DocumentAttachment' => array(
'className'=> 'DocumentAttachment',
'foreignKey' => 'document_id',
'order' => 'DocumentAttachment.id ASC'
),
);
);
var $hasOne = array(
'Invoice' => array(
'className' => 'Invoice',
'foreignKey'=> 'document_id'
),
'Quote' => array(
'className'=>'Quote',
'foriegnKey'=>'document_id'
),
var $hasOne = array(
'Invoice' => array(
'className' => 'Invoice',
'foreignKey'=> 'document_id'
),
'Quote' => array(
'className'=>'Quote',
'foriegnKey'=>'document_id'
),
'PurchaseOrder' => array(
'className'=>'PurchaseOrder',
'foreignKey'=>'document_id'
),
'PurchaseOrder' => array(
'className'=>'PurchaseOrder',
'foreignKey'=>'document_id'
),
'OrderAcknowledgement' => array(
'className' => 'OrderAcknowledgement',
'foreignKey' => 'document_id'
)
);
'OrderAcknowledgement' => array(
'className' => 'OrderAcknowledgement',
'foreignKey' => 'document_id'
)
);
//So much refactoring possible on this.
function getCurrency($document) {
//So much refactoring possible on this.
function getCurrency($document) {
if(!empty($document['Invoice']['id'])) {
$currencyID = $document['Invoice']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
if(!empty($document['Invoice']['id'])) {
$currencyID = $document['Invoice']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->Invoice->Currency->find('first',$conditions);
}
elseif(!empty($document['Quote']['id'])) {
$currencyID = $document['Quote']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->Quote->Currency->find('first',$conditions);
}
elseif(!empty($document['PurchaseOrder']['id'])) {
$currencyID = $document['PurchaseOrder']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->PurchaseOrder->Currency->find('first',$conditions);
}
elseif(!empty($document['OrderAcknowledgement']['id'])) {
$currencyID = $document['OrderAcknowledgement']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->OrderAcknowledgement->Currency->find('first',$conditions);
}
}
function __getCurrencyConditions($currencyID) {
return array('recursive'=>0, 'conditions'=>array('Currency.id'=>$currencyID));
}
function getDocType($document) {
return $document['Document']['type'];
}
function getDocFullName($type) {
switch($type) {
case 'quote':
$fullName = 'Quotation';
break;
case 'invoice':
$fullName = 'Invoice';
break;
case 'purchaseOrder':
$fullName = 'Purchase Order';
break;
case 'orderAck':
$fullName = 'Order Acknowledgement';
break;
}
return $fullName;
}
/**
* Depending on the type of document. Return the CMC reference
* ie. Enquiry Number (Quote)
* Invoice Number (Invoice)
* @param <type> $document
* @param <type> $type
*/
function getCMCReferenceNumber($document, $type) {
switch($type) {
case 'quote':
break;
case 'invoice':
break;
case 'purchaseOrder':
break;
case 'orderAck':
break;
}
return $fullName;
}
function getEnquiry($document) {
if(!empty($document['Invoice']['id'])) {
return $this->Invoice->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
}
elseif(!empty($document['Quote']['id'])) {
return $this->Quote->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Quote']['enquiry_id'])));
}
elseif(!empty($document['PurchaseOrder']['id'])) {
return $this->PurchaseOrder->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
}
elseif(!empty($document['OrderAcknowledgement']['id'])) {
return $this->OrderAcknowledgement->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['OrderAcknowledgement']['enquiry_id'])));
}
}
/**
* Does GST apply on this document. Based on the Enquiry GST TinyInt.
* @param <type> $enquiry
* @return Bool
*/
function gstApplies($enquiry) {
if ($enquiry['Enquiry']['gst'] == 0) {
return false;
}
else {
return true;
}
}
function isLatestRevision($enquiry) {
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiry);
return $this->Invoice->Currency->find('first',$conditions);
}
elseif(!empty($document['Quote']['id'])) {
$currencyID = $document['Quote']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->Quote->Currency->find('first',$conditions);
}
elseif(!empty($document['PurchaseOrder']['id'])) {
$currencyID = $document['PurchaseOrder']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->PurchaseOrder->Currency->find('first',$conditions);
}
elseif(!empty($document['OrderAcknowledgement']['id'])) {
$currencyID = $document['OrderAcknowledgement']['currency_id'];
$conditions = $this->__getCurrencyConditions($currencyID);
return $this->OrderAcknowledgement->Currency->find('first',$conditions);
}
}
function __getCurrencyConditions($currencyID) {
return array('recursive'=>0, 'conditions'=>array('Currency.id'=>$currencyID));
}
function getDocType($document) {
return $document['Document']['type'];
}
function getDocFullName($type) {
switch($type) {
case 'quote':
$fullName = 'Quotation';
break;
case 'invoice':
$fullName = 'Invoice';
break;
case 'purchaseOrder':
$fullName = 'Purchase Order';
break;
case 'orderAck':
$fullName = 'Order Acknowledgement';
break;
}
return $fullName;
}
/**
* Depending on the type of document. Return the CMC reference
* ie. Enquiry Number (Quote)
* Invoice Number (Invoice)
* @param <type> $document
* @param <type> $type
*/
function getCMCReferenceNumber($document, $type) {
switch($type) {
case 'quote':
break;
case 'invoice':
break;
case 'purchaseOrder':
break;
case 'orderAck':
break;
}
return $fullName;
}
function getEnquiry($document) {
if(!empty($document['Invoice']['id'])) {
return $this->Invoice->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
}
elseif(!empty($document['Quote']['id'])) {
return $this->Quote->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Quote']['enquiry_id'])));
}
elseif(!empty($document['PurchaseOrder']['id'])) {
return $this->PurchaseOrder->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['Invoice']['enquiry_id'])));
}
elseif(!empty($document['OrderAcknowledgement']['id'])) {
return $this->OrderAcknowledgement->Enquiry->find('first',array('conditions'=>array('Enquiry.id'=>$document['OrderAcknowledgement']['enquiry_id'])));
}
}
/**
* Does GST apply on this document. Based on the Enquiry GST TinyInt.
* @param <type> $enquiry
* @return Bool
*/
function gstApplies($enquiry) {
if ($enquiry['Enquiry']['gst'] == 0) {
return false;
}
else {
return true;
}
}
function isLatestRevision($enquiry) {
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiry);
}
}

View file

@ -1,13 +1,14 @@
<h2>Order Acknowledgement: <?=$html->link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?> for <?=$html->link($enquiry['Customer']['name'], '/customers/view/'.$enquiry['Customer']['id']);?></h2>
<h2>Order Acknowledgement: <span class="job-title"><?=$html->link($job['Job']['title'], array('controller'=>'jobs', 'action'=>'view', $job['Job']['id']));?></span> for <?=$html->link($enquiry['Customer']['name'], '/customers/view/'.$enquiry['Customer']['id']);?></h2>
<div id="flashMessage" class="message">
</div>
<div class="docButtons">
<?=$html->link('Generate PDF of this Order Acknowledgement', '/documents/pdf/'.$document['Document']['id']);?>
<?=$html->link('Email PDF to Customer', '/documents/email_pdf/'.$document['Document']['id']);?>
</div>
<div class="docOperations" style="display: none;">
<div class="docOperations">
<h3>Create an Invoice from this OA</h3>
<?=$html->link('Create an Invoice based on this OA', '/documents/convert_to_invoice/'.$document['Document']['id'], array('class'=>'actionLink'));?>
</div>
@ -18,10 +19,15 @@
<? echo $form->create('Document',array('type'=>'post','action'=>'edit', 'default'=>false));
echo $form->input('Document.id');
echo $form->input('OrderAcknowledgement.id');
echo $form->input('OrderAcknowledgement.job_id');
echo $form->input('OrderAcknowledgement.currency_id');
echo $form->input('OrderAcknowledgement.issue_date');
echo $form->input('billing_address_id', array('div' => 'addressradio', 'legend' => 'Select Billing Address', 'options' => $billing_addresses_list, 'type' => 'radio', 'class'=>'billing_address'));
echo $form->input('Document.bill_to');
echo $form->input('shipping_address_id', array('div' => 'addressradio','legend' => 'Select Shipping Address', 'options' => $shipping_addresses_list, 'type' => 'radio', 'class' => 'shipping_address'));
echo $form->input('Document.ship_to');
@ -36,7 +42,6 @@
<span id="orderAckID" style="display: none;"><?=$document['OrderAcknowledgement']['id']?></span>
<? //debug($this->data);?>
<? //debug($enquiry);?>
<?php // debug($job);?>

View file

@ -29,8 +29,7 @@ echo $form->input('Document.id');
<div class="docOperations">
<h3>Has <?=$html->link($enquiry['Customer']['name'], array('controller'=>'customers','action'=>'view',$enquiry['Customer']['id']));?> placed an order for this Quote?</h3>
<? //$html->link('Convert this Enquiry to a new Job and Generate an Order Acknowledgement', '/documents/convert_to_oa/'.$document['Document']['id'], array('class'=>'actionLink'));?>
<button id="createJobAndOA">Create a New Job and Order Acknowledgement</button>
<button id="createOA">Create Order Acknowledgement</button>
</div>
<div class="pages">
@ -76,17 +75,19 @@ echo $form->input('Document.id');
<div id="addJobConfirmation" title="Create New Job and Order Acknowledgment">
<span>This will create a new job and an Order Acknowledgement based on this Quote</span><br>
<span>This will create an Order Acknowledgement based on this Quote</span><br>
<span>The Enquiry will also be marked as "Job Won - Order Placed"</span><br><br>
<span>You can create a new Job now, or add it to an existing Job later</span><br>
<? echo $form->create('Document',array('type'=>'post','action'=>'convert_to_oa'));
echo $form->input('Document.id');
echo $form->input('Job.customer_order_number');
echo $form->input('Document.id');
echo $form->input('Job.create_new_job', array('type'=>'select', 'options'=> array('No', 'Yes')));
echo $form->input('Job.customer_order_number');
echo $form->end();
?>
</div>
<? //debug($this->data);?>
<? //debug($enquiry);?>
<? //print_r($enquiry);?>
<?php //debug($document);?>
<?php //debug($docType);?>

View file

@ -337,13 +337,8 @@ $(function() {
});
$.get('/quotes/edit/'+quoteID, function(data) {
$("#QuoteDetails").html(data);
$('#QuoteCommercialComments').ckeditor(config);
$("#QuoteDetails").dialog('open');
});
});
@ -416,11 +411,11 @@ $(function() {
updateTextFields(); //Update the CKEditor instances.
var invoiceDetails = $('#DocumentEditForm').find('input,select,textarea');
var oaDetails = $('#DocumentEditForm').find('input,select,textarea');
$.post('/documents/ajax_edit', invoiceDetails, function(data) {
$.post('/documents/ajax_edit', oaDetails, function(data) {
if(data =='SUCCESS') {
$("#flashMessage").html("Order Acknowledgement Saved Successfully");
}
@ -428,6 +423,7 @@ $(function() {
$("#flashMessage").html("Unable to Save Order Acknowledgement");
}
$('.job-title').html($("#OrderAcknowledgementJobId :selected").text());
$("#flashMessage").show();
@ -438,10 +434,29 @@ $(function() {
$("#createJobAndOA").click(function() {
$("#createOA").click(function() {
$("#addJobConfirmation").dialog('open');
});
$(".billing_address").click(function() {
if($(this).val() > 0 ) {
var address = $(this).next().html();
var c = confirm("Set the 'Bill To' field to this address?");
if(c) {
$("#DocumentBillTo").val(address);
}
}
});
$(".shipping_address").click(function() {
if($(this).val() > 0 ) {
var address = $(this).next().html();
var c = confirm("Set the 'Ship To' field to this address?");
if(c) {
$("#DocumentShipTo").val(address);
}
}
});
});