salesPersonUser replaces salesPerson relation #378
|
@ -51,15 +51,9 @@ module.exports = Self => {
|
|||
scope: {
|
||||
fields: ['salesPersonFk', 'name'],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['nickname']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ module.exports = Self => {
|
|||
if (addressId)
|
||||
address = await models.Address.findById(addressId, null, options);
|
||||
|
||||
const salesPerson = sale.ticket().client().salesPerson();
|
||||
const salesPerson = sale.ticket().client().salesPersonUser();
|
||||
if (salesPerson) {
|
||||
const nickname = address && address.nickname || destination.description;
|
||||
const origin = ctx.req.headers.origin;
|
||||
|
@ -113,7 +113,10 @@ module.exports = Self => {
|
|||
relation: 'client',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'salesPerson'
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</vn-label-value>
|
||||
<vn-label-value
|
||||
label="Salesperson"
|
||||
value="{{$ctrl.summary.claim.client.salesPerson.user.nickname}}">
|
||||
value="{{$ctrl.summary.claim.client.salesPersonUser.name}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value
|
||||
label="Attended by"
|
||||
|
|
|
@ -46,7 +46,6 @@ module.exports = function(Self) {
|
|||
isEqualizated: data.isEqualizated
|
||||
}, options);
|
||||
|
||||
|
||||
let address = await Address.create({
|
||||
clientFk: client.id,
|
||||
nickname: client.name,
|
||||
|
|
|
@ -25,17 +25,6 @@ module.exports = function(Self) {
|
|||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'salesPerson',
|
||||
scope: {
|
||||
fields: ['userFk', 'firstName'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name', 'nickname']
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
relation: 'contactChannel',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
|
|
|
@ -30,8 +30,8 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.hasCustomerRole = (id, context, callback) => {
|
||||
let query =
|
||||
`SELECT COUNT(*) > 0 isCustomer
|
||||
let query = `
|
||||
SELECT COUNT(*) > 0 isCustomer
|
||||
FROM salix.Account A
|
||||
JOIN salix.Role r ON r.id = A.roleFK
|
||||
WHERE r.name = 'customer'
|
||||
|
|
|
@ -30,8 +30,8 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.isValidClient = async id => {
|
||||
let query =
|
||||
`SELECT r.name
|
||||
let query = `
|
||||
SELECT r.name
|
||||
FROM salix.Account a
|
||||
JOIN vn.client c ON a.id = c.id
|
||||
JOIN salix.RoleMapping rm ON rm.principalId = a.id
|
||||
|
|
|
@ -42,15 +42,9 @@ module.exports = Self => {
|
|||
}
|
||||
},
|
||||
{
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -25,7 +25,6 @@ module.exports = Self => {
|
|||
Self.createWithInsurance = async(data, ctx) => {
|
||||
const tx = await Self.beginTransaction({});
|
||||
const models = Self.app.models;
|
||||
const $t = ctx.req.__; // $translate
|
||||
|
||||
try {
|
||||
let options = {transaction: tx};
|
||||
|
|
|
@ -105,7 +105,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
function hasSalesMan(err) {
|
||||
if (this.payMethod && !this.salesPerson)
|
||||
if (this.payMethod && !this.salesPersonUser)
|
||||
err();
|
||||
}
|
||||
|
||||
|
|
|
@ -131,11 +131,6 @@
|
|||
"model": "PayMethod",
|
||||
"foreignKey": "payMethodFk"
|
||||
},
|
||||
"salesPerson": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "salesPersonFk"
|
||||
},
|
||||
"salesPersonUser": {
|
||||
"type": "belongsTo",
|
||||
"model": "Account",
|
||||
|
|
|
@ -51,7 +51,7 @@ module.exports = function(Self) {
|
|||
const data = ctx.instance;
|
||||
const insurance = await Self.findById(data.id, null, options);
|
||||
const client = insurance.classification().customer();
|
||||
const salesPerson = client.salesPerson();
|
||||
const salesPerson = client.salesPersonUser();
|
||||
|
||||
if (!salesPerson) return;
|
||||
|
||||
|
|
|
@ -43,15 +43,9 @@
|
|||
"scope": {
|
||||
"fields": ["name", "salesPersonFk"],
|
||||
"include": {
|
||||
"relation": "salesPerson",
|
||||
"relation": "salesPersonUser",
|
||||
"scope": {
|
||||
"fields": "userFk",
|
||||
"include": {
|
||||
"relation": "user",
|
||||
"scope": {
|
||||
"fields": ["name"]
|
||||
}
|
||||
}
|
||||
"fields": ["id", "name"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<span
|
||||
ng-click="workerDescriptor.show($event, $ctrl.client.salesPersonFk)"
|
||||
class="link">
|
||||
{{$ctrl.client.salesPerson.user.name}}
|
||||
{{$ctrl.client.salesPersonUser.name}}
|
||||
</span>
|
||||
</vn-label-value>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<vn-card class="summary">
|
||||
<h5>{{$ctrl.summary.name}} - {{$ctrl.summary.id}} - {{$ctrl.summary.salesPerson.user.nickname}}</h5>
|
||||
<h5>{{$ctrl.summary.name}} - {{$ctrl.summary.id}} - {{$ctrl.summary.salesPersonUser.name}}</h5>
|
||||
<vn-horizontal>
|
||||
<vn-one>
|
||||
<h4 translate>Basic data</h4>
|
||||
|
@ -25,7 +25,7 @@
|
|||
<span
|
||||
ng-click="workerDescriptor.show($event, $ctrl.summary.salesPersonFk)"
|
||||
class="link">
|
||||
{{$ctrl.summary.salesPerson.user.name}}
|
||||
{{$ctrl.summary.salesPersonUser.name}}
|
||||
</span>
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Channel"
|
||||
|
|
|
@ -91,7 +91,8 @@ module.exports = Self => {
|
|||
]
|
||||
));
|
||||
|
||||
stmt = new ParameterizedSQL(`SELECT
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
i.id,
|
||||
i.name,
|
||||
i.subName,
|
||||
|
|
|
@ -38,16 +38,16 @@ module.exports = Self => {
|
|||
order.agencyModeFk
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmt = new ParameterizedSQL(`SELECT it.id, it.name, ic.name categoryName
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT it.id, it.name, ic.name categoryName
|
||||
FROM tmp.availableCalc ac
|
||||
JOIN cache.available a ON a.calc_id = ac.calcFk
|
||||
JOIN item i ON i.id = a.item_id
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
WHERE it.categoryFk = ?
|
||||
GROUP BY it.id`, [
|
||||
itemCategoryId
|
||||
]);
|
||||
GROUP BY it.id`, [itemCategoryId]
|
||||
);
|
||||
let categoriesIndex = stmts.push(stmt) - 1;
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
|
|
@ -28,7 +28,6 @@ module.exports = Self => {
|
|||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order');
|
||||
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE TEMPORARY TABLE tmp.order
|
||||
(INDEX (orderFk))
|
||||
|
|
|
@ -31,14 +31,17 @@ module.exports = Self => {
|
|||
async function getOrderData(Self, orderId) {
|
||||
let filter = {
|
||||
include: [
|
||||
{relation: 'agencyMode', scope: {fields: ['name']}},
|
||||
{
|
||||
relation: 'agencyMode', scope: {fields: ['name']}},
|
||||
{
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['salesPersonFk', 'name'],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
fields: ['firstName', 'name']
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -31,15 +31,9 @@ class Controller extends ModuleCard {
|
|||
'isTaxDataChecked'
|
||||
],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<span
|
||||
ng-click="workerDescriptor.show($event, $ctrl.order.client.salesPersonFk)"
|
||||
class="link">
|
||||
{{$ctrl.order.client.salesPerson.user.name}}
|
||||
{{$ctrl.order.client.salesPersonUser.name}}
|
||||
</span>
|
||||
</vn-label-value>
|
||||
<vn-label-value
|
||||
|
|
|
@ -31,7 +31,10 @@ module.exports = Self => {
|
|||
relation: 'client',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'salesPerson'
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
@ -69,7 +72,7 @@ module.exports = Self => {
|
|||
|
||||
await ticketTracking.destroy();
|
||||
|
||||
const salesPerson = ticket.client().salesPerson();
|
||||
const salesPerson = ticket.client().salesPersonUser();
|
||||
if (salesPerson) {
|
||||
const origin = ctx.req.headers.origin;
|
||||
const message = $t('This ticket is not an stowaway anymore', {
|
||||
|
|
|
@ -89,12 +89,9 @@ module.exports = Self => {
|
|||
scope: {
|
||||
fields: ['id', 'salesPersonFk'],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['id', 'userFk'],
|
||||
include: {
|
||||
relation: 'user'
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,15 +118,14 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
// Send notification to salesPerson
|
||||
const salesPerson = ticket.client().salesPerson();
|
||||
if (salesPerson) {
|
||||
const salesPersonUser = salesPerson.user().name;
|
||||
const salesPersonUser = ticket.client().salesPersonUser();
|
||||
if (salesPersonUser) {
|
||||
const origin = ctx.req.headers.origin;
|
||||
const message = $t(`Has deleted the ticket id`, {
|
||||
id: id,
|
||||
url: `${origin}/#!/ticket/${id}/summary`
|
||||
});
|
||||
await models.Chat.send(ctx, `@${salesPersonUser}`, message);
|
||||
await models.Chat.send(ctx, `@${salesPersonUser.name}`, message);
|
||||
}
|
||||
|
||||
return ticket.updateAttribute('isDeleted', true);
|
||||
|
|
|
@ -57,15 +57,9 @@ module.exports = Self => {
|
|||
scope: {
|
||||
fields: ['salesPersonFk', 'name', 'phone', 'mobile'],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,15 +38,9 @@ class Controller extends ModuleCard {
|
|||
'mobile'
|
||||
],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
<span
|
||||
ng-click="workerDescriptor.show($event, $ctrl.ticket.client.salesPersonFk)"
|
||||
class="link">
|
||||
{{$ctrl.ticket.client.salesPerson.user.name}}
|
||||
{{$ctrl.ticket.client.salesPersonUser.name}}
|
||||
</span>
|
||||
</vn-label-value>
|
||||
<vn-label-value
|
||||
|
|
|
@ -204,15 +204,9 @@ class Controller extends Descriptor {
|
|||
'isTaxDataChecked'
|
||||
],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
relation: 'salesPersonUser',
|
||||
scope: {
|
||||
fields: ['userFk'],
|
||||
include: {
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<span
|
||||
ng-click="workerDescriptor.show($event, $ctrl.summary.client.salesPersonFk)"
|
||||
class="link">
|
||||
{{$ctrl.summary.client.salesPerson.user.name}}
|
||||
{{$ctrl.summary.client.salesPersonUser.name}}
|
||||
</span>
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Agency"
|
||||
|
|
Loading…
Reference in New Issue