-
Notifications
You must be signed in to change notification settings - Fork 5
/
MobileService.txt
643 lines (460 loc) · 16.2 KB
/
MobileService.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
Перем Параметры;
//=================================================
Function PrepareString(Стр)
//Стр = СтрЗаменить(Стр,"\", " "); // x5c
//Стр = СтрЗаменить(Стр,"/", " "); // x2f
//Стр = СтрЗаменить(Стр,Символ(008), "\b"), // x08
Стр = СтрЗаменить(Стр,СимволТабуляции, " "); // x09
Стр = СтрЗаменить(Стр,РазделительСтрок, " "); // x0a
//Стр = СтрЗаменить(Стр,Символы.ПФ, "\f"), // x0c
//Стр = СтрЗаменить(Стр,Символы.ВК, "\r"), // x0d
//Стр = СтрЗаменить(Стр,"і","i");
//Стр = СтрЗаменить(Стр,"ї","i");
//Стр = СтрЗаменить(Стр,"І","I");
//Стр = СтрЗаменить(Стр,"є","е");
//Стр = СтрЗаменить(Стр,"Є","Е");
//Стр = СтрЗаменить(Стр,",",".");
Стр = СтрЗаменить(Стр,"""","");
//Стр = ПреобразоватьСтрокуВУТФ8(СокрЛП(Стр));
//Стр = СтрЗаменить(Стр,","," ");
//Стр = СтрЗаменить(Стр," "," ");
//Если ПустаяСтрока(Стр) = 1 Тогда
// Стр = Пусто;
//КонецЕсли;
Return Стр;
EndFunction
//=============================================
Function ConvertListToJSONObject(valueList)
stringResult = "{";
For i=1 To valueList.GetListSize() Do
key = "";
value = valueList.GetValue(i, key);
stringResult = stringResult+""""+key+""":";
Если Лев(value,1) = "#" Тогда
digits = Mid(value, 2, 1);
value = Mid(value,3);
stringResult = stringResult+Формат(value,"Ч."+digits+".");
ИначеЕсли ПустоеЗначение(value) = 1 Тогда
stringResult = stringResult+"null";
Иначе
stringResult = stringResult+""""+PrepareString(value)+"""";
КонецЕсли;
Если i<valueList.GetListSize() Тогда
stringResult = stringResult+",";
КонецЕсли;
EndDo;
stringResult = stringResult+"}";
Return stringResult;
EndFunction
//=============================================
Function ConvertListToJSONArray(key, valueList)
stringResult = "{"""+key+""":[";
For i=1 To valueList.GetListSize() Do
key = "";
value = valueList.GetValue(i, key);
stringResult = stringResult+ConvertListToJSONObject(value);
Если i<valueList.GetListSize() Тогда
stringResult = stringResult+",";
КонецЕсли;
EndDo;
stringResult = stringResult+"]}";
Return stringResult;
EndFunction
//=============================================
Функция ТипОбъекта(Тип)
Если Тип = "goods" Тогда
Возврат "Справочник.ТМЦ";
ИначеЕсли Тип = "inventory" Тогда
Возврат "Документ.Инвентаризация";
ИначеЕсли Тип = "ship" Тогда
Возврат "Документ.РасходнаяНакладная";
ИначеЕсли Тип = "receive" Тогда
Возврат "Документ.ПриходнаяНакладная";
КонецЕсли;
КонецФункции
//=============================================
Функция ИдентификаторЭлемента(Элемент) Экспорт
Попытка
Стр = ЗначениеВСтрокуВнутр(Элемент);
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат "";
КонецПопытки;
Стр = СтрЗаменить(Стр, "{", "");
Стр = СтрЗаменить(Стр, "}", "");
Стр = СтрЗаменить(Стр, """", "");
Стр = СтрЗаменить(Стр, ",", "-");
Стр = СтрЗаменить(Стр, " ", "");
Возврат Стр;
КонецФункции
//=============================================
Функция ДатаДокумента(Док) Экспорт
Возврат Формат(Док.ДатаДок, "ДДДММГГГГ");
КонецФункции
//=============================================
Функция КонтрагентВДокументе(Док) Экспорт
Стр = "";
Если Док.Вид() = "РасходнаяНакладная" Тогда
Стр = Док.Покупатель;
ИначеЕсли Док.Вид() = "ПриходнаяНакладная" Тогда
Стр = Док.Поставщик;
ИначеЕсли Док.Вид() = "Инвентаризация" Тогда
Стр = Док.Сотрудник;
КонецЕсли;
Возврат СокрЛП(Стр);
КонецФункции
//=============================================
Функция СуммаДокумента(Док) Экспорт
Сумма = 0;
Если Док.Вид() = "РасходнаяНакладная" Тогда
Сумма = Док.Итог("Сумма");
ИначеЕсли Док.Вид() = "ПриходнаяНакладная" Тогда
Сумма = Док.Итог("Сумма");
ИначеЕсли Док.Вид() = "Инвентаризация" Тогда
Сумма = Док.Итог("СуммаРазн");
КонецЕсли;
Возврат Формат(Сумма, "Ч0.2.");
КонецФункции
//=============================================
Функция saveDocument(ДанныеДокумента) Экспорт
Перем Позиция;
Результат = СоздатьОбъект("СписокЗначений");
Результат.Установить("saved","no");
Результат.Установить("error","");
Тип = ДанныеДокумента.Получить("type");
Номер = ДанныеДокумента.Получить("number");
Идентификатор = ДанныеДокумента.Получить("guid");
ДанныеСтрок = ДанныеДокумента.Получить("lines");
Попытка
Док = СоздатьОбъект(ТипОбъекта(Тип));
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат Результат;
КонецПопытки;
Если ПустоеЗначение(ДанныеСтрок) = 1 Тогда
Возврат Результат;
КонецЕсли;
Если Тип = "inventory" Тогда
Номер = Число(Номер);
ИначеЕсли Тип = "ship" Тогда
Номер = "РТ-"+Номер;
ИначеЕсли Тип = "receive" Тогда
Номер = "ПТ-"+Номер;
КонецЕсли;
Спр = СоздатьОбъект("Справочник.ТМЦ");
Если Док.НайтиПоНомеру(Номер, ТекущаяДата()) = 1 Тогда
Если Док.Проведен() = 1 Тогда
Результат.Установить("error","Документ уже проведен");
Возврат Результат;
КонецЕсли;
Для Н=1 По ДанныеСтрок.РазмерСписка() Цикл
ДанныеСтроки = ДанныеСтрок.ПолучитьЗначение(Н);
КодТовара = ДанныеСтроки.Получить("code");
Если ПустаяСтрока(КодТовара) = 1 Тогда
Продолжить;
КонецЕсли;
Если Спр.НайтиПоКоду(КодТовара, 2) = 1 Тогда
ВыбранныйТовар = Спр.ТекущийЭлемент();
фНайден = 0;
Док.ВыбратьСтроки();
Пока Док.ПолучитьСтроку() = 1 Цикл
Если Тип = "inventory" Тогда
Товар = Док.ТМЦ;
Иначе
Товар = Док.Товар;
КонецЕсли;
Если Товар <> ВыбранныйТовар Тогда
Продолжить;
КонецЕсли;
фНайден = 1;
Если Тип = "inventory" Тогда
Док.Факт = ДанныеСтроки.Получить("quantity");
Иначе
Док.Количество = ДанныеСтроки.Получить("quantity");
КонецЕсли;
КонецЦикла;
Если фНайден = 0 Тогда
Док.НоваяСтрока();
Если Тип = "inventory" Тогда
Док.ТМЦ = ВыбранныйТовар;
Док.Факт = ДанныеСтроки.Получить("quantity");
Иначе
Док.Товар = ВыбранныйТовар;
Док.Количество = ДанныеСтроки.Получить("quantity");
КонецЕсли;
КонецЕсли;
КонецЕсли;
КонецЦикла;
Попытка
Док.Записать();
Результат.Установить("saved","ok");
Исключение
Результат.Установить("error", ОписаниеОшибки());
КонецПопытки;
Иначе
ЗаписьЖурналаРегистрации("Не найден документ "+Тип+" по номеру "+Номер);
Возврат Результат;
КонецЕсли;
Возврат Результат;
КонецФункции
//=============================================
Функция getDocumentsData(Тип, Период) Экспорт
Перем Позиция;
Результат = СоздатьОбъект("СписокЗначений");
Попытка
Док = СоздатьОбъект(ТипОбъекта(Тип));
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат "";
КонецПопытки;
ДатаОт = ДобавитьМесяц(ТекущаяДата(), -6);
//Если Период = "all" Тогда
Кол = 0;
Док.ОбратныйПорядок(1);
Док.ВыбратьДокументы(,);
Пока Док.ПолучитьДокумент() = 1 Цикл
Позиция = Док.ТекущийДокумент();
Кол = Кол+1;
Если Кол = 100 Тогда
ДатаОт = Док.ДатаДок;
Прервать;
КонецЕсли;
КонецЦикла;
//КонецЕсли;
Док.ОбратныйПорядок(1);
Док.ВыбратьДокументы(ДатаОт,);
Пока Док.ПолучитьДокумент() = 1 Цикл
Номер = Сред(Док.НомерДок, Найти(Док.НомерДок, "-")+1);
Элемент = СоздатьОбъект("СписокЗначений");
Элемент.Установить("guid", ИдентификаторЭлемента(Док.ТекущийДокумент()));
Элемент.Установить("isProcessed", Док.Проведен());
Элемент.Установить("isDeleted", Док.ПометкаУдаления());
Элемент.Установить("number", Номер);
Элемент.Установить("date", ДатаДокумента(Док));
Элемент.Установить("contractor", КонтрагентВДокументе(Док));
Элемент.Установить("company", Строка(Док.Фирма));
Элемент.Установить("warehouse", Строка(Док.Склад));
Элемент.Установить("sum", СуммаДокумента(Док));
Результат.ДобавитьЗначение(Элемент);
Элемент = "";
Если Док.ТекущийДокумент() = Позиция Тогда
Прервать;
КонецЕсли;
КонецЦикла;
Возврат Результат;
КонецФункции
//=============================================
Функция getDocumentContent(Тип, Номер, Идентификатор) Экспорт
Результат = СоздатьОбъект("СписокЗначений");
Попытка
Док = СоздатьОбъект(ТипОбъекта(Тип));
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат "";
КонецПопытки;
Если Тип = "inventory" Тогда
Номер = Число(Номер);
ИначеЕсли Тип = "ship" Тогда
Номер = "РТ-"+Номер;
ИначеЕсли Тип = "receive" Тогда
Номер = "ПТ-"+Номер;
КонецЕсли;
Если Док.НайтиПоНомеру(Номер, ТекущаяДата()) = 1 Тогда
Если Док.КоличествоСтрок() > 300 Тогда
Элемент = СоздатьОбъект("СписокЗначений");
Элемент.Установить("line", "");
Элемент.Установить("code", "");
Элемент.Установить("art", "");
Элемент.Установить("description", "ВНИМАНИЕ: показаны первые 300 строк, всего строк в документе: "+Док.КоличествоСтрок());
Элемент.Установить("notes", ""); //всего строк в документе: "+Док.КоличествоСтрок());
Элемент.Установить("unit", "");
Элемент.Установить("quantity", "");
Элемент.Установить("rest", "");
Элемент.Установить("price", "");
Элемент.Установить("sum", "");
Результат.ДобавитьЗначение(Элемент);
Элемент = "";
КонецЕсли;
Док.ВыбратьСтроки();
Пока Док.ПолучитьСтроку() = 1 Цикл
Если Тип = "inventory" Тогда
Товар = Док.ТМЦ;
Количество = Док.Факт;
Остаток = Док.ОстБух;
Цена = Док.ТМЦ.ОтпЦена.Получить(Док.ДатаДок);
Сумма = Цена * Док.Разница;
Иначе
Товар = Док.Товар;
Количество = Формат(Док.Количество, "Ч.3");
Остаток = "";
Цена = Док.Цена;
Сумма = Док.Сумма;
КонецЕсли;
Если ПустаяСтрока(Товар.Наименование) = 1 Тогда
Продолжить;
КонецЕсли;
Элемент = СоздатьОбъект("СписокЗначений");
Элемент.Установить("line", "#0"+Док.НомерСтроки);
Элемент.Установить("code", Товар.ПолныйКод());
Элемент.Установить("art", Товар.ПолныйКод());
Элемент.Установить("description", Товар.Наименование);
Элемент.Установить("notes", "");
Элемент.Установить("unit", Товар.ЕдИзм);
Элемент.Установить("quantity", "#3"+Количество);
Элемент.Установить("rest", "#3"+Остаток);
Элемент.Установить("price", "#2"+Формат(Цена, "Ч.2"));
Элемент.Установить("sum", "#2"+Формат(Сумма, "Ч.2"));
Результат.Установить("line"+Док.НомерСтроки, Элемент);
Элемент = "";
Если Результат.РазмерСписка() = 301 Тогда
Прервать;
КонецЕсли;
КонецЦикла;
Иначе
ЗаписьЖурналаРегистрации("Не найден документ "+Тип+" по номеру "+Номер);
КонецЕсли;
Текст = СоздатьОбъект("Текст");
Текст.ДобавитьСтроку(ConvertListToJSONArray("result", Результат));
Текст.Записать("d:\ftp_root\json.txt");
Возврат ConvertListToJSONArray("result", Результат);
КонецФункции
//=============================================
Функция ДанныеТовара(Товар)
Элемент = СоздатьОбъект("СписокЗначений");
Элемент.Установить("id", Товар.ПолныйКод());
Элемент.Установить("isGroup", Товар.ЭтоГруппа());
Элемент.Установить("code", Товар.ПолныйКод());
Элемент.Установить("art", Товар.ПолныйКод());
Элемент.Установить("description", Товар.Наименование);
Если Товар.ЭтоГруппа() = 1 Тогда
Элемент.Установить("unit", "");
Иначе
Элемент.Установить("unit", Товар.ЕдИзм);
КонецЕсли;
Если ПустоеЗначение(Товар.Родитель) = 1 Тогда
Элемент.Установить("groupName", "");
Элемент.Установить("groupCode", "");
Иначе
Элемент.Установить("groupName", Товар.Родитель.Наименование);
Элемент.Установить("groupCode", Товар.Родитель.ПолныйКод());
КонецЕсли;
Возврат Элемент;
КонецФункции
//=============================================
Функция getReferenceData(Тип, КодГруппы)
Результат = СоздатьОбъект("СписокЗначений");
ТипОбъекта = ТипОбъекта(Тип);
Попытка
Спр = СоздатьОбъект(ТипОбъекта);
Спр2 = СоздатьОбъект(ТипОбъекта);
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат Результат;
КонецПопытки;
ТекущаяГруппа = ПолучитьПустоеЗначение(ТипОбъекта);
Если КодГруппы <> "noGroup" Тогда
Если Спр2.НайтиПоКоду(КодГруппы, 2) = 1 Тогда
ТекущаяГруппа = Спр2.ТекущийЭлемент();
КонецЕсли;
КонецЕсли;
Если Спр.ВыбратьЭлементыПоРеквизиту("ОтборПоРодителю", ТекущаяГруппа, 0) = 1 Тогда
Пока Спр.ПолучитьЭлемент() = 1 Цикл
Если ПустаяСтрока(Спр.Наименование) = 1 Тогда
Продолжить;
КонецЕсли;
Если Спр.ПометкаУдаления() = 1 Тогда
Продолжить;
КонецЕсли;
Результат.ДобавитьЗначение(ДанныеТовара(Спр.ТекущийЭлемент()));
КонецЦикла;
Иначе
//ЗаписьЖурналаРегистрации("По группе "+ТекущаяГруппа+" ничего не выбрано");
КонецЕсли;
Возврат Результат;
КонецФункции
//=============================================
Функция getCatalogDataWithFilter(Тип, СтрокаПоиска)
Результат = СоздатьОбъект("СписокЗначений");
ТипОбъекта = ТипОбъекта(Тип);
Попытка
Спр = СоздатьОбъект(ТипОбъекта);
Исключение
ЗаписьЖурналаРегистрации("http: "+ОписаниеОшибки());
Возврат Результат;
КонецПопытки;
//search by description takes too mach time !!!
//
//Если Спр.НайтиПоНаименованию(СтрокаПоиска, 0, 0) = 1 Тогда
// Результат.ДобавитьЗначение(ДанныеТовара(Спр.ТекущийЭлемент()));
//КонецЕсли;
Если Спр.НайтиПоКоду(СтрЗаменить(СтрокаПоиска,"-","/"), 2) = 1 Тогда
Результат.ДобавитьЗначение(ДанныеТовара(Спр.ТекущийЭлемент()));
КонецЕсли;
Возврат Результат;
КонецФункции
//=============================================
Функция findBarcode(Штрихкод)
Перем Товар, ВесИзШК;
Результат = СоздатьОбъект("СписокЗначений");
Если глПолучитьТоварПоШтрихкоду(Товар,Штрихкод,ВесИзШК) <> 0 Тогда
Результат.ДобавитьЗначение(ДанныеТовара(Товар));
КонецЕсли;
Возврат Результат;
КонецФункции
//=============================================
Функция getOptionsData(Идентификатор)
Результат = СоздатьОбъект("СписокЗначений");
Элемент = СоздатьОбъект("СписокЗначений");
Элемент.Установить("read", "true");
Элемент.Установить("write", "true");
Элемент.Установить("user", "");
Элемент.Установить("catalog", "goods");
Элемент.Установить("document", "inventory");
Результат.ДобавитьЗначение(Элемент);
Элемент = "";
Возврат Результат;
КонецФункции
//=============================================
Процедура Выход()
Форма.Параметр = Параметры;
Форма.Закрыть();
КонецПроцедуры
//=============================================
Процедура ПриОткрытии()
Результат = СоздатьОбъект("СписокЗначений");
Параметры = Форма.Параметр;
Если ПустоеЗначение(Параметры) = 1 Тогда
Параметры = СоздатьОбъект("СписокЗначений");
ЗаписьЖурналаРегистрации("Сервис: пустой параметр");
Иначе
Команда = Параметры.Получить("Команда");
Пар1 = Параметры.Получить("Пар1");
Пар2 = Параметры.Получить("Пар2");
Пар3 = Параметры.Получить("Пар3");
//ЗаписьЖурналаРегистрации("Сервис команда: "+Команда+" П1:"+Пар1+" П2:"+Пар2+" П3:"+Пар3);
Попытка
Если Команда = "getReferenceData" Тогда
Результат = getReferenceData(Пар1, Пар2);
ИначеЕсли Команда = "getDocumentsData" Тогда
Результат = getDocumentsData(Пар1, Пар2);
ИначеЕсли Команда = "getDocumentContent" Тогда
Результат = getDocumentContent(Пар1, Пар2, Пар3);
ИначеЕсли Команда = "readOptions" Тогда
Результат = getOptionsData(Пар1);
ИначеЕсли Команда = "findBarcode" Тогда
Результат = findBarcode(Пар1);
ИначеЕсли Команда = "getCatalogDataWithFilter" Тогда
Результат = getCatalogDataWithFilter(Пар1, Пар2);
ИначеЕсли Команда = "saveDocument" Тогда
Результат = saveDocument(Пар1);
Иначе
ЗаписьЖурналаРегистрации("Сервис: неизвестная команда. "+Команда);
КонецЕсли;
Исключение
ЗаписьЖурналаРегистрации("Сервис: ошибка: "+ОписаниеОшибки());
КонецПопытки;
//
Параметры.Установить("Результат", Результат);
КонецЕсли;
Выход();
КонецПроцедуры