<?php

namespace App\Http\Controllers\Backend;

use App\Components\Functions;
use App\Jobs\RemindRating;
use App\Models\Contract;
use App\Models\Hostel;
use App\Models\MoneyInfo;
use App\Models\Notification;
use App\Models\RenterRoom;
use App\Models\Room;
use App\Models\RoomEw;
use App\Models\RoomFee;
use App\Models\TypeSpend;
use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;

class RoomController extends AdminController {
	//
	public function getRoomByAttributeView( Request $request ) {
		return view( 'admin.room.list' );

	}

	public function getRoomView( $id ) {

		$hostel = Hostel::find( $id );

		if ( $hostel ) {


			if ( \request()->ajax() ) {
				return response( [
					'status' => 1,
					'html'   => view( 'admin.room.block_ajax', compact( 'hostel' ) )->render()
				] );
			}

			return view( 'admin.room.blocks', compact( 'hostel' ) );
		}
	}

	public function saveRoomType( Request $request ) {
		$data = $request->all();

		$groups = $data['group-c'];

		foreach ( $groups as $group ) {
			$name  = $group['room_name'];
			$size  = $group['room_size'];
			$price = $group['room_price'];
			if ( isset( $group['features'] ) ) {
				$features = $group['features'];
			} else {
				$features = [];
			}
			$desc      = $group['desc'];
			$imageData = [];
			if ( isset( $group['images'] ) ) {
				$images = $group['images'];


				foreach ( $images as $image ) {
					$imageData[] = Functions::uploadImage( $image );
				}
			}

			\DB::table( 'room_types' )->insert( [
				'name'       => $name,
				'images'     => \GuzzleHttp\json_encode( $imageData ),
				'features'   => json_encode( $features ),
				'size'       => $size,
				'price'      => $price,
				'desc'       => $desc,
				'created_at' => Carbon::now()->toDateTimeString(),
				'updated_at' => Carbon::now()->toDateTimeString(),
				'owner_id'   => auth( 'backend' )->user()->id
			] );
		}

		return redirect()->to( url( 'admin/dashboard/step2' ) );
	}

	public function saveHostelFirstTime( Request $request ) {

		$name          = $request->input( 'name' );
		$type          = $request->input( 'type' );
		$desc          = $request->input( 'desc' );
		$numberFloors  = $request->input( 'number_floors' );
		$electricPrice = $request->input( 'electric_price' );
		$waterPrice    = $request->input( 'water_price' );

		$status        = true;
		$statusConfirm = true;

		$ownerId = null;

		if ( auth( 'backend' )->check() ) {
			$ownerId = auth( 'backend' )->user()->id;
		}

		$hostel = Hostel::create( [
			'name'           => $name,
			'type'           => $type,
			'desc'           => $desc,
			'status'         => $status,
			'status_confirm' => $statusConfirm,
			'number_floors'  => $numberFloors,
			'electric_price' => $electricPrice,
			'water_price'    => $waterPrice,
			'owner_id'       => $ownerId
		] );

		$numberRoomAvailable = 0;
		$numberRoom          = 0;


		for ( $numberFloor = 1; $numberFloor <= $numberFloors; $numberFloor ++ ) {
			$roomNames          = $request->input( 'room-name-' . $numberFloor );
			$roomTypes          = $request->input( 'room-type-' . $numberFloor );
			$roomStatuses       = $request->input( 'room-status-' . $numberFloor );
			$roomSizes          = $request->input( 'room-size-' . $numberFloor );
			$roomPrices         = $request->input( 'room-price-' . $numberFloor );
			$roomStartElectrics = $request->input( 'room-start-electric-' . $numberFloor );
			$roomStartWaters    = $request->input( 'room-start-water-' . $numberFloor );
			$floors             = $request->input( 'room-floors-' . $numberFloor );


			if ( is_array( $roomNames ) && count( $roomNames ) > 0 ) {
				foreach ( $roomNames as $key => $roomName ) {

					$roomType   = isset( $roomTypes[ $key ] ) ? $roomTypes[ $key ] : 0;
					$roomStatus = isset( $roomStatuses[ $key ] ) ? $roomTypes[ $key ] : 0;
					$roomSize   = isset( $roomSizes[ $key ] ) ? $roomTypes[ $key ] : 0;

					$roomStartElectric = isset( $roomStartElectrics[ $key ] ) ? $roomStartElectrics[ $key ] : 0;
					$roomStartWater    = isset( $roomStartWaters[ $key ] ) ? $roomStartWaters[ $key ] : 0;
					$roomPrice         = isset( $roomPrices[ $key ] ) ? $roomPrices[ $key ] : 0;
					$floor             = isset( $floors[ $key ] ) ? $floors[ $key ] : 0;

					$numberRoom ++;

					if ( $roomStatus == Room::AVAILABLE ) {
						$numberRoomAvailable ++;
					}

					Room::create( [
						'floor'          => $floor,
						'name'           => $roomName,
						'status'         => $roomStatus,
						'size'           => $roomSize,
						'hostel_id'      => $hostel->id,
						'start_electric' => $roomStartElectric,
						'start_water'    => $roomStartWater,
						'type'           => $roomType,
						'price'          => $roomPrice,
					] );

				}
			}
		}


		$hostel->number_empty_rooms = $numberRoomAvailable;
		$hostel->number_empty_room  = $numberRoomAvailable;
		$hostel->number_rooms       = $numberRoom;
		$hostel->save();


		auth( 'backend' )->user()->is_owner_first = false;
		auth( 'backend' )->user()->save();

		return redirect()->to( url( 'admin/dashboard' ) );
	}

