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 // If argument is false, this whole process was cancelled
82 if (workspace === false) {
85 // If a workspace brought us here, process the information it obtained
86 } else if (workspace) {
87 model = workspace.getValue();
88 toTransact = model.get(model.quantityAttribute);
89 transDate = model.transactionDate;
92 if (transFunction === "receipt") {
93 wsOptions.freight = model.get("freight");
95 wsOptions.detail = model.formatDetail();
96 wsOptions.asOf = transDate;
104 workspace.doPrevious();
108 // If we've worked through all the models then forward to the server
109 if (i === models.length) {
111 that.doProcessingChanged({isProcessing: true});
112 dispOptions.success = function () {
113 that.doProcessingChanged({isProcessing: false});
115 dispOptions.error = function () {
116 that.doProcessingChanged({isProcessing: false});
118 transModule.transactItem(data, dispOptions, transFunction);
123 // Else if there's something here we can transact, handle it
126 toTransact = model.get(model.quantityAttribute);
127 if (toTransact === null) {
128 toTransact = model.get("balance");
130 transDate = model.transactionDate;
132 // See if there's anything to transact here
133 if (toTransact || transactStock) {
135 // If prompt or distribution detail required,
136 // open a workspace to handle it
137 if (prompt || model.undistributed()) {
139 workspace: transWorkspace,
143 success: function (model) {
144 model.transactionDate = transDate;
148 // Otherwise just use the data we have
150 if (transFunction === "receipt") {
151 options.freight = model.get("freight");
153 options.asOf = transDate;
154 options.detail = model.formatDetail();
157 quantity: toTransact,
164 // Nothing to transact, move on
172 transactAll: function () {
173 var models = this.getValue().models;
174 this.transact(models);
176 transactLine: function () {
177 var models = this.selectedModels();
178 this.transact(models);
180 transactItem: function () {
181 var models = this.selectedModels();
182 this.transact(models, true, true);
184 returnItem: function () {
185 var models = this.selectedModels(),
192 transModule = that.getTransModule();
194 for (i = 0; i < models.length; i++) {
196 qtyTransacted = model.get(model.quantityTransactedAttribute);
198 // See if there's anything to transact here
205 that.doProcessingChanged({isProcessing: true});
206 options.success = function () {
207 that.doProcessingChanged({isProcessing: false});
209 transModule.returnItem(data, options);
212 selectedModels: function () {
213 var collection = this.getValue(),
217 if (collection.length) {
218 selected = this.getSelection().selected;
219 for (prop in selected) {
220 if (selected.hasOwnProperty(prop)) {
221 models.push(this.getModel(prop - 0));