Permalink
Browse files

NEW: Tidy up of admin interface. Used customer name, instead of first…

… 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 65a79173dd54e753e6c781bce09eb0d56efc6119
Showing with 58 additions and 99 deletions.
  1. +32 −7 code/cms/OrdersAdmin.php
  2. +15 −25 code/model/Order.php
  3. +0 −22 code/search/filters/OrderFilters.php
  4. +0 −9 css/order.css
  5. +11 −36 templates/Includes/Order_Printable.ss
View
@@ -63,7 +63,8 @@ function search($request, $form) {
class OrdersAdmin_RecordController extends ModelAdmin_RecordController {
static $allowed_actions = array(
- 'recalculate'
+ 'recalculate',
+ 'printorder'
);
public function EditForm() {
@@ -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;
}
@@ -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');
}
}
View
@@ -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'
);
@@ -168,7 +166,6 @@ class Order extends DataObject {
'filter' => 'PartialMatchFilter',
'title' => 'Reference'
),
- 'Printed',
'FirstName' => array(
'title' => 'Customer Name',
'filter' => 'PartialMatchFilter'
@@ -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',
@@ -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))
));
@@ -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;
}
@@ -1,6 +1,5 @@
<?php
-
class OrderFilters_AroundDateFilter extends ExactMatchFilter {
protected static $how_many_days_around = 31;
@@ -34,8 +33,6 @@ public function isEmpty() {
}
-
-
class OrderFilters_MultiOptionsetFilter extends SearchFilter {
public function apply(SQLQuery $query) {
@@ -48,7 +45,6 @@ public function apply(SQLQuery $query) {
Convert::raw2sql(str_replace("'", '', $value))
);
}
-
return $query->where(implode(" OR ", $matches));
}
return $query;
@@ -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;
- }
-}
View
@@ -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 {
@@ -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.