Skip to content
Code-Schnipsel Gruppen Projekte
Commit 1b70f047 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: summary calc fixed because of invoice#66

Übergeordneter f82ea6eb
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -11,9 +11,13 @@
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_products_calc',
function ($params, $user) {
$params = \json_decode($params, true);
$user = \json_decode($user, true);
function ($articles, $user) {
$articles = \json_decode($articles, true);
$user = \json_decode($user, true);
if (!\is_array($articles)) {
$articles = [];
}
if (!empty($user)) {
try {
......@@ -26,11 +30,14 @@ function ($params, $user) {
$Calc = QUI\ERP\Accounting\Calc::getInstance();
}
$Article = new QUI\ERP\Accounting\Article($params);
$Article->calc($Calc);
$Articles = new QUI\ERP\Accounting\ArticleList($articles);
$Articles->setUser($Calc->getUser());
$Articles->calc($Calc);
$result = $Articles->toArray();
return $Article->toArray();
return $result;
},
['params', 'user'],
['articles', 'user'],
'Permission::checkAdminUser'
);
......@@ -12,7 +12,7 @@
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_erp_ajax_products_summary',
function ($article) {
function ($article, $user) {
$article = \json_decode($article, true);
$Brutto = new QUI\ERP\User([
......@@ -38,8 +38,10 @@ function ($article) {
$Article->setUser($Brutto);
$Article->calc($Calc);
return $Article->toArray();
$result = $Article->toArray();
return $result;
},
['article'],
['article', 'user'],
'Permission::checkAdminUser'
);
......@@ -301,8 +301,6 @@ define('package/quiqqer/erp/bin/backend/controls/articles/Article', [
var price = Formatter.format(product.calculated.nettoSubSum);
var total = Formatter.format(product.calculated.nettoSum);
self.$calculations = product;
var setElement = function (Node, text) {
var isInEditMode = Node.getElement('input');
......@@ -337,16 +335,37 @@ define('package/quiqqer/erp/bin/backend/controls/articles/Article', [
* @return {Promise}
*/
$calc: function () {
var self = this;
var Calc;
var self = this,
attr = self.getAttributes(),
pos = parseInt(attr.position);
return new Promise(function (resolve, reject) {
//QUIAjax.get('package_quiqqer_invoice_ajax_invoices_temporary_product_calc', resolve, {
QUIAjax.get('package_quiqqer_erp_ajax_products_calc', resolve, {
'package': 'quiqqer/erp',
onError : reject,
params : JSON.encode(self.getAttributes()),
user : JSON.encode(self.$user)
if (this.getAttribute('List')) {
Calc = this.getAttribute('List').$executeCalculation();
} else {
Calc = new Promise(function (resolve, reject) {
QUIAjax.get('package_quiqqer_erp_ajax_products_calc', resolve, {
'package': 'quiqqer/erp',
onError : reject,
params : JSON.encode({
articles: [attr]
}),
user : JSON.encode(self.$user)
});
});
}
return Calc.then(function (result) {
var articles = result.articles;
var article = articles.filter(function (article) {
return parseInt(article.position) === pos;
})[0];
self.$calculations = article;
self.fireEvent('calc', [self, result, article]);
return article;
});
},
......@@ -356,7 +375,11 @@ define('package/quiqqer/erp/bin/backend/controls/articles/Article', [
* @returns {{}|*}
*/
getCalculations: function () {
return this.$calculations;
if (!this.$calculations) {
return {};
}
return this.$calculations.calculated;
},
/**
......
......@@ -38,6 +38,7 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
'$onArticleSelect',
'$onArticleUnSelect',
'$onArticleReplace',
'$onArticleCalc',
'$calc',
'$onInject'
],
......@@ -245,13 +246,14 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
Child.setUser(this.$user);
Child.setPosition(this.$articles.length);
Child.setAttribute('List', this);
Child.addEvents({
onDelete : this.$onArticleDelete,
onSelect : this.$onArticleSelect,
onUnSelect: this.$onArticleUnSelect,
onReplace : this.$onArticleReplace,
onCalc : this.$calc
onDelete : this.$onArticleDelete,
onSelect : this.$onArticleSelect,
onUnSelect : this.$onArticleUnSelect,
onReplace : this.$onArticleReplace,
onArticleCalc: this.$onArticleCalc
});
if (this.$Container) {
......@@ -342,6 +344,19 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
$executeCalculation: function () {
var self = this;
if (this.$calculationRunning) {
return new Promise(function (resolve) {
var trigger = function () {
resolve(self.$calculations);
self.removeEvent('onCalc', trigger);
};
self.addEvent('onCalc', trigger);
});
}
this.$calculationRunning = true;
return new Promise(function (resolve) {
var articles = self.$articles.map(function (Article) {
return Article.getAttributes();
......@@ -353,7 +368,7 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
resolve(result);
}, {
'package': 'quiqqer/erp',
articles : JSON.encode(articles),
articles : JSON.encode({articles: articles}),
user : JSON.encode(self.$user)
});
});
......@@ -587,7 +602,7 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
this.$articles = articles;
this.$executeCalculation().then(function () {
this.$calc().then(function () {
if (self.$articles.length) {
self.$articles[0].select();
}
......@@ -630,6 +645,16 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleList', [
this.fireEvent('articleReplaceClick', [this, Article]);
},
/**
* event: on article calculation
*
* @param Article
* @param calculation
*/
$onArticleCalc: function (Article, calculation) {
this.$calculations = calculation;
},
/**
* Return the current selected Article
*
......
......@@ -8,13 +8,14 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary', [
'qui/QUI',
'qui/controls/Control',
'package/quiqqer/erp/bin/backend/controls/articles/Article',
'Mustache',
'Locale',
'text!package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary.html',
'css!package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary.css'
], function (QUI, QUIControl, Mustache, QUILocale, template) {
], function (QUI, QUIControl, Article, Mustache, QUILocale, template) {
"use strict";
return new Class({
......@@ -102,48 +103,50 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary', [
}
var self = this;
List.addEvent('onCalc', function (List) {
var data = List.getCalculation();
self.$NettoSum.set('html', self.$Formatter.format(data.nettoSum));
self.$BruttoSum.set('html', self.$Formatter.format(data.sum));
if (typeOf(data.vatArray) === 'array' && !data.vatArray.length) {
self.$VAT.set('html', '---');
return;
}
var key, Entry;
var vatText = '';
for (key in data.vatArray) {
if (!data.vatArray.hasOwnProperty(key)) {
continue;
}
Entry = data.vatArray[key];
if (typeof Entry.sum === 'undefined') {
Entry.sum = 0;
}
if (typeof Entry.text === 'undefined') {
Entry.text = '';
}
if (Entry.text === '') {
Entry.text = '';
}
Entry.sum = parseFloat(Entry.sum);
vatText = vatText + Entry.text + ' (' + self.$Formatter.format(Entry.sum) + ')<br />';
}
self.$VAT.set('html', vatText);
});
//
// List.addEvent('onCalc', function (List) {
// return;
// var data = List.getCalculation();
// console.log(data);
// self.$NettoSum.set('html', self.$Formatter.format(data.nettoSum));
// self.$BruttoSum.set('html', self.$Formatter.format(data.sum));
//
// if (typeOf(data.vatArray) === 'array' && !data.vatArray.length) {
// self.$VAT.set('html', '---');
// return;
// }
//
// var key, Entry;
// var vatText = '';
//
// for (key in data.vatArray) {
// if (!data.vatArray.hasOwnProperty(key)) {
// continue;
// }
//
// Entry = data.vatArray[key];
//
// if (typeof Entry.sum === 'undefined') {
// Entry.sum = 0;
// }
//
// if (typeof Entry.text === 'undefined') {
// Entry.text = '';
// }
//
// if (Entry.text === '') {
// Entry.text = '';
// }
//
// Entry.sum = parseFloat(Entry.sum);
//
// vatText = vatText + Entry.text + ' (' + self.$Formatter.format(Entry.sum) + ')<br />';
// }
//
// self.$VAT.set('html', vatText);
// });
List.addEvent('onCalc', this.$refreshArticleSelect);
List.addEvent('onArticleSelect', this.$refreshArticleSelect);
},
......@@ -228,7 +231,35 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary', [
* @param List
* @param Article
*/
$refreshArticleSelect: function (List, Article) {
$refreshArticleSelect: function (List, ArticleInstance) {
var calculated = List.getCalculation();
if (typeof calculated.calculations === 'undefined') {
return;
}
var calc = calculated.calculations;
if (ArticleInstance instanceof Article) {
var articleCalc = ArticleInstance.getCalculations();
if (articleCalc && typeof articleCalc.nettoSum !== 'undefined') {
this.$ArticleNettoSum.set('html', this.$Formatter.format(articleCalc.nettoSum));
} else {
this.$ArticleNettoSum.set('html', '---');
}
if (articleCalc && typeof articleCalc.sum !== 'undefined') {
this.$ArticleBruttoSum.set('html', this.$Formatter.format(articleCalc.sum));
} else {
this.$ArticleBruttoSum.set('html', '---');
}
}
this.$NettoSum.set('html', this.$Formatter.format(calc.nettoSum));
this.$BruttoSum.set('html', this.$Formatter.format(calc.sum));
return;
var self = this;
require(['Ajax'], function (QUIAjax) {
......@@ -236,15 +267,11 @@ define('package/quiqqer/erp/bin/backend/controls/articles/ArticleSummary', [
console.warn('##################');
console.warn(result);
self.$ArticleNettoSum.set(
'html',
self.$Formatter.format(result.calculated.nettoSum)
);
self.$ArticleNettoSum.set('html', self.$Formatter.format(result.calculated.nettoSum));
self.$ArticleBruttoSum.set('html', self.$Formatter.format(result.calculated.sum));
self.$ArticleBruttoSum.set(
'html',
self.$Formatter.format(result.calculated.sum)
);
self.$NettoSum.set('html', self.$Formatter.format(result.calculated.nettoSum));
self.$BruttoSum.set('html', self.$Formatter.format(result.calculated.sum));
}, {
'package': 'quiqqer/erp',
article : JSON.encode(Article.getAttributes())
......
......@@ -241,6 +241,7 @@ public function toArray()
$calculations['display_vatSum'] = $Currency->format($calculations['vatSum']);
foreach ($articles as $key => $article) {
$articles[$key]['position'] = $key + 1;
$articles[$key]['display_sum'] = $Currency->format($article['sum']);
$articles[$key]['display_unitPrice'] = $Currency->format($article['unitPrice']);
}
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren