Oleg K 5 vuotta sitten
vanhempi
commit
10abe6a117

+ 37 - 0
app/assets/OrgFormAsset.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright (c) 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+namespace app\assets;
+
+use rmrevin\yii\fontawesome\NpmFreeAssetBundle;
+use yii\bootstrap4\BootstrapPluginAsset;
+use yii\web\AssetBundle;
+use yii\web\JqueryAsset;
+
+/**
+ * Main application asset bundle.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @since 2.0
+ */
+class OrgFormAsset extends AssetBundle
+{
+    public $basePath = '@webroot';
+    public $baseUrl = '@web';
+    public $css = [
+    ];
+    public $js = [
+        'js/org-form.js'
+    ];
+    public $depends = [
+        JqueryAsset::class,
+        BootstrapPluginAsset::class,
+        NpmFreeAssetBundle::class,
+        '\yii\widgets\ActiveFormAsset',
+    ];
+}
+

+ 3 - 0
app/config/params.php

@@ -4,4 +4,7 @@ return [
     'adminEmail' => 'admin@example.com',
     'senderEmail' => 'noreply@example.com',
     'senderName' => 'Example.com mailer',
+
+    //'bsDependencyEnabled' => false,
+    'bsVersion' => '4',
 ];

+ 5 - 1
app/config/web.php

@@ -16,7 +16,11 @@ $config = [
     ],
     'components' => [
         'assetManager' => [
-            //
+            'bundles' => [
+                'kartik\form\ActiveFormAsset' => [
+                    'bsDependencyEnabled' => false // do not load bootstrap assets for a specific asset bundle
+                ],
+            ],
         ],
         'request' => [
             // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation

+ 40 - 1
app/controllers/OrganizationsController.php

@@ -2,9 +2,11 @@
 
 namespace app\controllers;
 
+use app\models\Banks;
 use Yii;
 use app\models\Organizations;
 use app\models\OrganizationsSearch;
+use yii\helpers\ArrayHelper;
 use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
@@ -52,8 +54,16 @@ class OrganizationsController extends Controller
      */
     public function actionView($id)
     {
+        $org = $this->findModel($id);
+
+        $persons = $org->persons;
+
+        $bank = Banks::findOne($org->bank_id);
+
         return $this->render('view', [
-            'model' => $this->findModel($id),
+            'model' => $org,
+            'persons' => $persons,
+            'bank' => $bank,
         ]);
     }
 
@@ -66,6 +76,23 @@ class OrganizationsController extends Controller
     {
         $model = new Organizations();
 
+        if (Yii::$app->request->isAjax) {
+            if ($model->load(Yii::$app->request->post()) && $model->save()) {
+
+                return $this->asJson(['success' => true, 'id' => $model->getPrimaryKey()]);
+            }
+
+            $result = [];
+            // The code below comes from ActiveForm::validate(). We do not need to validate the model
+            // again, as it was already validated by save(). Just collect the messages.
+            foreach ($model->getErrors() as $attribute => $errors) {
+                $result[yii\helpers\Html::getInputId($model, $attribute)] = $errors;
+            }
+
+            return $this->asJson(['validation' => $result]);
+
+        }
+
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
@@ -85,13 +112,25 @@ class OrganizationsController extends Controller
     public function actionUpdate($id)
     {
         $model = $this->findModel($id);
+        $banks = Banks::find()->asArray()->all();
+        //$banks2 = Banks::find()->all();
 
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
 
+        $items = [];
+        foreach ($banks as $bank){
+            $mfo = isset($bank['mfo']) ? $bank['mfo'] . '<br>' : '';
+            $name = isset($bank['name']) ? '<a>' . $bank['name'] .'</a>' : '';
+            $address = isset($bank['address']) ? '<br>' . $bank['address'] : '';
+
+            $items[$bank['id']] = $mfo . $name . $address;
+        }
+
         return $this->render('update', [
             'model' => $model,
+            'banks' => $items
         ]);
     }
 

+ 69 - 0
app/models/Banks.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%banks}}".
+ *
+ * @property int $id
+ * @property string|null $name
+ * @property string|null $mfo
+ * @property string|null $edrpou
+ * @property string|null $name_e
+ * @property int|null $type
+ * @property string|null $address
+ * @property int|null $created_at
+ * @property int|null $updated_at
+ * @property int|null $deleted_at
+ */
+class Banks extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%banks}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['type', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
+            [['name', 'mfo', 'edrpou', 'name_e', 'address'], 'string', 'max' => 191],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'name' => 'Name',
+            'mfo' => 'Mfo',
+            'edrpou' => 'Edrpou',
+            'name_e' => 'Name E',
+            'type' => 'Type',
+            'address' => 'Address',
+            'created_at' => 'Created At',
+            'updated_at' => 'Updated At',
+            'deleted_at' => 'Deleted At',
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     * @return BanksQuery the active query used by this AR class.
+     */
+    public static function find()
+    {
+        return new BanksQuery(get_called_class());
+    }
+}

