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) { |
* @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" | |||||
]; | ]; | ||||
} | } | ||||
} | } |
</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"> |
]); ?> | ]); ?> | ||||
<?= $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']) ?> |
}; | }; | ||||
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) { |
/** | /** | ||||
* @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."); | ||||
} | } |