@@ -68,11 +68,14 @@ class UserImportController extends BackendController | |||
public function actionIndex() | |||
{ | |||
$model = new UserImportUploadForm(); | |||
if (\Yii::$app->request->isPost) { | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$model->file = UploadedFile::getInstance($model, 'file'); | |||
if($model->file && $model->validate()) { | |||
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é."); | |||
} | |||
catch(ErrorException $exception) { |
@@ -11,6 +11,7 @@ class UserImportUploadForm extends Model | |||
* @var UploadedFile file attribute | |||
*/ | |||
public $file; | |||
public $send_mail_welcome; | |||
/** | |||
* @return array the validation rules. | |||
@@ -19,13 +20,15 @@ class UserImportUploadForm extends Model | |||
{ | |||
return [ | |||
[['file'], 'file', 'skipOnEmpty' => false, 'mimeTypes' => 'text/csv, text/plain'], | |||
[['send_mail_welcome'], 'boolean'] | |||
]; | |||
} | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'file' => "Fichier d'import (CSV)" | |||
'file' => "Fichier d'import (CSV)", | |||
'send_mail_welcome' => "Envoyer un email de bienvenue aux utilisateurs importés" | |||
]; | |||
} | |||
} |
@@ -396,17 +396,19 @@ $this->setPageTitle('Distributions') ; | |||
</div> | |||
</td> | |||
<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 class="column-credit" v-if="!idActivePointSale || (pointSaleActive && pointSaleActive.credit == 1)"> | |||
<template v-if="order.isCreditContext"> |
@@ -56,6 +56,7 @@ $this->addBreadcrumb($this->getTitle()); | |||
]); ?> | |||
<?= $form->field($model, 'file')->fileInput() ?> | |||
<?= $form->field($model, 'send_mail_welcome')->checkbox() ?> | |||
<div class="form-group"> | |||
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary']) ?> |
@@ -67,13 +67,15 @@ var UrlManager = { | |||
}; | |||
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); | |||
}); | |||
$fieldUserEmail.keyup(function () { | |||
opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome); | |||
}); | |||
} | |||
} | |||
function opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome) { |
@@ -30,7 +30,7 @@ class UserBulkImporter extends AbstractManager | |||
/** | |||
* @throws ErrorException | |||
*/ | |||
public function import(string $fileName): void | |||
public function import(string $fileName, bool $sendMailWelcome = true): void | |||
{ | |||
$usersArray = $this->loadCsv($fileName); | |||
@@ -44,7 +44,8 @@ class UserBulkImporter extends AbstractManager | |||
$userData[self::PHONE], | |||
$userData[self::ADDRESS], | |||
$userData[self::NEWSLETTER], | |||
Password::generate() | |||
Password::generate(), | |||
$sendMailWelcome | |||
); | |||
} | |||
} | |||
@@ -53,7 +54,7 @@ class UserBulkImporter extends AbstractManager | |||
{ | |||
$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. | |||
Veuillez vous baser sur le fichier d'exemple téléchargeable ci-dessous."); | |||
} |