	public function createHostelForOwner() {

	}

	public function getRoomByAttribute( Request $request ) {
		$rooms = Room::query()
		             ->with( 'hostel' )
		             ->has( 'hostel' )
		             ->when( ! $request->has( 'order' ), function ( $q ) {
			             $q->orderBy( 'id', 'desc' );
		             } )->when( ! empty( $request->input( 'owner_id' ) ), function ( $q ) {
				$q->whereHas( 'hostel', function ( $q ) {
					$q->where( 'owner_id', \request()->input( 'owner_id' ) );
				} );
			} )->when( ! empty( $request->input( 'hostel_id' ) ), function ( $q ) {
				$q->where( 'hostel_id', request()->input( 'hostel_id' ) );
				if ( ! empty( \request()->input( 'is_empty' ) ) ) {
					$q->doesntHave( 'renters' );
				}
			} )->when( ! empty( $request->input( 'status' ) ), function ( $q ) {
				$status = request()->input( 'status' );
				if($status == 'reserved')
				{
					$q->has('reserves', '>', 0);
				} else if ($status == 'empty')
				{
					$q->has('reserves', 0)
						->has('renters', 0);

				} else if ($status == 'soon')
				{
					$q->whereNotNull('date_available');
				} else if ($status == 'stay')
				{
$q->has('renters', '>', 0);
				}
			} );

		if ( auth( 'backend' )->check() ) {
			if ( auth( 'backend' )->user()->type == User::OWNER ) {
				$hostels = Hostel::where( 'owner_id', auth( 'backend' )->user()->id )->pluck( 'id' )->toArray();
				$rooms   = $rooms->whereIn( 'hostel_id', $hostels );
			}
		}

		return Datatables::of( $rooms )
		                 ->filterColumn( 'owner_id', function ( $query, $keyword ) {
			                 $query->whereHas( 'hostel.owner', function ( $q ) use ( $keyword ) {
				                 $q->where( 'name', 'LIKE', '%' . $keyword . '%' );
			                 } );
		                 } )
		                 ->editColumn( 'type', function ( $room ) {
			                 return $room->type_text;
		                 } )->editColumn( 'price', function ( $room ) {
				return number_format( $room->price, 0, '.', '.' );
			} )
		                 ->editColumn( 'deposit', function ( $room ) {
			                 return number_format( $room->deposit, 0, '.', '.' );
		                 } )->editColumn( 'hostel_id', function ( $room ) {
				return optional( $room->hostel )->name;
			} )->editColumn( 'owner_id', function ( $room ) {
				return optional( optional( $room->hostel )->owner )->name_text;
			} )->editColumn( 'status', function ( $room ) {

				$isEmpty = Functions::ifEmptyRoom( $room );
				if ( ! $isEmpty ) {
					$reserves = $room->reserves;
					if ( $reserves->count() > 0 ) {
						return '<label class="label label-warning">Đang cọc</label>';
					}

					return '<label class="label label-success">Đang trống</label>';
				}

				if ( ! empty( $room->date_available ) ) {
					return '<label class="label label-primary">Sắp chuyển đi</label>';
				}

				return '<label class="label label-danger">Đang ở</label>';


			} )->editColumn( 'current_renter', function ( $room ) {
				if ( $room->currentRenter ) {
					return $room->currentRenter->name;
				}

				return 'Chưa có người thuê';
			} )->editColumn( 'debt', function ( $room ) {
				return number_format( $room->debt, 0, '.', '.' );
			} )->addColumn( 'action', function ( $room ) {
				return
					'<a href="' . url( 'admin/room/detail', [ 'id' => $room->id ] ) . '" class="btn btn-outline green" target="_blank">Chi tiết</a>';
			} )->make( true );
	}

