@@ -75,14 +75,13 @@ export class CalculateShipmentsService {
7575 return params . RequiredTruckInformation . Full === true ;
7676 } ) ;
7777
78- shipments = ld . difference ( shipments , FinalSortedArray )
78+ shipments = ld . difference ( shipments , FinalSortedArray ) ;
7979
8080 // if destination is selected
8181 if ( driver . Destination ) {
8282 // otherwise run compatibility algo
83- 83+ CompatibilityAlgo ( ) ;
8484 } else {
85- 8685 // sort shipments with same origin and destination into an array
8786 let destinations = [ ] ;
8887
@@ -94,23 +93,129 @@ export class CalculateShipmentsService {
9493 destinations = ld . uniq ( destinations ) ;
9594
9695 // loop through destinations and check against shipments then sort into new array
97- destinations . forEach ( ( d ) => {
96+ destinations . forEach ( d => {
9897 const x = shipments . filter ( s => {
9998 return s . Destination === d ;
10099 } ) ;
101100 FinalSortedArray . push ( x ) ;
102101 } ) ;
103102
104103 // otherwise run compatibility algo
105- 104+ CompatibilityAlgo ( ) ;
106105 }
107106
108107 // CompatibilityAlgo
109- function CompatibilityAlgo ( ) { }
108+ async function CompatibilityAlgo ( ) {
109+ 110+ const tempStorageOfArray = [ ] ;
111+ 112+ await FinalSortedArray . forEach ( async shipment => {
113+ if ( shipment . length > 1 ) {
114+ await tempStorageOfArray . push ( shipment ) ;
115+ await FinalSortedArray . splice ( FinalSortedArray . indexOf ( shipment ) ) ;
116+ }
117+ } ) ;
118+ 119+ await tempStorageOfArray . forEach ( async ships => {
120+ await ships . forEach ( async s => {
121+ let a = [ ] ;
122+ a = await ships . filter ( ( el ) => {
123+ return CheckMixability ( s . CargoInformation . TypeName [ 0 ] , el . CargoInformation . TypeName [ 0 ] ) ;
124+ } ) ;
125+ 126+ if ( a . length === 1 ) {
127+ FinalSortedArray . push ( a [ 0 ] ) ;
128+ } else {
129+ FinalSortedArray . push ( a ) ;
130+ }
131+ } ) ;
132+ } ) ;
133+ 134+ FinalSortedArray = await ld . uniq ( FinalSortedArray ) ;
135+ }
110136
111137 // SortMixability
112- function SortMixability ( ) {
138+ function CheckMixability ( x , y ) {
113139 // if x then proceed to switch
140+ switch ( x ) {
141+ case 'Regular' :
142+ switch ( y ) {
143+ case 'Regular' :
144+ return true ;
145+ case 'Heavy' :
146+ return true ;
147+ case 'Construction' :
148+ return true ;
149+ case 'Chemicals' :
150+ return false ;
151+ case 'Food' :
152+ return false ;
153+ default :
154+ return false ;
155+ }
156+ case 'Heavy' :
157+ switch ( y ) {
158+ case 'Regular' :
159+ return true ;
160+ case 'Heavy' :
161+ return true ;
162+ case 'Construction' :
163+ return true ;
164+ case 'Chemicals' :
165+ return false ;
166+ case 'Food' :
167+ return false ;
168+ default :
169+ return false ;
170+ }
171+ case 'Construction' :
172+ switch ( y ) {
173+ case 'Regular' :
174+ return true ;
175+ case 'Heavy' :
176+ return true ;
177+ case 'Construction' :
178+ return true ;
179+ case 'Chemicals' :
180+ return false ;
181+ case 'Food' :
182+ return false ;
183+ default :
184+ return false ;
185+ }
186+ case 'Chemicals' :
187+ switch ( y ) {
188+ case 'Regular' :
189+ return false ;
190+ case 'Heavy' :
191+ return false ;
192+ case 'Construction' :
193+ return false ;
194+ case 'Chemicals' :
195+ return true ;
196+ case 'Food' :
197+ return false ;
198+ default :
199+ return false ;
200+ }
201+ case 'Food' :
202+ switch ( y ) {
203+ case 'Regular' :
204+ return false ;
205+ case 'Heavy' :
206+ return false ;
207+ case 'Construction' :
208+ return false ;
209+ case 'Chemicals' :
210+ return false ;
211+ case 'Food' :
212+ return true ;
213+ default :
214+ return false ;
215+ }
216+ default :
217+ return false ;
218+ }
114219 }
115220
116221 // SortCombination
0 commit comments