Improved order management in back-office

This commit is contained in:
Franck Allimant
2014-01-25 19:14:57 +01:00
parent 5f883a41a4
commit 6b78a33f97
7 changed files with 219 additions and 48 deletions

View File

@@ -46,7 +46,11 @@ class OrderController extends BaseAdminController
public function indexAction() public function indexAction()
{ {
if (null !== $response = $this->checkAuth(AdminResources::ORDER, array(), AccessManager::VIEW)) return $response; if (null !== $response = $this->checkAuth(AdminResources::ORDER, array(), AccessManager::VIEW)) return $response;
return $this->render("orders", array("display_order" => 20));
return $this->render("orders", array(
"display_order" => 20,
"orders_order" => $this->getListOrderFromSession("orders", "orders_order", "create-date-reverse")
));
} }
public function viewAction($order_id) public function viewAction($order_id)

View File

@@ -26,17 +26,20 @@ namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface; use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Element\SearchLoopInterface; use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\Base\Customer;
use Thelia\Model\CustomerQuery; use Thelia\Model\CustomerQuery;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Model\Map\OrderAddressTableMap;
use Thelia\Model\OrderAddressQuery; use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery; use Thelia\Model\OrderQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type; use Thelia\Type;
use Thelia\Type\TypeCollection;
/** /**
* *
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
@@ -72,7 +75,14 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(
new Type\EnumListType(array('create-date', 'create-date-reverse')) new Type\EnumListType(array(
'id', 'id-reverse',
'reference', 'reference-reverse',
'create-date', 'create-date-reverse',
'company', 'company-reverse',
'customer-name', 'customer-name-reverse',
'status', 'status-reverse'
))
), ),
'create-date-reverse' 'create-date-reverse'
) )
@@ -165,12 +175,67 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt
foreach ($orderers as $orderer) { foreach ($orderers as $orderer) {
switch ($orderer) { switch ($orderer) {
case 'id':
$search->orderById(Criteria::ASC);
break;
case 'id_reverse':
$search->orderById(Criteria::DESC);
break;
case 'reference':
$search->orderByRef(Criteria::ASC);
break;
case 'reference_reverse':
$search->orderByRef(Criteria::DESC);
break;
case "create-date": case "create-date":
$search->orderByCreatedAt(Criteria::ASC); $search->orderByCreatedAt(Criteria::ASC);
break; break;
case "create-date-reverse": case "create-date-reverse":
$search->orderByCreatedAt(Criteria::DESC); $search->orderByCreatedAt(Criteria::DESC);
break; break;
case "status":
$search->orderByStatusId(Criteria::ASC);
break;
case "status":
$search->orderByStatusId(Criteria::DESC);
break;
case 'company' :
$search
->joinOrderAddressRelatedByDeliveryOrderAddressId()
->withColumn(OrderAddressTableMap::COMPANY, 'company')
->orderBy('company', Criteria::ASC)
;
break;
case 'companyreverse' :
$search
->joinOrderAddressRelatedByDeliveryOrderAddressId()
->withColumn(OrderAddressTableMap::COMPANY, 'company')
->orderBy('company', Criteria::DESC)
;
break;
case 'customer-name' :
$search
->joinCustomer()
->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
->withColumn(CustomerTableMap::LASTNAME, 'lastname')
->orderBy('lastname', Criteria::ASC)
->orderBy('firstname', Criteria::ASC)
;
break;
case 'customer-name-reverse' :
$search
->joinCustomer()
->withColumn(CustomerTableMap::FIRSTNAME, 'firstname')
->withColumn(CustomerTableMap::LASTNAME, 'lastname')
->orderBy('lastname', Criteria::DESC)
->orderBy('firstname', Criteria::DESC)
;
break;
} }
} }

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException; use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Tools\DateTimeFormat; use Thelia\Tools\DateTimeFormat;
use Thelia\Tools\MoneyFormat;
use Thelia\Tools\NumberFormat; use Thelia\Tools\NumberFormat;
/** /**
@@ -135,6 +136,40 @@ class Format extends AbstractSmartyPlugin
$this->getParam($params, "thousands_sep", null) $this->getParam($params, "thousands_sep", null)
); );
} }
/**
*
* display a amount in expected format
*
* available parameters :
* number => int or float number
* decimals => how many decimals format expected
* dec_point => separator for the decimal point
* thousands_sep => thousands separator
* symbol => Currency symbol
*
* ex : {format_money number="1246.12" decimals="1" dec_point="," thousands_sep=" " symbol="€"} will output "1 246,1 €"
*
* @param $params
* @param null $template
* @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
* @return string the expected number formatted
*/
public function formatMoney($params, $template = null)
{
$number = $this->getParam($params, "number", false);
if ($number === false || $number == '') {
return "";
}
return MoneyFormat::getInstance($this->request)->format(
$number,
$this->getParam($params, "decimals", null),
$this->getParam($params, "dec_point", null),
$this->getParam($params, "thousands_sep", null),
$this->getParam($params, "symbol", null)
);
}
/** /**
* @return an array of SmartyPluginDescriptor * @return an array of SmartyPluginDescriptor
@@ -143,7 +178,8 @@ class Format extends AbstractSmartyPlugin
{ {
return array( return array(
new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"), new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"),
new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber") new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber"),
); new SmartyPluginDescriptor("function", "format_money", $this, "formatMoney")
);
} }
} }

View File

@@ -82,8 +82,9 @@ class Module extends AbstractSmartyPlugin
} }
} }
if (! empty($content)) if (! empty($content)) {
return $template->fetch(sprintf("string:%s", $content)); return $template->fetch(sprintf("string:%s", $content));
}
return ""; return "";
} }

View File

@@ -160,6 +160,7 @@
</span> </span>
</p> </p>
{ifloop rel="address"}
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">
<thead> <thead>
@@ -212,6 +213,13 @@
</tbody> </tbody>
</table> </table>
</div> </div>
{/ifloop}
{elseloop rel="address"}
<div class="alert alert-info">
{intl l="This customer has not defined any delivery address"}
</div>
{/elseloop}
</div> </div>
</form> </form>

View File

@@ -28,22 +28,30 @@
{loop type="order" name="the-order" id=$order_id customer="*"} {loop type="order" name="the-order" id=$order_id customer="*"}
{loop type="currency" name="order-currency" id=$CURRENCY} {loop type="currency" name="order-currency" id=$CURRENCY}
{assign "orderCurrency" $SYMBOL} {$orderCurrency=$SYMBOL}
{/loop} {/loop}
{assign "orderStatusId" $STATUS} {assign "orderStatusId" $STATUS}
<div class="lead clearfix"> <div class="row">
<span class='label label-default pull-left'>{$REF}</span> <div class="col-md-7 title">
<div class="pull-right select-fixed-width"> {intl l='Order %ref' ref=$REF}
<form id="order-update-status-form" action="{url path="/admin/order/update/$ID/status"}" method="post"> </div>
<div class="col-md-5 actions">
<form class="form-horizontal" role="form" id="order-update-status-form" action="{url path="/admin/order/update/$ID/status"}" method="post">
<input class="js-current-tab" type="hidden" name="tab" value="{$oder_tab}"> <input class="js-current-tab" type="hidden" name="tab" value="{$oder_tab}">
<select class="js-update-order-status" name="status_id" data-toggle="selectpicker"> <div class="form-group">
{loop type="order-status" name="all-status"} <label class="col-sm-6 control-label">{intl l="Order status:"}</label>
{assign "orderStatusLabel" "order_$CODE"} <div class="col-sm-6">
<option {if $ID == $orderStatusId}selected="selected" {/if} value="{$ID}" data-content="<span class='label label-{#$orderStatusLabel#}'>{$TITLE}</span>">{$TITLE}</option> <select class="js-update-order-status" name="status_id" data-toggle="selectpicker">
{/loop} {loop type="order-status" name="all-status"}
</select> {assign "orderStatusLabel" "order_$CODE"}
<option {if $ID == $orderStatusId}selected="selected" {/if} value="{$ID}" data-content="<span class='label label-{#$orderStatusLabel#}'>{$TITLE}</span>">{$TITLE}</option>
{/loop}
</select>
</div>
</div>
</form> </form>
</div> </div>
</div> </div>
@@ -59,16 +67,16 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned"> <table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix"> <caption class="clearfix">
{intl l='Cart'} {intl l='Cart - Prices in %currency' currency=$orderCurrency}
</caption> </caption>
<thead> <thead>
<tr> <tr>
<th class="col-md-7">{intl l="Product"}</th> <th class="col-md-7">{intl l="Product"}</th>
<th class="col-md-1">{intl l="Unit. price"}</th> <th class="col-md-1 text-right">{intl l="Unit. price"}</th>
<th class="col-md-1">{intl l="Tax"}</th> <th class="col-md-1 text-right">{intl l="Tax"}</th>
<th class="col-md-1">{intl l="Unit taxed price"}</th> <th class="col-md-1 text-right">{intl l="Unit taxed price"}</th>
<th class="col-md-1">{intl l="Quantity"}</th> <th class="col-md-1 text-right">{intl l="Quantity"}</th>
<th class="col-md-1">{intl l="Taxed total"}</th> <th class="col-md-1 text-right">{intl l="Taxed total"}</th>
</tr> </tr>
</thead> </thead>
@@ -95,11 +103,11 @@
</dl> </dl>
{/ifloop} {/ifloop}
</td> </td>
<td>{$orderCurrency} {$realPrice}</td> <td class="text-right">{format_money number=$realPrice symbol=$orderCurrency}</td>
<td>{$orderCurrency} {$realTax}</td> <td class="text-right">{format_money number=$realTax symbol=$orderCurrency}</td>
<td>{$orderCurrency} {$realTaxedPrice}</td> <td class="text-right">{format_money number=$realTaxedPrice symbol=$orderCurrency}</td>
<td>{$QUANTITY}</td> <td class="text-right">{$QUANTITY}</td>
<td>{$orderCurrency} {$realTaxedPrice * $QUANTITY}</td> <td class="text-right">{format_money number=$realTaxedPrice * $QUANTITY symbol=$orderCurrency}</td>
</tr> </tr>
{/loop} {/loop}
</tbody> </tbody>
@@ -107,17 +115,17 @@
<tr class="active"> <tr class="active">
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3"><strong>{intl l="Total without discount"}</strong></td> <td colspan="3"><strong>{intl l="Total without discount"}</strong></td>
<td><strong>{$orderCurrency} {$TOTAL_TAXED_AMOUNT-$POSTAGE}</strong></td> <td class="text-right"><strong>{format_money number=$TOTAL_TAXED_AMOUNT-$POSTAGE symbol=$orderCurrency}</strong></td>
</tr> </tr>
<tr> <tr>
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3"><strong>{intl l="Discount"}</strong></td> <td colspan="3"><strong>{intl l="Discount"}</strong></td>
<td><strong>{$orderCurrency} {$DISCOUNT}</strong></td> <td class="text-right"><strong>{format_money number=$DISCOUNT symbol=$orderCurrency}</strong></td>
</tr> </tr>
<tr class="active"> <tr class="active">
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3"><strong>{intl l="Coupon code"}</strong></td> <td colspan="3"><strong>{intl l="Coupon code"}</strong></td>
<td> <td class="text-right">
{loop type="order_coupon" name="couponcode" order=$ID} {loop type="order_coupon" name="couponcode" order=$ID}
{$CODE}{if $LOOP_COUNT != $LOOP_TOTAL}, {/if} {$CODE}{if $LOOP_COUNT != $LOOP_TOTAL}, {/if}
{/loop} {/loop}
@@ -129,17 +137,17 @@
<tr> <tr>
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3"><strong>{intl l="Total including discount"}</strong></td> <td colspan="3"><strong>{intl l="Total including discount"}</strong></td>
<td><strong>{$orderCurrency} {$TOTAL_TAXED_AMOUNT-$POSTAGE}</strong></td> <td class="text-right"><strong>{format_money number=$TOTAL_TAXED_AMOUNT-$POSTAGE symbol=$orderCurrency}</strong></td>
</tr> </tr>
<tr class="active"> <tr class="active">
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3"><strong>{intl l="Postage"}</strong></td> <td colspan="3"><strong>{intl l="Postage"}</strong></td>
<td><strong>{$orderCurrency} {$POSTAGE}</strong></td> <td class="text-right"><strong>{format_money number=$POSTAGE symbol=$orderCurrency}</strong></td>
</tr> </tr>
<tr> <tr>
<td colspan="2" class="td-unstyled"></td> <td colspan="2" class="td-unstyled"></td>
<td colspan="3" class="last"><strong>{intl l="Total"}</strong></td> <td colspan="3" class="last"><strong>{intl l="Total"}</strong></td>
<td class="last"><strong>{$orderCurrency} {$TOTAL_TAXED_AMOUNT}</strong></td> <td class="last text-right"><strong>{format_money number=$TOTAL_TAXED_AMOUNT symbol=$orderCurrency}</strong></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -32,12 +32,57 @@
<thead> <thead>
<tr> <tr>
<th>{intl l="Order n°"}</th> <th class="object-title">
<th>{intl l="Date & Hour"}</th> {admin_sortable_header
<th>{intl l="Company"}</th> current_order=$orders_order
<th>{intl l="Name"}</th> order='reference'
<th>{intl l="Amount"}</th> reverse_order='reference-reverse'
<th>{intl l="Status"}</th> path={url path='/admin/orders'}
request_parameter_name='orders_order'
label="{intl l='Order #'}"
} </th>
<th class="object-title">
{admin_sortable_header
current_order=$orders_order
order='create-date'
reverse_order='create-date-reverse'
path={url path='/admin/orders'}
request_parameter_name='orders_order'
label="{intl l='Date & Hour'}"
} </th>
<th class="object-title">
{admin_sortable_header
current_order=$orders_order
order='company'
reverse_order='company-reverse'
path={url path='/admin/orders'}
request_parameter_name='orders_order'
label="{intl l='Company'}"
} </th>
<th class="object-title">
{admin_sortable_header
current_order=$orders_order
order='customer-name'
reverse_order='customer-name-reverse'
path={url path='/admin/orders'}
request_parameter_name='orders_order'
label="{intl l='Cutomer Name'}"
} </th>
<th class="object-title text-right">{intl l='Amount'}</th>
<th class="object-title text-center">
{admin_sortable_header
current_order=$orders_order
order='status'
reverse_order='status-reverse'
path={url path='/admin/orders'}
request_parameter_name='orders_order'
label="{intl l='Status'}"
} </th>
{module_include location='orders_table_header'} {module_include location='orders_table_header'}
@@ -47,7 +92,11 @@
<tbody> <tbody>
{loop type="order" name="order-list" customer="*" backend_context="1" page={$order_page} limit={#max_displayed_orders#} status=$status_filter|default:'*'} {loop type="order" name="order-list" customer="*" order=$orders_order backend_context="1" page={$order_page} limit={#max_displayed_orders#} status=$status_filter|default:'*'}
{loop type="currency" name="order-currency" id=$CURRENCY}
{$orderCurrency=$SYMBOL}
{/loop}
{loop type="order_address" name="order-invoice-address" id=$INVOICE_ADDRESS} {loop type="order_address" name="order-invoice-address" id=$INVOICE_ADDRESS}
{assign "orderInvoiceFirstName" $FIRSTNAME} {assign "orderInvoiceFirstName" $FIRSTNAME}
@@ -66,8 +115,8 @@
<td>{format_date date=$CREATE_DATE}</td> <td>{format_date date=$CREATE_DATE}</td>
<td>{$orderInvoiceCompany}</td> <td>{$orderInvoiceCompany}</td>
<td><a href="{url path='/admin/customer/update' customer_id=$CUSTOMER}">{$orderInvoiceFirstName|ucwords} {$orderInvoiceLastName|upper}</a></td> <td><a href="{url path='/admin/customer/update' customer_id=$CUSTOMER}">{$orderInvoiceFirstName|ucwords} {$orderInvoiceLastName|upper}</a></td>
<td>{$TOTAL_TAXED_AMOUNT}</td> <td class="text-right">{format_money number=$TOTAL_TAXED_AMOUNT symbol=$orderCurrency}</td>
<td><span class="label label-{#$orderStatusLabel#}">{$orderStatus}</span></td> <td class="text-center"><span class="label label-{#$orderStatusLabel#}">{$orderStatus}</span></td>
{module_include location='orders_table_row'} {module_include location='orders_table_row'}
@@ -94,14 +143,14 @@
<div class="text-center"> <div class="text-center">
<ul class="pagination pagination-centered"> <ul class="pagination pagination-centered">
{if $order_page != 1} {if $order_page != 1}
<li><a href="{url path="/admin/orders" page="1"}">&laquo;</a></li> <li><a href="{url path="/admin/orders" page=1 orders_order=$orders_order}">&laquo;</a></li>
{else} {else}
<li class="disabled"><a href="#">&laquo;</a></li> <li class="disabled"><a href="#">&laquo;</a></li>
{/if} {/if}
{pageloop rel="order-list"} {pageloop rel="order-list"}
{if $PAGE != $CURRENT} {if $PAGE != $CURRENT}
<li><a href="{url path="/admin/orders" page=$PAGE}">{$PAGE}</a></li> <li><a href="{url path="/admin/orders" page=$PAGE orders_order=$orders_order}">{$PAGE}</a></li>
{else} {else}
<li class="active"><a href="#">{$PAGE}</a></li> <li class="active"><a href="#">{$PAGE}</a></li>
@@ -110,7 +159,7 @@
{/pageloop} {/pageloop}
{if $PAGE == $LAST && $LAST != $CURRENT} {if $PAGE == $LAST && $LAST != $CURRENT}
<li><a href="{url path="/admin/orders" page="$PAGE"}">&raquo;</a></li> <li><a href="{url path="/admin/orders" page=$PAGE orders_order=$orders_order}">&raquo;</a></li>
{else} {else}
<li class="disabled"><a href="#">&raquo;</a></li> <li class="disabled"><a href="#">&raquo;</a></li>
{/if} {/if}