@@ -142,6 +142,19 @@ class ProducerAdminController extends BackendController | |||
} | |||
} | |||
/** | |||
* 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) | |||
{ | |||
$producerManager = $this->getProducerManager(); |
@@ -1,6 +1,6 @@ | |||
<?php | |||
/** | |||
/** | |||
Copyright distrib (2018) | |||
contact@opendistrib.net | |||
@@ -34,56 +34,17 @@ sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||
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 | |||
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> |
@@ -202,7 +202,7 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico | |||
], | |||
[ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{update}', | |||
'template' => '{update} {billing}', | |||
'headerOptions' => ['class' => 'column-actions'], | |||
'contentOptions' => ['class' => 'column-actions'], | |||
'buttons' => [ | |||
@@ -216,6 +216,16 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico | |||
] | |||
); | |||
}, | |||
'billing' => function ($url, $model) { | |||
return Html::a( | |||
'<span class="glyphicon glyphicon-euro"></span>', | |||
$url, | |||
[ | |||
'title' => 'Facturation', | |||
'class' => 'btn btn-default' | |||
] | |||
); | |||
}, | |||
], | |||
], | |||
], |
@@ -155,33 +155,44 @@ class ProducerRepository extends AbstractRepository | |||
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 = ''; | |||
$numMonthCurrent = date('m'); | |||
$sumInvoicePrice = 0; | |||
if ($numberOfMonths == 1 | |||
|| ($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++) { | |||
$month = date('Y-m', strtotime('-' . $i . ' month')); | |||
$timeMonth = strtotime('-' . $i . ' month'); | |||
$month = date('Y-m', $timeMonth); | |||
$turnover = $this->getTurnover($producer, $month); | |||
if ($turnover) { | |||
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); | |||
$text .= '<br />'; | |||
$sumInvoicePrice += $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, false); | |||
} | |||
} | |||
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; |