Merge branch 'master' of github.com:thelia/thelia
This commit is contained in:
@@ -257,7 +257,7 @@ class Install extends ContainerAwareCommand
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database host");
|
||||
throw new \RuntimeException("You must specify a database host");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
@@ -266,12 +266,12 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$connectionInfo["dbName"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Database Name (if database does not exists, Thelia will try to create it) : "),
|
||||
$this->decorateInfo("Database name (if database does not exist, Thelia will try to create it) : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database name");
|
||||
throw new \RuntimeException("You must specify a database name");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
@@ -280,12 +280,12 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$connectionInfo["username"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Databse username : "),
|
||||
$this->decorateInfo("Database username : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must sprcify database username");
|
||||
throw new \RuntimeException("You must specify a database username");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
|
||||
@@ -48,7 +48,7 @@ class HomeController extends BaseAdminController
|
||||
/* sales */
|
||||
$saleSeries = new \stdClass();
|
||||
$saleSeries->color = $this->getRequest()->query->get('sales_color', '#adadad');
|
||||
$saleSeries->data = OrderQuery::getSaleStats(
|
||||
$saleSeries->data = OrderQuery::getMonthlySaleStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -56,7 +56,7 @@ class HomeController extends BaseAdminController
|
||||
/* new customers */
|
||||
$newCustomerSeries = new \stdClass();
|
||||
$newCustomerSeries->color = $this->getRequest()->query->get('customers_color', '#f39922');
|
||||
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
|
||||
$newCustomerSeries->data = CustomerQuery::getMonthlyNewCustomersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -64,7 +64,7 @@ class HomeController extends BaseAdminController
|
||||
/* orders */
|
||||
$orderSeries = new \stdClass();
|
||||
$orderSeries->color = $this->getRequest()->query->get('orders_color', '#5cb85c');
|
||||
$orderSeries->data = OrderQuery::getOrdersStats(
|
||||
$orderSeries->data = OrderQuery::getMonthlyOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -80,7 +80,7 @@ class HomeController extends BaseAdminController
|
||||
/* cancelled orders */
|
||||
$cancelledOrderSeries = new \stdClass();
|
||||
$cancelledOrderSeries->color = $this->getRequest()->query->get('cancelled_orders_color', '#d9534f');
|
||||
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
|
||||
$cancelledOrderSeries->data = OrderQuery::getMonthlyOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y')),
|
||||
array(5)
|
||||
|
||||
@@ -36,6 +36,7 @@ use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
@@ -247,6 +248,97 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
return ConfigQuery::read($key, $default);
|
||||
}
|
||||
|
||||
public function StatsAccess($params, $smarty)
|
||||
{
|
||||
if (false === array_key_exists("key", $params)) {
|
||||
throw new \InvalidArgumentException(sprintf("missing key attribute in stats access function"));
|
||||
}
|
||||
if (false === array_key_exists("startDate", $params) || $params['startDate'] === '') {
|
||||
throw new \InvalidArgumentException(sprintf("missing startDate attribute in stats access function"));
|
||||
}
|
||||
if (false === array_key_exists("endDate", $params) || $params['endDate'] === '') {
|
||||
throw new \InvalidArgumentException(sprintf("missing endDate attribute in stats access function"));
|
||||
}
|
||||
|
||||
if (false !== array_key_exists("includeShipping", $params) && $params['includeShipping'] == 'false') {
|
||||
$includeShipping = false;
|
||||
} else {
|
||||
$includeShipping = true;
|
||||
}
|
||||
|
||||
if($params['startDate'] == 'today') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'yesterday') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->setTime(0, 0, 0);
|
||||
$startDate->modify('-1 day');
|
||||
} elseif($params['startDate'] == 'this_month') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of this month');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'last_month') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of last month');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'this_year') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of January this year');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'last_year') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of December last year');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} else {
|
||||
try {
|
||||
$startDate = new \DateTime($params['startDate']);
|
||||
} catch(\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf("invalid startDate attribute '%s' in stats access function", $params['startDate']));
|
||||
}
|
||||
}
|
||||
|
||||
if($params['endDate'] == 'today') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'yesterday') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->setTime(0, 0, 0);
|
||||
$endDate->modify('-1 day');
|
||||
} elseif($params['endDate'] == 'this_month') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of this month');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'last_month') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of last month');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'this_year') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of December this year');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'last_year') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of January last year');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} else {
|
||||
try {
|
||||
$endDate = new \DateTime($params['endDate']);
|
||||
} catch(\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf("invalid endDate attribute '%s' in stats access function", $params['endDate']));
|
||||
}
|
||||
}
|
||||
|
||||
switch( $params['key'] ) {
|
||||
case 'sales' :
|
||||
return OrderQuery::getSaleStats($startDate, $endDate, $includeShipping);
|
||||
case 'orders' :
|
||||
return OrderQuery::getOrderStats($startDate, $endDate, array(1,2,3,4));
|
||||
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf("invalid key attribute '%s' in stats access function", $params['key']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $objectLabel
|
||||
* @param $params
|
||||
@@ -358,6 +450,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'order', $this, 'orderDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'config', $this, 'ConfigDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'stats', $this, 'StatsAccess'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class CustomerQuery extends BaseCustomerQuery {
|
||||
return self::create()->findOneByEmail($email);
|
||||
}
|
||||
|
||||
public static function getNewCustomersStats($month, $year)
|
||||
public static function getMonthlyNewCustomersStats($month, $year)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
|
||||
@@ -50,11 +50,12 @@ class Order extends BaseOrder
|
||||
/**
|
||||
* calculate the total amount
|
||||
*
|
||||
* @param int $tax
|
||||
* @param int $tax
|
||||
* @param bool $includePostage
|
||||
*
|
||||
* @return int|string|Base\double
|
||||
* @return float|int|string
|
||||
*/
|
||||
public function getTotalAmount(&$tax = 0)
|
||||
public function getTotalAmount(&$tax = 0, $includePostage = true)
|
||||
{
|
||||
$amount = 0;
|
||||
$tax = 0;
|
||||
@@ -76,7 +77,13 @@ class Order extends BaseOrder
|
||||
$tax += round($taxAmount->getVirtualColumn('total_tax'), 2) * $orderProduct->getQuantity();
|
||||
}
|
||||
|
||||
return $amount + $tax + $this->getPostage(); // @todo : manage discount
|
||||
$total = $amount + $tax;
|
||||
|
||||
if(false !== $includePostage) {
|
||||
$total += $this->getPostage();
|
||||
}
|
||||
|
||||
return $total; // @todo : manage discount
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function getSaleStats($month, $year)
|
||||
public static function getMonthlySaleStats($month, $year)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
@@ -75,7 +75,7 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public static function getOrdersStats($month, $year, $status = null)
|
||||
public static function getMonthlyOrdersStats($month, $year, $status = null)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
@@ -121,5 +121,42 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $startDate
|
||||
* @param \DateTime $endDate
|
||||
* @param $includeShipping
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSaleStats(\DateTime $startDate, \DateTime $endDate, $includeShipping)
|
||||
{
|
||||
$amount = 0;
|
||||
foreach(self::create()
|
||||
->filterByStatusId(array(2,3,4), Criteria::IN)
|
||||
->filterByCreatedAt(sprintf("%s 00:00:00", $startDate->format('Y-m-d')), Criteria::GREATER_EQUAL)
|
||||
->filterByCreatedAt(sprintf("%s 23:59:59", $endDate->format('Y-m-d')), Criteria::LESS_EQUAL)
|
||||
->find() as $order) {
|
||||
$tax = 0;
|
||||
$amount += $order->getTotalAmount($tax, $includeShipping);
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $startDate
|
||||
* @param \DateTime $endDate
|
||||
* @param $status
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getOrderStats(\DateTime $startDate, \DateTime $endDate, $status = array(1,2,3,4))
|
||||
{
|
||||
return self::create()
|
||||
->filterByStatusId($status, Criteria::IN)
|
||||
->filterByCreatedAt(sprintf("%s 00:00:00", $startDate->format('Y-m-d')), Criteria::GREATER_EQUAL)
|
||||
->filterByCreatedAt(sprintf("%s 23:59:59", $endDate->format('Y-m-d')), Criteria::LESS_EQUAL)
|
||||
->count();
|
||||
}
|
||||
|
||||
} // OrderQuery
|
||||
|
||||
@@ -47,43 +47,39 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{intl l="Customers"}</th>
|
||||
<td>1</td>
|
||||
<td>
|
||||
{count type="customer" current="false" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Categories"}</th>
|
||||
<td>8</td>
|
||||
<td>
|
||||
{count type="category" visible="*" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Products"}</th>
|
||||
<td>43</td>
|
||||
<td>
|
||||
{count type="product" visible="*" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Online products"}</th>
|
||||
<td>43</td>
|
||||
<td>
|
||||
{count type="product" visible="true" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Offline products"}</th>
|
||||
<td>0</td>
|
||||
<td>
|
||||
{count type="product" visible="false" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Orders"}</th>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Pending orders"}</th>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="In process orderst"}</th>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Shipped orders"}</th>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Canceled orders"}</th>
|
||||
<td>0</td>
|
||||
<td>
|
||||
{count type="order" status="*" backend_context="1"}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -108,31 +104,35 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{intl l="Overall sales"}</th>
|
||||
<td>2500.00 €</td>
|
||||
<td>{stats key="sales" startDate="today" endDate="today"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Sales excluding shipping"}</th>
|
||||
<td>2000.00 €</td>
|
||||
<td>
|
||||
{$salesNoShipping = {stats key="sales" startDate="today" endDate="today" includeShipping="false"}}
|
||||
{$salesNoShipping} €
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Yesterday sales"}</th>
|
||||
<td>1700.00 €</td>
|
||||
<td>{stats key="sales" startDate="yesterday" endDate="yesterday"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Waiting orders"}</th>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="In process orders"}</th>
|
||||
<td>52</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Canceled orders"}</th>
|
||||
<td>3</td>
|
||||
<th>{intl l="Orders"}</th>
|
||||
<td>
|
||||
{$orderCount = {stats key="orders" startDate="today" endDate="today"}}
|
||||
{$orderCount}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Average cart"}</th>
|
||||
<td>25.00 €</td>
|
||||
<td>
|
||||
{if $orderCount == 0}
|
||||
0 €
|
||||
{else}
|
||||
{($salesNoShipping/$orderCount)|round:"2"} €
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -144,31 +144,35 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{intl l="Overall sales"}</th>
|
||||
<td>2500.00 €</td>
|
||||
<td>{stats key="sales" startDate="this_month" endDate="this_month"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Sales excluding shipping"}</th>
|
||||
<td>2000.00 €</td>
|
||||
<td>
|
||||
{$salesNoShipping = {stats key="sales" startDate="this_month" endDate="this_month" includeShipping="false"}}
|
||||
{$salesNoShipping} €
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Previous month sales"}</th>
|
||||
<td>1700.00 €</td>
|
||||
<td>{stats key="sales" startDate="last_month" endDate="last_month"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Waiting orders"}</th>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="In process orders"}</th>
|
||||
<td>52</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Canceled orders"}</th>
|
||||
<td>3</td>
|
||||
<th>{intl l="Orders"}</th>
|
||||
<td>
|
||||
{$orderCount = {stats key="orders" startDate="this_month" endDate="this_month"}}
|
||||
{$orderCount}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Average cart"}</th>
|
||||
<td>25.00 €</td>
|
||||
<td>
|
||||
{if $orderCount == 0}
|
||||
0 €
|
||||
{else}
|
||||
{($salesNoShipping/$orderCount)|round:"2"} €
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -180,31 +184,35 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{intl l="Overall sales"}</th>
|
||||
<td>2500.00 €</td>
|
||||
<td>{stats key="sales" startDate="this_year" endDate="this_year"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Sales excluding shipping"}</th>
|
||||
<td>2000.00 €</td>
|
||||
<td>
|
||||
{$salesNoShipping = {stats key="sales" startDate="this_year" endDate="this_year" includeShipping="false"}}
|
||||
{$salesNoShipping} €
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Previous year sales"}</th>
|
||||
<td>1700.00 €</td>
|
||||
<td>{stats key="sales" startDate="last_year" endDate="last_year"} €</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Waiting orders"}</th>
|
||||
<td>4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="In process orders"}</th>
|
||||
<td>52</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Canceled orders"}</th>
|
||||
<td>3</td>
|
||||
<th>{intl l="Orders"}</th>
|
||||
<td>
|
||||
{$orderCount = {stats key="orders" startDate="this_year" endDate="this_year"}}
|
||||
{$orderCount}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{intl l="Average cart"}</th>
|
||||
<td>25.00 €</td>
|
||||
<td>
|
||||
{if $orderCount == 0}
|
||||
0 €
|
||||
{else}
|
||||
{($salesNoShipping/$orderCount)|round:"2"} €
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user