added invoice replacer for currently logged-in user (#2899)

This commit is contained in:
Kevin Papst
2021-11-03 12:00:52 +01:00
committed by GitHub
parent 1b35356f81
commit eb63dae405
3 changed files with 75 additions and 15 deletions

View File

@@ -151,7 +151,7 @@ final class ConfigurableNumberGenerator implements NumberGeneratorInterface
// for customer
case 'cc':
$partialResult = $this->repository->getCounterForAllTime($this->model->getCustomer()) + $increaseBy;
$partialResult = $this->repository->getCounterForCustomerAllTime($this->model->getCustomer()) + $increaseBy;
break;
case 'ccy':
@@ -166,9 +166,34 @@ final class ConfigurableNumberGenerator implements NumberGeneratorInterface
$partialResult = $this->repository->getCounterForDay($invoiceDate, $this->model->getCustomer()) + $increaseBy;
break;
// for user
case 'cu':
$partialResult = $this->repository->getCounterForUserAllTime($this->model->getUser()) + $increaseBy;
break;
case 'cuy':
$partialResult = $this->repository->getCounterForYear($invoiceDate, null, $this->model->getUser()) + $increaseBy;
break;
case 'cum':
$partialResult = $this->repository->getCounterForMonth($invoiceDate, null, $this->model->getUser()) + $increaseBy;
break;
case 'cud':
$partialResult = $this->repository->getCounterForDay($invoiceDate, null, $this->model->getUser()) + $increaseBy;
break;
case 'ustaff':
$partialResult = $this->model->getUser() !== null ? $this->model->getUser()->getAccountNumber() : '';
break;
case 'uid':
$partialResult = $this->model->getUser() !== null ? (string) $this->model->getUser()->getId() : '';
break;
// across all invoices
case 'c':
$partialResult = $this->repository->getCounterForAllTime() + $increaseBy;
$partialResult = $this->repository->getCounterForCustomerAllTime() + $increaseBy;
break;
case 'cy':
@@ -184,11 +209,11 @@ final class ConfigurableNumberGenerator implements NumberGeneratorInterface
break;
case 'cname':
$partialResult = $this->model->getCustomer()->getName();
$partialResult = $this->model->getCustomer() !== null ? $this->model->getCustomer()->getName() : '';
break;
case 'cnumber':
$partialResult = $this->model->getCustomer()->getNumber();
$partialResult = $this->model->getCustomer() !== null ? $this->model->getCustomer()->getNumber() : '';
break;
default:

View File

@@ -54,7 +54,7 @@ class InvoiceRepository extends EntityRepository
return $counter > 0;
}
private function getCounterFor(\DateTime $start, \DateTime $end, ?Customer $customer = null): int
private function getCounterFor(\DateTime $start, \DateTime $end, ?Customer $customer = null, ?User $user = null): int
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('count(i.createdAt) as counter')
@@ -68,7 +68,14 @@ class InvoiceRepository extends EntityRepository
if (null !== $customer) {
$qb
->andWhere($qb->expr()->eq('i.customer', ':customer'))
->setParameter('customer', $customer)
->setParameter('customer', $customer->getId())
;
}
if (null !== $user) {
$qb
->andWhere($qb->expr()->eq('i.user', ':user'))
->setParameter('user', $user->getId())
;
}
@@ -81,34 +88,43 @@ class InvoiceRepository extends EntityRepository
return $result['counter'];
}
public function getCounterForDay(\DateTime $date, ?Customer $customer = null): int
public function getCounterForDay(\DateTime $date, ?Customer $customer = null, ?User $user = null): int
{
$start = (clone $date)->setTime(0, 0, 0);
$end = (clone $date)->setTime(23, 59, 59);
return $this->getCounterFor($start, $end, $customer);
return $this->getCounterFor($start, $end, $customer, $user);
}
public function getCounterForMonth(\DateTime $date, ?Customer $customer = null): int
public function getCounterForMonth(\DateTime $date, ?Customer $customer = null, ?User $user = null): int
{
$start = (clone $date)->setDate((int) $date->format('Y'), (int) $date->format('n'), 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate((int) $date->format('Y'), (int) $date->format('n'), (int) $date->format('t'))->setTime(23, 59, 59);
return $this->getCounterFor($start, $end, $customer);
return $this->getCounterFor($start, $end, $customer, $user);
}
public function getCounterForYear(\DateTime $date, ?Customer $customer = null): int
public function getCounterForYear(\DateTime $date, ?Customer $customer = null, ?User $user = null): int
{
$start = (clone $date)->setDate((int) $date->format('Y'), 1, 1)->setTime(0, 0, 0);
$end = (clone $date)->setDate((int) $date->format('Y'), 12, 31)->setTime(23, 59, 59);
return $this->getCounterFor($start, $end, $customer);
return $this->getCounterFor($start, $end, $customer, $user);
}
public function getCounterForAllTime(?Customer $customer = null): int
public function getCounterForCustomerAllTime(?Customer $customer = null): int
{
if (null !== $customer) {
return $this->count(['customer' => $customer]);
return $this->count(['customer' => $customer->getId()]);
}
return $this->count([]);
}
public function getCounterForUserAllTime(?User $user = null): int
{
if (null !== $user) {
return $this->count(['user' => $user->getId()]);
}
return $this->count([]);