1 /*jshint bitwise:true, indent:2, curly:true, eqeqeq:true, immed:true,
2 latedef:true, newcap:true, noarg:true, regexp:true, undef:true,
3 trailing:true, white:true, strict:false*/
4 /*global XT:true, XM:true, XV:true, _:true, enyo:true */
9 Expected to a have a parameter widget that contains an order and
12 @name XV.TransactionList
16 name: "XV.TransactionList",
20 transWorkspace: XM.Inventory,
21 transFunction: "issueToShipping"
24 onProcessingChanged: "",
29 showDeleteAction: false,
32 {name: "transactItem", prerequisite: "canTransactItem",
33 method: "transactItem", notify: false, isViewMethod: true},
34 {name: "transactLine", prerequisite: "canTransactItem",
35 method: "transactLine", notify: false, isViewMethod: true},
36 {name: "returnLine", prerequisite: "canReturnItem",
37 method: "returnItem", notify: false, isViewMethod: true}
40 Helper function for transacting `transact` on an array of models
43 @param {Boolean} Prompt user for confirmation on every model
45 transact: function (models, prompt, transactStock) {
51 // Recursively transact everything we can
52 callback = function (workspace) {
61 transModule = that.getTransModule(),
62 transFunction = that.getTransFunction(),
63 transWorkspace = that.getTransWorkspace();
65 // If argument is false, this whole process was cancelled
66 if (workspace === false) {
69 // If a workspace brought us here, process the information it obtained
70 } else if (workspace) {
71 model = workspace.getValue();
72 toTransact = model.get(model.quantityAttribute);
73 transDate = model.transactionDate;
76 wsOptions.detail = model.formatDetail();
77 wsOptions.asOf = transDate;
85 workspace.doPrevious();
89 // If we've worked through all the models then forward to the server
90 if (i === models.length) {
92 that.doProcessingChanged({isProcessing: true});
93 dispOptions.success = function () {
94 that.doProcessingChanged({isProcessing: false});
96 transModule.transactItem(data, dispOptions, transFunction);
101 // Else if there's something here we can transact, handle it
104 toTransact = model.get(model.quantityAttribute);
105 if (toTransact === null) {
106 toTransact = model.get("balance");
108 transDate = model.transactionDate;
110 // See if there's anything to transact here
111 if (toTransact || transactStock) {
113 // If prompt or distribution detail required,
114 // open a workspace to handle it
115 if (prompt || model.undistributed()) {
117 workspace: transWorkspace,
121 success: function (model) {
122 model.transactionDate = transDate;
126 // Otherwise just use the data we have
128 options.asOf = transDate;
129 options.detail = model.formatDetail();
132 quantity: toTransact,
139 // Nothing to transact, move on
147 transactAll: function () {
148 var models = this.getValue().models;
149 this.transact(models);
151 transactLine: function () {
152 var models = this.selectedModels();
153 this.transact(models);
155 transactItem: function () {
156 var models = this.selectedModels();
157 this.transact(models, true, true);
159 returnItem: function () {
160 var models = this.selectedModels(),
167 transModule = that.getTransModule();
169 for (i = 0; i < models.length; i++) {
171 qtyTransacted = model.get(model.quantityTransactedAttribute);
173 // See if there's anything to transact here
180 that.doProcessingChanged({isProcessing: true});
181 options.success = function () {
182 that.doProcessingChanged({isProcessing: false});
184 transModule.returnItem(data, options);
187 selectedModels: function () {
188 var collection = this.getValue(),
192 if (collection.length) {
193 selected = this.getSelection().selected;
194 for (prop in selected) {
195 if (selected.hasOwnProperty(prop)) {
196 models.push(this.getModel(prop - 0));