Pārlūkot izejas kodu

[Administration] Utilisateurs : page crédit #1152

feature/souke
Guillaume Bourgeois pirms 1 gada
vecāks
revīzija
efc49ed87a
21 mainītis faili ar 412 papildinājumiem un 26 dzēšanām
  1. +90
    -0
      backend/controllers/CreditController.php
  2. +7
    -5
      backend/controllers/UserController.php
  3. +87
    -0
      backend/views/credit/index.php
  4. +1
    -1
      backend/views/distribution/index.php
  5. +2
    -5
      backend/views/layouts/header.php
  6. +11
    -0
      backend/views/layouts/left.php
  7. +7
    -0
      common/helpers/CSV.php
  8. +8
    -0
      common/logic/AbstractGenerator.php
  9. +1
    -0
      common/logic/AbstractService.php
  10. +8
    -0
      common/logic/GeneratorInterface.php
  11. +26
    -2
      common/logic/User/User/Repository/UserRepository.php
  12. +27
    -8
      common/logic/User/User/Service/UserSolver.php
  13. +50
    -0
      common/logic/User/User/Service/UsersCreditCsvGenerator.php
  14. +4
    -0
      common/logic/User/User/Wrapper/UserContainer.php
  15. +2
    -0
      common/logic/User/User/Wrapper/UserManager.php
  16. +19
    -0
      common/logic/User/UserProducer/Repository/UserProducerRepository.php
  17. +7
    -0
      common/logic/User/UserProducer/Repository/UserProducerRepositoryQuery.php
  18. +12
    -5
      common/logic/User/UserProducer/Service/UserProducerBuilder.php
  19. +14
    -0
      common/logic/User/UserProducer/Service/UserProducerSolver.php
  20. +2
    -0
      common/logic/User/UserProducer/Wrapper/UserProducerContainer.php
  21. +27
    -0
      console/migrations/m230825_090016_active_user_producer_with_credit_positive_or_negative.php

+ 90
- 0
backend/controllers/CreditController.php Parādīt failu

<?php

