Refactored copying of models on document_controller to make it more DRY. Changed invoice and OA PDF templates per email on May 14

This commit is contained in:
Karl Cordes 2013-06-09 14:09:30 +10:00
parent 95140a9a4b
commit b8866b4d03
5 changed files with 46 additions and 54 deletions

View file

@ -292,20 +292,10 @@ class DocumentsController extends AppController {
foreach($copy_doc_attributes as $attr) {
$this->data['Document'][$attr] = $sourceDoc['Document'][$attr];
}
/*echo "<pre>";
print_r($sourceDoc);
echo "--<br>";
print_r($this->data);
echo "</pre>";
die();*/
if(!empty($sourceDoc['LineItem'])) {
$this->data['LineItem'] = $sourceDoc['LineItem'];
foreach($this->data['LineItem'] as $index => $li) {
$this->data['LineItem'][$index]['id'] = null;
$this->data['LineItem'][$index]['document_id'] = null;
$this->data['LineItem'][$index]['costing_id'] = null;
}
}
$this->data['LineItem'] = $this->copy_related($sourceDoc, 'LineItem', array('id', 'document_id', 'costing_id'));
}
if ($this->Document->saveAll($this->data)) {
$newid = $this->Document->id;
@ -382,27 +372,14 @@ class DocumentsController extends AppController {
/** Copy the LineItems from this Document. Applies to all of the Document Types */
if(!empty($document['LineItem'])) {
$newDoc['LineItem'] = $document['LineItem'];
foreach($newDoc['LineItem'] as $index => $li) {
$newDoc['LineItem'][$index]['id'] = null;
$newDoc['LineItem'][$index]['document_id'] = null;
$newDoc['LineItem'][$index]['costing_id'] = null;
}
}
$newDoc['LineItem'] = $this->copy_related($document, 'LineItem', array('id', 'document_id', 'costing_id'));
if(!empty($document['DocumentAttachment'])) {
$newDoc['DocumentAttachment'] = $document['DocumentAttachment'];
foreach($newDoc['DocumentAttachment'] as $index => $da) {
$newDoc['DocumentAttachment'][$index]['id'] = null;
$newDoc['DocumentAttachment'][$index]['document_id'] = null;
}
}
$newDoc['DocumentAttachment'] = $this->copy_related($document, 'DocumentAttachment', 'id', 'document_id');
$this->set('newDoc', $newDoc);
//
//print_r($newDoc);
if ($this->Document->saveAll($newDoc)) {
$newid = $this->Document->id;
$this->Session->setFlash(__("Revision {$number_of_revisions} created", true));
@ -496,16 +473,11 @@ class DocumentsController extends AppController {
}
$newDoc['LineItem'] = $this->copy_related($originalDoc, 'LineItem', array('id', 'document_id', 'costing_id'));
$newDoc['DocumentAttachment'] = $this->copy_related($originalDoc, 'DocumentAttachment', array('id', 'document_id'));
/** Copy the LineItems from this Document. Applies to all of the Document Types */
if(!empty($originalDoc['LineItem'])) {
$newDoc['LineItem'] = $originalDoc['LineItem'];
foreach($newDoc['LineItem'] as $index => $li) {
$newDoc['LineItem'][$index]['id'] = null;
$newDoc['LineItem'][$index]['document_id'] = null;
$newDoc['LineItem'][$index]['costing_id'] = null;
}
}
if ($this->Document->saveAll($newDoc)) {
$newid = $this->Document->id;
@ -769,5 +741,29 @@ class DocumentsController extends AppController {
}
/** Helper function to make copying related models more DRY
*
* @param array $document
* @param string $model - eg 'LineItem'
* @param array $keys_to_null - eg. array('id', 'document_id')
*
* */
function copy_related($document, $model, $keys_to_null) {
if(empty($document[$model])) {
return null;
}
$newDoc[$model] = $document[$model];
foreach($newDoc[$model] as $index => $ele) {
foreach($keys_to_null as $key) {
$newDoc[$model][$index][$key] = null;
}
}
return $newDoc[$model];
}
}
?>

View file

@ -40,7 +40,7 @@ class PDFDOC extends FPDI {
$this->SetFontSize(10);
$this->SetY(22);
$this->Cell(30);
$this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1);
$this->Cell(0,0, "PTY LIMITED ACN: 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1);
//$this->Rect($x, $y, $w, $h, $style, $border_style);
$this->Rect($this->GetX()+33, $this->GetY()+2, 157, 1, 'DF', array('width'=>0), array(0, 0, 0));

View file

@ -71,7 +71,7 @@
</tbody>
<tfoot>
<tr nobr="true">
<td colspan="3" bgcolor="#f2f2f2" nobr="true">SHIPPING DETAILS:
<td colspan="3" bgcolor="#f2f2f2" nobr="true">FREIGHT DETAILS:
</td>
<td width="<?=$colWidths['unit'];?>" bgcolor="#f2f2f2" align="left"><?=$totalsDescText['subtotal']?></td>
<td width="<?=$colWidths['total'];?>" align="center">

View file

@ -6,14 +6,14 @@ $col3width = '30%';
?>
<table cellpadding="2" cellspacing="0" >
<tr>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Billing Details:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Delivery Details</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Sold To / Invoice Address:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Delivery Address:</td>
<td style="width: 3%;"></td>
<td style="font-size: 9pt; width: 37%;" colspan="4" rowspan="2" align="left">
<span style="text-decoration: underline; font-size: 11pt">CMC <?=$docTypeFullName?>#:</span> <span style="font-size: 11pt"><?=$docTitle?></span><br>
<span style="text-decoration: none;">Date: <?=$issue_date_string?></span><br>
<? if($docType == 'orderAck'): ?>
<span style="text-decoration: none;">Estimated Delivery:</span> <span style="text-align: right;"><?=$estimated_delivery?></span><br>
<span style="text-decoration: none;">Estimated Despatch Date:</span> <span style="text-align: right;"><?=$estimated_delivery?></span><br>
<? endif; ?>
<span style="text-decoration: none;">Page: <?=$pageNo?> of <?=$totalCount?></span><br><br>
<span style="text-decoration: underline;">MAKE PAYMENT TO:</span><br>
@ -39,16 +39,14 @@ $col3width = '30%';
<? $moreDetailsFont = '9pt'; ?>
<td style="font-size: <?=$moreDetailsFont?>;">CUSTOMER ORDER NO</td>
<td style="font-size: <?=$moreDetailsFont?>">CMC JOB #</td>
<td style="font-size: <?=$moreDetailsFont?>">FOB</td>
<td style="font-size: <?=$moreDetailsFont?>">SHIP VIA</td>
<td style="font-size: <?=$moreDetailsFont?>">TERMS</td>
<td style="font-size: <?=$moreDetailsFont?>">INCOTERMS 2010</td>
<td style="font-size: <?=$moreDetailsFont?>">PAYMENT TERMS</td>
<td style="font-size: <?=$moreDetailsFont?>">CUSTOMER ABN</td>
</tr>
<tr align="center">
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Job']['customer_order_number'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Job']['title'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$fob;?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$ship_via;?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Customer']['payment_terms'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$this->element('abn', array('abn'=>$job['Customer']['abn']));?></td>
</tr>

View file

@ -6,14 +6,14 @@ $col3width = '30%';
?>
<table cellpadding="2" cellspacing="0" >
<tr>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">BILL TO:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">SHIP TO:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Sold To / Invoice Address:</td>
<td style="width: <?=$col1width?>; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black; background-color: #f2f2f2">Delivery Address:</td>
<td style="width: 3%;"></td>
<td style="font-size: 9pt; width: 37%;" colspan="4" rowspan="2" align="left">
<span style="text-decoration: underline; font-size: 11pt">CMC <?=$docTypeFullName?>#:</span> <span style="font-size: 11pt"><?=$docTitle?></span><br>
<span style="text-decoration: none;">Date: <?=$issue_date_string?></span><br>
<? if($docType == 'orderAck'): ?>
<span style="text-decoration: none;">Estimated Delivery:</span> <span><?=$estimated_delivery?></span><br>
<span style="text-decoration: none;">Estimated Despatch Date:</span> <span><?=$estimated_delivery?></span><br>
<? endif; ?>
<span style="text-decoration: none;">Page: <?=$pageNo?> of <?=$totalCount?></span><br><br>
<span style="text-decoration: underline;">MAKE PAYMENT TO:</span><br>
@ -39,8 +39,7 @@ $col3width = '30%';
<? $moreDetailsFont = '9pt'; ?>
<td style="font-size: <?=$moreDetailsFont?>;">CUSTOMER ORDER NO</td>
<td style="font-size: <?=$moreDetailsFont?>">CMC REF #</td>
<td style="font-size: <?=$moreDetailsFont?>">EX WORKS</td>
<td style="font-size: <?=$moreDetailsFont?>">SHIP VIA</td>
<td style="font-size: <?=$moreDetailsFont?>">INCOTERMS 2010</td>
<td style="font-size: <?=$moreDetailsFont?>">PAYMENT TERMS</td>
<td style="font-size: <?=$moreDetailsFont?>">CUST. ABN</td>
</tr>
@ -48,7 +47,6 @@ $col3width = '30%';
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Job']['customer_order_number'];?></td>
<td style="font-size: 8pt"><?=$enquiry['Enquiry']['title'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$fob;?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$ship_via;?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$job['Customer']['payment_terms'];?></td>
<td style="font-size: <?=$moreDetailsFont?>"><?=$this->element('abn', array('abn'=>$job['Customer']['abn']));?></td>
</tr>