	public function create() {
		return view( 'admin.room.create' );
	}

	public function detail( $id ) {
		$room = Room::find( $id );
		if ( $room ) {
			$renters = RenterRoom::where( 'room_id', $id )->latest()->get();
			$fees    = RoomFee::where( 'room_id', $id )->get();

			return view( 'admin.room.detail', compact( 'renters', 'room', 'fees' ) );
		}
	}


	public function store( Request $request ) {
		$data = $request->all();

		if ( $request->file( 'image' ) && $request->file( 'image' )->isValid() ) {
			$data['image'] = $this->saveImage( $request->file( 'image' ) );
		}

		if ( isset( $data['status'] ) && $data['status'] == 'on' ) {
			$data['status'] = true;
		} else {
			$data['status'] = false;
		}

		if ( isset( $data['fee'] ) ) {
			$fees = $data['fee'];
			if ( is_array( $fees ) ) {
				foreach ( $fees as $key => $value ) {

					$item      = RoomFee::find( $key );
					$item->fee = $value;
					$item->save();
				}
			}
		}

		$electricPrice = $request->input( 'electric_price' );
		$waterPrice    = $request->input( 'water_price' );

		if ( ! empty( $data['date_available'] ) ) {
			try {

				$data['date_available'] = Carbon::createFromFormat( 'd/m/Y', $data['date_available'] )->toDateString();

			} catch ( \Exception $ex ) {
				$data['date_available'] = null;
			}
		}


		try {
			\DB::beginTransaction();

			$room = Room::create( $data );

			RoomEw::updateOrCreate( [ 'room_id' => $room->id ],
				[
					'price_electric' => $electricPrice,
					'price_water'    => $waterPrice,
					'room_id'        => $room->id
				] );

			$currentNumberRoom                      = auth( 'backend' )->user()->number_rooms;
			auth( 'backend' )->user()->number_rooms = $currentNumberRoom + 1;
			auth( 'backend' )->user()->save();

			\DB::commit();
		} catch ( \Exception $ex ) {
			\DB::rollBack();
			dd( $ex->getMessage() );

			return redirect()->back()->with( 'error', 'Có lỗi xảy ra vui lòng thử lại sau' );
		}


		return redirect()->back()->with( 'success', 'Tạo thành công' );
	}

	public function getLogRoom( Request $request ) {
		$room_id = $request->input( 'room_id' );
		$logs    = \DB::table( 'room_logs' )->where( 'room_id', $room_id )->orderBy( 'created_at', 'desc' );

		return Datatables::of( $logs )->editColumn( 'created_at', function ( $log ) {
			return Carbon::createFromFormat( 'Y-m-d H:i:s', $log->created_at )->format( 'd/m/Y H:i:s' );
		} )->make( true );
	}

