]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-243 Действия по замене (II этап)
authormarina <m.zozirova@gmail.com>
Tue, 3 Dec 2024 11:58:58 +0000 (14:58 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 3 Dec 2024 11:58:58 +0000 (14:58 +0300)
erp24/controllers/ReplacementInvoiceController.php
erp24/records/EqualizationRemains.php
erp24/records/ReplacementInvoice.php
erp24/records/ReplacementInvoiceProducts.php
erp24/views/replacement-invoice/view.php
erp24/views/shift-transfer/_replacement.php

index 79411bc867a4b9b3347fcb45cb21e843378dc07a..156b094c1dc6525b539c2ed6ec9e18438ff3fd53 100644 (file)
@@ -44,14 +44,14 @@ class ReplacementInvoiceController extends Controller
     {
         $model = $this->findModel($id);
 
-        $products =  new ActiveDataProvider([
+        $dataProvider = new ActiveDataProvider([
             'query' => ReplacementInvoiceProducts::find()
-                ->andWhere(['replacement_invoice_id' => $model->guid])
+                ->andWhere(['replacement_invoice_id' => $id])
         ]);
 
         return $this->render('view', [
             'model' => $model,
-            'products' =>$products
+            'dataProvider' =>$dataProvider
         ]);
     }
 
index 201827bc8180c8c880e41915ee2aca34dfc523ff..90cd3c3251bac6407b6dae1ef6c1d220db7f5e6a 100644 (file)
@@ -67,7 +67,6 @@ class EqualizationRemains extends \yii\db\ActiveRecord
             [['product_count', 'product_price', 'product_self_cost', 'product_replacement_count', 'product_replacement_price', 'product_replacement_self_cost', 'balance', 'balance_self_cost'], 'required'],
             [['created_at', 'updated_at'], 'safe'],
             [['product_id', 'product_replacement_id'], 'string', 'max' => 255],
-            [[]]
         ];
     }
 
index 8518f2adb024b505a37ca4cb6c8f7c6b791e2d93..5d017997ac7d9808056fdc068ef83c8550549935 100644 (file)
@@ -3,6 +3,10 @@
 namespace yii_app\records;
 
 use Yii;
+use yii\behaviors\BlameableBehavior;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+use yii_app\helpers\DataHelper;
 
 /**
  * This is the model class for table "replacement_invoice".
@@ -30,6 +34,7 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
 {
     public const ACTIVE = 1;
     public const DELETE = 0;
+    public const REPLACEMENT_ACTIONS = 2;
     /**
      * {@inheritdoc}
      */
@@ -38,6 +43,23 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
         return 'replacement_invoice';
     }
 
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+            [
+                'class' => BlameableBehavior::class,
+                'createdByAttribute' => 'created_admin_id',
+                'updatedByAttribute' => 'updated_admin_id',
+            ],
+        ];
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -56,14 +78,16 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
 
     public static function setData($shiftTransfer)
     {
-        $storeId = array_flip(CityStore::getAllActiveGuidId())[$shiftTransfer->store_guid];
+        $storeId = array_flip(array_map('strval', CityStore::getAllActiveGuidId()))[$shiftTransfer->store_guid];
+        $guid = DataHelper::createGuidMy();
         $model = new self();
         $model->setAttributes([
-            'guid' => GUID(),
-            'status' => 2,
+            'guid' => $guid,
+            'status' => self::REPLACEMENT_ACTIONS,
             'created_admin_id' => $shiftTransfer->end_shift_admin_id,
             'updated_admin_id' => $shiftTransfer->start_shift_admin_id,
             'confirm_admin_id' => $shiftTransfer->start_shift_admin_id,
+            'number' => $guid,
             'store_id' => $storeId,
             'store_guid' => $shiftTransfer->store_guid,
             'date' => $shiftTransfer->date,
@@ -76,7 +100,7 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
             $model->save();
             ReplacementInvoiceProducts::setData($model, $shiftTransfer);
         } else {
-            var_dump($model->errors);
+            var_dump($model->getErrors());
         }
     }
 
@@ -112,4 +136,9 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
     {
         return $this->hasMany(ReplacementInvoiceProducts::class, ['replacement_invoice_id' => 'id']);
     }
+
+
+    public function getCreatedBy() {
+        return $this->hasOne(Admin::class, ['id' => 'created_by']);
+    }
 }
index fb765eff9411ccc3956f6ba5534f7e2d8858f1ae..2f8065e779db60003e0fdc0a8cca3d3e7b1e4365 100644 (file)
@@ -3,6 +3,9 @@
 namespace yii_app\records;
 
 use Yii;
