Przeglądaj źródła

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

dev
Guillaume Bourgeois 4 lat temu
rodzic
commit
9463721211
6 zmienionych plików z 60 dodań i 6 usunięć
  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 Wyświetl plik

@@ -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 {

+ 1
- 1
backend/controllers/UserController.php Wyświetl plik

@@ -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);

+ 6
- 1
backend/views/document/_form.php Wyświetl plik

@@ -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',

+ 6
- 1
backend/views/user/index.php Wyświetl plik

@@ -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'] ;
}
}
],
[

+ 6
- 1
common/models/User.php Wyświetl plik

@@ -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;
}

+ 3
- 1
common/models/UserSearch.php Wyświetl plik

@@ -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;

Ładowanie…
Anuluj
Zapisz