Tarea #427 mover create order de ticket a order

This commit is contained in:
gerard 2018-07-24 13:48:31 +02:00
parent 81dc09999f
commit b68f34d3d4
15 changed files with 38 additions and 161 deletions

View File

@ -30,5 +30,5 @@
label="Agency"
show-field="agency"
value-field="id"
field="$ctrl.ticket.agencyModeFk">
field="$ctrl.order.agencyModeFk">
</vn-autocomplete>

View File

@ -1,59 +1,60 @@
import ngModule from '../module';
class Controller {
constructor($scope, $http, vnApp, $translate) {
constructor($scope, $http, vnApp, $translate, $state) {
this.$scope = $scope;
this.$http = $http;
this.translate = $translate;
this.vnApp = vnApp;
this.ticket = {};
this.order = {};
this.$state = $state;
}
set ticket(value) {
set order(value) {
if (value) {
this._ticket = value;
this._order = value;
}
}
get ticket() {
return this._ticket;
get order() {
return this._order;
}
set clientFk(value) {
this.ticket.clientFk = value;
this.order.clientFk = value;
this.addressFk = null;
}
get clientFk() {
return this.ticket.clientFk;
return this.order.clientFk;
}
set addressFk(value) {
this.ticket.addressFk = value;
this.order.addressFk = value;
this.getAvailableAgencies();
}
get addressFk() {
return this.ticket.addressFk;
return this.order.addressFk;
}
set landed(value) {
this.ticket.landed = value;
this.order.landed = value;
this.getAvailableAgencies();
}
get landed() {
return this.ticket.landed;
return this.order.landed;
}
get warehouseFk() {
return this.ticket.warehouseFk;
return this.order.warehouseFk;
}
getAvailableAgencies() {
this.ticket.agencyModeFk = null;
if (this.ticket.landed && this.ticket.addressFk) {
let filter = {addressFk: this.ticket.addressFk, landed: this.ticket.landed};
this.order.agencyModeFk = null;
if (this.order.landed && this.order.addressFk) {
let filter = {addressFk: this.order.addressFk, landed: this.order.landed};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/api/Agencies/landsThatDay?filter=${filter}`;
this.$http.get(query).then(res => {
@ -68,26 +69,25 @@ class Controller {
createOrder() {
let params = {
landed: this.ticket.landed,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
landed: this.order.landed,
addressFk: this.order.addressFk,
agencyModeFk: this.order.agencyModeFk
};
this.$http.post(`order/api/Orders/new`, params).then(res => {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
return res.data.id;
this.$state.go("order.card.summary", {id: res.data});
}).catch(e => {
this.vnApp.showError(this.translate.instant(e.data.error.message));
});
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', '$state'];
ngModule.component('vnTicketCreateCard', {
ngModule.component('vnOrderCreateCard', {
template: require('./card.html'),
controller: Controller,
bindings: {
ticket: '<?'
order: '<?'
}
});

View File

@ -1,7 +1,7 @@
<div margin-medium>
<div style="max-width: 70em; margin: 0 auto;" >
<vn-card pad-large>
<vn-ticket-create-card vn-id="card" on-save=""></vn-ticket-create-card>
<vn-order-create-card vn-id="card" on-save=""></vn-order-create-card>
</vn-card>
<vn-button-bar>
<vn-submit ng-click="$ctrl.onSubmit()" label="Save">

View File

@ -9,12 +9,13 @@ class Controller {
async onSubmit() {
let newOrderID = await this.$.card.createOrder();
this.$state.go("ticket.card.summary", {id: newOrderID});
console.log(newOrderID);
this.$state.go("order.card.summary", {id: newOrderID});
}
}
Controller.$inject = ['$scope', '$http', '$state'];
ngModule.component('vnTicketCreate', {
ngModule.component('vnOrderCreate', {
template: require('./index.html'),
controller: Controller
});

View File

@ -8,3 +8,5 @@ import './summary';
import './catalogue';
import './catalogue/product';
import './volume';
import './create';
import './create/card';

View File

@ -35,9 +35,10 @@
scroll-selector="ui-view">
</vn-pagination>
</div>
<!-- <a ui-sref="ticket.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
<a ui-sref="order.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
<!--
<vn-dialog class="dialog-summary"
vn-id="dialog-summary-ticket">
<tpl-body>

View File

@ -1,3 +1,4 @@
Address: Consignatario
Catalogue: Catálogo
from: desde
results: resultados

View File

@ -15,11 +15,6 @@
"state": "ticket.index",
"component": "vn-ticket-index"
},
{
"url": "/create",
"state": "ticket.create",
"component": "vn-ticket-create"
},
{
"url": "/:id",
"state": "ticket.card",

View File

@ -1,79 +0,0 @@
import './card.js';
describe('Ticket', () => {
describe('Component vnTicketCreateCard', () => {
let $componentController;
let $scope;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
controller = $componentController('vnTicketCreateCard', {$scope: $scope});
controller.item = {id: 3};
}));
describe('set clientFk', () => {
it(`should set addressFk to null and clientFk to a value`, () => {
controller.clientFk = 2;
expect(controller.clientFk).toEqual(2);
expect(controller.ticket.addressFk).toBe(null);
});
});
describe('set addressFk', () => {
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
controller.addressFk = 101;
expect(controller.addressFk).toEqual(101);
expect(controller.ticket.agencyModeFk).toBe(null);
});
});
describe('getAvailableAgencies()', () => {
it(`should make a query if landed and addressFk exists`, () => {
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.getAvailableAgencies();
$httpBackend.flush();
});
});
describe('onSubmit()', () => {
it(`should call createOrder()`, () => {
spyOn(controller, 'createOrder');
controller.onSubmit();
expect(controller.createOrder).toHaveBeenCalledWith();
});
});
describe('createOrder()', () => {
it(`should make a query`, () => {
controller.ticket.addressFk = 101;
controller.ticket.agencyModeFk = 101;
controller.ticket.landed = 101;
$httpBackend.whenPOST('order/api/Orders/new').respond({data: 1});
$httpBackend.expectPOST('order/api/Orders/new');
controller.createOrder();
$httpBackend.flush();
});
});
});
});

View File

@ -1,40 +0,0 @@
import './index.js';
describe('Ticket', () => {
describe('Component vnTicketCreate', () => {
let $componentController;
let $scope;
let controller;
let $state;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$scope.card = {createOrder: () => {}};
$state = _$state_;
controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state});
}));
describe('onSubmit()', () => {
it(`should call createOrder()`, () => {
spyOn(controller.$.card, 'createOrder');
controller.onSubmit();
expect(controller.$.card.createOrder).toHaveBeenCalledWith();
});
xit(`should call go()`, () => {
spyOn(controller.$state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith();
});
});
});
});

View File

@ -69,9 +69,6 @@
scroll-selector="ui-view">
</vn-pagination>
</div>
<a ui-sref="ticket.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
<vn-dialog class="dialog-summary"
vn-id="dialog-summary-ticket">
<tpl-body>

View File

@ -2,8 +2,6 @@ export * from './module';
import './search-panel';
import './index';
import './create';
import './create/card';
import './card';
import './descriptor';
import './summary';

View File

@ -40,12 +40,13 @@ module.exports = Self => {
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, [
[result] = await Self.rawSql(query, [
params.landed,
params.agencyModeFk,
params.addressFk,
"SALIX"
]);
return result[0].vOrderId;
};
};

View File

@ -1,5 +1,5 @@
module.exports = Self => {
require('../methods/new')(Self);
require('../methods/order/new')(Self);
require('../methods/order/getTotalVolume')(Self);
require('../methods/order/getVolumes')(Self);
require('../methods/order/getTotal')(Self);