Skip to content

Commit

Permalink
Merge branch 'release/1.22.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiov committed Feb 11, 2019
2 parents a66e626 + a74877c commit ae0be34
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Application\ViewHelper;

use Zend\Debug\Debug;
use Zend\Escaper\Escaper;
use Zend\Form\Element;
use Zend\View\Helper\AbstractHelper;
Expand Down
3 changes: 1 addition & 2 deletions module/Authorize/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
],
'MoneyLog\Controller\Movement' => [
'account' => 'user',
'add' => 'user',
'delete' => 'user',
'edit' => 'user',
'expense' => 'user',
'export' => 'user',
'income' => 'user',
'index' => 'user',
'move' => 'user',
'movement' => 'user',
Expand Down
47 changes: 25 additions & 22 deletions module/MoneyLog/src/MoneyLog/Controller/MovementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public function editAction()
/* @var Movement $item */
$item = $this->em->getRepository(Movement::class)->findOneBy(['id' => $id]);

$isIn = $item->amount > 0;
$type = $item->amount < 0 ? -1 : 1;
$item->amount = abs($item->amount);


if (!$item || $item->account->userId != $this->user->id) {
return $this->redirect()->toRoute('accantonaAccount', array('action' => 'index'));
}

$form = new MovementForm('movement', $this->em, $this->user->id);
$form->bind($item);
$form->get('type')->setValue($type);

$request = $this->getRequest();
$searchParams = $this->params()->fromQuery();
Expand All @@ -56,7 +56,7 @@ public function editAction()
$form->setData($data);

if ($form->isValid()) {
$item->amount = $item->amount * ($isIn ? Movement::IN : Movement::OUT);
$item->amount = $item->amount * $data['type'];
$item->category = $this->em->getRepository(Category::class)->findOneBy([
'id' => $data['category'], 'userId' => $this->user->id
]);
Expand All @@ -68,7 +68,7 @@ public function editAction()
}
}

return ['item' => $item, 'isIn' => $isIn, 'form' => $form, 'searchParams' => $searchParams];
return ['item' => $item, 'form' => $form, 'searchParams' => $searchParams];
}

/**
Expand Down Expand Up @@ -191,6 +191,7 @@ public function deleteAction()
public function moveAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
$searchParams = $this->params()->fromQuery();

/* @var AccountRepository $accountRepo */
$accountRepo = $this->em->getRepository('Application\Entity\Account');
Expand Down Expand Up @@ -247,26 +248,21 @@ public function moveAction()

$this->em->flush();

return $this->redirect()->toRoute('accantonaAccount', array('action' => 'index'));
$routeParams = ['action' => 'account', 'id' => $sourceAccount->id];
return $this->redirect()->toRoute('accantonaMovement', $routeParams, ['query' => $searchParams]);
}
}

return array('sourceAccount' => $sourceAccount, 'form' => $form);
}

public function expenseAction()
{
return $this->addMovement($this->params('action'));
}

public function incomeAction()
{
return $this->addMovement($this->params('action'));
$routeParams = ['action' => 'move', 'id' => $id];
$routeOptions = ['query' => $searchParams];
$form->setAttribute('action', $this->url()->fromRoute('accantonaMovement', $routeParams, $routeOptions));
return ['sourceAccount' => $sourceAccount, 'form' => $form, 'searchParams' => $searchParams];
}

