feat(notification): notify client metrics
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Refs: 3315
This commit is contained in:
parent
db0fe766b0
commit
f4ff854a1f
|
@ -45,3 +45,4 @@ import './dms/edit';
|
|||
import './consumption';
|
||||
import './consumption-search-panel';
|
||||
import './defaulter';
|
||||
import './notification';
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="Clients"
|
||||
limit="20">
|
||||
</vn-crud-model>
|
||||
<vn-portal slot="topbar">
|
||||
<vn-searchbar
|
||||
vn-focus
|
||||
panel="vn-client-search-panel"
|
||||
placeholder="Search client"
|
||||
info="Search client by id or name"
|
||||
auto-state="false"
|
||||
model="model"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
</vn-searchbar>
|
||||
</vn-portal>
|
||||
<vn-card>
|
||||
<smart-table
|
||||
model="model"
|
||||
options="$ctrl.smartTableOptions"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
<slot-actions>
|
||||
<vn-button disabled="$ctrl.checked.length === 0"
|
||||
icon="show_chart"
|
||||
ng-click="filters.show($event)"
|
||||
vn-tooltip="Client consumption">
|
||||
</vn-button>
|
||||
</slot-actions>
|
||||
<slot-table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th shrink>
|
||||
<vn-multi-check
|
||||
model="model"
|
||||
check-field="$checked">
|
||||
</vn-multi-check>
|
||||
</th>
|
||||
<th field="id">
|
||||
<span translate>Identifier</span>
|
||||
</th>
|
||||
<th field="socialName">
|
||||
<span translate>Social name</span>
|
||||
</th>
|
||||
<th field="city">
|
||||
<span translate>City</span>
|
||||
</th>
|
||||
<th field="phone">
|
||||
<span translate>Phone</span>
|
||||
</th>
|
||||
<th field="email">
|
||||
<span translate>Email</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="client in model.data"
|
||||
vn-anchor="::{
|
||||
state: 'item.card.summary',
|
||||
params: {id: item.id}
|
||||
}">
|
||||
<td>
|
||||
<vn-check
|
||||
ng-model="client.$checked"
|
||||
vn-click-stop>
|
||||
</vn-check>
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
vn-click-stop="itemDescriptor.show($event, item.id)"
|
||||
class="link">
|
||||
{{::client.id}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{::client.socialName}}</td>
|
||||
<td>{{::client.city}}</td>
|
||||
<td>{{::client.phone}}</td>
|
||||
<td>{{::client.email}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</slot-table>
|
||||
</smart-table>
|
||||
</vn-card>
|
||||
|
||||
|
||||
<vn-popover vn-id="filters">
|
||||
<div class="vn-pa-lg">
|
||||
<form ng-submit="$ctrl.onSendClientConsumption()">
|
||||
<vn-horizontal><h4>Client consumption</h4></vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-one
|
||||
url="Campaigns/latest"
|
||||
label="Campaign"
|
||||
translate-fields="['code']"
|
||||
show-field="code"
|
||||
value-field="id"
|
||||
ng-model="$ctrl.campaign.id"
|
||||
order="dated DESC"
|
||||
selection="$ctrl.campaignSelection"
|
||||
search-function="{dated: {like: '%'+ $search +'%'}}">
|
||||
<tpl-item>
|
||||
{{code}} {{dated | date: 'yyyy'}}
|
||||
</tpl-item>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="From"
|
||||
ng-model="$ctrl.campaign.from"
|
||||
on-change="$ctrl.onChangeDate(value)">
|
||||
</vn-date-picker>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="To"
|
||||
ng-model="$ctrl.campaign.to"
|
||||
on-change="$ctrl.onChangeDate(value)">
|
||||
</vn-date-picker>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-mt-lg">
|
||||
<vn-submit label="send"></vn-submit>
|
||||
</vn-horizontal>
|
||||
</form>
|
||||
</div>
|
||||
</vn-popover>
|
||||
<vn-contextmenu vn-id="contextmenu" targets="['smart-table']" model="model"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||
<slot-menu>
|
||||
<vn-item translate
|
||||
ng-if="contextmenu.isFilterAllowed()"
|
||||
ng-click="contextmenu.filterBySelection()">
|
||||
Filter by selection
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
ng-if="contextmenu.isFilterAllowed()"
|
||||
ng-click="contextmenu.excludeSelection()">
|
||||
Exclude selection
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
ng-if="contextmenu.isFilterAllowed()"
|
||||
ng-click="contextmenu.removeFilter()">
|
||||
Remove filter
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
ng-click="contextmenu.removeAllFilters()">
|
||||
Remove all filters
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
ng-if="contextmenu.isActionAllowed()"
|
||||
ng-click="contextmenu.copyValue()">
|
||||
Copy value
|
||||
</vn-item>
|
||||
</slot-menu>
|
||||
</vn-contextmenu>
|
|
@ -0,0 +1,129 @@
|
|||
import ngModule from '../module';
|
||||
import Section from 'salix/components/section';
|
||||
|
||||
export default class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.$checkAll = false;
|
||||
this.smartTableOptions = {
|
||||
activeButtons: {
|
||||
search: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'socialName',
|
||||
autocomplete: {
|
||||
url: 'Clients',
|
||||
showField: 'socialName',
|
||||
valueField: 'socialName'
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'city',
|
||||
autocomplete: {
|
||||
url: 'Towns',
|
||||
valueField: 'name',
|
||||
showField: 'name'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
this.campaign = {
|
||||
id: null,
|
||||
from: null,
|
||||
to: null
|
||||
};
|
||||
|
||||
// if (!this.dateParams)
|
||||
this.getUpcomingCampaing();
|
||||
}
|
||||
|
||||
get checked() {
|
||||
const clients = this.$.model.data || [];
|
||||
const checkedClients = [];
|
||||
for (const buy of clients) {
|
||||
if (buy.$checked)
|
||||
checkedClients.push(buy);
|
||||
}
|
||||
|
||||
return checkedClients;
|
||||
}
|
||||
|
||||
onChangeDate(value) {
|
||||
if (value)
|
||||
this.campaign.id = null;
|
||||
}
|
||||
|
||||
getUpcomingCampaing() {
|
||||
this.$http.get('Campaigns/upcoming').then(res => {
|
||||
this.campaign.id = res.data.id;
|
||||
});
|
||||
}
|
||||
|
||||
get campaignSelection() {
|
||||
return this._campaignSelection;
|
||||
}
|
||||
|
||||
set campaignSelection(value) {
|
||||
this._campaignSelection = value;
|
||||
|
||||
if (value) {
|
||||
const from = new Date(value.dated);
|
||||
from.setDate(from.getDate() - value.scopeDays);
|
||||
|
||||
this.campaign.to = value.dated;
|
||||
this.campaign.from = from;
|
||||
}
|
||||
}
|
||||
|
||||
get clientConsumptionParams() {
|
||||
const userParams = this.$.model.userParams;
|
||||
return Object.assign({
|
||||
recipient: this.client.email,
|
||||
recipientId: this.client.id
|
||||
}, userParams);
|
||||
}
|
||||
|
||||
onSendClientConsumption() {
|
||||
const clientIds = this.checked.map(client => client.id);
|
||||
const params = Object.assign({
|
||||
clientIds: clientIds
|
||||
}, this.campaign);
|
||||
|
||||
this.$http.post('notify/consumption', params)
|
||||
.then(() => this.$.filters.hide())
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {id: value}
|
||||
: {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]};
|
||||
case 'phone':
|
||||
return {
|
||||
or: [
|
||||
{phone: value},
|
||||
{mobile: value}
|
||||
]
|
||||
};
|
||||
case 'name':
|
||||
case 'socialName':
|
||||
case 'city':
|
||||
case 'email':
|
||||
return {[param]: {like: `%${value}%`}};
|
||||
case 'id':
|
||||
case 'fi':
|
||||
case 'postcode':
|
||||
case 'salesPersonFk':
|
||||
return {[param]: value};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnClientNotification', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
});
|
|
@ -7,6 +7,7 @@
|
|||
"menus": {
|
||||
"main": [
|
||||
{"state": "client.index", "icon": "person"},
|
||||
{"state": "client.notification", "icon": "campaign"},
|
||||
{"state": "client.defaulter.index", "icon": "icon-defaulter"}
|
||||
],
|
||||
"card": [
|
||||
|
@ -373,6 +374,12 @@
|
|||
"state": "client.defaulter.index",
|
||||
"component": "vn-client-defaulter-index",
|
||||
"description": "Defaulter"
|
||||
},
|
||||
{
|
||||
"url" : "/notification",
|
||||
"state": "client.notification",
|
||||
"component": "vn-client-notification",
|
||||
"description": "Notifications"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
const db = require('vn-print/core/database');
|
||||
const Email = require('vn-print/core/email');
|
||||
|
||||
module.exports = async function(request, response, next) {
|
||||
const reqArgs = request.body;
|
||||
|
||||
if (!reqArgs.clientIds)
|
||||
throw new Error('The argument clientIds is required');
|
||||
if (!reqArgs.from)
|
||||
throw new Error('The argument from is required');
|
||||
if (!reqArgs.to)
|
||||
throw new Error('The argument to is required');
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
|
||||
for (const clientId of reqArgs.clientIds) {
|
||||
const client = await db.findOne(`
|
||||
SELECT
|
||||
c.email,
|
||||
eu.email salesPersonEmail
|
||||
FROM client c
|
||||
JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
JOIN ticket t ON t.clientFk = c.id
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE c.id = ?
|
||||
AND it.isPackaging = FALSE
|
||||
AND DATE(t.shipped) BETWEEN ? AND ?
|
||||
GROUP BY c.id`, [clientId, reqArgs.from, reqArgs.to]);
|
||||
|
||||
if (client) {
|
||||
const args = Object.assign({
|
||||
recipientId: clientId,
|
||||
recipient: client.email,
|
||||
replyTo: client.salesPersonEmail
|
||||
}, response.locals);
|
||||
|
||||
const email = new Email('campaign-metrics', args);
|
||||
await email.send();
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
const express = require('express');
|
||||
const router = new express.Router();
|
||||
|
||||
router.post('/consumption', require('./consumption'));
|
||||
|
||||
module.exports = router;
|
|
@ -15,4 +15,8 @@ module.exports = [
|
|||
url: '/api/closure',
|
||||
cb: require('./closure')
|
||||
},
|
||||
{
|
||||
url: '/api/notify',
|
||||
cb: require('./notify')
|
||||
}
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue