From: fomichev Date: Fri, 20 Dec 2024 09:26:54 +0000 (+0300) Subject: Добавление Название документа в 1с X-Git-Tag: 1.7~118^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e20726912cafac1366ea5f6656de7c034a6927fd;p=erp24_rep%2Fyii-erp24%2F.git Добавление Название документа в 1с --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 05e252ea..e16dc9f5 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -1119,10 +1119,10 @@ class DataController extends BaseController ); } } - if (!empty($waybillWriteOffsErp)) { + if (!empty($waybillWriteOffsErp) && isset($arr["held"]) && $arr["held"]) { /** @var WaybillWriteOffs $waybillWriteOffsErp */ $waybillWriteOffsErp->status = WriteOffsErp::STATUS_CREATED_1С; - $waybillWriteOffsErp->number_1c = $arr["number"] ?? ''; + $waybillWriteOffsErp->number_1c = $arr["name"] ?? ''; $waybillWriteOffsErp->save(); if ($waybillWriteOffsErp->getErrors()) { LogService::apiErrorLog( diff --git a/erp24/migrations/m241210_090957_waybill_write_offs.php b/erp24/migrations/m241210_090957_waybill_write_offs.php index c5d058a2..89b31980 100644 --- a/erp24/migrations/m241210_090957_waybill_write_offs.php +++ b/erp24/migrations/m241210_090957_waybill_write_offs.php @@ -26,7 +26,7 @@ class m241210_090957_waybill_write_offs extends Migration 'store_id' => $this->integer()->notNull()->comment('id магазина в ERP'), 'store_guid' => $this->string(100)->notNull()->comment('GUID магазина из 1с'), 'number' => $this->string(100)->notNull()->comment('Название документа'), - 'number_1c' => $this->string(100)->null()->comment('Название документа в 1с'), + 'number_1c' => $this->string(100)->null()->comment('Номер документа в 1с'), 'date' => $this->dateTime()->notNull()->comment('Дата документа'), 'comment' => $this->text()->null()->comment('Комментарий'), 'quantity' => $this->float()->notNull()->comment('Количество'), diff --git a/erp24/migrations/m241220_084001_add_name_1c_to_waybill_write_offs.php b/erp24/migrations/m241220_084001_add_name_1c_to_waybill_write_offs.php new file mode 100644 index 00000000..e70f54dd --- /dev/null +++ b/erp24/migrations/m241220_084001_add_name_1c_to_waybill_write_offs.php @@ -0,0 +1,54 @@ +db->getTableSchema(self::TABLE_NAME); + if ($tableSchema !== null && !isset($tableSchema->columns['name_1c'])) { + $this->addColumn( + self::TABLE_NAME, + 'name_1c', + $this->string(255) + ->null() + ->comment('Название документа в 1с') + ); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if ($tableSchema !== null && isset($tableSchema->columns['name_1c'])) { + $this->dropColumn(self::TABLE_NAME, 'name_1c'); + } + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m241220_084001_add_name_1c_to_waybill_write_offs cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/records/WaybillWriteOffs.php b/erp24/records/WaybillWriteOffs.php index 5f5b8f68..2d1d90ba 100644 --- a/erp24/records/WaybillWriteOffs.php +++ b/erp24/records/WaybillWriteOffs.php @@ -20,7 +20,8 @@ use yii_app\helpers\DataHelper; * @property int $store_id id магазина в ERP * @property string $store_guid GUID магазина из 1с * @property string $number Название документа - * @property string|null $number_1c Название документа в 1с + * @property string|null $number_1c Номер документа в 1с + * @property string|null $name_1c Название документа в 1с * @property string $date Дата документа * @property string|null $comment Комментарий * @property float $quantity Количество @@ -55,7 +56,7 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord [['shift_transfer_id', 'status', 'created_admin_id', 'updated_admin_id', 'store_id'], 'default', 'value' => null], [['shift_transfer_id', 'status', 'created_admin_id', 'updated_admin_id', 'store_id'], 'integer'], [['date', 'created_at', 'updated_at', 'send_at'], 'safe'], - [['comment', 'error_text'], 'string'], + [['comment', 'error_text', 'name_1c'], 'string'], [['quantity', 'summ', 'summ_self_cost'], 'number'], [['guid', 'store_guid', 'number', 'number_1c'], 'string', 'max' => 100], [['guid'], 'unique'], @@ -95,7 +96,8 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord 'store_id' => 'id магазина в ERP', 'store_guid' => 'GUID магазина из 1с', 'number' => 'Название документа', - 'number_1c' => 'Название документа в 1с', + 'number_1c' => 'Номер документа в 1с', + 'name_1c' => 'Название документа в 1с', 'date' => 'Дата документа', 'comment' => 'Комментарий', 'quantity' => 'Количество', @@ -133,9 +135,11 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord WaybillWriteOffsProducts::setData($model, $shiftTransfer); - if (!WaybillWriteOffsProducts::find() + if ( + !WaybillWriteOffsProducts::find() ->andWhere(['waybill_write_offs_id' => $model->id]) - ->exists()) { + ->exists() + ) { $model->delete(); return; } @@ -157,7 +161,6 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord 'summ_self_cost' => $summaries['total_summ_self_cost'] ]); } - } catch (\Exception $exception) { throw new \Exception($exception); } diff --git a/erp24/views/waybill-write-offs/view.php b/erp24/views/waybill-write-offs/view.php index 885d0e8c..d9d2b147 100644 --- a/erp24/views/waybill-write-offs/view.php +++ b/erp24/views/waybill-write-offs/view.php @@ -25,7 +25,13 @@ $this->params['breadcrumbs'][] = $this->title; 'id', 'guid', 'number', - 'date', + [ + 'label' => 'Дата документа', + 'attribute' => 'date', + 'value' => function ($model) { + return date('d-m-Y H:i:s', strtotime($model->date)); + } + ], [ 'label' => 'Магазин', 'attribute' => 'store_id', @@ -48,8 +54,19 @@ $this->params['breadcrumbs'][] = $this->title; 'label' => 'Текст ошибки', 'attribute' => 'error_text', 'value' => function ($model) { - return $model->status == 8 ? $model->error_text : ''; - } + return $model->status == \yii_app\records\WriteOffsErp::STATUS_ERROR_1С ? $model->error_text : ''; + }, + 'visible' => $model->status == \yii_app\records\WriteOffsErp::STATUS_ERROR_1С, + ], + [ + 'label' => 'Название документа в 1С', + 'attribute' => 'name_1c', + 'value' => function ($model) { + return + $model->status == \yii_app\records\WriteOffsErp::STATUS_CREATED_1С ? + $model->name_1c : ''; + }, + 'visible' => $model->status == \yii_app\records\WriteOffsErp::STATUS_CREATED_1С, ], [ 'label' => 'Номер документа в 1С', @@ -58,11 +75,16 @@ $this->params['breadcrumbs'][] = $this->title; return $model->status == \yii_app\records\WriteOffsErp::STATUS_CREATED_1С ? $model->number_1c : ''; - } + }, + 'visible' => $model->status == \yii_app\records\WriteOffsErp::STATUS_CREATED_1С && isset($model->number_1c), ], [ 'label' => 'Отправлено в 1С', 'attribute' => 'send_at', + 'visible' => $model->status == \yii_app\records\WriteOffsErp::STATUS_SEND, + 'value' => function ($model) { + return date('d-m-Y H:i:s', strtotime($model->send_at)); + } ], [ 'label' => 'Создан пользователем', @@ -71,9 +93,20 @@ $this->params['breadcrumbs'][] = $this->title; return Admin::findOne([$model->created_admin_id])->name; } ], - - 'created_at', - 'updated_at', + [ + 'label' => 'Дата создания', + 'attribute' => 'created_at', + 'value' => function ($model) { + return date('d-m-Y H:i:s', strtotime($model->created_at)); + } + ], + [ + 'label' => 'Дата обновления', + 'attribute' => 'updated_at', + 'value' => function ($model) { + return $model->updated_at ? date('d-m-Y H:i:s', strtotime($model->updated_at)) : ''; + } + ], ], ]) ?>