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",
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 // #refactor see a simpler implementation of this sort of thing
53 // using async in inventory's ReturnListItem stomp
54 callback = function (workspace) {
63 transModule = that.getTransModule(),
64 transFunction = that.getTransFunction(),
65 transWorkspace = that.getTransWorkspace();
67 // If argument is false, this whole process was cancelled
68 if (workspace === false) {
71 // If a workspace brought us here, process the information it obtained
72 } else if (workspace) {
73 model = workspace.getValue();
74 toTransact = model.get(model.quantityAttribute);
75 transDate = model.transactionDate;
78 wsOptions.detail = model.formatDetail();
79 wsOptions.asOf = transDate;
87 workspace.doPrevious();
91 // If we've worked through all the models then forward to the server
92 if (i === models.length) {
94 that.doProcessingChanged({isProcessing: true});
95 dispOptions.success = function () {
96 that.doProcessingChanged({isProcessing: false});
98 transModule.transactItem(data, dispOptions, transFunction);
103 // Else if there's something here we can transact, handle it
106 toTransact = model.get(model.quantityAttribute);
107 if (toTransact === null) {
108 toTransact = model.get("balance");
110 transDate = model.transactionDate;
112 // See if there's anything to transact here
113 if (toTransact || transactStock) {
115 // If prompt or distribution detail required,
116 // open a workspace to handle it
117 if (prompt || model.undistributed()) {
119 workspace: transWorkspace,
123 success: function (model) {
124 model.transactionDate = transDate;
128 // Otherwise just use the data we have
130 options.asOf = transDate;
131 options.detail = model.formatDetail();
134 quantity: toTransact,
141 // Nothing to transact, move on
149 transactAll: function () {
150 var models = this.getValue().models;
151 this.transact(models);
153 transactLine: function () {
154 var models = this.selectedModels();
155 this.transact(models);
157 transactItem: function () {
158 var models = this.selectedModels();
159 this.transact(models, true, true);
161 returnItem: function () {
162 var models = this.selectedModels(),
169 transModule = that.getTransModule();
171 for (i = 0; i < models.length; i++) {
173 qtyTransacted = model.get(model.quantityTransactedAttribute);
175 // See if there's anything to transact here
182 that.doProcessingChanged({isProcessing: true});
183 options.success = function () {
184 that.doProcessingChanged({isProcessing: false});
186 transModule.returnItem(data, options);
189 selectedModels: function () {
190 var collection = this.getValue(),
194 if (collection.length) {
195 selected = this.getSelection().selected;
196 for (prop in selected) {
197 if (selected.hasOwnProperty(prop)) {
198 models.push(this.getModel(prop - 0));