	public function addRenterByOwner( Request $request ) {
		$data = $request->all();

		if ( empty( $data['room_id'] ) ) {
			return response( [
				'status'  => 0,
				'message' => 'Không được bỏ trống phòng',
			] );
		}

		if ( empty( $data['tag'] ) ) {
			$data['tag'] = '#nt';
		}

		$room = Room::find( $data['room_id'] );

		if ( ! $room ) {

			if ( $request->ajax() ) {

				return response( [
					'status'  => 0,
					'message' => 'Phòng không tồn tại',
				] );
			}

			return redirect()->to( \URL::previous() . $data['tag'] )->with( 'error', 'Phòng không tồn tại' );
		}

		$hostelId = $room->hostel->id;

		$hostel = Hostel::find( $hostelId );

		if ( ! $hostel ) {
			if ( $request->ajax() ) {
				return response( [
					'status'  => 0,
					'message' => 'Nhà trọ không tồn tại',
				] );
			}

			return redirect()->to( \URL::previous() . $data['tag'] )->with( 'error', 'Nhà trọ không tồn tại' );
		}

		$check = User::where( 'phone', $data['phone'] )->first();

		if ( ! empty( $data['email'] ) ) {
			$checkEmail = User::where( 'email', $data['email'] )->first();
		}

		$data['type']             = User::RENTER;
		$data['first_add_renter'] = true;

		if ( $request->file( 'image' ) && $request->file( 'image' )->isValid() ) {
			$image         = Functions::uploadImage( $request->file( 'image' ) );
			$data['image'] = $image;
		}

		if ( ! empty( $data['birthday'] ) ) {
			try {
				$birthday = Carbon::createFromFormat( 'd/m/Y', $data['birthday'] )->format( 'd/m/Y' );
			} catch ( \Exception $ex ) {
				$birthday = null;
			}

			$data['birthday'] = $birthday;
		}


		if ( $check ) {

			if ( $check->first_add_renter ) {
				$user = $check;
			} else {

				return response( [
					'status'  => 0,
					'message' => 'SĐT đã tồn tại trên hệ thống. Bạn vui lòng thêm người ở trọ bằng mã'
				] );
			}
		} else if ( ! empty( $checkEmail ) ) {

			if ( $checkEmail->first_add_renter ) {
				$user = $checkEmail;
			} else {
				return response( [
					'status'  => 0,
					'message' => 'Email đã tồn tại trên hệ thống. Bạn vui lòng thêm người ở trọ bằng mã'
				] );
			}
		} else {

			$user = User::create( $data );
		}

		$checkRenter = RenterRoom::where( 'user_id', $user->id )->where( 'room_id', $data['room_id'] )->count();

		if ( $checkRenter == 0 ) {
			RenterRoom::create( [
				'user_id'   => $user->id,
				'room_id'   => $data['room_id'],
				'hostel_id' => $hostelId
			] );
		}

		$room = Room::find( $data['room_id'] );

		if ( $room ) {
			$currentRenter         = Functions::getUserForRoom( $room );
			$room->date_available  = null;
			$room->is_start_remind = false;
			$room->current_renter  = $currentRenter->id;
			$room->save();
		}

		\DB::table( 'room_logs' )->insert( [
			'content'    => 'Thêm người ở trọ ' . $user->name,
			'room_id'    => $data['room_id'],
			'created_at' => Carbon::now()->toDateTimeString(),
			'updated_at' => Carbon::now()->toDateTimeString()
		] );

		$renters = RenterRoom::where( 'room_id', $data['room_id'] )->latest()->get();

		Functions::updateNumberEmptyRoom( $hostel );

		if ( $request->ajax() ) {
			return response( [
				'status'  => 1,
				'message' => 'Thêm người vào phòng trọ thành công',
				'html'    => view( 'admin.room.renters', compact( 'renters' ) )->render()
			] );
		}

		return redirect()->to( \URL::previous() . $data['tag'] )->with( 'success', 'Thêm người vào phòng trọ thành công' );
	}

	public function update( $id, Request $request ) {
		$data = $request->all();

		if ( isset( $data['fee'] ) ) {
			$fees = $data['fee'];
			if ( is_array( $fees ) ) {
				foreach ( $fees as $key => $value ) {

					$item      = RoomFee::find( $key );
					$item->fee = $value;
					$item->save();
				}
			}
		}

		$electricPrice = $request->input( 'electric_price' );
		$waterPrice    = $request->input( 'water_price' );

		if ( ! empty( $data['date_available'] ) ) {
			try {

				$data['date_available'] = Carbon::createFromFormat( 'd/m/Y', $data['date_available'] )->toDateString();

			} catch ( \Exception $ex ) {
				$data['date_available'] = null;
			}
		}

		$room = Room::find( $id );

		if ( $room ) {


			RoomEw::updateOrCreate( [ 'room_id' => $id ],
				[
					'price_electric' => $electricPrice,
					'price_water'    => $waterPrice,
					'room_id'        => $id
				] );

			$room->update( $data );
			$room->save();
		}

		if ( $request->ajax() ) {
			return response( [
				'status'  => 1,
				'message' => 'Thành công'
			] );
		}

		return redirect()->back()->with( 'success', 'Thành công' );
	}

