diff --git a/application/WarehouseArticle/WarehouseArticleController.php b/application/WarehouseArticle/WarehouseArticleController.php index 38fbc9704..bf4d1c3bd 100644 --- a/application/WarehouseArticle/WarehouseArticleController.php +++ b/application/WarehouseArticle/WarehouseArticleController.php @@ -55,7 +55,9 @@ class WarehouseArticleController extends TTCrud { public static function updateCheapestPurchasePrice(int $id): void { $article = WarehouseArticleModel::get($id); if (!$article instanceof WarehouseArticleModel) throw new Exception("Invalid article type"); - if (($distributor = WarehouseArticleDistributorModel::getAll(['articleId' => $id], 1, 0, ['key' => 'purchasePrice', 'order' => 'ASC'])) && $article->cheapestPurchasePrice != $distributor[0]->purchasePrice) + $distributor = WarehouseArticleDistributorModel::getAll(['articleId' => $id], 1, 0, ['key' => 'purchasePrice', 'order' => 'ASC']); + if (count($distributor) == 0) WarehouseArticleModel::update(array_merge(get_object_vars($article), ['cheapestPurchasePrice' => null])); + else if ($article->cheapestPurchasePrice != $distributor[0]->purchasePrice) WarehouseArticleModel::update(array_merge(get_object_vars($article), ['cheapestPurchasePrice' => $distributor[0]->purchasePrice])); } diff --git a/application/WarehouseArticleDistributor/WarehouseArticleDistributorController.php b/application/WarehouseArticleDistributor/WarehouseArticleDistributorController.php index 73aa7ca14..d001982d8 100644 --- a/application/WarehouseArticleDistributor/WarehouseArticleDistributorController.php +++ b/application/WarehouseArticleDistributor/WarehouseArticleDistributorController.php @@ -27,7 +27,7 @@ class WarehouseArticleDistributorController extends TTCrud { protected function checkExistingDistributorEntry($postData): bool { if (isset($postData['id'])) { $count = WarehouseArticleDistributorModel::count(['articleId' => $postData['articleId'], - 'distributorId' => $postData['articlePriceTypeId'], + 'distributorId' => $postData['distributorId'], 'id' => $postData['id']]); if ($count > 0) return true; @@ -66,6 +66,11 @@ class WarehouseArticleDistributorController extends TTCrud { WarehouseArticleController::updateSellPrices($postData['articleId']); } + protected function afterDelete($postData) { + WarehouseArticleController::updateCheapestPurchasePrice($postData); + WarehouseArticleController::updateSellPrices($postData); + } + protected function getHistoryAction() { $history = WarehouseHistoryModel::getByRowId($this->request->id, $this->mod); diff --git a/application/WarehouseShippingNote/WarehouseShippingNoteController.php b/application/WarehouseShippingNote/WarehouseShippingNoteController.php index b3c8b3810..d9de1f636 100644 --- a/application/WarehouseShippingNote/WarehouseShippingNoteController.php +++ b/application/WarehouseShippingNote/WarehouseShippingNoteController.php @@ -30,6 +30,7 @@ class WarehouseShippingNoteController extends TTCrud { protected array $defaultOrder = ['key' => 'create', 'order' => 'DESC']; protected array $additionalJSVariables = ['WAREHOUSE_ADMIN' => true]; + protected array $additionalJS = ['js/pages/WarehouseArticle/WarehouseArticleModal.js']; protected array $additionalHead = ['']; protected array $infoMessages = ['create' => 'Lieferschein wurde erstellt.', diff --git a/lib/TTCrud/TTCrud.php b/lib/TTCrud/TTCrud.php index 61e84108e..b76bbad8e 100644 --- a/lib/TTCrud/TTCrud.php +++ b/lib/TTCrud/TTCrud.php @@ -66,7 +66,7 @@ class TTCrud extends mfBaseController { protected function indexAction() { - $this->layout()->set('additionalJS', ['js/pages/WarehouseHistory/WarehouseHistoryModal.js']); + $this->layout()->set('additionalJS', array_merge(['js/pages/WarehouseHistory/WarehouseHistoryModal.js'], $this->additionalJS ?? [])); $pageName = (defined('BASEDIR') && file_exists(BASEDIR . "/public/js/pages/{$this->mod}/{$this->mod}.js")) ? $this->mod : "DefaultCrudView"; diff --git a/public/js/pages/WarehouseArticle/WarehouseArticle.js b/public/js/pages/WarehouseArticle/WarehouseArticle.js index 521f4b4a8..97061783a 100644 --- a/public/js/pages/WarehouseArticle/WarehouseArticle.js +++ b/public/js/pages/WarehouseArticle/WarehouseArticle.js @@ -14,12 +14,12 @@ Vue.component('warehouse-article-prices', {
{{ typeTitle }}
- - -
+ + +
- + +
@@ -47,6 +47,7 @@ Vue.component('warehouse-article-prices', { if (type) prices[type.title] = { id: pData.id, isRobot: false, + pendingChanges: false, articlePriceTypeId: pData.articlePriceTypeId, priceMultiplier: pData.priceMultiplier, priceOverride: pData.priceOverride @@ -58,8 +59,8 @@ Vue.component('warehouse-article-prices', { const payload = { articleId: this.id, articlePriceTypeId: price.articlePriceTypeId, - priceMultiplier: price.priceMultiplier, - priceOverride: price.priceOverride + priceMultiplier: price.priceMultiplier ? parseFloat(price.priceMultiplier.toString().replace(',', '.')) : null, + priceOverride: price.priceOverride ? parseFloat(price.priceOverride.toString().replace(',', '.')) : null }; if (price.isRobot) { await this.window.handleApiResponse(axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticlePrice/create`, payload)); @@ -89,13 +90,16 @@ Vue.component('warehouse-article-distributor', {
- - -
+ + +
+ @click="deleteDistributor(distributor.id)"/> + +
@@ -111,11 +115,13 @@ Vue.component('warehouse-article-distributor', { this.articleDistributors = res.data.rows; }, async saveDistributor(distributor) { + delete distributor.pendingChanges; + distributor.purchasePrice = distributor.purchasePrice ? parseFloat(distributor.purchasePrice.toString().replace(',', '.')) : null; await this.window.handleApiResponse(axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticleDistributor/${distributor.id ? 'update' : 'create'}`, distributor)); await this.fetchArticleDistributors(); }, - async deleteDistributor(distributor) { - await this.window.handleApiResponse(axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticleDistributor/delete`, distributor)); + async deleteDistributor(distributorId) { + await this.window.handleApiResponse(axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticleDistributor/delete`, {id: distributorId})); await this.fetchArticleDistributors(); } }, @@ -145,11 +151,22 @@ Vue.component('warehouse-article', { + + +