private function addMovement($action)
public function addAction()
{
$accountId = (int) $this->params()->fromRoute('id');
$searchParams = $this->params()->fromQuery();

/* @var $account Account */
$account = $this->em->getRepository('Application\Entity\Account')->find($accountId);
Expand All @@ -278,7 +274,6 @@ private function addMovement($action)
$request = $this->getRequest();
$form = new MovementForm('movement', $this->em, $this->user->id);
if ($request->isPost()) {

$movement = new Movement();
$data = $request->getPost();
$form->setInputFilter($movement->getInputFilter());
Expand All @@ -287,7 +282,8 @@ private function addMovement($action)
if ($form->isValid()) {

$repetitionNumber = (int) $data['repetitionNumber'];
$repetitionNumber = !empty($data['repetition']) && in_array($data['repetitionPeriod'], ['month', 'week']) &&
$repetitionNumber = !empty($data['repetition']) &&
in_array($data['repetitionPeriod'], ['month', 'week']) &&
$repetitionNumber > 0 && $repetitionNumber < 13 ? $repetitionNumber : 1;

$category = $this->em->getRepository('Application\Entity\Category')
Expand All @@ -297,7 +293,7 @@ private function addMovement($action)
$movement = new Movement();
$movement->exchangeArray([
'date' => date('Y-m-d', strtotime("{$data['date']} +$i {$data['repetitionPeriod']}")),
'amount' => $data['amount'] * ($action === 'expense' ? -1 : 1),
'amount' => $data['amount'] * $data['type'],
'description' => $data['description'],
'category' => $category,
]);
Expand All @@ -307,10 +303,17 @@ private function addMovement($action)
$this->em->flush();
}

return $this->redirect()->toRoute('accantonaMovement', ['action' => 'account', 'id' => $accountId]);
return $this->redirect()->toRoute('accantonaMovement', [
'action' => 'account',
'id' => $accountId
], ['query' => $searchParams]);
}
}

return ['sourceAccount' => $account, 'form' => $form];
$form->setAttribute('action', $this->url()->fromRoute('accantonaMovement', [
'action' => 'add',
'id' => $account->id
], ['query' => $searchParams]));
return ['sourceAccount' => $account, 'form' => $form, 'searchParams' => $searchParams];
}
}
13 changes: 13 additions & 0 deletions module/MoneyLog/src/MoneyLog/Form/MovementForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace MoneyLog\Form;

use Application\Entity\Movement;
use Doctrine\ORM\EntityManager;
use Zend\Form\Form;

Expand Down Expand Up @@ -28,6 +29,18 @@ public function __construct($name = 'movement', EntityManager $em, $userId)
$this->em = $em;
$this->userId = $userId;