	public function addRenterByCode( Request $request ) {
		$data = $request->all();
		$code = $request->input( 'code' );
		$type = $request->input( 'type' );
		$user = User::where( 'code', $code )->where( 'type', '<>', User::OWNER )->first();
		if ( ! $user ) {
			return response( [
				'status'  => 0,
				'message' => 'Mã code không tồn tại, vui lòng kiểm tra lại'
			] );
		}

		$room   = Room::find( $data['room_id'] );
		$hostel = Hostel::find( $data['hostel_id'] );

		if ( ! $hostel ) {
			return response( [
				'status'  => 0,
				'message' => 'Dữ liệu không hợp lệ',
			] );
		}

		if ( ! $room ) {
			return response( [
				'status'  => 0,
				'message' => 'Dữ liệu không hợp lệ',
			] );
		}

		RenterRoom::where( 'user_id', $user->id )->delete();

		RenterRoom::create( [
			'user_id'   => $user->id,
			'room_id'   => $data['room_id'],
			'hostel_id' => $hostel->id
		] );

		if ( $room ) {
			$currentRenter         = Functions::getUserForRoom( $room );
			$room->current_renter  = $currentRenter->id;
			$room->date_available  = null;
			$room->is_start_remind = false;
			$room->save();
		}

		\DB::table( 'room_logs' )->insert( [
			'content'    => 'Thêm người ở trọ ' . $user->name,
			'room_id'    => $data['room_id'],
			'created_at' => Carbon::now()->toDateTimeString(),
			'updated_at' => Carbon::now()->toDateTimeString()
		] );

		Notification::create( [
			'to_user'   => $user->id,
			'hostel_id' => $hostel->id,
			'room_id'   => $data['room_id'],
			'title'     => 'Thông báo từ itro.vn',
			'user_id'   => auth( 'backend' )->user()->id,
			'content'   => 'Bạn vừa được chủ trọ thêm vào nhà trọ  ' . $hostel->name . ', phòng ' . $room->name . '. Nếu thông tin không đúng, vui lòng liên hệ với chúng tôi để xoá bỏ sự liên kết này',
			'image'     => auth( 'backend' )->user()->image
		] );

		Notification::create( [
			'to_user'   => auth( 'backend' )->user()->id,
			'hostel_id' => $hostel->id,
			'room_id'   => $data['room_id'],
			'title'     => 'Thông báo từ itro.vn',
			'user_id'   => auth( 'backend' )->user()->id,
			'image'     => $user->image,
			'content'   => 'Bạn vừa thêm thành công ' . $user->name . ' vào phòng ' . $room->name . '. Hãy nhờ người trọ đánh giá về nhà trọ của bạn trên itro để tăng độ xếp hạng nhà trọ của bạn'
		] );

		$renters = RenterRoom::where( 'room_id', $data['room_id'] )->latest()->get();

		if ( empty( $type ) ) {
			$hostels = Hostel::where( 'owner_id', auth( 'backend' )->user()->id )->get();
			$rooms   = Room::whereIn( 'hostel_id', $hostels->pluck( 'id' )->toArray() )->pluck( 'id' )->toArray();

			$renters = RenterRoom::whereIn( 'renter_rooms.room_id', $rooms )->orderBy( 'id', 'desc' )->get();
		}

		Functions::updateNumberEmptyRoom( $hostel );

		$remindRating = ( new RemindRating( $user->id, $hostel->id ) )->delay( Carbon::now()->addMonth( 1 ) );

		dispatch( $remindRating );

		return response( [
			'status'  => 1,
			'message' => 'Thêm người vào phòng trọ thành công',
			'html'    => view( 'admin.room.renters', compact( 'renters' ) )->render()
		] );
	}

