+
+
- New ticket
-
+
-
+
+
-
+
\ No newline at end of file
diff --git a/client/ticket/src/create/index.js b/client/ticket/src/create/index.js
index d7a59d800..2c50c1e44 100644
--- a/client/ticket/src/create/index.js
+++ b/client/ticket/src/create/index.js
@@ -1,20 +1,18 @@
import ngModule from '../module';
class Controller {
- constructor($scope, $state) {
+ constructor($scope, $http, $state) {
this.$ = $scope;
+ this.$http = $http;
this.$state = $state;
- this.Ticket = {};
}
- onSubmit() {
- this.$.watcher.submit().then(
- json => this.$state.go('ticket.card.data', {id: json.data.id})
- );
+ async onSubmit() {
+ let newOrderID = await this.$.card.createOrder();
+ this.$state.go("ticket.card.summary", {id: newOrderID});
}
}
-
-Controller.$inject = ['$scope', '$state'];
+Controller.$inject = ['$scope', '$http', '$state'];
ngModule.component('vnTicketCreate', {
template: require('./index.html'),
diff --git a/client/ticket/src/create/index.spec.js b/client/ticket/src/create/index.spec.js
index 468e648eb..89a59ca39 100644
--- a/client/ticket/src/create/index.spec.js
+++ b/client/ticket/src/create/index.spec.js
@@ -15,18 +15,17 @@ describe('Ticket', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
- $scope.card = {createTicket: () => {}};
+ $scope.card = {createOrder: () => {}};
$state = _$state_;
- $state.go = () => {};
controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state});
}));
describe('onSubmit()', () => {
- it(`should call createTicket()`, () => {
- spyOn(controller.$.card, 'createTicket');
+ it(`should call createOrder()`, () => {
+ spyOn(controller.$.card, 'createOrder');
controller.onSubmit();
- expect(controller.$.card.createTicket).toHaveBeenCalledWith();
+ expect(controller.$.card.createOrder).toHaveBeenCalledWith();
});
xit(`should call go()`, () => {
diff --git a/client/ticket/src/create/locale/es.yml b/client/ticket/src/create/locale/es.yml
new file mode 100644
index 000000000..df21d09f4
--- /dev/null
+++ b/client/ticket/src/create/locale/es.yml
@@ -0,0 +1,6 @@
+You can't create an order for a frozen client: No puedes crear una orden a un cliente congelado
+You can't create an order for a inactive client: No puedes crear una orden a un cliente inactivo
+You can't create an order for a client that doesn't has tax data verified:
+ No puedes crear una orden a un cliente cuyos datos fiscales no han sido verificados
+You can't create an order for a client that has a debt: No puedes crear una orden a un cliente que tiene deuda
+New order: Nueva orden
\ No newline at end of file
diff --git a/client/ticket/src/data/step-one/index.js b/client/ticket/src/data/step-one/index.js
index d7d81747b..ff986b426 100644
--- a/client/ticket/src/data/step-one/index.js
+++ b/client/ticket/src/data/step-one/index.js
@@ -1,5 +1,4 @@
import ngModule from '../../module';
-import {toJsonDate} from 'core/src/lib/date';
class Controller {
constructor($scope, $http, $translate, vnApp) {
@@ -36,7 +35,7 @@ class Controller {
let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`;
let data = {
- landed: toJsonDate(this.ticket.landed),
+ landed: this.ticket.landed,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
diff --git a/client/ticket/src/fetched-tags/index.html b/client/ticket/src/fetched-tags/index.html
index a40073577..7b6515d7c 100644
--- a/client/ticket/src/fetched-tags/index.html
+++ b/client/ticket/src/fetched-tags/index.html
@@ -1,6 +1,6 @@
{{::$ctrl.sale.concept}}
-
+
{{::ticket.id}}
{{::ticket.client.salesPerson.name | dashIfEmpty}} |
{{::ticket.shipped | date:'dd/MM/yyyy'}} |
- {{::ticket.shipped | date:'HH:MM'}} |
+ {{::ticket.shipped | date:'HH:mm'}} |
{{::ticket.nickname}} |
{{::ticket.address.province.name}} |
{{::ticket.tracking.state.name}} |
diff --git a/client/ticket/src/note/index.js b/client/ticket/src/note/index.js
index 8c2c602c9..ff9eef7b3 100644
--- a/client/ticket/src/note/index.js
+++ b/client/ticket/src/note/index.js
@@ -106,11 +106,11 @@ class Controller {
});
if (this.$scope.form.$invalid) {
- return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid'));
+ return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
}
if (repeatedType) {
- return this.vnApp.showMessage(this.$translate.instant('The observation type must be unique'));
+ return this.vnApp.showError(this.$translate.instant('The observation type must be unique'));
}
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
@@ -122,7 +122,7 @@ class Controller {
this.$scope.watcher.notifySaved();
});
}
- this.vnApp.showMessage(this.$translate.instant('No changes to save'));
+ this.vnApp.showError(this.$translate.instant('No changes to save'));
}
$onInit() {
diff --git a/client/ticket/src/note/ticket-observation.spec.js b/client/ticket/src/note/ticket-observation.spec.js
index f1bbbdd0b..fc2681375 100644
--- a/client/ticket/src/note/ticket-observation.spec.js
+++ b/client/ticket/src/note/ticket-observation.spec.js
@@ -90,7 +90,7 @@ describe('ticket', () => {
it("should return an error message 'Some fields are invalid'", () => {
controller.$scope.form = {};
controller.$scope.form.$invalid = true;
- spyOn(controller.vnApp, 'showMessage').and.callThrough();
+ spyOn(controller.vnApp, 'showError').and.callThrough();
controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
{observationTypeFk: 1, description: 'one', itemFk: 1}
@@ -98,12 +98,12 @@ describe('ticket', () => {
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
controller.submit();
- expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Some fields are invalid');
+ expect(controller.vnApp.showError).toHaveBeenCalledWith('Some fields are invalid');
});
it("should return an error message 'The observation type must be unique'", () => {
controller.$scope.form = {};
- spyOn(controller.vnApp, 'showMessage').and.callThrough();
+ spyOn(controller.vnApp, 'showError').and.callThrough();
controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
{observationTypeFk: 1, description: 'one', itemFk: 1}
@@ -111,7 +111,7 @@ describe('ticket', () => {
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
controller.submit();
- expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique');
+ expect(controller.vnApp.showError).toHaveBeenCalledWith('The observation type must be unique');
});
it("should perfom a query to delete observations", () => {
@@ -149,7 +149,7 @@ describe('ticket', () => {
it("should return a message 'No changes to save' when there are no changes to apply", () => {
controller.$scope.form = {$setPristine: () => {}};
- spyOn(controller.vnApp, 'showMessage').and.callThrough();
+ spyOn(controller.vnApp, 'showError').and.callThrough();
controller.oldObservations = [
{id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
{id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true}
@@ -157,7 +157,7 @@ describe('ticket', () => {
controller.ticketObservations = [];
controller.submit();
- expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save');
+ expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save');
});
});
});
diff --git a/client/ticket/src/package/index.js b/client/ticket/src/package/index.js
index a3f1119f9..c26be3d21 100644
--- a/client/ticket/src/package/index.js
+++ b/client/ticket/src/package/index.js
@@ -26,10 +26,10 @@ class Controller {
});
if (this.$.form.$invalid)
- return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid'));
+ return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
if (!this.hasChanges(packagesObj))
- return this.vnApp.showMessage(this.$translate.instant('No changes to save'));
+ return this.vnApp.showError(this.$translate.instant('No changes to save'));
this.$http.post(query, packagesObj).then(res => {
this.$.index.accept();
diff --git a/client/ticket/src/sale/index.html b/client/ticket/src/sale/index.html
index d1b69c763..5803b9742 100644
--- a/client/ticket/src/sale/index.html
+++ b/client/ticket/src/sale/index.html
@@ -107,7 +107,7 @@
{{(sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price))/100) | currency:' €':2}} |
-
+
No results |
@@ -197,7 +197,7 @@
New price
-
{{($ctrl.sale.quantity * $ctrl.sale.price)
+
{{($ctrl.sale.quantity * $ctrl.editedPrice)
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency:' €':2}}
-
-
+
+
+
+
+
+
diff --git a/client/ticket/src/sale/index.js b/client/ticket/src/sale/index.js
index 804211bf9..e18abd4a2 100644
--- a/client/ticket/src/sale/index.js
+++ b/client/ticket/src/sale/index.js
@@ -51,10 +51,8 @@ class Controller {
getVAT() {
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/getVAT`).then(res => {
- if (res.data) {
- this.VAT = res.data;
- this.total = this.subTotal + this.VAT;
- }
+ this.VAT = res.data || 0;
+ this.total = this.subTotal + this.VAT;
});
}
@@ -117,6 +115,7 @@ class Controller {
let params = {ticketFk: this.$state.params.id, weekDay: day};
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
this.$.addTurn.hide();
+ this.vnApp.showSuccess(this.translate.instant('Data saved!'));
});
}
@@ -204,6 +203,19 @@ class Controller {
this.$state.go("ticket.card.sale", {id: ticketID});
}
+ // Focus First Input
+ focusFirstInput(e) {
+ let firstFocusable = e.querySelector('input, textarea');
+ if (firstFocusable) {
+ firstFocusable.addEventListener('focus', () => {
+ firstFocusable.select();
+ });
+ setTimeout(() => {
+ firstFocusable.focus();
+ }, 200);
+ }
+ }
+
// Slesperson Mana
getManaSalespersonMana() {
this.$http.get(`/api/Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => {
@@ -232,6 +244,7 @@ class Controller {
};
this.$.editPricePopover.parent = event.target;
this.$.editPricePopover.show();
+ this.focusFirstInput(this.$.editPricePopover.$element[0]);
}
updatePrice() {
@@ -255,11 +268,13 @@ class Controller {
}];
this.$.editPopover.parent = event.target;
this.$.editPopover.show();
+ this.focusFirstInput(this.$.editPopover.$element[0]);
}
- async showEditDialog() {
+ showEditDialog() {
this.edit = this.getCheckedLines();
this.$.editDialog.show();
+ this.focusFirstInput(this.$.editDialog.$element[0]);
}
hideEditDialog() {
@@ -281,27 +296,6 @@ class Controller {
});
}
- /* updateLine() {
- if (this.edit.quantity != this.sale.quantity) {
- this.$http.post(`/ticket/api/Sales/updateQuantity`, {id: this.edit.id, quantity: this.edit.quantity}).then(() => {
- this.sale.quantity = this.edit.quantity;
- });
- }
-
- if (this.edit.price != this.sale.price) {
- this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.edit.price}).then(() => {
- this.sale.price = this.edit.price;
- });
- }
-
- if (this.edit.discount != this.sale.discount) {
- this.$http.post(`/ticket/api/Sales/updateDiscount`, {id: this.edit.id, discount: this.edit.discount}).then(() => {
- this.sale.discount = this.edit.discount;
- });
- }
- this.$.edit.hide();
- }*/
-
/**
* Unmark sale as reserved
*/
diff --git a/client/ticket/src/sale/locale/es.yml b/client/ticket/src/sale/locale/es.yml
index bfeb9cd37..f834f4c23 100644
--- a/client/ticket/src/sale/locale/es.yml
+++ b/client/ticket/src/sale/locale/es.yml
@@ -11,4 +11,6 @@ New ticket: Nuevo ticket
Edit price: Editar precio
You are going to delete lines of the ticket: Vas a borrar lineas del ticket
Continue anyway?: ¿Estás seguro?
-The new quantity should be smaller than the old one: La nueva cantidad debe de ser menor que la anterior
\ No newline at end of file
+The new quantity should be smaller than the old one: La nueva cantidad debe de ser menor que la anterior
+You have to allow pop-ups in your web browser to use this functionality:
+ Debes permitir los pop-pups en tu navegador para que esta herramienta funcione correctamente
\ No newline at end of file
diff --git a/client/ticket/src/sale/style.scss b/client/ticket/src/sale/style.scss
index abff21c8c..c8d06babc 100644
--- a/client/ticket/src/sale/style.scss
+++ b/client/ticket/src/sale/style.scss
@@ -52,13 +52,13 @@ vn-ticket-sale {
}
vn-popover.transfer{
- & table {
+ table {
min-width: 650px;
margin-bottom: 10px;
}
- & i {
+ vn-icon:nth-child(1) {
padding-top: 0.2em;
- font-size: 1.8em;
+ font-size: 1.7em;
}
}
diff --git a/client/ticket/src/summary/index.html b/client/ticket/src/summary/index.html
index 3e33e01d8..77d66820d 100644
--- a/client/ticket/src/summary/index.html
+++ b/client/ticket/src/summary/index.html
@@ -83,6 +83,9 @@
{{::sale.discount}} % |
{{::sale.quantity * sale.price | currency:'€':2}} |
+
+ No results |
+
diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js
index 2632740d6..4212b486a 100644
--- a/client/ticket/src/ticket.js
+++ b/client/ticket/src/ticket.js
@@ -3,6 +3,7 @@ export * from './module';
import './search-panel';
import './index';
import './create';
+import './create/card';
import './card';
import './descriptor';
import './summary';
diff --git a/e2e/paths/ticket-module/03_list_sale.spec.js b/e2e/paths/ticket-module/03_list_sale.spec.js
index f62ac21e6..2f6ec4ab6 100644
--- a/e2e/paths/ticket-module/03_list_sale.spec.js
+++ b/e2e/paths/ticket-module/03_list_sale.spec.js
@@ -64,11 +64,10 @@ describe('Ticket', () => {
.wait(selectors.ticketSales.secondSaleText)
.getInnerText(selectors.ticketSales.secondSaleText)
.then(value => {
- expect(value).toContain('Yellow');
- expect(value).toContain('2');
- expect(value).toContain('€23.50');
+ expect(value).toContain('Red');
+ expect(value).toContain('€4.50');
expect(value).toContain('0 %');
- expect(value).toContain('€47.00');
+ expect(value).toContain('€45.00');
});
});
});
diff --git a/services/client/common/models/credit-classification.json b/services/client/common/models/credit-classification.json
index 51bda330a..2e636af63 100644
--- a/services/client/common/models/credit-classification.json
+++ b/services/client/common/models/credit-classification.json
@@ -33,7 +33,7 @@
"model": "Client",
"foreignKey": "client"
},
- "creditInsurances": {
+ "insurances": {
"type": "hasMany",
"model": "CreditInsurance",
"foreignKey": "creditClassification"
diff --git a/services/db/install/changes/1.0.8/alertLevel.sql b/services/db/install/changes/1.0.8/alertLevel.sql
new file mode 100644
index 000000000..c338d681b
--- /dev/null
+++ b/services/db/install/changes/1.0.8/alertLevel.sql
@@ -0,0 +1,18 @@
+USE `vn`;
+
+CREATE TABLE `vn`.`alertLevel` (
+ `code` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL,
+ `alertLevel` INT(11) NOT NULL,
+ PRIMARY KEY (`code`));
+
+ALTER TABLE `vn`.`alertLevel`
+ADD CONSTRAINT `fk_code_1`
+ FOREIGN KEY (`code`)
+ REFERENCES `vn2008`.`state` (`code`)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE;
+
+INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('FREE', '0');
+INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('ON_PREPARATION', '1');
+INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('PACKED', '2');
+INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('DELIVERED', '3');
diff --git a/services/db/install/changes/1.0.8/itemDiary.sql b/services/db/install/changes/1.0.8/itemDiary.sql
new file mode 100644
index 000000000..ca853c5af
--- /dev/null
+++ b/services/db/install/changes/1.0.8/itemDiary.sql
@@ -0,0 +1,105 @@
+USE `vn`;
+DROP procedure IF EXISTS `itemDiary`;
+
+DELIMITER $$
+USE `vn`$$
+CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT)
+BEGIN
+ DECLARE vDateInventory DATETIME;
+ DECLARE vCurdate DATE DEFAULT CURDATE();
+ -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance
+ SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores;
+ SET @a = 0;
+ SELECT DATE(date) AS date,
+ alertLevel,
+ stateName,
+ origin,
+ reference,
+ name,
+ `in`,
+ `out`,
+ @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance
+ FROM
+ ( SELECT tr.landed as date,
+ b.quantity as `in`,
+ NULL as `out`,
+ IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
+ st.name AS stateName,
+ s.name as name,
+ e.ref as reference,
+ e.id as origin
+ FROM vn.buy b
+ JOIN vn.entry e ON e.id = b.entryFk
+ JOIN vn.travel tr ON tr.id = e.travelFk
+ JOIN vn.supplier s ON s.id = e.supplierFk
+ JOIN vn.alertLevel al ON al.alertLevel =
+ CASE
+ WHEN tr.isReceived != FALSE THEN 3
+ WHEN tr.isDelivered THEN 1
+ ELSE 0
+ END
+ JOIN vn.state st ON st.code = al.code
+ WHERE tr.landed >= vDateInventory
+ AND vWarehouse = tr.warehouseInFk
+ AND b.itemFk = vItemId
+ AND e.isInventory = 0
+
+ UNION ALL
+
+ SELECT tr.shipped as date,
+ NULL as `in`,
+ b.quantity as `out`,
+ IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
+ st.name AS stateName,
+ s.name as name,
+ e.ref as reference,
+ e.id as origin
+ FROM vn.buy b
+ JOIN vn.entry e ON e.id = b.entryFk
+ JOIN vn.travel tr ON tr.id = e.travelFk
+ JOIN vn.warehouse w ON w.id = tr.warehouseOutFk
+ JOIN vn.supplier s ON s.id = e.supplierFk
+ JOIN vn.alertLevel al ON al.alertLevel =
+ CASE
+ WHEN tr.isReceived != FALSE THEN 3
+ WHEN tr.isDelivered THEN 1
+ ELSE 0
+ END
+ JOIN vn.state st ON st.code = al.code
+ WHERE tr.shipped >= vDateInventory
+ AND vWarehouse =tr.warehouseOutFk
+ AND s.id <> 4
+ AND b.itemFk = vItemId
+ AND e.isInventory = 0
+ AND w.isFeedStock = 0
+
+ UNION ALL
+
+ SELECT t.shipped as date,
+ NULL as `in`,
+ s.quantity as `out`,
+ IF(t.shipped < vCurdate,3,IF(t.shipped > vCurdate, 0, IFNULL(ts.alertLevel,0))) as alertLevel,
+ st.name AS stateName,
+ t.nickname as name,
+ t.refFk as reference,
+ t.id as origin
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ LEFT JOIN vn.ticketState ts ON ts.ticket = t.id
+ JOIN vn.client c ON c.id = t.clientFk
+ JOIN vn.alertLevel al ON al.alertLevel =
+ CASE
+ WHEN t.shipped < vCurdate THEN 3
+ WHEN t.shipped > vCurdate THEN 0
+ ELSE IFNULL(ts.alertLevel, 0)
+ END
+ JOIN vn.state st ON st.code = al.code
+ WHERE t.shipped >= vDateInventory
+ AND s.itemFk = vItemId
+ AND vWarehouse =t.warehouseFk
+ ) AS itemDiary
+ ORDER BY date, alertLevel, `in` DESC;
+END$$
+
+DELIMITER ;
+
diff --git a/services/loopback/common/methods/agency/landsThatDay.js b/services/loopback/common/methods/agency/landsThatDay.js
new file mode 100644
index 000000000..00184f32f
--- /dev/null
+++ b/services/loopback/common/methods/agency/landsThatDay.js
@@ -0,0 +1,27 @@
+module.exports = Self => {
+ Self.remoteMethod('landsThatDay', {
+ description: 'Returns a list of agencies that can land a shipment on a day for an address',
+ accessType: '',
+ accepts: [{
+ arg: 'filter',
+ type: 'object',
+ required: true,
+ description: 'addressFk'
+ }],
+ returns: {
+ type: 'object',
+ root: true
+ },
+ http: {
+ path: `/landsThatDay`,
+ verb: 'get'
+ }
+ });
+
+ Self.landsThatDay = async filter => {
+ let query = `CALL vn.agencyHourGetAgency(?, ?)`;
+ let result = await Self.rawSql(query, [filter.addressFk, filter.landed]);
+
+ return result;
+ };
+};
diff --git a/services/loopback/common/methods/client/summary.js b/services/loopback/common/methods/client/summary.js
index 95cecbc9d..ab0732032 100644
--- a/services/loopback/common/methods/client/summary.js
+++ b/services/loopback/common/methods/client/summary.js
@@ -47,6 +47,19 @@ module.exports = Self => {
where: {isDefaultAddress: true},
fields: ['nickname', 'street', 'city', 'postalCode']
}
+ },
+ {
+ relation: 'classifications',
+ scope: {
+ include: {
+ relation: 'insurances',
+ scope: {
+ fields: ['id', 'grade', 'created'],
+ order: 'created DESC'
+ }
+ },
+ where: {finished: null}
+ }
}
],
where: {id: clientId}
diff --git a/services/loopback/common/models/agency.js b/services/loopback/common/models/agency.js
index 251ba183a..9994624df 100644
--- a/services/loopback/common/models/agency.js
+++ b/services/loopback/common/models/agency.js
@@ -1,5 +1,5 @@
module.exports = Self => {
Self.defineScope({where: {isManaged: {neq: 0}}});
- //require('../methods/agency/sendsThatDay')(Self);
+ require('../methods/agency/landsThatDay')(Self);
require('../methods/agency/getFirstShipped')(Self);
};
diff --git a/services/loopback/common/models/client.json b/services/loopback/common/models/client.json
index 4c7d4d31b..d80e31d9e 100644
--- a/services/loopback/common/models/client.json
+++ b/services/loopback/common/models/client.json
@@ -160,7 +160,7 @@
"model": "Greuge",
"foreignKey": "clientFk"
},
- "creditClassifications": {
+ "classifications": {
"type": "hasMany",
"model": "CreditClassification",
"foreignKey": "client"
diff --git a/services/loopback/server/connectors/vn-mysql.js b/services/loopback/server/connectors/vn-mysql.js
new file mode 100644
index 000000000..27f200975
--- /dev/null
+++ b/services/loopback/server/connectors/vn-mysql.js
@@ -0,0 +1,55 @@
+
+var mysql = require('mysql');
+var SqlConnector = require('loopback-connector').SqlConnector;
+var MySQL = require('loopback-connector-mysql').MySQL;
+var EnumFactory = require('loopback-connector-mysql').EnumFactory;
+
+exports.initialize = function(dataSource, callback) {
+ dataSource.driver = mysql;
+ dataSource.connector = new VnMySQL(dataSource.settings);
+ dataSource.connector.dataSource = dataSource;
+
+ var modelBuilder = dataSource.modelBuilder;
+ var defineType = modelBuilder.defineValueType ?
+ modelBuilder.defineValueType.bind(modelBuilder) :
+ modelBuilder.constructor.registerType.bind(modelBuilder.constructor);
+
+ defineType(function Point() {});
+
+ dataSource.EnumFactory = EnumFactory;
+
+ if (callback) {
+ if (dataSource.settings.lazyConnect) {
+ process.nextTick(function() {
+ callback();
+ });
+ } else {
+ dataSource.connector.connect(callback);
+ }
+ }
+};
+
+exports.VnMySQL = VnMySQL;
+
+function VnMySQL(settings) {
+ SqlConnector.call(this, 'mysql', settings);
+}
+
+VnMySQL.prototype = Object.create(MySQL.prototype);
+VnMySQL.constructor = VnMySQL;
+
+VnMySQL.prototype.toColumnValue = function(prop, val) {
+ if (val == null || !prop || prop.type !== Date)
+ return MySQL.prototype.toColumnValue.call(this, prop, val);
+
+ return val.getFullYear() + '-' +
+ fillZeros(val.getMonth() + 1) + '-' +
+ fillZeros(val.getDate()) + ' ' +
+ fillZeros(val.getHours()) + ':' +
+ fillZeros(val.getMinutes()) + ':' +
+ fillZeros(val.getSeconds());
+
+ function fillZeros(v) {
+ return v < 10 ? '0' + v : v;
+ }
+};
diff --git a/services/loopback/server/datasources.json b/services/loopback/server/datasources.json
index e1e46bf4f..25d7d0739 100644
--- a/services/loopback/server/datasources.json
+++ b/services/loopback/server/datasources.json
@@ -3,7 +3,8 @@
"connector": "memory"
},
"vn": {
- "connector": "mysql",
+ "connector": "vn-mysql",
+ "timezone": "CET",
"database": "vn",
"debug": false,
"host": "${salixHost}",
@@ -14,7 +15,7 @@
"acquireTimeout": 20000
},
"salix": {
- "connector": "mysql",
+ "connector": "vn-mysql",
"database": "salix",
"debug": false,
"host": "${salixHost}",
@@ -25,7 +26,7 @@
"acquireTimeout": 20000
},
"account": {
- "connector": "mysql",
+ "connector": "vn-mysql",
"database": "account",
"debug": false,
"host": "${salixHost}",
@@ -36,7 +37,7 @@
"acquireTimeout": 20000
},
"edi": {
- "connector": "mysql",
+ "connector": "vn-mysql",
"database": "edi",
"debug": false,
"host": "${salixHost}",
@@ -47,7 +48,7 @@
"acquireTimeout": 20000
},
"bs": {
- "connector": "mysql",
+ "connector": "vn-mysql",
"database": "bs",
"debug": false,
"host": "${salixHost}",
@@ -58,7 +59,7 @@
"acquireTimeout": 20000
},
"hedera": {
- "connector": "mysql",
+ "connector": "vn-mysql",
"database": "hedera",
"debug": false,
"host": "${salixHost}",
diff --git a/services/loopback/server/server.js b/services/loopback/server/server.js
index 012dd21b7..f8678de06 100644
--- a/services/loopback/server/server.js
+++ b/services/loopback/server/server.js
@@ -1,9 +1,24 @@
let loopback = require('loopback');
let boot = require('loopback-boot');
+let DataSource = require('loopback-datasource-juggler').DataSource;
let fs = require('fs-extra');
let i18n = require('i18n');
let path = require('path');
+let _resolveConnector = DataSource._resolveConnector;
+
+DataSource._resolveConnector = function(name) {
+ let testPath = `${__dirname}/connectors/${name}.js`;
+
+ if (fs.existsSync(testPath))
+ return {
+ connector: require(testPath),
+ error: null
+ };
+
+ return _resolveConnector.apply(this, arguments);
+};
+
module.exports = {
loopback: loopback,
boot: vnBoot
diff --git a/services/mailer/application/config/datasources.json b/services/mailer/application/config/datasources.json
index 6d489ec36..5bcaf6dae 100644
--- a/services/mailer/application/config/datasources.json
+++ b/services/mailer/application/config/datasources.json
@@ -3,8 +3,8 @@
"port": 3000,
"debug": false,
"defaultLanguage": "es",
- "senderMail": "noreply@localhost",
- "senderName": "MySender"
+ "senderMail": "joan@verdnatura.es",
+ "senderName": "VerdNatura"
},
"mysql": {
"host": "localhost",
@@ -14,12 +14,12 @@
"password": "root"
},
"smtp": {
- "host": "localhost",
+ "host": "smtp.verdnatura.es",
"port": 465,
"secure": true,
"auth": {
- "user": "noreply",
- "pass": ""
+ "user": "joan",
+ "pass": "CLed3ejl$"
},
"tls": {
"rejectUnauthorized": false
diff --git a/services/order/common/methods/new.js b/services/order/common/methods/new.js
new file mode 100644
index 000000000..02154e337
--- /dev/null
+++ b/services/order/common/methods/new.js
@@ -0,0 +1,51 @@
+module.exports = Self => {
+ Self.remoteMethod('new', {
+ description: 'Create a new order and returns the new ID',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'params',
+ type: 'object',
+ http: {source: 'body'}
+ }],
+ returns: {
+ type: 'number',
+ root: true
+ },
+ http: {
+ path: `/new`,
+ verb: 'post'
+ }
+ });
+
+ Self.new = async params => {
+ let cli = await Self.app.models.Address.findOne({where: {id: params.addressFk}, fields: 'clientFk'});
+
+ let client = await Self.app.models.Client.findOne({
+ where: {id: cli.clientFk},
+ fields: ['isTaxDataChecked', 'isFreezed', 'isActive']
+ });
+
+ if (client.isFreezed)
+ throw new Error(`You can't create an order for a frozen client`);
+
+ if (!client.isActive)
+ throw new Error(`You can't create an order for a inactive client`);
+
+ if (!client.isTaxDataChecked)
+ throw new Error(`You can't create an order for a client that doesn't has tax data verified`);
+
+ let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
+ let clientDebt = await Self.rawSql(query, [cli.clientFk]);
+ if (clientDebt[0].debt > 0)
+ throw new Error(`You can't create an order for a client that has a debt`);
+
+ query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
+ result = await Self.rawSql(query, [
+ params.landed,
+ params.agencyModeFk,
+ params.addressFk,
+ "SALIX"
+ ]);
+ return result[0].vOrderId;
+ };
+};
diff --git a/services/order/common/models/order.js b/services/order/common/models/order.js
new file mode 100644
index 000000000..966d2750f
--- /dev/null
+++ b/services/order/common/models/order.js
@@ -0,0 +1,3 @@
+module.exports = Self => {
+ require('../methods/new')(Self);
+};