/**
* Copyright distrib (2018)
*
* contact@opendistrib.net
*
* Ce logiciel est un programme informatique servant à aider les producteurs
* à distribuer leur production en circuits courts.
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/

namespace backend\controllers;

use common\helpers\CSV;
use common\helpers\Price;
use http\Exception\InvalidArgumentException;
use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;

class CreditController extends BackendController
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return $this->getUserManager()->hasAccessBackend();
}
]
],
],
];
}

public function actionIndex()
{
$userManager = $this->getUserManager();
$userProducerManager = $this->getUserProducerManager();

$dataProviderUsersWithNegativeCredit = new ActiveDataProvider([
'query' => $userManager->queryUsersWithNegativeCredit(),
'sort' => false,
'pagination' => [
'pageSize' => 30,
],
]);

return $this->render('index', [
'sumUserProducerCredits' => $userProducerManager->sumUserProducerCredits(),
'dataProviderUsersWithNegativeCredit' => $dataProviderUsersWithNegativeCredit
]);
}

public function actionExportUsers(string $type)
{
$this->getUserManager()->exportUsersCreditAsCsv($type);
}
}

+ 7
- 5
backend/controllers/UserController.php Parādīt failu

$userProducer = $userProducerManager->findOneUserProducer($user); $userProducer = $userProducerManager->findOneUserProducer($user);


if ($userProducer) { if ($userProducer) {
$userProducer->active = 0;
$userProducer->bookmark = 0;
$userProducer->save();

$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.');
if($userProducerManager->hasOutstandingCredit($userProducer)) {
$this->setFlash('error', "Vous ne pouvez pas supprimer cet utilisateur car il a toujours du crédit en cours.");
}
else {
$userProducerManager->unlinkUserProducer($userProducer);
$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.');
}
} else { } else {
throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404);
} }

+ 87
- 0
backend/views/credit/index.php Parādīt failu

<?php

use common\helpers\Price;
use yii\grid\GridView;

$userManager = $this->getUserManager();

$this->setTitle('Somme en crédit');

?>

<div class="row">
<div class="col-md-6">

</div>
<div class="col-md-6">

</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="info-box">
<span class="info-box-icon <?= $sumUserProducerCredits >= 0 ? 'bg-green' : 'bg-red' ?>"><i
class="fa fa-euro"></i></span>
<div class="info-box-content">
<span class="info-box-text">Total</span>
<span class="info-box-number"><?= Price::format($sumUserProducerCredits); ?></span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="info-box">
<span class="info-box-icon bg-orange"><i class="fa fa-download"></i></span>
<div class="info-box-content">
<span class="info-box-text">Exports<br />
<a class="btn btn-default btn-sm" href="<?= Yii::$app->urlManager->createUrl(['credit/export-users', 'type' => 'negative']); ?>">Clients au crédit négatif (CSV)</a>
<a class="btn btn-default btn-sm" href="<?= Yii::$app->urlManager->createUrl(['credit/export-users', 'type' => 'positive']); ?>">Clients au crédit positif (CSV)</a>
</span>
</div>
</div>
</div>
</div>

<h3>Clients avec un crédit négatif</h3>

<?=

GridView::widget([
'dataProvider' => $dataProviderUsersWithNegativeCredit,
'summary' => '',
'columns' => [
[
'label' => 'Client',
'value' => function ($user) use ($userManager) {
return $userManager->getUsernameFromArray($user, true);
}
],
[
'label' => 'Email',
'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function ($user) {
return $user['email'];
}
],
[
'label' => 'Téléphone',
'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function ($user) {
return $user['phone'];
}
],
[
'label' => 'Crédit',
'format' => 'raw',
'value' => function ($user) {
return Price::format($user['credit']);
}
]
]
]);
?>

+ 1
- 1
backend/views/distribution/index.php Parādīt failu

<option value="0">--</option> <option value="0">--</option>
<option v-for="user in users" :value="user.id_user"> <option v-for="user in users" :value="user.id_user">
<template v-if="user.name_legal_person && user.name_legal_person.length"> <template v-if="user.name_legal_person && user.name_legal_person.length">
Personne morale / {{ user.name_legal_person }}
{{ user.name_legal_person }} (personne morale)
</template> </template>
<template v-else> <template v-else>
{{ user.lastname +' '+ user.name }} {{ user.lastname +' '+ user.name }}

+ 2
- 5
backend/views/layouts/header.php Parādīt failu



<?php <?php


$usersNegativeCreditArray = $userManager->queryUsersBy(['id_producer' => GlobalParam::getCurrentProducerId()])
->andWhere('user_producer.credit < 0')
->orderBy('lastname, name ASC')
->all();
$usersNegativeCreditArray = $userManager->findUsersWithNegativeCredit();


?> ?>




<ul class="dropdown-menu"> <ul class="dropdown-menu">
<?php if (count($usersNegativeCreditArray)): ?> <?php if (count($usersNegativeCreditArray)): ?>
<li class="header">Utilisateurs au crédit négatif</li>
<li class="header"><a href="<?= Yii::$app->urlManager->createUrl(['credit/index']); ?>">Utilisateurs au crédit négatif</a></li>
<li> <li>
<ul class="menu"> <ul class="menu">
<?php foreach ($usersNegativeCreditArray as $user): ?> <?php foreach ($usersNegativeCreditArray as $user): ?>

+ 11
- 0
backend/views/layouts/left.php Parādīt failu



$producerManager = $this->getProducerManager(); $producerManager = $this->getProducerManager();
$userManager = $this->getUserManager(); $userManager = $this->getUserManager();
$userProducerManager = $this->getUserProducerManager();
$ticketManager = $this->getTicketManager(); $ticketManager = $this->getTicketManager();
$producer = GlobalParam::getCurrentProducer(); $producer = GlobalParam::getCurrentProducer();


$countTicketsAdminUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsAdminUnread.'</small></span>'; $countTicketsAdminUnreadLabel = '<span class="pull-right-container"><small class="label pull-right bg-green">'.$countTicketsAdminUnread.'</small></span>';
} }


$sumUserProducerCredits = $userProducerManager->sumUserProducerCredits();
$sumUserProducerCreditsLabel = '<span class="pull-right-container"><small class="label pull-right '.($sumUserProducerCredits >= 0 ? 'bg-green' : 'bg-red') .'">'.number_format($sumUserProducerCredits, 2).' €</small></span>';

?> ?>


<?= dmstr\widgets\Menu::widget( <?= dmstr\widgets\Menu::widget(
'url' => ['/user/index'], 'url' => ['/user/index'],
'items' => [ 'items' => [
['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => $userManager->isCurrentProducer()], ['label' => 'Liste', 'icon' => 'th-list', 'url' => ['/user/index'], 'visible' => $userManager->isCurrentProducer()],
[
'label' => 'Crédit',
'icon' => 'euro',
'url' => ['/credit/index'],
'template' => '<a href="{url}">{icon} {label}' . $sumUserProducerCreditsLabel . '</a>',
'visible' => $userManager->isCurrentProducer() && $producerManager->getConfig('credit')
],
['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => $userManager->isCurrentProducer()], ['label' => 'Groupes', 'icon' => 'users', 'url' => ['/user-group/index'], 'visible' => $userManager->isCurrentProducer()],
], ],
], ],

+ 7
- 0
common/helpers/CSV.php Parādīt failu



class CSV class CSV
{ {
public static function send(string $filename, array $data)
{
CSV::downloadSendHeaders($filename);
echo CSV::array2csv($data);
die();
}

public static function array2csv(array &$array) public static function array2csv(array &$array)
{ {
$producerManager = ProducerManager::getInstance(); $producerManager = ProducerManager::getInstance();

+ 8
- 0
common/logic/AbstractGenerator.php Parādīt failu

<?php

namespace common\logic;

abstract class AbstractGenerator extends AbstractService implements GeneratorInterface
{

}

+ 1
- 0
common/logic/AbstractService.php Parādīt failu

RepositoryInterface::class, RepositoryInterface::class,
BuilderInterface::class, BuilderInterface::class,
ResolverInterface::class, ResolverInterface::class,
GeneratorInterface::class,
UtilsInterface::class, UtilsInterface::class,
]; ];
} }

+ 8
- 0
common/logic/GeneratorInterface.php Parādīt failu

<?php

namespace common\logic;

interface GeneratorInterface
{

}

+ 26
- 2
common/logic/User/User/Repository/UserRepository.php Parādīt failu

public function queryUsersBy(array $params = []) public function queryUsersBy(array $params = [])
{ {
if (!isset($params['id_producer'])) { if (!isset($params['id_producer'])) {
$params['id_producer'] = GlobalParam::getCurrentProducerId();
$params['id_producer'] = $this->getProducerContextId();
} }


$query = (new Query()) $query = (new Query())
->select(['user.id AS user_id', 'user.name', 'user.lastname', 'user.phone', 'user.email', 'user.created_at', 'user.date_last_connection', 'user_producer.*', 'user.address', 'user.name_legal_person'])
->select(['user.id AS user_id', 'user.type', 'user.name', 'user.lastname', 'user.phone', 'user.email', 'user.created_at', 'user.date_last_connection', 'user_producer.*', 'user.address', 'user.name_legal_person'])
->from('user'); ->from('user');


$active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1; $active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1;
return $query; return $query;
} }


public function queryUsersWithNegativeCredit()
{
return $this->queryUsersBy()
->andWhere('user_producer.credit < 0')
->orderBy('credit ASC');
}

public function findUsersWithNegativeCredit()
{
return $this->queryUsersWithNegativeCredit()->all();
}

public function queryUsersWithPositiveCredit()
{
return $this->queryUsersBy()
->andWhere('user_producer.credit > 0')
->orderBy('lastname, name ASC');
}

public function findUsersWithPositiveCredit()
{
return $this->queryUsersWithPositiveCredit()->all();
}

/** /**
* Finds user by password reset token * Finds user by password reset token
*/ */