	public function createFee( Request $request ) {
		$data = $request->all();

		$fee  = $data['fee'];
		$name = $data['name'];

		if ( empty( $name ) ) {
			if ( $request->ajax() ) {
				return response( [
					'status'  => 0,
					'message' => 'Không được bỏ trống tên'
				] );
			}

			return redirect()->back()->with( 'error', 'Không được bỏ trống tên' );
		}

		if ( ! is_numeric( $fee ) ) {
			if ( $request->ajax() ) {
				return response( [
					'status'  => 0,
					'message' => 'Giá trị phải là số'
				] );
			}

			return redirect()->back()->with( 'error', 'Giá trị phải là số' );
		}

		RoomFee::create( $data );

		$fees = RoomFee::where( 'room_id', $data['room_id'] )->get();


		if ( $request->ajax() ) {
			return response( [
				'status'  => 1,
				'message' => 'Tạo thành công',
				'html'    => view( 'admin.room.fees', compact( 'fees' ) )->render()
			] );
		}

		return redirect()->back()->with( 'success', 'Tạo thành công' );

	}

	public function deleteRenter( Request $request ) {
		$renterId = $request->input( 'renter_id' );
		$roomId   = $request->input( 'room_id' );
		$renter   = User::find( $renterId );
		if ( ! $renter ) {
			return response( [
				'status'  => 0,
				'message' => 'Dữ liệu không hợp lệ'
			] );
		}

		$room = Room::find( $roomId );

		if ( ! $room ) {
			return response( [
				'status'  => 0,
				'message' => 'Dữ liệu không hợp lệ'
			] );
		}

		$cntRenterRoom = RenterRoom::where( 'room_id', $roomId )->count();

		if ( $cntRenterRoom > 1 ) {
			RenterRoom::where( 'room_id', $roomId )->where( 'user_id', $renterId )->delete();
		} else {
			$remain = MoneyInfo::where( 'room_id', $roomId )->sum( 'remain' );
			if ( $remain > 0 ) {
				return response( [
					'status'  => 0,
					'message' => 'Người trọ phải thanh toán khoản nợ: ' . number_format( $remain, 0, '.', '.' ) . ' mới có thể xóa khỏi phòng trọ'
				] );
			}
			RenterRoom::where( 'room_id', $roomId )->where( 'user_id', $renterId )->delete();

		}

		Contract::query()->where( 'renter_id', $renterId )
		        ->where( 'room_id', $roomId )
		        ->delete();


		\DB::table( 'room_logs' )->insert( [
			'content'    => 'Xóa người ở trọ ' . $renter->name,
			'room_id'    => $roomId,
			'created_at' => Carbon::now()->toDateTimeString(),
			'updated_at' => Carbon::now()->toDateTimeString()
		] );

		Notification::create( [
			'to_user'   => $renter->id,
			'hostel_id' => $room->hostel->id,
			'room_id'   => $roomId,
			'title'     => 'Thông báo từ itro.vn',
			'user_id'   => auth( 'backend' )->user()->id,
			'content'   => 'Chủ trọ ' . auth( 'backend' )->user()->name . ' đã xóa bạn khỏi phòng ' . $room->name . ' nhà trọ ' . $room->hostel->name
		] );

		if ( $renter->first_add_renter ) {
			$renter->delete();
		}


		return response( [
			'status'  => 1,
			'message' => 'Xóa người ở trọ thành công'
		] );
	}

	public function insertMissingTypeSpend() {
		$users = User::where( 'type', User::OWNER )->get();
		foreach ( $users as $user ) {
			$count = TypeSpend::where( 'owner_id', $user->id )->where( 'is_default', TypeSpend::TIEN_NHA )->count();
			if ( $count == 0 ) {
				TypeSpend::create( [
					'owner_id'   => $user->id,
					'name'       => 'Tiền nhà',
					'is_default' => TypeSpend::TIEN_NHA,
				] );
			}

			$countElectric = TypeSpend::where( 'owner_id', $user->id )->where( 'is_default', TypeSpend::TIEN_DIEN )->count();
			if ( $countElectric == 0 ) {
				TypeSpend::create( [
					'owner_id'   => $user->id,
					'name'       => 'Tiền điện',
					'is_default' => TypeSpend::TIEN_DIEN,
				] );
			}

			$countWater = TypeSpend::where( 'owner_id', $user->id )->where( 'is_default', TypeSpend::TIEN_NUOC )->count();
			if ( $countWater == 0 ) {
				TypeSpend::create( [
					'owner_id'   => $user->id,
					'name'       => 'Tiền nước',
					'is_default' => TypeSpend::TIEN_NUOC,
				] );
			}

			//return re;
		}

	}
}
