From: marina Date: Tue, 3 Dec 2024 11:58:58 +0000 (+0300) Subject: ERP-243 Действия по замене (II этап) X-Git-Tag: 1.7~203^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=664c11cd1e71151264293f9e6f71efc23929e3a6;p=erp24_rep%2Fyii-erp24%2F.git ERP-243 Действия по замене (II этап) --- diff --git a/erp24/controllers/ReplacementInvoiceController.php b/erp24/controllers/ReplacementInvoiceController.php index 79411bc8..156b094c 100644 --- a/erp24/controllers/ReplacementInvoiceController.php +++ b/erp24/controllers/ReplacementInvoiceController.php @@ -44,14 +44,14 @@ class ReplacementInvoiceController extends Controller { $model = $this->findModel($id); - $products = new ActiveDataProvider([ + $dataProvider = new ActiveDataProvider([ 'query' => ReplacementInvoiceProducts::find() - ->andWhere(['replacement_invoice_id' => $model->guid]) + ->andWhere(['replacement_invoice_id' => $id]) ]); return $this->render('view', [ 'model' => $model, - 'products' =>$products + 'dataProvider' =>$dataProvider ]); } diff --git a/erp24/records/EqualizationRemains.php b/erp24/records/EqualizationRemains.php index 201827bc..90cd3c32 100644 --- a/erp24/records/EqualizationRemains.php +++ b/erp24/records/EqualizationRemains.php @@ -67,7 +67,6 @@ class EqualizationRemains extends \yii\db\ActiveRecord [['product_count', 'product_price', 'product_self_cost', 'product_replacement_count', 'product_replacement_price', 'product_replacement_self_cost', 'balance', 'balance_self_cost'], 'required'], [['created_at', 'updated_at'], 'safe'], [['product_id', 'product_replacement_id'], 'string', 'max' => 255], - [[]] ]; } diff --git a/erp24/records/ReplacementInvoice.php b/erp24/records/ReplacementInvoice.php index 8518f2ad..5d017997 100644 --- a/erp24/records/ReplacementInvoice.php +++ b/erp24/records/ReplacementInvoice.php @@ -3,6 +3,10 @@ namespace yii_app\records; use Yii; +use yii\behaviors\BlameableBehavior; +use yii\behaviors\TimestampBehavior; +use yii\db\Expression; +use yii_app\helpers\DataHelper; /** * This is the model class for table "replacement_invoice". @@ -30,6 +34,7 @@ class ReplacementInvoice extends \yii\db\ActiveRecord { public const ACTIVE = 1; public const DELETE = 0; + public const REPLACEMENT_ACTIONS = 2; /** * {@inheritdoc} */ @@ -38,6 +43,23 @@ class ReplacementInvoice extends \yii\db\ActiveRecord return 'replacement_invoice'; } + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + [ + 'class' => BlameableBehavior::class, + 'createdByAttribute' => 'created_admin_id', + 'updatedByAttribute' => 'updated_admin_id', + ], + ]; + } + /** * {@inheritdoc} */ @@ -56,14 +78,16 @@ class ReplacementInvoice extends \yii\db\ActiveRecord public static function setData($shiftTransfer) { - $storeId = array_flip(CityStore::getAllActiveGuidId())[$shiftTransfer->store_guid]; + $storeId = array_flip(array_map('strval', CityStore::getAllActiveGuidId()))[$shiftTransfer->store_guid]; + $guid = DataHelper::createGuidMy(); $model = new self(); $model->setAttributes([ - 'guid' => GUID(), - 'status' => 2, + 'guid' => $guid, + 'status' => self::REPLACEMENT_ACTIONS, 'created_admin_id' => $shiftTransfer->end_shift_admin_id, 'updated_admin_id' => $shiftTransfer->start_shift_admin_id, 'confirm_admin_id' => $shiftTransfer->start_shift_admin_id, + 'number' => $guid, 'store_id' => $storeId, 'store_guid' => $shiftTransfer->store_guid, 'date' => $shiftTransfer->date, @@ -76,7 +100,7 @@ class ReplacementInvoice extends \yii\db\ActiveRecord $model->save(); ReplacementInvoiceProducts::setData($model, $shiftTransfer); } else { - var_dump($model->errors); + var_dump($model->getErrors()); } } @@ -112,4 +136,9 @@ class ReplacementInvoice extends \yii\db\ActiveRecord { return $this->hasMany(ReplacementInvoiceProducts::class, ['replacement_invoice_id' => 'id']); } + + + public function getCreatedBy() { + return $this->hasOne(Admin::class, ['id' => 'created_by']); + } } diff --git a/erp24/records/ReplacementInvoiceProducts.php b/erp24/records/ReplacementInvoiceProducts.php index fb765eff..2f8065e7 100644 --- a/erp24/records/ReplacementInvoiceProducts.php +++ b/erp24/records/ReplacementInvoiceProducts.php @@ -3,6 +3,9 @@ namespace yii_app\records; use Yii; +use yii\behaviors\BlameableBehavior; +use yii\behaviors\TimestampBehavior; +use yii\db\Expression; /** * This is the model class for table "replacement_invoice_products". @@ -38,6 +41,23 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord //Приходуемый товар (Товар, который надо заменить) public const INCOMING = 2; + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + [ + 'class' => BlameableBehavior::class, + 'createdByAttribute' => 'updated_admin_id', + 'updatedByAttribute' => 'created_admin_id', + ], + ]; + } + /** * {@inheritdoc} @@ -53,7 +73,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord foreach ($equalizationRemains as $equalizationRemain) { $incoming = new self(); $incoming->setAttributes([ - 'replacement_invoice_id' => $replacementInvoice->guid, + 'replacement_invoice_id' => $replacementInvoice->id, 'name' => $equalizationRemain->product->name, 'product_id' => $equalizationRemain->product_id, 'direction_id' => self::INCOMING, @@ -73,7 +93,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord $expending = new self(); $expending->setAttributes([ - 'replacement_invoice_id' => $replacementInvoice->guid, + 'replacement_invoice_id' => $replacementInvoice->id, 'name' => $equalizationRemain->productReplacement->name, 'product_id' => $equalizationRemain->product_replacement_id, 'direction_id' => self::EXPENDING, @@ -94,7 +114,7 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord if ($expending->validate() && $incoming->validate()) { $expending->save() && $incoming->save(); } else { - var_dump($expending->save() && $incoming->validate()); + var_dump($expending->getErrors(), $incoming->getErrors()); } } } @@ -141,4 +161,9 @@ class ReplacementInvoiceProducts extends \yii\db\ActiveRecord 'deleted_admin_id' => 'Deleted Admin ID', ]; } + + public function getUpdatedAdmin() { + return $this->hasOne(Admin::class, ['id' => 'updated_admin_id']); + } + } diff --git a/erp24/views/replacement-invoice/view.php b/erp24/views/replacement-invoice/view.php index b3d9bbc7..c65a01d8 100644 --- a/erp24/views/replacement-invoice/view.php +++ b/erp24/views/replacement-invoice/view.php @@ -1 +1,102 @@ title = 'Детали замены #' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Товары', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + + $model, + 'attributes' => [ + 'id', + 'guid', + 'status', + 'store_id', + 'store_guid', + 'number', + 'number_1c', + 'date', + 'comment', + 'created_at::datetime', + [ + 'attribute' => 'updated_by', + 'value' => function ($model) { + return $model->createdBy->name_full; + } + ], + ], + ]) ?> + + + $dataProvider, + 'columns' => [ + 'name', + 'product_id', + [ + 'attribute' => 'direction_id', + 'value' => function ($model) { + return $model->direction_id == ReplacementInvoiceProducts::EXPENDING ? 'Списываемый товар' : 'Приходуемый товар'; + } + ], + 'quantity', + [ + 'attribute' => 'price', + 'format' => ['decimal', 2], + ], + [ + 'attribute' => 'price_retail', + 'format' => ['decimal', 2], + 'value' => function ($model) { + return $model->price_retail ?? 'N/A'; + }, + ], + [ + 'attribute' => 'price_self_cost', + 'format' => ['decimal', 2], + 'value' => function ($model) { + return $model->price_self_cost ?? 'N/A'; + }, + ], + [ + 'attribute' => 'summ', + 'format' => ['decimal', 2], + ], + [ + 'attribute' => 'summ_retail', + 'format' => ['decimal', 2], + 'value' => function ($model) { + return $model->summ_retail ?? 'N/A'; + }, + ], + [ + 'attribute' => 'summ_self_cost', + 'format' => ['decimal', 2], + 'value' => function ($model) { + return $model->summ_self_cost ?? 'N/A'; + }, + ], + 'active_product:boolean', + 'updated_at:datetime', + [ + 'attribute' => 'updated_admin_id', + 'value' => function ($model) { + return $model->updatedAdmin->name_full; + }, + ], + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/erp24/views/shift-transfer/_replacement.php b/erp24/views/shift-transfer/_replacement.php index fdeb9fbe..1937192c 100644 --- a/erp24/views/shift-transfer/_replacement.php +++ b/erp24/views/shift-transfer/_replacement.php @@ -18,7 +18,8 @@ use yii\widgets\ActiveForm; $this->registerJsFile('/js/shift-transfer/replacement.js', ['position' => \yii\web\View::POS_END]); $usersOnStoreArray = \yii_app\records\Timetable::find() - ->andWhere(['store_id' => array_flip(\yii_app\records\CityStore::getAllActiveGuidId())[$shiftTransfer->store_guid]]) + ->andWhere(['date' => $shiftTransfer->date]) + ->andWhere(['store_id' => array_flip(array_filter(\yii_app\records\CityStore::getAllActiveGuidId(), 'is_string'))[$shiftTransfer->store_guid]]) ->select(['admin_id']) ->column();