public function transform($transaction)
 {
     $return_array = ['id' => $transaction->id, 'type' => "receive", 'money' => $transaction->money, 'status' => transaction_status_raw($transaction->status), 'created_at' => format_time_to_mysql(strtotime($transaction->created_at)), 'type' => transaction_type_raw($transaction->type)];
     if ($transaction->type == 0) {
         if ($transaction->receiver != null) {
             $return_array['receiver'] = $transaction->receiver->name;
         }
         $return_array['note'] = "Người nhận: " . $transaction->receiver->name;
     } else {
         $return_array['note'] = $transaction->note;
     }
     if ($transaction->sender != null) {
         $return_array['sender'] = $transaction->sender->name;
     }
     return $return_array;
 }
 public function get_money(Request $request)
 {
     if ($request->register_id == null || $request->money == null || $request->code == null) {
         return $this->responseBadRequest('Not enough parameters!');
     }
     $register_id = $request->register_id;
     $money = str_replace(array('.', ','), '', $request->money);
     $code = $request->code;
     $register = Register::find($register_id);
     if ($register->status == 1) {
         return $this->responseBadRequest('Học viên này đã đóng tiền rồi');
     }
     $register->money = $money;
     $register->paid_time = format_time_to_mysql(time());
     $register->note = $request->note;
     $register->staff_id = $this->user->id;
     $regis_by_code = Register::where('code', $code)->first();
     if ($regis_by_code != null) {
         return $this->responseBadRequest('code is already existed');
     } else {
         $register->code = $code;
         $register->status = 1;
         $register->save();
         $transaction = new Transaction();
         $transaction->money = $money;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $register->id;
         $transaction->sender_money = $this->user->money;
         $transaction->note = "Học viên " . $register->user->name . " - Lớp " . $register->studyClass->name;
         $transaction->status = 1;
         $transaction->type = 1;
         $transaction->save();
         DB::insert(DB::raw("\n                insert into attendances(`register_id`,`checker_id`,class_lesson_id)\n                (select registers.id,-1,class_lesson.id\n                from class_lesson\n                join registers on registers.class_id = class_lesson.class_id\n                where registers.id = {$register->id}\n                )\n                "));
         $current_money = $this->user->money;
         $this->user->money = $current_money + $money;
         $this->user->save();
         send_mail_confirm_receive_studeny_money($register, ["*****@*****.**", "*****@*****.**"]);
     }
     $return_data = array('data' => ['money' => $register->money, 'code' => $register->code, 'paid_time' => format_date_full_option($register->paid_time)], 'message' => "success");
     return $this->respond($return_data);
 }
Example #3
0
 public function get_money(Request $request)
 {
     $status = 0;
     $register_id = $request->id;
     $money = str_replace(array('.', ','), '', $request->money);
     $code = $request->code;
     $register = Register::find($register_id);
     $register->status = $request->status;
     //        $transaction=Transaction::where()
     $register->money = $money;
     $register->paid_time = format_time_to_mysql(time());
     $register->note = $request->note;
     $register->staff_id = $this->user->id;
     $regis_by_code = Register::where('code', $code)->first();
     if ($regis_by_code != null) {
         $status = 1;
     } else {
         $register->code = $code;
         $register->save();
         $transaction = new Transaction();
         $transaction->money = $money;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $register->id;
         $transaction->sender_money = $this->user->money;
         $transaction->note = "Học viên " . $register->user->name . " - Lớp " . $register->studyClass->name;
         $transaction->status = 1;
         $transaction->type = 1;
         $transaction->save();
         DB::insert(DB::raw("\n                insert into attendances(`register_id`,`checker_id`,class_lesson_id)\n                (select registers.id,-1,class_lesson.id\n                from class_lesson\n                join registers on registers.class_id = class_lesson.class_id\n                where registers.id = {$register->id}\n                )\n                "));
         $current_money = $this->user->money;
         $this->user->money = $current_money + $money;
         $this->user->save();
         send_mail_confirm_receive_studeny_money($register, ["*****@*****.**", "*****@*****.**"]);
     }
     $return_data = array('money' => $register->money, 'code' => $register->code, 'paid_time' => format_date_full_option($register->paid_time), 'status' => $status);
     return json_encode($return_data);
 }