-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Sales): dispatch documents and evaluate document transport co…
…nfig
- Loading branch information
1 parent
2a82041
commit 3533376
Showing
22 changed files
with
768 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const abstractAction = Ext.extend(Ext.Action, { | ||
|
||
|
||
/** | ||
* @param config | ||
* | ||
* maskMsg: 'Please Wait...', | ||
* documentType: '', // one of Offer|Order|Delivery|Invoice | ||
* | ||
*/ | ||
constructor: function (config) { | ||
config.app = Tine.Tinebase.appMgr.get('Sales') | ||
config.recordClass = Tine.Tinebase.data.RecordMgr.get(`Sales.Document_${config.documentType}`) | ||
config.statusFieldName = `${config.documentType.toLowerCase()}_status` | ||
config.statusDef = Tine.Tinebase.widgets.keyfield.getDefinitionFromMC(config.recordClass, config.statusFieldName) | ||
|
||
Ext.Action.prototype.constructor.call(this, config); | ||
}, | ||
// NOTE: action updater is not executed in action but in component of the action | ||
// so it does not work to define it here | ||
// actionUpdater(action, grants, records, isFilterSelect, filteredContainers) { | ||
// let enabled = records.length === 1 // no batch processing yet, needs a robust concept! | ||
// action.setDisabled(!enabled) | ||
// action.baseAction.setDisabled(!enabled) // WTF? | ||
// }, | ||
handler: async function(cmp) { | ||
// @TODO working with this might be a bad idea as it's excecuted here only and not in constructor? | ||
|
||
|
||
// this.recordsName = recordClass.getRecordsName() | ||
this.selections = [...this.initialConfig.selections] | ||
this.errorMsgs = [] | ||
this.editDialog = cmp.findParentBy((c) => {return c instanceof Tine.widgets.dialog.EditDialog}) | ||
this.maskEl = cmp.findParentBy((c) => {return c instanceof Tine.widgets.dialog.EditDialog || c instanceof Tine.widgets.MainScreen }).getEl() | ||
this.mask = new Ext.LoadMask(this.maskEl, { msg: this.maskMsg || this.app.i18n._('Please wait...') }) | ||
|
||
this.unbooked = this.selections.reduce((unbooked, record) => { | ||
record.noProxy = true // kill grid autoSave | ||
const status = record.get(this.statusFieldName) | ||
return unbooked.concat(this.statusDef.records.find((r) => { return r.id === status })?.booked ? [] : [record]) | ||
}, []) | ||
|
||
// if (editDialog) { | ||
// try { | ||
// await editDialog.isValid() | ||
// } catch (e) { | ||
// return | ||
// } | ||
// } | ||
// | ||
// this.handle(options) | ||
} | ||
}); | ||
|
||
export default abstractAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Tine 2.0 | ||
* | ||
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3 | ||
* @author Cornelius Weiss <[email protected]> | ||
* @copyright Copyright (c) 2022 Metaways Infosystems GmbH (http://www.metaways.de) | ||
*/ | ||
import AbstractAction from "./AbstractAction"; | ||
|
||
Promise.all([Tine.Tinebase.appMgr.isInitialised('Sales'), | ||
Tine.Tinebase.ApplicationStarter.isInitialised()]).then(() => { | ||
const app = Tine.Tinebase.appMgr.get('Sales') | ||
|
||
const getAction = (type, config) => { | ||
return new AbstractAction({ | ||
documentType: type, | ||
text: app.i18n._('Book Document'), | ||
iconCls: `action_book_document`, | ||
actionUpdater(action, grants, records, isFilterSelect, filteredContainers) { | ||
let enabled = records.length | ||
|
||
enabled = records.reduce((enabled, record) => { | ||
return enabled && !_.find(action.statusDef.records, {id: record.get(action.statusFieldName) })?.booked | ||
}, enabled) | ||
|
||
// action.setDisabled(!enabled) // this is the component itsef | ||
action.baseAction.setDisabled(!enabled) // this is the action which sets all instances | ||
}, | ||
handler: async function(cmp) { | ||
AbstractAction.prototype.handler.call(this, cmp); | ||
|
||
// @TODO: maybe we should define default booked state somehow? e.g. offer should be accepted (not only send) or let the user select? | ||
const bookedState = this.statusDef.records.find((r) => { return r.booked }) | ||
this.mask.show() | ||
|
||
try { | ||
// check if date is set and ask if user want's to change it to today | ||
const notToday = _.reduce(this.unbooked, (acc, record) => { | ||
return _.concat(acc, record.get('date') && record.get('date').format('Ymd') !== new Date().format('Ymd') ? record : []); | ||
}, []) | ||
if (notToday.length) { | ||
_.each(await Tine.widgets.dialog.MultiOptionsDialog.getOption({ | ||
title: this.app.formatMessage('Change Document Date?'), | ||
questionText: this.app.formatMessage('Please select the { sourceRecordsName } where you want to change the document date to today.', { sourceRecordsName: this.recordClass.getRecordsName() }), | ||
allowMultiple: true, | ||
allowEmpty: true, | ||
allowCancel: false, | ||
height: notToday.length * 30 + 100, | ||
options: notToday.map((source) => { | ||
return { text: source.getTitle() + ': ' + Tine.Tinebase.common.dateRenderer(source.get('date')), name: source.id, checked: false, source } | ||
}) | ||
}), (option) => { _.find(unbooked, { id: option.name }).set('date', new Date().clearTime()); debugger}); | ||
} | ||
} catch (e) {/* USERABORT -> continue */ } | ||
|
||
await this.unbooked.asyncForEach(async (record) => { | ||
if (record.phantom) { | ||
record = await this.recordClass.getProxy().promiseSaveRecord(record) | ||
if (this.recordClass === this.editDialog?.recordClass) { | ||
this.editDialog ? await this.editDialog.loadRecord(record) : null | ||
} | ||
} | ||
record.set(this.statusFieldName, bookedState.id) | ||
let updatedRecord | ||
try { | ||
updatedRecord = await this.recordClass.getProxy().promiseSaveRecord(record) | ||
this.selections.splice.apply(this.selections, [this.selections.indexOf(record), 1].concat(updatedRecord ? [updatedRecord] : [])) | ||
if (this.recordClass === this.editDialog?.recordClass) { | ||
this.editDialog ? await this.editDialog.loadRecord(updatedRecord) : null | ||
} | ||
} catch (e) { | ||
record.reject() | ||
this.errorMsgs.push(this.app.formatMessage('Cannot book { sourceDocument }: ({e.code}) { e.message }', { sourceDocument: record.getTitle(), e })) | ||
} | ||
}) | ||
this.mask.hide() | ||
|
||
if (this.errorMsgs.length) { | ||
await Ext.MessageBox.show({ | ||
buttons: Ext.Msg.OK, | ||
icon: Ext.MessageBox.WARNING, | ||
title: this.app.formatMessage('There where Errors:'), | ||
msg: this.errorMsgs.join('<br />') | ||
}) | ||
} | ||
} | ||
}) | ||
} | ||
['Offer', 'Order', 'Delivery', 'Invoice'].forEach((type) => { | ||
const action = getAction(type, {}) | ||
const medBtnStyle = { scale: 'medium', rowspan: 2, iconAlign: 'top'} | ||
Ext.ux.ItemRegistry.registerItem(`Sales-Document_${type}-GridPanel-ContextMenu`, action, 2) | ||
Ext.ux.ItemRegistry.registerItem(`Sales-Document_${type}-editDialog-Toolbar`, Ext.apply(new Ext.Button(action), medBtnStyle), 30) | ||
Ext.ux.ItemRegistry.registerItem(`Sales-Document_${type}-GridPanel-ActionToolbar-leftbtngrp`, Ext.apply(new Ext.Button(action), medBtnStyle), 30) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.