Tarea #356 Crear Order
This commit is contained in:
parent
e863388346
commit
18929e379c
|
@ -0,0 +1,34 @@
|
||||||
|
<vn-title>New order</vn-title>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-focus
|
||||||
|
vn-id="client"
|
||||||
|
url="/api/Clients"
|
||||||
|
label="Client"
|
||||||
|
show-field="name"
|
||||||
|
value-field="id"
|
||||||
|
field="$ctrl.clientFk">
|
||||||
|
<tpl-item>{{id}}: {{name}}</tpl-item>
|
||||||
|
</vn-autocomplete>
|
||||||
|
<vn-autocomplete
|
||||||
|
disabled="!$ctrl.clientFk"
|
||||||
|
url="{{ $ctrl.clientFk ? '/api/Clients/'+ $ctrl.clientFk +'/addresses' : null }}"
|
||||||
|
select-fields=["nickname","street","city"]
|
||||||
|
field="$ctrl.addressFk"
|
||||||
|
show-field="nickname"
|
||||||
|
value-field="id"
|
||||||
|
label="Address">
|
||||||
|
<tpl-item>{{nickname}}: {{street}}, {{city}}</tpl-item>
|
||||||
|
</vn-autocomplete>
|
||||||
|
<vn-date-picker
|
||||||
|
label="Landed"
|
||||||
|
model="$ctrl.landed"
|
||||||
|
ini-options="{enableTime: false}">
|
||||||
|
</vn-date-picker>
|
||||||
|
<vn-autocomplete
|
||||||
|
disabled="!$ctrl.clientFk || !$ctrl.landed"
|
||||||
|
data="$ctrl._avaibleAgencies"
|
||||||
|
label="Agency"
|
||||||
|
show-field="agency"
|
||||||
|
value-field="id"
|
||||||
|
field="$ctrl.ticket.agencyModeFk">
|
||||||
|
</vn-autocomplete>
|
|
@ -0,0 +1,93 @@
|
||||||
|
import ngModule from '../module';
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
constructor($scope, $http, vnApp, $translate) {
|
||||||
|
this.$scope = $scope;
|
||||||
|
this.$http = $http;
|
||||||
|
this.translate = $translate;
|
||||||
|
this.vnApp = vnApp;
|
||||||
|
this.ticket = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
set ticket(value) {
|
||||||
|
if (value) {
|
||||||
|
this._ticket = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get ticket() {
|
||||||
|
return this._ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
set clientFk(value) {
|
||||||
|
this.ticket.clientFk = value;
|
||||||
|
this.addressFk = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get clientFk() {
|
||||||
|
return this.ticket.clientFk;
|
||||||
|
}
|
||||||
|
|
||||||
|
set addressFk(value) {
|
||||||
|
this.ticket.addressFk = value;
|
||||||
|
this.getAvaibleAgencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
get addressFk() {
|
||||||
|
return this.ticket.addressFk;
|
||||||
|
}
|
||||||
|
|
||||||
|
set landed(value) {
|
||||||
|
this.ticket.landed = value;
|
||||||
|
this.getAvaibleAgencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
get landed() {
|
||||||
|
return this.ticket.landed;
|
||||||
|
}
|
||||||
|
|
||||||
|
get warehouseFk() {
|
||||||
|
return this.ticket.warehouseFk;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAvaibleAgencies() {
|
||||||
|
this.ticket.agencyModeFk = null;
|
||||||
|
if (this.ticket.landed && this.ticket.addressFk) {
|
||||||
|
let filter = {addressFk: this.ticket.addressFk, landed: this.ticket.landed};
|
||||||
|
filter = encodeURIComponent(JSON.stringify(filter));
|
||||||
|
let query = `/api/Agencies/landsThatDay?filter=${filter}`;
|
||||||
|
this.$http.get(query).then(res => {
|
||||||
|
this._avaibleAgencies = res.data[0];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
this.createOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
createOrder() {
|
||||||
|
let params = {
|
||||||
|
landed: this.ticket.landed,
|
||||||
|
addressFk: this.ticket.addressFk,
|
||||||
|
agencyModeFk: this.ticket.agencyModeFk
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$http.post(`order/api/Orders/new`, params).then(res => {
|
||||||
|
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
|
||||||
|
return res.data.id;
|
||||||
|
}).catch(e => {
|
||||||
|
this.vnApp.showError(this.translate.instant(e.data.error.message));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
||||||
|
|
||||||
|
ngModule.component('vnTicketCreateCard', {
|
||||||
|
template: require('./card.html'),
|
||||||
|
controller: Controller,
|
||||||
|
bindings: {
|
||||||
|
ticket: '<?'
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
//import './card.js';
|
import './card.js';
|
||||||
|
|
||||||
xdescribe('Ticket', () => {
|
fdescribe('Ticket', () => {
|
||||||
describe('Component vnTicketCreateCard', () => {
|
describe('Component vnTicketCreateCard', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $scope;
|
let $scope;
|
||||||
|
@ -19,7 +19,7 @@ xdescribe('Ticket', () => {
|
||||||
controller.item = {id: 3};
|
controller.item = {id: 3};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('set clientFk()', () => {
|
describe('set clientFk', () => {
|
||||||
it(`should set addressFk to null and clientFk to a value`, () => {
|
it(`should set addressFk to null and clientFk to a value`, () => {
|
||||||
controller.clientFk = 2;
|
controller.clientFk = 2;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ xdescribe('Ticket', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('set addressFk()', () => {
|
describe('set addressFk', () => {
|
||||||
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
|
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
|
||||||
controller.addressFk = 101;
|
controller.addressFk = 101;
|
||||||
|
|
||||||
|
@ -37,25 +37,39 @@ xdescribe('Ticket', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('set onSubmit()', () => {
|
describe('getAvaibleAgencies()', () => {
|
||||||
it(`should call createTicket()`, () => {
|
it(`should make a query if landed and addressFk exists`, () => {
|
||||||
spyOn(controller, 'createTicket');
|
controller.ticket.addressFk = 101;
|
||||||
|
controller.ticket.landed = 101;
|
||||||
|
|
||||||
|
let filter = {addressFk: controller.ticket.addressFk, landed: controller.ticket.landed};
|
||||||
|
filter = encodeURIComponent(JSON.stringify(filter));
|
||||||
|
$httpBackend.whenGET(`/api/Agencies/landsThatDay?filter=${filter}`).respond({data: 1});
|
||||||
|
$httpBackend.expectGET(`/api/Agencies/landsThatDay?filter=${filter}`);
|
||||||
|
|
||||||
|
controller.getAvaibleAgencies();
|
||||||
|
$httpBackend.flush();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onSubmit()', () => {
|
||||||
|
it(`should call createOrder()`, () => {
|
||||||
|
spyOn(controller, 'createOrder');
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.createTicket).toHaveBeenCalledWith();
|
expect(controller.createOrder).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createTicket()', () => {
|
describe('createOrder()', () => {
|
||||||
it(`should make a query`, () => {
|
it(`should make a query`, () => {
|
||||||
controller.ticket.clientFk = 101;
|
|
||||||
controller.ticket.addressFk = 101;
|
controller.ticket.addressFk = 101;
|
||||||
controller.ticket.agencyModeFk = 101;
|
controller.ticket.agencyModeFk = 101;
|
||||||
controller.ticket.shipped = 101;
|
controller.ticket.landed = 101;
|
||||||
|
|
||||||
$httpBackend.whenPOST('order/api/Orders/new').respond({data: 'item'});
|
$httpBackend.whenPOST('order/api/Orders/new').respond({data: 1});
|
||||||
$httpBackend.expectPOST('order/api/Orders/new');
|
$httpBackend.expectPOST('order/api/Orders/new');
|
||||||
controller.createTicket();
|
controller.createOrder();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
<mg-ajax path="/item/api/Tickets" options="vnPost"></mg-ajax>
|
<div margin-medium>
|
||||||
<vn-watcher
|
<div style="max-width: 70em; margin: 0 auto;" >
|
||||||
vn-id="watcher"
|
|
||||||
data="$ctrl.ticket"
|
|
||||||
form="form"
|
|
||||||
save="post">
|
|
||||||
</vn-watcher>
|
|
||||||
<form name="form" ng-submit="$ctrl.onSubmit()" margin-medium>
|
|
||||||
<div style="max-width: 70em; margin: 0 auto;">
|
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-title>New ticket</vn-title>
|
<vn-ticket-create-card vn-id="card" on-save=""></vn-ticket-create-card>
|
||||||
|
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-submit label="Create"></vn-submit>
|
<vn-submit ng-click="$ctrl.onSubmit()" label="Save">
|
||||||
|
</vn-submit>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
|
@ -1,20 +1,18 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor($scope, $state) {
|
constructor($scope, $http, $state) {
|
||||||
this.$ = $scope;
|
this.$ = $scope;
|
||||||
|
this.$http = $http;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
this.Ticket = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
async onSubmit() {
|
||||||
this.$.watcher.submit().then(
|
let newOrderID = await this.$.card.createOrder();
|
||||||
json => this.$state.go('ticket.card.data', {id: json.data.id})
|
this.$state.go("ticket.card.summary", {id: newOrderID});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Controller.$inject = ['$scope', '$http', '$state'];
|
||||||
Controller.$inject = ['$scope', '$state'];
|
|
||||||
|
|
||||||
ngModule.component('vnTicketCreate', {
|
ngModule.component('vnTicketCreate', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
|
|
||||||
xdescribe('Ticket', () => {
|
fdescribe('Ticket', () => {
|
||||||
describe('Component vnTicketCreate', () => {
|
describe('Component vnTicketCreate', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $scope;
|
let $scope;
|
||||||
|
@ -15,18 +15,17 @@ xdescribe('Ticket', () => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
|
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.card = {createTicket: () => {}};
|
$scope.card = {createOrder: () => {}};
|
||||||
$state = _$state_;
|
$state = _$state_;
|
||||||
$state.go = () => {};
|
|
||||||
controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state});
|
controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('onSubmit()', () => {
|
describe('onSubmit()', () => {
|
||||||
it(`should call createTicket()`, () => {
|
it(`should call createOrder()`, () => {
|
||||||
spyOn(controller.$.card, 'createTicket');
|
spyOn(controller.$.card, 'createOrder');
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.$.card.createTicket).toHaveBeenCalledWith();
|
expect(controller.$.card.createOrder).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit(`should call go()`, () => {
|
xit(`should call go()`, () => {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
You can't create an order for a frozen client: No puedes crear una orden a un cliente congelado
|
||||||
|
You can't create an order for a inactive client: No puedes crear una orden a un cliente inactivo
|
||||||
|
You can't create an order for a client that doesn't has tax data verified:
|
||||||
|
No puedes crear una orden a un cliente cuyos datos fiscales no han sido verificados
|
||||||
|
You can't create an order for a client that has a debt: No puedes crear una orden a un cliente que tiene deuda
|
||||||
|
New order: Nueva orden
|
|
@ -3,6 +3,7 @@ export * from './module';
|
||||||
import './search-panel';
|
import './search-panel';
|
||||||
import './index';
|
import './index';
|
||||||
import './create';
|
import './create';
|
||||||
|
import './create/card';
|
||||||
import './card';
|
import './card';
|
||||||
import './descriptor';
|
import './descriptor';
|
||||||
import './summary';
|
import './summary';
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('landsThatDay', {
|
||||||
|
description: 'Returns a list of agencies that can land a shipment on a day for an address',
|
||||||
|
accessType: '',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
required: true,
|
||||||
|
description: 'addressFk'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/landsThatDay`,
|
||||||
|
verb: 'get'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.landsThatDay = async filter => {
|
||||||
|
let query = `CALL vn.agencyHourGetAgency(?, ?)`;
|
||||||
|
let result = await Self.rawSql(query, [filter.addressFk, filter.landed]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,5 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.defineScope({where: {isManaged: {neq: 0}}});
|
Self.defineScope({where: {isManaged: {neq: 0}}});
|
||||||
//require('../methods/agency/sendsThatDay')(Self);
|
require('../methods/agency/landsThatDay')(Self);
|
||||||
require('../methods/agency/getFirstShipped')(Self);
|
require('../methods/agency/getFirstShipped')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('new', {
|
||||||
|
description: 'Create a new order and returns the new ID',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'params',
|
||||||
|
type: 'object',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/new`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.new = async params => {
|
||||||
|
let cli = await Self.app.models.Address.findOne({where: {id: params.addressFk}, fields: 'clientFk'});
|
||||||
|
|
||||||
|
let client = await Self.app.models.Client.findOne({
|
||||||
|
where: {id: cli.clientFk},
|
||||||
|
fields: ['isTaxDataChecked', 'isFreezed', 'isActive']
|
||||||
|
});
|
||||||
|
|
||||||
|
if (client.isFreezed)
|
||||||
|
throw new Error(`You can't create an order for a frozen client`);
|
||||||
|
|
||||||
|
if (!client.isActive)
|
||||||
|
throw new Error(`You can't create an order for a inactive client`);
|
||||||
|
|
||||||
|
if (!client.isTaxDataChecked)
|
||||||
|
throw new Error(`You can't create an order for a client that doesn't has tax data verified`);
|
||||||
|
|
||||||
|
let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
|
||||||
|
let clientDebt = await Self.rawSql(query, [cli.clientFk]);
|
||||||
|
if (clientDebt[0].debt > 0)
|
||||||
|
throw new Error(`You can't create an order for a client that has a debt`);
|
||||||
|
|
||||||
|
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
|
||||||
|
result = await Self.rawSql(query, [
|
||||||
|
params.landed,
|
||||||
|
params.agencyModeFk,
|
||||||
|
params.addressFk,
|
||||||
|
"SALIX"
|
||||||
|
]);
|
||||||
|
return result[0].vOrderId;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/new')(Self);
|
||||||
|
};
|
Loading…
Reference in New Issue