Got this damn thing working
This commit is contained in:
parent
6549c00b49
commit
c1f7384550
|
|
@ -25,7 +25,8 @@ class DocumentsController extends AppController {
|
|||
$this->Session->setFlash(__('Invalid Document.', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
$document = $this->Document->read(null,$id);
|
||||
//$document = $this->Document->read(null,$id);
|
||||
$document = $this->Document->find('first', array('conditions' => array('Document.id' => $id), 'recursive'=>1));
|
||||
|
||||
$this->set('document', $document);
|
||||
|
||||
|
|
@ -77,6 +78,12 @@ class DocumentsController extends AppController {
|
|||
case 'purchaseOrder':
|
||||
$docTypeElement = 'document_purchase_order_view';
|
||||
$this->set('currencies', $this->Document->PurchaseOrder->Currency->find('list'));
|
||||
$this->set('purchaseOrder', $this->Document->PurchaseOrder->find('first',
|
||||
array('conditions'=>
|
||||
array('PurchaseOrder.id' => $document['PurchaseOrder']['id'])
|
||||
)
|
||||
));
|
||||
|
||||
break;
|
||||
case 'orderAck':
|
||||
$this->set('currencies', $this->Document->OrderAcknowledgement->Currency->find('list'));
|
||||
|
|
@ -266,7 +273,7 @@ class DocumentsController extends AppController {
|
|||
|
||||
break;
|
||||
case "purchaseOrder":
|
||||
$enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid);
|
||||
//$enquiry = $this->Document->OrderAcknowledgement->Enquiry->read(null, $enquiryid);
|
||||
$count = $this->Document->PurchaseOrder->findCount();
|
||||
$count++;
|
||||
$offset = 2060;
|
||||
|
|
@ -295,9 +302,8 @@ ALEXANDRIA NSW 2015 AUSTRALIA<br>
|
|||
ENDINSTRUCTIONS;
|
||||
|
||||
|
||||
|
||||
|
||||
$this->data['Document']['user_id']= $enquiry['Enquiry']['user_id'];
|
||||
$currentuser = $this->Session->read('Auth.User');
|
||||
$this->data['Document']['user_id'] = $currentuser['id'];
|
||||
$this->data['Document']['revision'] = 0; //No revisions for POs. I have decreed it!
|
||||
$this->data['Document']['type'] = 'purchaseOrder';
|
||||
break;
|
||||
|
|
@ -492,6 +498,31 @@ ENDINSTRUCTIONS;
|
|||
$this->Document->DocPage->deleteAll(array('document_id'=>$docID));
|
||||
$this->Document->DocPage->updateCounterCache(array('document_id'=>$docID));
|
||||
|
||||
if(isset($this->data['PurchaseOrder'])) {
|
||||
//Delete all the existing JobPurchaseOrder relationships for this PO.
|
||||
//Fuck it. @TODO SQL injection potential here.
|
||||
$query = "DELETE FROM jobs_purchase_orders WHERE purchase_order_id =".$this->data['PurchaseOrder']['id'];
|
||||
$result = $this->Document->query($query);
|
||||
|
||||
}
|
||||
|
||||
if(isset($this->data['PurchaseOrder']['Job'])) {
|
||||
//Loop over the submitted Jobs and add them. Fuck CakePHP is a piece of shit.
|
||||
//This is easier than using the fucking built in crap that doesnt work.
|
||||
//Fuck everything about this.
|
||||
$po_id = $this->data['PurchaseOrder']['id'];
|
||||
foreach($this->data['PurchaseOrder']['Job'] as $job_id) {
|
||||
$query = "INSERT INTO `quotenik`.`jobs_purchase_orders` (`id`, `job_id`, `purchase_order_id`) VALUES (NULL, '{$job_id}', '{$po_id}');";
|
||||
$this->Document->query($query);
|
||||
}
|
||||
|
||||
$result = $this->Document->PurchaseOrder->saveAll($this->data['PurchaseOrder']);
|
||||
|
||||
|
||||
//die(print_r($this->data['PurchaseOrder']));
|
||||
//die(print_r($result));
|
||||
//die(print_r($this->data));
|
||||
}
|
||||
|
||||
if ($this->Document->saveAll($this->data)) {
|
||||
echo 'SUCCESS';
|
||||
|
|
@ -851,6 +882,51 @@ ENDINSTRUCTIONS;
|
|||
}
|
||||
|
||||
|
||||
function add_job_items_to_po($job_id, $document_id) {
|
||||
$this->layout = 'ajax';
|
||||
$job = $this->Document->PurchaseOrder->Job->find('first', array('conditions'=>array('Job.id' => $job_id)));
|
||||
|
||||
$orderack = $this->Document->OrderAcknowledgement->find('first', array('conditions'=>array('OrderAcknowledgement.enquiry_id' => $job['Job']['enquiry_id']), 'recursive' => 1));
|
||||
|
||||
$oa_document = $this->Document->find('first',
|
||||
array('conditions'=>
|
||||
array('Document.id' => $orderack['Document']['id']
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$destination_document = $this->Document->find('first', array('conditions'=>array('Document.id' => $document_id)));
|
||||
|
||||
$new_items = $this->copy_related($oa_document, 'LineItem', array('id', 'document_id', 'costing_id'));
|
||||
|
||||
$last_item_number = 1.0;
|
||||
foreach($destination_document['LineItem'] as $item) {
|
||||
$last_item_number = $item['item_number'];
|
||||
}
|
||||
if($last_item_number != 1.0) { //Fuck knows
|
||||
$last_item_number++;
|
||||
}
|
||||
|
||||
foreach($new_items as $i => $item) {
|
||||
$item['item_number'] = $last_item_number++;
|
||||
$item['document_id'] = $document_id;
|
||||
$destination_document['LineItem'][] = $item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($this->Document->LineItem->saveAll($destination_document['LineItem'])) {
|
||||
echo 'SUCCESS';
|
||||
}
|
||||
else {
|
||||
echo 'FAILURE';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function costing() {
|
||||
}
|
||||
|
||||
|
|
|
|||
0
app/views/documents/add_job_items_to_po.ctp
Normal file
0
app/views/documents/add_job_items_to_po.ctp
Normal file
|
|
@ -1,5 +1,4 @@
|
|||
<h2>Purchase Order: <?=$document['PurchaseOrder']['title']?></h2>
|
||||
<h2>Job: </h2>
|
||||
|
||||
<div id="flashMessage" class="message">
|
||||
</div>
|
||||
|
|
@ -26,10 +25,10 @@
|
|||
<?
|
||||
echo $form->input('job', array('id'=>'job_autocomplete', array('label'=>'Job (start typing and select from the list)')));
|
||||
?>
|
||||
<span class="moreInfo">Jobs in this Shipment will be updated as "sent"</span>
|
||||
<span class="moreInfo">Items from the OA for this Job will be added automatically to the PO.</span>
|
||||
|
||||
<ul id="jobsList" class="habtmList">
|
||||
<?php foreach($this->data['Job'] as $job):?>
|
||||
<?php foreach($purchaseOrder['Job'] as $job):?>
|
||||
<li id="JobID_<?=$job['id']?>">
|
||||
<button class="removeFromList">X</button>
|
||||
<?=$job['title'];?>
|
||||
|
|
@ -37,7 +36,6 @@
|
|||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<h2><?php __('PurchaseOrders');?></h2>
|
||||
|
||||
<div class="actions">
|
||||
<a href="/documents/newDocument/purchaseOrder/0/0/0">New blank Purchase Order</a>
|
||||
<a href="/documents/newDocument/purchaseOrder">New Purchase Order</a>
|
||||
</div>
|
||||
<p>
|
||||
<?php
|
||||
|
|
|
|||
|
|
@ -34,9 +34,17 @@ $(function() {
|
|||
thisLI.append(thisHiddenInput);
|
||||
ULelement.append(thisLI);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Remove X button clicked.
|
||||
$('.removeFromList').live('click', function() {
|
||||
$(this).parent().remove();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// var config defined in global.js
|
||||
|
|
@ -471,9 +479,17 @@ $(function() {
|
|||
minLength: 2,
|
||||
select: function( event, ui ) {
|
||||
|
||||
if($('#JobID_'+ui.item.id).length == 0) { //This Job is already in the List. Don't do anything.'
|
||||
if($('#JobID_'+ui.item.id).length == 0) { //This Job is not already in the List.
|
||||
addToList('Job', ui.item.id, ui.item.value, $('#jobsList'));
|
||||
console.log(ui.item.id);
|
||||
console.log(ui.item.value);
|
||||
//POST the job ID to a method on the documents controller to add the LineItems
|
||||
$.post('/documents/add_job_items_to_po/'+ui.item.id+'/'+$("#DocumentId").val(), function(data) {
|
||||
|
||||
loadLineItems();
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue