Browse Source

[Administration] Distributions : activation automatique de X semaines à l'avance #1187

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
1ea8502b4e
9 changed files with 79 additions and 10 deletions
  1. +5
    -5
      backend/controllers/OrderController.php
  2. +0
    -1
      backend/views/distribution/index.php
  3. +9
    -0
      backend/views/producer/update.php
  4. +1
    -1
      backend/web/js/vuejs/distribution-index.js
  5. +6
    -1
      common/logic/Distribution/Distribution/Service/DistributionBuilder.php
  6. +3
    -1
      common/logic/Producer/Producer/Model/Producer.php
  7. +1
    -1
      common/logic/Producer/Producer/Repository/ProducerRepository.php
  8. +28
    -0
      console/commands/ActiveDistributionsInAdvanceController.php
  9. +26
    -0
      console/migrations/m230908_085432_add_column_producer_option_weeks_distributions_activated_in_advance.php

+ 5
- 5
backend/controllers/OrderController.php View File



if (abs($order->amount - $amountPaid) < 0.0001) { if (abs($order->amount - $amountPaid) < 0.0001) {
$html .= '<span class="label label-success">Payé</span>'; $html .= '<span class="label label-success">Payé</span>';
$buttonsCredit = Html::a('Rembourser ' . $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']);
$buttonsCredit = Html::a('Recréditer ' . $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $order->amount, 'data-type' => 'refund']);
} elseif ($order->amount > $amountPaid) { } elseif ($order->amount > $amountPaid) {
$amountToPay = $order->amount - $amountPaid; $amountToPay = $order->amount - $amountPaid;
$html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($amountToPay, 2) . ' €</strong> à payer';
$buttonsCredit = Html::a('Payer ' . number_format($amountToPay, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs payer', 'data-montant' => $amountToPay, 'data-type' => 'payment']);
$html .= '<span class="label label-danger">Non payé</span> reste <strong>' . number_format($amountToPay, 2) . ' €</strong> à débiter';
$buttonsCredit = Html::a('Débiter ' . number_format($amountToPay, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs payer', 'data-montant' => $amountToPay, 'data-type' => 'payment']);
} elseif ($order->amount < $amountPaid) { } elseif ($order->amount < $amountPaid) {
$amountToRefund = $amountPaid - $order->amount; $amountToRefund = $amountPaid - $order->amount;
$html .= ' <span class="label label-success">Payé</span> <strong>' . number_format($amountToRefund, 2) . ' €</strong> à rembourser';
$buttonsCredit = Html::a('Rembourser ' . number_format($amountToRefund, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $amountToRefund, 'data-type' => 'refund']);
$html .= ' <span class="label label-success">Payé</span> <strong>' . number_format($amountToRefund, 2) . ' €</strong> à recréditer';
$buttonsCredit = Html::a('Recréditer ' . number_format($amountToRefund, 2) . ' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser', 'data-montant' => $amountToRefund, 'data-type' => 'refund']);
} }


$html .= '<span class="buttons-credit">' $html .= '<span class="buttons-credit">'

+ 0
- 1
backend/views/distribution/index.php View File

</div> </div>


<div class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0"> <div class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0">
{{ distribution }}
Attention, ce jour de distribution n'est pas activé et vous avez quand même des commandes enregistrées. Attention, ce jour de distribution n'est pas activé et vous avez quand même des commandes enregistrées.
</div> </div>



+ 9
- 0
backend/views/producer/update.php View File

], []); ?> ], []); ?>