+ 27
- 8
common/logic/User/User/Service/UserSolver.php Parādīt failu

$username = ''; $username = '';
if (isset($modelArray['name_legal_person']) && strlen($modelArray['name_legal_person'])) { if (isset($modelArray['name_legal_person']) && strlen($modelArray['name_legal_person'])) {
$username = $modelArray['name_legal_person']; $username = $modelArray['name_legal_person'];

if ($withType) {
$username = 'Personne morale / ' . $username;
}
} else { } else {
$username = $modelArray['lastname'] . ' ' . $modelArray['name']; $username = $modelArray['lastname'] . ' ' . $modelArray['name'];
} }


if ($withType && $modelArray['type'] == User::TYPE_LEGAL_PERSON) {
$username = $username . ' (personne morale)';
}

return $username; return $username;
} }


public function getContactSummaryFromArrayAsHtml(array $user): string
{
$html = '';

if (strlen($user['phone'])) {
$html .= $user['phone'];
}

if (strlen($user['phone']) && strlen($user['email'])) {
$html .= '<br />';
}

if (strlen($user['email'])) {
$html .= $user['email'];
}

return $html;
}

public function getUsername(User $user, $withType = false): string public function getUsername(User $user, $withType = false): string
{ {
$username = ''; $username = '';
if (isset($user->name_legal_person) && strlen($user->name_legal_person)) { if (isset($user->name_legal_person) && strlen($user->name_legal_person)) {
$username = $user->name_legal_person; $username = $user->name_legal_person;

if ($withType) {
$username = 'Personne morale / ' . $username;
}
} else { } else {
$username = $user->lastname . ' ' . $user->name; $username = $user->lastname . ' ' . $user->name;
} }


if ($withType) {
$username = $username . ' (personne morale)';
}

return $username; return $username;
} }