+use yii\behaviors\BlameableBehavior;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
 
 /**
  * This is the model class for table "replacement_invoice_products".
@@ -38,6 +41,23 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord
     //Приходуемый товар (Товар, который надо заменить)
     public const INCOMING = 2;
 
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+            [
+                'class' => BlameableBehavior::class,
+                'createdByAttribute' => 'updated_admin_id',
+                'updatedByAttribute' => 'created_admin_id',
+            ],
+        ];
+    }
+
 
     /**
      * {@inheritdoc}
@@ -53,7 +73,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord
         foreach ($equalizationRemains as $equalizationRemain) {
             $incoming = new self();
             $incoming->setAttributes([
-                'replacement_invoice_id' => $replacementInvoice->guid,
+                'replacement_invoice_id' => $replacementInvoice->id,
                 'name' => $equalizationRemain->product->name,
                 'product_id' => $equalizationRemain->product_id,
                 'direction_id' => self::INCOMING,
@@ -73,7 +93,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord
 
             $expending = new self();
             $expending->setAttributes([
-                'replacement_invoice_id' => $replacementInvoice->guid,
+                'replacement_invoice_id' => $replacementInvoice->id,
                 'name' => $equalizationRemain->productReplacement->name,
                 'product_id' => $equalizationRemain->product_replacement_id,
                 'direction_id' => self::EXPENDING,
@@ -94,7 +114,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord
             if ($expending->validate() && $incoming->validate()) {
                 $expending->save() && $incoming->save();
             } else {
-                var_dump($expending->save() && $incoming->validate());
+                var_dump($expending->getErrors(), $incoming->getErrors());
             }
         }
     }
@@ -141,4 +161,9 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord
             'deleted_admin_id' => 'Deleted Admin ID',
         ];
     }
+
+    public function getUpdatedAdmin() {
+        return $this->hasOne(Admin::class, ['id' => 'updated_admin_id']);
+    }
+
 }
index b3d9bbc7f3711e882119cd6b3af051245d859d04..c65a01d8e869df09cb91e4e98491c872e9b44a07 100644 (file)
@@ -1 +1,102 @@
 <?php
+
+use kartik\grid\GridView;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\widgets\DetailView;
+use yii_app\records\ReplacementInvoiceProducts;
+
+/* @var $this yii\web\View */
+
+$this->title = 'Детали замены #' . $model->id;
+$this->params['breadcrumbs'][] = ['label' => 'Товары', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="replacement-invoice-view">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <!-- Детали товара -->
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'guid',
+            'status',
+            'store_id',
+            'store_guid',
+            'number',
+            'number_1c',
+            'date',
+            'comment',
+            'created_at::datetime',
+            [
+                'attribute' => 'updated_by',
+                'value' => function ($model) {
+                    return $model->createdBy->name_full;
+                }
+            ],
+        ],
+    ]) ?>
+
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            'name',
+            'product_id',
+            [
+                'attribute' => 'direction_id',
+                'value' => function ($model) {
+                    return $model->direction_id == ReplacementInvoiceProducts::EXPENDING ? 'Списываемый товар' : 'Приходуемый товар';
+                }
+            ],
+            'quantity',
+            [
+                'attribute' => 'price',
+                'format' => ['decimal', 2],
+            ],
+            [
+                'attribute' => 'price_retail',
+                'format' => ['decimal', 2],
+                'value' => function ($model) {
+                    return $model->price_retail ?? 'N/A';
+                },
+            ],
+            [
+                'attribute' => 'price_self_cost',
+                'format' => ['decimal', 2],
+                'value' => function ($model) {
+                    return $model->price_self_cost ?? 'N/A';
+                },
+            ],
+            [
+                'attribute' => 'summ',
+                'format' => ['decimal', 2],
+            ],
+            [
+                'attribute' => 'summ_retail',
+                'format' => ['decimal', 2],
+                'value' => function ($model) {
+                    return $model->summ_retail ?? 'N/A';
+                },
+            ],
+            [
+                'attribute' => 'summ_self_cost',
+                'format' => ['decimal', 2],
+                'value' => function ($model) {
+                    return $model->summ_self_cost ?? 'N/A';
+                },
+            ],
+            'active_product:boolean',
+            'updated_at:datetime',
+            [
+                'attribute' => 'updated_admin_id',
+                'value' => function ($model) {
+                    return $model->updatedAdmin->name_full;
+                },
+            ],
+            ['class' => 'yii\grid\ActionColumn'],
+        ],
+    ]); ?>
+</div>
index fdeb9fbee8c45d831a4438bea3d4bdd75a4c9ce9..1937192c39af814f4c68c40f63aa131deffc988b 100644 (file)
@@ -18,7 +18,8 @@ use yii\widgets\ActiveForm;
 $this->registerJsFile('/js/shift-transfer/replacement.js', ['position' => \yii\web\View::POS_END]);
 
 $usersOnStoreArray = \yii_app\records\Timetable::find()
-    ->andWhere(['store_id' => array_flip(\yii_app\records\CityStore::getAllActiveGuidId())[$shiftTransfer->store_guid]])
+    ->andWhere(['date' => $shiftTransfer->date])
+    ->andWhere(['store_id' => array_flip(array_filter(\yii_app\records\CityStore::getAllActiveGuidId(), 'is_string'))[$shiftTransfer->store_guid]])
     ->select(['admin_id'])
     ->column();