Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2787-change_css_date_time
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
7c34555afd
|
@ -2178,6 +2178,15 @@ INSERT INTO `hedera`.`imageCollectionSize`(`id`, `collectionFk`,`width`, `height
|
|||
VALUES
|
||||
(1, 4, 160, 160);
|
||||
|
||||
INSERT INTO `vn`.`rateConfig`(`rate0`, `rate1`, `rate2`, `rate3`)
|
||||
VALUES
|
||||
(36, 31, 25, 21);
|
||||
|
||||
INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate3`)
|
||||
VALUES
|
||||
(DATE_ADD(CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25),
|
||||
(CURDATE(), 1, 12, 17, 22, 27);
|
||||
|
||||
INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk)
|
||||
VALUES
|
||||
(1, '07546501420', 67, 671, CURDATE(), 1761, 1, 1),
|
||||
|
@ -2243,3 +2252,8 @@ INSERT INTO `vn`.`duaInvoiceIn`(`id`, `duaFk`, `invoiceInFk`)
|
|||
(8, 8, 8),
|
||||
(9, 9, 9),
|
||||
(10, 10, 10);
|
||||
|
||||
INSERT INTO `vn`.`ticketRecalc`(`ticketFk`)
|
||||
SELECT `id` FROM `vn`.`ticket`;
|
||||
|
||||
CALL `vn`.`ticket_doRecalc`();
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
"invoices": [
|
||||
{
|
||||
"tx_company": "TESSAROSES S.A.",
|
||||
"id_invoice": "20062926",
|
||||
"id_purchaseorder": "20106319",
|
||||
"tx_customer_ref": "",
|
||||
"id_customer": "56116",
|
||||
"id_customer_floricode": "",
|
||||
"nm_bill": "VERDNATURA LEVANTE SL",
|
||||
"nm_ship": "VERDNATURA LEVANTE SL",
|
||||
"nm_cargo": "OYAMBARILLO",
|
||||
"dt_purchaseorder": "06/19/2020",
|
||||
"dt_fly": "06/20/2020",
|
||||
"dt_invoice": "06/19/2020",
|
||||
"nm_incoterm": "FOB UIO",
|
||||
"tx_awb": "729-6340 2846",
|
||||
"tx_hawb": "LA0061832844",
|
||||
"tx_oe": "05520204000335992",
|
||||
"nu_totalstemsPO": "850",
|
||||
"mny_flower": "272.5000",
|
||||
"mny_freight": "0.0000",
|
||||
"mny_total": "272.5000",
|
||||
"nu_boxes": "4",
|
||||
"nu_fulls": "1.75",
|
||||
"dt_posted": "2020-06-19T13:31:41",
|
||||
"boxes": [
|
||||
{
|
||||
"id_box": "200573095",
|
||||
"nm_box": "HB",
|
||||
"tp_box": "HB",
|
||||
"tx_label": "",
|
||||
"nu_length": "96",
|
||||
"nu_width": "32",
|
||||
"nu_height": "30.5",
|
||||
"products": [
|
||||
{
|
||||
"id_floricode": "27887",
|
||||
"id_migros_variety": "",
|
||||
"nm_product": "FREEDOM 60CM 25ST",
|
||||
"nm_species": "ROSES",
|
||||
"nm_variety": "FREEDOM",
|
||||
"nu_length": "60",
|
||||
"nu_stems_bunch": "25",
|
||||
"nu_bunches": "10",
|
||||
"mny_rate_stem": "0.3500",
|
||||
"mny_freight_unit": "0.0000",
|
||||
"barcodes": "202727621,202725344,202725345,202725571,202725730,202725731,202725732,202725925,202726131,202726685"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id_box": "200573106",
|
||||
"nm_box": "HB",
|
||||
"tp_box": "HB",
|
||||
"tx_label": "",
|
||||
"nu_length": "96",
|
||||
"nu_width": "32",
|
||||
"nu_height": "30.5",
|
||||
"products": [
|
||||
{
|
||||
"id_floricode": "27887",
|
||||
"id_migros_variety": "",
|
||||
"nm_product": "FREEDOM 70CM 25ST",
|
||||
"nm_species": "ROSES",
|
||||
"nm_variety": "FREEDOM",
|
||||
"nu_length": "70",
|
||||
"nu_stems_bunch": "25",
|
||||
"nu_bunches": "8",
|
||||
"mny_rate_stem": "0.4000",
|
||||
"mny_freight_unit": "0.0000",
|
||||
"barcodes": "202727077,202727078,202727079,202727080,202727650,202727654,202727656,202727657"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id_box": "200573117",
|
||||
"nm_box": "HB",
|
||||
"tp_box": "HB",
|
||||
"tx_label": "",
|
||||
"nu_length": "96",
|
||||
"nu_width": "32",
|
||||
"nu_height": "30.5",
|
||||
"products": [
|
||||
{
|
||||
"id_floricode": "28409",
|
||||
"id_migros_variety": "",
|
||||
"nm_product": "TIBET 40CM 25ST",
|
||||
"nm_species": "ROSES",
|
||||
"nm_variety": "TIBET",
|
||||
"nu_length": "40",
|
||||
"nu_stems_bunch": "25",
|
||||
"nu_bunches": "12",
|
||||
"mny_rate_stem": "0.2500",
|
||||
"mny_freight_unit": "0.0000",
|
||||
"barcodes": "202723350,202723351,202723352,202723353,202723354,202723355,202723356,202723357,202726690,202726745,202726813,202726814"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id_box": "200573506",
|
||||
"nm_box": "QB 2",
|
||||
"tp_box": "QB",
|
||||
"tx_label": "",
|
||||
"nu_length": "80",
|
||||
"nu_width": "30",
|
||||
"nu_height": "17.5",
|
||||
"products": [
|
||||
{
|
||||
"id_floricode": "27887",
|
||||
"id_migros_variety": "",
|
||||
"nm_product": "FREEDOM 50CM 25ST",
|
||||
"nm_species": "ROSES",
|
||||
"nm_variety": "FREEDOM",
|
||||
"nu_length": "50",
|
||||
"nu_stems_bunch": "25",
|
||||
"nu_bunches": "4",
|
||||
"mny_rate_stem": "0.3000",
|
||||
"mny_freight_unit": "0.0000",
|
||||
"barcodes": "202727837,202727839,202727842,202726682"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
@ -1015,6 +1015,17 @@ export default {
|
|||
travelsQuicklink: 'vn-entry-descriptor vn-quick-link[icon="local_airport"] > a',
|
||||
entriesQuicklink: 'vn-entry-descriptor vn-quick-link[icon="icon-entry"] > a'
|
||||
},
|
||||
entryBuys: {
|
||||
importButton: 'vn-entry-buy-index vn-icon[icon="publish"]',
|
||||
ref: 'vn-entry-buy-import vn-textfield[ng-model="$ctrl.import.ref"]',
|
||||
observation: 'vn-entry-buy-import vn-textarea[ng-model="$ctrl.import.observation"]',
|
||||
file: 'vn-entry-buy-import vn-input-file[ng-model="$ctrl.import.file"]',
|
||||
firstImportedItem: 'vn-entry-buy-import tbody:nth-child(2) vn-autocomplete[ng-model="buy.itemFk"]',
|
||||
secondImportedItem: 'vn-entry-buy-import tbody:nth-child(3) vn-autocomplete[ng-model="buy.itemFk"]',
|
||||
thirdImportedItem: 'vn-entry-buy-import tbody:nth-child(4) vn-autocomplete[ng-model="buy.itemFk"]',
|
||||
fourthImportedItem: 'vn-entry-buy-import tbody:nth-child(5) vn-autocomplete[ng-model="buy.itemFk"]',
|
||||
importBuysButton: 'vn-entry-buy-import button[type="submit"]'
|
||||
},
|
||||
entryLatestBuys: {
|
||||
firstBuy: 'vn-entry-latest-buys vn-tbody > a:nth-child(1)',
|
||||
allBuysCheckBox: 'vn-entry-latest-buys vn-thead vn-check',
|
||||
|
|
|
@ -38,7 +38,7 @@ describe('Travel thermograph path', () => {
|
|||
|
||||
it('should select the file to upload', async() => {
|
||||
let currentDir = process.cwd();
|
||||
let filePath = `${currentDir}/storage/dms/ecc/3.jpeg`;
|
||||
let filePath = `${currentDir}/e2e/assets/thermograph.jpeg`;
|
||||
|
||||
const [fileChooser] = await Promise.all([
|
||||
page.waitForFileChooser(),
|
||||
|
|
|
@ -41,6 +41,6 @@ describe('Entry lastest buys path', () => {
|
|||
|
||||
it('should navigate to the entry.buy section by clicking one of the buys', async() => {
|
||||
await page.waitToClick(selectors.entryLatestBuys.firstBuy);
|
||||
await page.waitForState('entry.card.buy');
|
||||
await page.waitForState('entry.card.buy.index');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
import selectors from '../../helpers/selectors.js';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('Entry import buys path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('buyer', 'entry');
|
||||
await page.accessToSearchResult('1');
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
it('should count the summary buys and find there only one at this point', async() => {
|
||||
const buysCount = await page.countElement(selectors.entrySummary.anyBuyLine);
|
||||
|
||||
expect(buysCount).toEqual(1);
|
||||
});
|
||||
|
||||
it('should navigate to the buy section and then click the import button opening the import form', async() => {
|
||||
await page.accessToSection('entry.card.buy.index');
|
||||
await page.waitToClick(selectors.entryBuys.importButton);
|
||||
await page.waitForState('entry.card.buy.import');
|
||||
});
|
||||
|
||||
it('should fill the form, import the designated JSON file and select items for each import and confirm import', async() => {
|
||||
await page.write(selectors.entryBuys.ref, 'a reference');
|
||||
await page.write(selectors.entryBuys.observation, 'an observation');
|
||||
|
||||
let currentDir = process.cwd();
|
||||
let filePath = `${currentDir}/e2e/assets/07_import_buys.json`;
|
||||
|
||||
const [fileChooser] = await Promise.all([
|
||||
page.waitForFileChooser(),
|
||||
page.waitToClick(selectors.entryBuys.file)
|
||||
]);
|
||||
await fileChooser.accept([filePath]);
|
||||
|
||||
await page.autocompleteSearch(selectors.entryBuys.firstImportedItem, 'Ranged Reinforced weapon pistol 9mm');
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondImportedItem, 'Melee Reinforced weapon heavy shield 1x0.5m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.thirdImportedItem, 'Container medical box 1m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.fourthImportedItem, 'Container ammo box 1m');
|
||||
|
||||
await page.waitToClick(selectors.entryBuys.importBuysButton);
|
||||
|
||||
const message = await page.waitForSnackbar();
|
||||
const state = await page.getState();
|
||||
|
||||
expect(message.text).toContain('Data saved!');
|
||||
expect(state).toBe('entry.card.buy.index');
|
||||
});
|
||||
|
||||
it('should navigate to the entry summary and count the buys to find 4 buys have been added', async() => {
|
||||
await page.waitToClick('vn-icon[icon="preview"]');
|
||||
await page.waitForNumberOfElements(selectors.entrySummary.anyBuyLine, 5);
|
||||
});
|
||||
});
|
|
@ -20,7 +20,8 @@ export default class Field extends FormInput {
|
|||
super.$onInit();
|
||||
|
||||
if (this.info) this.classList.add('has-icons');
|
||||
this.input.addEventListener('change', () => this.onChange());
|
||||
this.input.addEventListener('change', event =>
|
||||
this.onChange(event));
|
||||
}
|
||||
|
||||
set field(value) {
|
||||
|
@ -82,6 +83,9 @@ export default class Field extends FormInput {
|
|||
this._required = value;
|
||||
let required = this.element.querySelector('.required');
|
||||
display(required, this._required);
|
||||
|
||||
this.$.$applyAsync(() =>
|
||||
this.input.setAttribute('required', value));
|
||||
}
|
||||
|
||||
get required() {
|
||||
|
@ -186,10 +190,13 @@ export default class Field extends FormInput {
|
|||
this.refreshHint();
|
||||
}
|
||||
|
||||
onChange() {
|
||||
onChange($event) {
|
||||
// Changes doesn't reflect until appling async
|
||||
this.$.$applyAsync(() => {
|
||||
this.emit('change', {value: this.field});
|
||||
this.emit('change', {
|
||||
value: this.field,
|
||||
$event: $event
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,12 +71,23 @@ export default class InputFile extends Field {
|
|||
this.input.click();
|
||||
}
|
||||
|
||||
onChange() {
|
||||
onChange($event) {
|
||||
this.emit('change', {
|
||||
value: this.field,
|
||||
$files: this.files
|
||||
$files: this.files,
|
||||
$event: $event
|
||||
});
|
||||
}
|
||||
|
||||
get accept() {
|
||||
return this._accept;
|
||||
}
|
||||
|
||||
set accept(value) {
|
||||
this._accept = value;
|
||||
this.$.$applyAsync(() =>
|
||||
this.input.setAttribute('accept', value));
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnInputFile', {
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('importBuys', {
|
||||
description: 'Imports the buys from a list',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'options',
|
||||
type: 'object',
|
||||
description: 'Callback options',
|
||||
},
|
||||
{
|
||||
arg: 'ref',
|
||||
type: 'string',
|
||||
description: 'The buyed boxes ids',
|
||||
},
|
||||
{
|
||||
arg: 'observation',
|
||||
type: 'string',
|
||||
description: 'The observation',
|
||||
},
|
||||
{
|
||||
arg: 'buys',
|
||||
type: ['Object'],
|
||||
description: 'The buys',
|
||||
}],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/importBuys`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.importBuys = async(ctx, id, options = {}) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
const models = Self.app.models;
|
||||
|
||||
let tx;
|
||||
if (!options.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
options.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const entry = await models.Entry.findById(id, null, options);
|
||||
await entry.updateAttributes({
|
||||
observation: args.observation,
|
||||
ref: args.ref
|
||||
}, options);
|
||||
|
||||
const buys = [];
|
||||
for (let buy of args.buys) {
|
||||
buys.push({
|
||||
entryFk: entry.id,
|
||||
itemFk: buy.itemFk,
|
||||
stickers: 1,
|
||||
quantity: 1,
|
||||
packing: buy.packing,
|
||||
grouping: buy.grouping,
|
||||
buyingValue: buy.buyingValue,
|
||||
packageFk: buy.packageFk
|
||||
});
|
||||
}
|
||||
|
||||
const createdBuys = await models.Buy.create(buys, options);
|
||||
const buyIds = createdBuys.map(buy => buy.id);
|
||||
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc');
|
||||
stmt = new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.buyRecalc
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT ? AS id`, [buyIds]);
|
||||
|
||||
stmts.push(stmt);
|
||||
stmts.push('CALL buy_recalcPrices()');
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
await conn.executeStmt(sql, options);
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('importBuysPreview', {
|
||||
description: 'Calculates the preview buys for an entry import',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'buys',
|
||||
type: ['Object'],
|
||||
description: 'The buys',
|
||||
}],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/importBuysPreview`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.importBuysPreview = async(id, buys) => {
|
||||
const models = Self.app.models;
|
||||
for (let buy of buys) {
|
||||
const packaging = await models.Packaging.findOne({
|
||||
fields: ['id'],
|
||||
where: {volume: {gte: buy.volume}},
|
||||
order: 'volume ASC'
|
||||
});
|
||||
buy.packageFk = packaging.id;
|
||||
}
|
||||
|
||||
return buys;
|
||||
};
|
||||
};
|
|
@ -37,11 +37,11 @@ module.exports = Self => {
|
|||
}, {
|
||||
arg: 'active',
|
||||
type: 'Boolean',
|
||||
description: 'Whether the the item is or not active',
|
||||
description: 'Whether the item is or not active',
|
||||
}, {
|
||||
arg: 'visible',
|
||||
type: 'Boolean',
|
||||
description: 'Whether the the item is or not visible',
|
||||
description: 'Whether the item is or not visible',
|
||||
}, {
|
||||
arg: 'typeFk',
|
||||
type: 'Integer',
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('entry import()', () => {
|
||||
let newEntry;
|
||||
const buyerId = 35;
|
||||
const companyId = 442;
|
||||
const travelId = 1;
|
||||
const supplierId = 1;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: buyerId},
|
||||
};
|
||||
|
||||
beforeAll(async done => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should import the buy rows', async() => {
|
||||
const expectedRef = '1, 2';
|
||||
const expectedObservation = '123456';
|
||||
const ctx = {
|
||||
req: activeCtx,
|
||||
args: {
|
||||
observation: expectedObservation,
|
||||
ref: expectedRef,
|
||||
buys: [
|
||||
{
|
||||
itemFk: 1,
|
||||
buyingValue: 5.77,
|
||||
description: 'Bow',
|
||||
grouping: 1,
|
||||
packing: 1,
|
||||
size: 1,
|
||||
volume: 1200,
|
||||
packageFk: '94'
|
||||
},
|
||||
{
|
||||
itemFk: 4,
|
||||
buyingValue: 2.16,
|
||||
description: 'Arrow',
|
||||
grouping: 1,
|
||||
packing: 1,
|
||||
size: 25,
|
||||
volume: 1125,
|
||||
packageFk: '94'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
const tx = await app.models.Entry.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
newEntry = await app.models.Entry.create({
|
||||
dated: new Date(),
|
||||
supplierFk: supplierId,
|
||||
travelFk: travelId,
|
||||
companyFk: companyId,
|
||||
observation: 'The entry',
|
||||
ref: 'Entry ref'
|
||||
}, options);
|
||||
|
||||
await app.models.Entry.importBuys(ctx, newEntry.id, options);
|
||||
|
||||
const updatedEntry = await app.models.Entry.findById(newEntry.id, null, options);
|
||||
const entryBuys = await app.models.Buy.find({
|
||||
where: {entryFk: newEntry.id}
|
||||
}, options);
|
||||
|
||||
expect(updatedEntry.observation).toEqual(expectedObservation);
|
||||
expect(updatedEntry.ref).toEqual(expectedRef);
|
||||
expect(entryBuys.length).toEqual(2);
|
||||
|
||||
// Restores
|
||||
await tx.rollback();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('entry importBuysPreview()', () => {
|
||||
const entryId = 1;
|
||||
beforeAll(async done => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return the buys with the calculated packageFk', async() => {
|
||||
const expectedPackageFk = '3';
|
||||
const buys = [
|
||||
{
|
||||
itemFk: 1,
|
||||
buyingValue: 5.77,
|
||||
description: 'Bow',
|
||||
grouping: 1,
|
||||
size: 1,
|
||||
volume: 1200
|
||||
},
|
||||
{
|
||||
itemFk: 4,
|
||||
buyingValue: 2.16,
|
||||
description: 'Arrow',
|
||||
grouping: 1,
|
||||
size: 25,
|
||||
volume: 1125
|
||||
}
|
||||
];
|
||||
|
||||
const result = await app.models.Entry.importBuysPreview(entryId, buys);
|
||||
const randomIndex = Math.floor(Math.random() * result.length);
|
||||
const buy = result[randomIndex];
|
||||
|
||||
expect(buy.packageFk).toEqual(expectedPackageFk);
|
||||
});
|
||||
});
|
|
@ -2,4 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/entry/filter')(Self);
|
||||
require('../methods/entry/getEntry')(Self);
|
||||
require('../methods/entry/getBuys')(Self);
|
||||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"notes": {
|
||||
"type": "String"
|
||||
"type": "string"
|
||||
},
|
||||
"isConfirmed": {
|
||||
"type": "boolean"
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
<mg-ajax path="dms/upload" options="vnPost"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.dms">
|
||||
</vn-watcher>
|
||||
<form
|
||||
name="form"
|
||||
ng-submit="$ctrl.onSubmit()"
|
||||
class="vn-ma-md">
|
||||
<div class="vn-w-lg">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-horizontal>
|
||||
<vn-textfield vn-focus
|
||||
vn-one
|
||||
label="Reference"
|
||||
ng-model="$ctrl.import.ref">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textarea
|
||||
vn-one
|
||||
label="Observation"
|
||||
ng-model="$ctrl.import.observation">
|
||||
</vn-textarea>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-input-file
|
||||
vn-one
|
||||
label="File"
|
||||
ng-model="$ctrl.import.file"
|
||||
on-change="$ctrl.onFileChange($event)"
|
||||
accept="application/json"
|
||||
required="true">
|
||||
<append>
|
||||
<vn-icon vn-none
|
||||
color-marginal
|
||||
title="{{'JSON files only' | translate}}"
|
||||
icon="info">
|
||||
</vn-icon>
|
||||
</append>
|
||||
</vn-input-file>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal ng-show="$ctrl.import.buys.length > 0">
|
||||
<table class="vn-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th translate>Item</th>
|
||||
<th translate expand>Description</th>
|
||||
<th translate center>Size</th>
|
||||
<th translate center>Packing</th>
|
||||
<th translate center>Grouping</th>
|
||||
<th translate center>Buying value</th>
|
||||
<th translate center>Box</th>
|
||||
<th translate center>Volume</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody ng-repeat="buy in $ctrl.import.buys">
|
||||
<tr>
|
||||
<td title="{{::buy.itemFk}}">
|
||||
<vn-autocomplete
|
||||
class="dense"
|
||||
vn-focus
|
||||
url="Items"
|
||||
ng-model="buy.itemFk"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
search-function="$ctrl.itemSearchFunc($search)"
|
||||
order="id DESC"
|
||||
tabindex="1">
|
||||
<tpl-item>
|
||||
{{::id}} - {{::name}}
|
||||
</tpl-item>
|
||||
</vn-autocomplete>
|
||||
</td>
|
||||
<td title="{{::buy.description}}" expand>{{::buy.description | dashIfEmpty}}</td>
|
||||
<td center title="{{::buy.size}}">{{::buy.size | dashIfEmpty}}</td>
|
||||
<td center>
|
||||
<vn-chip>
|
||||
<span>{{::buy.packing | dashIfEmpty}}</span>
|
||||
</vn-chip>
|
||||
</td>
|
||||
<td center>
|
||||
<vn-chip>
|
||||
<span>{{::buy.grouping | dashIfEmpty}}</span>
|
||||
</vn-chip>
|
||||
</vn-td>
|
||||
<td>{{::buy.buyingValue | currency: 'EUR':2}}</td>
|
||||
<td center title="{{::buy.packageFk | dashIfEmpty}}">
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
url="Packagings"
|
||||
show-field="id"
|
||||
value-field="id"
|
||||
where="{isBox: true}"
|
||||
ng-model="buy.packageFk">
|
||||
</vn-autocomplete>
|
||||
</td>
|
||||
<td center title="{{::buy.volume}}">{{::buy.volume | number}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</vn-horizontal>
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit
|
||||
label="Import buys">
|
||||
</vn-submit>
|
||||
<vn-button
|
||||
class="cancel"
|
||||
label="Cancel"
|
||||
ui-sref="entry.card.buy.index">
|
||||
</vn-button>
|
||||
</vn-button>
|
||||
</vn-button-bar>
|
||||
</div>
|
||||
</form>
|
|
@ -0,0 +1,99 @@
|
|||
import ngModule from '../../module';
|
||||
import Section from 'salix/components/section';
|
||||
import './style.scss';
|
||||
|
||||
class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.import = {
|
||||
file: '',
|
||||
invoice: null,
|
||||
buys: []
|
||||
};
|
||||
}
|
||||
|
||||
onFileChange($event) {
|
||||
const input = $event.target;
|
||||
const file = input.files[0];
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = event =>
|
||||
this.fillData(event.target.result);
|
||||
reader.readAsText(file, 'UTF-8');
|
||||
}
|
||||
|
||||
fillData(raw) {
|
||||
const data = JSON.parse(raw);
|
||||
const [invoice] = data.invoices;
|
||||
|
||||
this.$.$applyAsync(() => {
|
||||
this.import.observation = invoice.tx_awb;
|
||||
|
||||
const boxes = invoice.boxes;
|
||||
const buys = [];
|
||||
for (let box of boxes) {
|
||||
const boxVolume = box.nu_length * box.nu_width * box.nu_height;
|
||||
for (let product of box.products) {
|
||||
const packing = product.nu_stems_bunch * product.nu_bunches;
|
||||
buys.push({
|
||||
description: product.nm_product,
|
||||
size: product.nu_length,
|
||||
packing: packing,
|
||||
grouping: product.nu_stems_bunch,
|
||||
buyingValue: parseFloat(product.mny_rate_stem),
|
||||
volume: boxVolume
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const boxesId = boxes.map(box => box.id_box);
|
||||
this.import.ref = boxesId.join(', ');
|
||||
|
||||
this.fetchBuys(buys);
|
||||
});
|
||||
}
|
||||
|
||||
fetchBuys(buys) {
|
||||
const params = {buys};
|
||||
const query = `Entries/${this.entry.id}/importBuysPreview`;
|
||||
this.$http.get(query, {params}).then(res => {
|
||||
this.import.buys = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
try {
|
||||
const params = this.import;
|
||||
const hasAnyEmptyRow = params.buys.some(buy => {
|
||||
return buy.itemFk == null;
|
||||
});
|
||||
|
||||
if (hasAnyEmptyRow)
|
||||
throw new Error(`Some of the imported buys doesn't have an item`);
|
||||
|
||||
const query = `Entries/${this.entry.id}/importBuys`;
|
||||
return this.$http.post(query, params)
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||
.then(() => this.$state.go('entry.card.buy.index'));
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
itemSearchFunc($search) {
|
||||
return /^\d+$/.test($search)
|
||||
? {id: $search}
|
||||
: {name: {like: '%' + $search + '%'}};
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope'];
|
||||
|
||||
ngModule.vnComponent('vnEntryBuyImport', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
worker: '<'
|
||||
}
|
||||
});
|
|
@ -0,0 +1,145 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Entry', () => {
|
||||
describe('Component vnEntryBuyImport', () => {
|
||||
let controller;
|
||||
let $httpParamSerializer;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(ngModule('entry'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
let $element = $compile('<vn-entry-buy-import-buys></vn-entry-latest-buys')($rootScope);
|
||||
controller = $componentController('vnEntryBuyImport', {$element});
|
||||
controller.entry = {
|
||||
id: 1
|
||||
};
|
||||
}));
|
||||
|
||||
describe('fillData()', () => {
|
||||
it(`should call to the fillData() method`, () => {
|
||||
controller.fetchBuys = jest.fn();
|
||||
|
||||
const rawData = `{
|
||||
"invoices": [
|
||||
{
|
||||
"tx_awb": "123456",
|
||||
"boxes": [
|
||||
{
|
||||
"id_box": 1,
|
||||
"nu_length": 1,
|
||||
"nu_width": 15,
|
||||
"nu_height": 80,
|
||||
"products": [
|
||||
{
|
||||
"nm_product": "Bow",
|
||||
"nu_length": 1,
|
||||
"nu_stems_bunch": 1,
|
||||
"nu_bunches": 1,
|
||||
"mny_rate_stem": 5.77
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"id_box": 2,
|
||||
"nu_length": 25,
|
||||
"nu_width": 1,
|
||||
"nu_height": 45,
|
||||
"products": [
|
||||
{
|
||||
"nm_product": "Arrow",
|
||||
"nu_length": 25,
|
||||
"nu_stems_bunch": 1,
|
||||
"nu_bunches": 1,
|
||||
"mny_rate_stem": 2.16
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]}`;
|
||||
const expectedBuys = [
|
||||
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
|
||||
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
|
||||
];
|
||||
controller.fillData(rawData);
|
||||
controller.$.$apply();
|
||||
|
||||
const importData = controller.import;
|
||||
|
||||
expect(importData.observation).toEqual('123456');
|
||||
expect(importData.ref).toEqual('1, 2');
|
||||
|
||||
expect(controller.fetchBuys).toHaveBeenCalledWith(expectedBuys);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchBuys()', () => {
|
||||
it(`should perform a query to fetch the buys data`, () => {
|
||||
const buys = [
|
||||
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
|
||||
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
|
||||
];
|
||||
|
||||
const serializedParams = $httpParamSerializer({buys});
|
||||
const query = `Entries/1/importBuysPreview?${serializedParams}`;
|
||||
$httpBackend.expectGET(query).respond(200, buys);
|
||||
controller.fetchBuys(buys);
|
||||
$httpBackend.flush();
|
||||
|
||||
const importData = controller.import;
|
||||
|
||||
expect(importData.buys.length).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it(`should throw an error when some of the rows doesn't have an item`, () => {
|
||||
jest.spyOn(controller.vnApp, 'showError');
|
||||
|
||||
controller.import = {
|
||||
observation: '123456',
|
||||
ref: '1, 2',
|
||||
buys: [
|
||||
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
|
||||
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
|
||||
]
|
||||
};
|
||||
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.vnApp.showError).toHaveBeenCalledWith(`Some of the imported buys doesn't have an item`);
|
||||
});
|
||||
|
||||
it(`should perform a query to update columns`, () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
controller.$state.go = jest.fn();
|
||||
|
||||
controller.import = {
|
||||
observation: '123456',
|
||||
ref: '1, 2',
|
||||
buys: [
|
||||
{'itemFk': 10, 'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
|
||||
{'itemFk': 11, 'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
|
||||
]
|
||||
};
|
||||
const params = controller.import;
|
||||
|
||||
const query = `Entries/1/importBuys`;
|
||||
$httpBackend.expectPOST(query, params).respond(200, params.buys);
|
||||
controller.onSubmit();
|
||||
$httpBackend.flush();
|
||||
|
||||
const importData = controller.import;
|
||||
|
||||
expect(importData.buys.length).toEqual(2);
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('entry.card.buy.index');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
vn-entry-buy-import {
|
||||
.vn-table > tbody td:nth-child(1) {
|
||||
width: 250px
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<div fixed-bottom-right>
|
||||
<vn-vertical style="align-items: center;">
|
||||
<a ui-sref="entry.card.buy.import"
|
||||
vn-bind="+"
|
||||
vn-acl="buyer"
|
||||
vn-acl-action="remove">
|
||||
<vn-button class="round md vn-mb-sm"
|
||||
icon="publish"
|
||||
vn-tooltip="Import buys"
|
||||
tooltip-position="left">
|
||||
</vn-button>
|
||||
</a>
|
||||
</vn-vertical>
|
||||
</div>
|
|
@ -1,7 +1,7 @@
|
|||
import ngModule from '../module';
|
||||
import ngModule from '../../module';
|
||||
import Section from 'salix/components/section';
|
||||
|
||||
ngModule.vnComponent('vnEntryBuy', {
|
||||
ngModule.vnComponent('vnEntryBuyIndex', {
|
||||
template: require('./index.html'),
|
||||
controller: Section,
|
||||
bindings: {
|
|
@ -0,0 +1 @@
|
|||
Buy: Lineas de entrada
|
|
@ -1 +1,5 @@
|
|||
Buy: Lineas de entrada
|
||||
reference: Referencia
|
||||
Observation: Observación
|
||||
Box: Embalaje
|
||||
Import buys: Importar compras
|
||||
Some of the imported buys doesn't have an item: Algunas de las compras importadas no tienen un artículo
|
|
@ -13,4 +13,6 @@ import './card';
|
|||
import './note';
|
||||
import './summary';
|
||||
import './log';
|
||||
import './buy';
|
||||
import './buy/index';
|
||||
import './buy/import';
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<vn-tbody>
|
||||
<a ng-repeat="buy in $ctrl.buys"
|
||||
class="clickable vn-tr search-result"
|
||||
ui-sref="entry.card.buy({id: {{::buy.entryFk}}})">
|
||||
ui-sref="entry.card.buy.index({id: {{::buy.entryFk}}})">
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
ng-model="buy.checked"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
],
|
||||
"card": [
|
||||
{"state": "entry.card.basicData", "icon": "settings"},
|
||||
{"state": "entry.card.buy", "icon": "icon-lines"},
|
||||
{"state": "entry.card.buy.index", "icon": "icon-lines"},
|
||||
{"state": "entry.card.observation", "icon": "insert_drive_file"},
|
||||
{"state": "entry.card.log", "icon": "history"}
|
||||
]
|
||||
|
@ -56,7 +56,8 @@
|
|||
"description": "Summary",
|
||||
"params": {
|
||||
"entry": "$ctrl.entry"
|
||||
}
|
||||
},
|
||||
"acl": ["buyer", "administrative"]
|
||||
}, {
|
||||
"url": "/basic-data",
|
||||
"state": "entry.card.basicData",
|
||||
|
@ -64,7 +65,8 @@
|
|||
"description": "Basic data",
|
||||
"params": {
|
||||
"entry": "$ctrl.entry"
|
||||
}
|
||||
},
|
||||
"acl": ["buyer", "administrative"]
|
||||
},{
|
||||
"url": "/observation",
|
||||
"state": "entry.card.observation",
|
||||
|
@ -72,20 +74,40 @@
|
|||
"description": "Notes",
|
||||
"params": {
|
||||
"entry": "$ctrl.entry"
|
||||
}
|
||||
},
|
||||
"acl": ["buyer", "administrative"]
|
||||
},{
|
||||
"url" : "/log",
|
||||
"state": "entry.card.log",
|
||||
"component": "vn-entry-log",
|
||||
"description": "Log"
|
||||
}, {
|
||||
"url" : "/buy",
|
||||
"description": "Log",
|
||||
"acl": ["buyer", "administrative"]
|
||||
},
|
||||
{
|
||||
"url": "/buy",
|
||||
"state": "entry.card.buy",
|
||||
"component": "vn-entry-buy",
|
||||
"abstract": true,
|
||||
"component": "ui-view"
|
||||
},
|
||||
{
|
||||
"url" : "/index",
|
||||
"state": "entry.card.buy.index",
|
||||
"component": "vn-entry-buy-index",
|
||||
"description": "Buy",
|
||||
"params": {
|
||||
"entry": "$ctrl.entry"
|
||||
}
|
||||
},
|
||||
"acl": ["buyer", "administrative"]
|
||||
},
|
||||
{
|
||||
"url" : "/import",
|
||||
"state": "entry.card.buy.import",
|
||||
"component": "vn-entry-buy-import",
|
||||
"description": "Import buys",
|
||||
"params": {
|
||||
"entry": "$ctrl.entry"
|
||||
},
|
||||
"acl": ["buyer"]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('canBeInvoiced', {
|
||||
description: 'Change property isEqualizated in all client addresses',
|
||||
description: 'Whether the ticket can or not be invoiced',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
description: 'The ticket id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
|
@ -23,8 +23,9 @@ module.exports = function(Self) {
|
|||
});
|
||||
|
||||
Self.canBeInvoiced = async id => {
|
||||
let ticket = await Self.app.models.Ticket.findById(id, {fields: ['id', 'refFk', 'shipped']});
|
||||
let ticketTotal = await Self.app.models.Ticket.getTotal(id);
|
||||
let ticket = await Self.app.models.Ticket.findById(id, {
|
||||
fields: ['id', 'refFk', 'shipped', 'totalWithVat']
|
||||
});
|
||||
|
||||
let query = `SELECT vn.hasSomeNegativeBase(?) AS hasSomeNegativeBase`;
|
||||
let [result] = await Self.rawSql(query, [id]);
|
||||
|
@ -33,7 +34,7 @@ module.exports = function(Self) {
|
|||
let today = new Date();
|
||||
let shipped = new Date(ticket.shipped);
|
||||
|
||||
if (ticket.refFk || ticketTotal == 0 || shipped.getTime() > today.getTime() || hasSomeNegativeBase)
|
||||
if (ticket.refFk || ticket.totalWithVat == 0 || shipped.getTime() > today.getTime() || hasSomeNegativeBase)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -203,6 +203,8 @@ module.exports = Self => {
|
|||
t.routeFk,
|
||||
t.warehouseFk,
|
||||
t.clientFk,
|
||||
t.totalWithoutVat,
|
||||
t.totalWithVat,
|
||||
io.id AS invoiceOutId,
|
||||
a.provinceFk,
|
||||
p.name AS province,
|
||||
|
@ -246,6 +248,7 @@ module.exports = Self => {
|
|||
stmts.push(stmt);
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');
|
||||
|
||||
stmts.push(`
|
||||
CREATE TEMPORARY TABLE tmp.ticketGetProblems
|
||||
(INDEX (ticketFk))
|
||||
|
@ -255,23 +258,15 @@ module.exports = Self => {
|
|||
LEFT JOIN alertLevel al ON al.alertLevel = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= CURDATE()`);
|
||||
stmts.push('CALL ticketGetProblems()');
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket');
|
||||
stmts.push(`
|
||||
CREATE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk)) ENGINE = MEMORY
|
||||
SELECT id ticketFk FROM tmp.filter`);
|
||||
stmts.push('CALL ticketGetTotal()');
|
||||
stmts.push('CALL ticketGetProblems()');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
f.*,
|
||||
tt.total,
|
||||
tp.*
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`);
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id`);
|
||||
|
||||
if (args.problems != undefined && (!args.from && !args.to))
|
||||
throw new UserError('Choose a date range or days forward');
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getTaxes', {
|
||||
description: 'Returns ticket taxes',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTaxes`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTaxes = async ticketFk => {
|
||||
let query = `CALL vn.ticketGetTaxAdd(?)`;
|
||||
let [taxes] = await Self.rawSql(query, [ticketFk]);
|
||||
|
||||
return taxes;
|
||||
};
|
||||
};
|
|
@ -1,28 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getTotal', {
|
||||
description: 'Returns the total of a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTotal`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTotal = async ticketFk => {
|
||||
let query = `SELECT vn.ticketGetTotal(?) AS amount`;
|
||||
let [total] = await Self.rawSql(query, [ticketFk]);
|
||||
|
||||
return total.amount ? total.amount : 0.00;
|
||||
};
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getVAT', {
|
||||
description: 'Returns ticket total VAT',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getVAT`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getVAT = async ticketFk => {
|
||||
let totalTax = 0.00;
|
||||
let taxes = await Self.app.models.Ticket.getTaxes(ticketFk);
|
||||
|
||||
taxes.forEach(tax => {
|
||||
totalTax += tax.tax;
|
||||
});
|
||||
|
||||
return Math.round(totalTax * 100) / 100;
|
||||
};
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket getTaxes()', () => {
|
||||
it('should return the tax of a given ticket', async() => {
|
||||
let result = await app.models.Ticket.getTaxes(1);
|
||||
|
||||
expect(result[0].tax).toEqual(7.1);
|
||||
});
|
||||
});
|
|
@ -1,15 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket getTotal()', () => {
|
||||
it('should return the total of a ticket', async() => {
|
||||
let result = await app.models.Ticket.getTotal(1);
|
||||
|
||||
expect(result).toEqual(891.87);
|
||||
});
|
||||
|
||||
it(`should return zero if the ticket doesn't have lines`, async() => {
|
||||
let result = await app.models.Ticket.getTotal(21);
|
||||
|
||||
expect(result).toEqual(0);
|
||||
});
|
||||
});
|
|
@ -1,10 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket getVAT()', () => {
|
||||
it('should return the ticket VAT', async() => {
|
||||
await app.models.Ticket.getVAT(1)
|
||||
.then(response => {
|
||||
expect(response).toEqual(84.64);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,15 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket subtotal()', () => {
|
||||
it('should return the subtotal of a ticket', async() => {
|
||||
let result = await app.models.Ticket.subtotal(1);
|
||||
|
||||
expect(result).toEqual(809.23);
|
||||
});
|
||||
|
||||
it(`should return 0 if the ticket doesn't have lines`, async() => {
|
||||
let result = await app.models.Ticket.subtotal(21);
|
||||
|
||||
expect(result).toEqual(0.00);
|
||||
});
|
||||
});
|
|
@ -14,23 +14,15 @@ describe('ticket summary()', () => {
|
|||
expect(result.sales.length).toEqual(4);
|
||||
});
|
||||
|
||||
it('should return a summary object containing subtotal for 1 ticket', async() => {
|
||||
it('should return a summary object containing totalWithoutVat for 1 ticket', async() => {
|
||||
let result = await app.models.Ticket.summary(1);
|
||||
|
||||
expect(Math.round(result.subtotal * 100) / 100).toEqual(809.23);
|
||||
});
|
||||
|
||||
it('should return a summary object containing VAT for 1 ticket', async() => {
|
||||
let result = await app.models.Ticket.summary(1);
|
||||
|
||||
expect(Math.round(result.vat * 100) / 100).toEqual(84.64);
|
||||
expect(result.totalWithoutVat).toEqual(807.23);
|
||||
});
|
||||
|
||||
it('should return a summary object containing total for 1 ticket', async() => {
|
||||
let result = await app.models.Ticket.summary(1);
|
||||
let total = result.subtotal + result.vat;
|
||||
let expectedTotal = Math.round(total * 100) / 100;
|
||||
|
||||
expect(result.total).toEqual(expectedTotal);
|
||||
expect(result.totalWithVat).toEqual(891.87);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('subtotal', {
|
||||
description: 'Returns the total of a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/subtotal`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.subtotal = async ticketFk => {
|
||||
const sale = Self.app.models.Sale;
|
||||
const ticketSales = await sale.find({where: {ticketFk}});
|
||||
const ticketService = Self.app.models.TicketService;
|
||||
const ticketServices = await ticketService.find({where: {ticketFk}});
|
||||
|
||||
let subtotal = 0.00;
|
||||
ticketSales.forEach(sale => {
|
||||
subtotal += sale.price * sale.quantity * ((100 - sale.discount) / 100);
|
||||
});
|
||||
|
||||
ticketServices.forEach(service => {
|
||||
subtotal += service.price * service.quantity;
|
||||
});
|
||||
|
||||
return Math.round(subtotal * 100) / 100;
|
||||
};
|
||||
};
|
|
@ -23,9 +23,6 @@ module.exports = Self => {
|
|||
let models = Self.app.models;
|
||||
let summaryObj = await getTicketData(Self, ticketFk);
|
||||
summaryObj.sales = await getSales(models.Sale, ticketFk);
|
||||
summaryObj.subtotal = await models.Ticket.subtotal(ticketFk);
|
||||
summaryObj.vat = await models.Ticket.getVAT(ticketFk);
|
||||
summaryObj.total = summaryObj.subtotal + summaryObj.vat;
|
||||
summaryObj.packagings = await models.TicketPackaging.find({
|
||||
where: {ticketFk: ticketFk},
|
||||
include: [{relation: 'packaging',
|
||||
|
|
|
@ -6,16 +6,12 @@ module.exports = Self => {
|
|||
require('../methods/ticket/getVolume')(Self);
|
||||
require('../methods/ticket/getTotalVolume')(Self);
|
||||
require('../methods/ticket/summary')(Self);
|
||||
require('../methods/ticket/getTotal')(Self);
|
||||
require('../methods/ticket/getTaxes')(Self);
|
||||
require('../methods/ticket/subtotal')(Self);
|
||||
require('../methods/ticket/priceDifference')(Self);
|
||||
require('../methods/ticket/componentUpdate')(Self);
|
||||
require('../methods/ticket/new')(Self);
|
||||
require('../methods/ticket/isEditable')(Self);
|
||||
require('../methods/ticket/setDeleted')(Self);
|
||||
require('../methods/ticket/restore')(Self);
|
||||
require('../methods/ticket/getVAT')(Self);
|
||||
require('../methods/ticket/getSales')(Self);
|
||||
require('../methods/ticket/getSalesPersonMana')(Self);
|
||||
require('../methods/ticket/filter')(Self);
|
||||
|
|
|
@ -12,30 +12,30 @@
|
|||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "Number",
|
||||
"type": "number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"shipped": {
|
||||
"type": "Date",
|
||||
"type": "date",
|
||||
"required": true
|
||||
},
|
||||
"landed": {
|
||||
"type": "Date"
|
||||
"type": "date"
|
||||
},
|
||||
"nickname": {
|
||||
"type": "String"
|
||||
"type": "string"
|
||||
},
|
||||
"location": {
|
||||
"type": "String"
|
||||
"type": "string"
|
||||
},
|
||||
"solution": {
|
||||
"type": "String"
|
||||
"type": "string"
|
||||
},
|
||||
"packages": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"updated": {
|
||||
"type": "Date",
|
||||
"type": "date",
|
||||
"mysql": {
|
||||
"columnName": "created"
|
||||
}
|
||||
|
@ -44,16 +44,22 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"priority": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"zoneFk": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"zonePrice": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"zoneBonus": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"totalWithVat": {
|
||||
"type": "number"
|
||||
},
|
||||
"totalWithoutVat": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
<vn-td>{{::ticket.warehouse}}</vn-td>
|
||||
<vn-td number>
|
||||
<span class="chip {{$ctrl.totalPriceColor(ticket)}}">
|
||||
{{::ticket.total | currency: 'EUR': 2}}
|
||||
{{::(ticket.totalWithVat ? ticket.totalWithVat : 0) | currency: 'EUR': 2}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td actions>
|
||||
|
|
|
@ -49,7 +49,7 @@ export default class Controller extends Section {
|
|||
throw new UserError('You cannot make a payment on account from multiple clients');
|
||||
|
||||
for (let ticket of checkedTickets) {
|
||||
this.$.balanceCreateDialog.amountPaid += ticket.total;
|
||||
this.$.balanceCreateDialog.amountPaid += ticket.totalWithVat;
|
||||
this.$.balanceCreateDialog.clientFk = ticket.clientFk;
|
||||
description.push(`${ticket.id}`);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
totalPriceColor(ticket) {
|
||||
const total = parseInt(ticket.total);
|
||||
const total = parseInt(ticket.totalWithVat);
|
||||
if (total > 0 && total < 50)
|
||||
return 'warning';
|
||||
}
|
||||
|
|
|
@ -6,18 +6,18 @@ describe('Component vnTicketIndex', () => {
|
|||
let tickets = [{
|
||||
id: 1,
|
||||
clientFk: 1,
|
||||
total: 10.5,
|
||||
checked: false
|
||||
checked: false,
|
||||
totalWithVat: 10.5
|
||||
}, {
|
||||
id: 2,
|
||||
clientFk: 1,
|
||||
total: 20.5,
|
||||
checked: true
|
||||
checked: true,
|
||||
totalWithVat: 20.5
|
||||
}, {
|
||||
id: 3,
|
||||
clientFk: 1,
|
||||
total: 30,
|
||||
checked: true
|
||||
checked: true,
|
||||
totalWithVat: 30
|
||||
}];
|
||||
|
||||
beforeEach(ngModule('ticket'));
|
||||
|
@ -76,7 +76,6 @@ describe('Component vnTicketIndex', () => {
|
|||
jest.spyOn(controller.$.balanceCreateDialog, 'show').mockReturnThis();
|
||||
|
||||
controller.$.model = {data: tickets};
|
||||
controller.$.balanceCreateDialog.amountPaid = 0;
|
||||
controller.openBalanceDialog();
|
||||
|
||||
let description = controller.$.balanceCreateDialog.description;
|
||||
|
|
|
@ -39,8 +39,8 @@ class Controller extends Section {
|
|||
|
||||
getSubTotal() {
|
||||
if (!this.$params.id || !this.sales) return;
|
||||
this.$http.get(`Tickets/${this.$params.id}/subtotal`).then(res => {
|
||||
this.subtotal = res.data || 0.0;
|
||||
this.$http.get(`Tickets/${this.$params.id}`).then(res => {
|
||||
this.subtotal = res.data.totalWithoutVat || 0.0;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ class Controller extends Section {
|
|||
getVat() {
|
||||
this.VAT = 0.0;
|
||||
if (!this.$params.id || !this.sales) return;
|
||||
this.$http.get(`Tickets/${this.$params.id}/getVAT`).then(res => {
|
||||
this.VAT = res.data || 0.0;
|
||||
this.$http.get(`Tickets/${this.$params.id}`).then(res => {
|
||||
this.VAT = res.data.totalWithVat - res.data.totalWithoutVat || 0.0;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -84,13 +84,13 @@ describe('Ticket', () => {
|
|||
|
||||
describe('getSubTotal()', () => {
|
||||
it('should make an HTTP GET query and then set the subtotal property', () => {
|
||||
const expectedAmount = 128;
|
||||
const expectedResponse = {totalWithoutVat: 128};
|
||||
|
||||
$httpBackend.expect('GET', 'Tickets/1/subtotal').respond(200, expectedAmount);
|
||||
$httpBackend.expect('GET', 'Tickets/1').respond(200, expectedResponse);
|
||||
controller.getSubTotal();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.subtotal).toEqual(expectedAmount);
|
||||
expect(controller.subtotal).toEqual(expectedResponse.totalWithoutVat);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -125,13 +125,15 @@ describe('Ticket', () => {
|
|||
describe('getVat()', () => {
|
||||
it('should make an HTTP GET query and return the ticket VAT', () => {
|
||||
controller.edit = {};
|
||||
const expectedAmount = 67;
|
||||
const expectedResponse = {totalWithVat: 1000, totalWithoutVat: 999};
|
||||
|
||||
$httpBackend.expect('GET', 'Tickets/1/getVAT').respond(200, expectedAmount);
|
||||
const expectedVAT = expectedResponse.totalWithVat - expectedResponse.totalWithoutVat;
|
||||
|
||||
$httpBackend.expect('GET', 'Tickets/1').respond(200, expectedResponse);
|
||||
controller.getVat();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.VAT).toEqual(expectedAmount);
|
||||
expect(controller.VAT).toEqual(expectedVAT);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -99,9 +99,9 @@
|
|||
</vn-label-value>
|
||||
</vn-one>
|
||||
<vn-one class="taxes">
|
||||
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.subtotal | currency: 'EUR':2}}</p>
|
||||
<p><vn-label translate>VAT</vn-label> {{$ctrl.summary.vat | currency: 'EUR':2}}</p>
|
||||
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.total | currency: 'EUR':2}}</strong></p>
|
||||
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.totalWithoutVat | currency: 'EUR':2}}</p>
|
||||
<p><vn-label translate>VAT</vn-label> {{$ctrl.summary.totalWithVat - $ctrl.summary.totalWithoutVat | currency: 'EUR':2}}</p>
|
||||
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.totalWithVat | currency: 'EUR':2}}</strong></p>
|
||||
</vn-one>
|
||||
<vn-auto name="sales">
|
||||
<h4>
|
||||
|
|
Loading…
Reference in New Issue