Advertisement
Guest User

macro_Inprogress

a guest
Aug 25th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.02 KB | None | 0 0
  1.  
  2.         print( '<br> <b>Calling  macro_update_user_liabilities </b> <br>' );
  3.         // purpose of the macro is to update the table CashSILOwnership for the users where status is different than zero
  4.         // for those there has been a change in their ownership of SIL
  5.         // the macro will update the following fields in the table CashSILOwnership:
  6.         // cash_to_be_paid_order_matched, representing the cash to be paid should all the buy orders of a given user be //matched
  7.         // sil_to_be_given_order_matched, representing the SIL to be given away should all the sell orders of a given user //be
  8.         // matched and sil_to_be_obtained_order_matched, representing the SIL to be obtained should all the buy orders of a
  9.         // user be matched
  10.  
  11.         $cash_sil_Ownerships_obj  = null;
  12.         $cash_sil_Ownership_table = CashSILOwnership::where( 'id', '>', 0 );
  13.         $user_ids                 = [];
  14.         $order_ids                = [];
  15.         $original_orders          = [];
  16.         $final_records            = [];
  17.  
  18.         $cash_to_be_paid_order_matched_user    = 0;
  19.         $sil_to_be_given_order_matched_user    = 0;
  20.         $sil_to_be_obtained_order_matched_user = 0;
  21.  
  22.         if ( $cash_sil_Ownership_table->exists() ) {
  23.             $cash_sil_Ownerships_obj = $cash_sil_Ownership_table->get();
  24.             $list_orders_array       = [];
  25.             $list_orders_array_sell  = [];
  26.  
  27.             $list_of_order_table = ListAllOrders::where( 'order_number', '>', 0 );
  28.             $list_of_orders_obj  = $list_of_order_table->get();
  29.  
  30.             foreach ( $cash_sil_Ownerships_obj as $cash_sil_Ownership_obj ) {
  31.                 $user_id    = $cash_sil_Ownership_obj->user_id;
  32.                 $user_ids[] = $user_id;
  33.             }
  34.  
  35.             foreach ( $user_ids as $user_id ) {
  36.  
  37.                 foreach ( $list_of_orders_obj as $list_of_order_obj ) {
  38.                     $user_id_in_list_orders = $list_of_order_obj->user_id;
  39.                     $number_sil_user        = $list_of_order_obj->desired_sil;
  40.                     $buy_sell               = $list_of_order_obj->buy_sell;
  41.                     $order_number_user      = $list_of_order_obj->order_number;
  42.  
  43.                     if ( $user_id_in_list_orders == $user_id ) {
  44.  
  45.                         if ( $buy_sell == 'B' ) {
  46.                             $order_ids_buy[] = $order_number_user;
  47.  
  48.                             $list_orders_array[] = [
  49.                                 'user_id_in_list_orders' => $list_of_order_obj->user_id,
  50.                                 'number_sil_user'        => $list_of_order_obj->desired_sil,
  51.                                 'buy_sell'               => $list_of_order_obj->buy_sell,
  52.                                 'order_number_user'      => $list_of_order_obj->order_number,
  53.                             ];
  54.                             //print ( ' am in if buy_sell == B ' );
  55. //                          print( "<br> <h3> user_id: " . $user_id . "</h3><br>" );
  56. //                          print( "<br> order_number_user: " . $order_number_user . "<br>" );
  57. //                          print( "<br> number_sil_user: " . $number_sil_user . "<br>" );
  58.                         } elseif ( $buy_sell == 'S' ) {
  59.                             $list_orders_array_sell[] = [
  60.                                 'user_id_in_list_orders' => $list_of_order_obj->user_id,
  61.                                 'number_sil_user'        => $list_of_order_obj->desired_sil,
  62.                                 'buy_sell'               => $list_of_order_obj->buy_sell,
  63.                                 'order_number_user'      => $list_of_order_obj->order_number,
  64.                             ];
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.  
  70.  
  71.             $original_list_of_orders_obj = OrginalListOrders::whereIn( 'order_number',
  72.                 $order_ids_buy )->select( [
  73.                 'price',
  74.                 'user_id',
  75.                 'order_number'
  76.             ] )->orderByRaw( 'user_id,order_number desc' )->get();
  77.  
  78.  
  79.             foreach ( $original_list_of_orders_obj as $original_list_of_order_obj ) {
  80.                 $original_orders[] = [
  81.                     'user_id'      => $original_list_of_order_obj->user_id,
  82.                     'price'        => $original_list_of_order_obj->price,
  83.                     'order_number' => $original_list_of_order_obj->order_number
  84.                 ];
  85.             }
  86.  
  87.             $arr_rec = [];
  88.  
  89.             for ( $i = 0; $i < count( $list_orders_array ); $i ++ ) {
  90.                 $arr_rec[] = [
  91.                     'user_id_in_list_orders' => $list_orders_array[ $i ]['user_id_in_list_orders'],
  92.                     'number_sil_user'        => $list_orders_array[ $i ]['number_sil_user'],
  93.                     'buy_sell'               => $list_orders_array[ $i ]['buy_sell'],
  94.                     'order_number_user'      => $list_orders_array[ $i ]['order_number_user'],
  95.                     'price'                  => $original_orders[ $i ]['price'],
  96.                 ];
  97.             }
  98.  
  99.             for ( $i = 0; $i < count( $arr_rec ); $i ++ ) {
  100.                 $price_user_original    = $original_list_of_orders_obj[ $i ]['price'];
  101.                 $number_sil_user        = $list_orders_array[ $i ]['number_sil_user'];
  102.                 $user_id_in_list_orders = $list_orders_array[ $i ]['user_id_in_list_orders'];
  103.                 $order_number_user      = $list_orders_array[ $i ]['order_number_user'];
  104.                 $buy_sell               = $list_orders_array[ $i ]['buy_sell'];
  105.  
  106.                 print( '<br> ORDER MODE = ' . $buy_sell . "<br>" );
  107.  
  108.                 print( "<br> <h3> user_id: " . $user_id_in_list_orders . "</h3><br>" );
  109.  
  110.                 print( "<br> price_user_original in original list of order: " . $price_user_original . "<br>" );
  111.  
  112.                 $cash_to_be_paid_order_matched_user_spcific_trade = $price_user_original * $number_sil_user;
  113.                 print( "<br> cash_to_be_paid_order_matched_user_spcific_trade: " . $cash_to_be_paid_order_matched_user_spcific_trade . "<br>" );
  114.  
  115.                 $cash_to_be_paid_order_matched_user = $cash_to_be_paid_order_matched_user + $cash_to_be_paid_order_matched_user_spcific_trade;
  116.  
  117.                 print( "<br> cash_to_be_paid_order_matched_user: " . $cash_to_be_paid_order_matched_user . "<br>" );
  118.  
  119.                 // SIL update
  120.                 $sil_to_be_obtained_order_matched_user = $sil_to_be_obtained_order_matched_user + $number_sil_user;
  121.                 print( "<br> sil_to_be_obtained_order_matched_user: " . $sil_to_be_obtained_order_matched_user . "<br>" );
  122.  
  123.                 $final_records[] = [
  124.                     'user_id'                          => $user_id_in_list_orders,
  125.                     'cash_to_be_paid_order_matched'    => $cash_to_be_paid_order_matched_user,
  126.                     'sil_to_be_given_order_matched'    => $sil_to_be_given_order_matched_user,
  127.                     'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
  128.                 ];
  129.  
  130.             }
  131.  
  132.             print( "<br> <b>DEALING WITH SELL</b> <br>" );
  133.  
  134.             for ( $i = 0; $i < count( $list_orders_array_sell ); $i ++ ) {
  135.                 $number_sil_user        = $list_orders_array_sell[ $i ]['number_sil_user'];
  136.                 $user_id_in_list_orders = $list_orders_array_sell[ $i ]['user_id_in_list_orders'];
  137.                 $order_number_user      = $list_orders_array_sell[ $i ]['order_number_user'];
  138.                 $buy_sell               = $list_orders_array_sell[ $i ]['buy_sell'];
  139.  
  140.                 print( "<br> <h3> user_id: " . $user_id_in_list_orders . "</h3><br>" );
  141.                 print( "<br> order_number_user: " . $order_number_user . "<br>" );
  142.                 print( "<br> number_sil_user: " . $number_sil_user . "<br>" );
  143.  
  144.                 $final_records[] = [
  145.                     'user_id'                          => $user_id_in_list_orders,
  146.                     'cash_to_be_paid_order_matched'    => $cash_to_be_paid_order_matched_user,
  147.                     'sil_to_be_given_order_matched'    => $sil_to_be_given_order_matched_user,
  148.                     'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
  149.                 ];
  150.  
  151.                 $sil_to_be_given_order_matched_user = $sil_to_be_given_order_matched_user + $number_sil_user;
  152.                 print( "<br> sil_to_be_given_order_matched_user: " . $sil_to_be_given_order_matched_user . "<br>" );
  153.             }
  154.  
  155.  
  156.             foreach ( $user_ids as $user_id ) {
  157.                 $cash_sil_Ownership_table = CashSILOwnership::where( 'user_id', $user_id );
  158.  
  159.                 if ( $cash_sil_Ownership_table->exists() ) {
  160.                     $cash_sil_Ownership_table->update( [
  161.                         'cash_to_be_paid_order_matched'    => $cash_to_be_paid_order_matched_user,
  162.                         'sil_to_be_given_order_matched'    => $sil_to_be_given_order_matched_user,
  163.                         'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
  164.                     ] );
  165.  
  166.                     print( '<br><b>Yaar Printing value after the update for the user = </b> ' . $user_id . "<br>" );
  167.                 }
  168.             }
  169.             dd( 'BUS BHAI' );
  170.  
  171.             $list_of_stop_order_table = StopOrderList::where( 'order_number', '>', 0 );
  172.  
  173.             foreach ( $cash_sil_Ownerships_obj as $cash_sil_Ownership_obj ) {
  174.                 $user_id = $cash_sil_Ownership_obj->user_id;
  175.                 print( "<br> user_id : " . $user_id . "<br>" );
  176.                 $this->macro_update_user_liabilities_for_specific_user( $user_id, $list_of_order_table->get(),
  177.                     $list_of_stop_order_table->get() );
  178.             } // end of for each
  179.  
  180.         } // end of if ( $cash_sil_Ownership_table->exists()
  181.     } // end of macro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement