Skip to content

Commit

Permalink
set article price by history
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Feb 9, 2020
1 parent 5db5117 commit e2d9900
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions data/data_simple.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';
17 changes: 17 additions & 0 deletions src/Controller/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.0';
const VERSION = '1.0.1';

/**
* Load module config file
Expand Down

0 comments on commit e2d9900

Please sign in to comment.