+ 34 - 0
app/models/BanksQuery.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\models;
+
+/**
+ * This is the ActiveQuery class for [[Banks]].
+ *
+ * @see Banks
+ */
+class BanksQuery extends \yii\db\ActiveQuery
+{
+    /*public function active()
+    {
+        return $this->andWhere('[[status]]=1');
+    }*/
+
+    /**
+     * {@inheritdoc}
+     * @return Banks[]|array
+     */
+    public function all($db = null)
+    {
+        return parent::all($db);
+    }
+
+    /**
+     * {@inheritdoc}
+     * @return Banks|array|null
+     */
+    public function one($db = null)
+    {
+        return parent::one($db);
+    }
+}

+ 2 - 2
app/models/Organizations.php

@@ -40,7 +40,7 @@ class Organizations extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['name'], 'required'],
+            [['name', 'short_name'], 'required'],
             [['vat', 'edrpou', 'bank_id', 'person_id', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
             [['comment'], 'string'],
             [['name', 'short_name', 'address_1', 'address_2', 'address_3'], 'string', 'max' => 191],
@@ -77,7 +77,7 @@ class Organizations extends \yii\db\ActiveRecord
      */
     public function getPersons()
     {
-        return $this->hasMany(Persons::className(), ['org_id' => 'id'])->inverseOf('org');
+        return $this->hasMany(Persons::class, ['org_id' => 'id'])->inverseOf('org');
     }
 
     /**

+ 78 - 0
app/models/Persons.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%persons}}".
+ *
+ * @property int $id
+ * @property int|null $org_id
+ * @property string|null $first_name
+ * @property string|null $last_name
+ * @property string|null $position
+ * @property int|null $created_at
+ * @property int|null $updated_at
+ * @property int|null $deleted_at
+ *
+ * @property Organizations $org
+ */
+class Persons extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%persons}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['org_id', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
+            [['first_name', 'last_name', 'position'], 'string', 'max' => 191],
+            [['org_id'], 'exist', 'skipOnError' => true, 'targetClass' => Organizations::className(), 'targetAttribute' => ['org_id' => 'id']],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'org_id' => 'Org ID',
+            'first_name' => 'First Name',
+            'last_name' => 'Last Name',
+            'position' => 'Position',
+            'created_at' => 'Created At',
+            'updated_at' => 'Updated At',
+            'deleted_at' => 'Deleted At',
+        ];
+    }
+
+    /**
+     * Gets query for [[Org]].
+     *
+     * @return \yii\db\ActiveQuery|OrganizationsQuery
+     */
+    public function getOrg()
+    {
+        return $this->hasOne(Organizations::class, ['id' => 'org_id'])->inverseOf('persons');
+    }
+
+    /**
+     * {@inheritdoc}
+     * @return PersonsQuery the active query used by this AR class.
+     */
+    public static function find()
+    {
+        return new PersonsQuery(get_called_class());
+    }
+}

+ 34 - 0
app/models/PersonsQuery.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\models;
+
+/**
+ * This is the ActiveQuery class for [[Persons]].
+ *
+ * @see Persons
+ */
+class PersonsQuery extends \yii\db\ActiveQuery
+{
+    /*public function active()
+    {
+        return $this->andWhere('[[status]]=1');
+    }*/
+
+    /**
+     * {@inheritdoc}
+     * @return Persons[]|array
+     */
+    public function all($db = null)
+    {
+        return parent::all($db);
+    }
+
+    /**
+     * {@inheritdoc}
+     * @return Persons|array|null
+     */
+    public function one($db = null)
+    {
+        return parent::one($db);
+    }
+}

+ 75 - 6
app/views/organizations/create.php

@@ -1,20 +1,89 @@
 <?php
 
 use yii\helpers\Html;
+use yii\bootstrap4\ActiveForm;
 
 /* @var $this yii\web\View */
 /* @var $model app\models\Organizations */
 
