--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
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
<?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
<?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>
<?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