d i f f   - - g i t   a / H t t p / C o n t r o l l e r s / T p s A d d S t o c k C o n t r o l l e r . p h p   b / H t t p / C o n t r o l l e r s / T p s A d d S t o c k C o n t r o l l e r . p h p 
 
 i n d e x   3 e 9 c 4 a 8 . . 3 f e c 0 7 e   1 0 0 6 4 4 
 
 - - -   a / H t t p / C o n t r o l l e r s / T p s A d d S t o c k C o n t r o l l e r . p h p 
 
 + + +   b / H t t p / C o n t r o l l e r s / T p s A d d S t o c k C o n t r o l l e r . p h p 
 
 @ @   - 1 0 7 , 6   + 1 0 7 , 1 2   @ @   c l a s s   T p s A d d S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                   $ f r o m L o c a t i o n I d   =   r e q u e s t ( ) - > g e t ( ' f r o m _ l o c a t i o n _ i d ' ,   n u l l ) ; 
 
                   $ t o L o c a t i o n I d   =   r e q u e s t ( ) - > g e t ( ' t o _ l o c a t i o n _ i d ' ,   n u l l ) ; 
 
   
 
 +                 / /   C a s t   l o c a t i o n   I D s   t o   i n t e g e r s   t o   p r e v e n t   S Q L   i n j e c t i o n 
 
 +                 i f   ( $ f r o m L o c a t i o n I d )   { 
 
 +                         $ f r o m L o c a t i o n I d   =   a r r a y _ m a p ( ' i n t v a l ' ,   ( a r r a y )   $ f r o m L o c a t i o n I d ) ; 
 
 +                         $ f r o m L o c a t i o n I d   =   a r r a y _ f i l t e r ( $ f r o m L o c a t i o n I d ) ;   / /   r e m o v e   z e r o s 
 
 +                 } 
 
 + 
 
                   $ r e q u e s t P v i d s   =   r e q u e s t ( ) - > g e t ( ' p v i d ' ,   [ ] ) ; 
 
   
 
   / /                         / / f o r t e s t i n g 
 
 @ @   - 2 1 4 , 1 3   + 2 2 0 , 2 7   @ @   c l a s s   T p s A d d S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           ' b l . n a m e   a s   b l _ n a m e ' , 
 
                           D B : : r a w ( ' v l d . q t y _ a v a i l a b l e   a s   f r o m _ s t o c k ' ) , 
 
                           D B : : r a w ( ' i f n u l l ( t o _ v l d . q t y _ a v a i l a b l e , 0 )   a s   t o _ s t o c k ' ) , 
 
 -                         D B : : r a w ( " I f N u l l ( b l . c u s t o m _ f i e l d 1 ,   1 )   a s   c u s t o m _ f i e l d " ) 
 
 +                         D B : : r a w ( " I f N u l l ( b l . c u s t o m _ f i e l d 1 ,   1 )   a s   c u s t o m _ f i e l d " ) , 
 
 +                         D B : : r a w ( " ( 
 
 +                                 S E L E C T   C O A L E S C E ( S U M ( n p p . t r a n s f e r _ q u a n t i t y ) ,   0 ) 
 
 +                                 F R O M   n s t _ p r e p a r e _ p r o d u c t s   n p p 
 
 +                                 W H E R E   n p p . p r o d u c t _ i d   =   p r o d u c t s . i d 
 
 +                                     A N D   n p p . v a r i a t i o n _ i d   =   v . i d 
 
 +                                     A N D   n p p . f r o m _ l o c a t i o n _ i d   =   v l d . l o c a t i o n _ i d 
 
 +                                     A N D   n p p . s t a t u s   I N   ( ' p r e p a r e ' ,   ' r e c e i v e ' ) 
 
 +                                     A N D   n p p . d e l e t e d _ a t   I S   N U L L 
 
 +                         )   a s   c o m m i t t e d _ q t y " ) 
 
                   ) ; 
 
   
 
                   i f   ( ! r e q u e s t ( ) - > g e t ( ' o r d e r ' ) )   { 
 
                           $ p r o d u c t s - > o r d e r B y ( ' t o _ s t o c k ' ,   ' A S C ' ) - > o r d e r B y ( ' p r o d u c t s . i d ' ,   ' A S C ' ) ; 
 
 -                         i f ( $ f r o m L o c a t i o n I d ) { 
 
 -                                 $ q u e r y - > o r d e r B y R a w ( ' F I E L D ( v l d . l o c a t i o n _ i d ,   ' . i m p l o d e ( ' ,   ' ,   $ f r o m L o c a t i o n I d ) . ' ) ' ) ; 
 
 +                         i f   ( $ f r o m L o c a t i o n I d )   { 
 
 +                                 $ l o c a t i o n I d s   =   a r r a y _ f i l t e r ( a r r a y _ m a p ( ' i n t v a l ' ,   $ f r o m L o c a t i o n I d ) ,   f u n c t i o n   ( $ i d )   { 
 
 +                                         r e t u r n   $ i d   >   0 ; 
 
 +                                 } ) ; 
 
 +                                 i f   ( ! e m p t y ( $ l o c a t i o n I d s ) )   { 
 
 +                                         $ p r o d u c t s - > o r d e r B y R a w ( ' F I E L D ( v l d . l o c a t i o n _ i d ,   ' . i m p l o d e ( ' ,   ' ,   $ l o c a t i o n I d s ) . ' ) ' ) ; 
 
 +                                 } 
 
                           } 
 
                   } 
 
                   $ p r o d u c t s - > g r o u p B y ( ' v l d . i d ' ) ; 
 
 @ @   - 3 6 0 , 1 6   + 3 8 0 , 2 8   @ @   c l a s s   T p s A d d S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                   < / d i v > " ; 
 
                                   r e t u r n   $ h t m l ; 
 
                           } ) 
 
 -                         - > a d d C o l u m n ( ' p v l ' ,   f u n c t i o n   ( $ r o w ) { 
 
 -                                 r e t u r n   $ t h i s - > g e t C o m b i n a t i o n N u m b e r ( $ r o w ) ; 
 
 -                         } ) 
 
 -                         - > a d d C o l u m n ( ' c u s t o m _ f i e l d ' ,   f u n c t i o n   ( $ r o w ) { 
 
 -                                 r e t u r n   $ r o w - > c u s t o m _ f i e l d ; 
 
 +                         - > a d d C o l u m n ( ' c o m m i t t e d _ q t y _ d i s p l a y ' ,   f u n c t i o n   ( $ r o w )   { 
 
 +                                 i f   ( i s s e t ( $ r o w - > c o m m i t t e d _ q t y )   & &   $ r o w - > c o m m i t t e d _ q t y   >   0 )   { 
 
 +                                         r e t u r n   ' < s p a n   c l a s s = " l a b e l   l a b e l - w a r n i n g "   t i t l e = " '   .   _ _ ( ' t p s T r a n s f e r : : l a n g . c o m m i t t e d _ t o _ o t h e r _ t r a n s f e r s ' )   .   ' " > ' 
 
 +                                                 .   _ _ ( ' t p s T r a n s f e r : : l a n g . i n _ t r a n s i t ' )   .   ' :   ' 
 
 +                                                 .   $ r o w - > c o m m i t t e d _ q t y 
 
 +                                                 .   ' < / s p a n > ' ; 
 
 +                                 } 
 
 +                                 r e t u r n   ' ' ; 
 
                           } ) 
 
 -                         - > a d d C o l u m n ( ' p v ' ,   f u n c t i o n   ( $ r o w ) { 
 
 -                                 r e t u r n   $ r o w - > i d . ' - ' . $ r o w - > v a r i a t i o n _ i d ; 
 
 +                         - > e d i t C o l u m n ( ' f r o m _ s t o c k _ s p a n ' ,   f u n c t i o n   ( $ r o w )   { 
 
 +                                 $ c o m m i t t e d   =   $ r o w - > c o m m i t t e d _ q t y   ? ?   0 ; 
 
 +                                 $ e f f e c t i v e   =   $ r o w - > f r o m _ s t o c k   -   $ c o m m i t t e d ; 
 
 + 
 
 +                                 i f   ( $ c o m m i t t e d   >   0 )   { 
 
 +                                         r e t u r n   ' < s p a n   t i t l e = " '   .   _ _ ( ' t p s T r a n s f e r : : l a n g . e f f e c t i v e _ a v a i l a b l e ' )   .   ' " > ' 
 
 +                                                 .   $ e f f e c t i v e 
 
 +                                                 .   '   < s m a l l   c l a s s = " t e x t - m u t e d " > ( '   .   $ r o w - > f r o m _ s t o c k   .   '   -   '   .   $ c o m m i t t e d   .   ' ) < / s m a l l > ' 
 
 +                                                 .   ' < / s p a n > ' ; 
 
 +                                 } 
 
 +                                 r e t u r n   " < s p a n   c l a s s = ' c u r r e n t - s t o c k - q t y '   i d = ' q t y - " . $ t h i s - > g e t C o m b i n a t i o n N u m b e r ( $ r o w ) . " ' > " . i n t v a l ( $ r o w - > f r o m _ s t o c k ) . " < / s p a n > " ; 
 
                           } ) 
 
 -                         - > r a w C o l u m n s ( [ ' p r o d u c t ' ,   ' p r o d u c t E d i t e d ' ,   ' p u r c h a s e _ p r i c e ' ,   ' c a t e g o r y ' ,   ' f r o m _ s t o c k _ s p a n ' ,   ' s t o c k _ t r a n s f e r ' ,   ' a c t i o n s ' ] ) 
 
 +                         - > r a w C o l u m n s ( [ ' p r o d u c t ' ,   ' p r o d u c t E d i t e d ' ,   ' p u r c h a s e _ p r i c e ' ,   ' c a t e g o r y ' ,   ' f r o m _ s t o c k _ s p a n ' ,   ' s t o c k _ t r a n s f e r ' ,   ' a c t i o n s ' ,   ' c o m m i t t e d _ q t y _ d i s p l a y ' ] ) 
 
                           - > m a k e ( t r u e ) ; 
 
           } 
 
   
 
 @ @   - 3 9 1 , 1 4   + 4 2 3 , 1 4   @ @   c l a s s   T p s A d d S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                   $ s e l l i n g P e r i o d I n M i n u t e s   =   i n t v a l ( $ s e l l i n g P e r i o d )   *   1 4 4 0 ; 
 
                   $ f u t u r e P e r i o d   =   r e q u e s t ( ) - > g e t ( ' f u t u r e _ p e r i o d ' ,   0 ) ; 
 
   
 
 - / /                 v a r _ d u m p ( $ b u s i n e s s I d ) ; 
 
 - / /                 v a r _ d u m p ( $ t o L o c a t i o n I d ) ; 
 
 - / /                 v a r _ d u m p ( $ c a t e g o r y I d ) ; 
 
 - / /                 v a r _ d u m p ( $ s u b C a t e g o r y I d ) ; 
 
 - / /                 v a r _ d u m p ( $ b r a n d I d ) ; 
 
 - / /                 v a r _ d u m p ( $ s e l l i n g P e r i o d ) ; 
 
 - / /                 v a r _ d u m p ( $ f u t u r e P e r i o d ) ; 
 
 - / /                 e x i t ; 
 
 +                 / /   v a r _ d u m p ( $ b u s i n e s s I d ) ; 
 
 +                 / /   v a r _ d u m p ( $ t o L o c a t i o n I d ) ; 
 
 +                 / /   v a r _ d u m p ( $ c a t e g o r y I d ) ; 
 
 +                 / /   v a r _ d u m p ( $ s u b C a t e g o r y I d ) ; 
 
 +                 / /   v a r _ d u m p ( $ b r a n d I d ) ; 
 
 +                 / /   v a r _ d u m p ( $ s e l l i n g P e r i o d ) ; 
 
 +                 / /   v a r _ d u m p ( $ f u t u r e P e r i o d ) ; 
 
 +                 / /   e x i t ; 
 
   
 
                   / * * 
 
                     *   T h e   m a i n   p u r p o s e   o f   t h i s   q u e r y   i s   t o   g e t   t h e   p r o d u c t s : 
 
 @ @   - 4 7 2 , 9   + 5 0 4 , 1 0   @ @   c l a s s   T p s A d d S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           $ q u e r y - > w h e r e ( ' p r o d u c t s . b r a n d _ i d ' ,   $ b r a n d I d ) ; 
 
                   } 
 
   
 
 - / / p r i n t _ r ( $ q u e r y - > g e t ( ) ) ; 
 
 + / /   p r i n t _ r ( $ t s l _ q u e r y - > g e t ( ) ) ; 
 
 + / /   p r i n t _ r ( $ q u e r y - > g e t ( ) ) ; 
 
   / / p r i n t _ r ( $ t h i s - > g e t S q l W i t h B i n d i n g s ( $ q u e r y ) ) ; 
 
 - / / e x i t ; 
 
 + / /   e x i t ; 
 
                   r e t u r n   j s o n _ e n c o d e ( $ q u e r y - > g e t ( ) - > k e y B y ( ' p v ' ) ) ; 
 
           } 
 
   
 
 d i f f   - - g i t   a / H t t p / C o n t r o l l e r s / T p s P r e p a r e S t o c k C o n t r o l l e r . p h p   b / H t t p / C o n t r o l l e r s / T p s P r e p a r e S t o c k C o n t r o l l e r . p h p 
 
 i n d e x   b 7 e e 5 4 b . . 2 e 2 2 a 6 6   1 0 0 6 4 4 
 
 - - -   a / H t t p / C o n t r o l l e r s / T p s P r e p a r e S t o c k C o n t r o l l e r . p h p 
 
 + + +   b / H t t p / C o n t r o l l e r s / T p s P r e p a r e S t o c k C o n t r o l l e r . p h p 
 
 @ @   - 9 2 , 3 3   + 9 2 , 3 2   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                   $ q u e r y   =   N s t P r e p a r e S t o c k : : q u e r y ( ) 
 
                           - > w h e r e ( ' n s t _ p r e p a r e _ p r o d u c t s . s t a t u s ' ,   ' p r e p a r e ' ) 
 
                           - > w h e r e ( ' n s t _ p r e p a r e _ p r o d u c t s . b u s i n e s s _ i d ' ,   $ b u s i n e s s I d ) 
 
 -                         - > l e f t J o i n ( ' u s e r s ' , ' u s e r s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . c r e a t e d _ b y ' ) 
 
 -                         - > l e f t J o i n ( ' b u s i n e s s _ l o c a t i o n s   a s   f r o m _ b u s i n e s s _ l o c a t i o n s ' , ' f r o m _ b u s i n e s s _ l o c a t i o n s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d ' ) 
 
 -                         - > l e f t J o i n ( ' p r o d u c t s ' , ' p r o d u c t s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . p r o d u c t _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' u s e r s ' ,   ' u s e r s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . c r e a t e d _ b y ' ) 
 
 +                         - > l e f t J o i n ( ' b u s i n e s s _ l o c a t i o n s   a s   f r o m _ b u s i n e s s _ l o c a t i o n s ' ,   ' f r o m _ b u s i n e s s _ l o c a t i o n s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' p r o d u c t s ' ,   ' p r o d u c t s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . p r o d u c t _ i d ' ) 
 
                           - > l e f t J o i n ( ' c a t e g o r i e s   a s   c 1 ' ,   ' p r o d u c t s . c a t e g o r y _ i d ' ,   ' = ' ,   ' c 1 . i d ' ) 
 
                           - > l e f t J o i n ( ' c a t e g o r i e s   a s   c 2 ' ,   ' p r o d u c t s . s u b _ c a t e g o r y _ i d ' ,   ' = ' ,   ' c 2 . i d ' ) 
 
                           - > l e f t J o i n ( ' b r a n d s ' ,   ' p r o d u c t s . b r a n d _ i d ' ,   ' = ' ,   ' b r a n d s . i d ' ) 
 
                           - > j o i n ( ' u n i t s ' ,   ' p r o d u c t s . u n i t _ i d ' ,   ' = ' ,   ' u n i t s . i d ' ) 
 
                           - > l e f t J o i n ( ' t a x _ r a t e s ' ,   ' p r o d u c t s . t a x ' ,   ' = ' ,   ' t a x _ r a t e s . i d ' ) 
 
 -                         - > l e f t J o i n ( ' v a r i a t i o n s ' , ' v a r i a t i o n s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . v a r i a t i o n _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' v a r i a t i o n s ' ,   ' v a r i a t i o n s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . v a r i a t i o n _ i d ' ) 
 
                           - > j o i n ( ' p r o d u c t _ v a r i a t i o n s   a s   p v ' ,   ' p v . i d ' ,   ' = ' ,   ' v a r i a t i o n s . p r o d u c t _ v a r i a t i o n _ i d ' ) 
 
 -                         - > l e f t J o i n ( ' p u r c h a s e _ l i n e s ' , ' p u r c h a s e _ l i n e s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . p u r c h a s e _ l i n e s _ i d ' ) 
 
 -                         - > l e f t J o i n ( ' b u s i n e s s _ l o c a t i o n s   a s   t o _ b u s i n e s s _ l o c a t i o n s ' , ' t o _ b u s i n e s s _ l o c a t i o n s . i d ' , ' = ' , ' n s t _ p r e p a r e _ p r o d u c t s . t o _ l o c a t i o n _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' p u r c h a s e _ l i n e s ' ,   ' p u r c h a s e _ l i n e s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . p u r c h a s e _ l i n e s _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' b u s i n e s s _ l o c a t i o n s   a s   t o _ b u s i n e s s _ l o c a t i o n s ' ,   ' t o _ b u s i n e s s _ l o c a t i o n s . i d ' ,   ' = ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . t o _ l o c a t i o n _ i d ' ) 
 
                           - > w h e r e N u l l ( ' n s t _ p r e p a r e _ p r o d u c t s . d e l e t e d _ a t ' ) 
 
 - 
 
 -                         - > l e f t J o i n ( ' v a r i a t i o n _ l o c a t i o n _ d e t a i l s   a s   t o _ v l d ' , f u n c t i o n ( $ j o i n )   { 
 
 -                                 $ j o i n - > o n ( ' v a r i a t i o n s . i d ' , ' = ' , ' t o _ v l d . v a r i a t i o n _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' v a r i a t i o n _ l o c a t i o n _ d e t a i l s   a s   t o _ v l d ' ,   f u n c t i o n   ( $ j o i n )   { 
 
 +                                 $ j o i n - > o n ( ' v a r i a t i o n s . i d ' ,   ' = ' ,   ' t o _ v l d . v a r i a t i o n _ i d ' ) 
 
                                           - > w h e r e R a w ( ' t o _ v l d . l o c a t i o n _ i d   =   t o _ b u s i n e s s _ l o c a t i o n s . i d ' ) ; 
 
                           } ) 
 
 -                         - > l e f t J o i n ( ' v a r i a t i o n _ l o c a t i o n _ d e t a i l s   a s   f r o m _ v l d ' , f u n c t i o n ( $ j o i n )   { 
 
 -                                 $ j o i n - > o n ( ' v a r i a t i o n s . i d ' , ' = ' , ' f r o m _ v l d . v a r i a t i o n _ i d ' ) 
 
 +                         - > l e f t J o i n ( ' v a r i a t i o n _ l o c a t i o n _ d e t a i l s   a s   f r o m _ v l d ' ,   f u n c t i o n   ( $ j o i n )   { 
 
 +                                 $ j o i n - > o n ( ' v a r i a t i o n s . i d ' ,   ' = ' ,   ' f r o m _ v l d . v a r i a t i o n _ i d ' ) 
 
                                           - > w h e r e R a w ( ' f r o m _ v l d . l o c a t i o n _ i d   =   f r o m _ b u s i n e s s _ l o c a t i o n s . i d ' ) ; 
 
                           } ) ; 
 
   
 
                   i f   ( ! e m p t y ( $ f r o m _ l o c a t i o n _ i d )   & &   $ f r o m _ l o c a t i o n _ i d   ! =   ' n o n e ' )   { 
 
                           $ q u e r y - > w h e r e ( ' n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d ' ,   ' = ' ,   $ f r o m _ l o c a t i o n _ i d ) ; 
 
 -                 } e l s e { 
 
 - 	                 $ q u e r y - > w h e r e R a w (   ' 1   =   2 '   ) ; 
 
 +                 }   e l s e   { 
 
 +                         $ q u e r y - > w h e r e R a w ( ' 1   =   2 ' ) ; 
 
                   } 
 
   
 
                   i f   ( ! e m p t y ( $ t o _ l o c a t i o n _ i d )   & &   $ t o _ l o c a t i o n _ i d   ! =   ' n o n e ' )   { 
 
 @ @   - 1 4 8 , 1 5   + 1 4 7 , 1 5   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           ' p u r c h a s e _ l i n e s . i d   a s   p u r c h a s e _ l i n e _ i d ' , 
 
                           ' p u r c h a s e _ l i n e s . l o t _ n u m b e r ' , 
 
                           ' p u r c h a s e _ l i n e s . p u r c h a s e _ p r i c e ' , 
 
 -                         ' p u r c h a s e _ l i n e s . q u a n t i t y   a s   p u r c h a s e _ l i n e s _ q u a n t i t y ' , 
 
 +                         D B : : r a w ( ' ( p u r c h a s e _ l i n e s . q u a n t i t y   -   p u r c h a s e _ l i n e s . q u a n t i t y _ s o l d   -   p u r c h a s e _ l i n e s . q u a n t i t y _ a d j u s t e d   -   p u r c h a s e _ l i n e s . q u a n t i t y _ r e t u r n e d   +   p u r c h a s e _ l i n e s . m f g _ q u a n t i t y _ u s e d )   a s   p u r c h a s e _ l i n e s _ q u a n t i t y ' ) , 
 
                           ' p u r c h a s e _ l i n e s . p u r c h a s e _ p r i c e _ i n c _ t a x ' , 
 
                           ' n s t _ p r e p a r e _ p r o d u c t s . t r a n s f e r _ q u a n t i t y ' , 
 
                           ' t o _ l o c a t i o n _ i d ' , 
 
                           ' t o _ b u s i n e s s _ l o c a t i o n s . n a m e   a s   t o _ l o c a t i o n _ n a m e ' , 
 
                           ' n s t _ p r e p a r e _ p r o d u c t s . i s _ i m p o r t a n t ' , 
 
                           ' n s t _ p r e p a r e _ p r o d u c t s . n o t e ' , 
 
 - 	                 ' n s t _ p r e p a r e _ p r o d u c t s . c r e a t e d _ a t ' , 
 
 - 	                 D B : : r a w ( ' t o _ v l d . q t y _ a v a i l a b l e   a s   t o _ q t y _ a v a i l a b l e ' ) , 
 
 +                         ' n s t _ p r e p a r e _ p r o d u c t s . c r e a t e d _ a t ' , 
 
 +                         D B : : r a w ( ' t o _ v l d . q t y _ a v a i l a b l e   a s   t o _ q t y _ a v a i l a b l e ' ) , 
 
                           D B : : r a w ( ' f r o m _ v l d . q t y _ a v a i l a b l e   a s   f r o m _ q t y _ a v a i l a b l e ' ) 
 
                   ) ; 
 
                   i f   ( ! r e q u e s t ( ) - > g e t ( ' o r d e r ' ) )   { 
 
 @ @   - 1 9 5 , 4 4   + 1 9 4 , 5 0   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                   } 
 
   
 
                   r e t u r n   D a t a t a b l e s : : o f ( $ q u e r y ) 
 
 - 	                 - > e d i t C o l u m n ( ' c r e a t e d _ a t ' ,   ' { { @ f o r m a t _ d a t e t i m e ( $ c r e a t e d _ a t ) } } ' ) 
 
 - 	                 - > a d d C o l u m n ( ' d a t a - h r e f ' ,   f u n c t i o n   ( $ r o w ) { 
 
 +                         - > e d i t C o l u m n ( ' c r e a t e d _ a t ' ,   ' { { @ f o r m a t _ d a t e t i m e ( $ c r e a t e d _ a t ) } } ' ) 
 
 +                         - > a d d C o l u m n ( ' d a t a - h r e f ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   r e t u r n   a c t i o n ( ' \ \ A p p \ H t t p \ C o n t r o l l e r s \ P r o d u c t C o n t r o l l e r @ v i e w ' ,   [ $ r o w - > p r o d u c t _ i d ] ) ; 
 
                           } ) 
 
 -                         - > a d d C o l u m n ( ' r o w _ c h e c k b o x ' ,   f u n c t i o n   ( $ r o w ) { 
 
 +                         - > a d d C o l u m n ( ' r o w _ c h e c k b o x ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   r e t u r n   " < i n p u t   t y p e = ' c h e c k b o x '   c l a s s = ' p r o d u c t - r o w - i n p u t '   v a l u e = ' 1 '   d a t a - i d = ' { $ r o w - > i d } '   d a t a - n a m e = ' a c c e p t e d ' >   " ; 
 
                           } ) 
 
 -                         - > e d i t C o l u m n ( ' f r o m _ l o c a t i o n _ n a m e ' ,   f u n c t i o n   ( $ r o w ) { 
 
 +                         - > e d i t C o l u m n ( ' f r o m _ l o c a t i o n _ n a m e ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   $ f r o m _ q t y _ a v a i l a b l e   =   $ r o w - > f r o m _ q t y _ a v a i l a b l e ; 
 
 -                                 / /   i f ( $ r o w - > p u r c h a s e _ l i n e _ i d ) { 
 
 -                                 / /           $ f r o m _ q t y _ a v a i l a b l e   =   $ r o w - > p u r c h a s e _ l i n e s _ q u a n t i t y ; 
 
 -                                 / /   } 
 
 -                                 r e t u r n   $ r o w - > f r o m _ l o c a t i o n _ n a m e   . '   ( ' . i n t v a l ( $ f r o m _ q t y _ a v a i l a b l e ) . ' ) ' ; 
 
 +                                 i f ( $ r o w - > p u r c h a s e _ l i n e _ i d ) { 
 
 +                                         $ f r o m _ q t y _ a v a i l a b l e   =   $ r o w - > p u r c h a s e _ l i n e s _ q u a n t i t y ; 
 
 +                                 } 
 
 +                                 r e t u r n   $ r o w - > f r o m _ l o c a t i o n _ n a m e   .   '   ( '   .   i n t v a l ( $ f r o m _ q t y _ a v a i l a b l e )   .   ' ) ' ; 
 
                           } ) 
 
 -                         - > e d i t C o l u m n ( ' t o _ l o c a t i o n _ n a m e ' ,   f u n c t i o n   ( $ r o w ) { 
 
 -                                 r e t u r n   $ r o w - > t o _ l o c a t i o n _ n a m e   . '   ( ' . i n t v a l ( $ r o w - > t o _ q t y _ a v a i l a b l e ) . ' ) ' ; 
 
 +                         - > e d i t C o l u m n ( ' t o _ l o c a t i o n _ n a m e ' ,   f u n c t i o n   ( $ r o w )   { 
 
 +                                 r e t u r n   $ r o w - > t o _ l o c a t i o n _ n a m e   .   '   ( '   .   i n t v a l ( $ r o w - > t o _ q t y _ a v a i l a b l e )   .   ' ) ' ; 
 
                           } ) 
 
 -                         - > a d d C o l u m n ( ' t r a n s f e r _ q u a n t i t y _ i n p u t ' ,   f u n c t i o n   ( $ r o w ) { 
 
 +                         - > e d i t C o l u m n ( ' f r o m _ q t y _ a v a i l a b l e ' ,   f u n c t i o n   ( $ r o w )   { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ l i n e _ i d )   { 
 
 +                                         r e t u r n   $ r o w - > p u r c h a s e _ l i n e s _ q u a n t i t y ; 
 
 +                                 } 
 
 +                                 r e t u r n   $ r o w - > f r o m _ q t y _ a v a i l a b l e ; 
 
 +                         } ) 
 
 +                         - > a d d C o l u m n ( ' t r a n s f e r _ q u a n t i t y _ i n p u t ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   $ f r o m _ q t y _ a v a i l a b l e   =   $ r o w - > f r o m _ q t y _ a v a i l a b l e ; 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ l i n e _ i d ) { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ l i n e _ i d )   { 
 
                                           $ f r o m _ q t y _ a v a i l a b l e   =   $ r o w - > p u r c h a s e _ l i n e s _ q u a n t i t y ; 
 
                                   } 
 
   
 
 -                                 $ h t m l   =   " < i n p u t   i d = ' t Q t y _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   d a t a - n a m e = ' t r a n s f e r _ q u a n t i t y '   c l a s s = ' f o r m - c o n t r o l   p r o d u c t - r o w - i n p u t   t r a n s f e r _ q u a n t i t y   r o w - s e l e c t '   s t y l e = ' w i d t h : 1 0 0 % '   t y p e = ' n u m b e r '   m i n = ' 1 '   m a x = ' " . i n t v a l ( $ f r o m _ q t y _ a v a i l a b l e ) . " '   v a l u e = ' " . i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) . " ' > " ; 
 
 +                                 $ h t m l   =   " < i n p u t   i d = ' t Q t y _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   d a t a - n a m e = ' t r a n s f e r _ q u a n t i t y '   c l a s s = ' f o r m - c o n t r o l   p r o d u c t - r o w - i n p u t   t r a n s f e r _ q u a n t i t y   r o w - s e l e c t '   s t y l e = ' w i d t h : 1 0 0 % '   t y p e = ' n u m b e r '   m i n = ' 1 '   m a x = ' "   .   i n t v a l ( $ f r o m _ q t y _ a v a i l a b l e )   .   " '   v a l u e = ' "   .   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y )   .   " ' > " ; 
 
   
 
                                   r e t u r n   $ h t m l ; 
 
 -                         } ) 
 
 -                         - > a d d C o l u m n ( ' a c t i o n s ' ,   f u n c t i o n   ( $ r o w ) { 
 
 +                         } ) / / f r o m _ q t y _ a v a i l a b l e ,   p u r c h a s e _ l i n e s _ q u a n t i t y 
 
 +                         - > a d d C o l u m n ( ' a c t i o n s ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   $ c l a s s   =   i s _ n u l l ( $ r o w - > n o t e )   ?   ' '   :   ' b t n - s u c c e s s ' ; 
 
                                   $ h t m l   =   " 
 
                                   < d i v   c l a s s = ' b t n - g r o u p ' > 
 
                                           < d i v   c l a s s = ' d r o p d o w n   a c t i o n s - l i s t ' > 
 
 -                                                 < b u t t o n   c l a s s = ' b t n   b t n - p r i m a r y   { $ c l a s s }   d r o p d o w n - t o g g l e '   t y p e = ' b u t t o n '   d a t a - t o g g l e = ' d r o p d o w n '   i d = ' a c t i o n s _ b t n _ { $ r o w - > i d } ' > " . _ _ ( ' m e s s a g e s . a c t i o n s ' ) . " < / b u t t o n > 
 
 +                                                 < b u t t o n   c l a s s = ' b t n   b t n - p r i m a r y   { $ c l a s s }   d r o p d o w n - t o g g l e '   t y p e = ' b u t t o n '   d a t a - t o g g l e = ' d r o p d o w n '   i d = ' a c t i o n s _ b t n _ { $ r o w - > i d } ' > "   .   _ _ ( ' m e s s a g e s . a c t i o n s ' )   .   " < / b u t t o n > 
 
                                                   < d i v   c l a s s = ' d r o p d o w n - m e n u   d r o p d o w n - m e n u - r i g h t ' > 
 
 -                                                 < l i > < a   t a r g e t = ' _ b l a n k '   h r e f = ' " . a c t i o n ( ' \ M o d u l e s \ T p s T r a n s f e r \ H t t p \ C o n t r o l l e r s \ T p s L a b e l s C o n t r o l l e r @ s h o w ' ,   [ ' p r o d u c t _ i d '   = >   $ r o w - > p r o d u c t _ i d ,   ' q t y '   = >   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) ,   ' p u r c h a s e _ l i n e _ i d '   = >   i n t v a l ( $ r o w - > p u r c h a s e _ l i n e _ i d ) ] )   . " '   d a t a - t o g g l e = ' t o o l t i p '   t i t l e = ' "   .   _ _ ( ' l a n g _ v 1 . l a b e l _ h e l p ' )   .   " ' > < i   c l a s s = ' f a   f a - b a r c o d e ' > < / i >   "   .   _ _ ( ' b a r c o d e . l a b e l s ' )   .   " < / a > < / l i > 
 
 -                                                 < l i > < a   d a t a - t o g g l e = ' m o d a l '   d a t a - t a r g e t = ' # a d d _ n o t e s '   i d = ' n o t e _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   c l a s s = ' b t n   d r o p d o w n - i t e m   a d d _ n o t e s '   t y p e = ' b u t t o n ' > " . _ _ ( ' t p s T r a n s f e r : : l a n g . n o t e ' ) . " < / a > < / l i > " ; 
 
 +                                                 < l i > < a   t a r g e t = ' _ b l a n k '   h r e f = ' "   .   a c t i o n ( ' \ M o d u l e s \ T p s T r a n s f e r \ H t t p \ C o n t r o l l e r s \ T p s L a b e l s C o n t r o l l e r @ s h o w ' ,   [ ' p r o d u c t _ i d '   = >   $ r o w - > p r o d u c t _ i d ,   ' q t y '   = >   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) ,   ' p u r c h a s e _ l i n e _ i d '   = >   i n t v a l ( $ r o w - > p u r c h a s e _ l i n e _ i d ) ] )   .   " '   d a t a - t o g g l e = ' t o o l t i p '   t i t l e = ' "   .   _ _ ( ' l a n g _ v 1 . l a b e l _ h e l p ' )   .   " ' > < i   c l a s s = ' f a   f a - b a r c o d e ' > < / i >   "   .   _ _ ( ' b a r c o d e . l a b e l s ' )   .   " < / a > < / l i > 
 
 +                                                 < l i > < a   d a t a - t o g g l e = ' m o d a l '   d a t a - t a r g e t = ' # a d d _ n o t e s '   i d = ' n o t e _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   c l a s s = ' b t n   d r o p d o w n - i t e m   a d d _ n o t e s '   t y p e = ' b u t t o n ' > "   .   _ _ ( ' t p s T r a n s f e r : : l a n g . n o t e ' )   .   " < / a > < / l i > " ; 
 
                                   i f   ( a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . c a n _ d e l e t e _ n s t _ r o w ' ) )   { 
 
 -                                         $ h t m l   . =   " < l i > < a   d a t a - t o g g l e = ' m o d a l '   d a t a - t a r g e t = ' # d e l e t e _ c o n f i r m '   i d = ' d e l e t e _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   c l a s s = ' b t n   d r o p d o w n - i t e m   d e l e t e _ r o w _ b u t t o n '   t y p e = ' b u t t o n ' > " . _ _ ( ' m e s s a g e s . d e l e t e ' ) . " < / a > < / l i > " ; 
 
 +                                         $ h t m l   . =   " < l i > < a   d a t a - t o g g l e = ' m o d a l '   d a t a - t a r g e t = ' # d e l e t e _ c o n f i r m '   i d = ' d e l e t e _ { $ r o w - > i d } '   d a t a - i d = ' { $ r o w - > i d } '   c l a s s = ' b t n   d r o p d o w n - i t e m   d e l e t e _ r o w _ b u t t o n '   t y p e = ' b u t t o n ' > "   .   _ _ ( ' m e s s a g e s . d e l e t e ' )   .   " < / a > < / l i > " ; 
 
                                   } 
 
                                   $ h t m l   . =   " 
 
                                                   < / d i v > 
 
 @ @   - 2 5 2 , 7   + 2 5 7 , 7   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                   r e t u r n   ' < d i v   s t y l e = " d i s p l a y :   f l e x ; " > < i m g   s r c = " '   .   $ r o w - > i m a g e _ u r l   .   ' "   a l t = " P r o d u c t   i m a g e "   c l a s s = " p r o d u c t - t h u m b n a i l - s m a l l " > < / d i v > ' ; 
 
                           } ) 
 
                           - > e d i t C o l u m n ( ' p u r c h a s e _ p r i c e ' ,   f u n c t i o n   ( $ r o w )   u s e   ( $ b u s i n e s s I d )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
                                           r e t u r n   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
                                   } 
 
   
 
 @ @   - 2 6 2 , 1 2   + 2 6 7 , 1 2   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
   
 
                                   $ l o t N u m b e r s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > g e t L o t D a t a F r o m V a r i a t i o n ( $ r o w - > v a r i a t i o n _ i d ,   $ b u s i n e s s I d ,   $ r o w - > f r o m _ l o c a t i o n _ i d ,   t r u e ) ; 
 
   
 
 -                                 i f ( $ l o t N u m b e r s ) { 
 
 +                                 i f   ( $ l o t N u m b e r s )   { 
 
                                           f o r e a c h   ( $ l o t N u m b e r s   a s   $ l o t N u m b e r )   { 
 
                                                   $ a v g P u r c h a s e P r i c e   + =   $ l o t N u m b e r - > p u r c h a s e _ p r i c e   *   $ l o t N u m b e r - > q t y _ a v a i l a b l e ; 
 
                                                   $ c o u n t   + =   $ l o t N u m b e r - > q t y _ a v a i l a b l e ; 
 
                                           } 
 
 -                                         i f ( $ c o u n t ) { 
 
 +                                         i f   ( $ c o u n t )   { 
 
                                                   $ a v g P u r c h a s e P r i c e   =   $ a v g P u r c h a s e P r i c e   /   $ c o u n t ; 
 
                                           } 
 
                                   } 
 
 @ @   - 2 7 8 , 7   + 2 8 3 , 7   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                   r e t u r n   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) ; 
 
                           } ) 
 
                           - > f i l t e r C o l u m n ( ' p r o d u c t s . s k u ' ,   f u n c t i o n   ( $ q u e r y ,   $ k e y w o r d )   { 
 
 -                                 $ q u e r y - > w h e r e H a s ( ' p r o d u c t . v a r i a t i o n s ' ,   f u n c t i o n ( $ q )   u s e ( $ k e y w o r d ) { 
 
 +                                 $ q u e r y - > w h e r e H a s ( ' p r o d u c t . v a r i a t i o n s ' ,   f u n c t i o n   ( $ q )   u s e   ( $ k e y w o r d )   { 
 
                                           $ q - > w h e r e ( ' s u b _ s k u ' ,   ' l i k e ' ,   " % { $ k e y w o r d } % " ) ; 
 
                                   } ) 
 
                                           - > o r W h e r e ( ' p r o d u c t s . s k u ' ,   ' l i k e ' ,   " % { $ k e y w o r d } % " ) ; 
 
 @ @   - 2 9 2 , 6 0   + 2 9 7 , 1 0 1   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                                   r e t u r n   ' b g - r e d ' ; 
 
                                           } 
 
                                           r e t u r n   ' ' ; 
 
 -                                 } 
 
 +                                 } , 
 
                           ] ) 
 
                           - > r a w C o l u m n s ( [ ' a c t i o n s ' ,   ' r o w _ c h e c k b o x ' ,   ' p r o d u c t ' ,   ' s e l l i n g _ p r i c e ' ,   ' p u r c h a s e _ p r i c e ' ,   ' c a t e g o r y ' ,   ' t r a n s f e r _ q u a n t i t y _ i n p u t ' ] ) 
 
                           - > m a k e ( t r u e ) ; 
 
           } 
 
   
 
 -         p u b l i c   f u n c t i o n   s t o r e ( R e q u e s t   $ r e q u e s t ) { 
 
 -                 i f ( ! $ r e q u e s t - > m a n u a l T p s D a t a   | |   c o u n t ( $ r e q u e s t - > m a n u a l T p s D a t a )   = =   0 ) { 
 
 +         p u b l i c   f u n c t i o n   s t o r e ( R e q u e s t   $ r e q u e s t ) 
 
 +         { 
 
 +                 i f   ( ! a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . a c c e s s _ p r e p a r e _ s t o c k _ t r a n s f e r ' ) )   { 
 
 +                         a b o r t ( 4 0 3 ,   ' U n a u t h o r i z e d   a c t i o n . ' ) ; 
 
 +                 } 
 
 + 
 
 +                 i f   ( ! $ r e q u e s t - > m a n u a l T p s D a t a   | |   c o u n t ( $ r e q u e s t - > m a n u a l T p s D a t a )   = =   0 )   { 
 
                           r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ] ) ; 
 
                   } 
 
   
 
 -                 D B : : b e g i n T r a n s a c t i o n ( ) ; 
 
 +                 t r y   { 
 
 +                         D B : : b e g i n T r a n s a c t i o n ( ) ; 
 
 + 
 
 +                         $ b u s i n e s s I d   =   r e q u e s t ( ) - > s e s s i o n ( ) - > g e t ( ' u s e r . b u s i n e s s _ i d ' ) ; 
 
 +                         $ t r a n s a c t i o n D a t e   =   $ t h i s - > p r o d u c t U t i l - > u f _ d a t e ( r e q u e s t ( ) - > g e t ( ' t r a n s a c t i o n _ d a t e ' ,   n u l l ) ,   t r u e ) ; 
 
 +                         $ c r e a t e d B y   =   a u t h ( ) - > u s e r ( ) - > i d ; 
 
 +                         $ c r e a t e d A t   =   n o w ( ) ; 
 
 +                         $ u p d a t e d A t   =   n o w ( ) ; 
 
 +                         $ i s S h i p p i n g C a l c u l a t e d   =   f a l s e ; 
 
 +                         $ n s t S h i p p i n g I d   =   n u l l ; 
 
 + 
 
 +                         f o r e a c h   ( a r r a y _ c h u n k ( r e q u e s t ( ) - > g e t ( ' m a n u a l T p s D a t a ' ,   n u l l ) ,   5 0 0 ,   t r u e )   a s   $ c h u n k e d D a t a )   { 
 
 +                                 $ e x t r a D a t a   =   [ ] ; 
 
 +                                 f o r e a c h   ( $ c h u n k e d D a t a   a s   $ i n d e x   = >   $ d a t a )   { 
 
 +                                         $ l o t N u m b e r s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > g e t L o t D a t a F r o m V a r i a t i o n ( 
 
 +                                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' v a r i a t i o n _ i d ' ] ,   $ b u s i n e s s I d , 
 
 +                                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' f r o m _ l o c a t i o n _ i d ' ] ,   t r u e 
 
 +                                         ) ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' b u s i n e s s _ i d ' ]   =   $ b u s i n e s s I d ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' t r a n s a c t i o n _ d a t e ' ]   =   $ t r a n s a c t i o n D a t e ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' c r e a t e d _ b y ' ]   =   $ c r e a t e d B y ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' c r e a t e d _ a t ' ]   =   $ c r e a t e d A t ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' u p d a t e d _ a t ' ]   =   $ u p d a t e d A t ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' i s _ s h i p p i n g _ c a l c u l a t e d ' ]   =   $ i s S h i p p i n g C a l c u l a t e d ; 
 
 +                                         $ c h u n k e d D a t a [ $ i n d e x ] [ ' n s t _ s h i p p i n g _ i d ' ]   =   $ n s t S h i p p i n g I d ; 
 
 +                                         u n s e t ( $ c h u n k e d D a t a [ $ i n d e x ] [ ' c u s t o m _ f i e l d ' ] ) ; 
 
 + 
 
 +                                         i f   ( $ l o t N u m b e r s - > c o u n t ( )   >   1   & &   $ c h u n k e d D a t a [ $ i n d e x ] [ ' t r a n s f e r _ q u a n t i t y ' ]   >   $ l o t N u m b e r s - > f i r s t ( ) - > q t y _ a v a i l a b l e )   { 
 
 +                                                 $ r e m a i n i n g Q u a n t i t y   =   $ c h u n k e d D a t a [ $ i n d e x ] [ ' t r a n s f e r _ q u a n t i t y ' ]   -   $ l o t N u m b e r s - > f i r s t ( ) - > q t y _ a v a i l a b l e ; 
 
 +                                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' t r a n s f e r _ q u a n t i t y ' ]   =   $ l o t N u m b e r s - > f i r s t ( ) - > q t y _ a v a i l a b l e ; 
 
 +                                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' p u r c h a s e _ l i n e s _ i d ' ]   =   $ l o t N u m b e r s - > f i r s t ( ) - > p u r c h a s e _ l i n e _ i d ; 
 
 + 
 
 +                                                 $ p r o d u c t D a t a   =   a r r a y _ m e r g e ( [ ] ,   $ c h u n k e d D a t a [ $ i n d e x ] ) ; 
 
 +                                                 f o r e a c h   ( $ l o t N u m b e r s - > s k i p ( 1 )   a s   $ l o t N u m b e r )   { 
 
 +                                                         $ q t y   =   m i n ( $ l o t N u m b e r - > q t y _ a v a i l a b l e ,   $ r e m a i n i n g Q u a n t i t y ) ; 
 
 +                                                         $ e x t r a D a t a [ ]   =   a r r a y _ m e r g e ( $ p r o d u c t D a t a ,   [ 
 
 +                                                                 ' t r a n s f e r _ q u a n t i t y '   = >   $ q t y , 
 
 +                                                                 ' p u r c h a s e _ l i n e s _ i d '   = >   $ l o t N u m b e r - > p u r c h a s e _ l i n e _ i d , 
 
 +                                                         ] ) ; 
 
 +                                                         $ r e m a i n i n g Q u a n t i t y   - =   $ q t y ; 
 
 +                                                         i f   ( $ r e m a i n i n g Q u a n t i t y   < =   0 ) 
 
 +                                                                 b r e a k ; 
 
 +                                                 } 
 
 +                                         } 
 
 +                                 } 
 
   
 
 -                 $ b u s i n e s s I d   =   r e q u e s t ( ) - > s e s s i o n ( ) - > g e t ( ' u s e r . b u s i n e s s _ i d ' ) ; 
 
 -                 $ t r a n s a c t i o n D a t e   =   $ t h i s - > p r o d u c t U t i l - > u f _ d a t e ( r e q u e s t ( ) - > g e t ( ' t r a n s a c t i o n _ d a t e ' ,   n u l l ) ,   t r u e ) ; 
 
 -                 $ c r e a t e d B y   =   a u t h ( ) - > u s e r ( ) - > i d ; 
 
 -                 $ c r e a t e d A t   =   n o w ( ) ; 
 
 -                 $ u p d a t e d A t   =   n o w ( ) ; 
 
 -                 $ i s S h i p p i n g C a l c u l a t e d   =   f a l s e ; 
 
 -                 $ n s t S h i p p i n g I d   =   n u l l ; 
 
 - 
 
 -                 f o r e a c h ( a r r a y _ c h u n k ( r e q u e s t ( ) - > g e t ( ' m a n u a l T p s D a t a ' ,   n u l l ) ,   5 0 0 ,   t r u e )   a s   $ c h u n k e d D a t a ) { 
 
 -                         f o r e a c h ( $ c h u n k e d D a t a   a s   $ i n d e x   = >   $ d a t a ) { 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' b u s i n e s s _ i d ' ]   =   $ b u s i n e s s I d ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' t r a n s a c t i o n _ d a t e ' ]   =   $ t r a n s a c t i o n D a t e ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' c r e a t e d _ b y ' ]   =   $ c r e a t e d B y ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' c r e a t e d _ a t ' ]   =   $ c r e a t e d A t ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' u p d a t e d _ a t ' ]   =   $ u p d a t e d A t ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' i s _ s h i p p i n g _ c a l c u l a t e d ' ]   =   $ i s S h i p p i n g C a l c u l a t e d ; 
 
 -                                 $ c h u n k e d D a t a [ $ i n d e x ] [ ' n s t _ s h i p p i n g _ i d ' ]   =   $ n s t S h i p p i n g I d ; 
 
 -                                 u n s e t ( $ c h u n k e d D a t a [ $ i n d e x ] [ ' c u s t o m _ f i e l d ' ] ) ; 
 
 -                         } 
 
   
 
 -                         $ n s t P r e p a r e S t o c k C r e a t i o n   =   N s t P r e p a r e S t o c k : : i n s e r t ( $ c h u n k e d D a t a ) ; 
 
 +                                 $ n s t P r e p a r e S t o c k C r e a t i o n   =   N s t P r e p a r e S t o c k : : i n s e r t ( a r r a y _ m e r g e ( a r r a y _ v a l u e s ( $ c h u n k e d D a t a ) ,   $ e x t r a D a t a ) ) ; 
 
   
 
 -                         i f ( $ n s t P r e p a r e S t o c k C r e a t i o n ) { 
 
 -                                 c o n t i n u e ; 
 
 +                                 i f   ( $ n s t P r e p a r e S t o c k C r e a t i o n )   { 
 
 +                                         c o n t i n u e ; 
 
 +                                 } 
 
 +                                 D B : : r o l l B a c k ( ) ; 
 
 +                                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ] ) ; 
 
                           } 
 
 + 
 
 +                         D B : : c o m m i t ( ) ; 
 
 +                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ] ) ; 
 
 + 
 
 +                 }   c a t c h   ( \ E x c e p t i o n   $ e )   { 
 
                           D B : : r o l l B a c k ( ) ; 
 
 -                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ] ) ; 
 
 +                         \ L o g : : e r r o r ( ' T P S   P r e p a r e   f a i l e d :   '   .   $ e - > g e t M e s s a g e ( ) ) ; 
 
 +                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   _ _ ( ' m e s s a g e s . s o m e t h i n g _ w e n t _ w r o n g ' ) ] ) ; 
 
                   } 
 
 - 
 
 -                 D B : : c o m m i t ( ) ; 
 
 -                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ] ) ; 
 
           } 
 
   
 
 -         p u b l i c   f u n c t i o n   u p d a t e ( R e q u e s t   $ r e q u e s t ) { 
 
 -                 i f ( ! i n _ a r r a y ( $ r e q u e s t - > s t a t u s ,   [ ' p r e p a r e ' ,   ' r e c e i v e ' ] ) ) { 
 
 +         p u b l i c   f u n c t i o n   u p d a t e ( R e q u e s t   $ r e q u e s t ) 
 
 +         { 
 
 +                 i f   ( ! a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . a c c e s s _ p r e p a r e _ s t o c k _ t r a n s f e r ' ) )   { 
 
 +                         a b o r t ( 4 0 3 ,   ' U n a u t h o r i z e d   a c t i o n . ' ) ; 
 
 +                 } 
 
 + 
 
 +                 i f   ( ! i n _ a r r a y ( $ r e q u e s t - > s t a t u s ,   [ ' p r e p a r e ' ,   ' r e c e i v e ' ] ) )   { 
 
                           r e t u r n   f a l s e ; 
 
                   } 
 
   
 
                   $ r e d i r e c t   =   " / t p s - p r o d u c t / { $ r e q u e s t - > s t a t u s } - s t o c k " ; 
 
   
 
 -                 f o r e a c h ( $ r e q u e s t - > p r e p a r e D o n e T p s D a t a   a s   $ i d   = >   $ d a t a ) { 
 
 +                 f o r e a c h   ( $ r e q u e s t - > p r e p a r e D o n e T p s D a t a   a s   $ i d   = >   $ d a t a )   { 
 
                           u n s e t ( $ d a t a [ ' a c c e p t e d ' ] ) ; 
 
                           $ d a t a [ ' s t a t u s ' ]   =   $ r e q u e s t - > s t a t u s ; 
 
   
 
 @ @   - 3 5 4 , 1 4   + 4 0 0 , 1 4   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           / /   C h e c k   t h e   v a l i d i t y   o f   t h e   q u a n t i t y   f r o m   L o c a t i o n   X   t o   L o c a t i o n   Y 
 
                           $ c h e c k S t a t u s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > c h e c k Q u a n t i t y M i s m a t c h ( $ n s t P r e p a r e S t o c k ,   \ A r r : : g e t ( $ d a t a ,   ' t r a n s f e r _ q u a n t i t y ' ) ) ; 
 
   
 
 -                         i f ( ! $ c h e c k S t a t u s ) { 
 
 +                         i f   ( ! $ c h e c k S t a t u s )   { 
 
                                   r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' c h e c k   q u a n t i t y   m i s m a t c h ' ] ) ; 
 
                           } 
 
   
 
                           $ n s t P r e p a r e S t o c k B e f o r e   =   $ n s t P r e p a r e S t o c k - > r e p l i c a t e ( ) ; 
 
                           $ n s t P r e p a r e S t o c k - > u p d a t e ( $ d a t a ) ; 
 
   
 
 -                         i f ( ! $ n s t P r e p a r e S t o c k ) { 
 
 +                         i f   ( ! $ n s t P r e p a r e S t o c k )   { 
 
                                   r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ] ) ; 
 
                           } 
 
                           $ t h i s - > u t i l - > a c t i v i t y L o g ( $ n s t P r e p a r e S t o c k ,   ' e d i t e d ' ,   $ n s t P r e p a r e S t o c k B e f o r e ) ; 
 
 @ @   - 3 6 9 , 2 0   + 4 1 5 , 3 0   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                   r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ,   ' r e d i r e c t '   = >   $ r e d i r e c t ] ) ; 
 
           } 
 
   
 
 -         p u b l i c   f u n c t i o n   d e s t r o y ( R e q u e s t   $ r e q u e s t ) { 
 
 +         p u b l i c   f u n c t i o n   d e s t r o y ( R e q u e s t   $ r e q u e s t ) 
 
 +         { 
 
 +                 i f   ( ! a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . a c c e s s _ p r e p a r e _ s t o c k _ t r a n s f e r ' ) )   { 
 
 +                         a b o r t ( 4 0 3 ,   ' U n a u t h o r i z e d   a c t i o n . ' ) ; 
 
 +                 } 
 
 + 
 
                   $ n s t P r e p a r e S t o c k   =   N s t P r e p a r e S t o c k : : f i n d O r F a i l ( $ r e q u e s t - > g e t ( ' i d ' ) ) ; 
 
 -                 i f ( $ n s t P r e p a r e S t o c k - > d e s t r o y ( $ r e q u e s t - > g e t ( ' i d ' ) ) ) { 
 
 +                 i f   ( $ n s t P r e p a r e S t o c k - > d e s t r o y ( $ r e q u e s t - > g e t ( ' i d ' ) ) )   { 
 
                           $ t h i s - > u t i l - > a c t i v i t y L o g ( $ n s t P r e p a r e S t o c k ,   ' d e l e t e d ' ) ; 
 
                           r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ] ) ; 
 
                   } 
 
                   r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ] ) ; 
 
           } 
 
 -         
 
 -         p u b l i c   f u n c t i o n   d e s t r o y S e l e c t e d ( R e q u e s t   $ r e q u e s t ) { 
 
 + 
 
 +         p u b l i c   f u n c t i o n   d e s t r o y S e l e c t e d ( R e q u e s t   $ r e q u e s t ) 
 
 +         { 
 
 +                 i f   ( ! a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . a c c e s s _ p r e p a r e _ s t o c k _ t r a n s f e r ' ) )   { 
 
 +                         a b o r t ( 4 0 3 ,   ' U n a u t h o r i z e d   a c t i o n . ' ) ; 
 
 +                 } 
 
 + 
 
                   $ n s t P r e p a r e S t o c k s   =   N s t P r e p a r e S t o c k : : w h e r e I n ( ' i d ' ,   a r r a y _ k e y s ( $ r e q u e s t - > p r e p a r e D o n e T p s D a t a ) ) - > g e t ( ) ; 
 
   
 
 -                 f o r e a c h ( $ n s t P r e p a r e S t o c k s   a s   $ n s t P r e p a r e S t o c k ) { 
 
 -                         i f ( $ n s t P r e p a r e S t o c k - > d e l e t e ( ) ) { 
 
 +                 f o r e a c h   ( $ n s t P r e p a r e S t o c k s   a s   $ n s t P r e p a r e S t o c k )   { 
 
 +                         i f   ( $ n s t P r e p a r e S t o c k - > d e l e t e ( ) )   { 
 
                                   $ t h i s - > u t i l - > a c t i v i t y L o g ( $ n s t P r e p a r e S t o c k ,   ' d e l e t e d ' ) ; 
 
                                   c o n t i n u e ; 
 
                           } 
 
 @ @   - 3 9 5 , 7   + 4 5 1 , 7   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
           { 
 
                   $ t p s D a t a   =   $ r e q u e s t - > t p s D a t a ; 
 
                   $ b u s i n e s s I d   =   r e q u e s t ( ) - > s e s s i o n ( ) - > g e t ( ' u s e r . b u s i n e s s _ i d ' ) ; 
 
 -                 $ s e t t i n g   =   ( N s t S e t t i n g : : w h e r e ( ' b u s i n e s s _ i d ' ,   $ b u s i n e s s I d ) - > f i r s t ( ) ) - > v a l u e   ? ?   [ ] ; 
 
 +                 $ s e t t i n g   =   N s t S e t t i n g : : w h e r e ( ' b u s i n e s s _ i d ' ,   $ b u s i n e s s I d ) - > f i r s t ( ) ? - > v a l u e   ? ?   [ ] ; 
 
   
 
                   $ p a y m e n t _ t y p e s   =   $ t h i s - > p r o d u c t U t i l - > p a y m e n t _ t y p e s ( n u l l ,   t r u e ,   $ b u s i n e s s I d ) ; 
 
                   $ p a y m e n t _ l i n e   =   [ ' m e t h o d '   = >   ' c a s h ' ,   ' a m o u n t '   = >   0 ,   ' n o t e '   = >   ' ' ,   ' c a r d _ t r a n s a c t i o n _ n u m b e r '   = >   ' ' ,   ' c a r d _ n u m b e r '   = >   ' ' ,   ' c a r d _ t y p e '   = >   ' ' ,   ' c a r d _ h o l d e r _ n a m e '   = >   ' ' ,   ' c a r d _ m o n t h '   = >   ' ' ,   ' c a r d _ y e a r '   = >   ' ' ,   ' c a r d _ s e c u r i t y '   = >   ' ' ,   ' c h e q u e _ n u m b e r '   = >   ' ' ,   ' b a n k _ a c c o u n t _ n u m b e r '   = >   ' ' ,   ' i s _ r e t u r n '   = >   0 ,   ' t r a n s a c t i o n _ n o '   = >   ' ' ] ; 
 
 @ @   - 4 2 9 , 1 2   + 4 8 5 , 2 2   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                   ' b u s i n e s s _ l o c a t i o n s . i d   A s   f r o m _ l o c a t i o n _ i d ' , 
 
                                   ' b u s i n e s s _ l o c a t i o n s . n a m e   A s   f r o m _ l o c a t i o n _ n a m e ' , 
 
                                   ' n s t _ p r e p a r e _ p r o d u c t s . t r a n s f e r _ q u a n t i t y ' , 
 
 -                                 ' p u r c h a s e _ l i n e s . p u r c h a s e _ p r i c e ' 
 
 +                                 ' p u r c h a s e _ l i n e s . p u r c h a s e _ p r i c e ' , 
 
 +                                 D B : : r a w ( " ( 
 
 +                                         S E L E C T   C O A L E S C E ( S U M ( n p p . t r a n s f e r _ q u a n t i t y ) ,   0 ) 
 
 +                                         F R O M   n s t _ p r e p a r e _ p r o d u c t s   n p p 
 
 +                                         W H E R E   n p p . p r o d u c t _ i d   =   n s t _ p r e p a r e _ p r o d u c t s . p r o d u c t _ i d 
 
 +                                             A N D   n p p . v a r i a t i o n _ i d   =   n s t _ p r e p a r e _ p r o d u c t s . v a r i a t i o n _ i d 
 
 +                                             A N D   n p p . f r o m _ l o c a t i o n _ i d   =   n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d 
 
 +                                             A N D   n p p . s t a t u s   I N   ( ' p r e p a r e ' ,   ' r e c e i v e ' ) 
 
 +                                             A N D   n p p . d e l e t e d _ a t   I S   N U L L 
 
 +                                             A N D   n p p . i d   ! =   n s t _ p r e p a r e _ p r o d u c t s . i d 
 
 +                                 )   a s   c o m m i t t e d _ q t y " ) 
 
                           ) 
 
 -                         - > j o i n ( ' v a r i a t i o n s ' , ' n s t _ p r e p a r e _ p r o d u c t s . v a r i a t i o n _ i d ' , ' = ' , ' v a r i a t i o n s . i d ' ) 
 
 -                         - > j o i n ( ' b u s i n e s s _ l o c a t i o n s ' , ' n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d ' , ' = ' , ' b u s i n e s s _ l o c a t i o n s . i d ' ) 
 
 -                         - > l e f t J o i n ( ' p u r c h a s e _ l i n e s ' , ' n s t _ p r e p a r e _ p r o d u c t s . p u r c h a s e _ l i n e s _ i d ' , ' = ' , ' p u r c h a s e _ l i n e s . i d ' ) 
 
 -                         - > j o i n ( ' p r o d u c t s ' , ' n s t _ p r e p a r e _ p r o d u c t s . p r o d u c t _ i d ' , ' = ' , ' p r o d u c t s . i d ' ) ; 
 
 +                         - > j o i n ( ' v a r i a t i o n s ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . v a r i a t i o n _ i d ' ,   ' = ' ,   ' v a r i a t i o n s . i d ' ) 
 
 +                         - > j o i n ( ' b u s i n e s s _ l o c a t i o n s ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . f r o m _ l o c a t i o n _ i d ' ,   ' = ' ,   ' b u s i n e s s _ l o c a t i o n s . i d ' ) 
 
 +                         - > l e f t J o i n ( ' p u r c h a s e _ l i n e s ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . p u r c h a s e _ l i n e s _ i d ' ,   ' = ' ,   ' p u r c h a s e _ l i n e s . i d ' ) 
 
 +                         - > j o i n ( ' p r o d u c t s ' ,   ' n s t _ p r e p a r e _ p r o d u c t s . p r o d u c t _ i d ' ,   ' = ' ,   ' p r o d u c t s . i d ' ) ; 
 
   
 
                   $ s h i p p i n g _ m e t h o d   =   $ r e q u e s t - > s h i p p i n g _ m e t h o d ; 
 
                   $ s h i p p i n g _ c h a r g e s   =   $ r e q u e s t - > s h i p p i n g _ c h a r g e s ; 
 
 @ @   - 4 4 5 , 2 7   + 5 1 1 , 2 7   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           - > w h e r e ( ' n s t _ p r e p a r e _ p r o d u c t s . b u s i n e s s _ i d ' ,   $ b u s i n e s s I d ) 
 
                           - > s u m ( ' n s t _ p r e p a r e _ p r o d u c t s . t r a n s f e r _ q u a n t i t y ' ) ; 
 
   
 
 -                 i f ( $ t o t a l T r a n s f e r Q u a n t i t y   = =   0 ) { 
 
 +                 i f   ( $ t o t a l T r a n s f e r Q u a n t i t y   = =   0 )   { 
 
                           $ i s D i s a b l e d   =   ' d i s a b l e d ' ; 
 
 -                         $ s h i p p i n g V a l u e P e r U n i t   =   0   ; 
 
 -                 } e l s e i f ( $ s h i p p i n g _ m e t h o d   = =   ' e q u a l _ r a t i o ' ) { 
 
 +                         $ s h i p p i n g V a l u e P e r U n i t   =   0 ; 
 
 +                 }   e l s e i f   ( $ s h i p p i n g _ m e t h o d   = =   ' e q u a l _ r a t i o ' )   { 
 
                           $ i s D i s a b l e d   =   ' d i s a b l e d ' ; 
 
 -                         $ s h i p p i n g V a l u e P e r U n i t   =   $ s h i p p i n g _ c h a r g e s   /   $ t o t a l T r a n s f e r Q u a n t i t y   ; 
 
 -                 } e l s e i f ( $ s h i p p i n g _ m e t h o d   = =   ' a s _ c h a r g e ' ) { 
 
 +                         $ s h i p p i n g V a l u e P e r U n i t   =   $ s h i p p i n g _ c h a r g e s   /   $ t o t a l T r a n s f e r Q u a n t i t y ; 
 
 +                 }   e l s e i f   ( $ s h i p p i n g _ m e t h o d   = =   ' a s _ c h a r g e ' )   { 
 
                           $ i s D i s a b l e d   =   ' d i s a b l e d ' ; 
 
                           $ s h i p p i n g V a l u e P e r U n i t   =   0 ; 
 
 -                 } e l s e i f ( $ s h i p p i n g _ m e t h o d   = =   ' d i f f e r e n t _ r a t i o ' ) { 
 
 +                 }   e l s e i f   ( $ s h i p p i n g _ m e t h o d   = =   ' d i f f e r e n t _ r a t i o ' )   { 
 
                           $ i s D i s a b l e d   =   ' ' ; 
 
                           $ s h i p p i n g V a l u e P e r U n i t   =   0 ; 
 
                   } 
 
   
 
                   r e t u r n   D a t a t a b l e s : : o f ( $ q u e r y ) 
 
                           - > a d d C o l u m n ( ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g ' ,   f u n c t i o n   ( $ r o w )   u s e   ( $ b u s i n e s s I d ,   & $ a v g P u r c h a s e P r i c e )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
                                           r e t u r n   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e   *   $ r o w - > t r a n s f e r _ q u a n t i t y ,   2 ) ; 
 
                                   } 
 
   
 
 -                                 i f ( ! i s s e t ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] ) ) { 
 
 +                                 i f   ( ! i s s e t ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] ) )   { 
 
                                           $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ]   =   [ ] ; 
 
                                   } 
 
   
 
 @ @   - 4 7 5 , 2 7   + 5 4 1 , 2 7   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
   
 
                                   $ l o t N u m b e r s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > g e t L o t D a t a F r o m V a r i a t i o n ( $ r o w - > v a r i a t i o n _ i d ,   $ b u s i n e s s I d ,   $ r o w - > f r o m _ l o c a t i o n _ i d ,   t r u e ) ; 
 
   
 
 -                                 i f ( $ l o t N u m b e r s ) { 
 
 +                                 i f   ( $ l o t N u m b e r s )   { 
 
                                           f o r e a c h   ( $ l o t N u m b e r s   a s   $ l o t N u m b e r )   { 
 
                                                   $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' t o t a l _ p u r c h a s e _ p r i c e ' ]   + =   $ l o t N u m b e r - > p u r c h a s e _ p r i c e   *   $ l o t N u m b e r - > q t y _ a v a i l a b l e ; 
 
                                                   $ c o u n t   + =   $ l o t N u m b e r - > q t y _ a v a i l a b l e ; 
 
                                           } 
 
 -                                         i f ( $ c o u n t ) { 
 
 +                                         i f   ( $ c o u n t )   { 
 
                                                   $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ]   =   r o u n d ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' t o t a l _ p u r c h a s e _ p r i c e ' ]   /   $ c o u n t ,   2 ) ; 
 
                                           } 
 
                                   } 
 
 -                                 r e t u r n   " < s p a n   c l a s s = ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g '   i d = ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g _ { $ r o w - > i d } ' > ( a v g )   " . ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ]   *   $ r o w - > t r a n s f e r _ q u a n t i t y ) . " < / s p a n > " ; 
 
 +                                 r e t u r n   " < s p a n   c l a s s = ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g '   i d = ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g _ { $ r o w - > i d } ' > ( a v g )   "   .   ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ]   *   $ r o w - > t r a n s f e r _ q u a n t i t y )   .   " < / s p a n > " ; 
 
                           } ) 
 
                           - > a d d C o l u m n ( ' s h i p p i n g _ r a t i o ' ,   f u n c t i o n   ( $ r o w )   u s e   ( $ s h i p p i n g V a l u e P e r U n i t ,   $ t o t a l T r a n s f e r Q u a n t i t y ,   $ i s D i s a b l e d ,   & $ a v g P u r c h a s e P r i c e )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 -                                         $ p u r c h a s e P r i c e   =     r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 -                                 } e l s e { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
 +                                         $ p u r c h a s e P r i c e   =   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 +                                 }   e l s e   { 
 
                                           $ p u r c h a s e P r i c e   =   r o u n d ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ] ,   2 ) ; 
 
                                   } 
 
   
 
                                   $ s h i p p i n g R a t i o   =   0 ; 
 
 -                                 i f ( $ s h i p p i n g V a l u e P e r U n i t ) { 
 
 -                                         $ s h i p p i n g R a t i o   =   ( $ r o w - > t r a n s f e r _ q u a n t i t y   /   $ t o t a l T r a n s f e r Q u a n t i t y )   *     1 0 0 ; 
 
 +                                 i f   ( $ s h i p p i n g V a l u e P e r U n i t )   { 
 
 +                                         $ s h i p p i n g R a t i o   =   ( $ r o w - > t r a n s f e r _ q u a n t i t y   /   $ t o t a l T r a n s f e r Q u a n t i t y )   *   1 0 0 ; 
 
                                   } 
 
                                   r e t u r n   " < i n p u t   i d = ' s h i p p i n g _ r a t i o _ { $ r o w - > i d } '   c l a s s = ' f o r m - c o n t r o l   s h i p p i n g - i n p u t s   s h i p p i n g _ r a t i o '   d a t a - i d = ' { $ r o w - > i d } '   d a t a - t r a n s f e r - q u a n t i t y = ' { $ r o w - > t r a n s f e r _ q u a n t i t y } '   d a t a - p u r c h a s e - p r i c e = ' { $ p u r c h a s e P r i c e } '   d a t a - t o t a l - t r a n s f e r - q u a n t i t y = ' { $ t o t a l T r a n s f e r Q u a n t i t y } '   s t y l e = ' w i d t h : 1 0 0 % '   t y p e = ' n u m b e r '   m i n = ' 0 '   v a l u e = ' { $ s h i p p i n g R a t i o } '   { $ i s D i s a b l e d } > " ; 
 
                           } ) 
 
 @ @   - 5 0 3 , 3 2   + 5 6 9 , 3 2   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                                   r e t u r n   " < s p a n   c l a s s = ' s h i p p i n g - i n p u t s   s h i p p i n g _ v a l u e _ p e r _ u n i t '   i d = ' s h i p p i n g _ v a l u e _ p e r _ u n i t _ { $ r o w - > i d } ' >   $ s h i p p i n g V a l u e P e r U n i t   < / s p a n > " ; 
 
                           } ) 
 
                           - > e d i t C o l u m n ( ' p u r c h a s e _ p r i c e ' ,   f u n c t i o n   ( $ r o w )   u s e   ( & $ a v g P u r c h a s e P r i c e )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
                                           r e t u r n   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
                                   } 
 
 -                                 r e t u r n   ' ( a v g )   ' . $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ] ; 
 
 +                                 r e t u r n   ' ( a v g )   '   .   $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ] ; 
 
                           } ) 
 
 -                         - > a d d C o l u m n ( ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ,   f u n c t i o n   ( $ r o w )   u s e (   & $ a v g P u r c h a s e P r i c e ,   $ s h i p p i n g V a l u e P e r U n i t   )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 -                                         $ p u r c h a s e P r i c e   =     r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 -                                 } e l s e { 
 
 +                         - > a d d C o l u m n ( ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ,   f u n c t i o n   ( $ r o w )   u s e   ( & $ a v g P u r c h a s e P r i c e ,   $ s h i p p i n g V a l u e P e r U n i t )   { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
 +                                         $ p u r c h a s e P r i c e   =   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 +                                 }   e l s e   { 
 
                                           $ p u r c h a s e P r i c e   =   r o u n d ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ] ,   2 ) ; 
 
                                   } 
 
   
 
                                   $ u n i t P r i c e A f t e r S h i p p i n g   =   r o u n d ( ( $ p u r c h a s e P r i c e )   +   ( $ s h i p p i n g V a l u e P e r U n i t ) ,   2 ) ; 
 
                                   $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ]   =   $ u n i t P r i c e A f t e r S h i p p i n g ; 
 
 -                                 r e t u r n   " < s p a n   c l a s s = ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g '   i d = ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g _ { $ r o w - > i d } ' >   " .   $ u n i t P r i c e A f t e r S h i p p i n g   . "   < / s p a n > " ; 
 
 +                                 r e t u r n   " < s p a n   c l a s s = ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g '   i d = ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g _ { $ r o w - > i d } ' >   "   .   $ u n i t P r i c e A f t e r S h i p p i n g   .   "   < / s p a n > " ; 
 
                           } ) 
 
                           - > a d d C o l u m n ( ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g ' ,   f u n c t i o n   ( $ r o w )   u s e   ( & $ a v g P u r c h a s e P r i c e ,   $ s h i p p i n g V a l u e P e r U n i t )   { 
 
 -                                 i f ( $ r o w - > p u r c h a s e _ p r i c e ) { 
 
 -                                         $ p u r c h a s e P r i c e   =     r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 -                                 } e l s e { 
 
 +                                 i f   ( $ r o w - > p u r c h a s e _ p r i c e )   { 
 
 +                                         $ p u r c h a s e P r i c e   =   r o u n d ( $ r o w - > p u r c h a s e _ p r i c e ,   2 ) ; 
 
 +                                 }   e l s e   { 
 
                                           $ p u r c h a s e P r i c e   =   r o u n d ( $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' p u r c h a s e _ p r i c e ' ] ,   2 ) ; 
 
                                   } 
 
   
 
                                   $ u n i t P r i c e A f t e r S h i p p i n g   =   r o u n d ( ( $ p u r c h a s e P r i c e   *   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) )   +   ( $ s h i p p i n g V a l u e P e r U n i t   *   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) ) ,   2 ) ; 
 
                                   $ a v g P u r c h a s e P r i c e [ $ r o w - > i d ] [ ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ]   =   $ u n i t P r i c e A f t e r S h i p p i n g ; 
 
 -                                 r e t u r n   " < s p a n   c l a s s = ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g '   i d = ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g _ { $ r o w - > i d } ' >   " .   $ u n i t P r i c e A f t e r S h i p p i n g   . "   < / s p a n > " ; 
 
 +                                 r e t u r n   " < s p a n   c l a s s = ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g '   i d = ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g _ { $ r o w - > i d } ' >   "   .   $ u n i t P r i c e A f t e r S h i p p i n g   .   "   < / s p a n > " ; 
 
                           } ) 
 
                           - > e d i t C o l u m n ( ' p r o d u c t s _ n a m e ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   $ n a m e   =   $ r o w - > p r o d u c t s _ n a m e ; 
 
 @ @   - 5 4 0 , 1 1   + 6 0 6 , 2 5   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           - > e d i t C o l u m n ( ' t r a n s f e r _ q u a n t i t y ' ,   f u n c t i o n   ( $ r o w )   { 
 
                                   r e t u r n   i n t v a l ( $ r o w - > t r a n s f e r _ q u a n t i t y ) ; 
 
                           } ) 
 
 -                         - > r a w C o l u m n s ( [ ' s h i p p i n g _ r a t i o ' ,   ' s h i p p i n g _ v a l u e _ p e r _ u n i t ' ,   ' s h i p p i n g _ v a l u e _ p e r _ u n i t ' ,   ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g ' ,   ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ,   ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g ' ] ) 
 
 +                         - > a d d C o l u m n ( ' c o m m i t t e d _ q t y _ d i s p l a y ' ,   f u n c t i o n   ( $ r o w )   { 
 
 +                                 i f   ( i s s e t ( $ r o w - > c o m m i t t e d _ q t y )   & &   $ r o w - > c o m m i t t e d _ q t y   >   0 )   { 
 
 +                                         r e t u r n   ' < s p a n   c l a s s = " l a b e l   l a b e l - w a r n i n g "   t i t l e = " '   .   _ _ ( ' t p s T r a n s f e r : : l a n g . c o m m i t t e d _ t o _ o t h e r _ t r a n s f e r s ' )   .   ' " > ' 
 
 +                                                 .   _ _ ( ' t p s T r a n s f e r : : l a n g . i n _ t r a n s i t ' )   .   ' :   ' 
 
 +                                                 .   $ r o w - > c o m m i t t e d _ q t y 
 
 +                                                 .   ' < / s p a n > ' ; 
 
 +                                 } 
 
 +                                 r e t u r n   ' ' ; 
 
 +                         } ) 
 
 +                         - > r a w C o l u m n s ( [ ' s h i p p i n g _ r a t i o ' ,   ' s h i p p i n g _ v a l u e _ p e r _ u n i t ' ,   ' s h i p p i n g _ v a l u e _ p e r _ u n i t ' ,   ' t o t a l _ p r i c e _ b e f o r e _ s h i p p i n g ' ,   ' u n i t _ p r i c e _ a f t e r _ s h i p p i n g ' ,   ' t o t a l _ p r i c e _ a f t e r _ s h i p p i n g ' ,   ' c o m m i t t e d _ q t y _ d i s p l a y ' ] ) 
 
                           - > m a k e ( t r u e ) ; 
 
           } 
 
   
 
 -         p u b l i c   f u n c t i o n   s t o r e S h i p p i n g ( R e q u e s t   $ r e q u e s t ) { 
 
 +         p u b l i c   f u n c t i o n   s t o r e S h i p p i n g ( R e q u e s t   $ r e q u e s t ) 
 
 +         { 
 
 +                 i f   ( ! a u t h ( ) - > u s e r ( ) - > c a n ( ' t p s T r a n s f e r . a c c e s s _ p r e p a r e _ s t o c k _ t r a n s f e r ' ) )   { 
 
 +                         a b o r t ( 4 0 3 ,   ' U n a u t h o r i z e d   a c t i o n . ' ) ; 
 
 +                 } 
 
 + 
 
                   $ d a t a   =   [ ] ; 
 
                   p a r s e _ s t r ( $ r e q u e s t - > i n p u t ( ' d a t a ' ) ,   $ d a t a ) ; 
 
                   $ f r o m _ l o c a t i o n _ i d   =   $ r e q u e s t - > i n p u t ( ' f r o m _ l o c a t i o n _ i d ' ) ; 
 
 @ @   - 5 5 4 , 7 9   + 6 3 4 , 9 2   @ @   c l a s s   T p s P r e p a r e S t o c k C o n t r o l l e r   e x t e n d s   C o n t r o l l e r 
 
                           r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' m a i n   i n p u t s   e r r o r   o r   m i s m a t c h ' ] ) ; 
 
                   } 
 
   
 
 -                 D B : : b e g i n T r a n s a c t i o n ( ) ; 
 
 -                 $ b u s i n e s s I d   =   r e q u e s t ( ) - > s e s s i o n ( ) - > g e t ( ' u s e r . b u s i n e s s _ i d ' ) ; 
 
 -                 $ c r e a t e d B y   =   a u t h ( ) - > u s e r ( ) - > i d ; 
 
 - 
 
 -                 $ n s t S h i p p i n g   =   N s t S h i p p i n g : : c r e a t e ( [ 
 
 -                         ' b u s i n e s s _ i d '   = >   $ b u s i n e s s I d , 
 
 -                         ' s h i p p i n g _ d e t a i l s '   = >   $ d a t a [ ' s h i p p i n g _ d e t a i l s ' ] , 
 
 -                         ' s h i p p i n g _ m e t h o d '   = >   $ d a t a [ ' s h i p p i n g _ m e t h o d ' ] , 
 
 -                         ' s h i p p i n g _ c h a r g e s '   = >   $ d a t a [ ' s h i p p i n g _ c h a r g e s ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ k e y _ 1 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 1 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 1 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 1 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ k e y _ 2 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 2 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 2 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 2 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ k e y _ 3 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 3 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 3 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 3 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ k e y _ 4 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 4 ' ] , 
 
 -                         ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 4 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 4 ' ] , 
 
 -                         ' c r e a t e d _ b y '   = >   $ c r e a t e d B y , 
 
 -                 ] ) ; 
 
 -                 $ n s t S h i p p i n g - > r e f _ n u m   =   ' N S T '   .   \ C a r b o n : : n o w ( ) - > y e a r   .   ' - '   .   $ n s t S h i p p i n g - > i d ; 
 
 -                 $ n s t S h i p p i n g - > s a v e ( ) ; 
 
 - 
 
 -                 f o r e a c h ( a r r a y _ c h u n k ( r e q u e s t ( ) - > g e t ( ' t p s S h i p p i n g C a l c u l a t i o n ' ,   n u l l ) ,   5 0 0 ,   t r u e )   a s   $ c h u n k e d D a t a ) { 
 
 -                         f o r e a c h ( $ c h u n k e d D a t a   a s   $ i n d e x   = >   $ d a t a ) { 
 
 -                                 $ u n i t P r i c e A f t e r S h i p p i n g   =   0 ; 
 
 -                                 $ n s t S t o c k   =   N s t P r e p a r e S t o c k : : f i n d O r F a i l ( $ i n d e x ) ; 
 
 -                                 / /   V a l i d a t e   t h e   l o c a t i o n   f r o m   a n d   t o 
 
 -                                 i f ( $ n s t S t o c k - > f r o m _ l o c a t i o n _ i d   ! =   $ f r o m _ l o c a t i o n _ i d   | |   $ n s t S t o c k - > t o _ l o c a t i o n _ i d   ! =   $ t o _ l o c a t i o n _ i d   ) { 
 
 -                                         D B : : r o l l B a c k ( ) ; 
 
 -                                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' T h e   l o c a t i o n   m u s t   b e   s a m e   s e l e c t e d   l o c a t i o n s ' ,   ] ) ; 
 
 -                                 } 
 
 -                                 i f ( $ n s t S t o c k - > p u r c h a s e _ l i n e s _ i d ) { 
 
 -                                         $ p u r c h a s e L i n e   =   P u r c h a s e L i n e : : f i n d O r F a i l ( $ n s t S t o c k - > p u r c h a s e _ l i n e s _ i d ) ; 
 
 - 
 
 -                                         i f ( $ p u r c h a s e L i n e - > q u a n t i t y   <   $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y ) { 
 
 +                 t r y   { 
 
 +                         D B : : b e g i n T r a n s a c t i o n ( ) ; 
 
 +                         $ b u s i n e s s I d   =   r e q u e s t ( ) - > s e s s i o n ( ) - > g e t ( ' u s e r . b u s i n e s s _ i d ' ) ; 
 
 +                         $ c r e a t e d B y   =   a u t h ( ) - > u s e r ( ) - > i d ; 
 
 + 
 
 +                         $ n s t S h i p p i n g   =   N s t S h i p p i n g : : c r e a t e ( [ 
 
 +                                 ' b u s i n e s s _ i d '   = >   $ b u s i n e s s I d , 
 
 +                                 ' s h i p p i n g _ d e t a i l s '   = >   $ d a t a [ ' s h i p p i n g _ d e t a i l s ' ] , 
 
 +                                 ' s h i p p i n g _ m e t h o d '   = >   $ d a t a [ ' s h i p p i n g _ m e t h o d ' ] , 
 
 +                                 ' s h i p p i n g _ c h a r g e s '   = >   $ d a t a [ ' s h i p p i n g _ c h a r g e s ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ k e y _ 1 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 1 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 1 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 1 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ k e y _ 2 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 2 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 2 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 2 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ k e y _ 3 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 3 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 3 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 3 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ k e y _ 4 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ k e y _ 4 ' ] , 
 
 +                                 ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 4 '   = >   $ d a t a [ ' a d d i t i o n a l _ e x p e n s e _ v a l u e _ 4 ' ] , 
 
 +                                 ' c r e a t e d _ b y '   = >   $ c r e a t e d B y , 
 
 +                         ] ) ; 
 
 +                         $ n s t S h i p p i n g - > r e f _ n u m   =   ' N S T '   .   \ C a r b o n : : n o w ( ) - > y e a r   .   ' - '   .   $ n s t S h i p p i n g - > i d ; 
 
 +                         $ n s t S h i p p i n g - > s a v e ( ) ; 
 
 + 
 
 +                         f o r e a c h   ( a r r a y _ c h u n k ( r e q u e s t ( ) - > g e t ( ' t p s S h i p p i n g C a l c u l a t i o n ' ,   n u l l ) ,   5 0 0 ,   t r u e )   a s   $ c h u n k e d D a t a )   { 
 
 +                                 f o r e a c h   ( $ c h u n k e d D a t a   a s   $ i n d e x   = >   $ d a t a )   { 
 
 +                                         $ u n i t P r i c e A f t e r S h i p p i n g   =   0 ; 
 
 +                                         $ n s t S t o c k   =   N s t P r e p a r e S t o c k : : f i n d O r F a i l ( $ i n d e x ) ; 
 
 +                                         / /   V a l i d a t e   t h e   l o c a t i o n   f r o m   a n d   t o 
 
 +                                         i f   ( $ n s t S t o c k - > f r o m _ l o c a t i o n _ i d   ! =   $ f r o m _ l o c a t i o n _ i d   | |   $ n s t S t o c k - > t o _ l o c a t i o n _ i d   ! =   $ t o _ l o c a t i o n _ i d )   { 
 
                                                   D B : : r o l l B a c k ( ) ; 
 
 -                                                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' T r a n s f e r   q u a n t i t y   m u s t   b e   l e s s   t h a n   l o t   q u a n t i t y   ' ,   ] ) ; 
 
 +                                                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' T h e   l o c a t i o n   m u s t   b e   s a m e   s e l e c t e d   l o c a t i o n s ' , ] ) ; 
 
                                           } 
 
 +                                         i f   ( $ n s t S t o c k - > p u r c h a s e _ l i n e s _ i d )   { 
 
 +                                                 $ p u r c h a s e L i n e   =   P u r c h a s e L i n e : : f i n d O r F a i l ( $ n s t S t o c k - > p u r c h a s e _ l i n e s _ i d ) ; 
 
   
 
 -                                         $ u n i t P r i c e A f t e r S h i p p i n g   =   f l o a t v a l ( $ p u r c h a s e L i n e - > p u r c h a s e _ p r i c e )   +   f l o a t v a l ( $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ) ; 
 
 -                                 } e l s e { 
 
 -                                         $ u n i t P r i c e s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > g e t P u r c h a s e P r i c e F r o m V a r i a t i o n B y Q u a n t i t y ( $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y ,   $ n s t S t o c k - > v a r i a t i o n _ i d ,   $ b u s i n e s s I d ,   $ n s t S t o c k - > f r o m _ l o c a t i o n _ i d ) ; 
 
 -                                         
 
 -                                         f o r e a c h   ( $ u n i t P r i c e s   a s   $ u n i t P r i c e ) { 
 
 -                                                 $ u n i t P r i c e A f t e r S h i p p i n g   + =   f l o a t v a l ( $ u n i t P r i c e [ ' p u r c h a s e _ p r i c e ' ] )   *   i n t v a l ( $ u n i t P r i c e [ ' q u a n t i t y ' ] ) ; 
 
 -                                         } 
 
 +                                                 $ a v a i l a b l e _ q t y   =   $ p u r c h a s e L i n e - > q u a n t i t y 
 
 +                                                         -   ( $ p u r c h a s e L i n e - > q u a n t i t y _ s o l d   ? ?   0 ) 
 
 +                                                         -   ( $ p u r c h a s e L i n e - > q u a n t i t y _ a d j u s t e d   ? ?   0 ) 
 
 +                                                         -   ( $ p u r c h a s e L i n e - > q u a n t i t y _ r e t u r n e d   ? ?   0 ) ; 
 
   
 
 -                                         $ u n i t P r i c e A f t e r S h i p p i n g   =   ( $ u n i t P r i c e A f t e r S h i p p i n g   /   i n t v a l ( $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y ) )   +   f l o a t v a l ( $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ) ; 
 
 -                                 } 
 
 +                                                 i f   ( $ a v a i l a b l e _ q t y   <   $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y )   { 
 
 +                                                         D B : : r o l l B a c k ( ) ; 
 
 +                                                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' T r a n s f e r   q u a n t i t y   m u s t   b e   l e s s   t h a n   a v a i l a b l e   l o t   q u a n t i t y   ' , ] ) ; 
 
 +                                                 } 
 
   
 
 -                                 $ n s t S t o c k - > s h i p p i n g _ r a t i o   =   $ d a t a [ ' s h i p p i n g _ r a t i o ' ] ; 
 
 -                                 $ n s t S t o c k - > v a l u e _ p e r _ u n i t   =   $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ; 
 
 -                                 $ n s t S t o c k - > u n i t _ p r i c e _ a f t e r _ s h i p p i n g   =   $ u n i t P r i c e A f t e r S h i p p i n g ; 
 
 -                                 $ n s t S t o c k - > n s t _ s h i p p i n g _ i d   =   $ n s t S h i p p i n g - > i d ; 
 
 -                                 / / C h e c k   i f   t h i s   N S T   r o w   i s   a l r e a d y   h a v e   s h i p p i n g   c a l c u l a t i o n 
 
 -                                 i f ( $ n s t S t o c k - > i s _ s h i p p i n g _ c a l c u l a t e d   = =   1 ) { 
 
 -                                         D B : : r o l l B a c k ( ) ; 
 
 -                                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' p r o d u c t   a l r e a d y   h a v e   s h i p p i n g   c a l c u l a t i o n . ' ] ) ; 
 
 -                                 } 
 
 -                                 $ n s t S t o c k - > i s _ s h i p p i n g _ c a l c u l a t e d   =   t r u e ; 
 
 -                                 $ n s t S t o c k - > s t a t u s   =   ' r e c e i v e ' ; 
 
 -                                 $ n s t S t o c k - > s a v e ( ) ; 
 
 -                                 i f ( ! $ n s t S t o c k ) { 
 
 -                                         D B : : r o l l B a c k ( ) ; 
 
 -                                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' u n e x p e c t e d   e r r o r . ' ] ) ; 
 
 +                                                 $ u n i t P r i c e A f t e r S h i p p i n g   =   f l o a t v a l ( $ p u r c h a s e L i n e - > p u r c h a s e _ p r i c e )   +   f l o a t v a l ( $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ) ; 
 
 +                                         }   e l s e   { 
 
 +                                                 $ u n i t P r i c e s   =   $ t h i s - > t r a n s a c t i o n S e r v i c e - > g e t P u r c h a s e P r i c e F r o m V a r i a t i o n B y Q u a n t i t y ( $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y ,   $ n s t S t o c k - > v a r i a t i o n _ i d ,   $ b u s i n e s s I d ,   $ n s t S t o c k - > f r o m _ l o c a t i o n _ i d ) ; 
 
 + 
 
 +                                                 f o r e a c h   ( $ u n i t P r i c e s   a s   $ u n i t P r i c e )   { 
 
 +                                                         $ u n i t P r i c e A f t e r S h i p p i n g   + =   f l o a t v a l ( $ u n i t P r i c e [ ' p u r c h a s e _ p r i c e ' ] )   *   i n t v a l ( $ u n i t P r i c e [ ' q u a n t i t y ' ] ) ; 
 
 +                                                 } 
 
 + 
 
 +                                                 $ u n i t P r i c e A f t e r S h i p p i n g   =   ( $ u n i t P r i c e A f t e r S h i p p i n g   /   i n t v a l ( $ n s t S t o c k - > t r a n s f e r _ q u a n t i t y ) )   +   f l o a t v a l ( $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ) ; 
 
 +                                         } 
 
 + 
 
 +                                         $ n s t S t o c k - > s h i p p i n g _ r a t i o   =   $ d a t a [ ' s h i p p i n g _ r a t i o ' ] ; 
 
 +                                         $ n s t S t o c k - > v a l u e _ p e r _ u n i t   =   $ d a t a [ ' v a l u e _ p e r _ u n i t ' ] ; 
 
 +                                         $ n s t S t o c k - > u n i t _ p r i c e _ a f t e r _ s h i p p i n g   =   $ u n i t P r i c e A f t e r S h i p p i n g ; 
 
 +                                         $ n s t S t o c k - > n s t _ s h i p p i n g _ i d   =   $ n s t S h i p p i n g - > i d ; 
 
 +                                         / / C h e c k   i f   t h i s   N S T   r o w   i s   a l r e a d y   h a v e   s h i p p i n g   c a l c u l a t i o n 
 
 +                                         i f   ( $ n s t S t o c k - > i s _ s h i p p i n g _ c a l c u l a t e d   = =   1 )   { 
 
 +                                                 D B : : r o l l B a c k ( ) ; 
 
 +                                                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' p r o d u c t   a l r e a d y   h a v e   s h i p p i n g   c a l c u l a t i o n . ' ] ) ; 
 
 +                                         } 
 
 +                                         $ n s t S t o c k - > i s _ s h i p p i n g _ c a l c u l a t e d   =   t r u e ; 
 
 +                                         $ n s t S t o c k - > s t a t u s   =   ' r e c e i v e ' ; 
 
 +                                         $ n s t S t o c k - > s a v e ( ) ; 
 
 +                                         i f   ( ! $ n s t S t o c k )   { 
 
 +                                                 D B : : r o l l B a c k ( ) ; 
 
 +                                                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   ' u n e x p e c t e d   e r r o r . ' ] ) ; 
 
 +                                         } 
 
                                   } 
 
                           } 
 
 +                         D B : : c o m m i t ( ) ; 
 
 +                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ,   ' r e d i r e c t '   = >   " / t p s - p r o d u c t / r e c e i v e - s t o c k " ] ) ; 
 
 + 
 
 +                 }   c a t c h   ( \ E x c e p t i o n   $ e )   { 
 
 +                         D B : : r o l l B a c k ( ) ; 
 
 +                         \ L o g : : e r r o r ( ' T P S   P r e p a r e   S h i p p i n g   f a i l e d :   '   .   $ e - > g e t M e s s a g e ( ) ) ; 
 
 +                         r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' e r r o r ' ,   ' m s g '   = >   _ _ ( ' m e s s a g e s . s o m e t h i n g _ w e n t _ w r o n g ' ) ] ) ; 
 
                   } 
 
 -                 D B : : c o m m i t ( ) ; 
 
 -                 r e t u r n   r e s p o n s e ( ) - > j s o n ( [ ' s t a t u s '   = >   ' s u c c e s s ' ,   ' r e d i r e c t '   = >   " / t p s - p r o d u c t / r e c e i v e - s t o c k " ] ) ; 
 
           } 
 
   
 
 -         p u b l i c   f u n c t i o n   g e t S q l W i t h B i n d i n g s ( $ q u e r y ) { 
 
 +         p u b l i c   f u n c t i o n   g e t S q l W i t h B i n d i n g s ( $ q u e r y ) 
 
 +         { 
 
                   r e t u r n   v s p r i n t f ( s t r _ r e p l a c e ( ' ? ' ,   ' % s ' ,   $ q u e r y - > t o S q l ( ) ) ,   c o l l e c t ( $ q u e r y - > g e t B i n d i n g s ( ) ) - > m a p ( f u n c t i o n   ( $ b i n d i n g )   { 
 
                           r e t u r n   i s _ n u m e r i c ( $ b i n d i n g )   ?   $ b i n d i n g   :   " ' { $ b i n d i n g } ' " ; 
 
                   } ) - > t o A r r a y ( ) ) ; 
 
 