Browse Source

Génération automatique de la personne morale lors de la création du document si le point de vente n'a pas de contact facturation

refactoring
Guillaume Bourgeois 4 years ago
parent
commit
9463721211
6 changed files with 60 additions and 6 deletions
  1. +38
    -1
      backend/controllers/DistributionController.php
  2. +1
    -1
      backend/controllers/UserController.php
  3. +6
    -1
      backend/views/document/_form.php
  4. +6
    -1
      backend/views/user/index.php
  5. +6
    -1
      common/models/User.php
  6. +3
    -1
      common/models/UserSearch.php

+ 38
- 1
backend/controllers/DistributionController.php View File

use common\models\Subscription; use common\models\Subscription;
use common\helpers\Price; use common\helpers\Price;
use common\models\PointSaleDistribution; use common\models\PointSaleDistribution;
use common\models\UserProducer;
use DateTime; use DateTime;


class DistributionController extends BackendController class DistributionController extends BackendController
if(!$deliveryNote) { if(!$deliveryNote) {
$deliveryNote = new DeliveryNote; $deliveryNote = new DeliveryNote;
$deliveryNote->name = 'Bon de livraison ' . $firstOrder->pointSale->name . ' (' . date('d/m/Y', strtotime($firstOrder->distribution->date)) . ')'; $deliveryNote->name = 'Bon de livraison ' . $firstOrder->pointSale->name . ' (' . date('d/m/Y', strtotime($firstOrder->distribution->date)) . ')';
$deliveryNote->id_user = 1;
$deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); $deliveryNote->id_producer = GlobalParam::getCurrentProducerId();

if($firstOrder->pointSale->id_user) {
$deliveryNote->id_user = $firstOrder->pointSale->id_user;
}
else {
$user = new User ;
$user->type = User::TYPE_LEGAL_PERSON ;
$user->name_legal_person = $firstOrder->pointSale->name ;
$user->address = $firstOrder->pointSale->address ;
$user->id_producer = 0 ;
$user->setPassword(Password::generate());
$user->generateAuthKey();
$user->email = '' ;
if (!strlen($user->email)) {
$user->username = 'inconnu@opendistrib.net';
}
$user->save() ;

$userProducer = new UserProducer;
$userProducer->id_user = $user->id;
$userProducer->id_producer = GlobalParam::getCurrentProducerId();
$userProducer->credit = 0;
$userProducer->active = 1;
$userProducer->save();

$firstOrder->pointSale->id_user = $user->id ;
$firstOrder->pointSale->save() ;

$deliveryNote->id_user = $user->id;
}

if(!isset($user)) {
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
}
$deliveryNote->address = $user->getFullAddress() ;
$deliveryNote->save(); $deliveryNote->save();
} }
else { else {

+ 1
- 1
backend/controllers/UserController.php View File



if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') {


// save use
// save user
$password = Password::generate(); $password = Password::generate();
$model->id_producer = 0 ; $model->id_producer = 0 ;
$model->setPassword($password); $model->setPassword($password);

+ 6
- 1
backend/views/document/_form.php View File

]) ])
->dropDownList( ->dropDownList(
ArrayHelper::map($usersArray, 'user_id', function ($model) { ArrayHelper::map($usersArray, 'user_id', function ($model) {
return $model['lastname'] . ' ' . $model['name'];
if(isset($model['name_legal_person']) && strlen($model['name_legal_person'])) {
return $model['name_legal_person'] ;
}
else {
return $model['lastname'] . ' ' . $model['name'];
}
}), }),
[ [
'@change' => 'changeUser', '@change' => 'changeUser',

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

'attribute' => 'username', 'attribute' => 'username',
'label' => 'Nom', 'label' => 'Nom',
'value' => function($model) { 'value' => function($model) {
return $model['lastname'].' '.$model['name'] ;
if(isset($model['name_legal_person'])) {
return $model['name_legal_person'] ;
}
else {
return $model['lastname'].' '.$model['name'] ;
}
} }
], ],
[ [

+ 6
- 1
common/models/User.php View File

public function getFullAddress() public function getFullAddress()
{ {
$address = ''; $address = '';
$address .= $this->lastname . ' ' . $this->name . "\n";
if(isset($this->lastname) && isset($this->name) && strlen($this->lastname) && strlen($this->name)) {
$address .= $this->lastname . ' ' . $this->name . "\n";
}
if(isset($this->name_legal_person) && strlen($this->name_legal_person)) {
$address .= $this->name_legal_person. "\n";
}
$address .= $this->address; $address .= $this->address;
return $address; return $address;
} }

+ 3
- 1
common/models/UserSearch.php View File

. '`user`.mail_distribution_sunday, ' . '`user`.mail_distribution_sunday, '
. '`user`.id_producer, ' . '`user`.id_producer, '
. '`user`.date_last_connection, ' . '`user`.date_last_connection, '
. '`user`.name_legal_person, '
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); . '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders');


$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
$query->andFilterWhere([ $query->andFilterWhere([
'or', 'or',
['like', 'user.lastname', $this->username], ['like', 'user.lastname', $this->username],
['like', 'user.name', $this->username]
['like', 'user.name', $this->username],
['like', 'user.name_legal_person', $this->username],
]); ]);


return $dataProvider; return $dataProvider;

Loading…
Cancel
Save