fixed price index implementation
This commit is contained in:
parent
78d9b40828
commit
3251d737e6
|
@ -0,0 +1 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('FixedPrice', '*', '*', 'ALLOW', 'ROLE', 'buyer');
|
|
@ -0,0 +1,192 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('filter', {
|
||||
description: 'Find all instances of the model matched by filter from the data source.',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
},
|
||||
{
|
||||
arg: 'search',
|
||||
type: 'string',
|
||||
description: `If it's and integer searchs by itemFk, otherwise it searchs by the itemType code`,
|
||||
},
|
||||
{
|
||||
arg: 'itemFk',
|
||||
type: 'integer',
|
||||
description: 'The item id',
|
||||
},
|
||||
{
|
||||
arg: 'typeFk',
|
||||
type: 'integer',
|
||||
description: 'The item type id',
|
||||
},
|
||||
{
|
||||
arg: 'categoryFk',
|
||||
type: 'integer',
|
||||
description: 'The item category id',
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'integer',
|
||||
description: 'The warehouse id',
|
||||
},
|
||||
{
|
||||
arg: 'buyerFk',
|
||||
type: 'integer',
|
||||
description: 'The buyer id',
|
||||
},
|
||||
{
|
||||
arg: 'rate2',
|
||||
type: 'integer',
|
||||
description: 'The price per unit',
|
||||
},
|
||||
{
|
||||
arg: 'rate3',
|
||||
type: 'integer',
|
||||
description: 'The price per package',
|
||||
},
|
||||
{
|
||||
arg: 'minPrice',
|
||||
type: 'integer',
|
||||
description: 'The minimum price of the item',
|
||||
},
|
||||
{
|
||||
arg: 'hasMinPrice',
|
||||
type: 'boolean',
|
||||
description: 'whether a minimum price has been defined for the item',
|
||||
},
|
||||
{
|
||||
arg: 'started',
|
||||
type: 'date',
|
||||
description: 'Price validity start date',
|
||||
},
|
||||
{
|
||||
arg: 'ended',
|
||||
type: 'date',
|
||||
description: 'Price validity end date',
|
||||
},
|
||||
{
|
||||
arg: 'tags',
|
||||
type: ['object'],
|
||||
description: 'List of tags to filter with',
|
||||
},
|
||||
{
|
||||
arg: 'mine',
|
||||
type: 'Boolean',
|
||||
description: `Search requests attended by the current user`
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/filter`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
|
||||
if (ctx.args.mine)
|
||||
ctx.args.buyerFk = userId;
|
||||
|
||||
const where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {'fp.itemFk': {inq: value}}
|
||||
: {'it.code': {like: `%${value}%`}};
|
||||
case 'categoryFk':
|
||||
return {'it.categoryFk': value};
|
||||
case 'buyerFk':
|
||||
return {'it.workerFk': value};
|
||||
case 'warehouseFk':
|
||||
case 'rate2':
|
||||
case 'rate3':
|
||||
case 'started':
|
||||
case 'ended':
|
||||
param = `fp.${param}`;
|
||||
return {[param]: value};
|
||||
case 'minPrice':
|
||||
case 'hasMinPrice':
|
||||
case 'typeFk':
|
||||
param = `i.${param}`;
|
||||
return {[param]: value};
|
||||
}
|
||||
});
|
||||
filter = mergeFilters(filter, {where});
|
||||
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmt = new ParameterizedSQL(
|
||||
`SELECT fp.id,
|
||||
fp.itemFk,
|
||||
fp.warehouseFk,
|
||||
fp.rate2,
|
||||
fp.rate3,
|
||||
fp.started,
|
||||
fp.ended,
|
||||
i.minPrice,
|
||||
i.hasMinPrice,
|
||||
i.name,
|
||||
i.subName,
|
||||
i.tag5,
|
||||
i.value5,
|
||||
i.tag6,
|
||||
i.value6,
|
||||
i.tag7,
|
||||
i.value7,
|
||||
i.tag8,
|
||||
i.value8,
|
||||
i.tag9,
|
||||
i.value9,
|
||||
i.tag10,
|
||||
i.value10
|
||||
FROM priceFixed fp
|
||||
JOIN item i ON i.id = fp.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk`
|
||||
);
|
||||
|
||||
if (ctx.args.tags) {
|
||||
let i = 1;
|
||||
for (const tag of ctx.args.tags) {
|
||||
const tAlias = `it${i++}`;
|
||||
|
||||
if (tag.tagFk) {
|
||||
stmt.merge({
|
||||
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
|
||||
AND ${tAlias}.tagFk = ?
|
||||
AND ${tAlias}.value LIKE ?`,
|
||||
params: [tag.tagFk, `%${tag.value}%`],
|
||||
});
|
||||
} else {
|
||||
stmt.merge({
|
||||
sql: `JOIN vn.itemTag ${tAlias} ON ${tAlias}.itemFk = i.id
|
||||
AND ${tAlias}.value LIKE ?`,
|
||||
params: [`%${tag.value}%`],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
|
||||
const fixedPriceIndex = stmts.push(stmt) - 1;
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql);
|
||||
return fixedPriceIndex === 0 ? result : result[fixedPriceIndex];
|
||||
};
|
||||
};
|
|
@ -0,0 +1,62 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('upsertFixedPrice()', () => {
|
||||
const now = new Date();
|
||||
const fixedPriceId = 1;
|
||||
let originalFixedPrice;
|
||||
let originalItem;
|
||||
|
||||
beforeAll(async() => {
|
||||
originalFixedPrice = await app.models.FixedPrice.findById(fixedPriceId);
|
||||
originalItem = await app.models.Item.findById(originalFixedPrice.itemFk);
|
||||
});
|
||||
|
||||
beforeAll(async() => {
|
||||
await originalFixedPrice.save();
|
||||
await originalItem.save();
|
||||
});
|
||||
|
||||
it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => {
|
||||
const ctx = {args: {
|
||||
id: fixedPriceId,
|
||||
itemFk: 1,
|
||||
warehouseFk: 1,
|
||||
rate2: 100,
|
||||
rate3: 300,
|
||||
started: now,
|
||||
ended: now,
|
||||
minPrice: 100,
|
||||
hasMinPrice: false
|
||||
}};
|
||||
|
||||
const result = await app.models.FixedPrice.upsertFixedPrice(ctx, ctx.args.id);
|
||||
|
||||
delete ctx.args.started;
|
||||
delete ctx.args.ended;
|
||||
ctx.args.hasMinPrice = true;
|
||||
|
||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||
});
|
||||
|
||||
it(`should toggle the hasMinPrice boolean if there's no minPrice and update the rest of the data`, async() => {
|
||||
const ctx = {args: {
|
||||
id: fixedPriceId,
|
||||
itemFk: 1,
|
||||
warehouseFk: 1,
|
||||
rate2: 2.5,
|
||||
rate3: 2,
|
||||
started: now,
|
||||
ended: now,
|
||||
minPrice: 0,
|
||||
hasMinPrice: true
|
||||
}};
|
||||
|
||||
const result = await app.models.FixedPrice.upsertFixedPrice(ctx, ctx.args.id);
|
||||
|
||||
delete ctx.args.started;
|
||||
delete ctx.args.ended;
|
||||
ctx.args.hasMinPrice = false;
|
||||
|
||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||
});
|
||||
});
|
|
@ -0,0 +1,116 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('upsertFixedPrice', {
|
||||
description: 'Inserts or updates a fixed price for an item',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'ctx',
|
||||
type: 'object',
|
||||
http: {source: 'context'}
|
||||
},
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
description: 'The fixed price id'
|
||||
},
|
||||
{
|
||||
arg: 'itemFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'started',
|
||||
type: 'date'
|
||||
},
|
||||
{
|
||||
arg: 'ended',
|
||||
type: 'date'
|
||||
},
|
||||
{
|
||||
arg: 'rate2',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'rate3',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'minPrice',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'hasMinPrice',
|
||||
type: 'any'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/upsertFixedPrice`,
|
||||
verb: 'PATCH'
|
||||
}
|
||||
});
|
||||
|
||||
Self.upsertFixedPrice = async ctx => {
|
||||
const models = Self.app.models;
|
||||
|
||||
const args = ctx.args;
|
||||
const tx = await models.Address.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
delete args.ctx; // removed unwanted data
|
||||
|
||||
const fixedPrice = await models.FixedPrice.upsert(args, options);
|
||||
const targetItem = await models.Item.findById(args.itemFk, null, options);
|
||||
await targetItem.updateAttributes({
|
||||
minPrice: args.minPrice,
|
||||
hasMinPrice: args.minPrice ? true : false
|
||||
}, options);
|
||||
|
||||
const itemFields = [
|
||||
'minPrice',
|
||||
'hasMinPrice',
|
||||
'name',
|
||||
'subName',
|
||||
'tag5',
|
||||
'value5',
|
||||
'tag6',
|
||||
'value6',
|
||||
'tag7',
|
||||
'value7',
|
||||
'tag8',
|
||||
'value8',
|
||||
'tag9',
|
||||
'value9',
|
||||
'tag10',
|
||||
'value10'
|
||||
];
|
||||
|
||||
const fieldsCopy = [].concat(itemFields);
|
||||
const filter = {
|
||||
include: {
|
||||
relation: 'item',
|
||||
scope: {
|
||||
fields: fieldsCopy
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await models.FixedPrice.findById(fixedPrice.id, filter, options);
|
||||
const item = result.item();
|
||||
|
||||
for (let key of itemFields)
|
||||
result[key] = item[key];
|
||||
|
||||
await tx.commit();
|
||||
return result;
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -76,5 +76,8 @@
|
|||
},
|
||||
"TaxType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"FixedPrice": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/fixed-price/filter')(Self);
|
||||
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"name": "FixedPrice",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "priceFixed"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"itemFk": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"warehouseFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"rate2": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"rate3": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"started": {
|
||||
"type": "date",
|
||||
"required": true
|
||||
},
|
||||
"ended": {
|
||||
"type": "date",
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"item": {
|
||||
"type": "belongsTo",
|
||||
"model": "Item",
|
||||
"foreignKey": "itemFk"
|
||||
},
|
||||
"warehouse": {
|
||||
"type": "belongsTo",
|
||||
"model": "Warehouse",
|
||||
"foreignKey": "warehouseFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "buyer",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
<vn-crud-model
|
||||
url="Tags"
|
||||
fields="['id','name','isFree', 'sourceTable']"
|
||||
data="tags"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<div class="search-panel">
|
||||
<form class="vn-pa-lg" ng-submit="$ctrl.onSearch()">
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="General search"
|
||||
ng-model="filter.search"
|
||||
vn-focus>
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
url="ItemCategories"
|
||||
label="Category"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
ng-model="filter.categoryFk">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
url="ItemTypes"
|
||||
label="Type"
|
||||
where="{categoryFk: filter.categoryFk}"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
ng-model="filter.typeFk"
|
||||
fields="['categoryFk']"
|
||||
include="'category'">
|
||||
<tpl-item>
|
||||
<div>{{name}}</div>
|
||||
<div class="text-caption text-secondary">
|
||||
{{category.name}}
|
||||
</div>
|
||||
</tpl-item>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="filter.buyerFk"
|
||||
url="Clients/activeWorkersWithRole"
|
||||
show-field="nickname"
|
||||
search-function="{firstName: $search}"
|
||||
value-field="id"
|
||||
where="{role: 'buyer'}"
|
||||
label="Buyer">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
label="Warehouse"
|
||||
ng-model="filter.warehouseFk"
|
||||
url="Warehouses">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="Started"
|
||||
ng-model="filter.started">
|
||||
</vn-date-picker>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="Ended"
|
||||
ng-model="filter.ended">
|
||||
</vn-date-picker>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-check vn-one
|
||||
triple-state="true"
|
||||
label="For me"
|
||||
ng-model="filter.mine">
|
||||
</vn-check>
|
||||
<vn-check vn-one
|
||||
triple-state="true"
|
||||
label="Minimum price"
|
||||
ng-model="filter.hasMinPrice">
|
||||
</vn-check>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-pt-sm">
|
||||
<vn-one class="text-subtitle1" translate>
|
||||
Tags
|
||||
</vn-one>
|
||||
<vn-icon-button
|
||||
vn-none
|
||||
vn-bind="+"
|
||||
vn-tooltip="Add tag"
|
||||
icon="add_circle"
|
||||
ng-click="filter.tags.push({})">
|
||||
</vn-icon-button>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal ng-repeat="itemTag in filter.tags">
|
||||
<vn-autocomplete vn-two vn-id="tag"
|
||||
label="Tag"
|
||||
initial-data="itemTag.tag"
|
||||
ng-model="itemTag.tagFk"
|
||||
data="tags"
|
||||
show-field="name"
|
||||
on-change="itemTag.value = null"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-textfield vn-three
|
||||
ng-show="tag.selection.isFree || tag.selection.isFree == undefined"
|
||||
vn-id="text"
|
||||
label="Value"
|
||||
ng-model="itemTag.value"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-three
|
||||
ng-show="tag.selection.isFree === false"
|
||||
url="{{'Tags/' + itemTag.tagFk + '/filterValue'}}"
|
||||
search-function="{value: $search}"
|
||||
label="Value"
|
||||
ng-model="itemTag.value"
|
||||
show-field="value"
|
||||
value-field="value"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-icon-button
|
||||
vn-none
|
||||
vn-tooltip="Remove tag"
|
||||
icon="delete"
|
||||
ng-click="filter.tags.splice($index, 1)"
|
||||
tabindex="-1">
|
||||
</vn-icon-button>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-mt-lg">
|
||||
<vn-submit label="Search"></vn-submit>
|
||||
</vn-horizontal>
|
||||
</form>
|
||||
</div>
|
|
@ -0,0 +1,19 @@
|
|||
import ngModule from '../module';
|
||||
import SearchPanel from 'core/components/searchbar/search-panel';
|
||||
|
||||
class Controller extends SearchPanel {
|
||||
get filter() {
|
||||
return this.$.filter;
|
||||
}
|
||||
|
||||
set filter(value = {}) {
|
||||
if (!value.tags) value.tags = [{}];
|
||||
|
||||
this.$.filter = value;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnFixedPriceSearchPanel', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
Started: Inicio
|
||||
Ended: Fin
|
||||
Minimum price: Precio mínimo
|
||||
Item ID: ID Artículo
|
|
@ -0,0 +1,162 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="FixedPrices/filter"
|
||||
limit="20"
|
||||
data="$ctrl.prices"
|
||||
auto-load="true"
|
||||
order="itemFk">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="Warehouses"
|
||||
data="warehouses"
|
||||
order="name">
|
||||
</vn-crud-model>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.prices">
|
||||
</vn-watcher>
|
||||
<vn-portal slot="topbar">
|
||||
<vn-searchbar
|
||||
auto-state="false"
|
||||
panel="vn-fixed-price-search-panel"
|
||||
info="Search prices by item ID or code"
|
||||
filter="{}"
|
||||
model="model">
|
||||
</vn-searchbar>
|
||||
</vn-portal>
|
||||
<div class="vn-w-xl">
|
||||
<vn-card>
|
||||
<vn-table model="model">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th field="itemFk">Item ID</vn-th>
|
||||
<vn-th field="itemFk">Item</vn-th>
|
||||
<vn-th field="warehouseFk">Warehouse</vn-th>
|
||||
<vn-th field="rate2">P.P.U.</vn-th>
|
||||
<vn-th field="rate3">P.P.P.</vn-th>
|
||||
<vn-th field="minPrice">Min price</vn-th>
|
||||
<vn-th field="started" style="width: 90px">Started</vn-th>
|
||||
<vn-th field="ended" style="width: 90px">Ended</vn-th>
|
||||
<vn-th shrink></vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="price in $ctrl.prices">
|
||||
<vn-td>
|
||||
<span
|
||||
ng-if="price.itemFk"
|
||||
ng-click="itemDescriptor.show($event, price.itemFk)"
|
||||
class="link">
|
||||
{{price.itemFk}}
|
||||
</span>
|
||||
<vn-autocomplete
|
||||
class="dense"
|
||||
ng-if="!price.itemFk"
|
||||
vn-focus
|
||||
url="Items"
|
||||
ng-model="price.itemFk"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
search-function="$ctrl.itemSearchFunc($search)"
|
||||
on-change="$ctrl.upsertPrice(price)"
|
||||
order="id DESC"
|
||||
tabindex="1">
|
||||
<tpl-item>
|
||||
{{::id}} - {{::name}}
|
||||
</tpl-item>
|
||||
</vn-autocomplete>
|
||||
</vn-td>
|
||||
<vn-td expand>
|
||||
<text>
|
||||
<vn-fetched-tags
|
||||
max-length="6"
|
||||
item="price"
|
||||
name="price.name"
|
||||
sub-name="price.subName"
|
||||
tabindex="-1">
|
||||
</vn-fetched-tags>
|
||||
</text>
|
||||
</vn-td>
|
||||
<vn-td>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
label="Warehouse"
|
||||
ng-model="price.warehouseFk"
|
||||
url="Warehouses"
|
||||
on-change="$ctrl.upsertPrice(price)"
|
||||
tabindex="2">
|
||||
</vn-autocomplete>
|
||||
</vn-td>
|
||||
<vn-td-editable number>
|
||||
<text>{{price.rate2 | currency: 'EUR':2}}</text>
|
||||
<field>
|
||||
<vn-input-number
|
||||
class="dense"
|
||||
vn-focus
|
||||
ng-model="price.rate2"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-input-number>
|
||||
</field>
|
||||
</vn-td-editable>
|
||||
<vn-td-editable number>
|
||||
<text>{{price.rate3 | currency: 'EUR':2}}</text>
|
||||
<field>
|
||||
<vn-input-number
|
||||
class="dense"
|
||||
vn-focus
|
||||
ng-model="price.rate3"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-input-number>
|
||||
</field>
|
||||
</vn-td-editable>
|
||||
<vn-td-editable number>
|
||||
<text>{{(price.hasMinPrice ? (price.minPrice | currency: 'EUR':2) : "-")}}</text>
|
||||
<field>
|
||||
<vn-input-number
|
||||
class="dense"
|
||||
vn-focus
|
||||
ng-model="price.minPrice"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-input-number>
|
||||
</field>
|
||||
</vn-td-editable>
|
||||
<vn-td>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="Started"
|
||||
ng-model="price.started"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
</vn-td>
|
||||
<vn-td>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="Ended"
|
||||
ng-model="price.ended"
|
||||
on-change="$ctrl.upsertPrice(price)">
|
||||
</vn-date-picker>
|
||||
</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-icon-button
|
||||
icon="delete"
|
||||
vn-tooltip="Delete"
|
||||
ng-click="$ctrl.removePrice($index)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
<div class="vn-pa-md">
|
||||
<vn-icon-button
|
||||
vn-tooltip="Add fixed price"
|
||||
icon="add_circle"
|
||||
vn-bind="+"
|
||||
ng-click="model.insert()">
|
||||
</vn-icon-button>
|
||||
</div>
|
||||
</vn-card>
|
||||
</div>
|
||||
<vn-item-descriptor-popover
|
||||
vn-id="itemDescriptor">
|
||||
</vn-item-descriptor-popover>
|
|
@ -0,0 +1,48 @@
|
|||
import ngModule from '../module';
|
||||
import Section from 'salix/components/section';
|
||||
import './style.scss';
|
||||
|
||||
export default class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new instance
|
||||
*/
|
||||
add() {
|
||||
this.$.model.insert({});
|
||||
}
|
||||
|
||||
upsertPrice(price) {
|
||||
price.hasMinPrice = price.minPrice ? true : false;
|
||||
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
||||
|
||||
for (let field of requiredFields)
|
||||
if (price[field] == undefined) return;
|
||||
|
||||
const query = 'FixedPrices/upsertFixedPrice';
|
||||
this.$http.patch(query, price)
|
||||
.then(res => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
Object.assign(price, res.data);
|
||||
});
|
||||
}
|
||||
|
||||
removePrice($index) {
|
||||
const price = this.$.model.data[$index];
|
||||
if (price.id) {
|
||||
this.$http.delete(`FixedPrices/${price.id}`)
|
||||
.then(() => {
|
||||
this.$.model.remove($index);
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
});
|
||||
} else
|
||||
this.$.model.remove($index);
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnFixedPrice', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
Fixed prices: Precios fijados
|
|
@ -0,0 +1,5 @@
|
|||
@import "variables";
|
||||
|
||||
vn-date-picker {
|
||||
max-width: 90px;
|
||||
}
|
|
@ -21,4 +21,6 @@ import './botanical';
|
|||
import './barcode';
|
||||
import './summary';
|
||||
import './waste';
|
||||
import './fixed-price';
|
||||
import './fixed-price-search-panel';
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
"main": [
|
||||
{"state": "item.index", "icon": "icon-item"},
|
||||
{"state": "item.request", "icon": "pan_tool"},
|
||||
{"state": "item.waste", "icon": "icon-claims"}
|
||||
{"state": "item.waste", "icon": "icon-claims"},
|
||||
{"state": "item.fixedPrice", "icon": "icon-invoices"}
|
||||
],
|
||||
"card": [
|
||||
{"state": "item.card.basicData", "icon": "settings"},
|
||||
|
@ -32,22 +33,26 @@
|
|||
"abstract": true,
|
||||
"description": "Items",
|
||||
"component": "vn-items"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url": "/index?q",
|
||||
"state": "item.index",
|
||||
"component": "vn-item-index",
|
||||
"description": "Items"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url": "/create",
|
||||
"state": "item.create",
|
||||
"component": "vn-item-create",
|
||||
"description": "New item"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url": "/:id",
|
||||
"state": "item.card",
|
||||
"abstract": true,
|
||||
"component": "vn-item-card"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/basic-data",
|
||||
"state": "item.card.basicData",
|
||||
"component": "vn-item-basic-data",
|
||||
|
@ -56,7 +61,8 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["buyer"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/tags",
|
||||
"state": "item.card.tags",
|
||||
"component": "vn-item-tags",
|
||||
|
@ -65,13 +71,15 @@
|
|||
"item-tags": "$ctrl.itemTags"
|
||||
},
|
||||
"acl": ["buyer", "replenisher"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/tax",
|
||||
"state": "item.card.tax",
|
||||
"component": "vn-item-tax",
|
||||
"description": "Tax",
|
||||
"acl": ["administrative","buyer"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/niche",
|
||||
"state": "item.card.niche",
|
||||
"component": "vn-item-niche",
|
||||
|
@ -80,7 +88,8 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["buyer","replenisher"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/botanical",
|
||||
"state": "item.card.botanical",
|
||||
"component": "vn-item-botanical",
|
||||
|
@ -89,7 +98,8 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["buyer"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/barcode",
|
||||
"state": "item.card.itemBarcode",
|
||||
"component": "vn-item-barcode",
|
||||
|
@ -98,7 +108,8 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["buyer","replenisher"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/summary",
|
||||
"state": "item.card.summary",
|
||||
"component": "vn-item-summary",
|
||||
|
@ -106,7 +117,8 @@
|
|||
"params": {
|
||||
"item": "$ctrl.item"
|
||||
}
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/diary?warehouseFk&lineFk",
|
||||
"state": "item.card.diary",
|
||||
"component": "vn-item-diary",
|
||||
|
@ -115,7 +127,8 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["employee"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/last-entries",
|
||||
"state": "item.card.last-entries",
|
||||
"component": "vn-item-last-entries",
|
||||
|
@ -124,12 +137,14 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["employee"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/log",
|
||||
"state": "item.card.log",
|
||||
"component": "vn-item-log",
|
||||
"description": "Log"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/request?q",
|
||||
"state": "item.request",
|
||||
"component": "vn-item-request",
|
||||
|
@ -138,12 +153,20 @@
|
|||
"item": "$ctrl.item"
|
||||
},
|
||||
"acl": ["employee"]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"url" : "/waste",
|
||||
"state": "item.waste",
|
||||
"component": "vn-item-waste",
|
||||
"description": "Waste breakdown",
|
||||
"acl": ["buyer"]
|
||||
},
|
||||
{
|
||||
"url" : "/fixed-price",
|
||||
"state": "item.fixedPrice",
|
||||
"component": "vn-fixed-price",
|
||||
"description": "Fixed prices",
|
||||
"acl": ["buyer"]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue