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: "",
27 onShipmentChanged: "",
31 onBarcodeCapture: "captureBarcode"
34 showDeleteAction: false,
37 {name: "transactItem", prerequisite: "canTransactItem",
38 method: "transactItem", notify: false, isViewMethod: true},
39 {name: "transactLine", prerequisite: "canTransactItem",
40 method: "transactLine", notify: false, isViewMethod: true},
41 {name: "returnLine", prerequisite: "canReturnItem",
42 method: "returnItem", notify: false, isViewMethod: true}
44 captureBarcode: function (inSender, inEvent) {
45 var models = _.filter(this.value.models, function (model) {
46 // match on upc code or item number
47 return model.getValue("itemSite.item.barcode") === inEvent.data ||
48 model.getValue("itemSite.item.number") === inEvent.data;
50 if (models.length > 0) {
51 this.transact(models, true, true);
53 inEvent.noItemFound = true;
56 this.doUpdateHeader(inEvent);
59 Helper function for transacting `transact` on an array of models.
62 @param {Boolean} Prompt user for confirmation on every model
63 @param {String} Optional to handle the transaction function name, if not passed
64 it will use the published value. Used by ReturnMaterial's actions.
65 @param {String} Optional to handle the workspace name, if not passed
66 it will use the published value. Used by ReturnMaterial's actions.
67 @param {String} Optional to handle the quantity attr name, if not passed
68 it will use the model.quantityAttribute. Used by ReturnMaterial's actions.
70 transact: function (models, prompt, transFunction, transWorkspace, transQty) {
76 // Recursively transact everything we can
77 // #refactor see a simpler implementation of this sort of thing
78 // using async in inventory's ReturnListItem stomp
79 callback = function (workspace, transFunction, transWorkspace, transQty) {
88 transModule = that.getTransModule();
90 transFunction = transFunction || that.getTransFunction();
91 transWorkspace = transWorkspace || that.getTransWorkspace();
93 that._printModels = [];
95 // If argument is false, this whole process was cancelled
96 if (workspace === false) {
99 // If a workspace brought us here, process the information it obtained
100 } else if (workspace) {
101 model = workspace.getValue();
102 toTransact = transQty ? model.get(transQty) : model.get(model.quantityAttribute);
103 transDate = model.transactionDate;
106 if (workspace._printAfterPersist) {
107 that._printModels.push(model);
111 if (transFunction === "receipt") {
112 wsOptions.freight = model.get("freight");
114 wsOptions.detail = model.formatDetail();
115 wsOptions.asOf = transDate;
118 quantity: toTransact,
123 workspace.doPrevious();
127 // If we've worked through all the models then forward to the server
128 if (i === models.length) {
130 that.doProcessingChanged({isProcessing: true});
131 dispOptions.success = function () {
132 _.each(that._printModels, function (printModel) {
133 // XXX eventually replace _auxilliaryInfo with meta, probably
134 printModel.doPrint(printModel._auxilliaryInfo);
136 that.doProcessingChanged({isProcessing: false});
138 dispOptions.error = function () {
139 that.doProcessingChanged({isProcessing: false});
141 transModule.transactItem(data, dispOptions, transFunction);
146 // Else if there's something here we can transact, handle it
149 toTransact = transQty ? model.get(transQty) : model.get(model.quantityAttribute);
150 if (toTransact === null) {
151 toTransact = model.get("balance");
153 transDate = model.transactionDate;
155 // See if there's anything to transact here
156 if (toTransact || prompt) {
158 // If prompt or distribution detail required,
159 // open a workspace to handle it
160 if (prompt || model.undistributed() || model.requiresDetail()) {
162 workspace: transWorkspace,
166 success: function (model) {
167 model.transactionDate = transDate;
171 // Otherwise just use the data we have
173 if (transFunction === "receipt") {
174 options.freight = model.get("freight");
176 options.asOf = transDate;
177 options.detail = model.formatDetail();
180 quantity: toTransact,
184 callback(null, transFunction, transWorkspace, transQty);
187 // Nothing to transact, move on
189 callback(null, transFunction, transWorkspace, transQty);
193 callback(null, transFunction, transWorkspace, transQty);
195 transactAll: function () {
196 var models = this.getValue().models;
197 this.transact(models);
199 transactLine: function () {
200 var models = this.selectedModels();
201 this.transact(models);
203 transactItem: function () {
204 var models = this.selectedModels();
205 this.transact(models, true);
207 returnItem: function () {
208 var models = this.selectedModels(),
215 transModule = that.getTransModule();
217 for (i = 0; i < models.length; i++) {
219 qtyTransacted = model.get(model.quantityTransactedAttribute);
221 // See if there's anything to transact here
228 that.doProcessingChanged({isProcessing: true});
229 options.success = function () {
230 that.doProcessingChanged({isProcessing: false});
232 transModule.returnItem(data, options);
235 selectedModels: function () {
236 var collection = this.getValue(),
240 if (collection.length) {
241 selected = this.getSelection().selected;
242 for (prop in selected) {
243 if (selected.hasOwnProperty(prop)) {
244 models.push(this.getModel(prop - 0));