2021-01-18 13:16:39 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2022-03-16 13:58:07 +00:00
|
|
|
|
|
|
|
this.smartTableOptions = {
|
|
|
|
activeButtons: {
|
|
|
|
search: true
|
2022-03-17 08:13:09 +00:00
|
|
|
},
|
|
|
|
defaultSearch: true,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
field: 'warehouseFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Warehouses',
|
|
|
|
showField: 'name',
|
|
|
|
valueField: 'id',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'started',
|
|
|
|
searchable: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'ended',
|
|
|
|
searchable: false
|
|
|
|
}
|
|
|
|
]
|
2022-03-16 13:58:07 +00:00
|
|
|
};
|
2021-01-18 13:16:39 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 12:40:14 +00:00
|
|
|
isBigger(date) {
|
|
|
|
let today = Date.vnNew();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
date = new Date(date);
|
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const timeDifference = today - date;
|
|
|
|
if (timeDifference < 0) return 'warning';
|
|
|
|
}
|
|
|
|
|
|
|
|
isLower(date) {
|
|
|
|
let today = Date.vnNew();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
date = new Date(date);
|
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const timeDifference = today - date;
|
|
|
|
if (timeDifference > 0) return 'warning';
|
|
|
|
}
|
|
|
|
|
2021-01-18 13:16:39 +00:00
|
|
|
add() {
|
2022-03-18 09:30:30 +00:00
|
|
|
if (!this.$.model.data || this.$.model.data.length == 0) {
|
|
|
|
this.$.model.data = [];
|
|
|
|
this.$.model.proxiedData = [];
|
2023-03-28 08:30:02 +00:00
|
|
|
|
|
|
|
const today = Date.vnNew();
|
|
|
|
|
|
|
|
const millisecsInDay = 86400000;
|
|
|
|
const daysInWeek = 7;
|
|
|
|
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
|
|
|
|
|
|
|
this.$.model.insert({
|
|
|
|
started: today,
|
|
|
|
ended: nextWeek
|
|
|
|
});
|
2022-03-18 09:30:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-23 11:26:58 +00:00
|
|
|
const lastIndex = this.$.model.data.length - 1;
|
|
|
|
const lastItem = this.$.model.data[lastIndex];
|
2022-03-16 13:58:07 +00:00
|
|
|
this.$.model.insert({
|
|
|
|
itemFk: lastItem.itemFk,
|
|
|
|
name: lastItem.name,
|
|
|
|
subName: lastItem.subName,
|
|
|
|
value5: lastItem.value5,
|
|
|
|
value6: lastItem.value6,
|
|
|
|
value7: lastItem.value7,
|
|
|
|
value8: lastItem.value8,
|
|
|
|
value9: lastItem.value9,
|
|
|
|
value10: lastItem.value10,
|
|
|
|
warehouseFk: lastItem.warehouseFk,
|
|
|
|
rate2: lastItem.rate2,
|
|
|
|
rate3: lastItem.rate3,
|
|
|
|
hasMinPrice: lastItem.hasMinPrice,
|
|
|
|
minPrice: lastItem.minPrice,
|
|
|
|
started: lastItem.started,
|
|
|
|
ended: lastItem.ended,
|
|
|
|
});
|
2021-01-18 13:16:39 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 13:39:38 +00:00
|
|
|
upsertPrice(price, resetMinPrice) {
|
|
|
|
if (resetMinPrice)
|
|
|
|
delete price['minPrice'];
|
|
|
|
|
2021-01-18 15:32:54 +00:00
|
|
|
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
2021-01-18 13:16:39 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-01-19 19:56:33 +00:00
|
|
|
|
|
|
|
itemSearchFunc($search) {
|
|
|
|
return /^\d+$/.test($search)
|
|
|
|
? {id: $search}
|
|
|
|
: {name: {like: '%' + $search + '%'}};
|
|
|
|
}
|
2022-03-17 08:13:09 +00:00
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
2022-11-02 08:40:09 +00:00
|
|
|
case 'name':
|
|
|
|
return {'i.name': {like: `%${value}%`}};
|
2022-03-17 08:13:09 +00:00
|
|
|
case 'itemFk':
|
|
|
|
case 'warehouseFk':
|
|
|
|
case 'rate2':
|
|
|
|
case 'rate3':
|
|
|
|
param = `fp.${param}`;
|
|
|
|
return {[param]: value};
|
|
|
|
case 'minPrice':
|
|
|
|
param = `i.${param}`;
|
|
|
|
return {[param]: value};
|
|
|
|
}
|
|
|
|
}
|
2021-01-18 13:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnFixedPrice', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|