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 if (transFunction === "receipt") {
79 wsOptions.freight = model.get("freight");
81 wsOptions.detail = model.formatDetail();
82 wsOptions.asOf = transDate;
90 workspace.doPrevious();
94 // If we've worked through all the models then forward to the server
95 if (i === models.length) {
97 that.doProcessingChanged({isProcessing: true});
98 dispOptions.success = function () {
99 that.doProcessingChanged({isProcessing: false});
101 transModule.transactItem(data, dispOptions, transFunction);
106 // Else if there's something here we can transact, handle it
109 toTransact = model.get(model.quantityAttribute);
110 if (toTransact === null) {
111 toTransact = model.get("balance");
113 transDate = model.transactionDate;
115 // See if there's anything to transact here
116 if (toTransact || transactStock) {
118 // If prompt or distribution detail required,
119 // open a workspace to handle it
120 if (prompt || model.undistributed()) {
122 workspace: transWorkspace,
126 success: function (model) {
127 model.transactionDate = transDate;
131 // Otherwise just use the data we have
133 if (transFunction === "receipt") {
134 options.freight = model.get("freight");
136 options.asOf = transDate;
137 options.detail = model.formatDetail();
140 quantity: toTransact,
147 // Nothing to transact, move on
155 transactAll: function () {
156 var models = this.getValue().models;
157 this.transact(models);
159 transactLine: function () {
160 var models = this.selectedModels();
161 this.transact(models);
163 transactItem: function () {
164 var models = this.selectedModels();
165 this.transact(models, true, true);
167 returnItem: function () {
168 var models = this.selectedModels(),
175 transModule = that.getTransModule();
177 for (i = 0; i < models.length; i++) {
179 qtyTransacted = model.get(model.quantityTransactedAttribute);
181 // See if there's anything to transact here
188 that.doProcessingChanged({isProcessing: true});
189 options.success = function () {
190 that.doProcessingChanged({isProcessing: false});
192 transModule.returnItem(data, options);
195 selectedModels: function () {
196 var collection = this.getValue(),
200 if (collection.length) {
201 selected = this.getSelection().selected;
202 for (prop in selected) {
203 if (selected.hasOwnProperty(prop)) {
204 models.push(this.getModel(prop - 0));