]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-152] Доработка отдела storage feature_smirnov_erp-152_storage
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 22 Aug 2024 15:42:45 +0000 (18:42 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 22 Aug 2024 15:51:05 +0000 (18:51 +0300)
erp24/actions/storage/AjaxBalancesInGroupAction.php [new file with mode: 0644]
erp24/actions/storage/IndexAction.php [new file with mode: 0644]
erp24/actions/storage/StoreAction.php [new file with mode: 0644]
erp24/controllers/StorageController.php
erp24/views/storage/ajax-balances-in-group.php
erp24/views/storage/index.php
erp24/views/storage/store.php

diff --git a/erp24/actions/storage/AjaxBalancesInGroupAction.php b/erp24/actions/storage/AjaxBalancesInGroupAction.php
new file mode 100644 (file)
index 0000000..0a9c9d0
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+namespace yii_app\actions\storage;
+
+use Yii;
+use yii\base\Action;
+use yii_app\records\Products1c;
+
+class AjaxBalancesInGroupAction extends Action
+{
+    public function run() {
+        $store_id = Yii::$app->request->post('store_id');
+        $parent_id = Yii::$app->request->post('parent_id');
+
+        $data = Products1c::find()->alias('p1c')->select(['p1c.name as name', 'p.price as price', 'b.quantity as quantity', 'b.reserv as reserv'])
+            ->leftJoin('prices p', 'p.product_id = p1c.id')->leftJoin('balances b', 'b.store_id = \'' . $store_id . '\' and b.product_id = p1c.id')
+            ->where(['p1c.tip' => 'products'])->andWhere(['p1c.parent_id' => $parent_id])
+            ->asArray()->all();
+
+        return $this->controller->renderPartial('ajax-balances-in-group',
+            compact('data'));
+    }
+}
\ No newline at end of file
diff --git a/erp24/actions/storage/IndexAction.php b/erp24/actions/storage/IndexAction.php
new file mode 100644 (file)
index 0000000..27678bb
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace yii_app\actions\storage;
+
+use Yii;
+use yii\base\Action;
+use yii\base\DynamicModel;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Balances;
+use yii_app\records\Products1c;
+
+class IndexAction extends Action
+{
+    public function run() {
+        $model = DynamicModel::validateData(['store_id' => null], [['store_id', 'safe']]);
+
+        $model->load(Yii::$app->request->get());
+
+        $products1c = null;
+        if ($model->store_id) {
+            $products1c = Products1c::find()->where(['id' => $model->store_id])->one();
+        }
+
+        $stores = ArrayHelper::map(Products1c::find()->where(['tip' => 'city_store', 'view' => 1])->orderBy(['name' => SORT_ASC])->all(),"id", "name");
+
+        $products = ArrayHelper::map(Products1c::find()->where(['tip' => 'products'])->all(),"id", "name");
+
+        $balances = Balances::find()->select(['product_id', 'quantity', 'reserv'])->where(['store_id' => $model->store_id])->orderBy(['quantity' => SORT_DESC])->all();
+
+        return $this->controller->render('index',
+            compact('products1c', 'stores', 'model', 'products', 'balances'));
+    }
+}
\ No newline at end of file
diff --git a/erp24/actions/storage/StoreAction.php b/erp24/actions/storage/StoreAction.php
new file mode 100644 (file)
index 0000000..79cdf3e
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace yii_app\actions\storage;
+
+use Yii;
+use yii\base\Action;
+use yii\base\DynamicModel;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Products1c;
+
+class StoreAction extends Action
+{
+    public function run() {
+
+        $model = DynamicModel::validateData(['store_id' => null], [['store_id', 'safe']]);
+
+        $model->load(Yii::$app->request->get());
+
+        $products1c = null;
+        if ($model->store_id) {
+            $products1c = Products1c::find()->where(['id' => $model->store_id])->one();
+        }
+
+        $stores = ArrayHelper::map(Products1c::find()->where(['tip' => 'city_store', 'view' => 1])->orderBy(['name' => SORT_ASC])->all(),"id", "name");
+
+        $productGroups = Products1c::find()->where(['tip' => 'products_group', 'view' => 1])->orderBy(['name' => SORT_ASC])->all();
+        $groups = ArrayHelper::map($productGroups, 'id', 'name');
+        $groups_arr = [];
+        foreach ($productGroups as $productGroup) {
+            $groups_arr[$productGroup->parent_id][$productGroup->id] = $productGroup;
+        }
+
+
+        return $this->controller->render('store',
+            compact('model', 'stores', 'products1c', 'groups_arr'));
+    }
+}
\ No newline at end of file
index dc4dda8ed7dbc43e2e0dbc09769b4a0e9529b484..a7196a228164073e4332b95e117ac840e78ead24 100644 (file)
@@ -6,7 +6,12 @@ use yii\web\Controller;
 
 class StorageController extends Controller
 {
-    public function actionIndex() { return $this->render('index'); }
-    public function actionStore() { return $this->render('store'); }
-    public function actionAjaxBalancesInGroup() { return $this->renderPartial('ajax-balances-in-group'); }
+    public function actions()
+    {
+        return [
+            'index' => \yii_app\actions\storage\IndexAction::class,
+            'store' => \yii_app\actions\storage\StoreAction::class,
+            'ajax-balances-in-group' => \yii_app\actions\storage\AjaxBalancesInGroupAction::class,
+        ];
+    }
 }
\ No newline at end of file
index 26b42f0d679040d6d97d7437ea8d4dc4f57e4ec6..3c3073061fa73f9f22cba48d1849bbf2b9644941 100644 (file)
@@ -1,5 +1,24 @@
 <?php
 
-chdir(__DIR__ . '/../../');
+/** @var $data array */
 
-include 'modul/storage/ajax_balances_in_group.php';
\ No newline at end of file
+?>
+
+<table>
+    <tbody>
+        <?php foreach ($data as $row): ?>
+            <tr>
+                <td><?= $row['name'] ?></td>
+                <td>
+                    <b><?= $row['quantity'] ?></b>
+                    <?php if (!empty($row['reserv'])): ?>
+                        (<?= $row['reserv'] ?>)
+                    <?php endif; ?>
+                </td>
+                <td>
+                    <?= $row['price'] ?>
+                </td>
+            </tr>
+        <?php endforeach; ?>
+    </tbody>
+</table>
\ No newline at end of file
index 095d83142a298ceb058b3fdaf438993af1a2d197..e61610d0a0546f7ab9b0d9ca329fad49c245dd14 100644 (file)
@@ -1,5 +1,73 @@
 <?php
 
-chdir(__DIR__ . '/../../');
+use \yii\helpers\Html;
+use \kartik\select2\Select2;
+use \yii\widgets\ActiveForm;
 
-include 'modul/storage/index.php';
\ No newline at end of file
+/** @var $products1c \yii_app\records\Products1c */
+/** @var $model \yii\base\DynamicModel */
+/** @var $stores array */
+/** @var $balances array */
+/** @var $products array */
+
+?>
+
+<div class="storageIndex m-5">
+    <?php if ($products1c): ?>
+        <div class="page-header">
+            <h1 class="page-title m-0 text-primary">Складские остатки <?= $products1c->name ?></h1>
+        </div>
+    <?php endif; ?>
+    <?php $form = ActiveForm::begin(['method' => 'GET', "action" => "/storage"]) ?>
+
+    <div class="row">
+        <div class="col-2">
+                <?= $form->field($model, 'store_id')->widget(Select2::class, [
+                    'data' => $stores,
+                    'language' => 'ru',
+                    'options' => ['placeholder' => 'Магазин...', 'onchange' => 'this.form.submit()'],
+                    'pluginOptions' => [
+                        'allowClear' => true
+                    ],
+                ])->label(false) ?>
+        </div>
+    </div>
+
+    <?php ActiveForm::end() ?>
+
+    <?= Html::a('Остатки по группам как в 1с', '/storage/store/', ['class' => 'btn btn-info']) ?>
+
+    <?php if ($products1c): ?>
+    <div class="row">
+        <div class="col-4">
+            <div class="table-responsive">
+                <table class="table table-sm table-stripped table-hover">
+                    <thead>
+                        <tr>
+                            <th width=70>Остаток</th>
+                            <th width=60>Резерв</th>
+                            <th>Наименование</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                        <?php foreach($balances as $balance): ?>
+                            <tr>
+                                <td>
+                                    <b><?= $balance->quantity ?></b>
+                                </td>
+                                <td>
+                                    <?= $balance->reserv ?>
+                                </td>
+                                <td>
+                                    <?= $products[$balance->product_id] ?>
+                                </td>
+                            </tr>
+                        <?php endforeach; ?>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+    <?php endif; ?>
+
+</div>
index 4a1249c843481cbb0e1daab37c4fc44fb747b1d7..1c6ce7326a33da60d254bc7c40361fb72e391f56 100644 (file)
@@ -1,5 +1,83 @@
 <?php
 
-chdir(__DIR__ . '/../../');
+use \yii_app\records\Products1c;
+use \kartik\select2\Select2;
+use \yii\widgets\ActiveForm;
+use \yii\base\DynamicModel;
 
-include 'modul/storage/store.php';
\ No newline at end of file
+/** @var $model DynamicModel */
+/** @var $stores array */
+/** @var $store_id string */
+/** @var $products1c Products1c */
+/** @var $groups_arr array */
+
+function build_tree($cats, $parent_id, $store_id, $only_parent = false) {
+    if (is_array($cats) and isset($cats[$parent_id])) {
+        $tree = '<ul style="margin-left:30px;" class="">';
+        if (!$only_parent) {
+            foreach ($cats[$parent_id] as $cat) {
+                $tree .= '<li class="grup"><table class="m-0 table table-hover"><tbody>';
+                $tree .= '<tr id="tr_'.$cat['id'].'"><td><span class="btn btn-info btn-sm me-2"
+                    onclick="if (!document.getElementById(\'trr_' . $cat['id'] . '\')) ajax_balances_in_group(\''.$cat['id'].'\',\''.$store_id.'\');
+                    $(\'#trr_'.$cat['id'].'\').toggle();">+</span>
+                    <b>'.$cat['name'].'</b>
+                </td>';
+
+                $tree .= '</tr></tbody></table>';
+                $tree .=  build_tree($cats, $cat['id'], $store_id);
+                $tree .= '</li>';
+            }
+        }
+        $tree .= '</ul>';
+        return $tree;
+    }
+    return null;
+}
+
+?>
+
+<div class="storageStore m-5">
+
+    <?php $form = ActiveForm::begin(['method' => 'GET', "action" => "/storage/store"]) ?>
+
+    <div class="row">
+        <div class="col-2">
+            <?= $form->field($model, 'store_id')->widget(Select2::class, [
+                'data' => $stores,
+                'language' => 'ru',
+                'options' => ['placeholder' => 'Магазин...', 'onchange' => 'this.form.submit()'],
+                'pluginOptions' => [
+                    'allowClear' => true
+                ],
+            ])->label(false) ?>
+        </div>
+    </div>
+
+    <?php ActiveForm::end() ?>
+
+    <?php if ($products1c): ?>
+        <h1>Остатки в 1с <?= $products1c->name ?></h1>
+        <div class="groups">
+            <div class="table-responsive">
+                <?= build_tree($groups_arr,"", $products1c->id) ?>
+            </div>
+        </div>
+    <?php endif; ?>
+</div>
+
+<script>
+    function ajax_balances_in_group(parent_id, store_id){
+        const param21 = $('meta[name=csrf-param]').attr('content');
+        const token21 = $('meta[name=csrf-token]').attr('content');
+
+        $.ajax({
+            url: '/storage/ajax-balances-in-group/',
+            method: 'post',
+            dataType: 'html',
+            data: {parent_id, store_id, [param21]: token21},
+            success: function(data){
+                $('#tr_'+parent_id+'').after('<tr id=\"trr_'+parent_id+'\"><td colspan=2>'+data+'</td></tr>');
+            }
+        });
+    }
+</script>
\ No newline at end of file