diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index 4014dd42d..e9abce5ca 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -24,7 +24,7 @@ module.exports = Self => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ - fields: ['clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType'] + fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType'] }); const expedition = await models.Expedition.findOne({ @@ -107,36 +107,16 @@ module.exports = Self => { ] }); - const shipped = expedition.ticket().shipped; - + const ticket = expedition.ticket(); + const sender = ticket.company().client(); + const shipped = ticket.shipped.toISOString(); const data = { - defaultWeight: viaexpressConfig.defaultWeight, - date: shipped.toISOString(), // const date = new Date().toISOString(); - deliveryType: viaexpressConfig.deliveryType, - senderName: expedition.ticket().company().client().socialName, - senderStreet: expedition.ticket().company().client().defaultAddress().street, - senderPostalCode: expedition.ticket().company().client().defaultAddress().postalCode, - senderCity: expedition.ticket().company().client().defaultAddress().city, - senderProvince: expedition.ticket().company().client().defaultAddress().province().name, - senderPhone: expedition.ticket().company().client().defaultAddress().mobile - || expedition.ticket().company().client().defaultAddress().phone - || expedition.ticket().company().client().mobile - || expedition.ticket().company().client().phone, - senderEmail: expedition.ticket().company().client().email, - receiverName: expedition.ticket().address().nickname, - receiverStreet: expedition.ticket().address().street, - receiverPostalCode: expedition.ticket().address().postalCode, - receiverCity: expedition.ticket().address().city, - receiverProvince: expedition.ticket().address().province().name, - receiverPhone: expedition.ticket().address().mobile - || expedition.ticket().address().phone - || expedition.ticket().client().mobile - || expedition.ticket().client().phone, - receiverEmail: expedition.ticket().client().email, - receiverCountry: expedition.ticket().address().province().country().code, - clientViaexpress: viaexpressConfig.clientViaexpress, - userViaexpress: viaexpressConfig.userViaexpress, - passwordViaexpress: viaexpressConfig.passwordViaexpress + viaexpressConfig, + sender, + senderAddress: sender.defaultAddress(), + client: ticket.client(), + address: ticket.address(), + shipped }; const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8'); diff --git a/back/methods/viaexpress-config/template.ejs b/back/methods/viaexpress-config/template.ejs index e8b1f1977..0b6eb468c 100644 --- a/back/methods/viaexpress-config/template.ejs +++ b/back/methods/viaexpress-config/template.ejs @@ -3,12 +3,12 @@ - <%= defaultWeight %> + <%= viaexpressConfig.defaultWeight %> 1 0 - <%= date %> + <%= shipped %> 0 - <%= deliveryType %> + <%= viaexpressConfig.deliveryType %> 0 0 0 @@ -20,31 +20,31 @@ - <%= senderName %> - <%= senderStreet %> - <%= senderPostalCode %> - <%= senderCity %> - <%= senderProvince %> + <%= sender.socialName %> + <%= senderAddress.street %> + <%= senderAddress.postalCode %> + <%= senderAddress.city %> + <%= senderAddress.province().name %> - <%= senderPhone %> - <%= senderEmail %> + <%= senderAddress.mobile || senderAddress.phone || sender.mobile || sender.phone %> + <%= sender.email %> - <%= receiverName %> - <%= receiverStreet %> - <%= receiverPostalCode %> - <%= receiverCity %> + <%= address.nickname %> + <%= address.street %> + <%= address.postalCode %> + <%= address.city %> - <%= receiverProvince %> + <%= address.province().name %> - <%= receiverPhone %> - <%= receiverEmail %> - <%= receiverCountry %> + <%= address.mobile || address.phone || client.mobile || client.phone %> + <%= client.email %> + <%= address.province().country().code %> - <%= clientViaexpress %> - <%= userViaexpress %> - <%= passwordViaexpress %> + <%= viaexpressConfig.client %> + <%= viaexpressConfig.user %> + <%= viaexpressConfig.password %> diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 26d6c8e37..8df24201b 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -15,13 +15,13 @@ "type": "string", "required": true }, - "clientViaexpress": { + "client": { "type": "string" }, - "userViaexpress": { + "user": { "type": "string" }, - "passwordViaexpress": { + "password": { "type": "string" }, "defaultWeight": { diff --git a/db/changes/232601/00-viaexpress.sql b/db/changes/232601/00-viaexpress.sql index 9e3baa9fd..42cf3b647 100644 --- a/db/changes/232601/00-viaexpress.sql +++ b/db/changes/232601/00-viaexpress.sql @@ -1,9 +1,9 @@ CREATE TABLE `vn`.`viaexpressConfig` ( id int auto_increment NOT NULL, url varchar(100) NOT NULL, - clientViaexpress varchar(100) NOT NULL, - userViaexpress varchar(100) NOT NULL, - passwordViaexpress varchar(100) NOT NULL, + client varchar(100) NOT NULL, + user varchar(100) NOT NULL, + password varchar(100) NOT NULL, defaultWeight decimal(10,2) NOT NULL, deliveryType varchar(5) NOT NULL, CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id)