Merge pull request '3758-client_unpaid' (#936) from 3758-client_unpaid into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #936
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2022-04-13 09:19:27 +00:00
commit 153b42cd26
14 changed files with 204 additions and 3 deletions

View File

@ -0,0 +1,10 @@
CREATE TABLE `vn`.`clientUnpaid` (
`clientFk` int(11) NOT NULL,
`dated` date NOT NULL,
`amount` double DEFAULT 0,
PRIMARY KEY (`clientFk`),
CONSTRAINT `clientUnpaid_clientFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE
);
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES('ClientUnpaid', '*', '*', 'ALLOW', 'ROLE', 'administrative');

View File

@ -321,6 +321,12 @@ export default {
deleteFirstPhone: 'vn-client-contact vn-icon[icon="delete"]',
saveButton: 'button[type=submit]'
},
clientUnpaid: {
hasDataCheckBox: 'vn-client-unpaid vn-check[ng-model="watcher.hasData"]',
dated: 'vn-client-unpaid vn-date-picker[ng-model="$ctrl.clientUnpaid.dated"]',
amount: 'vn-client-unpaid vn-input-number[ng-model="$ctrl.clientUnpaid.amount"]',
saveButton: 'vn-submit[label="Save"]'
},
itemsIndex: {
createItemButton: `vn-float-button`,
firstSearchResult: 'vn-item-index tbody tr:nth-child(1)',

View File

@ -0,0 +1,41 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Client unpaid path', () => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('administrative', 'client');
await page.accessToSearchResult('Charles Xavier');
await page.accessToSection('client.card.unpaid');
await page.waitForState('client.card.unpaid');
});
afterAll(async() => {
await browser.close();
});
it('should set cliet unpaid', async() => {
await page.waitToClick(selectors.clientUnpaid.hasDataCheckBox);
await page.pickDate(selectors.clientUnpaid.dated);
await page.write(selectors.clientUnpaid.amount, '500');
});
it('should save unpaid', async() => {
await page.waitToClick(selectors.clientUnpaid.saveButton);
const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!');
});
it('should confirm the unpaid have been saved', async() => {
await page.reloadSection('client.card.unpaid');
const result = await page.waitToGetProperty(selectors.clientUnpaid.amount, 'value');
expect(result).toEqual('500');
});
});

View File

@ -44,6 +44,9 @@
"ClientType": {
"dataSource": "vn"
},
"ClientUnpaid": {
"dataSource": "vn"
},
"Defaulter": {
"dataSource": "vn"
},

View File

@ -0,0 +1,28 @@
{
"name": "ClientUnpaid",
"base": "VnModel",
"options": {
"mysql": {
"table": "clientUnpaid"
}
},
"properties": {
"clientFk": {
"type": "number",
"id": true
},
"dated": {
"type": "date"
},
"amount": {
"type": "Number"
}
},
"relations": {
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
}
}
}

View File

@ -46,3 +46,4 @@ import './consumption';
import './consumption-search-panel';
import './defaulter';
import './notification';
import './unpaid';

View File

@ -62,3 +62,4 @@ Consumption: Consumo
Compensation Account: Cuenta para compensar
Amount to return: Cantidad a devolver
Delivered amount: Cantidad entregada
Unpaid: Impagado

View File

@ -32,7 +32,8 @@
{"state": "client.card.creditInsurance.index", "icon": "icon-solunion"},
{"state": "client.card.contact", "icon": "contact_phone"},
{"state": "client.card.webPayment", "icon": "icon-onlinepayment"},
{"state": "client.card.dms.index", "icon": "cloud_upload"}
{"state": "client.card.dms.index", "icon": "cloud_upload"},
{"state": "client.card.unpaid", "icon": "icon-defaulter"}
]
}
]
@ -374,6 +375,12 @@
"state": "client.notification",
"component": "vn-client-notification",
"description": "Notifications"
}, {
"url": "/unpaid",
"state": "client.card.unpaid",
"component": "vn-client-unpaid",
"acl": ["administrative"],
"description": "Unpaid"
}
]
}

View File

@ -0,0 +1,51 @@
<div>
<vn-watcher
vn-id="watcher"
url="ClientUnpaids"
data="$ctrl.clientUnpaid"
id-value="$ctrl.$params.id"
id-field="clientFk"
form="form">
</vn-watcher>
<form
name="form"
ng-submit="watcher.submit()"
class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-check
label="Unpaid client"
ng-model="watcher.hasData"
on-change="$ctrl.setDefaultDate(watcher.hasData)">
</vn-check>
</vn-vertical>
<vn-horizontal
ng-if="watcher.hasData">
<vn-date-picker
label="Date"
ng-model="$ctrl.clientUnpaid.dated"
vn-focus>
</vn-date-picker>
<vn-input-number
vn-focus
label="Amount"
ng-model="$ctrl.clientUnpaid.amount"
step="0.01"
required>
</vn-input-number>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Save">
</vn-submit>
<vn-button
class="cancel"
label="Undo changes"
disabled="!watcher.dataChanged()"
ng-click="watcher.loadOriginalData()">
</vn-button>
</vn-button-bar>
</form>
</div>

View File

@ -0,0 +1,14 @@
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
setDefaultDate(hasData) {
if (hasData && !this.clientUnpaid.dated)
this.clientUnpaid.dated = new Date();
}
}
ngModule.vnComponent('vnClientUnpaid', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,38 @@
import './index';
describe('client unpaid', () => {
describe('Component vnClientUnpaid', () => {
let controller;
beforeEach(ngModule('client'));
beforeEach(inject($componentController => {
const $element = angular.element('<vn-client-unpaid></vn-client-unpaid>');
controller = $componentController('vnClientUnpaid', {$element});
}));
describe('setDefaultDate()', () => {
it(`should not set today date if has dated`, () => {
const hasData = true;
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
controller.clientUnpaid = {
dated: yesterday
};
controller.setDefaultDate(hasData);
expect(controller.clientUnpaid.dated).toEqual(yesterday);
});
it(`should set today if not has dated`, () => {
const hasData = true;
controller.clientUnpaid = {};
controller.setDefaultDate(hasData);
expect(controller.clientUnpaid.dated).toBeDefined();
});
});
});
});

View File

@ -0,0 +1 @@
Unpaid client: Cliente impagado