-$this->title = 'Create Organizations';
+$this->title = 'Create';
 $this->params['breadcrumbs'][] = ['label' => 'Organizations', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
+
+\app\assets\OrgFormAsset::register($this);
+
+$creteJs = <<< SCRIPT
+
+
+SCRIPT;
+$this->registerJs($creteJs, \yii\web\View::POS_END);
+
 ?>
 <div class="organizations-create">
+    <div class="card">
+        <!-- /.card-header -->
+        <div id="orgFormContainer" class="card-body">
 
-    <h1><?= Html::encode($this->title) ?></h1>
-
-    <?= $this->render('_form', [
-        'model' => $model,
-    ]) ?>
+            <div class="form-progress row mb-3">
+                <div class="col info-box shadow-sm step active">
+                    <div class="overlay"></div>
+                    <span class="info-box-icon bg-success"><i class="fas fa-file-invoice"></i></span>
+                    <div class="info-box-content">
+                        <strong class="h3 d-block m-0">Организация</strong>
+                        <span>Данные об организации</span>
+                    </div>
+                </div>
+                <div class="col info-box shadow-sm mx-3 step">
+                    <div class="overlay"></div>
+                    <span class="info-box-icon bg-success"><i class="fas fa-university"></i></span>
+                    <div class="info-box-content">
+                        <strong class="h3 d-block m-0">Банк</strong>
+                        <span>Выберите или добавьте банк</span>
+                    </div>
+                </div>
+                <div class="col info-box shadow-sm step">
+                    <div class="overlay"></div>
+                    <span class="info-box-icon bg-success"><i class="fas fa-user"></i></span>
+                    <div class="info-box-content">
+                        <strong class="h3 d-block m-0">Контакты</strong>
+                        <span>Email и контактные лица</span>
+                    </div>
+                </div>
+            </div>
 
+            <div class="tab">
+                <?php $form = ActiveForm::begin([
+                    'id' => 'org-form',
+                    //'enableClientValidation' => true,
+                ]); ?>
+                <?= Html::hiddenInput('id', $model->id); ?>
+                <div class="row">
+                    <div class="col-md-6">
+                        <?= $form->field($model, 'short_name')->textInput(['maxlength' => true]) ?>
+                        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+                    </div>
+                    <div class="col-md-6">
+                        <?= $form->field($model, 'edrpou')->textInput(['maxlength' => true]) ?>
+                        <?= $form->field($model, 'vat')->dropDownList([
+                            '1' => 'Без НДС',
+                            '2' => '0%',
+                            '3'=>'20%'
+                        ]); ?>
+                    </div>
+                </div>
+                <?php ActiveForm::end(); ?>
+            </div>
+            <div class="tab" style="display: none">
+                tab2
+            </div>
+            <div class="tab" style="display: none">
+                tab3
+            </div>
+            <p>
+                <button id="prevBtn" class="btn btn-default d-none" type="button">Prev</button>
+                <button id="nextBtn" class="btn btn-success ml-auto" type="button">Next</button>
+            </p>
+        </div>
+        <!-- /.card-body -->
+    </div>
 </div>

+ 77 - 5
app/views/organizations/update.php

@@ -1,21 +1,93 @@
 <?php
 
 use yii\helpers\Html;
+use yii\bootstrap4\ActiveForm;
+use yii\web\JsExpression;
+use kartik\select2\Select2;
 
 /* @var $this yii\web\View */
 /* @var $model app\models\Organizations */
+/* @var $banks app\models\Banks */
 
-$this->title = 'Update Organizations: ' . $model->name;
+$this->title = 'Update: ' . $model->name;
 $this->params['breadcrumbs'][] = ['label' => 'Organizations', 'url' => ['index']];
 $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
 $this->params['breadcrumbs'][] = 'Update';
+
+$format = <<< SCRIPT
+function format(state) {
+    return state.text.replace(/<br>/gi, " | "); 
+}
+SCRIPT;
+$this->registerJs($format, \yii\web\View::POS_HEAD);
+
 ?>
+
 <div class="organizations-update">
 
-    <h1><?= Html::encode($this->title) ?></h1>
+    <div class="card">
+        <div class="card-body">
+            <?php $form = ActiveForm::begin(); ?>
+            <div class="row">
+                <div class="col-md-4"><?= $form->field($model, 'short_name')->textInput(['maxlength' => true]) ?></div>
+                <div class="col-md-4"><?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?></div>
+                <div class="col-md-4"><?= $form->field($model, 'edrpou')->textInput() ?></div>
+
+                <div class="col-md-4">
+                    <?= $form->field($model, 'vat')->dropDownList([
+                        '1' => 'Без НДС',
+                        '2' => '0%',
+                        '3'=>'20%'
+                    ]); ?>
+                </div>
+                <div class="col-md-4">
+                    <?php
+                    echo $form->field($model, 'bank_id')->widget(Select2::class, [
+                        'data' => $banks,//['1' => 'Some Bank Name'],
+                        'options' => ['placeholder' => 'Select a state ...'],
+                        'pluginOptions' => [
+                            'allowClear' => true,
+                            'templateSelection' => new JsExpression('format'),
+                            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
+                            //'templateSelection' => new JsExpression('function (markup) { console.log(markup); return markup; }'),
+                        ],
+                        'pluginEvents' => [
+                              "select2:select" => "function(e) {
+                                document.getElementById('bankCol').innerHTML = e.params.data.text;
+                              }",
+                              "select2:unselect" => "function() { document.getElementById('bankCol').innerHTML = ''; }"
+                        ],
+                    ]);
+                    ?>
+                    <?/*= $form->field($model, 'bank_id')->textInput() */?>
+                </div>
+                <div class="col-md-4 align-self-center">
+                    <div class="form-group">
+                        <label></label>
+                        <div id="bankCol" class=""></div>
+                    </div>
+                </div>
+
+                <div class="col-md-4"><?= $form->field($model, 'address_1')->textInput(['maxlength' => true]) ?></div>
+                <div class="col-md-4"><?= $form->field($model, 'address_2')->textInput(['maxlength' => true]) ?></div>
+                <div class="col-md-4"><?= $form->field($model, 'address_3')->textInput(['maxlength' => true]) ?></div>
+            </div>
+
+            <?= $form->field($model, 'comment')->textarea(['rows' => 6]) ?>
+
+
+
+
+
+            <div class="form-group">
+                <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
+            </div>
+
+            <?php ActiveForm::end(); ?>
+        </div>
+        <!-- /.card-body -->
+    </div>
+
 