+ 50
- 0
common/logic/User/User/Service/UsersCreditCsvGenerator.php Parādīt failu

<?php

namespace common\logic\User\User\Service;

use common\helpers\CSV;
use common\helpers\Price;
use common\logic\User\User\Repository\UserRepository;
use common\logic\AbstractGenerator;
use yii\base\ErrorException;

class UsersCreditCsvGenerator extends AbstractGenerator
{
protected UserSolver $userSolver;
protected UserRepository $userRepository;

public function loadDependencies(): void
{
$this->userSolver = $this->loadService(UserSolver::class);
$this->userRepository = $this->loadService(UserRepository::class);
}

public function exportUsersCreditAsCsv(string $type)
{
if($type == 'negative') {
$filename = 'Utilisateurs_credit_negatif.csv';
$usersArray = $this->userRepository->findUsersWithNegativeCredit();
}
elseif($type == 'positive') {
$filename = 'Utilisateurs_credit_positif.csv';
$usersArray = $this->userRepository->findUsersWithPositiveCredit();
}
else {
throw new ErrorException('Le paramètre $type est invalide.');
}

$data = [
['Client', 'Email', 'Téléphone', 'Crédit']
];
foreach($usersArray as $user) {
$data[] = [
$this->userSolver->getUsernameFromArray($user, true),
$user['email'],
$user['phone'],
Price::format($user['credit']),
];
}

CSV::send($filename, $data);
}
}

+ 4
- 0
common/logic/User/User/Wrapper/UserContainer.php Parādīt failu



use common\logic\AbstractContainer; use common\logic\AbstractContainer;
use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use common\logic\User\User\Repository\UserRepositoryQuery;
use common\logic\User\User\Service\UserBuilder; use common\logic\User\User\Service\UserBuilder;
use common\logic\User\User\Service\UserDefinition; use common\logic\User\User\Service\UserDefinition;
use common\logic\User\User\Service\UsersCreditCsvGenerator;
use common\logic\User\User\Service\UserSolver; use common\logic\User\User\Service\UserSolver;
use common\logic\User\User\Service\UserUtils; use common\logic\User\User\Service\UserUtils;


return [ return [
UserDefinition::class, UserDefinition::class,
UserSolver::class, UserSolver::class,
UserRepositoryQuery::class,
UserRepository::class, UserRepository::class,
UserBuilder::class, UserBuilder::class,
UsersCreditCsvGenerator::class,
UserUtils::class, UserUtils::class,
]; ];
} }

+ 2
- 0
common/logic/User/User/Wrapper/UserManager.php Parādīt failu

use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use common\logic\User\User\Service\UserBuilder; use common\logic\User\User\Service\UserBuilder;
use common\logic\User\User\Service\UserDefinition; use common\logic\User\User\Service\UserDefinition;
use common\logic\User\User\Service\UsersCreditCsvGenerator;
use common\logic\User\User\Service\UserSolver; use common\logic\User\User\Service\UserSolver;
use common\logic\User\User\Service\UserUtils; use common\logic\User\User\Service\UserUtils;


* @mixin UserRepository * @mixin UserRepository
* @mixin UserBuilder * @mixin UserBuilder
* @mixin UserUtils * @mixin UserUtils
* @mixin UsersCreditCsvGenerator
*/ */
class UserManager extends AbstractManager class UserManager extends AbstractManager
{ {

+ 19
- 0
common/logic/User/UserProducer/Repository/UserProducerRepository.php Parādīt failu

$userProducer = $this->findOneUserProducer($user); $userProducer = $this->findOneUserProducer($user);
return $userProducer ? $userProducer->bookmark : false; return $userProducer ? $userProducer->bookmark : false;
} }

public function findUserProducersWithNegativeOrPositiveCredit()
{
return $this->createDefaultQuery()
->filterHasNegativeOrPositiveCredit()
->find();
}

public function sumUserProducerCredits()
{
$sumUserProducersCredits = 0;
$userProducersWithNegativeOrPositiveCreditArray = $this->findUserProducersWithNegativeOrPositiveCredit();

foreach ($userProducersWithNegativeOrPositiveCreditArray as $userProducerWithNegativeOrPositiveCredit) {
$sumUserProducersCredits += $userProducerWithNegativeOrPositiveCredit->credit;
}

return $sumUserProducersCredits;
}
} }