$this->add([
'name' => 'type',
'options' => [
'disable_inarray_validator' => false,
'display_empty_item' => false,
'label' => 'Tipo',
'property' => 'descrizione',
'value_options' => ['-1' => 'Uscita', '1' => 'Entrata'],
],
'required' => true,
'type' => \Zend\Form\Element\Select::class,
]);
$this->add([
'attributes' => ['class' => 'form-control', 'value' => date('Y-m-d')],
'name' => 'date',
Expand Down
10 changes: 6 additions & 4 deletions module/MoneyLog/src/MoneyLog/View/Helper/Morris.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ public function donut($element, array $data, $labelKey = 'label', $valueKey = 'v
$d[] = ['label' => $i[$labelKey], 'value' => $i[$valueKey]];
}
$colors = [
'#2e6da4', // blu
'#3d8b3d', // verde
'#6d9e00', // verde scuro
'#7fb800', // verde
'#91d100', // verde chiaro
'#ebc400', // arancione chiaro
'#eb9d00', // arancione
'#e67300', // arancione scuro
'#d22300', // rosso
'#b80000', // rosso scuro
'#d22300', // rosso
'#e67300', // arancione scuro
'#eb9d00', // arancione
'#ebc400', // arancione chiaro
];
$jsonData = json_encode($d);
$jsonColors = json_encode(array_splice($colors, 0, count($data)));
Expand Down
8 changes: 4 additions & 4 deletions module/MoneyLog/view/money-log/movement/account.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Morris.Line({
<?php
$i = '<i class="mfb-component__child-icon glyphicon glyphicon-equalizer"></i>';
$this->floatingButtons()
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'expense', 'id' => $account->id]), 'label' => 'Uscita', 'icon' => 'minus'])
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'income', 'id' => $account->id]), 'label' => 'Entrata', 'icon' => 'plus'])
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'move', 'id' => $account->id]), 'label' => 'Giroconto', 'icon' => 'transfer'])
->addRawItem("<span class=\"balance mfb-component__button--child\" data-mfb-label=\"Conguaglio\" data-toggle=\"modal\" data-target=\"#modal-balance\">$i</span>");
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'add', 'id' => $account->id], ['query' => $searchParams]), 'label' => 'Nuovo movimento', 'icon' => 'plus'])
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'move', 'id' => $account->id], ['query' => $searchParams]), 'label' => 'Giroconto', 'icon' => 'transfer'])
->addRawItem("<span class=\"balance mfb-component__button--child\" data-toggle=\"modal\" data-target=\"#modal-balance\">$i</span>")
->addAnchorItem(['href' => $this->url('accantonaMovement', ['action' => 'export', 'id' => $account->id], ['query' => $searchParams]), 'label' => 'Esporta', 'icon' => 'export']);
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php echo $this->pageHeader('Aggiungi spesa'); ?>
<?php echo $this->pageHeader('Aggiungi movimento'); ?>
<div class="row">
<div class="col-lg-4">
</div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
Aggiungi spesa in <?php echo $sourceAccount->name; ?>
Aggiungi movimento in <?php echo $sourceAccount->name; ?>
</div>
<div class="panel-body">
<?php echo $this->partial('money-log/movement/partials/movement', ['form' => $this->form, 'accountId' => $this->sourceAccount->id, 'isRepeatable' => true]); ?>
<?php echo $this->partial('money-log/movement/partials/movement', [
'form' => $this->form, 'accountId' => $this->sourceAccount->id, 'isRepeatable' => true, 'searchParams' => $searchParams
]); ?>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions module/MoneyLog/view/money-log/movement/edit.phtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php echo $this->pageHeader(sprintf('Modifica %s', $isIn ? 'entrata' : 'spesa')); ?>
<?php echo $this->pageHeader('Modifica movimento'); ?>
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">Modifica <?php echo $isIn ? 'entrata' : 'spesa'; ?> in <?php echo $item->account->name; ?></div>
<div class="panel-heading">Modifica movimento in <?php echo $item->account->name; ?></div>
<div class="panel-body">
<?php $this->form->setAttribute('action', $this->url('accantonaMovement', ['action' => 'edit', 'id' => $this->item->id], ['query' => $searchParams])); ?>
<?php $this->form->prepare(); ?>
<?php echo $this->partial('money-log/movement/partials/movement', ['form' => $this->form, 'accountId' => $this->item->accountId, 'isRepeatable' => false]); ?>
<?php echo $this->partial('money-log/movement/partials/movement', ['form' => $this->form, 'accountId' => $this->item->accountId, 'isRepeatable' => false, 'searchParams' => $searchParams]); ?>
</div>
</div>
</div>
Expand Down
17 changes: 0 additions & 17 deletions module/MoneyLog/view/money-log/movement/income.phtml

This file was deleted.

4 changes: 3 additions & 1 deletion module/MoneyLog/view/money-log/movement/move.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<?php echo $this->sbaFormRow($form->get('targetAccountId')); ?>

<div class="text-right">
<a class="btn btn-default" href="<?= $this->url('accantonaMovement', array('action' => 'account', 'id' => $this->sourceAccount->id)) ?>">Annulla</a>
<a class="btn btn-default" href="<?php echo $this->url('accantonaMovement', ['action' => 'account', 'id' => $this->sourceAccount->id], ['query' => $searchParams]) ?>">
Annulla
</a>
<button type="submit" class="btn btn-primary">Sposta</button>
</div>
<?php echo $this->form()->closeTag(); ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php echo $this->form()->openTag($this->form); ?>

<?php echo $this->sbaFormRow($form->get('type')); ?>
<?php echo $this->sbaFormRow($form->get('date')); ?>
<?php echo $this->sbaFormRow($form->get('amount')); ?>
<?php echo $this->sbaFormRow($form->get('description')); ?>
Expand All @@ -24,7 +25,7 @@
<?php endif; ?>

<div class="text-right">
<a class="btn btn-default" href="<?php echo $this->url('accantonaMovement', ['action' => 'account', 'id' => $this->accountId]); ?>">
<a class="btn btn-default" href="<?php echo $this->url('accantonaMovement', ['action' => 'account', 'id' => $this->accountId], ['query' => $searchParams]); ?>">
Annulla
</a>
<button type="submit" class="btn btn-primary">
Expand Down

0 comments on commit ae0be34

Please sign in to comment.