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 /** @lends XV.TransactionList */{
17 name: "XV.TransactionList",
25 onProcessingChanged: "",
30 onBarcodeCapture: "captureBarcode"
33 showDeleteAction: false,
36 {name: "transactItem", prerequisite: "canTransactItem",
37 method: "transactItem", notify: false, isViewMethod: true},
38 {name: "transactLine", prerequisite: "canTransactItem",
39 method: "transactLine", notify: false, isViewMethod: true},
40 {name: "returnLine", prerequisite: "canReturnItem",
41 method: "returnItem", notify: false, isViewMethod: true}
43 captureBarcode: function (inSender, inEvent) {
44 var models = _.filter(this.value.models, function (model) {
45 // match on upc code or item number
46 return model.getValue("itemSite.item.barcode") === inEvent.data ||
47 model.getValue("itemSite.item.number") === inEvent.data;
49 if (models.length > 0) {
50 this.transact(models, true, true);
54 Helper function for transacting `transact` on an array of models
57 @param {Boolean} Prompt user for confirmation on every model
59 transact: function (models, prompt, transactStock) {
65 // Recursively transact everything we can
66 // #refactor see a simpler implementation of this sort of thing
67 // using async in inventory's ReturnListItem stomp
68 callback = function (workspace) {
77 transModule = that.getTransModule(),
78 transFunction = that.getTransFunction(),
79 transWorkspace = that.getTransWorkspace();
81 that._printModels = [];
83 // If argument is false, this whole process was cancelled
84 if (workspace === false) {
87 // If a workspace brought us here, process the information it obtained
88 } else if (workspace) {
89 model = workspace.getValue();
90 toTransact = model.get(model.quantityAttribute);
91 transDate = model.transactionDate;
94 if (workspace._printAfterPersist) {
95 that._printModels.push(model);
99 if (transFunction === "receipt") {
100 wsOptions.freight = model.get("freight");
102 wsOptions.detail = model.formatDetail();
103 wsOptions.asOf = transDate;
106 quantity: toTransact,
111 workspace.doPrevious();
115 // If we've worked through all the models then forward to the server
116 if (i === models.length) {
118 that.doProcessingChanged({isProcessing: true});
119 dispOptions.success = function () {
120 _.each(that._printModels, function (printModel) {
121 // XXX eventually replace _auxilliaryInfo with meta, probably
122 printModel.doPrint(printModel._auxilliaryInfo);
124 that.doProcessingChanged({isProcessing: false});
126 dispOptions.error = function () {
127 that.doProcessingChanged({isProcessing: false});
129 transModule.transactItem(data, dispOptions, transFunction);
134 // Else if there's something here we can transact, handle it
137 toTransact = model.get(model.quantityAttribute);
138 if (toTransact === null) {
139 toTransact = model.get("balance");
141 transDate = model.transactionDate;
143 // See if there's anything to transact here
144 if (toTransact || transactStock) {
146 // If prompt or distribution detail required,
147 // open a workspace to handle it
148 if (prompt || model.undistributed()) {
150 workspace: transWorkspace,
154 success: function (model) {
155 model.transactionDate = transDate;
159 // Otherwise just use the data we have
161 if (transFunction === "receipt") {
162 options.freight = model.get("freight");
164 options.asOf = transDate;
165 options.detail = model.formatDetail();
168 quantity: toTransact,
175 // Nothing to transact, move on
183 transactAll: function () {
184 var models = this.getValue().models;
185 this.transact(models);
187 transactLine: function () {
188 var models = this.selectedModels();
189 this.transact(models);
191 transactItem: function () {
192 var models = this.selectedModels();
193 this.transact(models, true, true);
195 returnItem: function () {
196 var models = this.selectedModels(),
203 transModule = that.getTransModule();
205 for (i = 0; i < models.length; i++) {
207 qtyTransacted = model.get(model.quantityTransactedAttribute);
209 // See if there's anything to transact here
216 that.doProcessingChanged({isProcessing: true});
217 options.success = function () {
218 that.doProcessingChanged({isProcessing: false});
220 transModule.returnItem(data, options);
223 selectedModels: function () {
224 var collection = this.getValue(),
228 if (collection.length) {
229 selected = this.getSelection().selected;
230 for (prop in selected) {
231 if (selected.hasOwnProperty(prop)) {
232 models.push(this.getModel(prop - 0));