Browse Source

[Administration] Utilisateurs > import : gestion de l'email de bienvenue et groupes

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
93968e5845
6 changed files with 33 additions and 21 deletions
  1. +5
    -2
      backend/controllers/UserImportController.php
  2. +4
    -1
      backend/forms/UserImportUploadForm.php
  3. +12
    -10
      backend/views/distribution/index.php
  4. +1
    -0
      backend/views/user-import/index.php
  5. +7
    -5
      backend/web/js/backend.js
  6. +4
    -3
      common/logic/User/User/Service/UserBulkImporter.php

+ 5
- 2
backend/controllers/UserImportController.php View File

public function actionIndex() public function actionIndex()
{ {
$model = new UserImportUploadForm(); $model = new UserImportUploadForm();
if (\Yii::$app->request->isPost) {
if ($model->load(\Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model, 'file'); $model->file = UploadedFile::getInstance($model, 'file');
if($model->file && $model->validate()) { if($model->file && $model->validate()) {
try { try {
$this->getUserModule()->getBulkImporter()->import($model->file->tempName);
$this->getUserModule()->getBulkImporter()->import(
$model->file->tempName,
(bool) $model->send_mail_welcome
);
$this->setFlash('success', "Fichier importé."); $this->setFlash('success', "Fichier importé.");
} }
catch(ErrorException $exception) { catch(ErrorException $exception) {

+ 4
- 1
backend/forms/UserImportUploadForm.php View File

* @var UploadedFile file attribute * @var UploadedFile file attribute
*/ */
public $file; public $file;
public $send_mail_welcome;


/** /**
* @return array the validation rules. * @return array the validation rules.
{ {
return [ return [
[['file'], 'file', 'skipOnEmpty' => false, 'mimeTypes' => 'text/csv, text/plain'], [['file'], 'file', 'skipOnEmpty' => false, 'mimeTypes' => 'text/csv, text/plain'],
[['send_mail_welcome'], 'boolean']
]; ];
} }


public function attributeLabels() public function attributeLabels()
{ {
return [ return [
'file' => "Fichier d'import (CSV)"
'file' => "Fichier d'import (CSV)",
'send_mail_welcome' => "Envoyer un email de bienvenue aux utilisateurs importés"
]; ];
} }
} }

+ 12
- 10
backend/views/distribution/index.php View File

</div> </div>
</td> </td>
<td class="column-state-payment"> <td class="column-state-payment">
<a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">
<order-state-payment :order="order" :producer="producer"></order-state-payment>
</a>
<span class="glyphicon glyphicon-time" title="Débit automatique du crédit la veille de la distribution" v-if="order.amount != 0 && order.isCreditAutoPayment && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span>
<template v-if="!order.date_delete">
<a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">
<order-state-payment :order="order" :producer="producer"></order-state-payment>
</a>
<span class="glyphicon glyphicon-time" title="Débit automatique du crédit la veille de la distribution" v-if="order.amount != 0 && order.isCreditAutoPayment && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span>


<div v-if="order.amount_paid > 0 && order.amount_paid < order.amount">
<span class="glyphicon glyphicon-alert"></span> Reste à payer
</div>
<div v-if="order.amount_paid > order.amount">
<span class="glyphicon glyphicon-alert"></span> Surplus à rembourser
</div>
<div v-if="order.amount_paid > 0 && order.amount_paid < order.amount">
<span class="glyphicon glyphicon-alert"></span> Reste à payer
</div>
<div v-if="order.amount_paid > order.amount">
<span class="glyphicon glyphicon-alert"></span> Surplus à rembourser
</div>
</template>
</td> </td>
<td class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)"> <td class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)">
<template v-if="order.isCreditContext"> <template v-if="order.isCreditContext">

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

]); ?> ]); ?>


<?= $form->field($model, 'file')->fileInput() ?> <?= $form->field($model, 'file')->fileInput() ?>
<?= $form->field($model, 'send_mail_welcome')->checkbox() ?>


<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary']) ?> <?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary']) ?>

+ 7
- 5
backend/web/js/backend.js View File

}; };


function opendistrib_user_form() { function opendistrib_user_form() {
var $fieldUserEmail = $('#app-user-form .field-user-email input');
var $fieldSendMailWelcome = $('#app-user-form .field-user-send_mail_welcome');
if($('#app-user-form').length) {
var $fieldUserEmail = $('#app-user-form .field-user-email input');
var $fieldSendMailWelcome = $('#app-user-form .field-user-send_mail_welcome');


opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
$fieldUserEmail.keyup(function () {
opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome); opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
});
$fieldUserEmail.keyup(function () {
opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
});
}
} }


function opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome) { function opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome) {

+ 4
- 3
common/logic/User/User/Service/UserBulkImporter.php View File

/** /**
* @throws ErrorException * @throws ErrorException
*/ */
public function import(string $fileName): void
public function import(string $fileName, bool $sendMailWelcome = true): void
{ {
$usersArray = $this->loadCsv($fileName); $usersArray = $this->loadCsv($fileName);


$userData[self::PHONE], $userData[self::PHONE],
$userData[self::ADDRESS], $userData[self::ADDRESS],
$userData[self::NEWSLETTER], $userData[self::NEWSLETTER],
Password::generate()
Password::generate(),
$sendMailWelcome
); );
} }
} }
{ {
$usersArray = CSV::csv2array($fileName); $usersArray = CSV::csv2array($fileName);


if(count($usersArray) && count($usersArray[0]) != 6) {
if(count($usersArray) && count($usersArray[0]) != 8) {
throw new ErrorException("Le fichier n'a pas le bon nombre de colonnes. throw new ErrorException("Le fichier n'a pas le bon nombre de colonnes.
Veuillez vous baser sur le fichier d'exemple téléchargeable ci-dessous."); Veuillez vous baser sur le fichier d'exemple téléchargeable ci-dessous.");
} }

Loading…
Cancel
Save