+ 7
- 0
common/logic/User/UserProducer/Repository/UserProducerRepositoryQuery.php Parādīt failu

$this->andWhere(['bookmark' => $bookmark]); $this->andWhere(['bookmark' => $bookmark]);
return $this; return $this;
} }

public function filterHasNegativeOrPositiveCredit(): self
{
$this->andWhere('user_producer.credit IS NOT NULL AND user_producer.credit != 0');

return $this;
}
} }

+ 12
- 5
common/logic/User/UserProducer/Service/UserProducerBuilder.php Parādīt failu

public function createUserProducer(User $user, Producer $producer, int $bookmark = 1): UserProducer public function createUserProducer(User $user, Producer $producer, int $bookmark = 1): UserProducer
{ {
$userProducer = $this->instanciateUserProducer($user, $producer, $bookmark); $userProducer = $this->instanciateUserProducer($user, $producer, $bookmark);
$this->saveCreate($userProducer);
$this->create($userProducer);
return $userProducer; return $userProducer;
} }


$userProducer->setCredit($userProducer->getCredit() - $creditHistory->getAmount()); $userProducer->setCredit($userProducer->getCredit() - $creditHistory->getAmount());
} }


$this->saveUpdate($userProducer);
$this->update($userProducer);
} }


public function initMeanPaymentOrder($creditHistory) public function initMeanPaymentOrder($creditHistory)


$order->mean_payment = MeanPayment::CREDIT; $order->mean_payment = MeanPayment::CREDIT;


$this->saveUpdate($order);
$this->update($order);
} }
} }
} }


$userProducer->active = $active; $userProducer->active = $active;


return $this->saveUpdate($userProducer);
return $this->update($userProducer);
} }


public function updateBookmark(UserProducer $userProducer, bool $bookmark) public function updateBookmark(UserProducer $userProducer, bool $bookmark)
{ {
$userProducer->bookmark = $bookmark; $userProducer->bookmark = $bookmark;
return $this->saveUpdate($userProducer);
return $this->update($userProducer);
} }


public function addProducerBookmark(User $user) public function addProducerBookmark(User $user)
$userProducer = $this->createUserProducerIfNotExist($user, $this->getProducerContext()); $userProducer = $this->createUserProducerIfNotExist($user, $this->getProducerContext());
return $this->updateBookmark($userProducer, false); return $this->updateBookmark($userProducer, false);
} }

public function unlinkUserProducer(UserProducer $userProducer)
{
$userProducer->active = 0;
$userProducer->bookmark = 0;
return $this->update($userProducer);
}
} }

+ 14
- 0
common/logic/User/UserProducer/Service/UserProducerSolver.php Parādīt failu

<?php

namespace common\logic\User\UserProducer\Service;

use common\logic\AbstractSolver;
use common\logic\User\UserProducer\Model\UserProducer;

class UserProducerSolver extends AbstractSolver
{
public function hasOutstandingCredit(UserProducer $userProducer): bool
{
return $userProducer->credit < 0 || $userProducer->credit > 0;
}
}

+ 2
- 0
common/logic/User/UserProducer/Wrapper/UserProducerContainer.php Parādīt failu

use common\logic\User\UserProducer\Repository\UserProducerRepository; use common\logic\User\UserProducer\Repository\UserProducerRepository;
use common\logic\User\UserProducer\Service\UserProducerBuilder; use common\logic\User\UserProducer\Service\UserProducerBuilder;
use common\logic\User\UserProducer\Service\UserProducerDefinition; use common\logic\User\UserProducer\Service\UserProducerDefinition;
use common\logic\User\UserProducer\Service\UserProducerSolver;


class UserProducerContainer extends AbstractContainer class UserProducerContainer extends AbstractContainer
{ {
{ {
return [ return [
UserProducerDefinition::class, UserProducerDefinition::class,
UserProducerSolver::class,
UserProducerRepository::class, UserProducerRepository::class,
UserProducerBuilder::class, UserProducerBuilder::class,
]; ];

+ 27
- 0
console/migrations/m230825_090016_active_user_producer_with_credit_positive_or_negative.php Parādīt failu

<?php

use yii\db\Migration;

/**
* Class m230825_090016_active_user_producer_with_credit_positive_or_negative
*/
class m230825_090016_active_user_producer_with_credit_positive_or_negative extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->execute('UPDATE user_producer SET active = 1 WHERE credit IS NOT NULL AND (credit < 0 OR credit > 0);');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m230825_090016_active_user_producer_with_credit_positive_or_negative cannot be reverted.\n";

return false;
}
}

Notiek ielāde…
Atcelt
Saglabāt