merchi_sdk_js 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. package/dist/address.js +109 -0
  2. package/dist/assignment.js +175 -0
  3. package/dist/automatic_payment_relationship.js +72 -0
  4. package/dist/backup.js +32 -0
  5. package/dist/bank.js +25 -0
  6. package/dist/cart.js +133 -0
  7. package/dist/cart_item.js +71 -0
  8. package/dist/cart_shipment_group.js +23 -0
  9. package/dist/cart_shipment_quote.js +26 -0
  10. package/dist/category.js +68 -0
  11. package/dist/company.js +248 -0
  12. package/dist/company_invitation.js +70 -0
  13. package/dist/component.js +107 -0
  14. package/dist/component_tag.js +60 -0
  15. package/dist/component_version.js +21 -0
  16. package/dist/country_tax.js +93 -0
  17. package/dist/dictionary.js +130 -0
  18. package/dist/discount.js +22 -0
  19. package/dist/discount_group.js +18 -0
  20. package/dist/domain.js +245 -0
  21. package/dist/domain_invitation.js +17 -0
  22. package/dist/domain_tag.js +87 -0
  23. package/dist/domain_types.js +22 -0
  24. package/dist/draft.js +97 -0
  25. package/dist/draft_comment.js +45 -0
  26. package/dist/draft_template.js +39 -0
  27. package/dist/email_address.js +34 -0
  28. package/dist/email_counter.js +47 -0
  29. package/dist/enrolled_domain.js +88 -0
  30. package/dist/exchange_rate.js +66 -0
  31. package/dist/field_types.js +19 -0
  32. package/dist/helpers.js +86 -0
  33. package/dist/internal_tag.js +98 -0
  34. package/dist/inventory.js +100 -0
  35. package/dist/inventory_unit_variation.js +19 -0
  36. package/dist/invoice.js +225 -0
  37. package/dist/invoice_types.js +11 -0
  38. package/dist/item.js +25 -0
  39. package/dist/job.js +536 -0
  40. package/dist/job_comment.js +45 -0
  41. package/dist/job_status.js +47 -0
  42. package/dist/matching_inventory.js +21 -0
  43. package/dist/md5.js +149 -0
  44. package/dist/menu.js +37 -0
  45. package/dist/menu_item.js +24 -0
  46. package/dist/merchi.js +1004 -0
  47. package/dist/merchi_file.js +165 -0
  48. package/dist/model.js +753 -0
  49. package/dist/notification.js +151 -0
  50. package/dist/notification_types.js +199 -0
  51. package/dist/output.cjs.js +31317 -0
  52. package/dist/output.esm.js +31312 -0
  53. package/dist/page.js +41 -0
  54. package/dist/payment.js +32 -0
  55. package/dist/payment_device.js +21 -0
  56. package/dist/payment_types.js +20 -0
  57. package/dist/phone_number.js +37 -0
  58. package/dist/product.js +288 -0
  59. package/dist/product_types.js +32 -0
  60. package/dist/production_comment.js +44 -0
  61. package/dist/quote.js +91 -0
  62. package/dist/quote_item.js +59 -0
  63. package/dist/roles.js +29 -0
  64. package/dist/seo_domain_page.js +42 -0
  65. package/dist/session.js +103 -0
  66. package/dist/set.js +29 -0
  67. package/dist/shipment.js +181 -0
  68. package/dist/shipment_item.js +17 -0
  69. package/dist/shipment_item_fulfillment.js +17 -0
  70. package/dist/shipment_method.js +81 -0
  71. package/dist/shipment_method_variation.js +38 -0
  72. package/dist/subscription_plan.js +75 -0
  73. package/dist/supply_domain.js +65 -0
  74. package/dist/system_role.js +12 -0
  75. package/dist/theme.js +180 -0
  76. package/dist/theme_css_setting.js +61 -0
  77. package/dist/theme_status.js +11 -0
  78. package/dist/user.js +409 -0
  79. package/dist/user_company.js +19 -0
  80. package/dist/user_types.js +23 -0
  81. package/dist/uuid.js +12 -0
  82. package/dist/variation.js +233 -0
  83. package/dist/variation_field.js +233 -0
  84. package/dist/variation_fields_option.js +41 -0
  85. package/dist/variation_option.js +62 -0
  86. package/dist/variations_group.js +43 -0
  87. package/dist/white_label_accessibilities.js +11 -0
  88. package/package.json +30 -0
  89. package/src/address.js +107 -0
  90. package/src/assignment.js +165 -0
  91. package/src/automatic_payment_relationship.js +65 -0
  92. package/src/backup.js +29 -0
  93. package/src/bank.js +21 -0
  94. package/src/cart.js +131 -0
  95. package/src/cart_item.js +71 -0
  96. package/src/cart_shipment_group.js +20 -0
  97. package/src/cart_shipment_quote.js +23 -0
  98. package/src/category.js +62 -0
  99. package/src/company.js +267 -0
  100. package/src/company_invitation.js +63 -0
  101. package/src/component.js +100 -0
  102. package/src/component_tag.js +53 -0
  103. package/src/component_version.js +17 -0
  104. package/src/country_tax.js +89 -0
  105. package/src/dictionary.js +135 -0
  106. package/src/discount.js +19 -0
  107. package/src/discount_group.js +15 -0
  108. package/src/domain.js +254 -0
  109. package/src/domain_invitation.js +13 -0
  110. package/src/domain_tag.js +79 -0
  111. package/src/domain_types.js +18 -0
  112. package/src/draft.js +92 -0
  113. package/src/draft_comment.js +41 -0
  114. package/src/draft_template.js +35 -0
  115. package/src/email_address.js +27 -0
  116. package/src/email_counter.js +42 -0
  117. package/src/enrolled_domain.js +79 -0
  118. package/src/exchange_rate.js +61 -0
  119. package/src/field_types.js +15 -0
  120. package/src/helpers.js +81 -0
  121. package/src/internal_tag.js +90 -0
  122. package/src/inventory.js +99 -0
  123. package/src/inventory_unit_variation.js +18 -0
  124. package/src/invoice.js +224 -0
  125. package/src/invoice_types.js +7 -0
  126. package/src/item.js +22 -0
  127. package/src/job.js +616 -0
  128. package/src/job_comment.js +41 -0
  129. package/src/job_status.js +51 -0
  130. package/src/matching_inventory.js +17 -0
  131. package/src/md5.js +162 -0
  132. package/src/menu.js +32 -0
  133. package/src/menu_item.js +22 -0
  134. package/src/merchi.js +1074 -0
  135. package/src/merchi_file.js +163 -0
  136. package/src/model.js +820 -0
  137. package/src/notification.js +153 -0
  138. package/src/notification_types.js +246 -0
  139. package/src/page.js +38 -0
  140. package/src/payment.js +32 -0
  141. package/src/payment_device.js +17 -0
  142. package/src/payment_types.js +18 -0
  143. package/src/phone_number.js +30 -0
  144. package/src/product.js +309 -0
  145. package/src/product_types.js +28 -0
  146. package/src/production_comment.js +40 -0
  147. package/src/quote.js +89 -0
  148. package/src/quote_item.js +51 -0
  149. package/src/roles.js +27 -0
  150. package/src/seo_domain_page.js +35 -0
  151. package/src/session.js +102 -0
  152. package/src/set.js +28 -0
  153. package/src/shipment.js +191 -0
  154. package/src/shipment_item.js +13 -0
  155. package/src/shipment_item_fulfillment.js +13 -0
  156. package/src/shipment_method.js +73 -0
  157. package/src/shipment_method_variation.js +34 -0
  158. package/src/subscription_plan.js +68 -0
  159. package/src/supply_domain.js +60 -0
  160. package/src/system_role.js +8 -0
  161. package/src/theme.js +188 -0
  162. package/src/theme_css_setting.js +54 -0
  163. package/src/theme_status.js +6 -0
  164. package/src/user.js +442 -0
  165. package/src/user_company.js +15 -0
  166. package/src/user_types.js +19 -0
  167. package/src/uuid.js +3 -0
  168. package/src/variation.js +257 -0
  169. package/src/variation_field.js +261 -0
  170. package/src/variation_fields_option.js +41 -0
  171. package/src/variation_option.js +59 -0
  172. package/src/variations_group.js +43 -0
  173. package/src/white_label_accessibilities.js +6 -0
package/dist/job.js ADDED
@@ -0,0 +1,536 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Job = Job;
7
+ exports.Jobs = Jobs;
8
+ var _uuid = require("./uuid.js");
9
+ var _dictionary = require("./dictionary.js");
10
+ var _model = require("./model.js");
11
+ var _helpers = require("./helpers.js");
12
+ var _job_status = require("./job_status.js");
13
+ var _roles = require("./roles.js");
14
+ var _address = require("./address.js");
15
+ var _assignment = require("./assignment.js");
16
+ var _product = require("./product.js");
17
+ var _country_tax = require("./country_tax.js");
18
+ var _company = require("./company.js");
19
+ var _merchi_file = require("./merchi_file.js");
20
+ var _draft = require("./draft.js");
21
+ var _draft_comment = require("./draft_comment.js");
22
+ var _domain = require("./domain.js");
23
+ var _domain_tag = require("./domain_tag.js");
24
+ var _email_address = require("./email_address.js");
25
+ var _invoice = require("./invoice.js");
26
+ var _notification = require("./notification.js");
27
+ var _shipment = require("./shipment.js");
28
+ var _phone_number = require("./phone_number.js");
29
+ var _matching_inventory = require("./matching_inventory.js");
30
+ var _user = require("./user.js");
31
+ var _variation = require("./variation.js");
32
+ var _variations_group = require("./variations_group.js");
33
+ var _job_comment = require("./job_comment.js");
34
+ var _internal_tag = require("./internal_tag.js");
35
+ function Job() {
36
+ this.resource = '/jobs';
37
+ this.json = 'job';
38
+ this.temporaryId = (0, _uuid.generateUUID)();
39
+ (0, _model.addPropertyTo)(this, 'id');
40
+ (0, _model.addPropertyTo)(this, 'currency');
41
+ (0, _model.addPropertyTo)(this, 'quantity');
42
+ (0, _model.addPropertyTo)(this, 'notes');
43
+ (0, _model.addPropertyTo)(this, 'jobType');
44
+ (0, _model.addPropertyTo)(this, 'product', _product.Product);
45
+ (0, _model.addPropertyTo)(this, 'supplyChainRequestProduct', _product.Product);
46
+ (0, _model.addPropertyTo)(this, 'createdProducts', _product.Product);
47
+ (0, _model.addPropertyTo)(this, 'priority');
48
+ (0, _model.addPropertyTo)(this, 'received');
49
+ (0, _model.addPropertyTo)(this, 'deadline');
50
+ (0, _model.addPropertyTo)(this, 'updated');
51
+ (0, _model.addPropertyTo)(this, 'deductionDate');
52
+ (0, _model.addPropertyTo)(this, 'preDraftCommentsCount');
53
+ (0, _model.addPropertyTo)(this, 'clientFiles', _merchi_file.MerchiFile);
54
+ (0, _model.addPropertyTo)(this, 'productionFiles', _merchi_file.MerchiFile);
55
+ (0, _model.addPropertyTo)(this, 'drafts', _draft.Draft);
56
+ (0, _model.addPropertyTo)(this, 'ownDrafts', _draft.Draft);
57
+ (0, _model.addPropertyTo)(this, 'sharedDrafts', _draft.Draft);
58
+ (0, _model.addPropertyTo)(this, 'draftComments', _draft_comment.DraftComment);
59
+ (0, _model.addPropertyTo)(this, 'comments', _job_comment.JobComment);
60
+ (0, _model.addPropertyTo)(this, 'invoice', _invoice.Invoice);
61
+ (0, _model.addPropertyTo)(this, 'shipment', _shipment.Shipment);
62
+ (0, _model.addPropertyTo)(this, 'client', _user.User);
63
+ (0, _model.addPropertyTo)(this, 'clientEmail', _email_address.EmailAddress);
64
+ (0, _model.addPropertyTo)(this, 'clientPhone', _phone_number.PhoneNumber);
65
+ (0, _model.addPropertyTo)(this, 'clientCompany', _company.Company);
66
+ (0, _model.addPropertyTo)(this, 'clientCompanyEmail', _email_address.EmailAddress);
67
+ (0, _model.addPropertyTo)(this, 'clientCompanyPhone', _phone_number.PhoneNumber);
68
+ (0, _model.addPropertyTo)(this, 'manager', _user.User);
69
+ (0, _model.addPropertyTo)(this, 'designer', _user.User);
70
+ (0, _model.addPropertyTo)(this, 'shipping', _address.Address);
71
+ (0, _model.addPropertyTo)(this, 'dropShip');
72
+ (0, _model.addPropertyTo)(this, 'pickUp');
73
+ (0, _model.addPropertyTo)(this, 'productionShippingAddress', _address.Address);
74
+ (0, _model.addPropertyTo)(this, 'supplyAssignment', _assignment.Assignment);
75
+ (0, _model.addPropertyTo)(this, 'supplyJob', Job);
76
+ (0, _model.addPropertyTo)(this, 'domain', _domain.Domain);
77
+ (0, _model.addPropertyTo)(this, 'cost');
78
+ (0, _model.addPropertyTo)(this, 'taxAmount');
79
+ (0, _model.addPropertyTo)(this, 'totalCost');
80
+ (0, _model.addPropertyTo)(this, 'taxType', _country_tax.CountryTax);
81
+ (0, _model.addPropertyTo)(this, 'costPerUnit');
82
+ (0, _model.addPropertyTo)(this, 'automaticPriceEnabled');
83
+ (0, _model.addPropertyTo)(this, 'tags', _domain_tag.DomainTag);
84
+
85
+ // not embedded by default
86
+ (0, _model.addPropertyTo)(this, 'unreadNotificationsCount');
87
+ (0, _model.addPropertyTo)(this, 'unreadJobInfoNotificationsCount');
88
+ (0, _model.addPropertyTo)(this, 'unreadJobDraftingNotificationsCount');
89
+ (0, _model.addPropertyTo)(this, 'unreadJobProductionNotificationsCount');
90
+ (0, _model.addPropertyTo)(this, 'unreadJobShippingNotificationsCount');
91
+ (0, _model.addPropertyTo)(this, 'unreadJobInvoicingNotificationsCount');
92
+ (0, _model.addPropertyTo)(this, 'matchingInventories', _matching_inventory.MatchingInventory);
93
+ (0, _model.addPropertyTo)(this, 'inventoryCount');
94
+ (0, _model.addPropertyTo)(this, 'inventorySufficient');
95
+ (0, _model.addPropertyTo)(this, 'limitedStock');
96
+ (0, _model.addPropertyTo)(this, 'canDeduct');
97
+ (0, _model.addPropertyTo)(this, 'productionNotes');
98
+ (0, _model.addPropertyTo)(this, "needsDrafting");
99
+ (0, _model.addPropertyTo)(this, "needsGroupBuy");
100
+ (0, _model.addPropertyTo)(this, "needsProduction");
101
+ (0, _model.addPropertyTo)(this, "needsShipping");
102
+ (0, _model.addPropertyTo)(this, "needsInvoicing");
103
+ (0, _model.addPropertyTo)(this, "needsSupplyChainRequest");
104
+ (0, _model.addPropertyTo)(this, 'hasValidVolumes');
105
+ (0, _model.addPropertyTo)(this, 'hasValidWeights');
106
+ (0, _model.addPropertyTo)(this, 'showProductionFilesToClient');
107
+ (0, _model.addPropertyTo)(this, 'allowClientDraftContribution');
108
+ (0, _model.addPropertyTo)(this, 'groupBuyStatus');
109
+ (0, _model.addPropertyTo)(this, 'groupBuyProductionStarted');
110
+ (0, _model.addPropertyTo)(this, 'shippingStatus');
111
+ (0, _model.addPropertyTo)(this, 'designStatus');
112
+ (0, _model.addPropertyTo)(this, 'paymentStatus');
113
+ (0, _model.addPropertyTo)(this, 'productionStatus');
114
+ (0, _model.addPropertyTo)(this, 'supplyChainRequestStatus');
115
+ (0, _model.addPropertyTo)(this, 'assignments', _assignment.Assignment);
116
+ (0, _model.addPropertyTo)(this, 'archived');
117
+ (0, _model.addPropertyTo)(this, 'notifications', _notification.Notification);
118
+ (0, _model.addPropertyTo)(this, 'variationsGroups', _variations_group.VariationsGroup);
119
+ (0, _model.addPropertyTo)(this, 'variations', _variation.Variation);
120
+ (0, _model.addPropertyTo)(this, 'jobVolume');
121
+ (0, _model.addPropertyTo)(this, 'jobWeight');
122
+ (0, _model.addPropertyTo)(this, 'completed');
123
+ (0, _model.addPropertyTo)(this, 'jobInfoApprovedByClient');
124
+ (0, _model.addPropertyTo)(this, 'quoteSet');
125
+ (0, _model.addPropertyTo)(this, 'shopifyShopUrl');
126
+ (0, _model.addPropertyTo)(this, 'shopifyOrderId');
127
+ (0, _model.addPropertyTo)(this, 'shopifyOrderLineItemId');
128
+ (0, _model.addPropertyTo)(this, 'internalTags', _internal_tag.InternalTag);
129
+ this.create = function (success, error, embed, asDomain, withRights) {
130
+ var data = (0, _model.serialise)(this),
131
+ self = this,
132
+ settings = {
133
+ as_domain: asDomain,
134
+ embed: embed,
135
+ error: error,
136
+ files: (0, _model.enumerateFiles)(data[1]),
137
+ parameters: data[0],
138
+ resource: this.resource,
139
+ withRights: withRights
140
+ };
141
+ function handleResponse(result) {
142
+ success((0, _model.fromJson)(self, result[self.json]));
143
+ }
144
+ settings.success = handleResponse;
145
+ (0, _model.create)(settings);
146
+ };
147
+ this.publicCreate = function (success, error) {
148
+ var data = (0, _model.serialise)(this),
149
+ self = this,
150
+ request = new _model.Request(),
151
+ jobType = this.product() && this.product().productType() === 0 ? 'mod' : 'supplier';
152
+ request.data().merge(data[0]);
153
+ request.resource("/public-".concat(jobType, "-quote/"));
154
+ request.method('POST');
155
+ request.query().add('skip_rights', true);
156
+ function handleResponse(status, data) {
157
+ if (status === 201) {
158
+ success((0, _model.fromJson)(self, data[self.json]));
159
+ } else {
160
+ error(data);
161
+ }
162
+ }
163
+ request.responseHandler(handleResponse).errorHandler(error);
164
+ request.send();
165
+ };
166
+ this.get = function (success, error, embed, includeArchived, withRights) {
167
+ var self = this,
168
+ parameters = {
169
+ embed: embed,
170
+ error: error,
171
+ id: this.id(),
172
+ includeArchived: includeArchived,
173
+ withRights: withRights,
174
+ resource: this.resource
175
+ };
176
+ function handleResponse(data) {
177
+ success((0, _model.fromJson)(self, data[self.json], {
178
+ makesDirty: false
179
+ }));
180
+ }
181
+ parameters.success = handleResponse;
182
+ (0, _model.getOne)(parameters);
183
+ };
184
+ this.destroy = function (success, error) {
185
+ (0, _model.deleteOne)(this.resource + "/" + this.id(), success, error);
186
+ };
187
+ this.recover = function (success, error) {
188
+ (0, _model.recoverOne)("jobs", this.id(), success, error);
189
+ };
190
+ this.patch = function (success, error, embed, asDomain, withRights) {
191
+ var self = this,
192
+ data = (0, _model.serialise)(this, undefined, undefined, undefined, {
193
+ excludeOld: true
194
+ })[0],
195
+ domain = Boolean(self.domain()) ? self.domain().id() : null,
196
+ domainId = (0, _helpers.isUndefinedOrNull)(asDomain) ? domain : asDomain,
197
+ settings = {
198
+ as_domain: domainId,
199
+ data: data,
200
+ embed: embed,
201
+ error: error,
202
+ id: this.id(),
203
+ withRights: withRights,
204
+ resource: this.resource
205
+ };
206
+ function handleResponse(data) {
207
+ success((0, _model.fromJson)(self, data[self.json], {
208
+ makesDirty: false
209
+ }));
210
+ }
211
+ settings.success = handleResponse;
212
+ (0, _model.patchOne)(settings);
213
+ };
214
+ this.hasVariations = function () {
215
+ var variations = this.variations();
216
+ return Boolean(variations) && variations.length > 0;
217
+ };
218
+ this.hasVariationsGroups = function () {
219
+ var groups = this.variationsGroups();
220
+ return Boolean(groups) && groups.length > 0;
221
+ };
222
+ this.variationGroupsTotalQuantity = function () {
223
+ var self = this,
224
+ groups = Boolean(self.variationsGroups()) ? self.variationsGroups() : [],
225
+ totalQuantity = 0,
226
+ group,
227
+ groupQuantity,
228
+ i;
229
+ for (i = 0; i < groups.length; i++) {
230
+ group = groups[i];
231
+ groupQuantity = isNaN(group.quantity()) ? 0 : group.quantity();
232
+ totalQuantity += parseInt(groupQuantity, 10);
233
+ }
234
+ return totalQuantity;
235
+ };
236
+ this.productTotalCost = function () {
237
+ var costPerUnit = this.costPerUnit() ? this.costPerUnit() : 0,
238
+ qty = this.quantity() ? this.quantity() : 0;
239
+ return costPerUnit * qty;
240
+ };
241
+ this.loopVariationsAndReturnAttributeTotal = function (attribute) {
242
+ var variations = this.variations() ? this.variations() : [],
243
+ total = 0,
244
+ i;
245
+ for (i = 0; i < variations.length; i++) {
246
+ total += variations[i][attribute]();
247
+ }
248
+ return parseFloat(total).toFixed(2);
249
+ };
250
+ this.variationsUnitCostAndOnceOffCost = function () {
251
+ return this.loopVariationsAndReturnAttributeTotal('unitCostAndOnceOffCost');
252
+ };
253
+ this.variationsTotalCost = function () {
254
+ return this.loopVariationsAndReturnAttributeTotal('unitCostTotalAndOnceOffCost');
255
+ };
256
+ this.assignmentsUnarchived = function () {
257
+ var assignments = this.assignments() ? this.assignments() : [],
258
+ unarchived = [],
259
+ i;
260
+ for (i = 0; i < assignments.length; i++) {
261
+ if (!assignments[i].archived()) {
262
+ unarchived.push(assignments[i]);
263
+ }
264
+ }
265
+ return unarchived;
266
+ };
267
+ this.productionAcceptedAssignment = function () {
268
+ var assignments = this.assignmentsUnarchived(),
269
+ i;
270
+ for (i = 0; i < assignments.length; i++) {
271
+ if (assignments[i].managerAccepts()) {
272
+ return assignments[i];
273
+ }
274
+ }
275
+ return null;
276
+ };
277
+ this.productionQuotingComplete = function () {
278
+ return this.productionStatus() >= _job_status.jobStatusProduction.get('ASSIGN_DEADLINE_REACHED');
279
+ };
280
+ this.sectionReached = function (jobAttribute, sectionState) {
281
+ var job = this,
282
+ section = job[jobAttribute]();
283
+ return section && section >= sectionState;
284
+ };
285
+ this.productionComplete = function () {
286
+ var isShipped = this.sectionReached('productionStatus', _job_status.jobStatusProduction.get('SHIPPED'));
287
+ var isCompleted = this.sectionReached('productionStatus', _job_status.jobStatusProduction.get('COMPLETED'));
288
+ return isShipped || isCompleted || !this.needsProduction();
289
+ };
290
+ this.draftingComplete = function () {
291
+ return this.sectionReached('designStatus', _job_status.jobStatusDrafting.get('DRAFTING_APPROVED')) || !this.needsDrafting();
292
+ };
293
+ this.paymentComplete = function () {
294
+ return this.sectionReached('paymentStatus', _job_status.jobStatusPayment.get('FULLY_PAID'));
295
+ };
296
+ this.shippingComplete = function () {
297
+ return this.sectionReached('shippingStatus', _job_status.jobStatusShipment.get('RECEIVED')) || !this.needsShipping();
298
+ };
299
+ this.isComplete = function () {
300
+ return this.productionComplete() && this.draftingComplete() && this.paymentComplete() && this.shippingComplete();
301
+ };
302
+ this.assignmentArrayIndexById = function (assignmentId) {
303
+ return this.assignments().findIndex(function (assignment) {
304
+ return assignmentId === assignment.id();
305
+ });
306
+ };
307
+ this.setAssignment = function (assignment) {
308
+ var assignmentIndex = this.assignmentArrayIndexById(assignment.id()),
309
+ assignments = this.assignments();
310
+ assignments[assignmentIndex] = assignment;
311
+ return assignments;
312
+ };
313
+ this.assignmentBySupplier = function (supplier) {
314
+ var assignments = this.assignmentsUnarchived(),
315
+ i;
316
+ for (i = 0; i < assignments.length; i++) {
317
+ if (assignments[i].isUserSupplier(supplier)) {
318
+ return assignments[i];
319
+ }
320
+ }
321
+ return null;
322
+ };
323
+ this.findAssignmentById = function (assignmentId) {
324
+ var self = this,
325
+ index = self.assignmentArrayIndexById(assignmentId);
326
+ if (!isNaN(index) && index !== -1) {
327
+ return self.assignments()[index];
328
+ }
329
+ return null;
330
+ };
331
+ this.fetchAndUpdateAssignmentById = function (success, error, assignmentId, embed) {
332
+ var self = this,
333
+ assignment = self.findAssignmentById(assignmentId),
334
+ index = self.assignmentArrayIndexById(assignmentId);
335
+ if (Boolean(assignment)) {
336
+ assignment.get(function (latestAssignment) {
337
+ self.assignments()[index] = latestAssignment;
338
+ success();
339
+ }, error, embed);
340
+ } else {
341
+ error();
342
+ }
343
+ };
344
+ this.assignedSupplierIdArray = function () {
345
+ // return an array of suppliers who have assignments
346
+ var assignments = this.assignmentsUnarchived(),
347
+ supplierIds = [],
348
+ i;
349
+ for (i = 0; i < assignments.length; i++) {
350
+ supplierIds.push(assignments[i].supplier().id());
351
+ }
352
+ return supplierIds;
353
+ };
354
+ this.updateDateOfAssignments = function (newDate, dateAttribute) {
355
+ var assignments = this.assignmentsUnarchived(),
356
+ i;
357
+ for (i = 0; i < assignments.length; i++) {
358
+ // new date should be in current user unix local time
359
+ assignments[i][dateAttribute](newDate);
360
+ }
361
+ return assignments;
362
+ };
363
+ this.firstAssignment = function () {
364
+ return this.assignmentsUnarchived()[0];
365
+ };
366
+ this.productionShipment = function () {
367
+ var acceptedAssignment = this.productionAcceptedAssignment();
368
+ return Boolean(acceptedAssignment) ? acceptedAssignment.shipment() : null;
369
+ };
370
+ this.productionDeadline = function () {
371
+ var firstAssignment = this.firstAssignment();
372
+ return firstAssignment ? firstAssignment.productionDeadline() : null;
373
+ };
374
+ this.assignmentDeadline = function () {
375
+ var firstAssignment = this.firstAssignment();
376
+ return firstAssignment ? firstAssignment.assignmentDeadline() : null;
377
+ };
378
+ this.productionAssignmentDeadline = function () {
379
+ return this.assignmentDeadline();
380
+ };
381
+ this.originalProduct = function () {
382
+ var product = this.product();
383
+ if (product) {
384
+ var original = product.originalProduct();
385
+ return original ? original : product;
386
+ }
387
+ return product;
388
+ };
389
+ this.draftsYoungestToEldest = function () {
390
+ var drafts = this.drafts();
391
+ return drafts ? (0, _helpers.sortArrayByObjectKeyDescending)(drafts, 'date') : [];
392
+ };
393
+ this.draftsEldestToYoungest = function () {
394
+ var drafts = this.drafts();
395
+ return drafts ? (0, _helpers.sortArrayByObjectKey)(drafts, 'date') : [];
396
+ };
397
+ this.currentDraft = function () {
398
+ return this.draftsYoungestToEldest()[0];
399
+ };
400
+ this.draftIndexEldestToYoungest = function (draft) {
401
+ return this.draftsEldestToYoungest().findIndex(function (draftEntity) {
402
+ return draft.id() === draftEntity.id();
403
+ });
404
+ };
405
+ this.draftCommentsYoungestToEldest = function () {
406
+ return (0, _helpers.sortArrayByObjectKeyDescending)(this.draftComments(), 'date');
407
+ };
408
+ this.allDraftCommentsYoungestToEldest = function () {
409
+ var jobDraftComments = this.draftCommentsYoungestToEldest(),
410
+ drafts = this.draftsYoungestToEldest(),
411
+ draftComments = [],
412
+ i;
413
+ for (i = 0; i < drafts.length; i++) {
414
+ draftComments.concat(drafts[i].commentsYoungestToEldest());
415
+ }
416
+ return draftComments.concat(jobDraftComments);
417
+ };
418
+ this.activeDraft = function () {
419
+ var drafts = this.draftsYoungestToEldest();
420
+ return drafts.length > 0 ? drafts[0] : null;
421
+ };
422
+ this.shippingIsValid = function () {
423
+ return this.shipping() && this.shipping().isValid();
424
+ };
425
+ this.userCanViewSection = function (user, allowedRoles) {
426
+ var domain = this.domain();
427
+ return domain ? user.hasAuthority(domain.id(), allowedRoles) : false;
428
+ };
429
+ this.isAdminOrManager = function (user) {
430
+ return user.isAdminOrManager(this.domain().id());
431
+ };
432
+ this.isClient = function (user) {
433
+ var clientId = this.client() ? this.client().id() : null;
434
+ return clientId && user.id() === clientId;
435
+ };
436
+ this.userCanViewInfo = function (user) {
437
+ var manager = _roles.roles.get('manager'),
438
+ admin = _roles.roles.get('admin'),
439
+ designer = _roles.roles.get('designer'),
440
+ sales = _roles.roles.get('sales'),
441
+ supplier = _roles.roles.get('supplier'),
442
+ accountant = _roles.roles.get('accountant');
443
+ return this.userCanViewSection(user, [manager, admin, designer, sales, supplier, accountant]);
444
+ };
445
+ this.userCanViewDrafting = function (user) {
446
+ var client = _roles.roles.get('client'),
447
+ manager = _roles.roles.get('manager'),
448
+ admin = _roles.roles.get('admin'),
449
+ designer = _roles.roles.get('designer');
450
+ return this.userCanViewSection(user, [client, manager, admin, designer]);
451
+ };
452
+ this.userCanViewProduction = function (user) {
453
+ var manager = _roles.roles.get('manager'),
454
+ admin = _roles.roles.get('admin'),
455
+ supplier = _roles.roles.get('supplier');
456
+ return this.userCanViewSection(user, [manager, admin, supplier]);
457
+ };
458
+ this.userCanViewShipping = function (user) {
459
+ var manager = _roles.roles.get('manager'),
460
+ admin = _roles.roles.get('admin'),
461
+ client = _roles.roles.get('client');
462
+ return this.userCanViewSection(user, [manager, admin, client]);
463
+ };
464
+ this.userCanViewInvoice = function (user) {
465
+ var manager = _roles.roles.get('manager'),
466
+ admin = _roles.roles.get('admin'),
467
+ accountant = _roles.roles.get('accountant');
468
+ return this.userCanViewSection(user, [manager, admin, accountant]);
469
+ };
470
+ this.userHasRole = function (user, roles) {
471
+ var domain = this.domain();
472
+ return user.hasAuthority(domain.id(), roles);
473
+ };
474
+ this.tax = function () {
475
+ var domain = this.domain();
476
+ return domain && domain.company() ? domain.company().defaultTaxType() : null;
477
+ };
478
+ this.isUserClient = function (user) {
479
+ var client = this.client();
480
+ return client && client.id() === user.id();
481
+ };
482
+ this.isUserManager = function (user) {
483
+ var manager = this.manager();
484
+ return manager && manager.id() === user.id();
485
+ };
486
+ this.isUserAdminOrManagerOfDomain = function (user) {
487
+ var domain = this.domain();
488
+ return domain ? user.isAdminOrManager(domain.id()) : false;
489
+ };
490
+ this.isUserAssignmentSupplier = function (user) {
491
+ var assignment = this.assignmentBySupplier(user);
492
+ return assignment ? assignment.isUserSupplier(user) : false;
493
+ };
494
+ this.tryDeduct = function (success, error) {
495
+ var request = new _model.Request(),
496
+ data = (0, _model.serialise)(this)[0],
497
+ query = new _dictionary.Dictionary(),
498
+ self = this;
499
+ query.add('embed', JSON.stringify({
500
+ inventory: {}
501
+ }));
502
+ request.resource('/jobs/' + this.id() + '/deduct/');
503
+ request.method('POST');
504
+ request.data().merge(data);
505
+ request.query().merge(query);
506
+ function handleResponse(status, data) {
507
+ if (status === 200) {
508
+ success((0, _model.fromJson)(self, data['job']));
509
+ } else {
510
+ error(data);
511
+ }
512
+ }
513
+ function handleError() {
514
+ error({
515
+ message: 'could not connect to server',
516
+ errorCode: 0
517
+ });
518
+ }
519
+ request.responseHandler(handleResponse).errorHandler(handleError);
520
+ request.send();
521
+ };
522
+ }
523
+ function Jobs() {
524
+ this.resource = '/jobs';
525
+ this.json = 'jobs';
526
+ this.single = Job;
527
+ this.get = function (success, error, parameters, withUpdates) {
528
+ var self = this;
529
+ function handleResponse(result) {
530
+ success((0, _model.fromJsonList)(self, result, {
531
+ makesDirty: false
532
+ }));
533
+ }
534
+ return (0, _model.getList)(this.resource, handleResponse, error, parameters, withUpdates);
535
+ };
536
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JobComment = JobComment;
7
+ var _uuid = require("./uuid.js");
8
+ var _model = require("./model.js");
9
+ var _job = require("./job.js");
10
+ var _user = require("./user.js");
11
+ var _merchi_file = require("./merchi_file.js");
12
+ var _notification = require("./notification.js");
13
+ function JobComment() {
14
+ this.resource = '/job_comments';
15
+ this.json = 'jobComment';
16
+ this.temporaryId = (0, _uuid.generateUUID)();
17
+ (0, _model.addPropertyTo)(this, 'id');
18
+ (0, _model.addPropertyTo)(this, 'job', _job.Job);
19
+ (0, _model.addPropertyTo)(this, 'user', _user.User);
20
+ (0, _model.addPropertyTo)(this, 'file', _merchi_file.MerchiFile);
21
+ (0, _model.addPropertyTo)(this, 'notifications', _notification.Notification);
22
+ (0, _model.addPropertyTo)(this, 'date');
23
+ (0, _model.addPropertyTo)(this, 'text');
24
+ (0, _model.addPropertyTo)(this, 'urgency');
25
+ (0, _model.addPropertyTo)(this, 'subject');
26
+ (0, _model.addPropertyTo)(this, 'sendSms');
27
+ (0, _model.addPropertyTo)(this, 'sendEmail');
28
+ (0, _model.addPropertyTo)(this, 'openToClient');
29
+ this.create = function (options) {
30
+ var data = (0, _model.serialise)(this),
31
+ self = this;
32
+ function handleResponse(result) {
33
+ options.success((0, _model.fromJson)(self, result[self.json]));
34
+ }
35
+ (0, _model.create)({
36
+ resource: this.resource,
37
+ parameters: data[0],
38
+ files: (0, _model.enumerateFiles)(data[1]),
39
+ success: handleResponse,
40
+ as_domain: options.as_domain,
41
+ error: options.error,
42
+ embed: options.embed
43
+ });
44
+ };
45
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.jobStatusShipment = exports.jobStatusProduction = exports.jobStatusPayment = exports.jobStatusDrafting = exports.jobPriority = void 0;
7
+ var _dictionary = require("./dictionary.js");
8
+ var jobStatusPayment = exports.jobStatusPayment = new _dictionary.Dictionary();
9
+ jobStatusPayment.add("INIT", 0);
10
+ jobStatusPayment.add("ISSUED", 1);
11
+ jobStatusPayment.add("OVERDUE", 2);
12
+ jobStatusPayment.add("PARTIAL_PAID", 3);
13
+ jobStatusPayment.add("FULLY_PAID", 4);
14
+ var jobStatusDrafting = exports.jobStatusDrafting = new _dictionary.Dictionary();
15
+ jobStatusDrafting.add("INIT", 0);
16
+ jobStatusDrafting.add("WAIT_DRAFTING", 1);
17
+ jobStatusDrafting.add("CHANGES_REQUESTED", 2);
18
+ jobStatusDrafting.add("DRAFTING_UPLOADED", 3);
19
+ jobStatusDrafting.add("DRAFTING_APPROVED", 4);
20
+ var jobStatusProduction = exports.jobStatusProduction = new _dictionary.Dictionary();
21
+ jobStatusProduction.add("INIT", 0);
22
+ jobStatusProduction.add("REJECTED", 1);
23
+ jobStatusProduction.add("QUOTING", 2);
24
+ jobStatusProduction.add("ASSIGN_SENT", 3);
25
+ jobStatusProduction.add("ASSIGN_DEADLINE_REACHED", 4);
26
+ jobStatusProduction.add("ASSIGN_COMPLETE", 5);
27
+ jobStatusProduction.add("QUESTIONING", 6);
28
+ jobStatusProduction.add("COMMENCED", 7);
29
+ jobStatusProduction.add("FINISHED", 8);
30
+ jobStatusProduction.add("SHIPPED", 9);
31
+ jobStatusProduction.add("COMPLETED", 10);
32
+ var jobStatusShipment = exports.jobStatusShipment = new _dictionary.Dictionary();
33
+ jobStatusShipment.add("NOT_ASSIGNED", 0);
34
+ jobStatusShipment.add("ASSIGNED", 1);
35
+ jobStatusShipment.add("DISPATCH_SET", 2);
36
+ jobStatusShipment.add("DISPATCH_WARNING", 3);
37
+ jobStatusShipment.add("DISPATCH_LATE", 4);
38
+ jobStatusShipment.add("DISPATCHED", 5);
39
+ jobStatusShipment.add("EXPECTED_RECEIVE_DATE_WARNING", 6);
40
+ jobStatusShipment.add("EXPECTED_RECEIVE_DATE_PAST", 7);
41
+ jobStatusShipment.add("RECEIVED", 8);
42
+ jobStatusShipment.add("PICKED_UP", 9);
43
+ var jobPriority = exports.jobPriority = new _dictionary.Dictionary();
44
+ jobPriority.add('urgent', 1);
45
+ jobPriority.add('high', 2);
46
+ jobPriority.add('medium', 3);
47
+ jobPriority.add('low', 4);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MatchingInventory = MatchingInventory;
7
+ var _uuid = require("./uuid.js");
8
+ var _model = require("./model.js");
9
+ var _inventory = require("./inventory.js");
10
+ var _job = require("./job.js");
11
+ var _variations_group = require("./variations_group.js");
12
+ function MatchingInventory() {
13
+ this.resource = '/matching_inventories';
14
+ this.json = 'matching_inventory';
15
+ this.temporaryId = (0, _uuid.generateUUID)();
16
+ (0, _model.addPropertyTo)(this, 'deductionDate');
17
+ (0, _model.addPropertyTo)(this, 'canDeduct');
18
+ (0, _model.addPropertyTo)(this, 'inventory', _inventory.Inventory);
19
+ (0, _model.addPropertyTo)(this, 'job', _job.Job);
20
+ (0, _model.addPropertyTo)(this, 'group', _variations_group.VariationsGroup);
21
+ }