feat: add new sub section itemShelving
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-10-05 15:13:48 +02:00
parent f2407ceb0e
commit 2f17257e46
11 changed files with 483 additions and 2 deletions

View File

@ -51,6 +51,7 @@ Entries: Entradas
Users: Usuarios
Suppliers: Proveedores
Monitors: Monitores
Shelvings: Carros
# Common

View File

@ -53,6 +53,9 @@
"ItemShelvingSale": {
"dataSource": "vn"
},
"ItemShelvingPlacementSupplyStock": {
"dataSource": "vn"
},
"ItemImageQueue": {
"dataSource": "vn"
},

View File

@ -0,0 +1,29 @@
{
"name": "ItemShelvingPlacementSupplyStock",
"base": "VnModel",
"options": {
"mysql": {
"table": "itemShelvingPlacementSupplyStock"
}
},
"properties": {
"created": {
"type": "date"
},
"itemFk": {
"type": "number"
},
"concept": {
"type": "string"
},
"parking": {
"type": "string"
},
"shelving": {
"type": "string"
},
"packing": {
"type": "number"
}
}
}

View File

@ -24,3 +24,5 @@ import './waste/detail';
import './fixed-price';
import './fixed-price-search-panel';
import './item-type';
import './item-shelving';

View File

@ -0,0 +1,172 @@
<vn-crud-model
vn-id="model"
url="Defaulters/filter"
filter="::$ctrl.filter"
limit="20"
order="amount DESC"
data="defaulters"
auto-load="true">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
placeholder="Search client"
info="Search client by id or name"
auto-state="false"
model="model">
</vn-searchbar>
</vn-portal>
<vn-card>
<smart-table
model="model"
options="$ctrl.smartTableOptions"
expr-builder="$ctrl.exprBuilder(param, value)">
<slot-actions>
<div>
<div class="totalBox" style="text-align: center;">
<h6 translate>Total</h6>
<vn-label-value
label="Balance due"
value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
</vn-label-value>
</div>
</div>
<div class="vn-pa-md">
<vn-button
ng-show="$ctrl.checked.length > 0"
ng-click="notesDialog.show()"
name="notesDialog"
vn-tooltip="Add observation"
icon="icon-notes">
</vn-button>
</div>
</slot-actions>
<slot-table>
<table>
<thead>
<tr>
<th shrink>
<vn-multi-check
model="model">
</vn-multi-check>
</th>
<th field="clientFk">
<span translate>Created</span>
</th>
<th field="salesPersonFk">
<span translate>Item</span>
</th>
<th
field="amount"
vn-tooltip="Balance due">
<span translate>Concept</span>
</th>
<th
field="workerFk"
vn-tooltip="Worker who made the last observation">
<span translate>Parking</span>
</th>
<th field="observation" expand>
<span translate>Shelving</span>
</th>
<th
vn-tooltip="Last observation date"
field="created">
<span translate>Etiqueta</span>
</th>
<th
field="creditInsurance"
shrink>
<span translate>Packing</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="defaulter in defaulters">
<td shrink>
<vn-check
ng-model="defaulter.checked"
vn-click-stop>
</vn-check>
</td>
<td title="{{::defaulter.clientName}}">
<span
vn-click-stop="clientDescriptor.show($event, defaulter.clientFk)"
title ="{{::defaulter.clientName}}"
class="link">
{{::defaulter.clientName}}
</span>
</td>
<td>
<span
title="{{::defaulter.salesPersonName}}"
vn-click-stop="workerDescriptor.show($event, defaulter.salesPersonFk)"
class="link">
{{::defaulter.salesPersonName | dashIfEmpty}}
</span>
</td>
<td>{{::defaulter.amount | currency: 'EUR': 2}}</td>
<td>
<span
title="{{::defaulter.workerName}}"
vn-click-stop="workerDescriptor.show($event, defaulter.workerFk)"
class="link">
{{::defaulter.workerName | dashIfEmpty}}
</span>
</td>
<td expand>
<vn-textarea
vn-three
disabled="true"
ng-model="defaulter.observation">
</vn-textarea>
</td>
<td shrink-date>
<span class="chip {{::$ctrl.chipColor(defaulter.created)}}">
{{::defaulter.created | date: 'dd/MM/yyyy'}}
</span>
</td>
<td shrink>{{::defaulter.creditInsurance | currency: 'EUR': 2}}</td>
<td shrink-date>{{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}}</td>
</tr>
</tbody>
</table>
</slot-table>
</smart-table>
</vn-card>
<vn-client-descriptor-popover
vn-id="client-descriptor">
</vn-client-descriptor-popover>
<vn-worker-descriptor-popover
vn-id="worker-descriptor">
</vn-worker-descriptor-popover>
<vn-popup vn-id="dialog-summary-client">
<vn-client-summary
client="$ctrl.clientSelected">
</vn-client-summary>
</vn-popup>
<!-- Dialog of add notes button -->
<vn-dialog
vn-id="notesDialog"
on-accept="$ctrl.onResponse()">
<tpl-body>
<section class="SMSDialog">
<h5 class="vn-py-sm">{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}</h5>
<vn-horizontal>
<vn-textarea vn-one
vn-id="message"
label="Message"
ng-model="$ctrl.defaulter.observation"
rows="3"
required="true"
rule>
</vn-textarea>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -0,0 +1,132 @@
import ngModule from '../module';
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.defaulter = {};
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
field: 'clientFk',
autocomplete: {
url: 'Clients',
showField: 'name',
valueField: 'id'
}
},
{
field: 'salesPersonFk',
autocomplete: {
url: 'Workers/activeWithInheritedRole',
where: `{role: 'salesPerson'}`,
searchFunction: '{firstName: $search}',
showField: 'name',
valueField: 'id',
}
},
{
field: 'workerFk',
autocomplete: {
url: 'Workers/activeWithInheritedRole',
searchFunction: '{firstName: $search}',
showField: 'name',
valueField: 'id',
}
},
{
field: 'observation',
searchable: false
},
{
field: 'created',
searchable: false
},
{
field: 'defaulterSinced',
searchable: false
}
]
};
this.getBalanceDueTotal();
}
get checked() {
const clients = this.$.model.data || [];
const checkedLines = [];
for (let defaulter of clients) {
if (defaulter.checked)
checkedLines.push(defaulter);
}
return checkedLines;
}
getBalanceDueTotal() {
this.$http.get('Defaulters/filter')
.then(res => {
if (!res.data) return 0;
this.balanceDueTotal = res.data.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
}
chipColor(date) {
const day = 24 * 60 * 60 * 1000;
const today = new Date();
today.setHours(0, 0, 0, 0);
const observationShipped = new Date(date);
observationShipped.setHours(0, 0, 0, 0);
const difference = today - observationShipped;
if (difference > (day * 20))
return 'alert';
if (difference > (day * 10))
return 'warning';
}
onResponse() {
if (!this.defaulter.observation)
throw new UserError(`The message can't be empty`);
const params = [];
for (let defaulter of this.checked) {
params.push({
text: this.defaulter.observation,
clientFk: defaulter.clientFk
});
}
this.$http.post(`ClientObservations`, params) .then(() => {
this.vnApp.showMessage(this.$t('Observation saved!'));
this.$state.reload();
});
}
exprBuilder(param, value) {
switch (param) {
case 'creditInsurance':
case 'amount':
case 'clientFk':
case 'workerFk':
case 'salesPersonFk':
return {[`d.${param}`]: value};
}
}
}
ngModule.vnComponent('vnItemShelving', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,121 @@
import './index';
import crudModel from 'core/mocks/crud-model';
describe('client defaulter', () => {
describe('Component vnClientDefaulter', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-defaulter></vn-client-defaulter>');
controller = $componentController('vnClientDefaulter', {$element});
controller.$.model = crudModel;
controller.$.model.data = [
{clientFk: 1101, amount: 125},
{clientFk: 1102, amount: 500},
{clientFk: 1103, amount: 250}
];
}));
describe('checked() getter', () => {
it('should return the checked lines', () => {
const data = controller.$.model.data;
data[1].checked = true;
data[2].checked = true;
const checkedRows = controller.checked;
const firstCheckedRow = checkedRows[0];
const secondCheckedRow = checkedRows[1];
expect(firstCheckedRow.clientFk).toEqual(1102);
expect(secondCheckedRow.clientFk).toEqual(1103);
});
});
describe('chipColor()', () => {
it('should return undefined when the date is the present', () => {
let today = new Date();
let result = controller.chipColor(today);
expect(result).toEqual(undefined);
});
it('should return warning when the date is 10 days in the past', () => {
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 11);
let result = controller.chipColor(pastDate);
expect(result).toEqual('warning');
});
it('should return alert when the date is 20 days in the past', () => {
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 21);
let result = controller.chipColor(pastDate);
expect(result).toEqual('alert');
});
});
describe('onResponse()', () => {
it('should return error for empty message', () => {
let error;
try {
controller.onResponse();
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error.message).toBe(`The message can't be empty`);
});
it('should return saved message', () => {
const data = controller.$.model.data;
data[1].checked = true;
controller.defaulter = {observation: 'My new observation'};
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('GET', `Defaulters/filter`).respond(200);
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
controller.onResponse();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!');
});
});
describe('exprBuilder()', () => {
it('should search by sales person', () => {
const expr = controller.exprBuilder('salesPersonFk', '5');
expect(expr).toEqual({'d.salesPersonFk': '5'});
});
it('should search by client', () => {
const expr = controller.exprBuilder('clientFk', '5');
expect(expr).toEqual({'d.clientFk': '5'});
});
});
describe('getBalanceDueTotal()', () => {
it('should return balance due total', () => {
const defaulters = controller.$.model.data;
$httpBackend.when('GET', `Defaulters/filter`).respond(defaulters);
controller.getBalanceDueTotal();
$httpBackend.flush();
expect(controller.balanceDueTotal).toEqual(875);
});
});
});
});

