|
|
@@ -3,7 +3,6 @@ |
|
|
|
namespace common\logic\Producer\Producer\Repository; |
|
|
|
|
|
|
|
use common\helpers\Departments; |
|
|
|
use common\helpers\GlobalParam; |
|
|
|
use common\helpers\Price; |
|
|
|
use common\logic\AbstractRepository; |
|
|
|
use common\logic\Document\Document\Model\DocumentInterface; |
|
|
@@ -119,6 +118,31 @@ class ProducerRepository extends AbstractRepository |
|
|
|
return $this->getTurnover($producer, $period, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getYearsWithTurnover(Producer $producer): array |
|
|
|
{ |
|
|
|
$year = date('Y'); |
|
|
|
$yearsArray = []; |
|
|
|
|
|
|
|
for($i = 0; $i <= 10; $i++) { |
|
|
|
if($this->hasTurnoverOverTheYear($producer, $year - $i)) { |
|
|
|
array_unshift($yearsArray, $year - $i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $yearsArray; |
|
|
|
} |
|
|
|
|
|
|
|
public function hasTurnoverOverTheYear(Producer $producer, int $year): bool |
|
|
|
{ |
|
|
|
for($month = 1; $month <= 12; $month++) { |
|
|
|
if($this->getTurnover($producer, $year.'-'.$month)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne le CA du producteur pour un mois donné |
|
|
|
*/ |
|
|
@@ -132,11 +156,10 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$command = $connection->createCommand( |
|
|
|
' |
|
|
|
SELECT SUM(product_order.price * product_order.quantity) AS turnover |
|
|
|
FROM `order`, product_order, distribution, product |
|
|
|
FROM `order`, product_order, distribution |
|
|
|
WHERE `order`.id = product_order.id_order |
|
|
|
AND distribution.id_producer = :id_producer |
|
|
|
AND `order`.id_distribution = distribution.id |
|
|
|
AND product_order.id_product = product.id |
|
|
|
AND distribution.date > :date_begin |
|
|
|
AND distribution.date < :date_end', |
|
|
|
[ |
|
|
@@ -160,7 +183,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
{ |
|
|
|
$totalTurnover = 0; |
|
|
|
|
|
|
|
for($i = 1; $i <= $numberMonths; $i++) { |
|
|
|
for ($i = 1; $i <= $numberMonths; $i++) { |
|
|
|
$timeMonth = strtotime('-' . $i . ' month'); |
|
|
|
$month = date('Y-m', $timeMonth); |
|
|
|
$totalTurnover += $this->getTurnover($producer, $month); |
|
|
@@ -175,6 +198,40 @@ class ProducerRepository extends AbstractRepository |
|
|
|
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getDatasChartTurnoverStatistics(Producer $producer, int $year) |
|
|
|
{ |
|
|
|
$interval = new \DateInterval('P1M'); |
|
|
|
$start = new \DateTime($year.'-01-01'); |
|
|
|
if($year == date('Y')) { |
|
|
|
$end = new \DateTime('last day of this month'); |
|
|
|
} |
|
|
|
else { |
|
|
|
$end = new \DateTime($year.'-12-31'); |
|
|
|
} |
|
|
|
$period = new \DatePeriod($start, $interval, $end); |
|
|
|
|
|
|
|
$data = []; |
|
|
|
$dataLabels = []; |
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
$month = $date->format('m/Y'); |
|
|
|
$dataLabels[] = $month; |
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m')); |
|
|
|
$data[$month] = $turnover; |
|
|
|
} |
|
|
|
|
|
|
|
// création d'un tableau sans index car chart.js n'accepte pas les index |
|
|
|
$dataNoIndex = []; |
|
|
|
foreach ($data as $key => $val) { |
|
|
|
$dataNoIndex[] = round($val, 2); |
|
|
|
} |
|
|
|
|
|
|
|
return [ |
|
|
|
'labels' => $dataLabels, |
|
|
|
'data' => $dataNoIndex |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function getSummaryAmountsToBeBilled(Producer $producer, string $label, int $numberOfMonths = 1, $context = 'list'): string |
|
|
|
{ |
|
|
|
$text = ''; |
|
|
@@ -192,14 +249,14 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$turnover = $this->getTurnover($producer, $month); |
|
|
|
|
|
|
|
if ($turnover) { |
|
|
|
if($numberOfMonths > 1) { |
|
|
|
$text .= ucfirst(strftime('%B ', $timeMonth)).' '.date('Y', $timeMonth).' : '; |
|
|
|
if ($numberOfMonths > 1) { |
|
|
|
$text .= ucfirst(strftime('%B ', $timeMonth)) . ' ' . date('Y', $timeMonth) . ' : '; |
|
|
|
} |
|
|
|
$isBold = $this->producerSolver->isBillingTypeClassic($producer) && !$producer->option_billing_permanent_transfer; |
|
|
|
if ($isBold) $text .= '<strong>'; |
|
|
|
$text .= $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, true); |
|
|
|
if ($isBold) $text .= '</strong>'; |
|
|
|
$text .= ' (' . Price::format($turnover, 0). ' CA)'; |
|
|
|
$text .= ' (' . Price::format($turnover, 0) . ' CA)'; |
|
|
|
$text .= '<br />'; |
|
|
|
|
|
|
|
$sumInvoicePrice += $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, false); |
|
|
@@ -207,12 +264,12 @@ class ProducerRepository extends AbstractRepository |
|
|
|
} |
|
|
|
|
|
|
|
if (strlen($text)) { |
|
|
|
$text = '<i>'.$label.'</i>' . ' : <br />' . $text; |
|
|
|
$text = '<i>' . $label . '</i>' . ' : <br />' . $text; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if($numberOfMonths > 1 && $sumInvoicePrice > 0) { |
|
|
|
$text .= '<br />Total : <strong>'.Price::format($sumInvoicePrice, 0).'</strong>'; |
|
|
|
if ($numberOfMonths > 1 && $sumInvoicePrice > 0) { |
|
|
|
$text .= '<br />Total : <strong>' . Price::format($sumInvoicePrice, 0) . '</strong>'; |
|
|
|
} |
|
|
|
|
|
|
|
return $text; |
|
|
@@ -273,9 +330,9 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$count = 0; |
|
|
|
$producersArray = $this->findProducersActive(); |
|
|
|
|
|
|
|
foreach($producersArray as $producer) { |
|
|
|
if($this->getTurnoverByNumberMonths($producer, 3)) { |
|
|
|
$count ++; |
|
|
|
foreach ($producersArray as $producer) { |
|
|
|
if ($this->getTurnoverByNumberMonths($producer, 3)) { |
|
|
|
$count++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -311,9 +368,9 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$producersWithTimeSavedArray = $this->findProducersWithTimeSaved(); |
|
|
|
$countProducersWithOptionTimeSaved = count($producersWithTimeSavedArray); |
|
|
|
|
|
|
|
if($countProducersWithOptionTimeSaved) { |
|
|
|
if ($countProducersWithOptionTimeSaved) { |
|
|
|
$sumTimeSaved = 0; |
|
|
|
foreach($producersWithTimeSavedArray as $producerWithTimeSaved) { |
|
|
|
foreach ($producersWithTimeSavedArray as $producerWithTimeSaved) { |
|
|
|
$sumTimeSaved += $producerWithTimeSaved->option_time_saved; |
|
|
|
} |
|
|
|
|