New file |
| | |
| | | import { Injectable } from '@angular/core'; |
| | | |
| | | @Injectable() |
| | | export class ListSort { |
| | | groupingSort(list:any){ |
| | | let relationListX = list; |
| | | let destX:any; |
| | | let newRelationListX = []; |
| | | let noRelationListX = []; |
| | | newRelationListX = relationListX.filter(x => x.AccountVoucherNumber); |
| | | let map = {}, |
| | | dest = []; |
| | | for(var i = 0; i < newRelationListX.length; i++){ |
| | | var ai = newRelationListX[i]; |
| | | if(!map[ai.AccountVoucherNumber]){ |
| | | dest.push({ |
| | | AccountVoucherNumber: ai.AccountVoucherNumber, |
| | | CREATE_DATE: ai.CREATE_DATE, |
| | | ServiceNumber: ai.ServiceNumber, |
| | | Accounting: ai.Accounting, |
| | | FinanceDirector: ai.FinanceDirector, |
| | | Cashier: ai.Cashier, |
| | | ToReview: ai.ToReview, |
| | | data: [ai] |
| | | }); |
| | | map[ai.AccountVoucherNumber] = ai; |
| | | }else{ |
| | | for(var j = 0; j < dest.length; j++){ |
| | | var dj = dest[j]; |
| | | if(dj.AccountVoucherNumber === ai.AccountVoucherNumber){ |
| | | dj.data.push(ai); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | function sortNumber(a: any,b: any){return parseInt(a.AccountVoucherNumber) - parseInt(b.AccountVoucherNumber)} |
| | | destX = dest.sort(sortNumber); |
| | | newRelationListX = []; |
| | | noRelationListX = relationListX.filter(x => !x.AccountVoucherNumber); |
| | | if(noRelationListX.length!=0){ |
| | | destX.push({ |
| | | AccountVoucherNumber: "", |
| | | CREATE_DATE: "", |
| | | ServiceNumber: "", |
| | | Accounting: "", |
| | | FinanceDirector: "", |
| | | Cashier: "", |
| | | ToReview: "", |
| | | data:noRelationListX |
| | | }) |
| | | } |
| | | console.log(noRelationListX); |
| | | console.log(destX); |
| | | return destX |
| | | } |
| | | } |