Import buys
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-02-09 07:59:55 +01:00
parent 411053bbec
commit c092bf58b4
7 changed files with 84 additions and 11 deletions

View File

@ -2175,3 +2175,12 @@ INSERT INTO `hedera`.`image`(`collectionFk`, `name`)
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);

View File

@ -1,3 +1,5 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethodCtx('import', {
description: 'Imports the buys from a JSON file',
@ -9,6 +11,16 @@ module.exports = Self => {
description: 'The entry id',
http: {source: 'path'}
},
{
arg: 'ref',
type: 'string',
description: 'The buyed boxes ids',
},
{
arg: 'observation',
type: 'string',
description: 'The observation',
},
{
arg: 'buys',
type: ['Object'],
@ -25,10 +37,14 @@ module.exports = Self => {
});
Self.import = async(ctx, id) => {
const conn = Self.dataSource.connector;
const args = ctx.args;
const models = Self.app.models;
const entry = await models.Entry.findById(id);
await entry.updateAttributes({
observation: args.notes
});
const buys = [];
for (let buy of args.buys) {
@ -44,6 +60,23 @@ module.exports = Self => {
});
}
await models.Buy.create(buys);
const createdBuys = await models.Buy.create(buys);
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); */
};
};

View File

@ -2,13 +2,18 @@ module.exports = Self => {
Self.remoteMethod('importPreview', {
description: '',
accessType: 'READ',
accepts: {
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
@ -19,7 +24,17 @@ module.exports = Self => {
}
});
Self.importPreview = async id => {
Self.importPreview = 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;
};
};

View File

@ -3,4 +3,5 @@ module.exports = Self => {
require('../methods/entry/getEntry')(Self);
require('../methods/entry/getBuys')(Self);
require('../methods/entry/import')(Self);
require('../methods/entry/importPreview')(Self);
};

View File

@ -28,7 +28,7 @@
"type": "boolean"
},
"notes": {
"type": "String"
"type": "string"
},
"isConfirmed": {
"type": "boolean"

View File

@ -59,8 +59,8 @@
<vn-horizontal>
<vn-textarea
vn-one
label="Notes"
ng-model="$ctrl.import.description">
label="Observation"
ng-model="$ctrl.import.observation">
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
@ -90,7 +90,7 @@
<th translate center>Packing</th>
<th translate center>Grouping</th>
<th translate center>Buying value</th>
<th translate center>Package</th>
<th translate center>Box</th>
<th translate center>Volume</th>
</tr>
</thead>
@ -125,7 +125,16 @@
</vn-chip>
</vn-td>
<td>{{::buy.buyingValue | currency: 'EUR':2}}</td>
<td center title="{{::buy.packageFk | dashIfEmpty}}">{{::buy.packageFk | dashIfEmpty}}</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>

View File

@ -30,7 +30,7 @@ class Controller extends Section {
this.$.$applyAsync(() => {
this.import.invoice = invoice.id_invoice;
this.import.description = invoice.tx_awb;
this.import.observation = invoice.tx_awb;
const boxes = invoice.boxes;
const buys = [];
@ -48,7 +48,13 @@ class Controller extends Section {
});
}
}
this.import.buys = buys;
const params = {buys};
const query = `Entries/${this.entry.id}/importPreview`;
this.$http.get(query, {params}).then(res => {
this.import.buys = res.data;
});
// this.import.buys = buys;
});
}