@@ -99,14 +99,14 @@ class ProducerAdminController extends BackendController | |||
$producersArray = Producer::find()->where('active = 1')->all(); | |||
$sumFreePrice = 0 ; | |||
$sumPrices = 0; | |||
foreach($producersArray as $producer) { | |||
$sumFreePrice += $producer->free_price ; | |||
$sumPrices += $producer->getAmountBilledLastMonth(); | |||
} | |||
return $this->render('index', [ | |||
'dataProviderProducer' => $dataProviderProducer, | |||
'sumFreePrice' => $sumFreePrice | |||
'sumPrices' => $sumPrices | |||
]); | |||
} | |||
@@ -49,28 +49,48 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico | |||
?> | |||
<div class="alert alert-info"> | |||
Abonnements mensuels : <strong><?= $sumFreePrice ?> € HT</strong> | |||
Facturé le mois dernier : <strong><?= $sumPrices ?> €</strong><br /> | |||
</div> | |||
<?= GridView::widget([ | |||
'dataProvider' => $dataProviderProducer, | |||
'columns' => [ | |||
'name', | |||
[ | |||
'attribute' => 'active', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
$html = '' ; | |||
if($model->active) { | |||
$html .= '<span class="label label-success">En ligne</span>' ; | |||
} | |||
else { | |||
$html .= '<span class="label label-danger">Hors-ligne</span>' ; | |||
} | |||
if(strlen($model->code)) | |||
{ | |||
$html .= ' <span class="glyphicon glyphicon-lock" data-toggle="tooltip" data-placement="bottom" data-original-title="'.Html::encode($model->code).'"></span>' ; | |||
} | |||
return $html ; | |||
} | |||
], | |||
'name', | |||
/*[ | |||
'attribute' => 'date_creation', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
return date('d/m/Y', strtotime($model->date_creation)) ; | |||
} | |||
], | |||
[ | |||
],*/ | |||
/*[ | |||
'attribute' => 'Lieu', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
return Html::encode($model->city.' ('.$model->postcode.')') ; | |||
} | |||
], | |||
[ | |||
],*/ | |||
/*[ | |||
'attribute' => 'Utilisateurs', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
@@ -87,7 +107,7 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico | |||
} | |||
} | |||
], | |||
],*/ | |||
[ | |||
'attribute' => 'Contact', | |||
'format' => 'raw', | |||
@@ -111,63 +131,60 @@ $this->addButton(['label' => 'Nouveau producteur <span class="glyphicon glyphico | |||
} | |||
], | |||
[ | |||
'attribute' => 'active', | |||
'attribute' => 'Prix libre', | |||
'label' => 'Prix libre', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
$html = '' ; | |||
if($model->active) { | |||
$html .= '<span class="label label-success">En ligne</span>' ; | |||
if(is_null($model->free_price)) { | |||
return '' ; | |||
} | |||
else { | |||
$html .= '<span class="label label-danger">Hors-ligne</span>' ; | |||
} | |||
if(strlen($model->code)) | |||
{ | |||
$html .= ' <span class="glyphicon glyphicon-lock" data-toggle="tooltip" data-placement="bottom" data-original-title="'.Html::encode($model->code).'"></span>' ; | |||
$str = ''; | |||
if($model->isBillingTypeFreePrice()) { | |||
$str .= '<strong>'; | |||
} | |||
$str .= $model->getFreePrice(); | |||
if($model->isBillingTypeFreePrice()) { | |||
$str .= '</strong>'; | |||
} | |||
return $str; | |||
} | |||
return $html ; | |||
} | |||
], | |||
[ | |||
'attribute' => 'Prix libre', | |||
'label' => 'Prix libre', | |||
'attribute' => 'À facturer / chiffre d\'affaire', | |||
'label' => 'À facturer / chiffre d\'affaire', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
if(is_null($model->free_price)) { | |||
return '' ; | |||
if($model->isBillingFrequencyMonthly()) { | |||
return $model->getSummaryAmountsToBeBilled('Mois dernier', 1); | |||
} | |||
else { | |||
return $model->getFreePrice() ; | |||
elseif($model->isBillingFrequencyQuarterly()) { | |||
return $model->getSummaryAmountsToBeBilled('3 derniers mois', 3); | |||
} | |||
elseif($model->isBillingFrequencyBiannual()) { | |||
return $model->getSummaryAmountsToBeBilled('6 derniers mois', 6); | |||
} | |||
} | |||
], | |||
[ | |||
'label' => 'Dons (mois précédent)', | |||
'attribute' => 'Facturation', | |||
'label' => 'Détails facturation', | |||
'format' => 'raw', | |||
'value' => function($model) { | |||
$productGift = Product::getProductGift() ; | |||
$res = Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total | |||
FROM `order`, product_order, distribution | |||
WHERE distribution.id_producer = :id_producer | |||
AND `order`.id_distribution = distribution.id | |||
AND `order`.id = product_order.id_order | |||
AND distribution.date >= :date_start | |||
AND distribution.date <= :date_end | |||
AND product_order.id_product = :id_product_gift | |||
") | |||
->bindValue(':id_producer', $model->id) | |||
->bindValue(':date_start', date('Y-m-01', strtotime("-1 month"))) | |||
->bindValue(':date_end', date('Y-m-31', strtotime("-1 month"))) | |||
->bindValue(':id_product_gift', $productGift->id) | |||
->queryOne(); | |||
return Price::format($res['total']) ; | |||
$str = ''; | |||
$str .= '- '.Producer::$billingTypeArray[$model->option_billing_type].'<br />'; | |||
$str .= '- '.Producer::$billingFrequencyArray[$model->option_billing_frequency]; | |||
if($model->option_billing_reduction) { | |||
$str .= '<br />- <u>Avec réduction</u>'; | |||
} | |||
return $str; | |||
} | |||
], | |||
] | |||
], | |||
]); ?> |
@@ -472,8 +472,15 @@ $this->addBreadcrumb($this->getTitle()) ; | |||
<h3 class="panel-title">Administration</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<?= $form->field($model, 'option_billing_type') | |||
->dropDownList(Producer::getBillingTypePopulateDropdown()); ?> | |||
<?= $form->field($model, 'option_billing_frequency') | |||
->dropDownList(Producer::getBillingFrequencyPopulateDropdown()); ?> | |||
<?= $form->field($model, 'option_billing_reduction') | |||
->dropDownList([ | |||
0 => 'Non', | |||
1 => 'Oui' | |||
]); ?> | |||
</div> | |||
</div> | |||
<?php endif; ?> |
@@ -102,6 +102,20 @@ class Producer extends ActiveRecordCommon | |||
const BILLING_FREQUENCY_QUARTERLY = 'quarterly'; | |||
const BILLING_FREQUENCY_BIANNUAL = 'biannual'; | |||
public static $billingFrequencyArray = [ | |||
self::BILLING_FREQUENCY_MONTHLY => 'Mensuelle', | |||
self::BILLING_FREQUENCY_QUARTERLY => 'Trimestrielle', | |||
self::BILLING_FREQUENCY_BIANNUAL => 'Biannuelle', | |||
]; | |||
const BILLING_TYPE_CLASSIC = 'classic'; | |||
const BILLING_TYPE_FREE_PRICE = 'free-price'; | |||
public static $billingTypeArray = [ | |||
self::BILLING_TYPE_CLASSIC => 'Classique', | |||
self::BILLING_TYPE_FREE_PRICE => 'Prix libre', | |||
]; | |||
var $secret_key_payplug; | |||
/** | |||
@@ -236,7 +250,8 @@ class Producer extends ActiveRecordCommon | |||
'option_delivery', | |||
'option_display_export_grid', | |||
'option_stripe_mode_test', | |||
'option_notify_producer_order_summary' | |||
'option_notify_producer_order_summary', | |||
'option_billing_reduction' | |||
], | |||
'boolean' | |||
], | |||
@@ -258,6 +273,7 @@ class Producer extends ActiveRecordCommon | |||
'document_invoice_first_reference', | |||
'document_delivery_note_prefix', | |||
'document_delivery_note_first_reference', | |||
'option_billing_type', | |||
'option_billing_frequency', | |||
], | |||
'string', | |||
@@ -368,7 +384,9 @@ class Producer extends ActiveRecordCommon | |||
'option_display_export_grid' => 'Afficher l\'export grille dans les distributions', | |||
'document_display_product_description' => 'Documents : afficher la description des produits', | |||
'option_notify_producer_order_summary' => 'Recevoir les récapitulatifs de commande par email', | |||
'option_billing_frequency' => 'Fréquence de facturation' | |||
'option_billing_type' => 'Type de facturation', | |||
'option_billing_frequency' => 'Fréquence de facturation', | |||
'option_billing_reduction' => 'Réduction appliquée au moment de la facturation' | |||
]; | |||
} | |||
@@ -496,6 +514,82 @@ class Producer extends ActiveRecordCommon | |||
} | |||
} | |||
public function getAmountToBeBilledByTurnover($turnover, $format = false) | |||
{ | |||
$amountToBeBilled = 0; | |||
$producerPriceRangeArray = ProducerPriceRange::find()->all(); | |||
foreach($producerPriceRangeArray as $priceRange) { | |||
if($turnover >= $priceRange->range_begin && $turnover < $priceRange->range_end) { | |||
$amountToBeBilled = $priceRange->price; | |||
} | |||
} | |||
if($format) { | |||
return Price::format($amountToBeBilled); | |||
} | |||
else { | |||
return $amountToBeBilled; | |||
} | |||
} | |||
public function getAmountToBeBilledByMonth($month, $format = false) | |||
{ | |||
$turnover = $this->getTurnover($month); | |||
return $this->getAmountToBeBilledByTurnover($turnover, $format); | |||
} | |||
public function getSummaryAmountsToBeBilled($label, $numberOfMonths = 1) | |||
{ | |||
$text = ''; | |||
$numMonthCurrent = date('m'); | |||
if($numberOfMonths == 1 | |||
|| ($numberOfMonths == 3 && (in_array($numMonthCurrent, [1, 4, 7, 10]))) | |||
|| ($numberOfMonths == 6 && (in_array($numMonthCurrent, [1, 7])))) { | |||
for ($i = 1; $i <= $numberOfMonths; $i++) { | |||
$month = date('Y-m', strtotime('-' . $i . ' month')); | |||
$turnover = $this->getTurnover($month); | |||
if ($turnover) { | |||
if ($this->isBillingTypeClassic()) { | |||
$text .= '<strong>'; | |||
} | |||
$text .= $this->getAmountToBeBilledByTurnover($turnover, true); | |||
if ($this->isBillingTypeClassic()) { | |||
$text .= '</strong>'; | |||
} | |||
$text .= ' / '.Price::format($turnover); | |||
$text .= '<br />'; | |||
} | |||
} | |||
if (strlen($text)) { | |||
$text = $label . ' : <br />' . $text; | |||
} | |||
} | |||
return $text; | |||
} | |||
public function getAmountBilledLastMonth() | |||
{ | |||
if($this->isBillingTypeClassic()) { | |||
$month = date('Y-m', strtotime('-1 month')); | |||
return $this->getAmountToBeBilledByMonth($month); | |||
} | |||
elseif($this->isBillingTypeFreePrice()) { | |||
return $this->free_price; | |||
} | |||
return 0; | |||
} | |||
/** | |||
* Retourne le montant à facturer pour une période donnée. | |||
* | |||
@@ -577,7 +671,7 @@ class Producer extends ActiveRecordCommon | |||
{ | |||
if (!is_null($this->free_price)) { | |||
if ($format) { | |||
return number_format($this->free_price, 2, ',', false) . ' € HT'; | |||
return number_format($this->free_price, 2, ',', false) . ' €'; | |||
} else { | |||
return $this->free_price; | |||
} | |||
@@ -839,11 +933,37 @@ class Producer extends ActiveRecordCommon | |||
public static function getBillingFrequencyPopulateDropdown() | |||
{ | |||
return [ | |||
self::BILLING_FREQUENCY_MONTHLY => 'Mensuelle', | |||
self::BILLING_FREQUENCY_QUARTERLY => 'Trimestrielle', | |||
self::BILLING_FREQUENCY_BIANNUAL => 'Biannuelle', | |||
]; | |||
return self::$billingFrequencyArray; | |||
} | |||
public function isBillingFrequencyMonthly() | |||
{ | |||
return $this->option_billing_frequency == self::BILLING_FREQUENCY_MONTHLY; | |||
} | |||
public function isBillingFrequencyQuarterly() | |||
{ | |||
return $this->option_billing_frequency == self::BILLING_FREQUENCY_QUARTERLY; | |||
} | |||
public function isBillingFrequencyBiannual() | |||
{ | |||
return $this->option_billing_frequency == self::BILLING_FREQUENCY_BIANNUAL; | |||
} | |||
public static function getBillingTypePopulateDropdown() | |||
{ | |||
return self::$billingTypeArray; | |||
} | |||
public function isBillingTypeClassic() | |||
{ | |||
return $this->option_billing_type == self::BILLING_TYPE_CLASSIC; | |||
} | |||
public function isBillingTypeFreePrice() | |||
{ | |||
return $this->option_billing_type == self::BILLING_TYPE_FREE_PRICE; | |||
} | |||
} | |||
@@ -0,0 +1,29 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\Schema; | |||
use common\models\Producer; | |||
/** | |||
* Class m220915_083713_producer_add_options_billing | |||
*/ | |||
class m220915_083713_producer_add_options_billing extends Migration | |||
{ | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeUp() | |||
{ | |||
$this->addColumn('producer', 'option_billing_type', Schema::TYPE_STRING.' DEFAULT \''.Producer::BILLING_TYPE_CLASSIC.'\''); | |||
$this->addColumn('producer', 'option_billing_reduction', Schema::TYPE_BOOLEAN.' DEFAULT 0'); | |||
} | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function safeDown() | |||
{ | |||
$this->dropColumn('producer','option_billing_type'); | |||
$this->dropColumn('producer','option_billing_reduction'); | |||
} | |||
} |