js-gei 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/Evaluator/ExpresionLogicService.ts +669 -0
  2. package/Evaluator/Parser/AddLeadZerosParse.ts +70 -0
  3. package/Evaluator/Parser/AppearParse.ts +67 -0
  4. package/Evaluator/Parser/BaseParse.ts +93 -0
  5. package/Evaluator/Parser/CalcDateParse.ts +73 -0
  6. package/Evaluator/Parser/CheckParse.ts +99 -0
  7. package/Evaluator/Parser/CommaParser.ts +17 -0
  8. package/Evaluator/Parser/ConcatParse.ts +34 -0
  9. package/Evaluator/Parser/CountParse.ts +26 -0
  10. package/Evaluator/Parser/EmptyParse.ts +41 -0
  11. package/Evaluator/Parser/ExistParse.ts +69 -0
  12. package/Evaluator/Parser/IfParse.ts +388 -0
  13. package/Evaluator/Parser/IfStategment.ts +345 -0
  14. package/Evaluator/Parser/InDetailParse.ts +109 -0
  15. package/Evaluator/Parser/InListParse.ts +57 -0
  16. package/Evaluator/Parser/LiteralValueParse.ts +36 -0
  17. package/Evaluator/Parser/LogicalOperatorParse.ts +16 -0
  18. package/Evaluator/Parser/OnlyExpressionParse.ts +137 -0
  19. package/Evaluator/Parser/OperatorParse.ts +17 -0
  20. package/Evaluator/Parser/StartsParse.ts +36 -0
  21. package/Evaluator/Parser/SubstrParse.ts +110 -0
  22. package/Evaluator/Parser/SumParse.ts +15 -0
  23. package/Evaluator/Parser/ToNullParser.ts +0 -0
  24. package/Evaluator/Parser/TrimParse.ts +30 -0
  25. package/Evaluator/Parser/UpperLoverParse.ts +41 -0
  26. package/Evaluator/Parser/ValueFromObjParse.ts +37 -0
  27. package/Evaluator/Parser/ValueParse.ts +61 -0
  28. package/HelperSessionStorage.ts +13 -0
  29. package/Interfaces/SchemaStruct.ts +28 -0
  30. package/Library/jsonrpc-2.0.js +869 -0
  31. package/Structure/InvoiceObj.ts +691 -0
  32. package/Structure/RecordArray.ts +145 -0
  33. package/Structure/RecordSingle.ts +1076 -0
  34. package/Structure/TableLevel.ts +248 -0
  35. package/dist/Evaluator/ExpresionLogicService.js +505 -0
  36. package/dist/Evaluator/Parser/AddLeadZerosParse.js +55 -0
  37. package/dist/Evaluator/Parser/AppearParse.js +48 -0
  38. package/dist/Evaluator/Parser/BaseParse.js +89 -0
  39. package/dist/Evaluator/Parser/CalcDateParse.js +54 -0
  40. package/dist/Evaluator/Parser/CheckParse.js +80 -0
  41. package/dist/Evaluator/Parser/CommaParser.js +13 -0
  42. package/dist/Evaluator/Parser/ConcatParse.js +29 -0
  43. package/dist/Evaluator/Parser/CountParse.js +23 -0
  44. package/dist/Evaluator/Parser/EmptyParse.js +35 -0
  45. package/dist/Evaluator/Parser/ExistParse.js +57 -0
  46. package/dist/Evaluator/Parser/IfParse.js +296 -0
  47. package/dist/Evaluator/Parser/IfStategment.js +287 -0
  48. package/dist/Evaluator/Parser/InDetailParse.js +79 -0
  49. package/dist/Evaluator/Parser/InListParse.js +40 -0
  50. package/dist/Evaluator/Parser/LiteralValueParse.js +26 -0
  51. package/dist/Evaluator/Parser/LogicalOperatorParse.js +13 -0
  52. package/dist/Evaluator/Parser/OnlyExpressionParse.js +106 -0
  53. package/dist/Evaluator/Parser/OperatorParse.js +13 -0
  54. package/dist/Evaluator/Parser/StartsParse.js +30 -0
  55. package/dist/Evaluator/Parser/SubstrParse.js +83 -0
  56. package/dist/Evaluator/Parser/SumParse.js +13 -0
  57. package/dist/Evaluator/Parser/ToNullParser.js +1 -0
  58. package/dist/Evaluator/Parser/TrimParse.js +25 -0
  59. package/dist/Evaluator/Parser/UpperLoverParse.js +32 -0
  60. package/dist/Evaluator/Parser/ValueFromObjParse.js +29 -0
  61. package/dist/Evaluator/Parser/ValueParse.js +59 -0
  62. package/dist/HelperSessionStorage.js +12 -0
  63. package/dist/Interfaces/SchemaStruct.js +2 -0
  64. package/dist/Structure/InvoiceObj.js +610 -0
  65. package/dist/Structure/RecordArray.js +102 -0
  66. package/dist/Structure/RecordSingle.js +950 -0
  67. package/dist/Structure/TableLevel.js +162 -0
  68. package/dist/index.js +19 -0
  69. package/index.ts +20 -0
  70. package/package.json +20 -0
  71. package/tsconfig.json +103 -0
