Javascript计算-自动化脚本

Javascript计算-自动化脚本,javascript,sql,Javascript,Sql,我正在尝试编写一个简单的自动化脚本,但在设置方面有点困难 我正在尝试获取输入的购买价格(成本)和销售价格(价格),并计算利润,同时考虑我可能产生的任何附加费(附加费) 我尝试了各种类似的方法: export default { label: 'Profit', description: 'Calculate Job Profit', * triggers ({ on }) { yield on('manual') .for('compose:

我正在尝试编写一个简单的自动化脚本,但在设置方面有点困难

我正在尝试获取输入的购买价格(成本)和销售价格(价格),并计算利润,同时考虑我可能产生的任何附加费(附加费)

我尝试了各种类似的方法:

export default {
    label: 'Profit',
    description: 'Calculate Job Profit',

    * triggers ({ on }) {
      yield on('manual')
        .for('compose:record')
        .where('module', 'job_record')
        .where('namespace', 'record_base')
        .uiProp('app', 'compose')
    },

    async exec ({ $record }, { Compose, ComposeUI }) {
      $record.values.Profit = $record.values.Price - $record.values.Cost - $record.values.Surcharge
      await Compose.saveRecord($record)
      return ComposeUI.success('Profit updated.')
    }
}
function updateDue() {

    var Price = parseInt(document.getElementById("Price").value);
    var Cost = parseInt(document.getElementById("Cost").value);

    if (!Price) { Price = 0; }
    if (!Cost) { Cost = 0; }

    var ansD = document.getElementById("Profit");
    ansD.value = Price- Cost;
}
有几个后端脚本将当前正在编辑的文件设置为
$record

利润
价格
成本
附加费
都是数据库条目

通常我会用不同的方式写这篇文章,类似于:

export default {
    label: 'Profit',
    description: 'Calculate Job Profit',

    * triggers ({ on }) {
      yield on('manual')
        .for('compose:record')
        .where('module', 'job_record')
        .where('namespace', 'record_base')
        .uiProp('app', 'compose')
    },

    async exec ({ $record }, { Compose, ComposeUI }) {
      $record.values.Profit = $record.values.Price - $record.values.Cost - $record.values.Surcharge
      await Compose.saveRecord($record)
      return ComposeUI.success('Profit updated.')
    }
}
function updateDue() {

    var Price = parseInt(document.getElementById("Price").value);
    var Cost = parseInt(document.getElementById("Cost").value);

    if (!Price) { Price = 0; }
    if (!Cost) { Cost = 0; }

    var ansD = document.getElementById("Profit");
    ansD.value = Price- Cost;
}
但是,由于这种自动化不是使用HTML输入计算的,我有点困惑,不知道如何使用数据库条目进行计算