'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);
}
],
'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',
'label' => 'Сумма',
'attribute' => 'summ',
'pageSummary' => true,
- 'footer' => Html::tag('b', 'Недостача: ') . ' ' . $writeOffsBalance
+ 'footer' => $writeOffsBalance != 0 ? Html::tag('b', 'Недостача: ') . ' ' . $writeOffsBalance : ''
],
],
'showPageSummary' => true,
'label' => 'Сумма',
'attribute' => 'summ',
'pageSummary' => true,
- 'footer' => Html::tag('b', 'Излишек: ') . ' ' . $incomingBalance,
+ 'footer' => $incomingBalance != 0 ? Html::tag('b', 'Излишек: ') . ' ' . $incomingBalance : '',
],
],
'showPageSummary' => true,