-    <?= $this->render('_form', [
-        'model' => $model,
-    ]) ?>
 
 </div>

+ 30 - 16
app/views/organizations/view.php

@@ -5,6 +5,8 @@ use yii\widgets\DetailView;
 
 /* @var $this yii\web\View */
 /* @var $model app\models\Organizations */
+/* @var $persons app\models\Persons */
+/* @var $bank app\models\Banks */
 
 $this->title = $model->short_name;
 $this->params['breadcrumbs'][] = ['label' => 'Organizations', 'url' => ['index']];
@@ -30,13 +32,13 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
     <div class="row">
         <div class="col-md-9">
 
-            <div class="card card-outline card-primary">
+            <div class="card ">
                 <div class="card-header">
                     <h3 class="card-title">Новые</h3>
 
                     <div class="card-tools">
-                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i>
-                        </button>
+                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i></button>
+                        <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
                     </div>
                     <!-- /.card-tools -->
                 </div>
@@ -64,13 +66,13 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                 <!-- /.card-body -->
             </div>
 
-            <div class="card card-warning">
+            <div class="card card-outline card-warning">
                 <div class="card-header">
                     <h3 class="card-title">Ожидающие</h3>
 
                     <div class="card-tools">
-                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i>
-                        </button>
+                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i></button>
+                        <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
                     </div>
                     <!-- /.card-tools -->
                 </div>
@@ -81,13 +83,13 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                 <!-- /.card-body -->
             </div>
 
-            <div class="card card-outline card-primary">
+            <div class="card ">
                 <div class="card-header">
                     <h3 class="card-title">Регулярные</h3>
 
                     <div class="card-tools">
-                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i>
-                        </button>
+                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i></button>
+                        <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
                     </div>
                     <!-- /.card-tools -->
                 </div>
@@ -98,13 +100,13 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                 <!-- /.card-body -->
             </div>
 
-            <div class="card card-success">
+            <div class="card card-outline card-success">
                 <div class="card-header">
                     <h3 class="card-title">Выполненные</h3>
 
                     <div class="card-tools">
-                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i>
-                        </button>
+                        <button type="button" class="btn btn-tool" data-card-widget="maximize"><i class="fas fa-expand"></i></button>
+                        <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
                     </div>
                     <!-- /.card-tools -->
                 </div>
@@ -115,7 +117,7 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                 <!-- /.card-body -->
             </div>
 
