diff --git a/.env.json b/.env.json new file mode 100644 index 000000000..0fa6162d9 --- /dev/null +++ b/.env.json @@ -0,0 +1,6 @@ +{ + "salixHost": "localhost", + "salixPort": "3306", + "salixUser": "root", + "salixPassword": "root" +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index d004f86bc..958de4d57 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,10 +6,14 @@ def branchTest = "test"; env.BRANCH_NAME = branchName; env.TAG = "${env.BUILD_NUMBER}"; +env.salixUser="${env.salixUser}"; +env.salixPassword="${env.salixPassword}"; switch (branchName){ case branchTest: env.NODE_ENV = "test"; + env.salixHost = "${env.testSalixHost}"; + env.salixPort = "${env.testSalixPort}"; break; case branchProduction: env.DOCKER_HOST = "tcp://172.16.255.29:2375"; @@ -20,7 +24,7 @@ switch (branchName){ node { stage ('Print environment variables'){ - echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}" + echo "Branch ${branchName}, Build ${env.TAG}, salixHost ${env.salixHost}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}" } stage ('Checkout') { checkout scm diff --git a/client/client/routes.json b/client/client/routes.json index 054f95ab9..6718ce135 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -1,7 +1,7 @@ { "module": "client", "name": "Clients", - "icon": "/static/images/icon_client.png", + "icon": "person", "validations" : true, "routes": [ { diff --git a/client/client/src/address-edit/address-edit.html b/client/client/src/address-edit/address-edit.html index 55154a996..84f00a579 100644 --- a/client/client/src/address-edit/address-edit.html +++ b/client/client/src/address-edit/address-edit.html @@ -59,9 +59,7 @@ field="observation.observationTypeFk" data="observationsTypes.model" show-field="description" - label="Observation type" - order="description ASC" - filter-search="{where: {description: {regexp: 'search'}}}"> + label="Observation type"> {{$parent.$parent.item.description}} {{::observation.description}} - + diff --git a/client/client/src/basic-data/basic-data.html b/client/client/src/basic-data/basic-data.html index 0a576574a..77865c4f6 100644 --- a/client/client/src/basic-data/basic-data.html +++ b/client/client/src/basic-data/basic-data.html @@ -30,7 +30,7 @@ value-field="id" select-fields="name" label="Salesperson" - filter-search="{where: {or: [{name: {regexp: 'search'}}, {name: {regexp: 'search'}}]}}"> + where="{or: [{firstName: {regexp: 'search'}}, {name: {regexp: 'search'}}]}"> + where="{or: [{firstName: {regexp: 'search'}}, {name: {regexp: 'search'}}]}"> diff --git a/client/client/src/descriptor/descriptor.js b/client/client/src/descriptor/descriptor.js index 729b85fb3..b8d68c493 100644 --- a/client/client/src/descriptor/descriptor.js +++ b/client/client/src/descriptor/descriptor.js @@ -25,6 +25,7 @@ class ClientDescriptor { } } } +ClientDescriptor.$inject = ['$http']; ngModule.component('vnClientDescriptor', { template: require('./descriptor.html'), diff --git a/client/core/src/components/autocomplete/style.scss b/client/core/src/components/autocomplete/style.scss index 26143c035..2dda27653 100755 --- a/client/core/src/components/autocomplete/style.scss +++ b/client/core/src/components/autocomplete/style.scss @@ -9,13 +9,6 @@ vn-autocomplete > div > .mdl-textfield { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; - - &:focus { - outline: none; - } - &::-moz-focus-inner { - border: 0; - } } & > .icons { display: none; diff --git a/client/core/src/components/date-picker/style.scss b/client/core/src/components/date-picker/style.scss index d729ba947..99f1cbc1b 100644 --- a/client/core/src/components/date-picker/style.scss +++ b/client/core/src/components/date-picker/style.scss @@ -1,7 +1,4 @@ vn-date-picker { - div { - outline: none; //remove chrome outline - } .mdl-chip__action { position: absolute; width: auto; diff --git a/client/core/src/components/drop-down/drop-down.html b/client/core/src/components/drop-down/drop-down.html index 02d2d50b2..560ef77fa 100755 --- a/client/core/src/components/drop-down/drop-down.html +++ b/client/core/src/components/drop-down/drop-down.html @@ -1,35 +1,38 @@ -
-
- - - -
- - -
- -
- {{$ctrl.statusText}} + + + + -
\ No newline at end of file + diff --git a/client/core/src/components/drop-down/drop-down.js b/client/core/src/components/drop-down/drop-down.js index c5e11a839..482297618 100755 --- a/client/core/src/components/drop-down/drop-down.js +++ b/client/core/src/components/drop-down/drop-down.js @@ -4,45 +4,34 @@ import './style.scss'; import './model'; export default class DropDown extends Component { - constructor($element, $scope, $transclude, $timeout, $http, $translate) { + constructor($element, $scope, $transclude, $timeout, $http) { super($element, $scope); this.$transclude = $transclude; this.$timeout = $timeout; - this.$translate = $translate; this.valueField = 'id'; this.showField = 'name'; this._search = undefined; - this._shown = false; this._activeOption = -1; this.showLoadMore = true; this.showFilter = true; - this.input = this.element.querySelector('.search'); - this.body = this.element.querySelector('.body'); - this.container = this.element.querySelector('ul'); - this.list = this.element.querySelector('.list'); - this.docKeyDownHandler = e => this.onDocKeyDown(e); - this.docFocusInHandler = e => this.onDocFocusIn(e); + } - this.element.addEventListener('mousedown', - e => this.onBackgroundMouseDown(e)); - this.element.addEventListener('focusin', - e => this.onFocusIn(e)); - this.list.addEventListener('scroll', - e => this.onScroll(e)); + $postLink() { + this.input = this.element.querySelector('.search'); + this.ul = this.element.querySelector('ul'); + this.list = this.element.querySelector('.list'); + this.list.addEventListener('scroll', e => this.onScroll(e)); } get shown() { - return this._shown; + return this.$.popover.shown; } set shown(value) { - if (value) - this.show(); - else - this.hide(); + this.$.popover.shown = value; } get search() { @@ -97,62 +86,18 @@ export default class DropDown extends Component { * @param {String} search The initial search term or %null */ show(search) { - if (this._shown) return; - this._shown = true; - this._activeOption = -1; this.search = search; + this._activeOption = -1; this.buildList(); - this.element.style.display = 'block'; - this.list.scrollTop = 0; - this.$timeout(() => this.$element.addClass('shown'), 40); - this.document.addEventListener('keydown', this.docKeyDownHandler); - this.document.addEventListener('focusin', this.docFocusInHandler); - this.relocate(); - this.input.focus(); + this.$.popover.parent = this.parent; + this.$.popover.show(); } /** * Hides the drop-down. */ hide() { - if (!this._shown) return; - this._shown = false; - this.element.style.display = ''; - this.$element.removeClass('shown'); - this.document.removeEventListener('keydown', this.docKeyDownHandler); - this.document.removeEventListener('focusin', this.docFocusInHandler); - if (this.parent) - this.parent.focus(); - } - - /** - * Repositions the drop-down to a correct location relative to the parent. - */ - relocate() { - if (!this.parent) return; - - let style = this.body.style; - style.width = ''; - style.height = ''; - - let parentRect = this.parent.getBoundingClientRect(); - let bodyRect = this.body.getBoundingClientRect(); - - let top = parentRect.top + parentRect.height; - let height = bodyRect.height; - let width = Math.max(bodyRect.width, parentRect.width); - - let margin = 10; - - if (top + height + margin > window.innerHeight) - top = Math.max(parentRect.top - height, margin); - - style.top = `${top}px`; - style.left = `${parentRect.left}px`; - style.width = `${width}px`; - - if (height + margin * 2 > window.innerHeight) - style.height = `${window.innerHeight - margin * 2}px`; + this.$.popover.hide(); } /** @@ -190,7 +135,7 @@ export default class DropDown extends Component { let data = this.$.model.data; if (option >= 0 && data && option < data.length) { - this.activeLi = this.container.children[option]; + this.activeLi = this.ul.children[option]; this.activeLi.className = 'active'; } } @@ -224,7 +169,7 @@ export default class DropDown extends Component { } if (!this.multiple) - this.hide(); + this.$.popover.hide(); } refreshModel() { @@ -260,22 +205,14 @@ export default class DropDown extends Component { return undefined; } - onMouseDown(event) { - this.lastMouseEvent = event; + onOpen() { + this.document.addEventListener('keydown', this.docKeyDownHandler); + this.list.scrollTop = 0; + this.input.focus(); } - onBackgroundMouseDown(event) { - if (event != this.lastMouseEvent) - this.hide(); - } - - onFocusIn(event) { - this.lastFocusEvent = event; - } - - onDocFocusIn(event) { - if (event !== this.lastFocusEvent) - this.hide(); + onClose() { + this.document.removeEventListener('keydown', this.docKeyDownHandler); } onClearClick() { @@ -299,7 +236,7 @@ export default class DropDown extends Component { onContainerClick(event) { if (event.defaultPrevented) return; - let index = getPosition(this.container, event); + let index = getPosition(this.ul, event); if (index != -1) this.selectOption(index); } @@ -318,9 +255,6 @@ export default class DropDown extends Component { case 13: // Enter this.selectOption(option); break; - case 27: // Escape - this.hide(); - break; case 38: // Up this.moveToOption(option <= 0 ? nOpts : option - 1); break; @@ -342,8 +276,7 @@ export default class DropDown extends Component { } buildList() { - this.destroyScopes(); - this.scopes = []; + this.destroyList(); let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem'); @@ -377,23 +310,26 @@ export default class DropDown extends Component { } } - this.container.innerHTML = ''; - this.container.appendChild(fragment); + this.ul.appendChild(fragment); this.activateOption(this._activeOption); - this.relocate(); + this.$.$applyAsync(() => this.$.popover.relocate()); } - destroyScopes() { + destroyList() { + this.ul.innerHTML = ''; + if (this.scopes) for (let scope of this.scopes) scope.$destroy(); + + this.scopes = []; } $onDestroy() { - this.destroyScopes(); + this.destroyList(); } } -DropDown.$inject = ['$element', '$scope', '$transclude', '$timeout', '$http', '$translate']; +DropDown.$inject = ['$element', '$scope', '$transclude', '$timeout', '$http']; /** * Gets the position of an event element relative to a parent. diff --git a/client/core/src/components/drop-down/drop-down.spec.js b/client/core/src/components/drop-down/drop-down.spec.js index fc4028fc8..0b46f9ade 100644 --- a/client/core/src/components/drop-down/drop-down.spec.js +++ b/client/core/src/components/drop-down/drop-down.spec.js @@ -7,6 +7,7 @@ describe('Component vnDropDown', () => { let $element; let $scope; let $httpBackend; + let $transitions; let $q; let $filter; let controller; @@ -15,18 +16,25 @@ describe('Component vnDropDown', () => { angular.mock.module('client'); }); - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_, _$httpBackend_, _$q_, _$filter_) => { + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_, _$httpBackend_, _$q_, _$filter_, _$transitions_) => { $componentController = _$componentController_; $element = angular.element(`
${template}
`); $timeout = _$timeout_; + $transitions = _$transitions_; $q = _$q_; $filter = _$filter_; $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + let popoverTemplate = require('../popover/popover.html'); + let $popover = angular.element(`
${popoverTemplate}
`); + $scope.popover = $componentController('vnPopover', {$element: $popover, $scope, $timeout, $transitions}); + $scope.popover.$postLink(); + $scope.model = $componentController('vnModel', {$httpBackend, $q, $filter}); controller = $componentController('vnDropDown', {$element, $scope, $transclude: null, $timeout, $httpBackend, $translate: null}); + controller.$postLink(); controller.parent = angular.element('')[0]; })); diff --git a/client/core/src/components/drop-down/style.scss b/client/core/src/components/drop-down/style.scss index 71bfdd296..94521aff8 100755 --- a/client/core/src/components/drop-down/style.scss +++ b/client/core/src/components/drop-down/style.scss @@ -1,30 +1,7 @@ vn-drop-down { - z-index: 10; - position: fixed; - display: none; - top: 0; - left: 0; - right: 0; - bottom: 0; - - &.shown { - & > .body { - transform: translateY(0); - opacity: 1; - } - } - & > .body { - position: fixed; - box-shadow: 0 .1em .4em rgba(1, 1, 1, .4); - border-radius: .1em; - background-color: white; + .dropdown { display: flex; flex-direction: column; - transform: translateY(-.4em); - opacity: 0; - transition-property: opacity, transform; - transition-duration: 250ms; - transition-timing-function: ease-in-out; & > .filter { position: relative; @@ -35,6 +12,7 @@ vn-drop-down { box-sizing: border-box; border: none; border-bottom: 1px solid #ccc; + font-size: inherit; padding: .6em; } & > vn-icon[icon=clear] { @@ -64,10 +42,9 @@ vn-drop-down { ul { padding: 0; margin: 0; + list-style-type: none; } li, .status { - outline: none; - list-style-type: none; padding: .6em; cursor: pointer; white-space: nowrap; diff --git a/client/core/src/components/index.js b/client/core/src/components/index.js index 9077ada71..774971572 100644 --- a/client/core/src/components/index.js +++ b/client/core/src/components/index.js @@ -2,8 +2,6 @@ import './textfield/textfield'; import './watcher/watcher'; import './paging/paging'; import './icon/icon'; -import './autocomplete/autocomplete'; -import './popover/popover'; import './dialog/dialog'; import './confirm/confirm'; import './title/title'; @@ -12,7 +10,10 @@ import './spinner/spinner'; import './snackbar/snackbar'; import './tooltip/tooltip'; import './icon-menu/icon-menu'; +import './popover/popover'; +import './autocomplete/autocomplete'; import './drop-down/drop-down'; +import './menu/menu'; import './column-header/column-header'; import './grid-header/grid-header'; import './multi-check/multi-check'; diff --git a/client/core/src/components/menu/menu.js b/client/core/src/components/menu/menu.js new file mode 100755 index 000000000..ce32502d9 --- /dev/null +++ b/client/core/src/components/menu/menu.js @@ -0,0 +1,24 @@ +import ngModule from '../../module'; +import Popover from '../popover/popover'; + +export default class Menu extends Popover { + $postLink() { + super.$postLink(); + this.element.addEventListener('click', + () => this.onClick()); + } + + onClick() { + this.hide(); + } +} + +ngModule.component('vnMenu', { + template: require('../popover/popover.html'), + controller: Menu, + transclude: true, + bindings: { + onOpen: '&?', + onClose: '&?' + } +}); diff --git a/client/core/src/components/multi-check/multi-check.scss b/client/core/src/components/multi-check/multi-check.scss index 596a2e6f5..c253bbde6 100644 --- a/client/core/src/components/multi-check/multi-check.scss +++ b/client/core/src/components/multi-check/multi-check.scss @@ -2,10 +2,6 @@ vn-icon{ cursor: pointer; } - &:focus, &:active, &:hover{ - outline: none; - border: none; - } .primaryCheckbox { vn-icon{ font-size: 22px; diff --git a/client/core/src/components/popover/popover.html b/client/core/src/components/popover/popover.html new file mode 100644 index 000000000..3e3e6ca59 --- /dev/null +++ b/client/core/src/components/popover/popover.html @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/client/core/src/components/popover/popover.js b/client/core/src/components/popover/popover.js index 8430f037c..4e2326c77 100644 --- a/client/core/src/components/popover/popover.js +++ b/client/core/src/components/popover/popover.js @@ -1,205 +1,223 @@ import ngModule from '../../module'; -import './style.css'; +import Component from '../../lib/component'; +import './style.scss'; -directive.$inject = ['vnPopover']; -export function directive(vnPopover) { - return { - restrict: 'A', - link: function($scope, $element, $attrs) { - $element.on('click', function(event) { - vnPopover.showComponent($attrs.vnDialog, $scope, $element); - event.preventDefault(); - }); - } - }; -} -ngModule.directive('vnPopover', directive); - -export class Popover { - constructor($document, $compile, $transitions) { - this.document = $document[0]; - this.$compile = $compile; +/** + * A simple popover. + */ +export default class Popover extends Component { + constructor($element, $scope, $timeout, $transitions) { + super($element, $scope); + this.$timeout = $timeout; this.$transitions = $transitions; - this.removeScope = false; - this.popOpens = 0; + this._shown = false; } - _init() { - this.docMouseDownHandler = e => this.onDocMouseDown(e); - this.document.addEventListener('mousedown', this.docMouseDownHandler); + + $postLink() { + this.$element.addClass('vn-popover'); + this.docKeyDownHandler = e => this.onDocKeyDown(e); + this.docFocusInHandler = e => this.onDocFocusIn(e); + + this.element.addEventListener('mousedown', + e => this.onBackgroundMouseDown(e)); + this.element.addEventListener('focusin', + e => this.onFocusIn(e)); + + this.popover = this.element.querySelector('.popover'); + this.popover.addEventListener('mousedown', + e => this.onMouseDown(e)); + + this.arrow = this.element.querySelector('.arrow'); + this.content = this.element.querySelector('.content'); + } + + set child(value) { + this.content.appendChild(value); + } + + get child() { + return this.content.firstChild; + } + + get shown() { + return this._shown; + } + + set shown(value) { + if (value) + this.show(); + else + this.hide(); + } + + /** + * Shows the popover. If a parent is specified it is shown in a visible + * relative position to it. + */ + show() { + if (this._shown) return; + + this._shown = true; + this.element.style.display = 'block'; + this.$timeout.cancel(this.showTimeout); + this.showTimeout = this.$timeout(() => { + this.$element.addClass('shown'); + this.showTimeout = null; + }, 30); + this.document.addEventListener('keydown', this.docKeyDownHandler); - this.deregisterCallback = this.$transitions.onStart({}, - () => this.hideAll()); + this.document.addEventListener('focusin', this.docFocusInHandler); + + this.deregisterCallback = this.$transitions.onStart({}, () => this.hide()); + this.relocate(); + + if (this.onOpen) + this.onOpen(); } - _destroy() { - this.document.removeEventListener('mousedown', this.docMouseDownHandler); + + /** + * Hides the popover. + */ + hide() { + if (!this._shown) return; + + this._shown = false; + this.$element.removeClass('shown'); + this.$timeout.cancel(this.showTimeout); + this.showTimeout = this.$timeout(() => { + this.element.style.display = 'none'; + this.showTimeout = null; + }, 250); + this.document.removeEventListener('keydown', this.docKeyDownHandler); - this.docMouseDownHandler = null; - this.docKeyDownHandler = null; - this.deregisterCallback(); - } - show(childElement, parent, popoverId) { - this.childElement = childElement; - let popover = this.document.createElement('div'); - this.popOpens++; + this.document.removeEventListener('focusin', this.docFocusInHandler); - if (!popoverId) { - popoverId = 'popover-' + this.popOpens; - popover.id = popoverId; - } + if (this.deregisterCallback) + this.deregisterCallback(); - popover.className = 'vn-popover'; - popover.addEventListener('mousedown', - e => this.onPopoverMouseDown(e)); - popover.appendChild(childElement); - this.popover = popover; + if (this.parent) + this.parent.focus(); - let style = popover.style; - - let spacing = 0; - let screenMargin = 20; - let dblMargin = screenMargin * 2; - - let width = popover.offsetWidth; - let height = popover.offsetHeight; - let innerWidth = window.innerWidth; - let innerHeight = window.innerHeight; - - if (width + dblMargin > innerWidth) { - width = innerWidth - dblMargin; - style.width = width + 'px'; - } - - if (height + dblMargin > innerHeight) { - height = innerHeight - dblMargin; - style.height = height + 'px'; - } - - if (parent) { - let parentNode = parent; - let rect = parentNode.getBoundingClientRect(); - let left = rect.left; - let top = rect.top + spacing + parentNode.offsetHeight; - - if (left + width > innerWidth) - left -= (left + width) - innerWidth + margin; - - if (top + height > innerHeight) - top -= height + parentNode.offsetHeight + spacing * 2; - - if (left < 0) - left = screenMargin; - - if (top < 0) - top = screenMargin; - - style.top = (top) + 'px'; - style.left = (left) + 'px'; - style.minWidth = (rect.width) + 'px'; - } - - this.document.body.appendChild(popover); - - if (this.popOpens === 1) { - this._init(); - } - return popoverId; + if (this.onClose) + this.onClose(); } - showComponent(childComponent, $scope, parent) { - let childElement = this.document.createElement(childComponent); - let id = 'popover-' + this.popOpens; - childElement.id = id; - this.removeScope = true; - this.$compile(childElement)($scope.$new()); - this.show(childElement, parent, id); - return childElement; - } + /** + * Repositions the popover to a correct location relative to the parent. + */ + relocate() { + if (!(this.parent && this._shown)) return; - _checkOpens() { - this.popOpens = this.document.querySelectorAll('*[id^="popover-"]').length; - if (this.popOpens === 0) { - this._destroy(); - } - } + let style = this.popover.style; + style.width = ''; + style.height = ''; - _removeElement(val) { - if (!val) return; - let element = angular.element(val); - let parent = val.parentNode; - if (element.scope() && element.scope().$id > 1) { - element.scope().$destroy(); - } - element.remove(); - if (parent.className.indexOf('vn-popover') !== -1) - this._removeElement(parent); - } + let arrowStyle = this.arrow.style; + arrowStyle.top = ''; + arrowStyle.bottom = ''; - hide(id) { - let popover = this.document.querySelector(`#${id}`); - if (popover) { - this._removeElement(popover); - } - this._checkOpens(); - } + let parentRect = this.parent.getBoundingClientRect(); + let popoverRect = this.popover.getBoundingClientRect(); + let arrowRect = this.arrow.getBoundingClientRect(); - hideChilds(id) { - let popovers = this.document.querySelectorAll('*[id^="popover-"]'); - let idNumber = parseInt(id.split('-')[1], 10); - popovers.forEach( - val => { - if (parseInt(val.id.split('-')[1], 10) > idNumber) - this._removeElement(val); - } - ); - this._checkOpens(); - } + let arrowHeight = Math.sqrt(Math.pow(arrowRect.height, 2) * 2) / 2; - hideAll() { - let popovers = this.document.querySelectorAll('*[id^="popover-"]'); - popovers.forEach( - val => { - this._removeElement(val); - } - ); - this._checkOpens(); - } + let top = parentRect.top + parentRect.height + arrowHeight; + let left = parentRect.left; + let height = popoverRect.height; + let width = Math.max(popoverRect.width, parentRect.width); - _findPopOver(node) { - while (node != null) { - if (node.id && node.id.startsWith('popover-')) { - return node.id; - } - node = node.parentNode; - } - return null; - } + let margin = 10; + let showTop = top + height + margin > window.innerHeight; - onDocMouseDown(event) { - let targetId = this._findPopOver(event.target); - if (targetId) { - this.hideChilds(targetId); - } else { - this.hideAll(); - } + if (showTop) + top = Math.max(parentRect.top - height - arrowHeight, margin); + if (left + width + margin > window.innerWidth) + left = window.innerWidth - width - margin; + + if (showTop) + arrowStyle.bottom = `0`; + else + arrowStyle.top = `0`; + + arrowStyle.left = `${(parentRect.left - left) + parentRect.width / 2}px`; + + style.top = `${top}px`; + style.left = `${left}px`; + style.width = `${width}px`; + + if (height + margin * 2 + arrowHeight > window.innerHeight) + style.height = `${window.innerHeight - margin * 2 - arrowHeight}px`; } onDocKeyDown(event) { - if (event.keyCode === 27) { - let targetId = this._findPopOver(this.lastTarget); - if (targetId) { - this.hideChilds(targetId); - } else { - this.hideAll(); - } - this.lastTarget = null; + if (event.defaultPrevented) return; + + if (event.keyCode == 27) { // Esc + event.preventDefault(); + this.hide(); } } - onPopoverMouseDown(event) { - this.lastTarget = event.target; + onMouseDown(event) { + this.lastMouseEvent = event; + } + + onBackgroundMouseDown(event) { + if (event != this.lastMouseEvent) + this.hide(); + } + + onFocusIn(event) { + this.lastFocusEvent = event; + } + + onDocFocusIn(event) { + if (event !== this.lastFocusEvent) + this.hide(); } } -Popover.$inject = ['$document', '$compile', '$transitions']; +Popover.$inject = ['$element', '$scope', '$timeout', '$transitions']; -ngModule.service('vnPopover', Popover); +ngModule.component('vnPopover', { + template: require('./popover.html'), + controller: Popover, + transclude: true, + bindings: { + onOpen: '&?', + onClose: '&?' + } +}); + +class PopoverService { + constructor($document, $compile, $transitions, $rootScope) { + this.$compile = $compile; + this.$rootScope = $rootScope; + this.$document = $document; + this.stack = []; + } + show(child, parent, $scope) { + let element = this.$compile('')($scope || this.$rootScope)[0]; + let popover = element.$ctrl; + popover.parent = parent; + popover.child = child; + popover.show(); + popover.onClose = () => { + this.$document[0].body.removeChild(element); + if ($scope) $scope.$destroy(); + }; + this.$document[0].body.appendChild(element); + return popover; + } + + showComponent(componentTag, $scope, parent) { + let $newScope = $scope.$new(); + let childElement = this.$compile(`<${componentTag}/>`)($newScope)[0]; + this.show(childElement, parent, $newScope); + return childElement; + } +} +PopoverService.$inject = ['$document', '$compile', '$transitions', '$rootScope']; + +ngModule.service('vnPopover', PopoverService); diff --git a/client/core/src/components/popover/style.css b/client/core/src/components/popover/style.css deleted file mode 100644 index 536359a2f..000000000 --- a/client/core/src/components/popover/style.css +++ /dev/null @@ -1,9 +0,0 @@ -.vn-popover { - position: fixed; - box-shadow: 0 0 .4em rgba(1,1,1,.4); - background-color: white; - z-index: 100; - border-radius: .1em; - top: 0; - left: 0; -} \ No newline at end of file diff --git a/client/core/src/components/popover/style.scss b/client/core/src/components/popover/style.scss new file mode 100644 index 000000000..458a47df9 --- /dev/null +++ b/client/core/src/components/popover/style.scss @@ -0,0 +1,43 @@ +.vn-popover { + display: none; + z-index: 10; + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + + opacity: 0; + transform: translateY(-.6em); + transition-property: opacity, transform; + transition-duration: 200ms; + transition-timing-function: ease-in-out; + + &.shown { + transform: translateY(0); + opacity: 1; + } + & > .popover { + position: absolute; + display: flex; + box-shadow: 0 .1em .4em rgba(1, 1, 1, .4); + + & > .arrow { + width: 1em; + height: 1em; + margin: -.5em; + background-color: white; + box-shadow: 0 .1em .4em rgba(1, 1, 1, .4); + position: absolute; + transform: rotate(45deg); + z-index: 0; + } + & > .content { + width: 100%; + border-radius: .1em; + overflow: auto; + background-color: white; + z-index: 1; + } + } +} \ No newline at end of file diff --git a/client/core/src/components/textarea/style.scss b/client/core/src/components/textarea/style.scss new file mode 100644 index 000000000..91b29b3cf --- /dev/null +++ b/client/core/src/components/textarea/style.scss @@ -0,0 +1,6 @@ +vn-textarea { + & > .mdl-textfield { + width: initial; + display: block; + } +} \ No newline at end of file diff --git a/client/core/src/components/textarea/textarea.js b/client/core/src/components/textarea/textarea.js index 6bacdfc9f..122259ff3 100644 --- a/client/core/src/components/textarea/textarea.js +++ b/client/core/src/components/textarea/textarea.js @@ -1,5 +1,6 @@ import ngModule from '../../module'; import template from './textarea.html'; +import './style.scss'; directive.$inject = ['vnTemplate']; export function directive(vnTemplate) { diff --git a/client/core/src/components/textfield/style.scss b/client/core/src/components/textfield/style.scss index 81e5ca74c..181ad8d8b 100644 --- a/client/core/src/components/textfield/style.scss +++ b/client/core/src/components/textfield/style.scss @@ -1,7 +1,4 @@ vn-textfield { - div { - outline: none; //remove chrome outline - } .mdl-chip__action { position: absolute; width: auto; diff --git a/client/core/src/directives/index.js b/client/core/src/directives/index.js index 02f922149..23392e5e0 100644 --- a/client/core/src/directives/index.js +++ b/client/core/src/directives/index.js @@ -1,6 +1,7 @@ import './id'; import './focus'; import './dialog'; +import './popover'; import './validation'; import './acl'; import './on-error-src'; diff --git a/client/core/src/directives/popover.js b/client/core/src/directives/popover.js new file mode 100644 index 000000000..437d93783 --- /dev/null +++ b/client/core/src/directives/popover.js @@ -0,0 +1,26 @@ +import ngModule from '../module'; +import Popover from '../components/popover/popover'; +import {kebabToCamel} from '../lib/string'; + +/** + * Directive used to open a popover. + * + * @return {Object} The directive + */ +export function directive() { + return { + restrict: 'A', + link: function($scope, $element, $attrs) { + $element.on('click', function(event) { + let popoverKey = kebabToCamel($attrs.vnPopover); + let popover = $scope[popoverKey]; + if (popover instanceof Popover) { + popover.parent = $element[0]; + popover.show(); + } + event.preventDefault(); + }); + } + }; +} +ngModule.directive('vnPopover', directive); diff --git a/client/item/routes.json b/client/item/routes.json index 541f9cdf6..1da5d28b2 100644 --- a/client/item/routes.json +++ b/client/item/routes.json @@ -1,7 +1,7 @@ { "module": "item", "name": "Items", - "icon": "/static/images/icon_item.png", + "icon": "inbox", "validations" : true, "routes": [ { diff --git a/client/item/src/create/item-create.html b/client/item/src/create/item-create.html index 50495b2d9..d537fe7f6 100644 --- a/client/item/src/create/item-create.html +++ b/client/item/src/create/item-create.html @@ -23,12 +23,9 @@ - {{$parent.$parent.item.description}} + show-field="description" + field="$ctrl.item.intrastatFk"> diff --git a/client/item/src/data/item-data.html b/client/item/src/data/item-data.html index ebf47872d..507fdc2b2 100644 --- a/client/item/src/data/item-data.html +++ b/client/item/src/data/item-data.html @@ -30,10 +30,9 @@ show-field="description" value-field="id" field="$ctrl.item.intrastatFk" - order="description ASC" - filter-search= "{where: {or: [{id: {regexp: 'search'}}, {description: {regexp: 'search'}}]}}" + where="{or: [{id: {regexp: 'search'}}, {description: {regexp: 'search'}}]}" initial-data="$ctrl.item.intrastat"> - {{$parent.$parent.item.id}} : {{$parent.$parent.item.description}} + {{id}} : {{description}} diff --git a/client/item/src/niche/item-niche.html b/client/item/src/niche/item-niche.html index eb33f1c4b..ae30034db 100644 --- a/client/item/src/niche/item-niche.html +++ b/client/item/src/niche/item-niche.html @@ -1,7 +1,7 @@ + form="form">
@@ -9,13 +9,12 @@ diff --git a/client/item/src/tags/item-tags.html b/client/item/src/tags/item-tags.html index cfcfa736a..318a5dec7 100644 --- a/client/item/src/tags/item-tags.html +++ b/client/item/src/tags/item-tags.html @@ -14,7 +14,6 @@ data="tags.model" show-field="name" label="Tag" - order="name ASC" vn-acl="buyer"> -
    -
  • - - - -
  • -
+ +
    +
  • + + {{::mod.name}} +
  • +
+
-
    -
  • - {{::lang}} -
  • -
+ +
    +
  • + {{::lang}} +
  • +
+
vn-icon { + padding-right: .3em; + vertical-align: middle; + } + &:hover { + background-color: #FF9300; + opacity: 0.7 !important; + } + &:last-child { + margin-bottom: 0; + } } - i { - float: left; - padding-top: 13px; - margin-right: 3px; - } - } - li.mdl-menu__item:hover { - background-color: #FF9300; - opacity: 0.7 !important; - } - li.mdl-menu__item:last-child { - margin-bottom: 0; } } \ No newline at end of file diff --git a/client/salix/src/styles/misc.scss b/client/salix/src/styles/misc.scss index 34fc2063c..e20bda7ed 100644 --- a/client/salix/src/styles/misc.scss +++ b/client/salix/src/styles/misc.scss @@ -3,6 +3,21 @@ @import "colors"; @import "border"; + +a:focus, +input:focus, +button:focus +{ + outline: none; +} +button::-moz-focus-inner, +input[type=submit]::-moz-focus-inner, +input[type=button]::-moz-focus-inner, +input[type=reset]::-moz-focus-inner +{ + border: none; +} + .form { height: 100%; box-sizing: border-box; diff --git a/client/spliting.js b/client/spliting.js index 9d472675f..d5f641029 100644 --- a/client/spliting.js +++ b/client/spliting.js @@ -8,5 +8,7 @@ export default { locator: cb => require.ensure([], () => cb(require('locator'))), item: - cb => require.ensure([], () => cb(require('item'))) + cb => require.ensure([], () => cb(require('item'))), + ticket: + cb => require.ensure([], () => cb(require('ticket'))) }; diff --git a/client/ticket/index.js b/client/ticket/index.js new file mode 100644 index 000000000..dc559e2d9 --- /dev/null +++ b/client/ticket/index.js @@ -0,0 +1 @@ +export * from './src/ticket'; diff --git a/client/ticket/routes.json b/client/ticket/routes.json new file mode 100644 index 000000000..8fd9b65f5 --- /dev/null +++ b/client/ticket/routes.json @@ -0,0 +1,14 @@ +{ + "module": "ticket", + "name": "Tickets", + "icon": "receipt", + "validations": false, + "routes": [ + { + "url": "/tickets", + "state": "tickets", + "component": "vn-ticket-index", + "acl": ["developer"] + } + ] +} \ No newline at end of file diff --git a/client/ticket/src/index/index.html b/client/ticket/src/index/index.html new file mode 100644 index 000000000..51a50474c --- /dev/null +++ b/client/ticket/src/index/index.html @@ -0,0 +1,24 @@ + +
+
+ + + + + + + + + + + +
+
+ + + diff --git a/client/ticket/src/index/index.js b/client/ticket/src/index/index.js new file mode 100644 index 000000000..bc514194c --- /dev/null +++ b/client/ticket/src/index/index.js @@ -0,0 +1,14 @@ +import ngModule from '../module'; +import './item'; + +export default class Controller { + search(index) { + index.accept(); + } +} +Controller.$inject = []; + +ngModule.component('vnTicketIndex', { + template: require('./index.html'), + controller: Controller +}); diff --git a/client/ticket/src/index/item.html b/client/ticket/src/index/item.html new file mode 100644 index 000000000..eed354bff --- /dev/null +++ b/client/ticket/src/index/item.html @@ -0,0 +1,17 @@ + + + +
{{::$ctrl.ticket.name}}
+
Id {{::$ctrl.ticket.id}}
+
+ + + + +
+
diff --git a/client/ticket/src/index/item.js b/client/ticket/src/index/item.js new file mode 100644 index 000000000..c48d773f1 --- /dev/null +++ b/client/ticket/src/index/item.js @@ -0,0 +1,20 @@ +import ngModule from '../module'; + +class Controller { + onClick(event) { + if (event.defaultPrevented) + event.stopImmediatePropagation(); + } + + preview(event) { + event.preventDefault(); + } +} + +ngModule.component('vnTicketItem', { + controller: Controller, + template: require('./item.html'), + bindings: { + ticket: '<' + } +}); diff --git a/client/ticket/src/index/style.scss b/client/ticket/src/index/style.scss new file mode 100644 index 000000000..eb363a9a7 --- /dev/null +++ b/client/ticket/src/index/style.scss @@ -0,0 +1,3 @@ +vn-ticket-item { + display: block; +} \ No newline at end of file diff --git a/client/ticket/src/locale/en.yml b/client/ticket/src/locale/en.yml new file mode 100644 index 000000000..1f272d420 --- /dev/null +++ b/client/ticket/src/locale/en.yml @@ -0,0 +1 @@ +Tickets: Tickets \ No newline at end of file diff --git a/client/ticket/src/locale/es.yml b/client/ticket/src/locale/es.yml new file mode 100644 index 000000000..1f272d420 --- /dev/null +++ b/client/ticket/src/locale/es.yml @@ -0,0 +1 @@ +Tickets: Tickets \ No newline at end of file diff --git a/client/ticket/src/module.js b/client/ticket/src/module.js new file mode 100644 index 000000000..9a852e647 --- /dev/null +++ b/client/ticket/src/module.js @@ -0,0 +1,5 @@ +import {ng} from 'vendor'; +import 'core'; + +const ngModule = ng.module('ticket', ['vnCore']); +export default ngModule; diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js new file mode 100644 index 000000000..c7b861d2c --- /dev/null +++ b/client/ticket/src/ticket.js @@ -0,0 +1,4 @@ +export * from './module'; + +import './index/index'; + diff --git a/e2e/helpers/components_selectors.js b/e2e/helpers/components_selectors.js index ea46353d6..488d002e0 100644 --- a/e2e/helpers/components_selectors.js +++ b/e2e/helpers/components_selectors.js @@ -8,7 +8,6 @@ export default { vnSubmit: 'vn-submit > input', vnTopbar: 'vn-topbar > header', vnIcon: 'vn-icon', - vnMainMenu: 'vn-main-menu > div', vnModuleContainer: 'vn-module-container > a', vnSearchBar: 'vn-searchbar > form > vn-horizontal', vnFloatButton: 'vn-float-button > button', diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index e424708e1..7f146d30e 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -23,7 +23,7 @@ Nightmare.action('changeLanguageToEnglish', function(done) { this.then(done); } else { this.click('#lang') - .click('#langs-menu > li[name="en"]') + .click('vn-main-menu [vn-id="langs-menu"] ul > li[name="en"]') .then(done); } }); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 7ff92e006..ab30e2db7 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -6,8 +6,8 @@ export default { globalItems: { logOutButton: `#logout`, applicationsMenuButton: `#apps`, - applicationsMenuVisible: `${components.vnMainMenu} .is-visible > div`, - clientsButton: `${components.vnMainMenu} > div > ul > li:nth-child(1)` + applicationsMenuVisible: `vn-main-menu [vn-id="apps-menu"] ul`, + clientsButton: `vn-main-menu [vn-id="apps-menu"] ul > li:nth-child(1)` }, moduleAccessView: { clientsSectionButton: `${components.vnModuleContainer}[ui-sref="clients"]`, diff --git a/gulpfile.js b/gulpfile.js index e1b3df473..b2d6f6d3f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,6 +6,7 @@ const exec = require('child_process').exec; const PluginError = require('plugin-error'); const argv = require('minimist')(process.argv.slice(2)); const log = require('fancy-log'); +const environment = require('gulp-env'); // Configuration @@ -37,7 +38,13 @@ let defaultPort = proxyConf.defaultPort; // Development gulp.task('default', () => { - return gulp.start('services', 'client'); + return gulp.start('environment', 'services', 'client'); +}); + +gulp.task('environment', async () => { + await environment({ + file: '.env.json' + }); }); gulp.task('client', ['build-clean'], async () => { @@ -48,7 +55,7 @@ gulp.task('client', ['build-clean'], async () => { * Starts all backend services, including the nginx proxy and the database. */ gulp.task('services', async () => { - await runSequenceP('docker-start', 'services-only', 'nginx'); + await runSequenceP('environment', 'docker-start', 'services-only', 'nginx'); }); /** @@ -137,7 +144,7 @@ gulp.task('install', () => { // Deployment gulp.task('build', ['clean'], async () => { - await runSequenceP(['routes', 'locales', 'webpack', 'docker-compose', 'nginx-conf']); + await runSequenceP(['environment', 'routes', 'locales', 'webpack', 'docker-compose', 'nginx-conf']); }); gulp.task('docker-compose', async () => { @@ -154,7 +161,9 @@ gulp.task('docker-compose', async () => { // dockerFile = 'Dockerfile'; composeYml.services[service.name] = { - environment: ['NODE_ENV=${NODE_ENV}'], + environment: ['NODE_ENV=${NODE_ENV}' ,'salixHost=${salixHost}', 'salixPort=${salixPort}', + 'salixUser=${salixUser}', 'salixPassword=${salixPassword}' + ], container_name: `\${BRANCH_NAME}-${service.name}`, image: `${service.name}:\${TAG}`, build: { @@ -480,7 +489,8 @@ gulp.task('docker-wait', callback => { let conn = mysql.createConnection({ host: 'localhost', - user: 'root' + user: 'root', + password: 'root' }); conn.on('error', () => {}); conn.connect(err => { diff --git a/package.json b/package.json index 059a1bedd..7b4c19023 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "file-loader": "^1.1.6", "gulp": "^3.9.1", "gulp-concat": "^2.6.0", + "gulp-env": "^0.4.0", "gulp-extend": "^0.2.0", "gulp-install": "^1.1.0", "gulp-jasmine": "^3.0.0", diff --git a/services-test.config.js b/services-test.config.js deleted file mode 100644 index aa8866fc8..000000000 --- a/services-test.config.js +++ /dev/null @@ -1,24 +0,0 @@ -// const SpecReporter = require('jasmine-spec-reporter').SpecReporter; - -// module.exports = { -// reporter: new SpecReporter({ -// spec: { -// // displayStacktrace: 'summary', -// displaySuccessful: false, -// displayFailedSpec: true, -// displaySpecDuration: true -// } -// }), -// config: { -// spec_dir: 'services', -// spec_files: [ -// // '**/*.spec.js', -// 'auth/server/**/*.spec.js', -// 'client/common/**/*.spec.js', -// 'loopback/common/**/*.spec.js' -// ], -// helpers: [ -// '/services/utils/jasmineHelpers.js' -// ] -// } -// }; diff --git a/services/db/01-structure.sql b/services/db/01-structure.sql index d6bbf773c..df95b77bc 100644 --- a/services/db/01-structure.sql +++ b/services/db/01-structure.sql @@ -174,7 +174,7 @@ CREATE TABLE `mailAlias` ( `isPublic` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `alias` (`alias`) -) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases'; +) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -239,7 +239,7 @@ CREATE TABLE `role` ( `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Roles'; +) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Roles'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -318,7 +318,7 @@ CREATE TABLE `user` ( KEY `nickname` (`nickname`), KEY `lang` (`lang`), CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=102553 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; +) ENGINE=InnoDB AUTO_INCREMENT=102559 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2245,7 +2245,7 @@ CREATE TABLE `Agencias` ( PRIMARY KEY (`Id_Agencia`), KEY `Agencias` (`Agencia`), KEY `Vista` (`Vista`) -) ENGINE=InnoDB AUTO_INCREMENT=1112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1203 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2264,7 +2264,7 @@ CREATE TABLE `Agencias_dits` ( `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idAgencia_dits`) -) ENGINE=InnoDB AUTO_INCREMENT=15957 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=16044 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2364,7 +2364,7 @@ CREATE TABLE `Articles` ( CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=302721 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=303660 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2548,7 +2548,7 @@ CREATE TABLE `Articles_dits` ( KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=19731 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=19761 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2569,7 +2569,7 @@ CREATE TABLE `Articles_nicho` ( KEY `Articles_nicho_wh_fk` (`warehouse_id`), CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=395727 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=402653 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2728,7 +2728,7 @@ CREATE TABLE `Cajas` ( KEY `warehouse_id` (`warehouse_id`), KEY `fk_Cajas_Proveedores_account1_idx` (`Proveedores_account_Id`), CONSTRAINT `Cajas_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=559383 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=561976 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2875,7 +2875,7 @@ CREATE TABLE `Clientes` ( CONSTRAINT `Clientes_ibfk_5` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`chanel_id`) REFERENCES `chanel` (`chanel_id`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientes_tipo_id`) REFERENCES `clientes_tipo` (`clientes_tipo_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=102553 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=102559 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3045,7 +3045,7 @@ CREATE TABLE `Clientes_cedidos` ( CONSTRAINT `cliente_cedido_fk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `new_trabajador_fk` FOREIGN KEY (`Id_Trabajador_new`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `trabajador_fk` FOREIGN KEY (`Id_Trabajador_old`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Clientes que se han cambiado de comercial, pero durante un tiempo comisionan a los dos, al anterior y al actual'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Clientes que se han cambiado de comercial, pero durante un tiempo comisionan a los dos, al anterior y al actual'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3085,7 +3085,7 @@ CREATE TABLE `Clientes_empresa` ( PRIMARY KEY (`Id_Clientes_empresa`), KEY `empresa_id_idx` (`empresa_id`), CONSTRAINT `empresa_id` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=470504 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; +) ENGINE=InnoDB AUTO_INCREMENT=470507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3166,7 +3166,7 @@ CREATE TABLE `Colas` ( CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=68533 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=83645 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3248,7 +3248,7 @@ CREATE TABLE `Compres` ( CONSTRAINT `Compres_ibfk_2` FOREIGN KEY (`Id_Cubo`) REFERENCES `Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_3` FOREIGN KEY (`container_id`) REFERENCES `container` (`container_id`) ON UPDATE CASCADE, CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=240317560 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=241963558 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3500,7 +3500,7 @@ CREATE TABLE `Compres_ok` ( KEY `Id_Movimiento` (`Id_Compra`), KEY `Id_Accion` (`Id_Accion`), CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=16463 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=16747 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3544,7 +3544,7 @@ CREATE TABLE `Consignatarios` ( CONSTRAINT `Consignatarios_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_4` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24319 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=24415 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3924,7 +3924,7 @@ CREATE TABLE `Entradas` ( CONSTRAINT `Entradas_ibfk_1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_6` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_7` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=135810 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB AUTO_INCREMENT=136543 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4078,7 +4078,7 @@ CREATE TABLE `Entradas_dits` ( CONSTRAINT `Entradas_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2592663 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2614566 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4096,7 +4096,7 @@ CREATE TABLE `Entradas_kop` ( PRIMARY KEY (`Id_Entradas_kop`), KEY `entradas_entradas_kop_idx` (`Id_Entrada`), CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=296 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +) ENGINE=InnoDB AUTO_INCREMENT=391 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4339,7 +4339,7 @@ CREATE TABLE `Facturas` ( CONSTRAINT `Facturas_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_bank_id` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=446004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=446219 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4557,7 +4557,7 @@ CREATE TABLE `Greuges` ( KEY `Id_Ticket_Greuge_Ticket_idx` (`Id_Ticket`), CONSTRAINT `Id_Ticket_Greuge_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuges_type_fk` FOREIGN KEY (`Greuges_type_id`) REFERENCES `Greuges_type` (`Greuges_type_id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1787985 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; +) ENGINE=InnoDB AUTO_INCREMENT=1855894 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4756,7 +4756,7 @@ CREATE TABLE `Movimientos` ( KEY `itemFk_ticketFk` (`Id_Article`,`Id_Ticket`), CONSTRAINT `Movimientos_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `movement_ticket_id` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=19943254 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=20082659 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4905,7 +4905,7 @@ CREATE TABLE `Movimientos_mark` ( `Id_Movimiento_mark` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id_Movimiento_mark`), KEY `Id_Movimiento` (`Id_Movimiento`) -) ENGINE=InnoDB AUTO_INCREMENT=9437681 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9556205 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4975,7 +4975,7 @@ CREATE TABLE `Ordenes` ( KEY `Id_Comprador` (`CodCOMPRADOR`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `Id_Vendedor` (`CodVENDEDOR`) -) ENGINE=InnoDB AUTO_INCREMENT=26718 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=27213 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5148,7 +5148,7 @@ CREATE TABLE `Proveedores` ( CONSTRAINT `pay_dem_id` FOREIGN KEY (`pay_dem_id`) REFERENCES `pay_dem` (`id`) ON UPDATE CASCADE, CONSTRAINT `pay_met_id` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2452 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2455 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5174,7 +5174,7 @@ CREATE TABLE `Proveedores_account` ( KEY `fk_Proveedores_account_entity1_idx` (`entity_id`), KEY `fk_banco_prov_account_idx` (`Id_Banco`), CONSTRAINT `fk_banco_prov_account` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=602 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=607 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5265,7 +5265,7 @@ CREATE TABLE `Recibos` ( CONSTRAINT `Recibos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Recibos_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=441693 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=444548 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5376,7 +5376,7 @@ CREATE TABLE `Remesas` ( KEY `empresa_id` (`empresa_id`), CONSTRAINT `Remesas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1012 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1020 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5401,7 +5401,7 @@ CREATE TABLE `Reservas` ( PRIMARY KEY (`Id_Reserva`), KEY `Id_1` (`Id_Ticket`), KEY `Id_Article` (`Id_Article`) -) ENGINE=InnoDB AUTO_INCREMENT=219 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5432,7 +5432,7 @@ CREATE TABLE `Rutas` ( KEY `Fecha` (`Fecha`), KEY `gestdoc_id` (`gestdoc_id`), CONSTRAINT `Rutas_ibfk_1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=35960 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36243 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5494,7 +5494,7 @@ CREATE TABLE `Rutas_Master` ( PRIMARY KEY (`id`), KEY `fk_rutas_warehouse_id_idx` (`warehouse_id`), CONSTRAINT `fk_rutas_warehouse_id` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5620,7 +5620,7 @@ CREATE TABLE `Split_lines` ( KEY `Id_Compra` (`Id_Compra`), CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Split_lines_ibfk_1` FOREIGN KEY (`Id_Split`) REFERENCES `Splits` (`Id_Split`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=313507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=314176 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5638,7 +5638,7 @@ CREATE TABLE `Splits` ( `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Split`), KEY `Id_Entrada` (`Id_Entrada`) -) ENGINE=InnoDB AUTO_INCREMENT=36137 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36145 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5666,7 +5666,7 @@ CREATE TABLE `Stockcontrol` ( CONSTRAINT `Stockcontrol_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_2` FOREIGN KEY (`Id_Remitente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_3` FOREIGN KEY (`Id_Solver`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=23320 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23336 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5723,7 +5723,7 @@ CREATE TABLE `Tickets` ( CONSTRAINT `Tickets_ibfk_9` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON UPDATE CASCADE, CONSTRAINT `ticket_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `tickets_fk10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1778942 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1788324 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5929,7 +5929,7 @@ CREATE TABLE `Tickets_dits` ( CONSTRAINT `Tickets_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=57333460 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=57478959 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5978,7 +5978,7 @@ CREATE TABLE `Tickets_turno` ( `weekDay` tinyint(1) DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1778280 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1786572 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6041,7 +6041,7 @@ CREATE TABLE `Tipos` ( CONSTRAINT `Tipos_fk3` FOREIGN KEY (`confeccion`) REFERENCES `vn`.`confectionType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Tipos_ibfk_1` FOREIGN KEY (`reino_id`) REFERENCES `reinos` (`id`) ON UPDATE CASCADE, CONSTRAINT `Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=225 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; +) ENGINE=InnoDB AUTO_INCREMENT=226 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6128,7 +6128,7 @@ CREATE TABLE `Trabajadores` ( KEY `sub` (`sub`), CONSTRAINT `Clientes` FOREIGN KEY (`Id_Cliente_Interno`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1051 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1056 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6255,7 +6255,7 @@ CREATE TABLE `Vehiculos` ( KEY `provinceFk_idx` (`warehouseFk`), CONSTRAINT `Vehiculos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `provinceFk` FOREIGN KEY (`warehouseFk`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=366 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=367 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6281,7 +6281,7 @@ CREATE TABLE `Vehiculos_consumo` ( PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `Vehiculos` (`Id_Vehiculo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7382 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; +) ENGINE=InnoDB AUTO_INCREMENT=7450 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6395,7 +6395,7 @@ CREATE TABLE `XDiario` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3213074 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3220097 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6532,7 +6532,7 @@ CREATE TABLE `account_conciliacion` ( KEY `fg_accconciliacion_key1_idx` (`Id_Proveedores_account`), KEY `index_id_calculated` (`id_calculated`), CONSTRAINT `fg_key1_accountconc` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=29757 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=30713 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6716,7 +6716,7 @@ CREATE TABLE `agency_hour` ( CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4319 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4338 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6882,7 +6882,7 @@ CREATE TABLE `albaran` ( CONSTRAINT `fk_albaran_empresa1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2081 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2100 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6959,7 +6959,7 @@ CREATE TABLE `awb` ( CONSTRAINT `awbInvoiceIn` FOREIGN KEY (`invoiceInFk`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `awbTransitoryFk` FOREIGN KEY (`transitario_id`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2383 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2396 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7128,7 +7128,7 @@ CREATE TABLE `awb_component_template` ( CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk1` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE, CONSTRAINT `role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=485 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=488 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7209,7 +7209,7 @@ CREATE TABLE `awb_gestdoc` ( KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2085 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2098 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7327,7 +7327,7 @@ CREATE TABLE `barcodes` ( UNIQUE KEY `Id_Article_2` (`Id_Article`,`code`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=34349 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=34507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7468,7 +7468,7 @@ CREATE TABLE `buy_edi` ( KEY `kop` (`kop`), KEY `barcode` (`barcode`), KEY `fec` (`fec`) -) ENGINE=InnoDB AUTO_INCREMENT=647123 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=652104 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7722,7 +7722,7 @@ CREATE TABLE `cl_act` ( CONSTRAINT `cl_act_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_4` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=78009 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=78358 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7756,7 +7756,7 @@ CREATE TABLE `cl_cau` ( CONSTRAINT `cl_cau_ibfk_7` FOREIGN KEY (`cl_mot_id`) REFERENCES `cl_mot` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_8` FOREIGN KEY (`cl_con_id`) REFERENCES `cl_con` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_9` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=43195 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=43355 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7810,7 +7810,7 @@ CREATE TABLE `cl_det` ( CONSTRAINT `cl_det_ibfk_6` FOREIGN KEY (`cl_pet_id`) REFERENCES `cl_pet` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_7` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_8` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=108119 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=108577 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7867,7 +7867,7 @@ CREATE TABLE `cl_main` ( CONSTRAINT `cl_main_ibfk_3` FOREIGN KEY (`cl_est_id`) REFERENCES `cl_est` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_4` FOREIGN KEY (`cl_dep_id`) REFERENCES `cl_dep` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_5` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=46179 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB AUTO_INCREMENT=46420 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7980,7 +7980,7 @@ CREATE TABLE `client_observation` ( KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `client_observation_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `client_observation_ibfk_2` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=58071 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=58973 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8144,7 +8144,7 @@ CREATE TABLE `consignatarios_observation` ( `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`consignatarios_observation_id`), UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`) -) ENGINE=InnoDB AUTO_INCREMENT=2919 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB AUTO_INCREMENT=2957 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8226,7 +8226,7 @@ CREATE TABLE `credit` ( KEY `credit_ClienteFk` (`Id_Cliente`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=60036 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=60393 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8351,7 +8351,7 @@ CREATE TABLE `device` ( PRIMARY KEY (`device_id`), UNIQUE KEY `device_id_UNIQUE` (`device_id`), UNIQUE KEY `sn_UNIQUE` (`sn`) -) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=178 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8698,7 +8698,7 @@ CREATE TABLE `entity` ( UNIQUE KEY `bic_UNIQUE` (`bic`), KEY `fg_entity1_idx` (`pais_id`), CONSTRAINT `fg_entity1` FOREIGN KEY (`pais_id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10231 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; +) ENGINE=InnoDB AUTO_INCREMENT=30004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8737,7 +8737,7 @@ CREATE TABLE `escritos_det` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `escritos_det_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14715 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14806 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8766,7 +8766,7 @@ CREATE TABLE `expeditions` ( KEY `index4` (`ticket_id`), CONSTRAINT `Id_Agencia` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2252508 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2267551 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8906,7 +8906,7 @@ CREATE TABLE `expeditions_deleted` ( KEY `index2` (`EsBulto`), KEY `index3` (`odbc_date`), KEY `index4` (`ticket_id`) -) ENGINE=InnoDB AUTO_INCREMENT=2252457 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2267374 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9031,7 +9031,7 @@ CREATE TABLE `gestdoc` ( UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`), KEY `trabajador_id` (`trabajador_id`), KEY `warehouse_id` (`warehouse_id`) -) ENGINE=InnoDB AUTO_INCREMENT=839921 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=853237 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9230,7 +9230,7 @@ CREATE TABLE `intrastat_data` ( KEY `recibida` (`recibida_id`), CONSTRAINT `intrastat_data_ibfk_1` FOREIGN KEY (`intrastat_id`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `intrastat_data_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=62609 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=62709 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9596,7 +9596,7 @@ CREATE TABLE `mail` ( `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=1258900 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=1268459 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9639,7 +9639,7 @@ CREATE TABLE `mandato` ( CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`idmandato_tipo`) REFERENCES `mandato_tipo` (`idmandato_tipo`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14440 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14523 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9862,7 +9862,7 @@ CREATE TABLE `pago` ( CONSTRAINT `pago_moneda` FOREIGN KEY (`id_moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `pago_pay_met` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`id_proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=39600 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=39712 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10357,7 +10357,7 @@ CREATE TABLE `price_fixed` ( KEY `date_end` (`date_end`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `price_fixed_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=51882 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=51998 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10419,7 +10419,7 @@ CREATE TABLE `producer` ( `visible` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`producer_id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3809 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3860 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10602,7 +10602,7 @@ CREATE TABLE `recibida` ( CONSTRAINT `recibida_ibfk_5` FOREIGN KEY (`cplusInvoiceType472Fk`) REFERENCES `vn`.`cplusInvoiceType472` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_6` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_7` FOREIGN KEY (`cplusTrascendency472Fk`) REFERENCES `vn`.`cplusTrascendency472` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=64665 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=64959 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11101,7 +11101,7 @@ CREATE TABLE `recibida_entrada` ( KEY `Id_Entrada` (`Id_Entrada`), KEY `recibida_id` (`recibida_id`), CONSTRAINT `recibida_entrada_ibfk_2` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10025 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10104 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11189,7 +11189,7 @@ CREATE TABLE `recibida_iva` ( CONSTRAINT `recibida_iva_ibfk_2` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_5` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_6` FOREIGN KEY (`gastos_id`) REFERENCES `Gastos` (`Id_Gasto`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=85990 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=86376 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11212,7 +11212,7 @@ CREATE TABLE `recibida_vencimiento` ( KEY `banco_id` (`banco_id`), CONSTRAINT `recibida_vencimiento_ibfk_6` FOREIGN KEY (`banco_id`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibida_vencimiento_ibfk_7` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=83610 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=84057 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11449,7 +11449,7 @@ CREATE TABLE `scan` ( `name` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=47227 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +) ENGINE=InnoDB AUTO_INCREMENT=48191 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11489,7 +11489,7 @@ CREATE TABLE `scan_line` ( PRIMARY KEY (`scan_line_id`), KEY `id_scan_id_idx` (`scan_id`), CONSTRAINT `id_scan_id` FOREIGN KEY (`scan_id`) REFERENCES `scan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=615831 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=626820 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11511,7 +11511,7 @@ CREATE TABLE `sharingcart` ( KEY `Suplent` (`Id_Suplente`), CONSTRAINT `Suplent_key` FOREIGN KEY (`Id_Suplente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1704 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1713 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11966,7 +11966,7 @@ CREATE TABLE `ticket_observation` ( KEY `observation_type_id` (`observation_type_id`), CONSTRAINT `ticket_observation_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticket_observation_ibfk_2` FOREIGN KEY (`observation_type_id`) REFERENCES `observation_type` (`observation_type_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1000244 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=1007858 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12089,7 +12089,7 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouse_id_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=100511 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=101307 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12226,7 +12226,7 @@ CREATE TABLE `travel_dits` ( KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `travel_dits_ibfk_1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=153042 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=154573 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13661,7 +13661,7 @@ CREATE TABLE `workerTeam` ( PRIMARY KEY (`id`), KEY `user_team_idx` (`user`), CONSTRAINT `user_team` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31572,7 +31572,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `mana_requery_kk` */; +/*!50003 DROP PROCEDURE IF EXISTS `mana_requery` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -31582,7 +31582,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `mana_requery_kk`() +CREATE DEFINER=`root`@`%` PROCEDURE `mana_requery`() BEGIN DECLARE MyFechaDesde DATE; @@ -33514,6 +33514,15 @@ BEGIN JOIN Tickets t on t.Id_Ticket = tt.Id_Ticket JOIN Clientes c on c.Id_Cliente = t.Id_Cliente WHERE c.Congelado; + + -- Datos del cliente sin confirmar + + INSERT INTO tmp.buffer_problems(Id_Ticket, problem) + SELECT DISTINCT tt.Id_Ticket, 'FICHA INCOMPLETA' + FROM tmp.ticket_list tt + JOIN Tickets t on t.Id_Ticket = tt.Id_Ticket + JOIN Clientes c on c.Id_Cliente = t.Id_Cliente + WHERE c.contabilizado = FALSE; -- Riesgo @@ -35427,66 +35436,58 @@ BEGIN -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; -- Creamos una tabla con los Comerciales de los que se mostraran los tickets CALL subordinate(worker,TRUE); - select now(),1; + -- Se genera una tabla con los tickets representados DROP TEMPORARY TABLE IF EXISTS ticketRange; CREATE TEMPORARY TABLE ticketRange SELECT T.Id_Ticket, T.Id_Cliente, C.Id_Trabajador - FROM Tickets T - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente - INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador - WHERE Fecha >= yesterday - AND Fecha <= maxDate AND T.Factura Is NULL - AND IFNULL(tls.alertLevel,0) < 3 + FROM Tickets T + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente + INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 UNION DISTINCT SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador - FROM sharingclient s - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 + FROM sharingclient s + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 UNION DISTINCT SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente - FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador - INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 + FROM Clientes C + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador + INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 UNION DISTINCT SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador - /* - (SELECT Id_Trabajador - FROM Trabajadores t - JOIN account.user u ON u.id = t.user_id - JOIN workerTeam w on w.user = u.id - JOIN (SELECT team FROM workerTeam wt JOIN Trabajadores tr on tr.user_id = wt.user WHERE Id_Trabajador = worker) sub on sub.team = w.team - ) sub2 ON sub2.Id_Trabajador = C.Id_Trabajador - */ + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador WHERE Fecha >= yesterday AND Fecha <= maxDate AND T.Factura Is NULL AND IFNULL(tls.alertLevel,0) < 3 AND w.workerId = worker; - select now(),2; + IF (SELECT COUNT(*) FROM ticketRange) THEN -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) @@ -35495,13 +35496,13 @@ BEGIN CREATE TEMPORARY TABLE tmp.client_list (INDEX (Id_Cliente)) ENGINE = MEMORY - SELECT DISTINCT Id_Cliente FROM ticketRange; + SELECT DISTINCT Id_Cliente FROM ticketRange; DROP TEMPORARY TABLE IF EXISTS cr5; CREATE TEMPORARY TABLE cr5 (INDEX (Id_Cliente)) ENGINE = MEMORY - SELECT Id_Cliente FROM tmp.client_list; + SELECT Id_Cliente FROM tmp.client_list; DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket @@ -35509,17 +35510,19 @@ BEGIN SELECT t.Id_Ticket ticketFk FROM Tickets t STRAIGHT_JOIN tmp.client_list c ON t.Id_Cliente = c.Id_Cliente WHERE Fecha BETWEEN dateStart AND maxDate - AND Factura Is NULL; - select now(),3; + AND Factura IS NULL; + CALL vn.ticketGetTotal(); - select now(),4; + -- Generamos otra tabla temporal con los Tickets_iva DROP TEMPORARY TABLE IF EXISTS tt3; CREATE TEMPORARY TABLE tt3 ENGINE = MEMORY - SELECT * FROM tmp.ticketTotal tt - JOIN ticketRange tr ON tr.Id_Ticket = tt.ticketFk; + SELECT t.ticketFk, tt.total, tr.* + FROM tmp.ticket t + LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk + JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; -- Generamos la lista de tickets y sus datos @@ -35602,24 +35605,27 @@ BEGIN ) as TOTAL GROUP BY TOTAL.Id_Cliente ) AS Peligros ON Peligros.Id_Cliente = C.Id_Cliente - ; + ORDER BY C.Id_Cliente; -- Actualizamos el Riesgo con los tickets futuros set @cliente:= 0; SET @riesgo := 0; + SELECT * FROM Radartest; + UPDATE Radartest SET Riesgo = - IF(@cliente <> @cliente:= Id_Cliente , - Importe + @riesgo:= - Riesgo + Importe , - Importe + @riesgo:= @riesgo + Importe) + IF(@cliente <> @cliente:= Id_Cliente , - Importe + @riesgo:= - Riesgo + Importe , - Importe + @riesgo = @riesgo + Importe), + Propio = @riesgo order by Id_Cliente, Fecha_Simple DESC; - select now(),5; + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; CREATE TEMPORARY TABLE tmp.ticket_list SELECT Id_Ticket, Id_Cliente FROM Radartest; - select now(),6; + select * from Radartest; CALL prepare_client_list(); - select now(),7; CALL production_buffer_problems; - select now(),8; + + UPDATE Radartest r JOIN ( SELECT Id_Ticket, GROUP_CONCAT(problem) problem @@ -35627,7 +35633,7 @@ BEGIN GROUP BY Id_Ticket ) p on p.Id_Ticket = r.Id_Ticket SET r.problem = p.problem; - select now(),9; + SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador @@ -42789,6 +42795,148 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `workerCreate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `workerCreate`( + vName VARCHAR(50), + vCognames VARCHAR(50), + vDNI VARCHAR(9), + vAddress TEXT, + vPostalCode VARCHAR(5), + vTown VARCHAR(25), + vProvince SMALLINT(5), + vCompany SMALLINT(5), + vPhone VARCHAR(11), + vMail VARCHAR(80) CHARSET utf8, + vDniExpiration DATETIME, + vEmployeeBoss INT, + vRole INT, + vUsername VARCHAR(50) CHARSET utf8, + vPassword VARCHAR(50), + vWorkerCode VARCHAR(8) +) +BEGIN + DECLARE vClient INT; + DECLARE vUser INT; + DECLARE vWorker INT; + DECLARE vOficial INT DEFAULT 1; + DECLARE vDiscount INT DEFAULT 3; + DECLARE vPayMethodFk INT DEFAULT 4; + DECLARE vDueDay INT DEFAULT 5; + DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; + DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; + DECLARE vHasCoreVnl TINYINT(1) DEFAULT 1; + DECLARE vMandateType INT DEFAULT 2; + + +############################################################################## +#### GENERAR CLIENTE +############################################################################## + + -- Comprobar si existe un cliente con el mismo DNI. + SELECT Id_cliente INTO vClient FROM vn2008.Clientes WHERE `if` = vDNI; + + -- Si no existe el cliente creamos uno nuevo. + IF vClient IS NULL THEN + SELECT (MAX(Id_Cliente) + 1) INTO vClient FROM Clientes WHERE Id_Cliente < 999999; + END IF; + + REPLACE INTO Clientes ( + Id_Cliente, + Cliente, + Domicilio, + `IF`, + Telefono, + province_id, + Poblacion, + CodPostal, + RazonSocial, + Contacto, + Oficial, + Descuento, + Codpos, + pay_met_id, + Vencimiento, + credito, + contabilizado, + coreVnl) + SELECT + vClient, + Concat('TR ', vName, ' ', vCognames), + vAddress, + vDNI, + vPhone, + vProvince, + vTown, + vPostalCode, + CONCAT(vCognames, ' ', vName), + vName, + vOficial, + vDiscount, + vPostalCode, + vPayMethodFk, + vDueDay, + vDefaultCredit, + vIsTaxDataChecked, + vHasCoreVnl; + + REPLACE INTO mandato (Id_Cliente, empresa_id, idmandato_tipo) + VALUES (vClient, vCompany, vMandateType); + +############################################################################## +#### GENERAR USUARIO +############################################################################## + + -- Comprobamos si existe un usuario con el mismo ID de cliente. + IF NOT (SELECT COUNT(*) FROM account.user where id = vClient) THEN + + -- Alta del usuario. + INSERT INTO account.user (id, role, `name`, `password`, active) VALUES (vClient, vRole, LCASE(vUsername), MD5(LCASE(vPassword)), TRUE); + SET vUser = vClient; + INSERT INTO account.account SET id = vClient; + + END IF; + +############################################################################## +#### GENERAR TRABAJADOR +############################################################################## + + + -- Comprobamos si ya existe un trabajador con el mismo DNI. + IF NOT (SELECT COUNT(*) FROM Trabajadores WHERE dni = vDNI) THEN + + -- Alta en la tabla trabajadores. + INSERT INTO Trabajadores (CodigoTrabajador, Nombre, Apellidos, `Password`, dni, empresa_id, user_id, boss, DniExpiration) + VALUES (vWorkerCode, vName, vCognames, LCASE(vPassword), vDNI, vCompany, vUser, vEmployeeBoss, VDniExpiration); + + SET vWorker = LAST_INSERT_ID(); + ELSE + UPDATE Trabajadores SET user_id = vUser WHERE dni = vDNI; + END IF; + +############################################################################## +#### REENVIO EMAIL +############################################################################## + + IF vMail IS NOT NULL AND NOT (SELECT COUNT(*) FROM account.mailForward WHERE forwardTo = vMail) THEN + INSERT INTO account.mailForward (account, forwardTo) VALUES (vUser, vMail); + UPDATE Trabajadores SET email = CONCAT(vUsername, '@verdnatura.es') WHERE user_id = vUser; + END IF; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `XDiario_Quadrator` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42825,50 +42973,6 @@ GROUP BY ASIEN SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre), Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `__abono` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `__abono`(IN idT MEDIUMINT, IN idUSER SMALLINT) -BEGIN --- OBSOLETO USAR vn.refund() - DECLARE idC MEDIUMINT; - DECLARE newFEC DATE; - DECLARE idWH TINYINT; - DECLARE idUSER SMALLINT; - DECLARE idEMP MEDIUMINT; - DECLARE idCON MEDIUMINT; - DECLARE newTICKET MEDIUMINT; - - - SELECT Id_Cliente, TIMESTAMPADD(DAY, 1,Fecha), warehouse_id, empresa_id, Id_Consigna INTO idC, newFEC, idWH, idEMP, idCON - FROM Tickets WHERE Id_Ticket = idT; - - SELECT Id_Trabajador into idUSER from Trabajadores where user_id = account.userGetId(); - IF idUSER IS NULL THEN - SET idUSER = 20; - END IF; - - CALL ticket_new_complet(idC, newFEC, idWH, idUSER, idEMP, idCON, 23,NULL,newTICKET); - - UPDATE Tickets SET Etiquetasemitidas = 1 WHERE Id_Ticket = newTICKET; - - INSERT INTO Movimientos(Id_Ticket, Id_Article, Cantidad, Concepte, Preu, Descuento, PrecioFijado) - SELECT newTICKET, Id_Article, -1 * Cantidad, Concepte, Preu, Descuento, 1 FROM Movimientos WHERE Id_Ticket = idT; - SELECT newTICKET; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43645,7 +43749,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=153795 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=155666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44016,7 +44120,7 @@ CREATE TABLE `creditClassification` ( KEY `creditClassifClientFk_idx` (`client`), KEY `creditClassifdateEnd_idx` (`dateEnd`), CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2676 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2687 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -44061,7 +44165,7 @@ CREATE TABLE `creditInsurance` ( PRIMARY KEY (`id`), KEY `CreditInsurance_Fk1_idx` (`creditClassification`), CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1763 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB AUTO_INCREMENT=1780 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -44240,7 +44344,7 @@ CREATE TABLE `entryLog` ( KEY `logEntry_ibfk_1` (`originFk`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=29542 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=31221 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44686,7 +44790,7 @@ CREATE TABLE `invoiceOutExpence` ( KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`), CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=52055 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; +) ENGINE=InnoDB AUTO_INCREMENT=52304 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44729,7 +44833,7 @@ CREATE TABLE `invoiceOutTax` ( KEY `pgcFk` (`pgcFk`), CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=879675 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=880014 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44916,7 +45020,7 @@ CREATE TABLE `itemTag` ( KEY `priorityItem` (`itemFk`,`priority`), KEY `tagFk` (`tagFk`,`value`), CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=262345 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=263224 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44977,7 +45081,7 @@ CREATE TABLE `itemTaxCountry` ( CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=450401 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB AUTO_INCREMENT=454112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45164,7 +45268,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB AUTO_INCREMENT=1376594 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1385526 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45186,7 +45290,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB AUTO_INCREMENT=1521049 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1530071 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45630,7 +45734,7 @@ CREATE TABLE `priceBuilder` ( KEY `priceBuilder_fk2_idx` (`userFk`), CONSTRAINT `priceBuilder_fk1` FOREIGN KEY (`itemTypeFk`) REFERENCES `vn2008`.`Tipos` (`tipo_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `priceBuilder_fk2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45663,7 +45767,7 @@ CREATE TABLE `priceBuilderTag` ( KEY `priceBuilderTag_fk2_idx` (`tagFk`), CONSTRAINT `priceBuilderTag_fk1` FOREIGN KEY (`priceBuilderFk`) REFERENCES `priceBuilder` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `priceBuilderTag_fk2` FOREIGN KEY (`tagFk`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45682,7 +45786,7 @@ CREATE TABLE `priceBuilderWarehouse` ( KEY `priceBuilderWarehouse_fk2_idx` (`priceBuilderFk`), CONSTRAINT `priceBuilderWarehouse_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `priceBuilderWarehouse_fk2` FOREIGN KEY (`priceBuilderFk`) REFERENCES `priceBuilder` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45999,7 +46103,7 @@ CREATE TABLE `routeLog` ( `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=365371 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=375081 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46071,7 +46175,7 @@ CREATE TABLE `sms` ( `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=89356 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=89795 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46220,7 +46324,7 @@ CREATE TABLE `stockBuyed` ( UNIQUE KEY `date_UNIQUE` (`date`,`user`), KEY `stockBuyed_user_idx` (`user`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=246618 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=254813 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46439,7 +46543,7 @@ CREATE TABLE `ticketLog` ( KEY `logTicketuserFk` (`userFk`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=432726 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=462427 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46522,7 +46626,7 @@ CREATE TABLE `ticketPackaging` ( KEY `ticketPackaging_fk2_idx` (`packagingFk`), CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10866 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=12252 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46723,7 +46827,7 @@ CREATE TABLE `travelObservation` ( `description` text COLLATE utf8_unicode_ci NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel'; +) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46895,7 +46999,9 @@ SET character_set_client = utf8; 1 AS `userFk`, 1 AS `phone`, 1 AS `bossFk`, - 1 AS `photo`*/; + 1 AS `photo`, + 1 AS `fi`, + 1 AS `fiDueDate`*/; SET character_set_client = @saved_cs_client; -- @@ -46914,7 +47020,7 @@ CREATE TABLE `workerDocument` ( KEY `workerDocument_ibfk_2` (`document`), CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE, CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3698 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3788 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46936,7 +47042,7 @@ CREATE TABLE `workerLog` ( KEY `userFk_idx` (`userFk`), CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=1371 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1476 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46986,7 +47092,7 @@ CREATE TABLE `workingHours` ( PRIMARY KEY (`id`), KEY `user_working_hour_idx` (`userId`), CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=16896 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; +) ENGINE=InnoDB AUTO_INCREMENT=17538 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -48841,6 +48947,94 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clientCreate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `clientCreate`( + vFirstname VARCHAR(50), + vSurnames VARCHAR(50), + vFi VARCHAR(9), + vAddress TEXT, + vPostcode CHAR(5), + vCity VARCHAR(25), + vProvinceFk SMALLINT(5), + vCompanyFk SMALLINT(5), + vPhone VARCHAR(11)) +BEGIN +/** + * Create new client + * + */ + DECLARE vClientFk INT; + DECLARE vPayMethodFk INT DEFAULT 4; + DECLARE vDueDay INT DEFAULT 5; + DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; + DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; + DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE; + DECLARE vMandateTypeFk INT DEFAULT 2; + + SELECT id INTO vClientFk + FROM `client` + WHERE `fi` = vFi; + + IF ISNULL(vClientFk) THEN + + SELECT (MAX(id) + 1) INTO vClientFk + FROM `client` + WHERE id < 999999; + + INSERT INTO `client` ( + id, + name, + street, + fi, + phone, + provinceFk, + city, + postcode, + socialName, + payMethodFk, + dueDay, + credit, + isTaxDataChecked, + hasCoreVnl, + isEqualizated) + VALUES ( + vClientFk, + CONCAT('TR ', vFirstname, ' ', vSurnames), + vAddress, + vFi, + vPhone, + vProvinceFk, + vCity, + vPostcode, + CONCAT(vSurnames, ' ', vFirstname), + vPayMethodFk, + vDueDay, + vDefaultCredit, + vIsTaxDataChecked, + vHasCoreVnl, + FALSE + ); + + INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) + VALUES (vClientFk, vCompanyFk, vMandateTypeFk); + END IF; + + SELECT vClientFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientFreeze` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49417,6 +49611,69 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +/*!50003 DROP PROCEDURE IF EXISTS `greugeSpray` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `greugeSpray`(IN vClientFk INT, IN onlyForHisOwner BOOL, IN vWorkerCode VARCHAR(3)) +BEGIN + + DECLARE vGreuge DECIMAL(10,2); + DECLARE vOwner INT; + DECLARE vTotalSale INT; + DECLARE vGreugeTypeFk INT DEFAULT 5; -- HERENCIA + + SELECT sum(amount) INTO vGreuge + FROM vn.greuge + WHERE clientFk = vClientFk; + + IF LENGTH(vWorkerCode) = 0 THEN + + SELECT salesPersonFk INTO vOwner + FROM vn.client + WHERE id = vClientFk; + + ELSE + + SELECT id INTO vOwner + FROM vn.worker + WHERE workerCode = vWorkerCode COLLATE utf8_general_ci; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientList; + CREATE TEMPORARY TABLE tmp.clientList + SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) AS monthSale + FROM vn.ticket t + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.manaSpellers ms ON ms.worker = c.salesPersonFk + JOIN vn.claimRatio cr ON cr.clientFk = c.id + WHERE ms.worker = IF(onlyForHisOwner, vOwner, ms.worker) + AND t.shipped >= TIMESTAMPADD(MONTH,-1,CURDATE()) + AND c.id != vClientFk + HAVING monthSale > 100; + + SELECT SUM(monthSale) INTO vTotalSale + FROM tmp.clientList; + + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) + SELECT clientFk, CONCAT('Cliente: ',vClientFk), vGreuge * monthSale / vTotalSale, CURDATE(), vGreugeTypeFk + FROM tmp.clientList + UNION ALL + SELECT vClientFk, 'Reparto greuge', -vGreuge, CURDATE(), vGreugeTypeFk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceExpenceMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54978,33 +55235,6 @@ BEGIN FROM vn.ticket WHERE refFk = vInvoiceRef; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketToInvoiceByTicketkk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketToInvoiceByTicketkk`(vTicket INT) -BEGIN - - DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice; - - CREATE TEMPORARY TABLE vn.ticketToInvoice - SELECT id - FROM vn.ticket - WHERE id = vTicket - AND refFk IS NULL; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55096,6 +55326,49 @@ BEGIN */ -- CALL itemTagArrangedUpdate(NULL); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `workerCreate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `workerCreate`( + vFirstname VARCHAR(50), + vSurnames VARCHAR(50), + vFi VARCHAR(9), + vFiDueDate DATETIME, + vWorkerCode CHAR(3), + vBossFk INT, + vUserFk INT +) +BEGIN +/** + * Create new worker + * + */ + DECLARE vWorkerFk INT; + + SELECT id INTO vWorkerFk FROM worker + WHERE fi = vFi; + + IF ISNULL(vWorkerFk) THEN + INSERT INTO worker (workerCode, firstName, name, fi, userFk, bossFk, fiDueDate) + VALUES (vWorkerCode, vFirstname, vSurnames, vFi, vUserFk, vBossFk, vFiDueDate); + + SET vWorkerFk = LAST_INSERT_ID(); + END IF; + + SELECT vWorkerFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55540,7 +55813,7 @@ CREATE TABLE `batch` ( KEY `buy_edi_id` (`buy_edi_id`), CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=286285 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=289696 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -55878,7 +56151,7 @@ CREATE TABLE `message` ( UNIQUE KEY `mail_id` (`mail_id`), KEY `sender_id` (`sender_id`), CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=306399 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=310144 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -60794,9 +61067,9 @@ BEGIN WHILE datFEC < CURDATE() DO - REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas) + REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) - SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas + SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 FROM @@ -60835,7 +61108,8 @@ BEGIN -- Ahora calcularemos el greuge muerto - -- + + UPDATE bi.Greuge_Evolution ge JOIN maxInvoice m using(Id_Cliente) SET FOSIL = GREUGE @@ -62102,7 +62376,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=MyISAM AUTO_INCREMENT=183860 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=185216 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -62900,7 +63174,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDB AUTO_INCREMENT=84523 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=91572 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -64813,7 +65087,7 @@ CREATE TABLE `ACL` ( `principalType` set('ROLE','USER') COLLATE utf8_unicode_ci DEFAULT 'ROLE', `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -65556,7 +65830,7 @@ CREATE TABLE `inter` ( CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=9238943 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9384779 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66408,7 +66682,7 @@ CREATE TABLE `order` ( CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1275248 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1288000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66507,7 +66781,7 @@ CREATE TABLE `orderRow` ( KEY `warehouse_shipment` (`warehouseFk`,`shipment`), CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7916678 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7994327 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66921,7 +67195,7 @@ CREATE TABLE `tpvTransaction` ( CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=193683 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=195778 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66969,7 +67243,7 @@ CREATE TABLE `visit` ( PRIMARY KEY (`id`), KEY `firstAgent` (`firstAgent`), CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1177223 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1187533 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66989,7 +67263,7 @@ CREATE TABLE `visitAccess` ( KEY `visit_access_idx_agent` (`agent`), KEY `stamp` (`stamp`), CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2515652 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2541962 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67014,7 +67288,7 @@ CREATE TABLE `visitAgent` ( KEY `firstAccess` (`firstAccess`), CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1701495 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1713434 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67034,7 +67308,7 @@ CREATE TABLE `visitUser` ( KEY `date_time` (`stamp`), KEY `user_id` (`user`), CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2432187 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2452966 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -69432,7 +69706,159 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `__myTicketGet` */; + +-- +-- Current Database: `stock` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `stock` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */; + +USE `stock`; + +-- +-- Table structure for table `buy` +-- + +DROP TABLE IF EXISTS `buy`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `buy` ( + `buyFk` int(10) unsigned NOT NULL, + `entryFk` int(10) unsigned NOT NULL, + `travelFk` int(10) unsigned NOT NULL, + `itemFk` int(10) unsigned NOT NULL, + `shipped` date DEFAULT NULL, + `warehouseOutFk` smallint(6) unsigned DEFAULT NULL, + `isInventoryOut` tinyint(4) NOT NULL, + `isDelivered` tinyint(1) NOT NULL DEFAULT '0', + `landed` date NOT NULL, + `warehouseInFk` smallint(6) unsigned DEFAULT NULL, + `isInventoryIn` tinyint(4) NOT NULL, + `isReceived` tinyint(1) NOT NULL DEFAULT '0', + `isRaid` tinyint(1) NOT NULL DEFAULT '0', + `validUntil` date DEFAULT NULL, + `quantity` int(11) NOT NULL DEFAULT '0', + `available` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`buyFk`), + KEY `travelFk` (`travelFk`), + KEY `entryFk` (`entryFk`), + KEY `itemFkOut` (`itemFk`,`warehouseOutFk`), + KEY `itemFk` (`itemFk`,`warehouseInFk`,`validUntil`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `fault` +-- + +DROP TABLE IF EXISTS `fault`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `fault` ( + `itemFk` int(10) unsigned NOT NULL, + `warehouseFk` int(10) unsigned NOT NULL, + `date` date NOT NULL, + `quantity` int(11) NOT NULL DEFAULT '0', + UNIQUE KEY `itemFk` (`itemFk`,`warehouseFk`,`date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `itemRecalc` +-- + +DROP TABLE IF EXISTS `itemRecalc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemRecalc` ( + `itemFk` int(10) unsigned NOT NULL, + `warehouseFk` int(10) unsigned NOT NULL, + UNIQUE KEY `itemFk` (`itemFk`,`warehouseFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `queue` +-- + +DROP TABLE IF EXISTS `queue`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `queue` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `operation` set('ADD','DEL') COLLATE utf8_unicode_ci NOT NULL, + `tableName` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `tableId` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `sale` +-- + +DROP TABLE IF EXISTS `sale`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sale` ( + `saleFk` int(10) unsigned NOT NULL, + `ticketFk` int(10) unsigned NOT NULL, + `itemFk` int(10) unsigned NOT NULL, + `warehouseFk` smallint(6) unsigned NOT NULL, + `shipped` date NOT NULL, + `isPicked` tinyint(1) NOT NULL DEFAULT '0', + `quantity` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`saleFk`), + KEY `ticketFk` (`ticketFk`), + KEY `itemFk` (`itemFk`,`warehouseFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `visible` +-- + +DROP TABLE IF EXISTS `visible`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `visible` ( + `itemFk` int(10) unsigned NOT NULL, + `warehouseFk` int(10) unsigned NOT NULL, + `quantity` int(11) NOT NULL, + PRIMARY KEY (`itemFk`,`warehouseFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping events for database 'stock' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `queuePoll` */; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8mb4 */ ;; +/*!50003 SET character_set_results = utf8mb4 */ ;; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `queuePoll` ON SCHEDULE EVERY 10 SECOND STARTS '2017-06-27 17:15:02' ON COMPLETION NOT PRESERVE DISABLE DO CALL queuePoll */ ;; +/*!50003 SET time_zone = @saved_time_zone */ ;; +/*!50003 SET sql_mode = @saved_sql_mode */ ;; +/*!50003 SET character_set_client = @saved_cs_client */ ;; +/*!50003 SET character_set_results = @saved_cs_results */ ;; +/*!50003 SET collation_connection = @saved_col_connection */ ;; +DELIMITER ; +/*!50106 SET TIME_ZONE= @save_time_zone */ ; + +-- +-- Dumping routines for database 'stock' +-- +/*!50003 DROP PROCEDURE IF EXISTS `buyCalcAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -69442,41 +69868,587 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `__myTicketGet`(vTicket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `buyCalcAvailable`(vItem INT, vWarehouse INT) BEGIN /** - * Returns a current user ticket header. + * Calcula el disponible de un artículo en un almacén para + * todas sus compras. * - * @param vTicket The ticket identifier + * @param vItem El id del artículo + * @param vWarehouse El id de almacén */ - DECLARE vTaxBase DECIMAL(10,2); - DECLARE vTax DECIMAL(10,2); + DECLARE vShipped DATE; + DECLARE vQuantity INT; + DECLARE vUnavailable BOOL; + DECLARE vBuyId INT; + DECLARE vAvailable INT; + DECLARE vPick INT; + DECLARE vDone BOOL; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket + DECLARE cSales CURSOR FOR + SELECT shipped, quantity + FROM tSale + ORDER BY shipped; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + START TRANSACTION; + + DROP TEMPORARY TABLE IF EXISTS tSale; + CREATE TEMPORARY TABLE tSale ENGINE = MEMORY - SELECT id ticketFk FROM myTicket - WHERE id = vTicket; + SELECT shipped, quantity + FROM sale + WHERE itemFk = vItem + AND warehouseFk = vWarehouse + UNION ALL + SELECT shipped, quantity + FROM buy + WHERE itemFk = vItem + AND warehouseOutFk = vWarehouse; - CALL vn.ticketGetTax (NULL); + -- Resetea el disponible y el faltante de compras y ventas - SELECT SUM(taxBase), SUM(tax + equalizationTax) - INTO vTaxBase, vTax - FROM tmp.ticketTax; + UPDATE buy SET available = quantity + WHERE itemFk = vItem + AND warehouseInFk = vWarehouse; + + DELETE FROM fault + WHERE itemFk = vItem + AND warehouseFk = vWarehouse; - SELECT t.id, t.landed, t.shipped, t.refFk, ag.description agency, - a.street, a.postalCode, a.city, a.nickname, p.name province, - vTaxBase taxBase, vTaxBase + vTax AS total - FROM tmp.ticket v - JOIN vn.ticket t ON t.id = v.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.agencyMode ag ON ag.id = t.agencyModeFk - LEFT JOIN vn.province p ON p.id = a.provinceFk - WHERE t.id = vTicket; + -- Calcula el disponible - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticketTax; + OPEN cSales; + + l: LOOP + SET vDone = FALSE; + FETCH cSales INTO vShipped, vQuantity; + + IF vDone THEN + LEAVE l; + END IF; + + SET vUnavailable = FALSE; + + WHILE vQuantity > 0 AND NOT vUnavailable + DO + SET vDone = FALSE; + + SELECT buyFk, available INTO vBuyId, vAvailable + FROM buy + WHERE itemFk = vItem + AND warehouseInFk = vWarehouse + AND landed <= vShipped + AND validUntil >= vShipped + AND available > 0 + ORDER BY landed + LIMIT 1; + + IF vDone + THEN + SET vUnavailable = TRUE; + + INSERT INTO fault SET + itemFk = vItem, + warehouseFk = vWarehouse, + date = vShipped, + quantity = vQuantity + ON DUPLICATE KEY UPDATE + quantity = quantity + vQuantity; + ELSE + SET vPick = LEAST(vQuantity, vAvailable); + SET vQuantity = vQuantity - vPick; + + UPDATE buy SET available = available - vPick + WHERE buyFk = vBuyId; + END IF; + END WHILE; + END LOOP; + + CLOSE cSales; + + DROP TEMPORARY TABLE tSale; + + -- Confirma los cambios + + COMMIT; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `queueAdd` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `queueAdd`(vTableName VARCHAR(255), vNewId INT, vOldId INT) +proc: BEGIN + -- XXX: Disabled while testing + LEAVE proc; + + IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) + THEN + INSERT INTO queue SET + tableName = vTableName, + tableId = vOldId, + operation = 'DEL'; + END IF; + + IF vNewId IS NOT NULL + THEN + INSERT INTO queue SET + tableName = vTableName, + tableId = vNewId, + operation = 'ADD'; + END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `queuePoll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `queuePoll`() +proc: BEGIN +/** + * Procesa las operaciones pendientes de la tabla #queue. + */ + DECLARE vCount INT; + DECLARE vOperation VARCHAR(255); + DECLARE vTableName VARCHAR(255); + DECLARE vTableId INT; + DECLARE vItem INT; + DECLARE vWarehouse INT; + DECLARE vDone BOOL; + + DECLARE cQueue CURSOR FOR + SELECT operation, tableName, tableId + FROM tQueue; + + DECLARE cItemRecalc CURSOR FOR + SELECT itemFk, warehouseFk + FROM itemRecalc; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + DO RELEASE_LOCK('stock.queuePoll'); + RESIGNAL; + END; + + IF NOT GET_LOCK('stock.queuePoll', 0) THEN + LEAVE proc; + END IF; + + -- Procesa las modificaciones sobre movimientos + + loopPoll: LOOP + START TRANSACTION; + + DROP TEMPORARY TABLE IF EXISTS tQueue; + CREATE TEMPORARY TABLE tQueue + ENGINE = MEMORY + SELECT * FROM queue + ORDER BY created + LIMIT 10; + + SELECT COUNT(*) INTO vCount + FROM tQueue; + + IF vCount = 0 THEN + COMMIT; + LEAVE loopPoll; + END IF; + + DELETE l FROM queue l + JOIN tQueue t ON t.id = l.id; + + OPEN cQueue; + + loopQueue: LOOP + SET vDone = FALSE; + FETCH cQueue INTO vOperation, vTableName, vTableId; + + IF vDone THEN + LEAVE loopQueue; + END IF; + + IF vTableName IN ('travel', 'entry', 'buy') + THEN + CALL queuePollBuy (vTableName, vTableId, vOperation); + END IF; + + IF vTableName IN ('ticket', 'sale') + THEN + CALL queuePollSale (vTableName, vTableId, vOperation); + END IF; + END LOOP; + + CLOSE cQueue; + + DROP TEMPORARY TABLE + tQueue; + END LOOP; + + -- Recalcula el disponible para los artículos y almacenes afectados + + OPEN cItemRecalc; + + loopRecalc: LOOP + SET vDone = FALSE; + FETCH cItemRecalc INTO vItem, vWarehouse; + + IF vDone THEN + LEAVE loopRecalc; + END IF; + + CALL buyCalcAvailable (vItem, vWarehouse); + CALL visibleCalc (vItem, vWarehouse); + + DELETE FROM itemRecalc + WHERE itemFk = vItem + AND warehouseFk = vWarehouse; + + END LOOP; + + CLOSE cItemRecalc; + + -- Libera el bloqueo + + DO RELEASE_LOCK('stock.queuePoll'); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `queuePollBuy` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `queuePollBuy`(vTableName VARCHAR(255), vTableId INT, vOperation VARCHAR(255)) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tOldValues; + CREATE TEMPORARY TABLE tOldValues + (INDEX (buyFk)) + ENGINE = MEMORY + SELECT * FROM buy + WHERE (vTableName = 'travel' AND travelFk = vTableId) + OR (vTableName = 'entry' AND entryFk = vTableId) + OR (vTableName = 'buy' AND buyFk = vTableId); + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseOutFk FROM tOldValues + WHERE isInventoryOut; + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseInFk FROM tOldValues + WHERE isInventoryIn; + + IF vOperation = 'ADD' + THEN + DROP TEMPORARY TABLE IF EXISTS tNewValues; + CREATE TEMPORARY TABLE tNewValues + (INDEX (buyFk)) + ENGINE = MEMORY + SELECT + c.id buyFk, + c.entryFk, + e.travelFk, + c.itemFk, + t.shipped, + t.warehouseOutFk, + wo.isInventory isInventoryOut, + t.isDelivered, + t.landed, + t.warehouseInFk, + wi.isInventory isInventoryIn, + t.isReceived, + e.isRaid, + c.quantity, + TIMESTAMPADD(DAY, IFNULL(f.life, 365), landed) validUntil + FROM vn.buy c + JOIN vn.entry e ON e.id = c.entryFk + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.item i ON i.id = c.itemFk + JOIN vn.itemType f ON f.id = i.typeFk + JOIN vn.warehouse wo ON wo.id = t.warehouseOutFk + JOIN vn.warehouse wi ON wi.id = t.warehouseInFk + WHERE ((vTableName = 'travel' AND t.id = vTableId) + OR (vTableName = 'entry' AND e.id = vTableId) + OR (vTableName = 'buy' AND c.id = vTableId)) + AND (t.landed >= vn.getInventoryDate() + AND NOT e.isInventory + AND c.quantity > 0 + AND (wo.isInventory OR wi.isInventory)); + + REPLACE INTO buy (buyFk, entryFk, travelFk, itemFk, + shipped, warehouseOutFk, isInventoryOut, isDelivered, + landed, warehouseInFk, isInventoryIn, isReceived, + isRaid, quantity, validUntil) + SELECT * FROM tNewValues; + + DELETE t + FROM buy t + JOIN tOldValues o ON o.buyFk = t.buyFk + LEFT JOIN tNewValues n ON n.buyFk = t.buyFk + WHERE n.buyFk IS NULL; + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseOutFk FROM tNewValues + WHERE isInventoryOut; + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseInFk FROM tNewValues + WHERE isInventoryIn; + + DROP TEMPORARY TABLE tNewValues; + + ELSEIF vOperation = 'DEL' + THEN + DELETE b FROM buy b + JOIN tOldValues t USING(buyFk); + END IF; + + DROP TEMPORARY TABLE tOldValues; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `queuePollSale` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `queuePollSale`(vTableName VARCHAR(255), vTableId INT, vOperation VARCHAR(255)) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tOldValues; + CREATE TEMPORARY TABLE tOldValues + (INDEX (saleFk)) + ENGINE = MEMORY + SELECT * FROM sale + WHERE (vTableName = 'ticket' AND ticketFk = vTableId) + OR (vTableName = 'sale' AND saleFk = vTableId); + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseFk FROM tOldValues; + + IF vOperation = 'ADD' + THEN + DROP TEMPORARY TABLE IF EXISTS tNewValues; + CREATE TEMPORARY TABLE tNewValues + (INDEX (saleFk)) + ENGINE = MEMORY + SELECT + m.id saleFk, + m.ticketFk, + m.itemFk, + t.warehouseFk, + t.shipped, + m.isPicked OR s.alertLevel > 1 isPicked, + m.quantity + FROM vn.sale m + JOIN vn.ticket t ON t.id = m.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.ticketState s ON s.ticketFk = t.id + WHERE ((vTableName = 'ticket' AND t.id = vTableId) + OR (vTableName = 'sale' AND m.id = vTableId)) + AND (t.shipped >= vn.getInventoryDate() + AND m.quantity != 0 + AND w.isInventory); + + REPLACE INTO sale (saleFk, ticketFk, itemFk, warehouseFk, shipped, isPicked, quantity) + SELECT * FROM tNewValues; + + DELETE t + FROM sale t + JOIN tOldValues o ON o.saleFk = t.saleFk + LEFT JOIN tNewValues n ON n.saleFk = t.saleFk + WHERE n.saleFk IS NULL; + + INSERT IGNORE INTO itemRecalc (itemFk, warehouseFk) + SELECT itemFk, warehouseFk FROM tNewValues; + + DROP TEMPORARY TABLE tNewValues; + + ELSEIF vOperation = 'DEL' + THEN + DELETE m FROM sale m + JOIN tOldValues t USING(saleFk); + END IF; + + DROP TEMPORARY TABLE tOldValues; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `refreshAll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `refreshAll`() +BEGIN +/** + * Recalcula la caché completa. + */ + TRUNCATE TABLE itemRecalc; + TRUNCATE TABLE queue; + TRUNCATE TABLE fault; + TRUNCATE TABLE visible; + TRUNCATE TABLE stock.buy; + TRUNCATE TABLE stock.sale; + + INSERT INTO queue (operation, tableName, tableId) + SELECT 'ADD', 'travel', id + FROM vn.travel + WHERE shipped >= vn.getInventoryDate(); + + INSERT INTO queue (operation, tableName, tableId) + SELECT 'ADD', 'ticket', id + FROM vn.ticket + WHERE shipped >= vn.getInventoryDate(); + + CALL queuePoll; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `refreshDaily` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `refreshDaily`() +BEGIN +/** + * Elimina de la cache todas las compras y ventas previas + * a la fecha del último inventario. + */ + INSERT INTO queue (operation, tableName, tableId) + SELECT 'DEL', 'movement', saleFk + FROM sale + WHERE shipped < vn.getInventoryDate(); + + INSERT INTO queue (operation, tableName, tableId) + SELECT 'DEL', 'buy', buyFk + FROM buy + WHERE landed < vn.getInventoryDate(); + + CALL queuePoll; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `visibleCalc` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `visibleCalc`(vItem INT, vWarehouse INT) +BEGIN +/** + * Recalcula el visible para un artículo en un almacén. + * + * @param vItem Id de artículo + * @param vWarehouse Id de almacén + */ + DECLARE vVisible INT; + DECLARE vCurdate DATE DEFAULT CURDATE(); + + SELECT SUM(quantity) INTO vVisible + FROM ( + SELECT SUM(IF(vCurdate > landed OR isReceived, quantity, 0)) quantity + FROM buy + WHERE itemFk = vItem + AND warehouseInFk = vWarehouse + AND landed <= vCurdate + UNION ALL + SELECT -SUM(IF(vCurdate > shipped OR isDelivered, quantity, 0)) + FROM buy + WHERE itemFk = vItem + AND warehouseOutFk = vWarehouse + AND shipped <= vCurdate + UNION ALL + SELECT -SUM(IF(vCurdate > shipped OR isPicked, quantity, 0)) + FROM sale + WHERE itemFk = vItem + AND warehouseFk = vWarehouse + AND shipped <= vCurdate + ) t; + + IF vVisible > 0 + THEN + REPLACE INTO visible SET + itemFk = vItem, + warehouseFk = vWarehouse, + quantity = vVisible; + ELSE + DELETE FROM visible + WHERE itemFk = vItem + AND warehouseFk = vWarehouse; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73410,7 +74382,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `worker` AS select `t`.`Id_Trabajador` AS `id`,`t`.`CodigoTrabajador` AS `workerCode`,`t`.`Nombre` AS `firstName`,`t`.`Apellidos` AS `name`,`t`.`user_id` AS `userFk`,`t`.`phone` AS `phone`,`t`.`boss` AS `bossFk`,`t`.`Foto` AS `photo` from `vn2008`.`Trabajadores` `t` */; +/*!50001 VIEW `worker` AS select `t`.`Id_Trabajador` AS `id`,`t`.`CodigoTrabajador` AS `workerCode`,`t`.`Nombre` AS `firstName`,`t`.`Apellidos` AS `name`,`t`.`user_id` AS `userFk`,`t`.`phone` AS `phone`,`t`.`boss` AS `bossFk`,`t`.`Foto` AS `photo`,`t`.`dni` AS `fi`,`t`.`DniExpiration` AS `fiDueDate` from `vn2008`.`Trabajadores` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -74640,6 +75612,12 @@ USE `hedera`; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Current Database: `stock` +-- + +USE `stock`; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -74650,4 +75628,4 @@ USE `hedera`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2018-03-01 14:15:25 +-- Dump completed on 2018-03-12 7:44:03 diff --git a/services/db/03-changes.sh b/services/db/03-changes.sh index 4e0d23d3a..0f714b2aa 100644 --- a/services/db/03-changes.sh +++ b/services/db/03-changes.sh @@ -2,5 +2,5 @@ for file in changes/*/*.sql; do echo "Importing $file" - mysql -u root < $file + mysql -u root -proot < $file done diff --git a/services/db/04-fixtures.sql b/services/db/04-fixtures.sql index bcb82cef5..9a8a36e6f 100644 --- a/services/db/04-fixtures.sql +++ b/services/db/04-fixtures.sql @@ -24,8 +24,6 @@ INSERT INTO `account`.`user`(`id`,`name`,`password`,`role`,`active`,`email`) (109, 'BruceBanner', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceBanner@verdnatura.es'), (110, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'JessicaJones@verdnatura.es'); - - INSERT INTO `vn`.`worker`(`workerCode`, `id`, `firstName`, `name`, `userFk`) VALUES ('LGN', 106, 'David Charles', 'Haller', 106), @@ -273,6 +271,12 @@ INSERT INTO `vn2008`.`empresa`(`id`, `abbreviation`, `registro`, `gerente_id`, ` (9, 5, 5, NULL, CURDATE(), 105, 'Hulk', 109), (10, 6, 5, NULL, CURDATE(), 105, 'Jessica Jones', 110); +INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) + VALUES + ( 1, 1 , 1, 'ready' ), + ( 2, 2 , 2, 'do it fast please'), + ( 3, 3 , 3, ''); + INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`) VALUES (1, 1, 1, 5, CURDATE()), @@ -393,6 +397,24 @@ INSERT INTO `vn`.`item`(`id`, `name`,`typeFk`,`size`,`inkFk`,`category`,`stems`, (4, 'Mark I', 1, 60, 'AMR', 'EXT', 1, 1, 'Iron Mans first armor', 1, 05080000, 1, 2, 0, NULL, 0, 66090, 2), (5, 'Mjolnir', 3, 30, 'AZR', 'EXT', 1, 2, 'Thors hammer!', 2, 06021010, 1, 2, 0, NULL, 0, 67350, 2); +INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPackageReturnable`, `created`, `itemFk`, `price`) + VALUES + (1, 0.00, 10, 10, 0, 0, CURDATE(), 1, 1.50), + (2, 100.00, 20, 20, 0, 0, CURDATE(), 2, 1.00), + ('a', 50.00, 30, 30, 0, 1, CURDATE(), 3, 0.00); + +INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) + VALUES + ( 1, 1, 1, 2, CURDATE(), NULL), + ( 2, 2, 2, 1, CURDATE(), NULL), + ( 3, 3, 'a', 4, CURDATE(), NULL); + +INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) + VALUES + ( 1, 1, 1, 'Gem of Time', 5 , 1.5, 0, 0, 0, CURDATE()), + ( 2, 1, 1, 'Gem of Time', 2 , 1.5, 0, 0, 0, CURDATE()), + ( 3, 2, 2, 'Mjolnir' , 10, 4 , 0, 0, 0, CURDATE()); + INSERT INTO `vn`.`itemBarcode`(`id`, `itemFk`, `code`) VALUES (1, 1 ,1 ), diff --git a/services/db/Dockerfile b/services/db/Dockerfile index 1cc2b17eb..55ca078d2 100644 --- a/services/db/Dockerfile +++ b/services/db/Dockerfile @@ -1,6 +1,6 @@ FROM mysql:5.6.37 -ENV MYSQL_ALLOW_EMPTY_PASSWORD yes +ENV MYSQL_ROOT_PASSWORD root ENV TZ GMT-1 WORKDIR /docker-entrypoint-initdb.d diff --git a/services/db/changes/1.0.2/01-ACLinserts.sql b/services/db/changes/1.0.2/01-ACLinserts.sql new file mode 100644 index 000000000..ec1bc0282 --- /dev/null +++ b/services/db/changes/1.0.2/01-ACLinserts.sql @@ -0,0 +1,9 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Ticket', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('TicketObservation', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Route', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Sale', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('TicketTracking', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('TicketState', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('TicketPackaging', '*', '*', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Packaging', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Packaging', '*', 'WRITE', 'ALLOW', 'ROLE', 'logistic'); diff --git a/services/db/changes/1.0.2/02-packaging.sql b/services/db/changes/1.0.2/02-packaging.sql new file mode 100644 index 000000000..28c84109d --- /dev/null +++ b/services/db/changes/1.0.2/02-packaging.sql @@ -0,0 +1,18 @@ +USE `vn`; +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `vn`.`packaging` AS + SELECT + `c`.`Id_Cubo` AS `id`, + `c`.`Volumen` AS `volume`, + `c`.`X` AS `width`, + `c`.`Y` AS `height`, + `c`.`Z` AS `depth`, + `c`.`Retornable` AS `isPackageReturnable`, + `c`.`odbc_date` AS `created`, + `c`.`item_id` AS `itemFk`, + `c`.`pvp` AS `price` + FROM + `vn2008`.`Cubos` `c`; diff --git a/services/db/export-structure.cmd b/services/db/export-structure.cmd index 9a55d6740..599743dad 100755 --- a/services/db/export-structure.cmd +++ b/services/db/export-structure.cmd @@ -1,2 +1,2 @@ -mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera > 01-structure.sql +mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock > 01-structure.sql diff --git a/services/db/testing_fixtures.js b/services/db/testing_fixtures.js index ca525ccb1..a6e32c0d5 100644 --- a/services/db/testing_fixtures.js +++ b/services/db/testing_fixtures.js @@ -4,7 +4,7 @@ let connection = mysql.createConnection({ multipleStatements: true, host: 'localhost', user: 'root', - password: '', + password: 'root', database: 'salix' }); diff --git a/services/loopback/common/methods/client/createWithUser.js b/services/loopback/common/methods/client/createWithUser.js index 802707d96..f5220a839 100644 --- a/services/loopback/common/methods/client/createWithUser.js +++ b/services/loopback/common/methods/client/createWithUser.js @@ -1,5 +1,3 @@ -let md5 = require('md5'); - module.exports = function(Self) { Self.remoteMethod('createWithUser', { description: 'Creates both client and its web account', @@ -18,7 +16,7 @@ module.exports = function(Self) { } }); - Self.createWithUser = (data, callback) => { + Self.createWithUser = async data => { let firstEmail = data.email ? data.email.split(',')[0] : null; let user = { name: data.userName, @@ -27,34 +25,24 @@ module.exports = function(Self) { }; let Account = Self.app.models.Account; - Account.beginTransaction({}, (error, transaction) => { - if (error) return callback(error); + let transaction = await Account.beginTransaction({}); - Account.create(user, {transaction}, (error, account) => { - if (error) { - transaction.rollback(); - return callback(error); - } - - let client = { - name: data.name, - fi: data.fi, - socialName: data.socialName, - id: account.id, - email: data.email, - salesPersonFk: data.salesPersonFk - }; - - Self.create(client, {transaction}, (error, newClient) => { - if (error) { - transaction.rollback(); - return callback(error); - } - - transaction.commit(); - callback(null, newClient); - }); - }); - }); + try { + let account = await Account.create(user, {transaction}); + let client = { + id: account.id, + name: data.name, + fi: data.fi, + socialName: data.socialName, + email: data.email, + salesPersonFk: data.salesPersonFk + }; + newClient = await Self.create(client, {transaction}); + await transaction.commit(); + return newClient; + } catch (e) { + transaction.rollback(); + throw e; + } }; }; diff --git a/services/loopback/common/methods/client/specs/createWithUser.spec.js b/services/loopback/common/methods/client/specs/createWithUser.spec.js index eb41d0873..25f6789fb 100644 --- a/services/loopback/common/methods/client/specs/createWithUser.spec.js +++ b/services/loopback/common/methods/client/specs/createWithUser.spec.js @@ -48,45 +48,39 @@ describe('Client Create', () => { .catch(catchErrors(done)); }); - it('should not be able to create a user if exists', done => { - app.models.Client.findOne({where: {name: 'Charles Xavier'}}) - .then(client => { - app.models.Account.findOne({where: {id: client.id}}) - .then(account => { - let formerAccountData = { - name: client.name, - userName: account.name, - email: client.email, - fi: client.fi, - socialName: client.socialName - }; + it('should not be able to create a user if exists', async() => { + let client = await app.models.Client.findOne({where: {name: 'Charles Xavier'}}); + let account = await app.models.Account.findOne({where: {id: client.id}}); - app.models.Client.createWithUser(formerAccountData, (err, client) => { - expect(err.details.codes.name[0]).toEqual('uniqueness'); - done(); - }); - }); - }) - .catch(catchErrors(done)); + let formerAccountData = { + name: client.name, + userName: account.name, + email: client.email, + fi: client.fi, + socialName: client.socialName + }; + + try { + let client = await app.models.Client.createWithUser(formerAccountData); + + expect(client).toBeNull(); + } catch (err) { + expect(err.details.codes.name[0]).toEqual('uniqueness'); + } }); - it('should create a new account', done => { - app.models.Client.createWithUser(newAccountData, (error, client) => { - if (error) return catchErrors(done)(error); - app.models.Account.findOne({where: {name: newAccountData.userName}}) - .then(account => { - expect(account.name).toEqual(newAccountData.userName); - app.models.Client.findOne({where: {name: newAccountData.name}}) - .then(client => { - expect(client.id).toEqual(account.id); - expect(client.name).toEqual(newAccountData.name); - expect(client.email).toEqual(newAccountData.email); - expect(client.fi).toEqual(newAccountData.fi); - expect(client.socialName).toEqual(newAccountData.socialName); - done(); - }); - }) - .catch(catchErrors(done)); - }); + it('should create a new account', async() => { + let client = await app.models.Client.createWithUser(newAccountData); + let account = await app.models.Account.findOne({where: {name: newAccountData.userName}}); + + expect(account.name).toEqual(newAccountData.userName); + + client = await app.models.Client.findOne({where: {name: newAccountData.name}}); + + expect(client.id).toEqual(account.id); + expect(client.name).toEqual(newAccountData.name); + expect(client.email).toEqual(newAccountData.email); + expect(client.fi).toEqual(newAccountData.fi); + expect(client.socialName).toEqual(newAccountData.socialName); }); }); diff --git a/services/production/common/methods/state/list.js b/services/loopback/common/methods/state/list.js similarity index 100% rename from services/production/common/methods/state/list.js rename to services/loopback/common/methods/state/list.js diff --git a/services/production/common/methods/ticket-state/change-state.js b/services/loopback/common/methods/ticket-state/change-state.js similarity index 100% rename from services/production/common/methods/ticket-state/change-state.js rename to services/loopback/common/methods/ticket-state/change-state.js diff --git a/services/production/common/methods/ticket/change-time.js b/services/loopback/common/methods/ticket/change-time.js similarity index 100% rename from services/production/common/methods/ticket/change-time.js rename to services/loopback/common/methods/ticket/change-time.js diff --git a/services/production/common/methods/ticket/change-worker.js b/services/loopback/common/methods/ticket/change-worker.js similarity index 100% rename from services/production/common/methods/ticket/change-worker.js rename to services/loopback/common/methods/ticket/change-worker.js diff --git a/services/production/common/methods/ticket/list.js b/services/loopback/common/methods/ticket/list.js similarity index 55% rename from services/production/common/methods/ticket/list.js rename to services/loopback/common/methods/ticket/list.js index 371acf653..22567838e 100644 --- a/services/production/common/methods/ticket/list.js +++ b/services/loopback/common/methods/ticket/list.js @@ -1,13 +1,6 @@ module.exports = function(Ticket) { Ticket.remoteMethod('list', { description: 'List tickets for production', - /* accepts: { - arg: 'id', - type: 'number', - required: true, - description: 'Model id', - http: {source: 'path'} - },*/ returns: { arg: 'tickets', type: 'object' @@ -19,19 +12,8 @@ module.exports = function(Ticket) { }); Ticket.list = function(cb) { - // list(); - }; - - function list() { var params = [1, 0]; - var query = 'CALL production_control_source(?, ?)'; - - var cb = function(error, res) { - if (error) console.log(error); - else console.log(res); - }; - Ticket.rawSql(query, params, cb); }; }; diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index fd12caa37..928fe43d5 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -44,10 +44,22 @@ module.exports = function(Self) { allowBlank: true }); - let validateDni = require('../validations/validateDni'); - Self.validateBinded('fi', validateDni, { + Self.validateAsync('fi', fiIsValid, { message: 'DNI Incorrecto' }); + let validateDni = require('../validations/validateDni'); + async function fiIsValid(err, done) { + let filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + let country = await Self.app.models.Country.findOne(filter); + let code = country ? country.code.toLowerCase() : null; + + if (!validateDni(this.fi, code)) + err(); + done(); + } Self.validate('payMethod', hasSalesMan, { message: 'No se puede cambiar la forma de pago si no hay comercial asignado' diff --git a/services/production/common/models/route.json b/services/loopback/common/models/route.json similarity index 100% rename from services/production/common/models/route.json rename to services/loopback/common/models/route.json diff --git a/services/production/common/models/state.js b/services/loopback/common/models/state.js similarity index 100% rename from services/production/common/models/state.js rename to services/loopback/common/models/state.js diff --git a/services/production/common/models/state.json b/services/loopback/common/models/state.json similarity index 100% rename from services/production/common/models/state.json rename to services/loopback/common/models/state.json diff --git a/services/production/common/models/ticket-state.js b/services/loopback/common/models/ticket-state.js similarity index 100% rename from services/production/common/models/ticket-state.js rename to services/loopback/common/models/ticket-state.js diff --git a/services/production/common/models/ticket-state.json b/services/loopback/common/models/ticket-state.json similarity index 100% rename from services/production/common/models/ticket-state.json rename to services/loopback/common/models/ticket-state.json diff --git a/services/production/common/models/ticket.js b/services/loopback/common/models/ticket.js similarity index 100% rename from services/production/common/models/ticket.js rename to services/loopback/common/models/ticket.js diff --git a/services/loopback/common/models/ticket.json b/services/loopback/common/models/ticket.json new file mode 100644 index 000000000..493c18a78 --- /dev/null +++ b/services/loopback/common/models/ticket.json @@ -0,0 +1,76 @@ +{ + "name": "Ticket", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticket" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "shipped": { + "type": "date", + "required": true + }, + "landed": { + "type": "date" + }, + "nickname": { + "type": "String" + }, + "location": { + "type": "String" + }, + "solution": { + "type": "String" + }, + "packages": { + "type": "Number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + }, + "warehouse": { + "type": "belongsTo", + "model": "Warehouse", + "foreignKey": "warehouseFk" + }, + "invoiceOut": { + "type": "belongsTo", + "model": "InvoiceOut", + "foreignKey": "refFk" + }, + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" + }, + "route": { + "type": "belongsTo", + "model": "Route", + "foreignKey": "routeFk" + }, + "company": { + "type": "belongsTo", + "model": "Company", + "foreignKey": "companyFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk", + "required": true + } + } + } \ No newline at end of file diff --git a/services/loopback/common/validations/specs/validateDni.spec.js b/services/loopback/common/validations/specs/validateDni.spec.js index 2e902d6a2..e61ab23c8 100644 --- a/services/loopback/common/validations/specs/validateDni.spec.js +++ b/services/loopback/common/validations/specs/validateDni.spec.js @@ -1,39 +1,39 @@ const validateDni = require('../validateDni'); describe('DNI validation', () => { - it('should return false for invented DNI', () => { + it('should return true for any DNI when no country is passed', () => { let isValid = validateDni('Pepinillos'); - expect(isValid).toBeFalsy(); + expect(isValid).toBeTruthy(); }); describe('Spanish', () => { it('should return true for valid spanish DNI', () => { - let isValid = validateDni('20849756A'); + let isValid = validateDni('20849756A', 'es'); expect(isValid).toBeTruthy(); }); - it('should return true for spanish DNI with exceeded digits', () => { - let isValid = validateDni('208497563239A'); + it('should return false for spanish DNI with exceeded digits', () => { + let isValid = validateDni('208497563239A', 'es'); expect(isValid).toBeFalsy(); }); it('should return false for spanish DNI with invalid letter', () => { - let isValid = validateDni('20243746E'); + let isValid = validateDni('20243746E', 'es'); expect(isValid).toBeFalsy(); }); it('should return true for valid spanish CIF', () => { - let isValid = validateDni('B97367486'); + let isValid = validateDni('B97367486', 'es'); expect(isValid).toBeTruthy(); }); it('should return false for spanish CIF with invalid letter', () => { - let isValid = validateDni('A97527786'); + let isValid = validateDni('A97527786', 'es'); expect(isValid).toBeFalsy(); }); @@ -41,19 +41,19 @@ describe('DNI validation', () => { describe('French', () => { it('should return true for valid french DNI', () => { - let isValid = validateDni('FR1B123456789'); + let isValid = validateDni('1B123456789', 'fr'); expect(isValid).toBeTruthy(); }); - it('should return true for french DNI with exceeded digits', () => { - let isValid = validateDni('FR1B12345678910'); + it('should return false for french DNI with exceeded digits', () => { + let isValid = validateDni('1B12345678910', 'fr'); expect(isValid).toBeFalsy(); }); - it('should return true for french DNI with bad syntax', () => { - let isValid = validateDni('FR1B12345678A'); + it('should return false for french DNI with bad syntax', () => { + let isValid = validateDni('1B12345678A', 'fr'); expect(isValid).toBeFalsy(); }); @@ -61,19 +61,19 @@ describe('DNI validation', () => { describe('Italian', () => { it('should return true for valid italian DNI', () => { - let isValid = validateDni('IT12345678911'); + let isValid = validateDni('12345678911', 'it'); expect(isValid).toBeTruthy(); }); - it('should return true for italian DNI with exceeded digits', () => { - let isValid = validateDni('IT123456789112'); + it('should return false for italian DNI with exceeded digits', () => { + let isValid = validateDni('123456789112', 'it'); expect(isValid).toBeFalsy(); }); - it('should return true for italian DNI with bad syntax', () => { - let isValid = validateDni('IT1234567891A'); + it('should return false for italian DNI with bad syntax', () => { + let isValid = validateDni('1234567891A', 'it'); expect(isValid).toBeFalsy(); }); @@ -81,19 +81,19 @@ describe('DNI validation', () => { describe('Portuguese', () => { it('should return true for valid portuguese DNI', () => { - let isValid = validateDni('PT123456789'); + let isValid = validateDni('123456789', 'pt'); expect(isValid).toBeTruthy(); }); - it('should return true for portuguese DNI with exceeded digits', () => { - let isValid = validateDni('PT12345678910'); + it('should return false for portuguese DNI with exceeded digits', () => { + let isValid = validateDni('12345678910', 'pt'); expect(isValid).toBeFalsy(); }); - it('should return true for portuguese DNI with bad syntax', () => { - let isValid = validateDni('PT12345678A'); + it('should return false for portuguese DNI with bad syntax', () => { + let isValid = validateDni('12345678A', 'pt'); expect(isValid).toBeFalsy(); }); diff --git a/services/loopback/common/validations/validateDni.js b/services/loopback/common/validations/validateDni.js index 150603b7f..b169b6100 100644 --- a/services/loopback/common/validations/validateDni.js +++ b/services/loopback/common/validations/validateDni.js @@ -1,14 +1,12 @@ -module.exports = function(fiWithCountry) { - if (fiWithCountry == null) return true; - if (typeof fiWithCountry != 'string') return false; +module.exports = function(fi, country) { + if (fi == null || country == null) + return true; + if (typeof fi != 'string' || typeof country != 'string') + return false; - fiWithCountry = fiWithCountry.toUpperCase(); + fi = fi.toUpperCase(); + country = country.toLowerCase(); - if (!/^[A-Z]{2}/.test(fiWithCountry)) - fiWithCountry = `ES${fiWithCountry}`; - - let country = fiWithCountry.substring(0, 2).toLowerCase(); - let fi = fiWithCountry.substring(2); let len = fi.length; let validators = { @@ -38,7 +36,7 @@ module.exports = function(fiWithCountry) { let sum = (pairSum + oddSum).toString(); let units = parseInt(sum.charAt(sum.length - 1)); - let control = units != 0 ? 10 - units : 0; + let control = units == 0 ? 0 : 10 - units; let index = 'JABCDEFGHI'.indexOf(lastDigit); computedDigit = index == -1 ? control.toString() : index; } else { @@ -67,7 +65,7 @@ module.exports = function(fiWithCountry) { let validator = validators[country]; if (!validator) - return false; + return true; return validator.regExp.test(fi) && (!validator.validate || validator.validate()); diff --git a/services/loopback/common/validations/validateIban.js b/services/loopback/common/validations/validateIban.js index 76fffef5e..2e8883642 100644 --- a/services/loopback/common/validations/validateIban.js +++ b/services/loopback/common/validations/validateIban.js @@ -4,7 +4,7 @@ module.exports = function(iban) { iban = iban.toUpperCase(); iban = trim(iban); - iban = iban.replace(/\s/g, ""); + iban = iban.replace(/\s/g, ''); if (iban.length != 24) { return false; @@ -33,7 +33,7 @@ module.exports = function(iban) { function module97(iban) { var parts = Math.ceil(iban.length / 7); - var remainer = ""; + var remainer = ''; for (var i = 1; i <= parts; i++) { remainer = String(parseFloat(remainer + iban.substr((i - 1) * 7, 7)) % 97); @@ -48,6 +48,6 @@ module.exports = function(iban) { } function trim(text) { - return (text || "").replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "" ); + return (text || '').replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, ''); } }; diff --git a/services/loopback/server/datasources.json b/services/loopback/server/datasources.json index da7bcd44a..945c81966 100644 --- a/services/loopback/server/datasources.json +++ b/services/loopback/server/datasources.json @@ -1,37 +1,41 @@ { "db": { + "name": "db", "connector": "memory" }, "vn": { + "name": "mysql", "connector": "mysql", "database": "vn", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, "salix": { + "name": "mysql", "connector": "mysql", "database": "salix", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, "account": { + "name": "mysql", "connector": "mysql", "database": "account", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 }, @@ -39,10 +43,10 @@ "connector": "mysql", "database": "edi", "debug": false, - "host": "localhost", - "port": 3306, - "username": "root", - "password": "", + "host": "${salixHost}", + "port": "${salixPort}", + "username": "${salixUser}", + "password": "${salixPassword}", "connectTimeout": 20000, "acquireTimeout": 20000 } diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index 578d9456c..b0d9eda0a 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -56,5 +56,17 @@ }, "Worker": { "dataSource": "vn" - } + }, + "Ticket": { + "dataSource": "vn" + }, + "Route": { + "dataSource": "vn" + }, + "State":{ + "dataSource": "vn" + }, + "TicketState":{ + "dataSource": "vn" + } } diff --git a/services/mailer/application/config/datasources.json b/services/mailer/application/config/datasources.json index 865c68e47..6d489ec36 100644 --- a/services/mailer/application/config/datasources.json +++ b/services/mailer/application/config/datasources.json @@ -11,7 +11,7 @@ "port": 3306, "database": "vn", "user": "root", - "password": "" + "password": "root" }, "smtp": { "host": "localhost", diff --git a/services/print/application/config/datasources.json b/services/print/application/config/datasources.json index c797136ea..0c08c7d0a 100644 --- a/services/print/application/config/datasources.json +++ b/services/print/application/config/datasources.json @@ -9,7 +9,7 @@ "port": 3306, "database": "vn", "user": "root", - "password": "" + "password": "root" }, "pdf": { "format": "A4", diff --git a/services/production/common/models/ticket.json b/services/production/common/models/ticket.json deleted file mode 100644 index 4bfdc34d6..000000000 --- a/services/production/common/models/ticket.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "Ticket", - "base": "VnModel", - "options": { - "mysql": { - "table": "ticket" - } - }, - "properties": { - "id": { - "id": true, - "type": "Number", - "forceId": false - }, - "shipped": { - "type": "date" - } - } -} \ No newline at end of file diff --git a/services/production/server/model-config.json b/services/production/server/model-config.json index f06d6f57d..1e26ebc09 100644 --- a/services/production/server/model-config.json +++ b/services/production/server/model-config.json @@ -7,20 +7,5 @@ }, "MessageInbox": { "dataSource": "vn" - }, - "Route": { - "dataSource": "vn" - }, - "State":{ - "dataSource": "vn" - }, - "Ticket": { - "dataSource": "vn" - }, - "TicketState":{ - "dataSource": "vn" - }, - "TicketTracking": { - "dataSource": "vn" } } diff --git a/services/ticket/Dockerfile b/services/ticket/Dockerfile new file mode 100644 index 000000000..b91214f21 --- /dev/null +++ b/services/ticket/Dockerfile @@ -0,0 +1,12 @@ +FROM node:8.9.4 + +COPY ticket /app +COPY loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] + diff --git a/services/ticket/common/models/observationType.json b/services/ticket/common/models/observationType.json new file mode 100644 index 000000000..d86c870d2 --- /dev/null +++ b/services/ticket/common/models/observationType.json @@ -0,0 +1,28 @@ +{ + "name": "ObservationType", + "base": "VnModel", + "options": { + "mysql": { + "table": "observationType" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "description": { + "type": "String", + "required": true + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/services/ticket/common/models/packaging.json b/services/ticket/common/models/packaging.json new file mode 100644 index 000000000..e05de2c93 --- /dev/null +++ b/services/ticket/common/models/packaging.json @@ -0,0 +1,45 @@ +{ + "name": "Packaging", + "base": "VnModel", + "options": { + "mysql": { + "table": "packaging" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "volume": { + "type": "Number" + }, + "X": { + "type": "Date" + }, + "Y": { + "type": "Number" + }, + "Z": { + "type": "Number" + }, + "isPackageReturnable": { + "type": "Number" + }, + "created": { + "type": "Date" + }, + "price": { + "type": "Number" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Iicket", + "foreignKey": "itemFk" + } + } + } + \ No newline at end of file diff --git a/services/ticket/common/models/sale.json b/services/ticket/common/models/sale.json new file mode 100644 index 000000000..0ed01a347 --- /dev/null +++ b/services/ticket/common/models/sale.json @@ -0,0 +1,51 @@ +{ + "name": "Sale", + "base": "VnModel", + "options": { + "mysql": { + "table": "sale" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "concept": { + "type": "String" + }, + "quantity": { + "type": "Number" + }, + "price": { + "type": "Number" + }, + "discount": { + "type": "Number" + }, + "reserved": { + "type": "Number" + }, + "isPicked": { + "type": "Number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk", + "required": true + }, + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk", + "required": true + } + } +} diff --git a/services/ticket/common/models/ticketObservation.json b/services/ticket/common/models/ticketObservation.json new file mode 100644 index 000000000..a6e5e3029 --- /dev/null +++ b/services/ticket/common/models/ticketObservation.json @@ -0,0 +1,34 @@ +{ + "name": "TicketObservation", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketObservation" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "description": { + "type": "String", + "required": true + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk", + "required": true + }, + "observationType": { + "type": "belongsTo", + "model": "ObservationType", + "foreignKey": "observationTypeFk", + "required": true + } + } + } \ No newline at end of file diff --git a/services/ticket/common/models/ticketPackaging.json b/services/ticket/common/models/ticketPackaging.json new file mode 100644 index 000000000..e80b3fa5c --- /dev/null +++ b/services/ticket/common/models/ticketPackaging.json @@ -0,0 +1,38 @@ +{ + "name": "TicketPackaging", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketPackaging" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "quantity": { + "type": "Number" + }, + "created": { + "type": "Date" + }, + "pvp": { + "type": "Number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Packaging", + "foreignKey": "packagingFk" + } + } + } + \ No newline at end of file diff --git a/services/production/common/models/ticket-tracking.json b/services/ticket/common/models/ticketTracking.json similarity index 95% rename from services/production/common/models/ticket-tracking.json rename to services/ticket/common/models/ticketTracking.json index ce7ea659a..b1f2769d4 100644 --- a/services/production/common/models/ticket-tracking.json +++ b/services/ticket/common/models/ticketTracking.json @@ -30,7 +30,7 @@ }, "worker": { "type": "belongsTo", - "model": "worker", + "model": "Worker", "foreignKey": "workerFk" } } diff --git a/services/ticket/package.json b/services/ticket/package.json new file mode 100644 index 000000000..9cb389b71 --- /dev/null +++ b/services/ticket/package.json @@ -0,0 +1,16 @@ +{ + "name": "vn-ticket", + "version": "1.0.0", + "main": "server/server.js", + "scripts": { + "lint": "eslint .", + "start": "node .", + "posttest": "npm run lint && nsp check" + }, + "repository": { + "type": "git", + "url": "https://git.verdnatura.es/salix" + }, + "license": "GPL-3.0", + "description": "vn-ticket" +} diff --git a/services/ticket/server/model-config.json b/services/ticket/server/model-config.json new file mode 100644 index 000000000..55ec2a2a5 --- /dev/null +++ b/services/ticket/server/model-config.json @@ -0,0 +1,20 @@ +{ + "TicketObservation": { + "dataSource": "vn" + }, + "ObservationType": { + "dataSource": "vn" + }, + "Sale": { + "dataSource": "vn" + }, + "TicketTracking": { + "dataSource": "vn" + }, + "TicketPackaging": { + "dataSource": "vn" + }, + "Packaging": { + "dataSource": "vn" + } +} diff --git a/services/ticket/server/server.js b/services/ticket/server/server.js new file mode 100644 index 000000000..030bbc1b4 --- /dev/null +++ b/services/ticket/server/server.js @@ -0,0 +1,5 @@ + +var vnLoopback = require('../../loopback/server/server.js'); + +var app = module.exports = vnLoopback.loopback(); +vnLoopback.boot(app, __dirname, module); diff --git a/services_tests.js b/services_tests.js index fe3c907da..cbd7e7f81 100644 --- a/services_tests.js +++ b/services_tests.js @@ -13,6 +13,9 @@ if (process.argv[2] === '--v') { var Jasmine = require('jasmine'); var jasmine = new Jasmine(); var SpecReporter = require('jasmine-spec-reporter').SpecReporter; +let environment = require('gulp-env'); + +environment(".env.json"); jasmine.loadConfig({ spec_dir: 'services',