]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-256 Сделать отправку документов Пересортица в 1с
authormarina <m.zozirova@gmail.com>
Wed, 18 Dec 2024 10:03:55 +0000 (13:03 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 18 Dec 2024 10:03:55 +0000 (13:03 +0300)
erp24/api2/controllers/DataController.php
erp24/controllers/ShiftTransferController.php
erp24/records/ReplacementInvoice.php
erp24/views/replacement-invoice/view.php

index 5428a4243302de4d1a6d3fc17a4dca468734ee70..34563df8e3c08fabfc4cc6ccfe2d2096b3a83b62 100644 (file)
@@ -459,7 +459,7 @@ class DataController extends BaseController
 
         try {
             $replacementInvoice = ReplacementInvoice::find()
-                ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ'])
+                ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ_self_cost'])
                 ->andWhere(['status' => WriteOffsErp::STATUS_CONFIRM])
                 ->indexBy('id')
                 ->asArray()
@@ -470,25 +470,34 @@ class DataController extends BaseController
                 $shiftTransferIds = array_column($replacementInvoice, 'shift_transfer_id');
 
                 $products = EqualizationRemains::find()
-                    ->where(['in', 'shift_transfer_id', $shiftTransferIds])
+                    ->alias('er')
+                    ->select([
+                        're.id as replacement_invoice_id',
+                        'er.product_id as product_id',
+                        'er.product_replacement_id as new_product_id',
+                        'er.product_replacement_count as quantity',
+                        'er.product_self_cost as price',
+                        'er.product_replacement_self_cost as new_price'])
+                    ->where(['in', 'er.shift_transfer_id', $shiftTransferIds])
+                    ->leftJoin('replacement_invoice re', 're.shift_transfer_id = er.shift_transfer_id')
                     ->asArray()
                     ->all();
 
                 $replacementInvoiceProducts = [];
 
                 foreach ($products as $product) {
-                    $replacementInvoiceProducts[$product['']][] = [
-                        'product_id' => $product->product_id,
+                    $replacementInvoiceProducts[$product['replacement_invoice_id']][] = [
+                        'product_id' => $product['product_id'],
                         'color' => Products1cAdditionalCharacteristics::findOne([
                                 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
-                                'product_id' => $product->product_id])->value ?? '',
-                        'price' => $product->product_price,
-                        'new_product_id' => $product->product_replacement_id,
+                                'product_id' => $product['product_id']])->value ?? '',
+                        'price' => $product['price'],
+                        'new_product_id' => $product['new_product_id'],
                         'new_color' => Products1cAdditionalCharacteristics::findOne([
                                 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
-                                'product_id' => $product->product_replacement_id])->value ?? '',
-                        'new_price' => $product->product_replacement_price,
-                        'quantity' => $product->product_replacement_count,
+                                'product_id' => $product['new_product_id']])->value ?? '',
+                        'new_price' => $product['new_price'],
+                        'quantity' => $product['quantity'],
                     ];
                 }
 
@@ -510,19 +519,17 @@ class DataController extends BaseController
                     $replacementInvoiceResult[] = [
                         'id' => $row['guid'],
                         'store_id' => $row['store_guid'],
-                        'type' => 'ревизия при передаче смены',
-                        'cause' => 'Документ пересортицы при передаче смены в ERP ' . $row['number'],
-                        'items' => $row['items'],
-                        'summ' => $row['summ'],
+                        'type' => 'ревизия пересортица при передаче смены',
+                        'cause' => 'Документ пересортица при передаче смены в ERP ' . $row['number'],
                         'comment' => $row['comment'],
+                        'items' => $row['items'],
+
                     ];
                 }
             }
-
         } catch (Exception $e3) {
             file_put_contents(self::OUT_DIR . '/log_created_replacement_invoice_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND);
         }
-
         return compact('replacementInvoice', 'replacementInvoicesIds', 'replacementInvoiceResult');
     }
 
index 63e7333f73e87139b1dd3174c97e48cdd2ab6623..faecd631c0836490facdd7151fd53fa69965d832 100644 (file)
@@ -298,11 +298,11 @@ class ShiftTransferController extends Controller
                 ShiftRemains::updateAll(['type' => ShiftRemains::ARCHIVE_RECORD], ['shift_transfer_id' => $id]);
                 ReplacementInvoice::setData($model);
                 StoreBalance::setData($model);
-            } elseif ($action === 'save') {
-                $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]);
                 WaybillIncoming::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
                 WaybillWriteOffs::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
                 ReplacementInvoice::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
+            } elseif ($action === 'save') {
+                $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]);
             } elseif ($action == 'recalculate') {
                 EqualizationRemains::setData($model);
                 Yii::$app->session->setFlash('success', 'Таблица замен успешно перерасчитана');
index 7510c55e02f8116159e25e6bfb0f9b2614d4f9af..6db5c212f239bbdfbfa0aa456fa87cc2c0709973 100644 (file)
@@ -100,12 +100,12 @@ class ReplacementInvoice extends \yii\db\ActiveRecord
 
             ReplacementInvoiceProducts::setData($model, $shiftTransfer);
 
-            $summaries = ReplacementInvoiceProducts::find()
-                ->andWhere(['replacement_invoice_id' => $model->id])
+            $summaries = EqualizationRemains::find()
+                ->andWhere(['shift_transfer_id' => $model->shift_transfer_id])
                 ->select([
-                    'total_product_count' => 'sum(product_count)',
-                    'total_summ' => 'sum(summ)',
-                    'total_summ_self_cost' => 'sum(summ_self_cost)'
+                    'total_product_count' => 'sum(product_replacement_count)',
+                    'total_summ' => 'sum(balance)',
+                    'total_summ_self_cost' => 'sum(balance_self_cost)'
                 ])
                 ->asArray()
                 ->one();
index 66c786fb04f834fcdb279cf24f16aa00fc568866..3a5939da2f3178a18873aa6cf8bc75c8177ba685 100644 (file)
@@ -25,9 +25,6 @@ $this->params['breadcrumbs'][] = $this->title;
             [
                 'format' => 'raw',
                 'attribute' => 'status',
-                'value' => function ($model) {
-                    return $model->status == \yii_app\records\ReplacementInvoice::REPLACEMENT_ACTIONS ? 'Действия по замене' : $model->status;
-                }
             ],
             [
                 'format' => 'raw',