-            <?= DetailView::widget([
+            <? /*Grid::widget([
                 'model' => $model,
                 'attributes' => [
                     'id',
@@ -133,7 +135,7 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                     'updated_at',
                     'deleted_at',
                 ],
-            ]) ?>
+            ])*/ ?>
         </div>
         <div class="col-md-3">
             <div class="card">
@@ -146,13 +148,25 @@ $this->params['actionButtons'][] = ['label' => 'Delete', 'url' => ['index'], 'li
                 <div class="card-body">
                     <?= isset($model->comment) ? '<div class="mb-lg-3">'.$model->comment.'</div>' : ''; ?>
                     <dl>
+                        <?php if (isset($bank)): ?>
+                        <dt>Банк</dt>
+                        <dd>
+                            <span class="d-block"><?= $bank->name; ?></span>
+                            <span class="d-block"><?= $bank->mfo; ?></span>
+                            <span class="d-block"><?= $bank->address; ?></span>
+                        </dd>
+                        <?php endif; ?>
                         <?php if ($model->edrpou): ?>
                         <dt><?= strlen($model->edrpou) <= 8 ? 'ЕДРПОУ' : 'инн'; ?></dt>
                         <dd><?= $model->edrpou; ?></dd>
                         <?php endif; ?>
-                        <?php if($model->person_id): ?>
+                        <?php if($persons): ?>
                         <dt>Представитель</dt>
-                        <dd><?= $model->person_id; ?></dd>
+                        <dd>
+                            <?php foreach ($persons as $person): ?>
+                                <?= $person->first_name; ?>
+                            <?php endforeach; ?>
+                        </dd>
                         <?php endif; ?>
                         <?php if ($model->address_1 || $model->address_2 || $model->address_3) : ?>
                             <dt>Адрес.</dt>

+ 2 - 1
composer.json

@@ -19,7 +19,8 @@
         "yiisoft/yii2-bootstrap4": "^2.0",
         "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
         "almasaeed2010/adminlte": "^3.0",
-        "rmrevin/yii2-fontawesome": "^3.4"
+        "rmrevin/yii2-fontawesome": "^3.4",
+        "kartik-v/yii2-widget-select2": "dev-master"
     },
     "require-dev": {
         "yiisoft/yii2-debug": "~2.1.0",

+ 167 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "03093772c85c3f705a57cbc35d351189",
+    "content-hash": "8225fbf027c7782d6c4c54f59f5df445",
     "packages": [
         {
             "name": "almasaeed2010/adminlte",
@@ -460,6 +460,127 @@
             "time": "2020-10-05T16:44:11+00:00"
         },
         {
+            "name": "kartik-v/yii2-krajee-base",
+            "version": "v2.0.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/kartik-v/yii2-krajee-base.git",
+                "reference": "9ddb662bdf49fdb671a90853912a40418a26a0dd"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/kartik-v/yii2-krajee-base/zipball/9ddb662bdf49fdb671a90853912a40418a26a0dd",
+                "reference": "9ddb662bdf49fdb671a90853912a40418a26a0dd",
+                "shasum": ""
+            },
+            "suggest": {
+                "yiisoft/yii2-bootstrap": "for Krajee extensions to work with Bootstrap 3.x version",
+                "yiisoft/yii2-bootstrap4": "for Krajee extensions to work with Bootstrap 4.x version"
+            },
+            "type": "yii2-extension",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "kartik\\base\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Kartik Visweswaran",
+                    "email": "kartikv2@gmail.com",
+                    "homepage": "http://www.krajee.com/"
+                }
+            ],
+            "description": "Base library and foundation components for all Yii2 Krajee extensions.",
+            "homepage": "https://github.com/kartik-v/yii2-krajee-base",
+            "keywords": [
+                "base",
+                "extension",
+                "foundation",
+                "krajee",
+                "widget",
+                "yii2"
+            ],
+            "support": {
+                "issues": "https://github.com/kartik-v/yii2-krajee-base/issues",
+                "source": "https://github.com/kartik-v/yii2-krajee-base/tree/master"
+            },
+            "time": "2019-03-13T17:14:54+00:00"
+        },
+        {
+            "name": "kartik-v/yii2-widget-select2",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/kartik-v/yii2-widget-select2.git",
+                "reference": "05ed365ea5ed3555646db27dfb9beea79757a054"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/05ed365ea5ed3555646db27dfb9beea79757a054",
+                "reference": "05ed365ea5ed3555646db27dfb9beea79757a054",
+                "shasum": ""
+            },
+            "require": {
+                "kartik-v/yii2-krajee-base": ">=1.9",
+                "select2/select2": ">=4.0"
+            },
+            "default-branch": true,
+            "type": "yii2-extension",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.2.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "kartik\\select2\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Kartik Visweswaran",
+                    "email": "kartikv2@gmail.com",
+                    "homepage": "http://www.krajee.com/"
+                }
+            ],
+            "description": "Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).",
+            "homepage": "https://github.com/kartik-v/yii2-widget-select2",
+            "keywords": [
+                "dropdown",
+                "extension",
+                "form",
+                "jquery",
+                "plugin",
+                "select2",
+                "widget",
+                "yii2"
+            ],
+            "support": {
+                "issues": "https://github.com/kartik-v/yii2-widget-select2/issues",
+                "source": "https://github.com/kartik-v/yii2-widget-select2/tree/master"
+            },
+            "funding": [
+                {
+                    "url": "https://opencollective.com/yii2-widget-select2",
+                    "type": "open_collective"
+                }
+            ],
+            "time": "2020-12-15T14:53:54+00:00"
+        },
+        {
             "name": "npm-asset/bootstrap",
             "version": "4.5.3",
             "dist": {
@@ -533,6 +654,48 @@
             "time": "2020-06-27T10:12:14+00:00"
         },
         {
+            "name": "select2/select2",
+            "version": "4.0.13",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/select2/select2.git",
+                "reference": "45f2b83ceed5231afa7b3d5b12b58ad335edd82e"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/select2/select2/zipball/45f2b83ceed5231afa7b3d5b12b58ad335edd82e",
+                "reference": "45f2b83ceed5231afa7b3d5b12b58ad335edd82e",
+                "shasum": ""
+            },
+            "type": "component",
+            "extra": {
+                "component": {
+                    "scripts": [
+                        "dist/js/select2.js"
+                    ],
+                    "styles": [
+                        "dist/css/select2.css"
+                    ],
+                    "files": [
+                        "dist/js/select2.js",
+                        "dist/js/i18n/*.js",
+                        "dist/css/select2.css"
+                    ]
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "Select2 is a jQuery based replacement for select boxes.",
+            "homepage": "https://select2.org/",
+            "support": {
+                "issues": "https://github.com/select2/select2/issues",
+                "source": "https://github.com/select2/select2/tree/4.0.13"
+            },
+            "time": "2020-01-28T05:01:22+00:00"
+        },
+        {
             "name": "swiftmailer/swiftmailer",
             "version": "v6.2.3",
             "source": {
@@ -5469,7 +5632,9 @@
     ],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [],
+    "stability-flags": {
+        "kartik-v/yii2-widget-select2": 20
+    },
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {

+ 8 - 0
public_html/css/site.css

@@ -113,3 +113,11 @@ a.desc:after {
 .nav > li > form > button.logout:focus {
     outline: none;
 }
+
+#orgFormContainer{}
+#orgFormContainer .step.active .overlay{
+    display: none!important;
+}
+/*#orgFormContainer .tab{
+    display: none;
+}*/

+ 225 - 0
public_html/js/org-form.js

@@ -0,0 +1,225 @@
+(function ($){
+
+    let orgForm = $('#org-form');
+    let curStep = 0;
+    let tabCount = document.getElementsByClassName("tab").length;
+
+    $('#organizations-short_name').focus();
+
+
+    $('#orgFormContainer .tab').each(function (index){
+        curStep = $(this).is('.d-block') ? index : 0;
+    });
+
+    $('#prevBtn').click(function (){
+        $(".tab:eq("+curStep+")").hide().prev().show();
+        curStep -= 1;
+        if(curStep === 0){
+            $(this).addClass('d-none');
+            $('#nextBtn').removeClass('d-none');
+        }
+        console.log(curStep);
+    });
+
+    $('#nextBtn').click(function (){
+        console.log(curStep);
+
+        if(curStep === 0) {
+            let valid;
+            orgForm.yiiActiveForm('validate', true);
+
+            orgForm.on('afterValidate', function (event, attribute, messages) {
+                console.log(messages);
+                if(messages.length > 0) {
+                    valid = false;
+                }
+                if(!valid) return false;
+            });
+            if(!valid) return false;
+        }
+        $(".tab:eq("+curStep+")").hide().next().show();
+        curStep += 1;
+        if(curStep >= (tabCount-1)) {
+            $(this).addClass('d-none');
+        }
+        $('#prevBtn').removeClass('d-none');
+
+    });
+
+    orgForm.on('beforeSubmit', function () {
+        var $yiiform = $(this);
+        $.ajax({
+                type: $yiiform.attr('method'),
+                url: $yiiform.attr('action'),
+                data: $yiiform.serializeArray(),
+            }
+        )
+        .done(function(data) {
+            if(data.success) {
+                // data is saved
+                $yiiform.find('input[name=id]').val(data.id)
+                $yiiform.attr('action', '/organizations/update?id='+data.id)
+                //goNext();
+            } else if (data.validation) {
+                // server validation failed
+                console.log('server validation failed ', data.validation);
+                //$yiiform.yiiActiveForm('updateMessages', data.validation, true); // renders validation messages at appropriate places
+            } else {
+                // incorrect server response
+            }
+        })
+        .fail(function () {
+            //alert('Fail message here');
+        });
+
+        function goNext(){
+            $(".step:eq("+curStep+")").removeClass('active').next().addClass('active');
+        }
+        function goNPrev(){
+            $(".step:eq("+curStep+")").removeClass('active').prev().addClass('active');
+        }
+
+        function validate(){
+
+        }
+
+        return false; // prevent default form submission
+    });
+
+    //showStep(currentTab);
+
+})(jQuery);
+
+
+
+
+
+/*
+
+var currentTab = 0; // Current tab is set to be the first tab (0)
+showTab(currentTab); // Display the current tab
+var orgForm = jQuery('#org-form');
+
+orgForm.on('beforeSubmit', function () {
+    var $yiiform = $(this);
+    console.log($(this));
+    $.ajax({
+            type: $yiiform.attr('method'),
+            url: $yiiform.attr('action'),
+            data: $yiiform.serializeArray(),
+        }
+    )
+        .done(function(data) {
+            if(data.success) {
+                // data is saved
+                $yiiform.find('input[name=id]').val(data.id)
+                $yiiform.attr('action', '/organizations/update?id='+data.id)
+            } else if (data.validation) {
+                // server validation failed
+                console.log('server validation failed ', data.validation);
+                //$yiiform.yiiActiveForm('updateMessages', data.validation, true); // renders validation messages at appropriate places
+            } else {
+                // incorrect server response
+            }
+        })
+        .fail(function () {
+            //alert('Fail message here');
+        })
+
+    return false; // prevent default form submission
+})
+
+function showTab(n) {
+    // This function will display the specified tab of the form ...
+    var x = document.getElementsByClassName("tab");
+    x[n].style.display = "block";
+    // ... and fix the Previous/Next buttons:
+    if (n == 0) {
+        document.getElementById("prevBtn").style.display = "none";
+    } else {
+        document.getElementById("prevBtn").style.display = "inline";
+    }
+    if (n == (x.length - 1)) {
+        document.getElementById("nextBtn").innerHTML = "Submit";
+    } else {
+        document.getElementById("nextBtn").innerHTML = "Next";
+    }
+    // ... and run a function that displays the correct step indicator:
+    fixStepIndicator(n);
+
+}
+
+function nextPrev(n) {
+    // This function will figure out which tab to display
+    var x = document.getElementsByClassName("tab");
+    var currentForm = x[currentTab].find('form');
+
+    console.log(currentForm);
+
+    orgForm.yiiActiveForm('validate', true);
+    console.log(x[currentTab].getElementsByTagName('form')[0].getAttribute('id'))
+
+
+    // Exit the function if any field in the current tab is invalid:
+
+
+    if (n === 1 && !validateForm()) return false;
+    //if (!valid) return false;
+    // Hide the current tab:
+    x[currentTab].style.display = "none";
+    // Increase or decrease the current tab by 1:
+    currentTab = currentTab + n;
+    // if you have reached the end of the form... :
+    if (currentTab >= x.length) {
+        //...the form gets submitted:
+        //document.getElementById("orgFormContainer").submit();
+        return false;
+    }
+
+    // Otherwise, display the correct tab:
+    showTab(currentTab);
+}
+
+function validateForm() {
+    var x, y, i, valid = false;
+
+    orgForm.on('afterValidate', function (event, attribute, messages, deferreds) {
+        if(messages.length>0) valid = false;
+    });
+
+    //valid = document.querySelectorAll('#orgFormContainer input.is-invalid').length <= 0;
+
+    console.log(valid);
+
+    // This function deals with validation of the form fields
+    /!*var x, y, i, valid = true;
+    x = document.getElementsByClassName("tab");
+    y = x[currentTab].getElementsByTagName("input");
+    // A loop that checks every input field in the current tab:
+    for (i = 0; i < y.length; i++) {
+        // If a field is empty...
+        if (y[i].value == "") {
+            // add an "invalid" class to the field:
+            y[i].className += " invalid";
+            // and set the current valid status to false:
+            valid = false;
+        }
+    }
+    // If the valid status is true, mark the step as finished and valid:
+    if (valid) {
+        document.getElementsByClassName("step")[currentTab].className += " finish";
+    }*!/
+    /!*var valid = false;
+    valid = document.querySelectorAll('#orgFormContainer input.is-invalid').length > 0 ? false : true;*!/
+    return valid; // return the valid status
+}
+
+function fixStepIndicator(n) {
+    // This function removes the "active" class of all steps...
+    var i, x = document.getElementsByClassName("step");
+    for (i = 0; i < x.length; i++) {
+        x[i].className = x[i].className.replace(" active", "");
+    }
+    //... and adds the "active" class to the current step:
+    x[n].className += " active";
+}*/

+ 97 - 6
reactcrmyii.sql

@@ -3,7 +3,7 @@
 -- https://www.phpmyadmin.net/
 --
 -- Хост: localhost
+-- Время создания: Дек 30 2020 г., 14:33
 -- Версия сервера: 10.4.16-MariaDB
 -- Версия PHP: 7.4.12
 
@@ -24,6 +24,33 @@ SET time_zone = "+00:00";
 -- --------------------------------------------------------
 
 --
+-- Структура таблицы `banks`
+--
+
+CREATE TABLE `banks` (
+  `id` int(11) NOT NULL,
+  `name` varchar(191) DEFAULT NULL,
+  `mfo` varchar(191) DEFAULT NULL,
+  `edrpou` varchar(191) DEFAULT NULL,
+  `name_e` varchar(191) DEFAULT NULL,
+  `type` int(11) DEFAULT NULL,
+  `address` varchar(191) DEFAULT NULL,
+  `created_at` int(11) DEFAULT NULL,
+  `updated_at` int(11) DEFAULT NULL,
+  `deleted_at` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--
+-- Дамп данных таблицы `banks`
+--
+
+INSERT INTO `banks` (`id`, `name`, `mfo`, `edrpou`, `name_e`, `type`, `address`, `created_at`, `updated_at`, `deleted_at`) VALUES
+(1, 'ПриватБанк', 'мфо1122', '1234567812', NULL, NULL, 'г. Полтава, ул. Кагамлыка, 30', NULL, NULL, NULL),
+(2, 'Альфабанк', 'мфо88878', '998877889', NULL, NULL, NULL, NULL, NULL, NULL);
+
+-- --------------------------------------------------------
+
+--
 -- Структура таблицы `migration`
 --
 
@@ -67,8 +94,51 @@ CREATE TABLE `organizations` (
 --
 
 INSERT INTO `organizations` (`id`, `name`, `short_name`, `vat`, `edrpou`, `address_1`, `address_2`, `address_3`, `comment`, `bank_id`, `person_id`, `created_at`, `updated_at`, `deleted_at`) VALUES
-(1, 'ФОП \"Широкие Потребности\"', 'Ширпотреб', 3, '00000001', 'адрес 1', 'адрес 2', 'адрес 3', 'lispsum comment', NULL, NULL, NULL, NULL, NULL),
-(2, 'ФОП \"Абра Кадабра\"', 'Абракадабра', 1, '0000000010', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+(1, 'ФОП \"Широкие Потребности\"', 'Ширпотреб', 3, '00000001', 'адрес 1', 'адрес 2', 'адрес 3', 'lispsum comment', 1, NULL, NULL, NULL, NULL),
+(2, 'ФОП \"Абра Кадабра\"', 'Абракадабра', 1, '0000000010', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(14, 'sadf', 'sadf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(15, 'asdfa', 'dfsaa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(16, 'asdf', 'dsaf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(17, 'asdf', 'safd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(18, 'asdfa', 'asdffasd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(19, 'asdfa', 'fasdf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(20, 'asdfa', 'sadfsa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(21, 'asdfasd', 'dsffas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(22, 'asdfa', 'dfsasfd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(23, 'asdfasdf', 'sadffas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(24, 'asdfads', 'sadfa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(25, 'asdfafds', 'asdfas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(26, 'asdfa', 'dffsa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(27, 'ывфафы', 'выафва', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(28, 'аыфваыфва', 'ыфвавыфаыфв', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(29, 'sadfsadf', 'dsfsadf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(30, 'sadf', 'dfsad', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(31, 'adsfa', 'sadfsadf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(32, 'ыфваыфваф', 'афыва', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(33, 'ыфвафыва', 'аывфва', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(34, 'asdfas', 'dasfasd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(35, 'sadfasdf', 'sadfdsa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(36, 'asdfas', 'sadfasdf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(37, 'sdafas', 'sadfasdf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(38, 'sdafafa', 'sdafasd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(39, 'asdfasdf', 'sadfads', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(40, 'asdfas', 'asdfas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(41, 'asdfadfa', 'sdadfasd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(42, 'asdfsa', 'dsfasf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(43, 'dsafdfa', 'fdsafdas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(44, 'sdfgsdf', 'fdgsdfg', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(45, 'wert', 'erwtertw', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(46, 'sadfa', 'asdfsad', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(47, 'asdfasdf', 'saf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(48, 'asdfasda', 'asdfsad', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(49, 'asdfa', 'sadfasd', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(50, 'asdfas', 'sdfa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(51, 'asdfasdfs', 'sdafsda', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(52, 'adsfdfsa', 'fdsa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(53, 'asdfas', 'dfsafas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(54, 'asdfas', 'fdasdfa', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(55, 'asdfa', 'dsafas', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+(56, 'asdfa', 'sdafasdf', 1, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
 
 -- --------------------------------------------------------
 
@@ -87,6 +157,13 @@ CREATE TABLE `persons` (
   `deleted_at` int(11) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
+--
+-- Дамп данных таблицы `persons`
+--
+
+INSERT INTO `persons` (`id`, `org_id`, `first_name`, `last_name`, `position`, `created_at`, `updated_at`, `deleted_at`) VALUES
+(2, 1, 'Василий Пупкин', NULL, NULL, NULL, NULL, NULL);
+
 -- --------------------------------------------------------
 
 --
@@ -114,6 +191,12 @@ INSERT INTO `settings` (`id`, `invoce`, `act`, `time`, `created_at`, `updated_at
 --
 
 --
+-- Индексы таблицы `banks`
+--
+ALTER TABLE `banks`
+  ADD PRIMARY KEY (`id`);
+
+--
 -- Индексы таблицы `migration`
 --
 ALTER TABLE `migration`
@@ -129,7 +212,8 @@ ALTER TABLE `organizations`
 -- Индексы таблицы `persons`
 --
 ALTER TABLE `persons`
-  ADD PRIMARY KEY (`id`);
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `fk_prn_id` (`org_id`);
 
 --
 -- Индексы таблицы `settings`
@@ -142,16 +226,22 @@ ALTER TABLE `settings`
 --
 
 --
+-- AUTO_INCREMENT для таблицы `banks`
+--
+ALTER TABLE `banks`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
+
+--
 -- AUTO_INCREMENT для таблицы `organizations`
 --
 ALTER TABLE `organizations`
-  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
+  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=57;
 
 --
 -- AUTO_INCREMENT для таблицы `persons`
 --
 ALTER TABLE `persons`
-  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
+  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
 
 --
 -- AUTO_INCREMENT для таблицы `settings`
@@ -167,7 +257,7 @@ ALTER TABLE `settings`
 -- Ограничения внешнего ключа таблицы `persons`
 --
 ALTER TABLE `persons`
-  ADD CONSTRAINT `fk_org_id` FOREIGN KEY (`org_id`) REFERENCES `organizations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+  ADD CONSTRAINT `fk_prn_id` FOREIGN KEY (`org_id`) REFERENCES `organizations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
 COMMIT;
 
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;