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 showDeleteAction: false,
33 {name: "transactItem", prerequisite: "canTransactItem",
34 method: "transactItem", notify: false, isViewMethod: true},
35 {name: "transactLine", prerequisite: "canTransactItem",
36 method: "transactLine", notify: false, isViewMethod: true},
37 {name: "returnLine", prerequisite: "canReturnItem",
38 method: "returnItem", notify: false, isViewMethod: true}
41 Helper function for transacting `transact` on an array of models
44 @param {Boolean} Prompt user for confirmation on every model
46 transact: function (models, prompt, transactStock) {
52 // Recursively transact everything we can
53 // #refactor see a simpler implementation of this sort of thing
54 // using async in inventory's ReturnListItem stomp
55 callback = function (workspace) {
64 transModule = that.getTransModule(),
65 transFunction = that.getTransFunction(),
66 transWorkspace = that.getTransWorkspace();
68 // If argument is false, this whole process was cancelled
69 if (workspace === false) {
72 // If a workspace brought us here, process the information it obtained
73 } else if (workspace) {
74 model = workspace.getValue();
75 toTransact = model.get(model.quantityAttribute);
76 transDate = model.transactionDate;
79 if (transFunction === "receipt") {
80 wsOptions.freight = model.get("freight");
82 wsOptions.detail = model.formatDetail();
83 wsOptions.asOf = transDate;
91 workspace.doPrevious();
95 // If we've worked through all the models then forward to the server
96 if (i === models.length) {
98 that.doProcessingChanged({isProcessing: true});
99 dispOptions.success = function () {
100 that.doProcessingChanged({isProcessing: false});
102 dispOptions.error = function () {
103 that.doProcessingChanged({isProcessing: false});
105 transModule.transactItem(data, dispOptions, transFunction);
110 // Else if there's something here we can transact, handle it
113 toTransact = model.get(model.quantityAttribute);
114 if (toTransact === null) {
115 toTransact = model.get("balance");
117 transDate = model.transactionDate;
119 // See if there's anything to transact here
120 if (toTransact || transactStock) {
122 // If prompt or distribution detail required,
123 // open a workspace to handle it
124 if (prompt || model.undistributed()) {
126 workspace: transWorkspace,
130 success: function (model) {
131 model.transactionDate = transDate;
135 // Otherwise just use the data we have
137 if (transFunction === "receipt") {
138 options.freight = model.get("freight");
140 options.asOf = transDate;
141 options.detail = model.formatDetail();
144 quantity: toTransact,
151 // Nothing to transact, move on
159 transactAll: function () {
160 var models = this.getValue().models;
161 this.transact(models);
163 transactLine: function () {
164 var models = this.selectedModels();
165 this.transact(models);
167 transactItem: function () {
168 var models = this.selectedModels();
169 this.transact(models, true, true);
171 returnItem: function () {
172 var models = this.selectedModels(),
179 transModule = that.getTransModule();
181 for (i = 0; i < models.length; i++) {
183 qtyTransacted = model.get(model.quantityTransactedAttribute);
185 // See if there's anything to transact here
192 that.doProcessingChanged({isProcessing: true});
193 options.success = function () {
194 that.doProcessingChanged({isProcessing: false});
196 transModule.returnItem(data, options);
199 selectedModels: function () {
200 var collection = this.getValue(),
204 if (collection.length) {
205 selected = this.getSelection().selected;
206 for (prop in selected) {
207 if (selected.hasOwnProperty(prop)) {
208 models.push(this.getModel(prop - 0));