Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print( '<br> <b>Calling macro_update_user_liabilities </b> <br>' );
- // purpose of the macro is to update the table CashSILOwnership for the users where status is different than zero
- // for those there has been a change in their ownership of SIL
- // the macro will update the following fields in the table CashSILOwnership:
- // cash_to_be_paid_order_matched, representing the cash to be paid should all the buy orders of a given user be //matched
- // sil_to_be_given_order_matched, representing the SIL to be given away should all the sell orders of a given user //be
- // matched and sil_to_be_obtained_order_matched, representing the SIL to be obtained should all the buy orders of a
- // user be matched
- $cash_sil_Ownerships_obj = null;
- $cash_sil_Ownership_table = CashSILOwnership::where( 'id', '>', 0 );
- $user_ids = [];
- $order_ids = [];
- $original_orders = [];
- $final_records = [];
- $cash_to_be_paid_order_matched_user = 0;
- $sil_to_be_given_order_matched_user = 0;
- $sil_to_be_obtained_order_matched_user = 0;
- if ( $cash_sil_Ownership_table->exists() ) {
- $cash_sil_Ownerships_obj = $cash_sil_Ownership_table->get();
- $list_orders_array = [];
- $list_orders_array_sell = [];
- $list_of_order_table = ListAllOrders::where( 'order_number', '>', 0 );
- $list_of_orders_obj = $list_of_order_table->get();
- foreach ( $cash_sil_Ownerships_obj as $cash_sil_Ownership_obj ) {
- $user_id = $cash_sil_Ownership_obj->user_id;
- $user_ids[] = $user_id;
- }
- foreach ( $user_ids as $user_id ) {
- foreach ( $list_of_orders_obj as $list_of_order_obj ) {
- $user_id_in_list_orders = $list_of_order_obj->user_id;
- $number_sil_user = $list_of_order_obj->desired_sil;
- $buy_sell = $list_of_order_obj->buy_sell;
- $order_number_user = $list_of_order_obj->order_number;
- if ( $user_id_in_list_orders == $user_id ) {
- if ( $buy_sell == 'B' ) {
- $order_ids_buy[] = $order_number_user;
- $list_orders_array[] = [
- 'user_id_in_list_orders' => $list_of_order_obj->user_id,
- 'number_sil_user' => $list_of_order_obj->desired_sil,
- 'buy_sell' => $list_of_order_obj->buy_sell,
- 'order_number_user' => $list_of_order_obj->order_number,
- ];
- //print ( ' am in if buy_sell == B ' );
- // print( "<br> <h3> user_id: " . $user_id . "</h3><br>" );
- // print( "<br> order_number_user: " . $order_number_user . "<br>" );
- // print( "<br> number_sil_user: " . $number_sil_user . "<br>" );
- } elseif ( $buy_sell == 'S' ) {
- $list_orders_array_sell[] = [
- 'user_id_in_list_orders' => $list_of_order_obj->user_id,
- 'number_sil_user' => $list_of_order_obj->desired_sil,
- 'buy_sell' => $list_of_order_obj->buy_sell,
- 'order_number_user' => $list_of_order_obj->order_number,
- ];
- }
- }
- }
- }
- $original_list_of_orders_obj = OrginalListOrders::whereIn( 'order_number',
- $order_ids_buy )->select( [
- 'price',
- 'user_id',
- 'order_number'
- ] )->orderByRaw( 'user_id,order_number desc' )->get();
- foreach ( $original_list_of_orders_obj as $original_list_of_order_obj ) {
- $original_orders[] = [
- 'user_id' => $original_list_of_order_obj->user_id,
- 'price' => $original_list_of_order_obj->price,
- 'order_number' => $original_list_of_order_obj->order_number
- ];
- }
- $arr_rec = [];
- for ( $i = 0; $i < count( $list_orders_array ); $i ++ ) {
- $arr_rec[] = [
- 'user_id_in_list_orders' => $list_orders_array[ $i ]['user_id_in_list_orders'],
- 'number_sil_user' => $list_orders_array[ $i ]['number_sil_user'],
- 'buy_sell' => $list_orders_array[ $i ]['buy_sell'],
- 'order_number_user' => $list_orders_array[ $i ]['order_number_user'],
- 'price' => $original_orders[ $i ]['price'],
- ];
- }
- for ( $i = 0; $i < count( $arr_rec ); $i ++ ) {
- $price_user_original = $original_list_of_orders_obj[ $i ]['price'];
- $number_sil_user = $list_orders_array[ $i ]['number_sil_user'];
- $user_id_in_list_orders = $list_orders_array[ $i ]['user_id_in_list_orders'];
- $order_number_user = $list_orders_array[ $i ]['order_number_user'];
- $buy_sell = $list_orders_array[ $i ]['buy_sell'];
- print( '<br> ORDER MODE = ' . $buy_sell . "<br>" );
- print( "<br> <h3> user_id: " . $user_id_in_list_orders . "</h3><br>" );
- print( "<br> price_user_original in original list of order: " . $price_user_original . "<br>" );
- $cash_to_be_paid_order_matched_user_spcific_trade = $price_user_original * $number_sil_user;
- print( "<br> cash_to_be_paid_order_matched_user_spcific_trade: " . $cash_to_be_paid_order_matched_user_spcific_trade . "<br>" );
- $cash_to_be_paid_order_matched_user = $cash_to_be_paid_order_matched_user + $cash_to_be_paid_order_matched_user_spcific_trade;
- print( "<br> cash_to_be_paid_order_matched_user: " . $cash_to_be_paid_order_matched_user . "<br>" );
- // SIL update
- $sil_to_be_obtained_order_matched_user = $sil_to_be_obtained_order_matched_user + $number_sil_user;
- print( "<br> sil_to_be_obtained_order_matched_user: " . $sil_to_be_obtained_order_matched_user . "<br>" );
- $final_records[] = [
- 'user_id' => $user_id_in_list_orders,
- 'cash_to_be_paid_order_matched' => $cash_to_be_paid_order_matched_user,
- 'sil_to_be_given_order_matched' => $sil_to_be_given_order_matched_user,
- 'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
- ];
- }
- print( "<br> <b>DEALING WITH SELL</b> <br>" );
- for ( $i = 0; $i < count( $list_orders_array_sell ); $i ++ ) {
- $number_sil_user = $list_orders_array_sell[ $i ]['number_sil_user'];
- $user_id_in_list_orders = $list_orders_array_sell[ $i ]['user_id_in_list_orders'];
- $order_number_user = $list_orders_array_sell[ $i ]['order_number_user'];
- $buy_sell = $list_orders_array_sell[ $i ]['buy_sell'];
- print( "<br> <h3> user_id: " . $user_id_in_list_orders . "</h3><br>" );
- print( "<br> order_number_user: " . $order_number_user . "<br>" );
- print( "<br> number_sil_user: " . $number_sil_user . "<br>" );
- $final_records[] = [
- 'user_id' => $user_id_in_list_orders,
- 'cash_to_be_paid_order_matched' => $cash_to_be_paid_order_matched_user,
- 'sil_to_be_given_order_matched' => $sil_to_be_given_order_matched_user,
- 'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
- ];
- $sil_to_be_given_order_matched_user = $sil_to_be_given_order_matched_user + $number_sil_user;
- print( "<br> sil_to_be_given_order_matched_user: " . $sil_to_be_given_order_matched_user . "<br>" );
- }
- foreach ( $user_ids as $user_id ) {
- $cash_sil_Ownership_table = CashSILOwnership::where( 'user_id', $user_id );
- if ( $cash_sil_Ownership_table->exists() ) {
- $cash_sil_Ownership_table->update( [
- 'cash_to_be_paid_order_matched' => $cash_to_be_paid_order_matched_user,
- 'sil_to_be_given_order_matched' => $sil_to_be_given_order_matched_user,
- 'sil_to_be_obtained_order_matched' => $sil_to_be_obtained_order_matched_user,
- ] );
- print( '<br><b>Yaar Printing value after the update for the user = </b> ' . $user_id . "<br>" );
- }
- }
- dd( 'BUS BHAI' );
- $list_of_stop_order_table = StopOrderList::where( 'order_number', '>', 0 );
- foreach ( $cash_sil_Ownerships_obj as $cash_sil_Ownership_obj ) {
- $user_id = $cash_sil_Ownership_obj->user_id;
- print( "<br> user_id : " . $user_id . "<br>" );
- $this->macro_update_user_liabilities_for_specific_user( $user_id, $list_of_order_table->get(),
- $list_of_stop_order_table->get() );
- } // end of for each
- } // end of if ( $cash_sil_Ownership_table->exists()
- } // end of macro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement