Fixed broken line item attachments
This commit is contained in:
parent
d5c995ae74
commit
3e46f30dd2
|
|
@ -123,20 +123,24 @@ class DocumentsController extends AppController {
|
||||||
foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) {
|
foreach($this->data['DocumentAttachment']['attachment_id'] as $i => $attachment_id) {
|
||||||
$docID = $this->data['DocumentAttachment']['document_id'];
|
$docID = $this->data['DocumentAttachment']['document_id'];
|
||||||
$query = "DELETE FROM document_attachments WHERE document_id = {$docID} AND attachment_id = {$attachment_id}";
|
$query = "DELETE FROM document_attachments WHERE document_id = {$docID} AND attachment_id = {$attachment_id}";
|
||||||
echo $query."<br>";
|
$this->Document->DocumentAttachment->query($query);
|
||||||
//$this->Document->DocumentAttachment->query($query);
|
|
||||||
|
|
||||||
$attachment['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id'];
|
$attachment[$i]['DocumentAttachment']['document_id'] = $this->data['DocumentAttachment']['document_id'];
|
||||||
$attachment['DocumentAttachment']['attachment_id'] = $attachment_id;
|
$attachment[$i]['DocumentAttachment']['attachment_id'] = $attachment_id;
|
||||||
if(!$this->Document->DocumentAttachment->save($attachment)) {
|
|
||||||
echo "FAIL";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
echo "SUCCESS";
|
if($this->Document->DocumentAttachment->saveAll($attachment)) {
|
||||||
|
echo "SUCCESS";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "FAIL";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
echo "FAIL";
|
|
||||||
|
function removeAttachments() {
|
||||||
|
$this->layout = 'ajax';
|
||||||
|
foreach($this->data as $attachment) {
|
||||||
|
$this->Document->DocumentAttachment->delete($attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,8 +639,7 @@ class DocumentsController extends AppController {
|
||||||
$this->Email->delivery = 'smtp';
|
$this->Email->delivery = 'smtp';
|
||||||
|
|
||||||
$document = $this->Document->read(null,$id);
|
$document = $this->Document->read(null,$id);
|
||||||
|
|
||||||
$attachments = $this->Document->DocumentAttachment->find('all', array('DocumentAttachment.document_id' => $id));
|
|
||||||
|
|
||||||
if(empty($document['Document']['pdf_filename'])) {
|
if(empty($document['Document']['pdf_filename'])) {
|
||||||
$this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true));
|
$this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true));
|
||||||
|
|
@ -646,8 +649,9 @@ class DocumentsController extends AppController {
|
||||||
$pdf_dir = Configure::read('pdf_directory');
|
$pdf_dir = Configure::read('pdf_directory');
|
||||||
|
|
||||||
$attachment_files = array($pdf_dir.$document['Document']['pdf_filename']);
|
$attachment_files = array($pdf_dir.$document['Document']['pdf_filename']);
|
||||||
foreach($attachments as $attachment) {
|
foreach($document['DocumentAttachment'] as $document_attachment) {
|
||||||
$attachment_files[] = $attachment['Attachment']['filename'];
|
$attachment = $this->Document->DocumentAttachment->Attachment->read(null, $document_attachment['attachment_id']);
|
||||||
|
$attachment_files[] = $attachment['Attachment']['file'];
|
||||||
}
|
}
|
||||||
$this->Email->attachments = $attachment_files;
|
$this->Email->attachments = $attachment_files;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,23 @@
|
||||||
<?
|
<table>
|
||||||
|
<thead>
|
||||||
|
<th></th>
|
||||||
|
<th>Filename</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Desc</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
foreach($attachments as $attachment) {
|
foreach($attachments as $attachment) {
|
||||||
echo "<li>";
|
|
||||||
echo $html->link($attachment['Attachment']['name'],
|
|
||||||
"/attachments/view/{$attachment['Attachment']['id']}");
|
|
||||||
echo "</li>";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $form->input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false)); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
|
||||||
|
</td>
|
||||||
|
<td><?php echo $attachment['Attachment']['name']; ?></td>
|
||||||
|
<td><?php echo $attachment['Attachment']['description']; ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
|
||||||
0
views/documents/remove_attachments.ctp
Normal file
0
views/documents/remove_attachments.ctp
Normal file
|
|
@ -33,28 +33,37 @@ echo $form->input("DocPage.content", array('class'=>'page', 'label'=>'Page', 'be
|
||||||
|
|
||||||
<div id="Attachments" title="Attachments">
|
<div id="Attachments" title="Attachments">
|
||||||
<h2 class="document-attachments">Attachments</h2><button id="addAttachment">Add Attachment</button>
|
<h2 class="document-attachments">Attachments</h2><button id="addAttachment">Add Attachment</button>
|
||||||
<table>
|
|
||||||
|
<div id="attachments-table">
|
||||||
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
<th></th>
|
||||||
<th>Filename</th>
|
<th>Filename</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Desc</th>
|
<th>Desc</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
foreach($attachments as $attachment) {
|
foreach($attachments as $index => $attachment) {
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td><?php echo $form->input("DocumentAttachment[{$index}].id",
|
||||||
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
|
array('type'=>'checkbox',
|
||||||
|
'value'=> $attachment['DocumentAttachment']['id'],
|
||||||
|
'label' => false, 'class'=>'documentAttachment-checkbox')); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo $attachment['Attachment']['name']; ?></td>
|
<td><?php echo $attachment['Attachment']['name']; ?></td>
|
||||||
<td><?php echo $attachment['Attachment']['id']; ?></td>
|
|
||||||
<td><?php echo $attachment['Attachment']['description']; ?></td>
|
<td><?php echo $attachment['Attachment']['description']; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div> <!-- #attachments-table -->
|
||||||
|
|
||||||
|
<button id="removeAttachments">Remove Selected</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="addAttachmentModal" title="Add Attachment">
|
<div id="addAttachmentModal" title="Add Attachment">
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<? echo $form->input('Product.principle_id', array('id'=>'principleAttachmentSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
<? echo $form->input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
||||||
<div id="productsDiv"></div>
|
<div id="productsDiv"></div>
|
||||||
<div id="productDetails"></div>
|
<div id="productDetails"></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1578,6 +1578,7 @@ div.address span {
|
||||||
}
|
}
|
||||||
|
|
||||||
table.lineItems {
|
table.lineItems {
|
||||||
|
margin-top: 0.2em;
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
border-spacing: 0px;
|
border-spacing: 0px;
|
||||||
}
|
}
|
||||||
|
|
@ -1647,8 +1648,8 @@ div.warning {
|
||||||
|
|
||||||
|
|
||||||
tr.no_items {
|
tr.no_items {
|
||||||
font-size: 2em;
|
font-size: 1.5em;
|
||||||
padding: 0.5em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
#Attachments {
|
#Attachments {
|
||||||
margin-top: 1.5em;
|
margin-top: 1.5em;
|
||||||
|
|
|
||||||
|
|
@ -18,24 +18,18 @@ $(function() {
|
||||||
var attachmentInputs = $('#DocumentAttachmentAddForm').find('input');
|
var attachmentInputs = $('#DocumentAttachmentAddForm').find('input');
|
||||||
|
|
||||||
$.post('/documents/saveAttachments', attachmentInputs, function(data) {
|
$.post('/documents/saveAttachments', attachmentInputs, function(data) {
|
||||||
if(data == 'SUCCESS') {
|
$("#addAttachmentModal").dialog( "close" );
|
||||||
loadAttachments();
|
|
||||||
$(this).dialog('close');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alert("Attachments could not be saved")
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
Cancel: function() {
|
Cancel: function() {
|
||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
loadAttachments();
|
loadAttachments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -45,6 +39,10 @@ $(function() {
|
||||||
loadPrincipleAttachments(principleID);
|
loadPrincipleAttachments(principleID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#removeAttachments").click(function() {
|
||||||
|
removeAttachments();
|
||||||
|
});
|
||||||
|
|
||||||
function loadPrincipleAttachments(id) {
|
function loadPrincipleAttachments(id) {
|
||||||
$.get('/documents/getAttachmentsByPrinciple/'+id, function(attachments) {
|
$.get('/documents/getAttachmentsByPrinciple/'+id, function(attachments) {
|
||||||
$('#principleAttachments').html(attachments);
|
$('#principleAttachments').html(attachments);
|
||||||
|
|
@ -52,13 +50,17 @@ $(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAttachments() {
|
function loadAttachments() {
|
||||||
|
|
||||||
$.get('/documents/getAttachments/'+documentID, function(attachments) {
|
$.get('/documents/getAttachments/'+documentID, function(attachments) {
|
||||||
|
$("#attachments-table").html(attachments);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAttachments() {
|
||||||
|
var selectedAttachments = $(".documentAttachment-checkbox:checked");
|
||||||
|
$.post('/documents/removeAttachments', selectedAttachments, function(data) {
|
||||||
|
loadAttachments();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue