|
| 1 | +// File: accountNumber.js |
| 2 | +// Location: musesuperchar/client/scripts/forms/xtuple |
| 3 | +// Project: Muse Systems Super Characteristics for xTuple ERP |
| 4 | +// |
| 5 | +// Licensed to Lima Buttgereit Holdings LLC (d/b/a Muse Systems) under one or |
| 6 | +// more agreements. Muse Systems licenses this file to you under the Apache |
| 7 | +// License, Version 2.0. |
| 8 | +// |
| 9 | +// See the LICENSE file in the project root for license terms and conditions. |
| 10 | +// See the NOTICE file in the project root for copyright ownership information. |
| 11 | +// |
| 12 | +// muse.information@musesystems.com :: https://muse.systems |
| 13 | + |
| 14 | +try { |
| 15 | + ////////////////////////////////////////////////////////////////////////// |
| 16 | + // Namespace Definition |
| 17 | + ////////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | + if (typeof MuseSuperChar === "undefined") { |
| 20 | + MuseSuperChar = {}; |
| 21 | + } |
| 22 | + |
| 23 | + if (typeof MuseSuperChar.LedgerAccountNumber === "undefined") { |
| 24 | + MuseSuperChar.LedgerAccountNumber = {}; |
| 25 | + } |
| 26 | + |
| 27 | + ////////////////////////////////////////////////////////////////////////// |
| 28 | + // Imports |
| 29 | + ////////////////////////////////////////////////////////////////////////// |
| 30 | + |
| 31 | + if (typeof MuseUtils === "undefined") { |
| 32 | + include("museUtils"); |
| 33 | + } |
| 34 | + |
| 35 | + MuseUtils.loadMuseUtils([ |
| 36 | + MuseUtils.MOD_EXCEPTION, |
| 37 | + MuseUtils.MOD_JSPOLYFILL, |
| 38 | + MuseUtils.MOD_JS, |
| 39 | + MuseUtils.MOD_CONFIG |
| 40 | + ]); |
| 41 | + |
| 42 | + if (typeof MuseSuperChar.Loader === "undefined") { |
| 43 | + include("museScLoader"); |
| 44 | + } |
| 45 | +} catch (e) { |
| 46 | + if ( |
| 47 | + typeof MuseUtils !== "undefined" && |
| 48 | + (MuseUtils.isMuseUtilsExceptionLoaded === true ? true : false) |
| 49 | + ) { |
| 50 | + var error = new MuseUtils.ScriptException( |
| 51 | + "musesuperchar", |
| 52 | + "We encountered a script level issue while processing MuseSuperChar.LedgerAccountNumber.", |
| 53 | + "MuseSuperChar.LedgerAccountNumber", |
| 54 | + { thrownError: e }, |
| 55 | + MuseUtils.LOG_FATAL |
| 56 | + ); |
| 57 | + |
| 58 | + MuseUtils.displayError(error, mainwindow); |
| 59 | + } else { |
| 60 | + QMessageBox.critical( |
| 61 | + mainwindow, |
| 62 | + "MuseSuperChar.LedgerAccountNumber Script Error", |
| 63 | + "We encountered a script level issue while processing MuseSuperChar.LedgerAccountNumber." |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +////////////////////////////////////////////////////////////////////////// |
| 69 | +// Module Defintion |
| 70 | +////////////////////////////////////////////////////////////////////////// |
| 71 | + |
| 72 | +(function(pPublicApi, pGlobal) { |
| 73 | + try { |
| 74 | + //-------------------------------------------------------------------- |
| 75 | + // Constants and Module State |
| 76 | + //-------------------------------------------------------------------- |
| 77 | + // Constants |
| 78 | + var ENTITY_DATA_TABLE = "public_accnt"; |
| 79 | + |
| 80 | + // Mutable state |
| 81 | + var preSaveAccntId = null; |
| 82 | + var scWidget = null; |
| 83 | + |
| 84 | + //-------------------------------------------------------------------- |
| 85 | + // Get Object References From Screen Definitions |
| 86 | + //-------------------------------------------------------------------- |
| 87 | + |
| 88 | + //-------------------------------------------------------------------- |
| 89 | + // Custom Screen Objects and Starting GUI Manipulation |
| 90 | + //-------------------------------------------------------------------- |
| 91 | + |
| 92 | + //-------------------------------------------------------------------- |
| 93 | + // Private Functional Logic |
| 94 | + //-------------------------------------------------------------------- |
| 95 | + var getAccntIdIfNecessary = function() { |
| 96 | + var get_param = function(name, property) { |
| 97 | + return mywindow.findChild(name)[property || "currentText"]; |
| 98 | + }; |
| 99 | + |
| 100 | + if (!preSaveAccntId) { |
| 101 | + var params = {}; |
| 102 | + params.number = get_param("_number", "text"); |
| 103 | + params.profit = get_param("_profit"); |
| 104 | + params.sub = get_param("_sub"); |
| 105 | + params.company = get_param("_company"); |
| 106 | + |
| 107 | + var query = MuseUtils.executeQuery( |
| 108 | + "SELECT accnt_id " + |
| 109 | + "FROM accnt " + |
| 110 | + "WHERE accnt_number = <? value('number') ?> " + |
| 111 | + " AND accnt_profit = <? value('profit') ?> " + |
| 112 | + " AND accnt_sub = <? value('sub') ?> " + |
| 113 | + " AND accnt_company = <? value('company') ?> ", |
| 114 | + params |
| 115 | + ); |
| 116 | + |
| 117 | + if (query.first()) { |
| 118 | + preSaveAccntId = query.value("accnt_id"); |
| 119 | + } else { |
| 120 | + throw new MuseUtils.NotFoundException( |
| 121 | + "musesuperchar", |
| 122 | + "We encountered an error while loading the new account record.", |
| 123 | + "MuseSuperChar.LedgerAccountNumber.getAccntIdIfNecessary", |
| 124 | + { |
| 125 | + params: params |
| 126 | + }, |
| 127 | + MuseUtils.LOG_CRITICAL |
| 128 | + ); |
| 129 | + } |
| 130 | + } |
| 131 | + }; |
| 132 | + |
| 133 | + var myPostSave = function() { |
| 134 | + getAccntIdIfNecessary(); |
| 135 | + |
| 136 | + try { |
| 137 | + if ( |
| 138 | + !MuseUtils.isValidId(preSaveAccntId) || |
| 139 | + MuseUtils.realNull(scWidget) === null |
| 140 | + ) { |
| 141 | + return; |
| 142 | + } |
| 143 | + |
| 144 | + scWidget.save(preSaveAccntId); |
| 145 | + preSaveAccntId = null; |
| 146 | + } catch (e) { |
| 147 | + var error = new MuseUtils.FormException( |
| 148 | + "musesuperchar", |
| 149 | + "We found problems while trying to save Super Characteristic data.", |
| 150 | + "MuseSuperChar.LedgerAccountNumber.myPostSave", |
| 151 | + { thrownError: e }, |
| 152 | + MuseUtils.LOG_CRITICAL |
| 153 | + ); |
| 154 | + MuseUtils.displayError(error, mywindow); |
| 155 | + } |
| 156 | + }; |
| 157 | + |
| 158 | + var initSuperChar = function(pMode, pParentId) { |
| 159 | + if (MuseUtils.realNull(scWidget) === null) { |
| 160 | + return; |
| 161 | + } |
| 162 | + scWidget.initWidget(pMode, pParentId); |
| 163 | + }; |
| 164 | + |
| 165 | + //-------------------------------------------------------------------- |
| 166 | + // Public Interface -- Slots |
| 167 | + //-------------------------------------------------------------------- |
| 168 | + |
| 169 | + //-------------------------------------------------------------------- |
| 170 | + // Public Interface -- Functions |
| 171 | + //-------------------------------------------------------------------- |
| 172 | + pPublicApi.getCurrentScWidget = function() { |
| 173 | + return scWidget; |
| 174 | + }; |
| 175 | + |
| 176 | + /** |
| 177 | + * Form startup initialization. Standard part of the xTuple ERP |
| 178 | + * startup process. |
| 179 | + * @param {Object} pParams An associative array of values passed from |
| 180 | + * the xTuple C++ forms which contain context |
| 181 | + * setting information. |
| 182 | + */ |
| 183 | + pPublicApi.set = function(pParams) { |
| 184 | + var myMode = pParams.mode.toString(); |
| 185 | + preSaveAccntId = pParams.accnt_id; |
| 186 | + |
| 187 | + if (["new", "edit", "view"].includes(myMode)) { |
| 188 | + if (scWidget === null) { |
| 189 | + scWidget = MuseSuperChar.Loader.getSuperCharWidget( |
| 190 | + ENTITY_DATA_TABLE |
| 191 | + ); |
| 192 | + } |
| 193 | + |
| 194 | + if (scWidget !== null) { |
| 195 | + mywindow.layout().addWidget(scWidget, 10, 0, 1, 5); |
| 196 | + } else { |
| 197 | + return; |
| 198 | + } |
| 199 | + |
| 200 | + initSuperChar(myMode, preSaveAccntId); |
| 201 | + } else { |
| 202 | + return; |
| 203 | + } |
| 204 | + }; |
| 205 | + |
| 206 | + //-------------------------------------------------------------------- |
| 207 | + // Definition Timed Connects/Disconnects |
| 208 | + //-------------------------------------------------------------------- |
| 209 | + // MuseUtils.LedgerAccountNumber.addPreSaveHookFunc(myPreSave); |
| 210 | + MuseUtils.LedgerAccountNumber.addPostSaveHookFunc(myPostSave); |
| 211 | + |
| 212 | + //-------------------------------------------------------------------- |
| 213 | + // Foreign Script "Set" Handling |
| 214 | + //-------------------------------------------------------------------- |
| 215 | + |
| 216 | + // "Set" handling base on suggestion of Gil Moskowitz/xTuple. |
| 217 | + var foreignSetFunc; |
| 218 | + |
| 219 | + // Lower graded scripts should be loaded prior to our call and as such we |
| 220 | + // should be able to intercept their set functions. |
| 221 | + if (typeof pGlobal.set === "function") { |
| 222 | + foreignSetFunc = pGlobal.set; |
| 223 | + } else { |
| 224 | + foreignSetFunc = function() {}; |
| 225 | + } |
| 226 | + |
| 227 | + pGlobal.set = function(pParams) { |
| 228 | + var funcParams = { pParams: pParams }; |
| 229 | + |
| 230 | + var myParams = MuseUtils.parseParams(pParams || {}); |
| 231 | + |
| 232 | + try { |
| 233 | + foreignSetFunc(myParams); |
| 234 | + pPublicApi.set(myParams); |
| 235 | + } catch (e) { |
| 236 | + var error = new MuseUtils.ModuleException( |
| 237 | + "musesuperchar", |
| 238 | + "We enountered an error while initializing the form.", |
| 239 | + "global.set", |
| 240 | + { |
| 241 | + params: funcParams, |
| 242 | + thrownError: e, |
| 243 | + context: { |
| 244 | + parsedParams: myParams |
| 245 | + } |
| 246 | + }, |
| 247 | + MuseUtils.LOG_FATAL |
| 248 | + ); |
| 249 | + MuseUtils.displayError(error, mywindow); |
| 250 | + mywindow.close(); |
| 251 | + } |
| 252 | + }; |
| 253 | + } catch (e) { |
| 254 | + var error = new MuseUtils.ModuleException( |
| 255 | + "musesuperchar", |
| 256 | + "We enountered a MuseSuperChar.LedgerAccountNumber module error that wasn't otherwise caught and handled.", |
| 257 | + "MuseSuperChar.LedgerAccountNumber", |
| 258 | + { thrownError: e }, |
| 259 | + MuseUtils.LOG_FATAL |
| 260 | + ); |
| 261 | + MuseUtils.displayError(error, mainwindow); |
| 262 | + } |
| 263 | +})(MuseSuperChar.LedgerAccountNumber, this); |
0 commit comments