Browse Source

[Administration] Producteurs > virement permanent : vue avec 6 et 12 derniers mois #812

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
d87a1c7629
4 changed files with 49 additions and 54 deletions
  1. +13
    -0
      backend/controllers/ProducerAdminController.php
  2. +10
    -49
      backend/views/producer-admin/billing.php
  3. +11
    -1
      backend/views/producer-admin/index.php
  4. +15
    -4
      common/logic/Producer/Producer/Repository/ProducerRepository.php

+ 13
- 0
backend/controllers/ProducerAdminController.php View File

} }
} }


/**
* Facturation producteur.
*/
public function actionBilling(int $id)
{
$producerManager = $this->getProducerManager();
$producer = $this->findModel($id);

return $this->render('billing', [
'producer' => $producer,
]);
}

public function actionUserTransfer($fromProducerId, $toProducerId, $withOrders = 1) public function actionUserTransfer($fromProducerId, $toProducerId, $withOrders = 1)
{ {
$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();

+ 10
- 49
backend/views/producer-admin/billing.php View File

<?php <?php


/**
/**
Copyright distrib (2018) Copyright distrib (2018)


contact@opendistrib.net contact@opendistrib.net
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
pris connaissance de la licence CeCILL, et que vous en avez accepté les pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes. termes.
*/
*/


use yii\helpers\Html;
use yii\grid\GridView;
use common\models\ User ;
use common\models\Etablissement ;
use common\logic\Producer\Producer\Wrapper\ProducerManager;


$this->title = 'Facturation';
$this->params['breadcrumbs'][] = 'Administration' ;
$this->params['breadcrumbs'][] = $this->title;
$this->setTitle('Facturation producteur ('.$producer->name.')') ;
$this->addBreadcrumb(['label' => 'Producteurs', 'url' => ['index']]) ;
$this->addBreadcrumb('Facturation') ;


$producerManager = ProducerManager::getInstance();
?> ?>


<h1>Facturation</h1>

<?= GridView::widget([
'dataProvider' => $datas_factures,
'columns' => [
[
'attribute' => 'reference',
'label' => 'Référence',
],
[
'attribute' => 'id_producer',
'label' => 'Producteur',
'value' => function($model) {
return Html::encode($model->producer->name) ;
}
],
'libelle',
[
'attribute' => 'amount_ht',
'label' => 'Montant',
'value' => function($model) {
return number_format($model->amount_ht,2).' €' ;
}
],
[
'attribute' => 'paid',
'label' => 'Payé',
'format' => 'raw',
'value' => function($model) {
if($model->paid)
{
return '<span class="label label-success">Oui</span>' ;
}
else {
return '<span class="label label-danger">Non</span>' ;
}
}
]
],
]); ?>
<div class="producer-billing">
<?= $producerManager->getSummaryAmountsToBeBilled($producer, '12 derniers mois', 12, 'billing'); ?>
</div>

+ 11
- 1
backend/views/producer-admin/index.php View File

], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update}',
'template' => '{update} {billing}',
'headerOptions' => ['class' => 'column-actions'], 'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'], 'contentOptions' => ['class' => 'column-actions'],
'buttons' => [ 'buttons' => [
] ]
); );
}, },
'billing' => function ($url, $model) {
return Html::a(
'<span class="glyphicon glyphicon-euro"></span>',
$url,
[
'title' => 'Facturation',
'class' => 'btn btn-default'
]
);
},
], ],
], ],
], ],

+ 15
- 4
common/logic/Producer/Producer/Repository/ProducerRepository.php View File

return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format);
} }


public function getSummaryAmountsToBeBilled(Producer $producer, string $label, int $numberOfMonths = 1): string
public function getSummaryAmountsToBeBilled(Producer $producer, string $label, int $numberOfMonths = 1, $context = 'list'): string
{ {
$text = ''; $text = '';
$numMonthCurrent = date('m'); $numMonthCurrent = date('m');
$sumInvoicePrice = 0;


if ($numberOfMonths == 1 if ($numberOfMonths == 1
|| ($numberOfMonths == 3 && (in_array($numMonthCurrent, [1, 4, 7, 10]))) || ($numberOfMonths == 3 && (in_array($numMonthCurrent, [1, 4, 7, 10])))
|| ($numberOfMonths == 6 && (in_array($numMonthCurrent, [1, 7])))) {
|| ($numberOfMonths == 6 && (in_array($numMonthCurrent, [1, 7])))
|| $context == 'billing') {


for ($i = 1; $i <= $numberOfMonths; $i++) { for ($i = 1; $i <= $numberOfMonths; $i++) {
$month = date('Y-m', strtotime('-' . $i . ' month'));
$timeMonth = strtotime('-' . $i . ' month');
$month = date('Y-m', $timeMonth);
$turnover = $this->getTurnover($producer, $month); $turnover = $this->getTurnover($producer, $month);


if ($turnover) { if ($turnover) {
if($numberOfMonths > 1) {
$text .= ucfirst(strftime('%B ', $timeMonth)).' '.date('Y', $timeMonth).' : ';
}
$isBold = $this->producerSolver->isBillingTypeClassic($producer) && !$producer->option_billing_permanent_transfer; $isBold = $this->producerSolver->isBillingTypeClassic($producer) && !$producer->option_billing_permanent_transfer;
if ($isBold) $text .= '<strong>'; if ($isBold) $text .= '<strong>';
$text .= $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, true); $text .= $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, true);
if ($isBold) $text .= '</strong>'; if ($isBold) $text .= '</strong>';
$text .= ' / ' . Price::format($turnover, 0); $text .= ' / ' . Price::format($turnover, 0);
$text .= '<br />'; $text .= '<br />';

$sumInvoicePrice += $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, false);
} }
} }


if (strlen($text)) { if (strlen($text)) {
$text = $label . ' : <br />' . $text;
$text = '<i>'.$label.'</i>' . ' : <br />' . $text;
} }
}


if($numberOfMonths > 1) {
$text .= '<br />Total : <strong>'.Price::format($sumInvoicePrice, 0).'</strong>';
} }


return $text; return $text;

Loading…
Cancel
Save