From e2d99000ee17847850d46cfca974a1cee926b07a Mon Sep 17 00:00:00 2001 From: Praesidiarius Date: Sun, 9 Feb 2020 08:44:53 +0100 Subject: [PATCH] set article price by history --- README.md | 23 +++++++++++++++++++++++ composer.json | 2 +- data/data_simple.sql | 1 + src/Controller/HistoryController.php | 17 +++++++++++++++++ src/Module.php | 2 +- 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7cb3b9a --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# oneplace-article-history + +Price History Plugin for onePlace Articles + +Record every single price change on your articles. +With price history, you can add every purchase of your Articles, +and set the selling price with every purchase. + +This way you will have long term statistics about your +costs, margins and retail prices over time for your articles. + +![article-history](http://docs.1plc.ch/img/addartpricehistory.jpg) + +## Requirements + +Requires [oneplace-core](https://github.com/OnePlc/PLC_X_Core), [oneplace-article](https://github.com/OnePlc/PLC_X_Article) + +## installation + +The easiest way to install this plugin is by using composer +```bash +$ composer require oneplace/oneplace-article-history +``` \ No newline at end of file diff --git a/composer.json b/composer.json index c05274f..2bc163d 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "oneplace/oneplace-article-history", "description": "onePlace Article History Plugin. Manage your Article's history", "type": "oneplace-plugin", - "version": "1.0.0", + "version": "1.0.1", "license": "BSD-3-Clause", "keywords": [ "laminas", diff --git a/data/data_simple.sql b/data/data_simple.sql index 8085166..6dd0ca9 100644 --- a/data/data_simple.sql +++ b/data/data_simple.sql @@ -7,3 +7,4 @@ INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, ` (NULL, 'currency', 'Price', 'price', 'history-base', 'articlehistory-single', 'col-md-1', '', '', 0, 1, 0, '', '', ''), (NULL, 'number', 'Amount', 'amount', 'history-base', 'articlehistory-single', 'col-md-1', '', '', 0, 1, 0, '', '', ''); +UPDATE `core_form_field` SET `readonly` = '1' WHERE `core_form_field`.`fieldkey` LIKE 'price_sell' AND `form` LIKE 'article-single'; diff --git a/src/Controller/HistoryController.php b/src/Controller/HistoryController.php index dc64e47..4db8556 100644 --- a/src/Controller/HistoryController.php +++ b/src/Controller/HistoryController.php @@ -22,6 +22,7 @@ use OnePlace\Article\History\Model\HistoryTable; use Laminas\View\Model\ViewModel; use Laminas\Db\Adapter\AdapterInterface; +use OnePlace\Article\Model\ArticleTable; class HistoryController extends CoreEntityController { /** @@ -108,9 +109,25 @@ public function attachHistoryForm($oItem = false) { ]; } + private function updateArticlePrice($fNewPrice,$iArticleID) { + try { + $oArtTbl = CoreEntityController::$oServiceManager->get(ArticleTable::class); + } catch(\RuntimeException $e) { + return false; + } + + if(isset($oArtTbl)) { + # Save price on article + $oArtTbl->updateAttribute('price_sell',$fNewPrice,'Article_ID',$iArticleID); + } + } + public function attachHistoryToArticle($oItem,$aRawData) { $oItem->article_idfs = $aRawData['ref_idfs']; + # Save new price to article + $this->updateArticlePrice($oItem->price,$oItem->article_idfs); + return $oItem; } diff --git a/src/Module.php b/src/Module.php index c867cab..8695d04 100644 --- a/src/Module.php +++ b/src/Module.php @@ -32,7 +32,7 @@ class Module { * * @since 1.0.0 */ - const VERSION = '1.0.0'; + const VERSION = '1.0.1'; /** * Load module config file