Skip to content

Commit

Permalink
Merge pull request #943 from inbaz/develop
Browse files Browse the repository at this point in the history
corrected statistics; adjusted matching
  • Loading branch information
BigAndini authored Apr 17, 2017
2 parents 9d6a396 + 9d22272 commit fb0697e
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 35 deletions.
Binary file modified data/ers.mwb
Binary file not shown.
Binary file modified data/ers.mwb.bak
Binary file not shown.
18 changes: 9 additions & 9 deletions module/Admin/src/Admin/Controller/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public function sendPaymentReminderAction() {
$qb->andWhere($qb->expr()->eq('o.payment_reminder_status', ':prstatus'));
$qb->setParameter('status', 'ordered');
$paymentTarget = new \DateTime;
$paymentTarget->modify( '-5 days' );
$paymentTarget->modify( '-10 days' );
$qb->setParameter('paymentTarget', $paymentTarget);
$qb->setParameter('prstatus', '0');
#$qb->setFirstResult( $offset )
Expand Down Expand Up @@ -493,10 +493,10 @@ public function sendPaymentReminderAction() {
$emailService->setFrom($config['ERS']['info_mail']);

/*** real buyer ***/
$buyer = $order->getBuyer();
$emailService->addTo($buyer);
#$buyer = $order->getBuyer();
#$emailService->addTo($buyer);
/***/
/*** test buyer **
/*** test buyer **/
$user = new Entity\User();
$user->setEmail('andi'.$order->getCode()->getValue().'@inbaz.org');
$emailService->addTo($user);
Expand Down Expand Up @@ -525,6 +525,7 @@ public function sendPaymentReminderAction() {
$em->flush();

echo "sent payment reminder for order ".$order->getCode()->getValue().PHP_EOL;
\sleep(5);
}
}

Expand Down Expand Up @@ -825,7 +826,7 @@ public function calcSumsAction() {
$em = $this->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
$qb = $em->getRepository('ErsBase\Entity\Order')->createQueryBuilder('o');
$qb->join('o.status', 's');
$qb->join('o.status', 's', 'WITH', 's.active = 1');
$qb->where($qb->expr()->neq('s.value', ':status'));
$qb->setParameter('status', 'order pending');

Expand All @@ -836,8 +837,9 @@ public function calcSumsAction() {
#echo $order->getCode()->getValue().PHP_EOL;
$orig_total_sum = $order->getTotalSum();
$orig_order_sum = $order->getOrderSum();
$order->getTotalSumEur();
$order->getOrderSumEur();

$persist = false;
if($orig_order_sum != $order->getPrice()) {
$order->setOrderSum($order->getPrice());
echo "update order sum for ".$order->getCode()->getValue().": ".$orig_order_sum." != ".$order->getPrice().PHP_EOL;
Expand All @@ -847,9 +849,7 @@ public function calcSumsAction() {
echo "update total sum for ".$order->getCode()->getValue().": ".$orig_total_sum." != ".$order->getSum().PHP_EOL;
}

if($persist) {
$em->persist($order);
}
$em->persist($order);
}
$em->flush();
}
Expand Down
41 changes: 20 additions & 21 deletions module/Admin/src/Admin/Controller/StatisticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function orgasAction() {
->get('Doctrine\ORM\EntityManager');

$qb1 = $em->getRepository('ErsBase\Entity\Order')->createQueryBuilder('o');
$qb1->select(array('SUM(o.order_sum) as ordersum'));
$qb1->select(array('SUM(o.order_sum_eur) as ordersum'));
$qb1->join('o.status', 's');
$qb1->join('o.paymentType', 'pt');
$qb1->where($qb1->expr()->eq('s.value', ':status'));
Expand All @@ -32,15 +32,15 @@ public function orgasAction() {
$ordersums = $qb1->getQuery()->getSingleResult();


/* SELECT SUM( order_sum ) , SUM( total_sum )
/* SELECT SUM( order_sum_eur ) , SUM( total_sum_eur )
FROM `order`
JOIN `match` ON `order`.id = `match`.order_id
JOIN bank_statement ON bank_statement.id = `match`.bank_statement_id
JOIN bank_account ON bank_account.id = bank_statement.bank_account_id
WHERE bank_account.id =2
*/
$qb2 = $em->getRepository('ErsBase\Entity\Match')->createQueryBuilder('m');
$qb2->select(array('SUM(o.order_sum) as ordersum'));
$qb2->select(array('SUM(o.order_sum_eur) as ordersum'));
$qb2->join('m.order', 'o');
$qb2->join('m.bankStatement', 'bs');
$qb2->join('bs.paymentType', 'pt');
Expand Down Expand Up @@ -141,7 +141,7 @@ public function ordersAction() {
$order_data['paymentfees'] = array_sum(array_map(function($row){ return floatval($row['fee']); }, $paymentFees));
$fastResults = $em->createQueryBuilder()
->select('SUM(o.total_sum) totalsum_fast', 'SUM(o.order_sum) ordersum_fast')->from('ErsBase\Entity\Order o')
->select('SUM(o.total_sum_eur) totalsum_fast', 'SUM(o.order_sum_eur) ordersum_fast')->from('ErsBase\Entity\Order o')
->getQuery()->getSingleResult();
$order_data['ordersum_fast'] = $fastResults['ordersum_fast'];
Expand All @@ -151,48 +151,47 @@ public function ordersAction() {



$orderSelectFields = array('COUNT(o.id) AS ordercount', 'SUM(o.order_sum) AS ordersum, SUM(o.total_sum) AS totalsum');
$orderSelectFields = array('COUNT(o.id) AS ordercount', 'SUM(o.order_sum_eur) AS ordersum, SUM(o.total_sum_eur) AS totalsum');

$paymentStatusStats = $em->createQueryBuilder()
#->select(array_merge(array('o.payment_status AS label'), $orderSelectFields))
->select(array_merge(array('s status, s.value label', 'o.currency_id'), $orderSelectFields))
->select(array_merge(array('s status, s.value label'), $orderSelectFields))
->from('ErsBase\Entity\Status', 's')
->leftJoin('s.orders', 'o')
#->groupBy('o.payment_status')
->groupBy('s.value', 's.id', 'o.currency_id')
->groupBy('s.value', 's.id')
->orderBy('s.position')
->getQuery()->getResult();

$currencies = $em->getRepository('ErsBase\Entity\Currency')->findAll();
$factor = array();
foreach($currencies as $currency) {
$factor[$currency->getId()] = $currency->getFactor();
}

$byStatusGroups = array('active' => array(), 'inactive' => array());
foreach($paymentStatusStats AS $statusData) {
error_log($statusData['ordersum'].' '.$statusData['currency_id']);
$statusData['ordersum'] = $statusData['ordersum'] * $factor[$statusData['currency_id']];
$statusData['totalsum'] = $statusData['totalsum'] * $factor[$statusData['currency_id']];
$group = ($statusData['status']->getActive() ? 'active' : 'inactive');
$byStatusGroups[$group][] = $statusData;
}
error_log('active: '.count($byStatusGroups['active']));
error_log('inactive: '.count($byStatusGroups['inactive']));

$paymentTypeStats = $em->createQueryBuilder()
->select(array_merge(array('pt.name AS label', 'c.short as currency'), $orderSelectFields))
->from('ErsBase\Entity\PaymentType', 'pt')
#->join('pt.orders', 'o', 'WITH', "o.payment_status != 'cancelled' AND o.payment_status != 'refund'")
->join('pt.orders', 'o')
->join('o.status', 's', 'WITH', "s.active = 1")
->join('pt.currency', 'c')
->groupBy('pt.id')
->getQuery()->getResult();



return new ViewModel(array(
'stats_paymentStatusGroups' => $byStatusGroups,
'stats_paymentTypes' => $paymentTypeStats
'stats_paymentTypes' => $paymentTypeStats,
/*'orderActiveCount' => $em->createQueryBuilder()
->select('COUNT(o.id)')
->from('ErsBase\Entity\Order', 'o')
->join('o.status', 's', 'WITH', "s.active = 1")
->getQuery()->getSingleScalarResult(),
'orderInactiveCount' => $em->createQueryBuilder()
->select('COUNT(o.id)')
->from('ErsBase\Entity\Order', 'o')
->join('o.status', 's', 'WITH', "s.active = 0")
->getQuery()->getSingleScalarResult(),*/
));
}

Expand Down
6 changes: 4 additions & 2 deletions module/Admin/view/admin/currency/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ $this->headTitle($title);

<table class="table">
<tr>
<th>Pos.</th>
<th>Name</th>
<th>#</th>
<th>name</th>
<th>factor</th>
<th>active</th>
<th class="text-right">
<a class="btn btn-success" href="<?php echo $this->url('admin/currency', array('action'=>'add'));?>"><i class="fa fa-plus"></i> currency</a>
Expand All @@ -19,6 +20,7 @@ $this->headTitle($title);
<tr>
<td><?php echo $currency->getPosition(); ?></td>
<td><?php echo $currency->getName(); ?> (<?php echo $currency->getShort().' / '.$currency->getSymbol(); ?>)</td>
<td><?php echo $currency->getFactor(); ?></td>
<td>
<?php if($currency->getActive()): ?>
<i class="fa fa-check"></i>
Expand Down
5 changes: 5 additions & 0 deletions module/Admin/view/admin/statistic/orders.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ $this->headTitle($title);

<div class="panel-footer">Only active orders are included in this view.</div>
</div>

<?php /*<div class="row">
<div class="col-xs-12">active order count: <?php echo $orderActiveCount; ?></div>
<div class="col-xs-12">inactive order count: <?php echo $orderInactiveCount; ?></div>
</div>*/ ?>
62 changes: 59 additions & 3 deletions module/ErsBase/src/ErsBase/Entity/Base/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Auto generated by MySQL Workbench Schema Exporter.
* Version 2.1.6-dev (doctrine2-mappedsuperclass) on 2017-03-06 16:58:38.
* Version 2.1.6-dev (doctrine2-mappedsuperclass) on 2017-04-17 14:11:19.
* Goto https://github.com/johmue/mysql-workbench-schema-exporter for more
* information.
*/
Expand Down Expand Up @@ -73,11 +73,21 @@ abstract class Order
*/
protected $order_sum;

/**
* @ORM\Column(name="`order_sum_eur`", type="float", nullable=true)
*/
protected $order_sum_eur;

/**
* @ORM\Column(name="`total_sum`", type="float", nullable=true)
*/
protected $total_sum;

/**
* @ORM\Column(name="`total_sum_eur`", type="float", nullable=true)
*/
protected $total_sum_eur;

/**
* @ORM\Column(name="`refund_sum`", type="float", nullable=true)
*/
Expand Down Expand Up @@ -414,6 +424,29 @@ public function getOrderSum()
return $this->order_sum;
}

/**
* Set the value of order_sum_eur.
*
* @param float $order_sum_eur
* @return \ErsBase\Entity\Base\Order
*/
public function setOrderSumEur($order_sum_eur)
{
$this->order_sum_eur = $order_sum_eur;

return $this;
}

/**
* Get the value of order_sum_eur.
*
* @return float
*/
public function getOrderSumEur()
{
return $this->order_sum_eur;
}

/**
* Set the value of total_sum.
*
Expand All @@ -437,6 +470,29 @@ public function getTotalSum()
return $this->total_sum;
}

/**
* Set the value of total_sum_eur.
*
* @param float $total_sum_eur
* @return \ErsBase\Entity\Base\Order
*/
public function setTotalSumEur($total_sum_eur)
{
$this->total_sum_eur = $total_sum_eur;

return $this;
}

/**
* Get the value of total_sum_eur.
*
* @return float
*/
public function getTotalSumEur()
{
return $this->total_sum_eur;
}

/**
* Set the value of refund_sum.
*
Expand Down Expand Up @@ -841,7 +897,7 @@ public function populate(array $data = array())
*/
public function getArrayCopy(array $fields = array())
{
$dataFields = array('id', 'code_id', 'status_id', 'buyer_id', 'payment_type_id', 'hashkey', 'invoice_detail', 'payment_status', 'payment_reminder_status', 'order_sum', 'total_sum', 'refund_sum', 'currency_id', 'comment', 'updated', 'created');
$dataFields = array('id', 'code_id', 'status_id', 'buyer_id', 'payment_type_id', 'hashkey', 'invoice_detail', 'payment_status', 'payment_reminder_status', 'order_sum', 'order_sum_eur', 'total_sum', 'total_sum_eur', 'refund_sum', 'currency_id', 'comment', 'updated', 'created');
$relationFields = array('user', 'paymentType', 'status', 'code', 'currency');
$copiedFields = array();
foreach ($relationFields as $relationField) {
Expand Down Expand Up @@ -874,6 +930,6 @@ public function getArrayCopy(array $fields = array())

public function __sleep()
{
return array('id', 'code_id', 'status_id', 'buyer_id', 'payment_type_id', 'hashkey', 'invoice_detail', 'payment_status', 'payment_reminder_status', 'order_sum', 'total_sum', 'refund_sum', 'currency_id', 'comment', 'updated', 'created');
return array('id', 'code_id', 'status_id', 'buyer_id', 'payment_type_id', 'hashkey', 'invoice_detail', 'payment_status', 'payment_reminder_status', 'order_sum', 'order_sum_eur', 'total_sum', 'total_sum_eur', 'refund_sum', 'currency_id', 'comment', 'updated', 'created');
}
}
15 changes: 15 additions & 0 deletions module/ErsBase/src/ErsBase/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,22 @@ public function getTotalSum()
}
return $this->total_sum;
}

public function getOrderSumEur() {
if($this->order_sum_eur == 0) {
$this->order_sum_eur = $this->getPrice()*$this->getCurrency()->getFactor();
}
return $this->order_sum_eur;
}

public function getTotalSumEur()
{
if($this->total_sum_eur == 0) {
$this->total_sum_eur = $this->getSum()*$this->getCurrency()->getFactor();
}
return $this->total_sum_eur;
}

/**
* Not needed here anymore the method of the base entity is used instead
* Add Package entity to collection (one to many).
Expand Down

0 comments on commit fb0697e

Please sign in to comment.