@@ -48,6 +48,7 @@ use common\models\User; | |||
use common\models\Subscription; | |||
use common\helpers\Price; | |||
use common\models\PointSaleDistribution; | |||
use common\models\UserProducer; | |||
use DateTime; | |||
class DistributionController extends BackendController | |||
@@ -1030,8 +1031,44 @@ class DistributionController extends BackendController | |||
if(!$deliveryNote) { | |||
$deliveryNote = new DeliveryNote; | |||
$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(); | |||
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(); | |||
} | |||
else { |
@@ -157,7 +157,7 @@ class UserController extends BackendController | |||
if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | |||
// save use | |||
// save user | |||
$password = Password::generate(); | |||
$model->id_producer = 0 ; | |||
$model->setPassword($password); |
@@ -64,7 +64,12 @@ use common\models\Producer; | |||
]) | |||
->dropDownList( | |||
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', |
@@ -67,7 +67,12 @@ $this->render('_menu',[ | |||
'attribute' => 'username', | |||
'label' => 'Nom', | |||
'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'] ; | |||
} | |||
} | |||
], | |||
[ |
@@ -672,7 +672,12 @@ class User extends ActiveRecordCommon implements IdentityInterface | |||
public function getFullAddress() | |||
{ | |||
$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; | |||
return $address; | |||
} |
@@ -84,6 +84,7 @@ class UserSearch extends User | |||
. '`user`.mail_distribution_sunday, ' | |||
. '`user`.id_producer, ' | |||
. '`user`.date_last_connection, ' | |||
. '`user`.name_legal_person, ' | |||
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); | |||
$dataProvider = new ActiveDataProvider([ | |||
@@ -133,7 +134,8 @@ class UserSearch extends User | |||
$query->andFilterWhere([ | |||
'or', | |||
['like', 'user.lastname', $this->username], | |||
['like', 'user.name', $this->username] | |||
['like', 'user.name', $this->username], | |||
['like', 'user.name_legal_person', $this->username], | |||
]); | |||
return $dataProvider; |