<h4>Divers</h4> <h4>Divers</h4>
<?php
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
for($i = 1; $i < 13; $i++) {
$choicesWeeksDistributionsActivatedInAdvanceArray[$i] = $i.' semaine'.(($i > 1) ? 's' : '');
}
?>
<?= $form->field($model, 'option_weeks_distributions_activated_in_advance')
->dropDownList($choicesWeeksDistributionsActivatedInAdvanceArray)
->hint("Attention, les premières semaines doivent être activées manuellement."); ?>
<?= $form->field($model, 'option_order_reference_type') <?= $form->field($model, 'option_order_reference_type')
->dropDownList([ ->dropDownList([
Producer::ORDER_REFERENCE_TYPE_NONE => '--', Producer::ORDER_REFERENCE_TYPE_NONE => '--',

+ 1
- 1
backend/web/js/vuejs/distribution-index.js View File

); );
appAlerts.alert( appAlerts.alert(
'info', 'info',
'Pensez à bien rembourser les clients qui auraient passé commande en utilisant leur crédit.',
'Pensez à bien recréditer les clients qui auraient passé commande en utilisant leur crédit.',
6000 6000
); );
} else { } else {

+ 6
- 1
common/logic/Distribution/Distribution/Service/DistributionBuilder.php View File

/** /**
* Active ou désactive la distribution. * Active ou désactive la distribution.
*/ */
// active
public function activeDistribution(Distribution $distribution, bool $active = true): void public function activeDistribution(Distribution $distribution, bool $active = true): void
{ {
$distribution->active = (int) $active; $distribution->active = (int) $active;
$distribution->trigger(Distribution::EVENT_ACTIVE, $distributionActiveEvent); $distribution->trigger(Distribution::EVENT_ACTIVE, $distributionActiveEvent);
} }
} }

public function activeDistributionByDate(\DateTime $date): void
{
$distribution = $this->createDistributionIfNotExist($date->format('Y-m-d'));
$this->activeDistribution($distribution);
}
} }

+ 3
- 1
common/logic/Producer/Producer/Model/Producer.php View File

'option_document_price_decimals', 'option_document_price_decimals',
'option_billing_reduction_percentage', 'option_billing_reduction_percentage',
'dolibarr_socid', 'dolibarr_socid',
'dolibarr_product_id'
'dolibarr_product_id',
'option_weeks_distributions_activated_in_advance'
], ],
'integer' 'integer'
], ],
'dolibarr_socid' => 'Dolibarr : id user', 'dolibarr_socid' => 'Dolibarr : id user',
'dolibarr_product_id' => 'Dolibarr : id produit', 'dolibarr_product_id' => 'Dolibarr : id produit',
'option_export_display_column_delivery_note' => "Récapitulatif PDF : afficher une colonne bon de livraison", 'option_export_display_column_delivery_note' => "Récapitulatif PDF : afficher une colonne bon de livraison",
'option_weeks_distributions_activated_in_advance' => "Semaines de distributions à activer à l'avance",
]; ];
} }



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

{ {
if (strlen($config)) { if (strlen($config)) {
if (!$idProducer) { if (!$idProducer) {
$idProducer = GlobalParam::getCurrentProducerId();
$idProducer = $this->getProducerContextId();
} }


$producer = $this->findOneProducerById($idProducer); $producer = $this->findOneProducerById($idProducer);

+ 28
- 0
console/commands/ActiveDistributionsInAdvanceController.php View File

<?php

namespace console\commands;

use common\logic\Distribution\Distribution\Wrapper\DistributionManager;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use yii\console\Controller;

class ActiveDistributionsInAdvanceController extends Controller
{
public function actionIndex()
{
$producerManager = ProducerManager::getInstance();
$distributionManager = DistributionManager::getInstance();

$producersArray = $producerManager->findProducersActive();
foreach($producersArray as $producer) {
\Yii::$app->logic->setProducerContext($producer);
$weeksDistributionsActivatedInAdvance = $producerManager->getConfig('option_weeks_distributions_activated_in_advance');
if($weeksDistributionsActivatedInAdvance) {
$date = new \DateTime('+'.$weeksDistributionsActivatedInAdvance.' weeks');
$distributionManager->activeDistributionByDate($date);
}
}
}
}

?>

+ 26
- 0
console/migrations/m230908_085432_add_column_producer_option_weeks_distributions_activated_in_advance.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m230908_085432_add_column_producer_option_weeks_distributions_activated_in_advance
*/
class m230908_085432_add_column_producer_option_weeks_distributions_activated_in_advance extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'option_weeks_distributions_activated_in_advance', Schema::TYPE_INTEGER);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'option_weeks_distributions_activated_in_advance');
}
}

Loading…
Cancel
Save