} | } | ||||
} | } | ||||
/** | |||||
* 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(); |
<?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> |
], | ], | ||||
[ | [ | ||||
'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' | |||||
] | |||||
); | |||||
}, | |||||
], | ], | ||||
], | ], | ||||
], | ], |
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; |