View File

@ -0,0 +1,9 @@
Add observation: Añadir observación
Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s)
Balance D.: Saldo V.
Credit I.: Crédito A.
Last observation: Última observación
L. O. Date: Fecha Ú. O.
Last observation date: Fecha última observación
Search client: Buscar clientes
Worker who made the last observation: Trabajador que ha realizado la última observación

View File

@ -54,6 +54,7 @@ Basic data: Datos básicos
Tax: IVA
History: Historial
Botanical: Botánico
Shelvings: Carros
Barcodes: Códigos de barras
Diary: Histórico
Item diary: Registro de compra-venta

View File

@ -17,6 +17,7 @@
{"state": "item.card.tags", "icon": "icon-tags"},
{"state": "item.card.tax", "icon": "icon-tax"},
{"state": "item.card.botanical", "icon": "local_florist"},
{"state": "item.card.shelving", "icon": "icon-inventory"},
{"state": "item.card.itemBarcode", "icon": "icon-barcode"},
{"state": "item.card.diary", "icon": "icon-transaction"},
{"state": "item.card.last-entries", "icon": "icon-regentry"},
@ -92,6 +93,16 @@
},
"acl": ["buyer"]
},
{
"url" : "/shelving",
"state": "item.card.shelving",
"component": "vn-item-shelving",
"description": "Shelvings",
"params": {
"item": "$ctrl.item"
},
"acl": ["employee"]
},
{
"url" : "/barcode",
"state": "item.card.itemBarcode",

View File

@ -14,7 +14,7 @@
]
},
"keybindings": [
{"key": "s", "state": "shelving.index"}
{"key": "c", "state": "shelving.index"}
],
"routes": [
{