Skip to content

Commit

Permalink
NEW: Tidy up of admin interface. Used customer name, instead of first…
Browse files Browse the repository at this point in the history
… and last name. Removed TotalOutstanding. Removed printed. Removed has payment search check. Added docs. Moved print action down next to save action. Removed customer tab. Moved print code to OrdersAdmin
  • Loading branch information
jedateach committed Aug 15, 2012
1 parent 8c75a3e commit 65a7917
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 99 deletions.
39 changes: 32 additions & 7 deletions code/cms/OrdersAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function search($request, $form) {
class OrdersAdmin_RecordController extends ModelAdmin_RecordController {

static $allowed_actions = array(
'recalculate'
'recalculate',
'printorder'
);

public function EditForm() {
Expand Down Expand Up @@ -91,12 +92,20 @@ public function EditForm() {
}
}
//add recalculate action
$link = $this->Link('recalculate');
$form->Fields()->addFieldToTab("Root.AdminActions",
new LiteralField("recalculate",
"<a href=\"$link\">recalculate order</a>"
)
$recalculatelink = $this->Link('recalculate');
$printlink = $this->Link('printorder')."?print=1";

$printwindowjs =<<<JS
window.open('$printlink', 'print_order', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 50,top = 50');return false;
JS;


$form->Actions()->insertFirst(
// new LiteralField("recalculate","<a href=\"$recalculatelink\">recalculate order</a>"),
new LiteralField("PrintOrder","<input type=\"submit\" onclick=\"javascript:$printwindowjs\" class=\"action\" value=\""._t("Order.PRINT","Print")."\">")
);


return $form;
}

Expand All @@ -108,7 +117,23 @@ public function recalculate(){
//TODO: only recalculate if all order items have retrievable product versions
$order->calculate();
$order->write();
return "success: ".$order->Total();
if(Director::is_ajax()){
return "success: ".$order->Total();
}
Director::redirectBack();
}

public function printorder(){
//include print javascript, if print argument is provided
if(isset($_REQUEST['print']) && $_REQUEST['print']) {
Requirements::customScript("if(document.location.href.indexOf('print=1') > 0) {window.print();}");
}
$this->Title = i18n::_t("ORDER.INVOICE","Invoice");
if($id = $this->urlParams['ID']) {
$this->Title .= " #$id";
}
Requirements::clear();
return $this->currentRecord->customise(array('SiteConfig' => SiteConfig::current_site_config()))->renderWith('Order_Printable');
}

}
40 changes: 15 additions & 25 deletions code/model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ class Order extends DataObject {
);

public static $summary_fields = array(
'FirstName' => 'First Name',
'Surname' => 'Surname',
'Reference' => 'Order No',
'Placed' => 'Date',
'Name' => 'Customer',
'LatestEmail' => 'Email',
'Total' => 'Total',
'TotalOutstanding' => 'Outstanding',
'Status' => 'Status'
);

Expand All @@ -168,7 +166,6 @@ class Order extends DataObject {
'filter' => 'PartialMatchFilter',
'title' => 'Reference'
),
'Printed',
'FirstName' => array(
'title' => 'Customer Name',
'filter' => 'PartialMatchFilter'
Expand All @@ -180,10 +177,7 @@ class Order extends DataObject {
'Placed' => array(
'field' => 'TextField',
'filter' => 'OrderFilters_AroundDateFilter',
'title' => "date"
),
'TotalPaid' => array(
'filter' => 'OrderFilters_MustHaveAtLeastOnePayment',
'title' => "Date"
),
'Status' => array(
'filter' => 'OrderFilters_MultiOptionsetFilter',
Expand All @@ -204,21 +198,24 @@ public static function get_order_status_options() {

function scaffoldSearchFields(){
$fieldSet = parent::scaffoldSearchFields();
$fieldSet->push(new CheckboxSetField("Status", "Status", self::get_order_status_options()));
$fieldSet->push(new DropdownField("TotalPaid", "Has Payment", array(1 => "yes", 0 => "no")));
$values = self::$placed_status;
$fields = array_combine(self::$placed_status,self::$placed_status);
$fieldSet->push(new CheckboxSetField("Status", "Status",$fields,$values));
return $fieldSet;
}


/**
* Create CMS fields for cms viewing and editing orders
* Also note that some fields are introduced in OrdersAdmin_RecordController
*/
function getCMSFields(){
$fields = new FieldSet(new TabSet('Root',new Tab('Main')));
$fields->insertBefore(new LiteralField('Title',"<h2>Order #$this->ID - ".$this->dbObject('Created')->Nice()." - ".$this->Member()->getName()."</h2>"),'Root');
$fieldsAndTabsToBeRemoved = array('Main','Payments','Status','Printed','MemberID','Attributes','SessionID');
foreach($fieldsAndTabsToBeRemoved as $field) {
$fields->removeByName($field);
}
$printlabel = (!$this->Printed) ? _t("Order.PRINT","Print Invoice") : _t("Order.PRINTAGAIN","Print Invoice Again");
$fields->insertBefore(new HeaderField('Title',"Order #".$this->getReference()),'Root');
$fields->insertBefore(new LiteralField('SubTitle',
"<h4 class=\"subtitle\">".$this->dbObject('Placed')->Nice()." - <a href=\"mailto:".$this->getLatestEmail()."\">".$this->getName()."</a></h4>"
),"Root");

$fields->addFieldsToTab('Root.Main', array(
new LiteralField("PrintInvoice",'<p class="print"><a href="OrderReport_Popup/index/'.$this->ID.'?print=1" onclick="javascript: window.open(this.href, \'print_order\', \'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 50,top = 50\'); return false;">'.$printlabel.'</a></p>'),
new DropdownField("Status","Status", self::get_order_status_options()),
new LiteralField('MainDetails', $this->renderWith(self::$admin_template))
));
Expand All @@ -234,13 +231,6 @@ function getCMSFields(){
$payments->setPageSize(20);
$payments->addSummary("Total",array("Total" => array("sum","Currency->Nice")));
$fields->addFieldToTab('Root.Payments',$payments);
if($m = $this->Member()) {
$lastv = new TextField("MemberLastLogin","Last login",$m->dbObject('LastVisited')->Nice());
$fields->addFieldsToTab('Root.Customer',array(
$lastv->performReadonlyTransformation(),
new LiteralField("MemberSummary", $m->renderWith("Order_Member"))
));
}
$this->extend('updateCMSFields',$fields);
return $fields;
}
Expand Down
22 changes: 0 additions & 22 deletions code/search/filters/OrderFilters.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


class OrderFilters_AroundDateFilter extends ExactMatchFilter {

protected static $how_many_days_around = 31;
Expand Down Expand Up @@ -34,8 +33,6 @@ public function isEmpty() {

}



class OrderFilters_MultiOptionsetFilter extends SearchFilter {

public function apply(SQLQuery $query) {
Expand All @@ -48,7 +45,6 @@ public function apply(SQLQuery $query) {
Convert::raw2sql(str_replace("'", '', $value))
);
}

return $query->where(implode(" OR ", $matches));
}
return $query;
Expand All @@ -63,21 +59,3 @@ public function isEmpty() {
}
}
}
class OrderFilters_MustHaveAtLeastOnePayment extends SearchFilter {

public function apply(SQLQuery $query) {
$query = $this->applyRelation($query);
$value = $this->getValue();
if($value) {
return $query->innerJoin(
$table = "Payment", // framework already applies quotes to table names here!
$onPredicate = "\"Payment\".\"OrderID\" = \"Order\".\"ID\"",
$tableAlias=null
);
}
}

public function isEmpty() {
return $this->getValue() == null || $this->getValue() == '' || $this->getValue() == 0;
}
}
9 changes: 0 additions & 9 deletions css/order.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@
font-size: 15px;
font-weight: normal;
font-family: Tahoma, Verdana, sans-serif;
}
table.infotable tr.Total {
background: #c9ebff;
}
table.infotable tr.Total td {
font-weight:bold;
font-size:14px;
color:#4EA3D7;
text-transform:uppercase;
}
table.infotable tr td,
table.infotable tr th {
Expand Down
47 changes: 11 additions & 36 deletions templates/Includes/Order_Printable.ss
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<% base_tag %>
<title><% _t("PAGETITLE","Print Orders") %></title>
<% include OrderReceiptStyle %>
</head>
<body>

<%-- todo: allow printing multiple invoices at once --%>
<div style="page-break-after: always;">
<h1 class="title">$Top.SiteConfig.Title Invoice</h1>

<table id="SenderTable">
<tbody>
<tr>
<td class="sender">
$Top.SiteConfig.SenderAddress
</td>
<td class="meta">
<table id="MetaTable">
<tbody>
<tr><td class="label">Invoice Date:</td><td class="date">$Now.Nice</td></tr>
<tr><td class="label">Order ID:</td><td class="id">$DisplayFinalisedOrder.ID</td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
$Content
<% control DisplayFinalisedOrder %>
<html>
<head>
<% base_tag %>
$MetaTags
<% include OrderReceiptStyle %>
</head>
<body>
<div style="page-break-after: always;">
<h1 class="title">$SiteConfig.Title <% _t("ORDER","Order") %> $Reference</h1>
<% include Order %>
<% end_control %>
</div>

</body>
</div>
</body>
</html>

0 comments on commit 65a7917

Please sign in to comment.