@@ -0,0 +1,691 @@
1
+
2
+
3
+ import { RecordArray } from "./RecordArray";
4
+ import { RecordSingle } from "./RecordSingle";
5
+ import { TableLevel } from "./TableLevel";
6
+
7
+ export class InvoiceObj {
8
+ rootLevel:TableLevel;
9
+ objectInfo:any;
10
+ objectInfoUIEdit:any;
11
+ mappings:any;
12
+ private masterRecord:RecordSingle|null=null;
13
+ private itemsRecord:RecordArray|null=null;
14
+ private taxRecord:RecordArray|null=null;
15
+ private taxRecordUI:RecordArray|null=null;
16
+ private paymentRecord:RecordArray|null=null;
17
+ private cnRefsRecord:RecordArray|null=null;
18
+
19
+ public CNRefs: TableLevel[] | null = null;
20
+ public defObj:any=null;
21
+ public OIObj:any=null;
22
+ public OIOutObj:any=null;
23
+
24
+ public constructor(
25
+ obj:any,
26
+ def:any,
27
+ oi:any,
28
+ oiOut:any,
29
+ map:any
30
+ )
31
+ {
32
+ this.defObj=JSON.parse(JSON.stringify(def));
33
+ this.OIObj=JSON.parse(JSON.stringify(oi));
34
+ this.OIOutObj=JSON.parse(JSON.stringify(oiOut));
35
+ this.objectInfo=oi;
36
+ this.objectInfoUIEdit=oiOut;
37
+ this.mappings=map;
38
+ const table="EU_Invoices";
39
+ this.rootLevel=new TableLevel(table,obj[table],def[table],this.objectInfo,this);
40
+
41
+ // console.log('obj12: ' + JSON.stringify(obj));
42
+
43
+
44
+
45
+ this.GetMasterRecord();
46
+ /*this.GetItemsRecord();
47
+ this.GetTaxesRecord();
48
+ this.GetTaxesUIRecord();
49
+ this.GetPaymentRecord();
50
+ this.GetCnRefsRecord();
51
+ this.HasCNRecords();*/
52
+ this.rewriteInvoiceClouse();
53
+ }
54
+ public static isMultiple(table:string):boolean{
55
+ return table == "EU_Invoices_Items_Classes" || table == "EU_Invoices_Items_AllowsCharges" || table == "EU_Invoices_CN_IICRefs_Items" || table == "EU_Invoices_AdvanceUsage" || table == "EU_Invoices_AdvanceUsageVatCode";
56
+ }
57
+ public InitAfterConst()
58
+ {
59
+
60
+ }
61
+ public FindTableLevel(tableName:string):TableLevel|null
62
+ {
63
+ var tableModel=this.RecursiveFindLevel(this.rootLevel,tableName);
64
+ if(tableModel==null)
65
+ {
66
+ // console.log("Can't find level "+tableName);
67
+ }
68
+ return tableModel;
69
+ }
70
+
71
+ private RecursiveFindLevel(current:TableLevel|null,tableName:string):TableLevel|null
72
+ {
73
+ if(current==null) {
74
+ return null;
75
+ }
76
+
77
+ if(current?.Tablename==tableName)
78
+ {
79
+ return current;
80
+ }
81
+ if(current.Record!=null)
82
+ {
83
+ if(current.Record.Details!=null)
84
+ {
85
+ for(let i=0;i<current.Record.Details.length;i++)
86
+ {
87
+ const tableLevel=this.RecursiveFindLevel(current.Record.Details[i],tableName);
88
+ if(tableLevel!=null)
89
+ {
90
+ return tableLevel;
91
+ }
92
+ }
93
+
94
+ }
95
+
96
+ }
97
+ return null;
98
+ }
99
+ public GetObject():any{
100
+ return this.rootLevel.GetObject();
101
+ }
102
+ public GetMasterRecord():RecordSingle|null{
103
+ const tableName="EU_Invoices";
104
+ if(this.masterRecord==null)
105
+ {
106
+ var tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
107
+ if(tableLevel!=null&&tableLevel.Record!=null)
108
+ {
109
+ this.masterRecord=tableLevel.Record;
110
+ }
111
+ else{
112
+
113
+ }
114
+
115
+ }
116
+ return this.masterRecord;
117
+
118
+ }
119
+ /*public GetItemsRecord():RecordArray|null{
120
+ const tableName="EU_Invoices_Items";
121
+ if(this.itemsRecord==null)
122
+ {
123
+ var tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
124
+ if(tableLevel!=null && tableLevel.Records!=null)
125
+ {
126
+ this.itemsRecord=tableLevel.Records;
127
+ }
128
+ else{
129
+ }
130
+
131
+ }
132
+ return this.itemsRecord;
133
+
134
+ }
135
+ public AddItem() {
136
+ this.itemsRecord?.Records?.push(new RecordSingle(JSON.parse(JSON.stringify(this.itemsRecord?.Parent?.DefaultRecord??{})),this.itemsRecord?.Parent?.DefaultRecord??{},this.itemsRecord.ObjectInfo,this.itemsRecord.Parent,this.service));
137
+ }
138
+ public RemoveItem(item:RecordSingle)
139
+ {
140
+ let index=this.itemsRecord?.Records?.indexOf(item);
141
+ if(index!=undefined&&index!=-1)
142
+ {
143
+ if(this.itemsRecord?.Records!=null)
144
+ {
145
+
146
+ this.itemsRecord?.Records?.splice(index,1);
147
+ }
148
+ }
149
+ }
150
+ public AddPaymentItem()
151
+ {
152
+ this.paymentRecord?.Records?.push(
153
+ // new RecordSingle(JSON.parse(JSON.stringify(this.paymentRecord?.Parent?.DefaultRecord??{})),this.paymentRecord?.Parent?.DefaultRecord??{},this.paymentRecord.ObjectInfo,this.paymentRecord.Parent));
154
+ new RecordSingle({},{},this.paymentRecord.ObjectInfo,this.paymentRecord.Parent,this.service));
155
+ }
156
+ public RemovePaymentItem(item:RecordSingle)
157
+ {
158
+ let index=this.paymentRecord?.Records?.indexOf(item);
159
+ if(index!=undefined&&index!=-1)
160
+ {
161
+ if(this.paymentRecord?.Records!=null)
162
+ {
163
+ this.paymentRecord?.Records?.splice(index,1);
164
+ }
165
+ }
166
+ }
167
+
168
+
169
+ public GetCnRefsRecord():RecordArray|null{
170
+ const tableName="EU_Invoices_CN_IICRefs";
171
+
172
+
173
+ let tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
174
+ if(tableLevel!=null&&tableLevel.Records!=null)
175
+ {
176
+ this.cnRefsRecord=tableLevel.Records;
177
+ this.service._cnRefsRecord.next(tableLevel.Records);
178
+ }
179
+ else{
180
+ this.cnRefsRecord=null;
181
+ }
182
+
183
+
184
+ // console.log(this.cnRefsRecord?.Records);
185
+ return this.cnRefsRecord;
186
+
187
+ }
188
+ public HasCNRecords():boolean
189
+ {
190
+ const cn=this.GetCnRefsRecord();
191
+ if(cn==null)
192
+ {
193
+ this.service.HasCNRecords.next(false);
194
+ return false;
195
+ }
196
+ if(cn.Records==null||cn.Records.length==0)
197
+ {
198
+ this.service.HasCNRecords.next(false);
199
+ return false;
200
+ }
201
+ if(cn.Records.length==1)
202
+ {
203
+ let empty=false;
204
+ for(var key in cn.Records[0].Record)
205
+ {
206
+ if(cn.Records[0].Record[key]!=null&&cn.Records[0].Record[key]!==false&&cn.Records[0].Record[key]!==0)
207
+ {
208
+ empty=true;
209
+ break;
210
+ }
211
+ }
212
+ this.service.HasCNRecords.next(empty);
213
+ return empty;
214
+ }
215
+ this.service.HasCNRecords.next(true);
216
+ return true;
217
+ }*/
218
+ public CreateRecordSingle(obj:any,table:string)
219
+ {
220
+ let CnRefRecord = this.RecursiveFindLevel(this.rootLevel,table);
221
+
222
+ if(!CnRefRecord) {
223
+ CnRefRecord = new TableLevel(table,[],[],this.objectInfo,this);
224
+ this.rootLevel.Record?.Details?.push(CnRefRecord);
225
+ }
226
+ return new RecordSingle(obj,{},this.objectInfo[table],CnRefRecord)
227
+ }
228
+ /*public ReplaceRecords(Records:RecordSingle[],table:string)
229
+ {
230
+ let CnRefRecord = this.RecursiveFindLevel(this.rootLevel,table);
231
+
232
+ if(!CnRefRecord) {
233
+ CnRefRecord = new TableLevel(table,[],[],this.objectInfo,this);
234
+ this.rootLevel.Record?.Details?.push(CnRefRecord);
235
+ }
236
+ if(CnRefRecord!=null&&CnRefRecord.Records!=null)
237
+ CnRefRecord.Records.Records=Records;
238
+
239
+ switch(table)
240
+ {
241
+ case "EU_Invoices_CN_IICRefs":
242
+ {
243
+
244
+ if(CnRefRecord.Records!=null)
245
+ this.service._cnRefsRecord.next(CnRefRecord.Records);
246
+
247
+ this.HasCNRecords();
248
+
249
+ break;
250
+ }
251
+ }
252
+ }*/
253
+ /*public AddCnRef(item:any) {
254
+ const tableNameCNRefs="EU_Invoices_CN_IICRefs";
255
+
256
+ let CnRefRecord = this.RecursiveFindLevel(this.rootLevel,tableNameCNRefs);
257
+
258
+ if(!CnRefRecord) {
259
+ CnRefRecord = new TableLevel(tableNameCNRefs,[],[],this.objectInfo,this,this.service);
260
+ this.rootLevel.Record?.Details?.push(CnRefRecord);
261
+ if(CnRefRecord.Records) {
262
+ this.service._cnRefsRecord.next(CnRefRecord.Records);
263
+ }
264
+ }
265
+
266
+ CnRefRecord.Records?.Records.push(
267
+ new RecordSingle(item,{},this.objectInfo[tableNameCNRefs],CnRefRecord,this.service)
268
+ );
269
+ }*/
270
+
271
+ /*public RemoveCnRef(item:RecordSingle)
272
+ {
273
+
274
+ if(this.cnRefsRecord?.Records==null){
275
+ this.GetCnRefsRecord();
276
+ }
277
+
278
+ let index = this.cnRefsRecord?.Records.findIndex((rec:RecordSingle) => rec=== item);
279
+
280
+ if(index!=undefined&&index!=-1)
281
+ {
282
+ if(this.cnRefsRecord?.Records!=null)
283
+ {
284
+ this.cnRefsRecord?.Records?.splice(index,1);
285
+ }
286
+ }
287
+ }*/
288
+ /*public RemoveCnRefAll()
289
+ {
290
+ const tableName="EU_Invoices_CN_IICRefs";
291
+ let tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
292
+ if(tableLevel==null)
293
+ {
294
+ return;
295
+ }
296
+ const index=this.rootLevel.Record?.Details?.indexOf(tableLevel);
297
+ if(index!=null&&index!=-1)
298
+ {
299
+ this.rootLevel.Record?.Details?.splice(index,1);
300
+ }
301
+ this.service._cnRefsRecord.next(new RecordArray({}, {}, {}, null,this.service));
302
+ this.HasCNRecords();
303
+ }
304
+ */
305
+
306
+ /*public GetTaxesRecord():RecordArray|null{
307
+ const tableName="EU_Invoices_Vats";
308
+ if(this.taxRecord==null)
309
+ {
310
+ let tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
311
+ if(tableLevel!=null&&tableLevel.Records!=null)
312
+ {
313
+ this.taxRecord=tableLevel.Records;
314
+ }
315
+ else{
316
+
317
+ }
318
+
319
+ }
320
+ return this.taxRecord;
321
+
322
+ }
323
+ public GetTaxesUIRecord():RecordArray|null{
324
+ const tableName="EU_Invoices_VatsUI";
325
+ if(this.taxRecordUI==null)
326
+ {
327
+ let tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
328
+ if(tableLevel!=null&&tableLevel.Records!=null)
329
+ {
330
+ this.taxRecordUI=tableLevel.Records;
331
+ }
332
+ else{
333
+
334
+ }
335
+
336
+ }
337
+ return this.taxRecordUI;
338
+
339
+ }
340
+ public GetPaymentRecord():RecordArray|null{
341
+ const tableName="EU_Invoices_PaymentInstrs";
342
+
343
+ if(this.paymentRecord==null)
344
+ {
345
+ let tableLevel=this.RecursiveFindLevel(this.rootLevel,tableName);
346
+ if(tableLevel!=null && tableLevel.Records!=null)
347
+ {
348
+ this.paymentRecord=tableLevel.Records;
349
+ }
350
+ else{
351
+
352
+ }
353
+
354
+ }
355
+ return this.paymentRecord;
356
+ }
357
+ */
358
+ public Inicalize()
359
+ {
360
+ console.log("Inicalize");
361
+ // console.log('Inicalize - GetObject: ' + JSON.stringify(this.GetObject()));
362
+
363
+
364
+ const skippedlevels=["EU_Invoices_Vats","EU_Invoices_VatsUI"];
365
+ this.rootLevel.Inicialize(skippedlevels);
366
+
367
+ for(let i=0;i<skippedlevels.length;i++)
368
+ {
369
+ let tablelevel=this.RecursiveFindLevel(this.rootLevel,skippedlevels[i]);
370
+ if(tablelevel==null)
371
+ {
372
+ tablelevel=new TableLevel(skippedlevels[i],[],{},this.objectInfo[skippedlevels[i]],this);
373
+ this.rootLevel.Record?.Details?.push(tablelevel);
374
+ }
375
+ /*switch(skippedlevels[i])
376
+ {
377
+ case "EU_Invoices_Vats":
378
+ {
379
+ this.InitEU_Invoices_Vats(tablelevel);
380
+ break;
381
+ }
382
+ case "EU_Invoices_VatsUI":
383
+ {
384
+ this.InitEU_Invoices_VatsUI(tablelevel);
385
+ break;
386
+ }
387
+ }*/
388
+ }
389
+ this.taxRecordUI=null;
390
+ /*this.GetTaxesUIRecord();
391
+ if(this.taxRecordUI!=null)
392
+ {
393
+ this.service._taxRecordsUI.next(this.taxRecordUI);
394
+ }*/
395
+ this.rewriteInvoiceClouse();
396
+
397
+
398
+ }
399
+
400
+ public rewriteInvoiceClouse()
401
+ {
402
+ /*const vatDescMap=new Map<string,string>();
403
+ for(let i=0;i<(this.GetItemsRecord()?.Records??[])?.length;i++)
404
+ {
405
+ const item=this.GetItemsRecord()?.Records[i].Record;
406
+ if(item==null)
407
+ {
408
+ continue;
409
+ }
410
+ const vatid=item.ItemVatCodeSC;
411
+ if(!vatDescMap.has(vatid))
412
+ {
413
+ vatDescMap.set(vatid,"");
414
+ }
415
+ }
416
+ let note="";
417
+ const vatDescMapDest=new Map<string,string>();
418
+ for(let i=0;i<this.service.VATArray.length;i++)
419
+ {
420
+ const vat=this.service.VATArray[i];
421
+ if(vat.VERDesc==null||vat.VERDesc==""||vatDescMapDest.has(vat.VERDesc))
422
+ {
423
+ continue;
424
+ }
425
+ if(vatDescMap.has(vat.Id))
426
+ {
427
+ if(note!="")
428
+ {
429
+ note += " ";
430
+ }
431
+ vatDescMapDest.set(vat.VERDesc,"");
432
+ note+=vat.VERDesc;
433
+ }
434
+ if(this.masterRecord!=null&&this.masterRecord.Record!=null)
435
+ {
436
+ this.masterRecord.Record["InvNoteClause"]=note;
437
+ }
438
+
439
+ }*/
440
+ }
441
+ private InitEU_Invoices_Vats(tablelevel:TableLevel){
442
+ /*var items=this.GetItemsRecord();
443
+ if(items==null)
444
+ {
445
+
446
+ return;
447
+ }
448
+ let myMap = new Map<string, RecordSingle[]>();
449
+ for(let i=0;i<items.Records?.length;i++)
450
+ {
451
+ let item=items.Records[i];
452
+ let key=item.Record["ItemVatCodeSC__VCCode_EN16931"]+"||"+item.Record["ItemVatCodeSC__Rate"]+"||"+item.Record["ItemVatCodeSC__VERCode"];
453
+ if(key=="||")
454
+ {
455
+ continue;
456
+ }
457
+ if(!myMap.has(key))
458
+ {
459
+
460
+ myMap.set(key,[]);
461
+ }
462
+
463
+ myMap.get(key)?.push(item);
464
+ }
465
+ const vats=[];
466
+ for(let array of myMap.values())
467
+ {
468
+
469
+ if(array==null)
470
+ {
471
+ continue;
472
+ }
473
+ let obj={
474
+ "VatInvAllowBaseAmount":this.sumBykey("LineBaseAmountInclAllow",array),
475
+ "VatInvAllowAmount":this.sumBykey("LineInvAllowAmount",array),
476
+ "VatTaxableAmount":this.sumBykey("LineTotalNetAmount",array),
477
+ "VatTaxAmount":this.sumBykey("LineTotalVatAmount",array),
478
+ "VatCatCode":array[0].Record["ItemVatCodeSC__VCCode_EN16931"],
479
+ "VatCatCode__Name":array[0].Record["ItemVatCodeSC__VCCode_EN16931__Name"],
480
+ "VatRate":array[0].Record["ItemVatCodeSC__Rate"],
481
+ "VatExemptReasonCode":""
482
+ };
483
+ vats.push(obj);
484
+ }
485
+ tablelevel.Records=new RecordArray(vats,{},this.objectInfo[tablelevel?.Tablename],tablelevel,this.service);
486
+ // console.log(vats)
487
+ }
488
+ private InitEU_Invoices_VatsUI(tablelevel:TableLevel){
489
+ var items=this.GetItemsRecord();
490
+ if(items==null)
491
+ {
492
+
493
+ return;
494
+ }
495
+ let myMap = new Map<string, RecordSingle[]>();
496
+ for(let i=0;i<items.Records?.length;i++)
497
+ {
498
+ let item=items.Records[i];
499
+ // let key=item.Record["ItemVatCodeSC__GroupUIVatCode"]+"||"+item.Record["ItemVatCodeSC__Rate"];
500
+ let key=item.Record["ItemVatCodeSC__GroupUIVatCode"];
501
+ if(key=="||")
502
+ {
503
+ continue;
504
+ }
505
+ if(!myMap.has(key))
506
+ {
507
+
508
+ myMap.set(key,[]);
509
+ }
510
+
511
+ myMap.get(key)?.push(item);
512
+ }
513
+ const vats=[];
514
+ for(let array of myMap.values())
515
+ {
516
+
517
+ if(array==null)
518
+ {
519
+ continue;
520
+ }
521
+ let obj={
522
+ "VatInvAllowAmount":this.sumBykey("LineInvAllowAmount",array),
523
+ "VatTaxableAmount":this.sumBykey("LineTotalNetAmount",array),
524
+ "VatTaxAmount":this.sumBykey("LineTotalVatAmount",array),
525
+ "VatInvChargeAmount":this.sumBykey("LineTotalVatAmount",array),
526
+ "VatInvAllowBaseAmount":this.sumBykey("LineBaseAmountInclAllow",array),
527
+ "VatInvChargeBaseAmount":this.sumBykey("LineTotalVatAmount",array),
528
+ "VatCatCode":array[0].Record["ItemVatCodeSC__VCCode_EN16931"],
529
+ "VatCatCode__Name":array[0].Record["ItemVatCodeSC__VCCode_EN16931__Name"],
530
+ "VatCodeUI":array[0].Record["ItemVatCodeSC__GroupUIVatCode"],
531
+ "VatCode":array[0].Record["ItemVatCodeSC__VatCode"],
532
+ "VatRate":array[0].Record["ItemVatCodeSC__Rate"],
533
+ "NumOfItems":array.length,
534
+ "VatExemptReasonCode":""
535
+ };
536
+ vats.push(obj);
537
+ }
538
+ tablelevel.Records=new RecordArray(vats,{},this.objectInfo[tablelevel?.Tablename],tablelevel,this.service);
539
+ // console.log(vats)
540
+ */
541
+ }
542
+ /*private sumBykey(key:string,array:RecordSingle[]):number{
543
+ let num=0;
544
+ for(let i=0;i<array.length;i++)
545
+ {
546
+ let item=array[i].Record;
547
+ if(item[key]==null){
548
+ continue;
549
+ }
550
+ num+=item[key];
551
+ }
552
+ return num;
553
+ }*/
554
+
555
+ public SumByKey(tAndF:string):number
556
+ {
557
+ // console.log(tAndF)
558
+ var splitifStat= tAndF.split(",");
559
+
560
+ var split = splitifStat[0].split(".");
561
+ if (split.length != 2)
562
+ {
563
+ throw "Key isn't well formmed! "+tAndF;
564
+ }
565
+ var tableLevel = this.RecursiveFindLevel(this.rootLevel, split[0]);
566
+ if (tableLevel == null)
567
+ {
568
+ throw "Can't find table level "+split[0];
569
+ }
570
+ let booleanField = null;
571
+ if(splitifStat.length==2)
572
+ {
573
+ var split2 = splitifStat[1].split(".");
574
+ booleanField=split2[1];
575
+ }
576
+ let sum = 0;
577
+ if (tableLevel.Records !=null)
578
+ {
579
+ var rec = tableLevel.Records ;
580
+ for (var i=0;i<rec.Records.length;i++)
581
+ {
582
+ const r=rec.Records[i]
583
+ if (r.Record[split[1]]!=null)
584
+ {
585
+ if(booleanField!=null&& !r.Record[booleanField]==true)
586
+ {
587
+ continue;
588
+ }
589
+ sum += r.Record[split[1]];
590
+ }
591
+ }
592
+ }
593
+ return sum;
594
+ }
595
+ public getSaveObject(){
596
+ const result:any={};
597
+ result[this.rootLevel?.Tablename]=this.rootLevel.getSaveObject(this.objectInfoUIEdit);
598
+ return result;
599
+ }
600
+ public getFullObject(){
601
+ const result:any={};
602
+ result[this.rootLevel?.Tablename]=this.rootLevel.getFullObject(this.objectInfo);
603
+ return result;
604
+ }
605
+
606
+ public ValidateBeforeSave()
607
+ {
608
+ var master=this.GetMasterRecord();
609
+ if(master!=null)
610
+ {
611
+ master.Record["InvTotalVatAmountCCInp"]=master.Record["InvTotalVatAmountCC"];
612
+ master.Record["InvAmountInclVatInp"]=master.Record["InvAmountInclVat"];
613
+ }
614
+ // let errors:string|null=this.rootLevel.Validate();
615
+ let errors:any=this.rootLevel.Validate();
616
+ // console.log(errors)
617
+
618
+ let additionalValidations:any = [];
619
+ let combineErrors:null|string = null;
620
+ let invErrors:any = [];
621
+ let invDetailErrors:any = [];
622
+
623
+
624
+
625
+ if(errors) {
626
+ combineErrors = errors['combineErrors'];
627
+ invErrors = errors['validateErrors'];
628
+ invDetailErrors = errors['validateDeatailErrors'];
629
+ }
630
+
631
+
632
+
633
+
634
+
635
+
636
+ if(master?.Record?.BuyerIsVat==true && (master?.Record?.BuyerVatNum==null || master?.Record?.BuyerVatNum.length == 0))
637
+ {
638
+ // errors=this.ConcateErrors(errors,"Buyer vat flag is true, but Buyer Vat number isn't defined!");
639
+ combineErrors=this.ConcateErrors(combineErrors,"Buyer vat flag is true, but Buyer Vat number isn't defined!");
640
+ additionalValidations.push('BuyerIsVat');
641
+ }
642
+ if(master?.Record?.BuyerIsBudget==true && (master?.Record?.BuyerBudgetNum==null || master?.Record?.BuyerBudgetNum.length == 0))
643
+ {
644
+ // errors=this.ConcateErrors(errors,"Buyer budget flag is true, but Buyer Budget number isn't defined!");
645
+ combineErrors=this.ConcateErrors(combineErrors,"Buyer budget flag is true, but Buyer Budget number isn't defined!");
646
+ additionalValidations.push('BuyerIsBudget');
647
+ }
648
+ if(master?.Record?.InvStartDate>master?.Record?.InvEndDate)
649
+ {
650
+ combineErrors=this.ConcateErrors(combineErrors,"Invoice end date can't be smaller that Invoice start date!");
651
+ additionalValidations.push('InvEndDate1');
652
+ }
653
+
654
+ if(invErrors.length > 0 || invDetailErrors.length > 0 || additionalValidations.length >0) {
655
+
656
+ // končal tu ker mi ne vrača array - uredi da vrne array in jih lokaliziraj!
657
+ let invErrorsParam = [];
658
+ if(invErrors.length > 0) {
659
+ invErrorsParam = invErrors[0]?.split(', ');
660
+ }
661
+
662
+
663
+ if(additionalValidations.length>0) {
664
+ invErrorsParam.unshift(additionalValidations);
665
+ }
666
+
667
+ let invDeatailErrorsParam = invDetailErrors;
668
+
669
+ // this.service.AlertMessageFromValidation("Error", invErrorsParam, invDeatailErrorsParam);
670
+
671
+ } else {
672
+ return true;
673
+ }
674
+ return false;
675
+ }
676
+
677
+ private ConcateErrors(combineErrors:string|null,error:string)
678
+ {
679
+ if(combineErrors=='')
680
+ {
681
+ combineErrors = error;
682
+ return combineErrors;
683
+ }
684
+ combineErrors+=" "+error;
685
+ return combineErrors;
686
+ }
687
+ public TranslateObj(obj:any)
688
+ {
689
+ this.rootLevel.TranslateObj(obj);
690
+ }
691
+ }