From: marina Date: Thu, 19 Dec 2024 08:43:16 +0000 (+0300) Subject: ERP-256 Сделать отправку документов Пересортица в 1с X-Git-Tag: 1.7~133^2~3 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=4612ec90abd49276e84e9f49a159cd9279d0d36e;p=erp24_rep%2Fyii-erp24%2F.git ERP-256 Сделать отправку документов Пересортица в 1с --- diff --git a/erp24/records/ReplacementInvoice.php b/erp24/records/ReplacementInvoice.php index 7b5629fe..5e5f78a6 100644 --- a/erp24/records/ReplacementInvoice.php +++ b/erp24/records/ReplacementInvoice.php @@ -111,6 +111,13 @@ class ReplacementInvoice extends \yii\db\ActiveRecord ->asArray() ->one(); + if (!ReplacementInvoiceProducts::find() + ->andWhere(['replacement_invoice_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + if ($summaries) { $model->updateAttributes([ 'quantity' => $summaries['total_product_count'], diff --git a/erp24/records/StoreBalance.php b/erp24/records/StoreBalance.php index 30743061..10f5ef1b 100644 --- a/erp24/records/StoreBalance.php +++ b/erp24/records/StoreBalance.php @@ -79,8 +79,75 @@ class StoreBalance extends \yii\db\ActiveRecord 'type_id' => self::REPLACEMENT_ACTIONS, ]); + $incomingData = WaybillIncomingProducts::find() + ->alias('wip') + ->where(['waybill_incoming_id' => WaybillIncoming::findOne(['shift_transfer_id' => $shiftTransfer->id])->id ?? '']) + ->leftJoin('products_1c AS product', 'product.id = wip.product_id') + ->select([ + 'wip.product_id', + 'product.name AS product_name', + 'wip.product_count', + 'wip.product_price', + 'wip.product_self_cost', + 'wip.summ', + 'wip.summ_self_cost' + ]) + ->asArray() + ->all(); + + + $incoming = new self(); + $incoming->setAttributes([ + 'store_id' => $shiftTransfer->store_guid, + 'shift_transfer_id' => $shiftTransfer->id, + 'date' => $shiftTransfer->date, + 'amount' => WaybillIncoming::find() + ->where(['shift_transfer_id' => $shiftTransfer->id]) + ->select(['summ']) + ->scalar() ?? '', + 'status_id' => self::STATUS_NEW, + 'comment' => $shiftTransfer->comment, + 'json' => json_encode($incomingData, JSON_UNESCAPED_UNICODE), + 'type_id' => self::REPLACEMENT_ACTIONS, + ]); + + $writeOffsData = WaybillWriteOffsProducts::find() + ->alias('wwop') + ->where(['waybill_write_offs_id' => WaybillWriteOffs::findOne(['shift_transfer_id' => $shiftTransfer->id])->id ?? '']) + ->leftJoin('products_1c AS product', 'product.id = wwop.product_id') + ->select([ + 'wwop.product_id', + 'product.name AS product_name', + 'wwop.product_count', + 'wwop.product_price', + 'wwop.product_self_cost', + 'wwop.summ', + 'wwop.summ_self_cost' + ]) + ->asArray() + ->all(); + + + $writeOffs = new self(); + $writeOffs->setAttributes([ + 'store_id' => $shiftTransfer->store_guid, + 'shift_transfer_id' => $shiftTransfer->id, + 'date' => $shiftTransfer->date, + 'amount' => WaybillWriteOffs::find() + ->where(['shift_transfer_id' => $shiftTransfer->id]) + ->select(['summ']) + ->scalar() ?? '', + 'status_id' => self::STATUS_NEW, + 'comment' => $shiftTransfer->comment, + 'json' => json_encode($writeOffsData, JSON_UNESCAPED_UNICODE), + 'type_id' => self::REPLACEMENT_ACTIONS, + ]); + + try { $model->save(); + $incoming->save(); + $writeOffs->save(); } catch (\Exception $exception) { throw new Exception($exception); } diff --git a/erp24/records/WaybillIncoming.php b/erp24/records/WaybillIncoming.php index 3ef5dc50..ffef3e74 100644 --- a/erp24/records/WaybillIncoming.php +++ b/erp24/records/WaybillIncoming.php @@ -138,6 +138,13 @@ class WaybillIncoming extends \yii\db\ActiveRecord WaybillIncomingProducts::setData($model, $shiftTransfer); + if (!WaybillIncomingProducts::find() + ->andWhere(['waybill_incoming_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + $summaries = WaybillIncomingProducts::find() ->andWhere(['waybill_incoming_id' => $model->id]) ->select([ diff --git a/erp24/records/WaybillWriteOffs.php b/erp24/records/WaybillWriteOffs.php index b93fb1d1..00eca977 100644 --- a/erp24/records/WaybillWriteOffs.php +++ b/erp24/records/WaybillWriteOffs.php @@ -134,6 +134,13 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord WaybillWriteOffsProducts::setData($model, $shiftTransfer); + if (!WaybillWriteOffsProducts::find() + ->andWhere(['waybill_write_offs_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + $summaries = WaybillWriteOffsProducts::find() ->andWhere(['waybill_write_offs_id' => $model->id]) ->select([ diff --git a/erp24/views/replacement-invoice/index.php b/erp24/views/replacement-invoice/index.php index 74ad3d41..38885ddd 100644 --- a/erp24/views/replacement-invoice/index.php +++ b/erp24/views/replacement-invoice/index.php @@ -33,6 +33,12 @@ $this->params['breadcrumbs'][] = $this->title; } ], 'number', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \yii_app\records\WriteOffsErp::STATUSES[$model->status]; + } + ], 'date', 'created_at', [ diff --git a/erp24/views/replacement-invoice/view.php b/erp24/views/replacement-invoice/view.php index 3a5939da..fea91ded 100644 --- a/erp24/views/replacement-invoice/view.php +++ b/erp24/views/replacement-invoice/view.php @@ -35,10 +35,23 @@ $this->params['breadcrumbs'][] = $this->title; ], 'number', 'number_1c', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \yii_app\records\WriteOffsErp::STATUSES[$model->status]; + } + ], [ 'attribute' => 'date', 'format' => 'datetime', ], + [ + 'label' => 'Текст ошибки', + 'attribute' => 'error_text', + 'value' => function ($model) { + return $model->status == 8 ? $model->error_text : 'Нет ошибки'; + } + ], 'comment', [ 'attribute' => 'created_at', diff --git a/erp24/views/shift-transfer/_replacement.php b/erp24/views/shift-transfer/_replacement.php index e429a6d3..45839726 100644 --- a/erp24/views/shift-transfer/_replacement.php +++ b/erp24/views/shift-transfer/_replacement.php @@ -320,7 +320,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'label' => 'Сумма', 'attribute' => 'summ', 'pageSummary' => true, - 'footer' => Html::tag('b', 'Недостача: ') . '  ' . $writeOffsBalance + 'footer' => $writeOffsBalance != 0 ? Html::tag('b', 'Недостача: ') . '  ' . $writeOffsBalance : '' ], ], 'showPageSummary' => true, @@ -363,7 +363,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'label' => 'Сумма', 'attribute' => 'summ', 'pageSummary' => true, - 'footer' => Html::tag('b', 'Излишек: ') . '  ' . $incomingBalance, + 'footer' => $incomingBalance != 0 ? Html::tag('b', 'Излишек: ') . '  ' . $incomingBalance : '', ], ], 'showPageSummary' => true,