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

discount -> verwaltung

Übergeordneter 798f639b
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
Pipeline-Nr.
<?php
/**
* This file contains package_quiqqer_discount_ajax_activate
*/
/**
* Activate a discount
*
* @param integer $discountId - Discount-ID
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_activate',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
$Discount->setAttribute('active', 1);
$Discount->update();
return $Discount->isActive();
},
array('discountId'),
'Permission::checkAdminUser'
);
......@@ -14,7 +14,12 @@
function ($params) {
$params = json_decode($params, true);
$Discounts = new QUI\ERP\Discount\Handler();
$Discount = $Discounts->createChild($params);
if (!isset($params['active'])) {
$params['active'] = 0;
}
$Discount = $Discounts->createChild($params);
return $Discount->getId();
},
......
<?php
/**
* This file contains package_quiqqer_discount_ajax_deactivate
*/
/**
* Deactivate a discount
*
* @param integer $discountId - Discount-ID
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_deactivate',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
$Discount->setAttribute('active', 0);
$Discount->update();
return $Discount->isActive();
},
array('discountId'),
'Permission::checkAdminUser'
);
......@@ -23,11 +23,17 @@ function ($params) {
);
foreach ($data as $entry) {
$result[] = array(
'id' => $entry['id'],
'title' => $Locale->getPartsOfLocaleString($entry['title']),
'text' => $Locale->parseLocaleString($entry['title'])
$entry['title'] = array(
'quiqqer/discount',
'discount.' . $entry['id'] . '.title'
);
$entry['text'] = $Locale->get(
'quiqqer/discount',
'discount.' . $entry['id'] . '.title'
);
$result[] = $entry;
}
usort($result, function ($a, $b) {
......
<?php
/**
* This file contains package_quiqqer_discount_ajax_toggle
*/
/**
* Toggle the status from a tax entry
*
* @param integer $discountId - Discount-ID
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_discount_ajax_toggle',
function ($discountId) {
$Handler = new QUI\ERP\Discount\Handler();
$Discount = $Handler->getChild($discountId);
/* @var $Tax \QUI\ERP\Tax\TaxEntry */
if ($Discount->isActive()) {
$Discount->setAttribute('active', 0);
} else {
$Discount->setAttribute('active', 1);
}
$Discount->update();
return $Discount->isActive();
},
array('discountId'),
'Permission::checkAdminUser'
);
......@@ -63,20 +63,6 @@ define('package/quiqqer/discount/bin/classes/Handler', [
return this.search();
},
/**
* Return all unassigned countries
*
* @returns {Promise}
*/
getUnAssignedCountries: function () {
return new Promise(function (resolve, reject) {
Ajax.get('package_quiqqer_discount_ajax_getUnAssignedCountries', resolve, {
'package': 'quiqqer/discount',
onError : reject
});
});
},
/**
* Create a new Discount
*
......@@ -140,7 +126,7 @@ define('package/quiqqer/discount/bin/classes/Handler', [
* @param {Number} discountId
* @param {Object} data - Discount attributes
*/
save: function (discountId, data) {
update: function (discountId, data) {
return new Promise(function (resolve, reject) {
Ajax.post('package_quiqqer_discount_ajax_update', resolve, {
'package' : 'quiqqer/discount',
......@@ -149,6 +135,60 @@ define('package/quiqqer/discount/bin/classes/Handler', [
params : JSON.encode(data)
});
});
},
/**
* Toggle the status from the discount
*
* @param {Number} discountId
* @returns {Promise}
*/
toggleStatus: function (discountId) {
return new Promise(function (resolve, reject) {
Ajax.post(
'package_quiqqer_discount_ajax_toggle',
resolve, {
'package' : 'quiqqer/discount',
discountId: discountId,
onError : reject
});
});
},
/**
* Activate the discount
*
* @param {Number} discountId
* @returns {Promise}
*/
activate: function (discountId) {
return new Promise(function (resolve, reject) {
Ajax.post(
'package_quiqqer_discount_ajax_activate',
resolve, {
'package' : 'quiqqer/discount',
discountId: discountId,
onError : reject
});
});
},
/**
* Deactivate the discount
*
* @param {Number} discountId
* @returns {Promise}
*/
deactivate: function (discountId) {
return new Promise(function (resolve, reject) {
Ajax.post(
'package_quiqqer_discount_ajax_deactivate',
resolve, {
'package' : 'quiqqer/discount',
discountId: discountId,
onError : reject
});
});
}
});
});
.discount-edit td {
width: 50%;
}
.field-container-item:first-child {
width: 170px !important;
}
\ No newline at end of file
<form>
<table class="data-table data-table-flexbox">
<thead>
<tr>
<th colspan="2">
Rabatt
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
<label class="field-container">
<span class="field-container-item">
ID
</span>
<div class="field-container-field field-id"></div>
</label>
</td>
</tr>
<tr class="even">
<td>
<label class="field-container">
<span class="field-container-item">
Titel
</span>
<div class="field-container-field discount-title"></div>
</label>
</td>
</tr>
<tr class="even">
<td>
<label class="field-container">
<span class="field-container-item">
Rabatt
</span>
<input type="text" name="discount"
class="field-container-field"/>
<select name="discount_type"
class="field-container-item"
style="width: 100px;"
>
<option value="%">%</option>
<option value="currency"></option>
</select>
</label>
</td>
</tr>
</tbody>
</table>
<table class="data-table data-table-flexbox">
<thead>
<tr>
<th colspan="2">
Nutzung definieren
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
<label class="field-container">
<span class="field-container-item">
<span class="fa fa-calendar"></span>
Nutzbar von
</span>
<input type="datetime" name="date_from"
class="field-container-field"/>
</label>
</td>
<td>
<label class="field-container">
<span class="field-container-item">
<span class="fa fa-calendar"></span>
Nutzbar bis
</span>
<input type="datetime" name="date_until"
class="field-container-field"/>
</label>
</td>
</tr>
<tr class="even">
<td>
<label class="field-container">
<span class="field-container-item">
Einkaufsmenge von
</span>
<input type="number" name="purchase_quantity_from"
class="field-container-field"/>
</label>
</td>
<td>
<label class="field-container">
<span class="field-container-item">
Einkaufsmenge bis
</span>
<input type="number" name="purchase_quantity_until"
class="field-container-field"/>
</label>
</td>
</tr>
<tr class="odd">
<td>
<label class="field-container">
<span class="field-container-item">
<span class="fa fa-money"></span>
Einkaufswert von
</span>
<input type="number" name="purchase_value_from"
class="field-container-field"/>
</label>
</td>
<td>
<label class="field-container">
<span class="field-container-item">
<span class="fa fa-money"></span>
Einkaufswert bis
</span>
<input type="number" name="purchase_value_until"
class="field-container-field"/>
</label>
</td>
</tr>
</tbody>
</table>
<table class="data-table data-table-flexbox">
<thead>
<tr>
<th colspan="2">
Zuweisung
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
<label class="field-container">
<span class="field-container-item">Artikel</span>
<input type="text" name="articles"
class="field-container-field"/>
</label>
</td>
</tr>
<tr class="even">
<td>
<label class="field-container">
<span class="field-container-item">
Kategorien
</span>
<input type="text" name="categories"
class="field-container-field"/>
</label>
</td>
</tr>
<tr class="odd">
<td>
<label class="field-container">
<span class="field-container-item">
Benutzer
</span>
<input type="text" name="user_groups"
class="field-container-field"/>
</label>
</td>
</tr>
<tr class="even">
<td>
<label class="field-container">
<span class="field-container-item">
Kombinerbar mit
</span>
<input type="text" name="combined"
class="field-container-field"/>
</label>
</td>
</tr>
</tbody>
</table>
</form>
\ No newline at end of file
/**
* Discount edit control
*
* @author www.pcsg.de (Henning Leutz)
*
* @require qui/QUI
* @require qui/controls/Control
* @require qui/controls/buttons/Button
* @require Locale
* @require package/quiqqer/discount/bin/classes/Handler
* @require package/quiqqer/translator/bin/controls/VariableTranslation
* @require text!package/quiqqer/discount/bin/controls/DiscountEdit.html
*
* @event onLoaded
*/
define('package/quiqqer/discount/bin/controls/DiscountEdit', [
'qui/QUI',
'qui/controls/Control',
'qui/controls/buttons/Button',
'qui/utils/Form',
'Locale',
'package/quiqqer/discount/bin/classes/Handler',
'package/quiqqer/translator/bin/controls/VariableTranslation',
'text!package/quiqqer/discount/bin/controls/DiscountEdit.html',
'css!package/quiqqer/discount/bin/controls/DiscountEdit.css'
], function (QUI, QUIControl, QUIButton, QUIFormUtils, QUILocale,
Handler, Translation, template) {
"use strict";
var lg = 'quiqqer/discount';
var Discounts = new Handler();
return new Class({
Extends: QUIControl,
Type : 'package/quiqqer/discount/bin/controls/DiscountEdit',
Binds: [
'$onInject'
],
options: {
discountId: false
},
initialize: function (options) {
this.parent(options);
this.addEvents({
onInject: this.$onInject
});
},
/**
* Return the DOMNode Element
*
* @returns {HTMLDivElement}
*/
create: function () {
this.$Elm = this.parent();
this.$Elm.set('html', template);
this.$Elm.set('class', 'discount-edit');
return this.$Elm;
},
/**
* event : on inject
*/
$onInject: function () {
var self = this;
require([
'utils/Controls'
], function (Utils) {
QUI.parse(self.$Elm).then(
Utils.parse(self.$Elm)
).then(function () {
return Discounts.getChild(self.getAttribute('discountId'));
}).then(function (data) {
var Elm = self.getElm(),
Form = Elm.getElement('form');
new Translation({
'group': 'quiqqer/discount',
'var' : 'discount.' + data.id + '.title'
}).inject(
Elm.getElement('.discount-title')
);
Elm.getElement('.field-id').set(
'html',
'#' + self.getAttribute('discountId')
);
console.log(data);
QUIFormUtils.setDataToForm(data, Form);
self.fireEvent('loaded');
});
});
},
/**
* Save the Discount
*
* @return {Promise}
*/
save: function () {
var self = this;
return new Promise(function (resolve, reject) {
var Elm = self.getElm(),
Form = Elm.getElement('form');
var data = QUIFormUtils.getFormData(Form);
console.warn(data);
Discounts.update(
self.getAttribute('discountId'),
data
).then(function () {
resolve();
}).catch(reject);
});
}
});
});
......@@ -3,6 +3,7 @@
* Create and edit discounts
*
* @author www.pcsg.de (Henning Leutz)
* @module package/quiqqer/discount/bin/controls/Discounts
*
* @require qui/QUI
* @require qui/controls/desktop/Panel
......@@ -41,7 +42,9 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
'deleteChildren',
'refresh',
'$onCreate',
'$onResize'
'$onResize',
'$toggleStatus',
'$setTaxEntryButtonStatus'
],
initialize: function (options) {
......@@ -49,10 +52,6 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
this.$Grid = null;
this.setAttributes({
'title': QUILocale.get(lg, 'menu.erp.discount.panel.title')
});
this.addEvents({
onCreate: this.$onCreate,
onResize: this.$onResize
......@@ -64,6 +63,12 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
*/
$onCreate: function () {
var self = this;
this.setAttributes({
title: QUILocale.get(lg, 'discount.panel.title')
});
// buttons
this.addButton({
name : 'add',
......@@ -80,7 +85,11 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
textimage: 'icon-edit fa fa-edit',
disabled : true,
events : {
onClick: this.createChild
onClick: function () {
self.editChild(
self.$Grid.getSelectedData()[0].id
);
}
}
});
......@@ -108,8 +117,6 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
});
// Grid
var self = this;
var Container = new Element('div').inject(
this.getContent()
);
......@@ -122,15 +129,65 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
dataType : 'number',
width : 60
}, {
header : QUILocale.get(lg, 'discount.grid.discount.title'),
dataIndex: 'title',
header : QUILocale.get('quiqqer/system', 'status'),
dataIndex: 'status',
dataType : 'button',
width : 60
}, {
header : QUILocale.get(lg, 'discount.grid.discount'),
dataIndex: 'discount',
dataType : 'number',
width : 100
}, {
header : QUILocale.get('quiqqer/system', 'title'),
dataIndex: 'text',
dataType : 'string',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.discount.areas'),
header : QUILocale.get(lg, 'discount.grid.date_from'),
dataIndex: 'date_from',
dataType : 'date',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.date_until'),
dataIndex: 'date_until',
dataType : 'date',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.purchase_quantity'),
dataIndex: 'purchase_quantity',
dataType : 'number',
width : 100
}, {
header : QUILocale.get(lg, 'discount.grid.purchase_value'),
dataIndex: 'purchase_value',
dataType : 'number',
width : 100
}, {
header : QUILocale.get(lg, 'discount.grid.areas'),
dataIndex: 'areas',
dataType : 'string',
width : 300
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.articles'),
dataIndex: 'articles',
dataType : 'string',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.categories'),
dataIndex: 'categories',
dataType : 'string',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.user_groups'),
dataIndex: 'user_groups',
dataType : 'string',
width : 200
}, {
header : QUILocale.get(lg, 'discount.grid.combined'),
dataIndex: 'combined',
dataType : 'string',
width : 100
}]
});
......@@ -180,6 +237,8 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
/**
* refresh the display
*
* @return {Promise}
*/
refresh: function () {
......@@ -188,14 +247,41 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
this.Loader.show();
this.getButtons('delete').disable();
this.getButtons('edit').disable();
this.parent();
Discounts.getList().then(function (data) {
var dataEntry,
return Discounts.getList().then(function (data) {
var i, len, active, entry,
gridData = [];
for (var i = 0, len = data.length; i < len; i++) {
dataEntry = data[i];
for (i = 0, len = data.length; i < len; i++) {
entry = data[i];
active = parseInt(data[i].active);
if (active) {
entry.status = {
icon : 'icon-ok fa fa-ok',
discountId: entry.id,
styles : {
lineHeight: 16
},
events : {
onClick: self.$toggleStatus
}
};
} else {
entry.status = {
icon : 'icon-remove fa fa-remove',
discountId: entry.id,
styles : {
lineHeight: 16
},
events : {
onClick: self.$toggleStatus
}
};
}
gridData.push(entry);
}
self.$Grid.setData({
......@@ -204,7 +290,155 @@ define('package/quiqqer/discount/bin/controls/Discounts', [
self.Loader.hide();
});
},
/**
* Create the child and open the edit
*
* @return {Promise}
*/
createChild: function () {
var self = this;
this.Loader.show();
return Discounts.createChild().then(function (discountId) {
return self.refresh().then(function () {
self.Loader.hide();
return self.editChild(discountId);
});
});
},
/**
* Open the discount edit
*
* @param {Number} discountId
*/
editChild: function (discountId) {
var self = this;
self.Loader.show();
return new Promise(function (resolve) {
self.createSheet({
events: {
onShow: function (Sheet) {
Sheet.getContent().set({
styles: {
padding: 20
}
});
require([
'package/quiqqer/discount/bin/controls/DiscountEdit'
], function (DiscountEdit) {
var Discount = new DiscountEdit({
discountId: discountId,
events : {
onLoaded: function () {
self.Loader.hide();
resolve();
}
}
}).inject(Sheet.getContent());
Sheet.addButton({
text : QUILocale.get(
'quiqqer/system',
'save'
),
textimage: 'icon-save',
events : {
click: function () {
self.Loader.show();
Discount.save().then(function () {
self.refresh();
}).catch(function () {
self.Loader.hide();
});
}
}
});
});
}
}
}).show();
});
},
/**
* Opens the delete dialog - delete
*
* @param {Array} discountIds
*/
deleteChildren: function (discountIds) {
var self = this,
str = discountIds.join(',');
new QUIConfirm({
title : QUILocale.get(lg, 'discount.window.delete.title'),
text : QUILocale.get(lg, 'discount.window.delete.text', {
ids: str
}),
information: QUILocale.get(lg, 'discount.window.delete.information', {
ids: str
}),
icon : 'icon-trash fa fa-trash',
textimage : 'icon-trash fa fa-trash',
maxHeight : 300,
maxWidth : 450,
autoclose : false,
events : {
onSubmit: function (Win) {
Win.Loader.show();
Discounts.deleteChildren(discountIds).then(function () {
return self.refresh();
}).then(function () {
Win.close();
});
}
}
}).open();
},
/**
* Toggle the discount status
*
* @param {Object} Button - qui/controls/buttons/Button
*/
$toggleStatus: function (Button) {
Button.setAttribute(
'icon',
'icon-spinner icon-spin fa fa-spinner fa-spin'
);
Discounts.toggleStatus(
Button.getAttribute('discountId')
).then(function (status) {
this.$setTaxEntryButtonStatus(Button, status);
}.bind(this));
},
/**
* Change the statusbutton of a discount
*
* @param {Object} Button
* @param {Boolean|Number} status
*/
$setTaxEntryButtonStatus: function (Button, status) {
if (status) {
Button.setAttribute('icon', 'icon-ok');
return;
}
Button.setAttribute('icon', 'icon-remove');
}
});
});
......@@ -4,11 +4,13 @@
<table name="discounts">
<field type="INT( 10 ) NOT NULL PRIMARY KEY">id</field>
<field type="INT( 1 )">active</field>
<field type="text">discount</field>
<field type="varchar( 255 )">discount</field>
<field type="text">date_from</field>
<field type="text">data_to</field>
<field type="INT( 10 )">purchase_quantity</field>
<field type="text">purchase_value</field>
<field type="text">date_until</field>
<field type="INT( 10 )">purchase_quantity_from</field>
<field type="INT( 10 )">purchase_quantity_until</field>
<field type="text">purchase_value_from</field>
<field type="text">purchase_value_until</field>
<field type="text">areas</field>
<field type="text">articles</field>
......
......@@ -12,6 +12,50 @@
</groups>
<groups name="quiqqer/discount" datatype="js">
<locale name="discount.panel.title">
<de><![CDATA[Rabatte]]></de>
<en><![CDATA[Discounts]]></en>
</locale>
<locale name="discount.grid.discount">
<de><![CDATA[Rabatt]]></de>
<en><![CDATA[Discount]]></en>
</locale>
<locale name="discount.grid.date_from">
<de><![CDATA[Nutzbar von]]></de>
<en><![CDATA[Available from]]></en>
</locale>
<locale name="discount.grid.date_until">
<de><![CDATA[Nutzbar bis]]></de>
<en><![CDATA[Available until]]></en>
</locale>
<locale name="discount.grid.areas">
<de><![CDATA[Zugewiesene Zonen]]></de>
<en><![CDATA[Assigned Areas]]></en>
</locale>
<locale name="discount.grid.purchase_quantity">
<de><![CDATA[Einkaufsmenge]]></de>
<en><![CDATA[Purchase quantity]]></en>
</locale>
<locale name="discount.grid.purchase_value">
<de><![CDATA[Einkaufswert]]></de>
<en><![CDATA[Purchase value]]></en>
</locale>
<locale name="discount.grid.articles">
<de><![CDATA[Zugewiesene Artikel]]></de>
<en><![CDATA[Assigned products]]></en>
</locale>
<locale name="discount.grid.categories">
<de><![CDATA[Zugewiesene Kategorien]]></de>
<en><![CDATA[Assigned categories]]></en>
</locale>
<locale name="discount.grid.user_groups">
<de><![CDATA[Zugewiesene Benutzer und Gruppen]]></de>
<en><![CDATA[Assigned users and groups]]></en>
</locale>
<locale name="discount.grid.combined">
<de><![CDATA[Kombinierbar mit]]></de>
<en><![CDATA[Combined with]]></en>
</locale>
</groups>
</locales>
\ No newline at end of file
......@@ -7,6 +7,8 @@
use QUI;
use QUI\Users\User;
use QUI\Rights\Permission;
use QUI\Utils\Security\Orthos;
/**
* Class Discount
......@@ -14,6 +16,73 @@
*/
class Discount extends QUI\CRUD\Child
{
/**
* Discount constructor.
* @param int $id
* @param Handler $Factory
*/
public function __construct($id, Handler $Factory)
{
parent::__construct($id, $Factory);
$this->Events->addEvent('onDeleteBegin', function () {
Permission::checkPermission('quiqqer.areas.area.delete');
});
$this->Events->addEvent('onDeleteEnd', function () {
QUI\Translator::delete(
'quiqqer/discount',
'discount.' . $this->getId() . '.title'
);
});
$this->Events->addEvent('onSaveBegin', function () {
Permission::checkPermission('quiqqer.areas.area.edit');
if ($this->getAttribute('date_from')
&& !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_from'))
) {
throw new QUI\Exception(array(
'quiqqer/discount',
'exception.discount.date.wrong'
));
}
if ($this->getAttribute('date_until')
&& !Orthos::checkMySqlDatetimeSyntax($this->getAttribute('date_until'))
) {
throw new QUI\Exception(array(
'quiqqer/discount',
'exception.discount.date.wrong'
));
}
QUI\System\Log::writeRecursive($this->getAttributes());
});
}
/**
* @return string
*/
public function getTitle()
{
return QUI::getLocale()->get(
'quiqqer/discount',
'discount.' . $this->getId() . '.title'
);
}
/**
* Return the discount status
*
* @return boolean
*/
public function isActive()
{
return $this->getAttribute('active') ? true : false;
}
/**
* Is the discount combinable with another discount?
......@@ -52,6 +121,10 @@ public function canCombinedWith(Discount $Discount)
*/
public function canUsedBy(User $User)
{
if ($this->isActive() === false) {
return false;
}
$userGroups = QUI\UsersGroups\Utils::parseUsersGroupsString(
$this->getAttribute('user_groups')
);
......
......@@ -39,10 +39,16 @@ public function __construct()
$title = QUI::getLocale()->get($parts[0], $parts[1]);
}
QUI\Translator::addUserVar('quiqqer/discount', $newVar, array(
$current => $title,
'datatype' => 'php,js'
));
try {
QUI\Translator::addUserVar('quiqqer/discount', $newVar, array(
$current => $title,
'datatype' => 'php,js'
));
} catch (QUI\Exception $Exception) {
QUI::getMessagesHandler()->addAttention(
$Exception->getMessage()
);
}
});
}
......@@ -77,12 +83,14 @@ public function getChildAttributes()
'active',
'discount',
'date_from',
'data_to',
'purchase_quantity',
'purchase_value',
'area',
'article',
'category',
'date_until',
'purchase_quantity_from',
'purchase_quantity_until',
'purchase_value_from',
'purchase_value_until',
'areas',
'articles',
'categories',
'user_groups',
'combined'
);
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren