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