From b471f5148292efe3d619b0cb9eaee93dded9e82a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 31 Dec 2019 10:38:19 +0100 Subject: [PATCH 1/4] refactor --- db/dump/dumpedFixtures.sql | 3 +- .../back/methods/client/byNameOrEmail.js | 47 +++++++++++++ modules/client/back/models/client.js | 1 + modules/client/front/fiscal-data/index.html | 2 +- modules/client/front/fiscal-data/index.js | 66 +++++++------------ 5 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 modules/client/back/methods/client/byNameOrEmail.js diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 687f05518..8893590a8 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -119,7 +119,8 @@ USE `salix`; LOCK TABLES `ACL` WRITE; /*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'WorkerCalendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'WorkerCalendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(164,'InvoiceOut','regenerate','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','READ','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','employee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(188,'TicketDms','removeFile','WRITE','ALLOW','ROLE','employee'),(189,'TicketDms','*','READ','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(193,'Zone','editPrices','WRITE','ALLOW','ROLE','deliveryBoss'),(194,'Postcode','*','WRITE','ALLOW','ROLE','employee'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','employee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','salesAssistant'),(203,'UserPhone','*','WRITE','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'WorkerCalendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'WorkerCalendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(164,'InvoiceOut','regenerate','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','READ','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','employee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(188,'TicketDms','removeFile','WRITE','ALLOW','ROLE','employee'),(189,'TicketDms','*','READ','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(193,'Zone','editPrices','WRITE','ALLOW','ROLE','deliveryBoss'),(194,'Postcode','*','WRITE','ALLOW','ROLE','employee'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','employee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'), +(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','salesAssistant'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; diff --git a/modules/client/back/methods/client/byNameOrEmail.js b/modules/client/back/methods/client/byNameOrEmail.js new file mode 100644 index 000000000..71fd72782 --- /dev/null +++ b/modules/client/back/methods/client/byNameOrEmail.js @@ -0,0 +1,47 @@ +module.exports = Self => { + Self.remoteMethod('byNameOrEmail', { + description: 'Returns the client with the matching phone or email', + accessType: 'READ', + accepts: [{ + arg: 'email', + type: 'String', + description: 'Find my matching client email', + required: false + }, + { + arg: 'phone', + type: 'String', + description: 'Find my matching client phone', + required: false + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/byNameOrEmail`, + verb: 'GET' + } + }); + + Self.byNameOrEmail = async(email, phone) => { + const models = Self.app.models; + + let match; + match = await Self.findOne({ + where: { + email: email + } + }); + + if (match) return match; + + match = await models.UserPhone.findOne({ + where: { + phone: phone + } + }); + + return await Self.findById(match.userFk); + }; +}; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 73626b408..552c99e18 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,6 +24,7 @@ module.exports = Self => { require('../methods/client/canBeInvoiced')(Self); require('../methods/client/uploadFile')(Self); require('../methods/client/lastActiveTickets')(Self); + require('../methods/client/byNameOrEmail')(Self); // Validations diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 524873f86..be22556df 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -148,5 +148,5 @@ vn-id="propagate-isEqualizated" question="You changed the equalization tax" message="Do you want to spread the change?" - on-response="$ctrl.returnDialogEt($response)"> + on-accept="$ctrl.onAcceptEt()"> diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 8a2d85109..57434b4eb 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -1,62 +1,44 @@ import ngModule from '../module'; +import Component from 'core/lib/component'; -export default class Controller { - constructor($scope, $http, vnApp, $translate) { - this.$ = $scope; - this.$http = $http; - this.vnApp = vnApp; - this.translate = $translate; - this.isEqualizated = undefined; - this.copyData(); - } - - $onChanges() { - this.copyData(); - } - - copyData() { - if (this.client) - this.isEqualizated = this.client.isEqualizated; - } - - buyerHaspermissions() { - if (!this.client) return true; - return !this.client.isTaxDataChecked; - } - +export default class Controller extends Component { onSubmit() { - if (this.isEqualizated != this.client.isEqualizated) { - this.oldHasToInvoiceByAddress = this.client.hasToInvoiceByAddress; + const orgData = this.$.watcher.orgData; + if (orgData.isEqualizated != this.client.isEqualizated) this.client.hasToInvoiceByAddress = false; + + if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) { + const serializedParams = {email: this.client.email, phone: 111}; + const query = `Clients/byNameOrEmail?filter=${serializedParams}`; + this.$http.get(query).then(res => { + console.log(res); + }); } - return this.$.watcher.submit().then( - () => this.checkEtChanges()); + return this.checkEtChanges().then( + () => this.$.watcher.submit()); } checkEtChanges() { - let equals = this.isEqualizated == this.client.isEqualizated; - this.isEqualizated = this.client.isEqualizated; + const orgData = this.$.watcher.orgData; + const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated; - if (!equals && !this.oldHasToInvoiceByAddress) + if (equalizatedHasChanged && !orgData.hasToInvoiceByAddress) this.$.propagateIsEqualizated.show(); - else if (!equals) - this.returnDialogEt('accept'); + else if (equalizatedHasChanged) + return this.onAcceptEt(); - delete this.oldHasToInvoiceByAddress; + return this.$q.resolve(); } - returnDialogEt(response) { - if (response === 'accept') { - this.$http.patch(`Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.isEqualizated}).then( - () => this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded')) - ); - } + onAcceptEt() { + const query = `Clients/${this.client.id}/addressesPropagateRe`; + return this.$http.patch(query, {isEqualizated: this.client.isEqualizated}).then( + () => this.vnApp.showMessage(this.$translate.instant('Equivalent tax spreaded')) + ); } } -Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; - ngModule.component('vnClientFiscalData', { template: require('./index.html'), controller: Controller, From 5b0bb5dc7302b68a97eaef06cbfc7e420a8e2904 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 4 Feb 2020 11:25:15 +0100 Subject: [PATCH 2/4] updated e2e --- e2e/helpers/selectors.js | 1 + .../03_edit_fiscal_data.spec.js | 7 +- .../12_lock_of_verified_data.spec.js | 1 + .../back/methods/client/byNameOrEmail.js | 47 ------ .../client/specs/updateFiscalData.spec.js | 46 ++---- .../back/methods/client/updateFiscalData.js | 137 +++++++++++++----- modules/client/back/models/client.js | 1 - modules/client/front/fiscal-data/index.html | 9 +- modules/client/front/fiscal-data/index.js | 74 +++++++--- .../client/front/fiscal-data/index.spec.js | 89 +++++++++++- .../client/front/fiscal-data/locale/en.yml | 1 + .../client/front/fiscal-data/locale/es.yml | 4 +- 12 files changed, 275 insertions(+), 142 deletions(-) delete mode 100644 modules/client/back/methods/client/byNameOrEmail.js create mode 100644 modules/client/front/fiscal-data/locale/en.yml diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 95f7610ba..34f21eff4 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -63,6 +63,7 @@ export default { fiscalIdInput: 'vn-client-fiscal-data [ng-model="$ctrl.client.fi"]', equalizationTaxCheckbox: 'vn-check[ng-model="$ctrl.client.isEqualizated"]', acceptPropagationButton: '.vn-confirm.shown button[response=accept]', + acceptDuplicationButton: '.vn-confirm.shown button[response=accept]', addressInput: 'vn-client-fiscal-data [ng-model="$ctrl.client.street"]', postcodeInput: 'vn-client-fiscal-data [ng-model="$ctrl.client.postcode"]', cityInput: 'vn-client-fiscal-data [ng-model="$ctrl.client.city"]', diff --git a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js index 25127e314..b1b92d288 100644 --- a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js @@ -80,6 +80,7 @@ describe('Client Edit fiscalData path', () => { await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox); await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); + await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Invalid Tax number'); @@ -89,6 +90,7 @@ describe('Client Edit fiscalData path', () => { await page.clearInput(selectors.clientFiscalData.fiscalIdInput); await page.write(selectors.clientFiscalData.fiscalIdInput, '94980061C'); await page.waitToClick(selectors.clientFiscalData.saveButton); + await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); @@ -151,6 +153,7 @@ describe('Client Edit fiscalData path', () => { it('should navigate back to fiscal data and uncheck EQtax then check VIES', async() => { await page.waitToClick(selectors.clientFiscalData.fiscalDataButton); await page.waitToClick(selectors.clientFiscalData.viesCheckbox); + await page.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox); await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); const result = await page.waitForLastSnackbar(); @@ -239,10 +242,10 @@ describe('Client Edit fiscalData path', () => { expect(result).toBe('unchecked'); }); - it('should confirm invoice by address checkbox is unchecked', async() => { + it('should confirm invoice by address checkbox is checked', async() => { const result = await page.checkboxState(selectors.clientFiscalData.invoiceByAddressCheckbox); - expect(result).toBe('unchecked'); + expect(result).toBe('checked'); }); it('should confirm Equalization tax checkbox is unchecked', async() => { diff --git a/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js b/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js index ddb5f6d04..651970292 100644 --- a/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client-module/12_lock_of_verified_data.spec.js @@ -59,6 +59,7 @@ describe('Client lock verified data path', () => { it('should check the Verified data checkbox', async() => { await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); + await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); diff --git a/modules/client/back/methods/client/byNameOrEmail.js b/modules/client/back/methods/client/byNameOrEmail.js deleted file mode 100644 index 71fd72782..000000000 --- a/modules/client/back/methods/client/byNameOrEmail.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('byNameOrEmail', { - description: 'Returns the client with the matching phone or email', - accessType: 'READ', - accepts: [{ - arg: 'email', - type: 'String', - description: 'Find my matching client email', - required: false - }, - { - arg: 'phone', - type: 'String', - description: 'Find my matching client phone', - required: false - }], - returns: { - type: 'number', - root: true - }, - http: { - path: `/byNameOrEmail`, - verb: 'GET' - } - }); - - Self.byNameOrEmail = async(email, phone) => { - const models = Self.app.models; - - let match; - match = await Self.findOne({ - where: { - email: email - } - }); - - if (match) return match; - - match = await models.UserPhone.findOne({ - where: { - phone: phone - } - }); - - return await Self.findById(match.userFk); - }; -}; diff --git a/modules/client/back/methods/client/specs/updateFiscalData.spec.js b/modules/client/back/methods/client/specs/updateFiscalData.spec.js index 90136cec7..a2b8f3d58 100644 --- a/modules/client/back/methods/client/specs/updateFiscalData.spec.js +++ b/modules/client/back/methods/client/specs/updateFiscalData.spec.js @@ -1,56 +1,40 @@ const app = require('vn-loopback/server/server'); describe('Client updateFiscalData', () => { + const clientId = 101; afterAll(async done => { - let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; - let validparams = {postcode: 46460}; - let idWithDataChecked = 101; + const clientId = 101; + const ctx = {req: {accessToken: {userId: 5}}}; + ctx.args = {postcode: 46460}; - await app.models.Client.updateFiscalData(ctxOfAdmin, validparams, idWithDataChecked); + await app.models.Client.updateFiscalData(ctx, clientId); done(); }); it('should return an error if the user is not administrative and the isTaxDataChecked value is true', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + ctx.args = {}; + let error; - - let ctxOfNoAdmin = {req: {accessToken: {userId: 1}}}; - let params = []; - let idWithDataChecked = 101; - - await app.models.Client.updateFiscalData(ctxOfNoAdmin, params, idWithDataChecked) + await app.models.Client.updateFiscalData(ctx, clientId) .catch(e => { error = e; }); - expect(error.toString()).toContain(`You can't make changes on a client with verified data`); - }); - - it('should return an error if the user is administrative and the isTaxDataChecked value is true BUT the params aint valid', async() => { - let error; - - let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; - let invalidparams = {invalid: 'param for update'}; - let idWithDataChecked = 101; - - await app.models.Client.updateFiscalData(ctxOfAdmin, invalidparams, idWithDataChecked) - .catch(e => { - error = e; - }); - - expect(error.toString()).toContain(`You don't have enough privileges to do that`); + expect(error.message).toBeDefined(); }); it('should update the client fiscal data and return the count if changes made', async() => { - let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; - let validparams = {postcode: 46680}; - let idWithDataChecked = 101; + const ctx = {req: {accessToken: {userId: 5}}}; + ctx.args = {postcode: 46680}; - let client = await app.models.Client.findById(idWithDataChecked); + + const client = await app.models.Client.findById(clientId); expect(client.postcode).toEqual('46460'); - let result = await app.models.Client.updateFiscalData(ctxOfAdmin, validparams, idWithDataChecked); + const result = await app.models.Client.updateFiscalData(ctx, clientId); expect(result.postcode).toEqual('46680'); }); diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 0f7810ed2..c1bd218d2 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -1,21 +1,87 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethodCtx('updateFiscalData', { - description: 'Updates billing data of a client', + Self.remoteMethod('updateFiscalData', { + description: 'Updates fiscal data of a client', accessType: 'WRITE', accepts: [{ - arg: 'data', + arg: 'ctx', type: 'Object', - required: true, - description: 'Params to update', - http: {source: 'body'} - }, { + http: {source: 'context'} + }, + { arg: 'id', - type: 'string', - required: true, - description: 'Model id', + type: 'Number', + description: 'The client id', http: {source: 'path'} + }, + { + arg: 'socialName', + type: 'String' + }, + { + arg: 'fi', + type: 'String' + }, + { + arg: 'street', + type: 'String' + }, + { + arg: 'postcode', + type: 'String' + }, + { + arg: 'city', + type: 'String' + }, + { + arg: 'countryFk', + type: 'Number' + }, + { + arg: 'provinceFk', + type: 'Number' + }, + { + arg: 'hasToInvoiceByAddress', + type: 'Boolean' + }, + { + arg: 'hasToInvoice', + type: 'Boolean' + }, + { + arg: 'isActive', + type: 'Boolean' + }, + { + arg: 'isFreezed', + type: 'Boolean' + }, + { + arg: 'isVies', + type: 'Boolean' + }, + { + arg: 'isToBeMailed', + type: 'Boolean' + }, + { + arg: 'isEqualizated', + type: 'Boolean' + }, + { + arg: 'isTaxDataVerified', + type: 'Boolean' + }, + { + arg: 'isTaxDataChecked', + type: 'Boolean' + }, + { + arg: 'despiteOfClient', + type: 'Number' }], returns: { arg: 'res', @@ -28,41 +94,34 @@ module.exports = Self => { } }); - Self.updateFiscalData = async(ctx, params, id) => { - let userId = ctx.req.accessToken.userId; - let isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant'); - let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']}); + Self.updateFiscalData = async(ctx, clientId) => { + const models = Self.app.models; + const args = ctx.args; + const userId = ctx.req.accessToken.userId; + const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); - if (!isSalesAssistant && taxData.isTaxDataChecked) + const client = await models.Client.findById(clientId); + + if (!isSalesAssistant && client.isTaxDataChecked) throw new UserError(`You can't make changes on a client with verified data`); - let validUpdateParams = [ - 'socialName', - 'fi', - 'street', - 'postcode', - 'city', - 'countryFk', - 'provinceFk', - 'isActive', - 'isFreezed', - 'hasToInvoice', - 'isVies', - 'isToBeMailed', - 'hasToInvoiceByAddress', - 'isEqualizated', - 'isTaxDataVerified', - 'isTaxDataChecked' - ]; + if (args.despiteOfClient) { + const logRecord = { + originFk: clientId, + userFk: userId, + action: 'update', + changedModel: 'Client', + changedModelId: clientId, + description: `Cliente comprobado a pesar de que existe el cliente id ${args.despiteOfClient}` + }; - for (const key in params) { - if (validUpdateParams.indexOf(key) === -1) - throw new UserError(`You don't have enough privileges to do that`); + await models.ClientLog.create(logRecord); } - params.id = id; + // Remove unwanted properties + delete args.ctx; + delete args.id; - let client = await Self.app.models.Client.findById(id); - return await client.updateAttributes(params); + return client.updateAttributes(args); }; }; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 216506e34..367e0f0eb 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,7 +24,6 @@ module.exports = Self => { require('../methods/client/canBeInvoiced')(Self); require('../methods/client/uploadFile')(Self); require('../methods/client/lastActiveTickets')(Self); - require('../methods/client/findByPhoneOrEmail')(Self); require('../methods/client/sendSms')(Self); require('../methods/client/createAddress')(Self); require('../methods/client/updateAddress')(Self); diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index be22556df..3bbc48630 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -2,6 +2,7 @@ @@ -129,7 +130,8 @@ vn-one label="Is equalizated" ng-model="$ctrl.client.isEqualizated" - info="In order to invoice, this field is not consulted, but the consignee's ET. When modifying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not."> + info="In order to invoice, this field is not consulted, but the consignee's ET. When modifying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not." + on-change="$ctrl.onChangeEqualizated(value)"> + + diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 57434b4eb..9e2be7241 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -4,30 +4,47 @@ import Component from 'core/lib/component'; export default class Controller extends Component { onSubmit() { const orgData = this.$.watcher.orgData; - if (orgData.isEqualizated != this.client.isEqualizated) - this.client.hasToInvoiceByAddress = false; - - if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) { - const serializedParams = {email: this.client.email, phone: 111}; - const query = `Clients/byNameOrEmail?filter=${serializedParams}`; - this.$http.get(query).then(res => { - console.log(res); - }); - } - - return this.checkEtChanges().then( - () => this.$.watcher.submit()); + delete this.client.despiteOfClient; + if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) + this.checkExistingClient(); + else this.save(); } - checkEtChanges() { - const orgData = this.$.watcher.orgData; - const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated; + checkExistingClient() { + const filterObj = { + where: { + and: [ + {or: [{email: this.client.email}, {phone: this.client.phone}]}, + {id: {neq: this.client.id}} + ] + } + }; - if (equalizatedHasChanged && !orgData.hasToInvoiceByAddress) + const $t = this.$translate.instant; + const filter = encodeURIComponent(JSON.stringify(filterObj)); + const query = `Clients/findOne?filter=${filter}`; + this.$http.get(query).then(res => { + if (res.data.id) { + const params = {clientId: res.data.id}; + const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); + + this.client.despiteOfClient = params.clientId; + this.$.confirmDuplicatedClient.question = question; + this.$.confirmDuplicatedClient.show(); + } + }); + } + + checkEtChanges(orgData) { + const equalizatedHasChanged = orgData.isEqualizated != this.client.isEqualizated; + const hasToInvoiceByAddress = orgData.hasToInvoiceByAddress || this.client.hasToInvoiceByAddress; + + if (equalizatedHasChanged && hasToInvoiceByAddress) this.$.propagateIsEqualizated.show(); else if (equalizatedHasChanged) return this.onAcceptEt(); + return this.$q.resolve(); } @@ -37,6 +54,29 @@ export default class Controller extends Component { () => this.vnApp.showMessage(this.$translate.instant('Equivalent tax spreaded')) ); } + + onAcceptDuplication() { + this.save(); + + return true; + } + + save() { + const orgData = this.$.watcher.orgData; + const clonedOrgData = JSON.parse(JSON.stringify(orgData)); + return this.$.watcher.submit().then( + () => this.checkEtChanges(clonedOrgData)); + } + + onChangeEqualizated(value) { + const orgData = this.$.watcher.orgData; + if (value === true) + this.client.hasToInvoiceByAddress = false; + else if (orgData.hasToInvoiceByAddress) + this.client.hasToInvoiceByAddress = true; + + this.$.$apply(); + } } ngModule.component('vnClientFiscalData', { diff --git a/modules/client/front/fiscal-data/index.spec.js b/modules/client/front/fiscal-data/index.spec.js index 5b5c5eab8..1e92426ec 100644 --- a/modules/client/front/fiscal-data/index.spec.js +++ b/modules/client/front/fiscal-data/index.spec.js @@ -1,9 +1,11 @@ import './index'; +import watcher from 'core/mocks/watcher'; describe('Client', () => { describe('Component vnClientFiscalData', () => { let $httpBackend; let $scope; + let $element; let controller; beforeEach(ngModule('client')); @@ -11,16 +13,97 @@ describe('Client', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - controller = $componentController('vnClientFiscalData', {$scope}); + $scope.watcher = watcher; + $scope.watcher.orgData = {id: 101, isEqualizated: false, isTaxDataChecked: false}; + $element = angular.element(''); + controller = $componentController('vnClientFiscalData', {$element, $scope}); controller.card = {reload: () => {}}; + controller.client = { + id: 101, + email: 'batman@gothamcity.com', + phone: '1111111111', + isEqualizated: false, + isTaxDataChecked: false + }; })); - describe('returnDialogEt()', () => { + describe('onSubmit()', () => { + it('should call the save() method directly', () => { + spyOn(controller, 'save'); + + controller.onSubmit(); + + expect(controller.save).toHaveBeenCalledWith(); + }); + + it('should call the checkExistingClient() if the isTaxDataChecked property is checked', () => { + spyOn(controller, 'save'); + spyOn(controller, 'checkExistingClient'); + + controller.client.isTaxDataChecked = true; + controller.onSubmit(); + + expect(controller.save).not.toHaveBeenCalledWith(); + expect(controller.checkExistingClient).toHaveBeenCalledWith(); + }); + }); + + describe('checkExistingClient()', () => { + it('should show a save confirmation when a duplicated client is found and then set the despiteOfClient property', () => { + controller.$.confirmDuplicatedClient = {show: () => {}}; + spyOn(controller.$.confirmDuplicatedClient, 'show'); + const filterObj = { + where: { + and: [ + {or: [{email: controller.client.email}, {phone: controller.client.phone}]}, + {id: {neq: controller.client.id}} + ] + } + }; + const expectedClient = {id: 102}; + const filter = encodeURIComponent(JSON.stringify(filterObj)); + $httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient); + controller.checkExistingClient(); + $httpBackend.flush(); + + expect(controller.$.confirmDuplicatedClient.show).toHaveBeenCalledWith(); + expect(controller.client.despiteOfClient).toEqual(102); + }); + }); + + describe('checkEtChanges()', () => { + it(`should show a propagation confirmation if isEqualizated property is changed and invoice by address is checked`, () => { + controller.$.propagateIsEqualizated = {show: () => {}}; + spyOn(controller.$.propagateIsEqualizated, 'show'); + + const orgData = $scope.watcher.orgData; + orgData.hasToInvoiceByAddress = true; + controller.client.isEqualizated = true; + + controller.checkEtChanges(orgData); + + expect(controller.$.propagateIsEqualizated.show).toHaveBeenCalledWith(); + }); + + it(`should call to the onAcceptEt() method if isEqualizated property is changed and invoice by address isn't checked`, () => { + spyOn(controller, 'onAcceptEt'); + + const orgData = $scope.watcher.orgData; + orgData.hasToInvoiceByAddress = false; + controller.client.isEqualizated = true; + + controller.checkEtChanges(orgData); + + expect(controller.onAcceptEt).toHaveBeenCalledWith(); + }); + }); + + describe('onAcceptEt()', () => { it('should request to patch the propagation of tax status', () => { controller.client = {id: 123, isEqualizated: false}; $httpBackend.when('PATCH', `Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done'); $httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}); - controller.returnDialogEt('accept'); + controller.onAcceptEt(); $httpBackend.flush(); }); }); diff --git a/modules/client/front/fiscal-data/locale/en.yml b/modules/client/front/fiscal-data/locale/en.yml new file mode 100644 index 000000000..14bd6d18f --- /dev/null +++ b/modules/client/front/fiscal-data/locale/en.yml @@ -0,0 +1 @@ +Found a client with this phone or email: The client with id {{clientId}} already has this phone or email.
¿Do you want to continue? \ No newline at end of file diff --git a/modules/client/front/fiscal-data/locale/es.yml b/modules/client/front/fiscal-data/locale/es.yml index 4cadd236f..087dd76d6 100644 --- a/modules/client/front/fiscal-data/locale/es.yml +++ b/modules/client/front/fiscal-data/locale/es.yml @@ -3,4 +3,6 @@ You changed the equalization tax: Has cambiado el recargo de equivalencia Do you want to spread the change?: ¿Deseas propagar el cambio a sus consignatarios? Frozen: Congelado In order to invoice, this field is not consulted, but the consignee's ET. When modifying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not.: Para facturar no se consulta este campo, sino el RE de consignatario. Al modificar este campo si no esta marcada la casilla Facturar por consignatario, se propagará automáticamente el cambio a todos los consignatarios, en caso contrario preguntará al usuario si quiere o no propagar. -You can use letters and spaces: Se pueden utilizar letras y espacios \ No newline at end of file +You can use letters and spaces: Se pueden utilizar letras y espacios +Found a client with this data: Se ha encontrado un cliente con estos datos +Found a client with this phone or email: El cliente con id {{clientId}} ya tiene este teléfono o email.
¿Quieres continuar? \ No newline at end of file From 494b14bab4cd8407215ce2891a5e392a42b19636 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 4 Feb 2020 12:28:01 +0100 Subject: [PATCH 3/4] added translation --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 3 ++- modules/client/back/methods/client/updateFiscalData.js | 6 +++++- modules/client/front/fiscal-data/index.js | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 2ea2b1a3a..23717ba8f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -63,5 +63,6 @@ "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})", "MESSAGE_CLAIM_ITEM_REGULARIZE": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to {{nickname}} coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", - "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member" + "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", + "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index a3490b372..d2f2882bc 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -124,5 +124,6 @@ "MESSAGE_BOUGHT_UNITS": "Se ha comprado {{quantity}} unidades de {{concept}} (#{{itemId}}) para el ticket id [#{{ticketId}}]({{{url}}})", "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", - "MESSAGE_CLAIM_ITEM_REGULARIZE": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a {{nickname}} provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})" + "MESSAGE_CLAIM_ITEM_REGULARIZE": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a {{nickname}} provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}" } \ No newline at end of file diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index c1bd218d2..e27a6f456 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -99,6 +99,7 @@ module.exports = Self => { const args = ctx.args; const userId = ctx.req.accessToken.userId; const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); + const $t = ctx.req.__; const client = await models.Client.findById(clientId); @@ -106,13 +107,16 @@ module.exports = Self => { throw new UserError(`You can't make changes on a client with verified data`); if (args.despiteOfClient) { + const translatedDescription = $t(`Client checked as validated despite of duplication`, { + clientId: args.despiteOfClient + }); const logRecord = { originFk: clientId, userFk: userId, action: 'update', changedModel: 'Client', changedModelId: clientId, - description: `Cliente comprobado a pesar de que existe el cliente id ${args.despiteOfClient}` + description: translatedDescription }; await models.ClientLog.create(logRecord); diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 9e2be7241..98773de75 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -44,7 +44,6 @@ export default class Controller extends Component { else if (equalizatedHasChanged) return this.onAcceptEt(); - return this.$q.resolve(); } From 041c4966d61ef533fff32828823fd746b2403dee Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 4 Feb 2020 12:29:04 +0100 Subject: [PATCH 4/4] changed line --- modules/client/back/methods/client/updateFiscalData.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index e27a6f456..4bc6fda9b 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -107,16 +107,15 @@ module.exports = Self => { throw new UserError(`You can't make changes on a client with verified data`); if (args.despiteOfClient) { - const translatedDescription = $t(`Client checked as validated despite of duplication`, { - clientId: args.despiteOfClient - }); const logRecord = { originFk: clientId, userFk: userId, action: 'update', changedModel: 'Client', changedModelId: clientId, - description: translatedDescription + description: $t(`Client checked as validated despite of duplication`, { + clientId: args.despiteOfClient + }) }; await models.ClientLog.create(logRecord);