Inheritance: extends Illuminate\Database\Eloquent\Model
Example #1
0
 private function create_payment($order_id)
 {
     $order = Order::find($order_id);
     if ($order) {
         $user = $order->user_id;
         $sum = $order->sum;
         $mrh_login = env('ROBOKASSA_LOGIN');
         $mrh_pass1 = env('ROBOKASSA_PASSWORD');
         $invoice_id = mt_rand();
         $inv_desc = 'Пополнение баланса';
         $crc = md5($mrh_login . ":" . $sum . ":" . $invoice_id . ":" . $mrh_pass1);
         if ($sum != 0) {
             try {
                 DB::beginTransaction();
                 $payment = new Payment();
                 $payment->uid = $invoice_id;
                 $payment->order_id = $order_id;
                 $payment->user_id = $user;
                 $payment->sum = $sum;
                 $payment->description = $inv_desc;
                 $payment->operation = '+';
                 $payment->payment_type = $order->payment_type;
                 $payment->save();
                 DB::commit();
             } catch (\PDOException $e) {
                 print $e->getMessage();
                 DB::connection()->getPdo()->rollBack();
             }
         }
         $redirect_url = "https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin={$mrh_login}&OutSum={$sum}&InvId={$invoice_id}&Desc={$inv_desc}&SignatureValue={$crc}&IsTest=1";
         return $redirect_url;
     }
     return Redirect::to('/')->with('message', 'Ошибка');
 }
Example #2
0
 public function createPayment(Request $request)
 {
     Auth::user();
     $order_id = session('order_id');
     $order = Order::find($order_id);
     if ($order) {
         $user = $order->id;
         $sum = $order->sum;
         $mrh_login = env('ROBOKASSA_LOGIN');
         $mrh_pass1 = env('ROBOKASSA_PASSWORD');
         $invoice_id = mt_rand();
         $inv_desc = 'Пополнение баланса';
         $crc = md5($mrh_login . ":" . $sum . ":" . $invoice_id . ":" . $mrh_pass1);
         if ($sum != 0) {
             try {
                 DB::beginTransaction();
                 $payment = new Payment();
                 $payment->uid = $invoice_id;
                 $payment->user_id = $user;
                 $payment->balance = $sum;
                 $payment->description = $inv_desc;
                 $payment->operation = '+';
                 $payment->save();
                 DB::commit();
             } catch (\PDOException $e) {
                 print $e->getMessage();
                 DB::connection()->getPdo()->rollBack();
             }
         }
         echo 'ok';
         return 1;
         header("Location: https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin={$mrh_login}&OutSum={$sum}&InvId={$invoice_id}&Desc={$inv_desc}&SignatureValue={$crc}");
     }
 }
 public function createPayment(Request $request)
 {
     \Auth::user();
     $user = $request->user()->id;
     $sum = $request->get('OutSum');
     $mrh_login = config('roboconfig.login');
     $mrh_pass1 = config('roboconfig.password1');
     $inv_id = mt_rand();
     $inv_desc = 'Пополнение баланса';
     $crc = md5($mrh_login . ":" . $sum . ":" . $inv_id . ":" . $mrh_pass1);
     if ($sum != 0) {
         try {
             DB::beginTransaction();
             $payment = new Payment();
             $payment->uid = $inv_id;
             $payment->user_id = $user;
             $payment->balance = $sum;
             $payment->description = $inv_desc;
             $payment->operation = '+';
             $payment->save();
             DB::commit();
         } catch (\PDOException $e) {
             print $e->getMessage();
             DB::connection()->getPdo()->rollBack();
         }
     }
     /* return redirect()->action('ZaLaravel\LaravelRobokassa\Controllers\IpnRobokassaController@getResult',
        array('OutSum' => $sum, 'InvId' => $inv_id, 'SignatureValue' => $crc));*/
     header("Location: https://auth.robokassa.ru/Merchant/Index.aspx?MrchLogin={$mrh_login}&OutSum={$sum}&InvId={$inv_id}&Desc={$inv_desc}&SignatureValue={$crc}");
 }
Example #4
0
 /**
  * Validation method
  *
  * @param $type
  *
  * @return array
  * @throws \yii\web\BadRequestHttpException
  */
 public function actionValidate($type)
 {
     $model = new Payment(['scenario' => $type]);
     // throw exception if scenario wrong
     if (!in_array($type, [Payment::SCENARIO_PHONE, Payment::SCENARIO_CARD])) {
         throw new BadRequestHttpException('Wrong type');
     }
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         // validate model
         $errors = ActiveForm::validate($model);
         return ['valid' => empty($errors), 'code' => empty($errors) ? self::CODE_OK : self::CODE_VALIDATION_ERROR, 'description' => $errors];
     }
 }
Example #5
0
 public static function readCallback($payload)
 {
     $crypt = new Encrypter(base64_decode(Config::get('services.etupay.key')), 'AES-256-CBC');
     $payload = json_decode($crypt->decrypt($payload));
     if ($payload && is_numeric($payload->service_data)) {
         $paymentId = $payload->service_data;
         $payment = Payment::findOrFail($paymentId);
         switch ($payload->step) {
             case 'INITIALISED':
                 $payment->state = 'returned';
                 break;
             case 'PAID':
             case 'AUTHORISATION':
                 $payment->state = 'paid';
                 break;
             case 'REFUSED':
             case 'CANCELED':
                 $payment->state = 'refused';
                 break;
             case 'REFUNDED':
                 $payment->state = 'refunded';
                 break;
         }
         $payment->informations = ['transaction_id' => $payload->transaction_id];
         $payment->save();
         if ($payment->newcomer) {
             $payment->newcomer->updateWei();
         } elseif ($payment->student) {
             $payment->student->updateWei();
         }
         return $payment;
     }
     return null;
 }
 public function getResult(Request $request)
 {
     $out_sum = $request->get('OutSum');
     $inv_id = $request->get('InvId');
     $user = Payment::select('user_id')->where('uid', '=', $inv_id)->first();
     $checksum = $request->get('SignatureValue');
     $password2 = config('roboconfig.password2');
     if (strtolower($checksum) == strtolower(md5($out_sum . ":" . $inv_id . ":" . $password2))) {
         if (Payment::where('uid', '=', $inv_id) && Payment::where('balance', '=', $out_sum)) {
             try {
                 DB::beginTransaction();
                 $payment = Payment::where('uid', '=', $inv_id)->first();
                 if ($payment->status == 0) {
                     $payment->status = 1;
                     $payment->update();
                     $addBalanceToUser = User::find($user->user_id);
                     $addBalanceToUser->balance += $out_sum;
                     $addBalanceToUser->update();
                 }
                 DB::commit();
             } catch (\PDOException $e) {
                 \Session::flash('message', "{$e->getMessage}()");
                 DB::connection()->getPdo()->rollBack();
             }
         }
     }
     return redirect()->action('ProfileController@index');
 }
 public function store()
 {
     $data = Input::all();
     $error = false;
     if (isset($data['invoice_id'])) {
         $invoice = Invoice::scope($data['invoice_id'])->with('client')->first();
         if ($invoice) {
             $data['invoice'] = $invoice->public_id;
             $data['client'] = $invoice->client->public_id;
         } else {
             $error = trans('validation.not_in', ['attribute' => 'invoice_id']);
         }
     } else {
         $error = trans('validation.not_in', ['attribute' => 'invoice_id']);
     }
     if (!isset($data['transaction_reference'])) {
         $data['transaction_reference'] = '';
     }
     if (!$error) {
         $payment = $this->paymentRepo->save($data);
         $payment = Payment::scope($payment->public_id)->with('client', 'contact', 'user', 'invoice')->first();
         $payment = Utils::remapPublicIds([$payment]);
     }
     $response = json_encode($error ?: $payment, JSON_PRETTY_PRINT);
     $headers = Utils::getApiHeaders();
     return Response::make($response, 200, $headers);
 }
Example #8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     Payment::truncate();
     Payment::create(array('apartment_id' => '1', 'due_date' => '2016-08-07', 'amount' => '1000', 'fine' => '100'));
     Payment::create(array('apartment_id' => '2', 'due_date' => '2016-08-07', 'amount' => '2000', 'fine' => '200'));
 }
 public function edit($publicId)
 {
     $payment = Payment::scope($publicId)->firstOrFail();
     $payment->payment_date = Utils::fromSqlDate($payment->payment_date);
     $data = array('client' => null, 'invoice' => null, 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false)->with('client', 'invoice_status')->orderBy('invoice_number')->get(), 'payment' => $payment, 'method' => 'PUT', 'url' => 'payments/' . $publicId, 'title' => trans('texts.edit_payment'), 'paymentTypes' => Cache::get('paymentTypes'), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get());
     return View::make('payments.edit', $data);
 }
Example #10
0
 /**
  * Tests the update function in the PaymentController
  * @param  void
  * @return void
  */
 public function testDestroy()
 {
     $this->withoutMiddleware();
     $this->call('POST', '/payment', $this->paymentData);
     $paymentStored = Payment::orderBy('id', 'desc')->first();
     $paymentStored->delete($paymentStored->id);
     $this->assertEquals(Payment::all()->count(), 0);
 }
 protected function getDatatableActions($entityType)
 {
     return [[trans('texts.apply_credit'), function ($model) {
         return URL::to("payments/create/{$model->client_public_id}") . '?paymentTypeId=1';
     }, function ($model) {
         return Payment::canCreate();
     }]];
 }
Example #12
0
 /**
  * @return \Illuminate\Routing\Route|null|string
  */
 public function ingnoreId()
 {
     $id = $this->route('payment');
     $patient_id = $this->input('patient_id');
     $charge_id = $this->input('charge_id');
     $full_amount = $this->input('full_amount');
     return Payment::where(compact('id', 'test_id'))->exists() ? $id : '';
 }
 public function index()
 {
     $payments = Payment::scope()->orderBy('created_at', 'desc')->get();
     $payments = Utils::remapPublicIds($payments->toArray());
     $response = json_encode($payments, JSON_PRETTY_PRINT);
     $headers = Utils::getApiHeaders(count($payments));
     return Response::make($response, 200, $headers);
 }
Example #14
0
 public function show(Request $request)
 {
     $dateFrom = $request->get('dateFrom');
     $dateTo = $request->get('dateTo');
     //$d1 = (new \DateTime($dateFrom))->format('Y-m-d H:i');
     //$payments = Payment::whereBetween('date', [$dateFrom, $dateTo])->whereNull('payment_date')->get();
     $payments = Payment::whereNotNull('payment_date')->with(['user', 'place'])->get();
     return view('director.reportinfo', compact('payments'));
 }
Example #15
0
 public function createPayment(Request $request)
 {
     $user = $request->user()->id;
     $sum = $request->get('OutSum');
     $mrh_login = config('roboconfig.testLogin');
     $mrh_pass1 = config('roboconfig.testPassword1');
     $inv_id = mt_rand();
     $inv_desc = 'Пополнение баланса';
     $crc = md5("{$mrh_login}:{$sum}:{$inv_id}:{$mrh_pass1}");
     if ($sum != 0) {
         $payment = new Payment();
         $payment->uid = $inv_id;
         $payment->user_id = $user;
         $payment->balance = $sum;
         $payment->description = $inv_desc;
         $payment->operation = '+';
         $payment->save();
     }
     return redirect()->action('ZaLaravel\\LaravelRobokassa\\Controllers\\IpnRobokassaController@getResult', array('OutSum' => $sum, 'InvId' => $inv_id));
     // header("Location: http://test.robokassa.ru/Index.aspx?MrchLogin=$mrh_login&OutSum=$sum&InvId=$inv_id&Desc=$inv_desc&SignatureValue=$crc");
 }
 public function save($input, $payment = null)
 {
     $publicId = isset($input['public_id']) ? $input['public_id'] : false;
     if ($payment) {
         // do nothing
     } elseif ($publicId) {
         $payment = Payment::scope($publicId)->firstOrFail();
         if (Utils::isNinjaDev()) {
             \Log::warning('Entity not set in payment repo save');
         }
     } else {
         $payment = Payment::createNew();
     }
     if ($payment->is_deleted) {
         return $payment;
     }
     $paymentTypeId = false;
     if (isset($input['payment_type_id'])) {
         $paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null;
         $payment->payment_type_id = $paymentTypeId;
     }
     if (isset($input['payment_date_sql'])) {
         $payment->payment_date = $input['payment_date_sql'];
     } elseif (isset($input['payment_date'])) {
         $payment->payment_date = Utils::toSqlDate($input['payment_date']);
     } else {
         $payment->payment_date = date('Y-m-d');
     }
     if (isset($input['transaction_reference'])) {
         $payment->transaction_reference = trim($input['transaction_reference']);
     }
     if (!$publicId) {
         $clientId = $input['client_id'];
         $amount = Utils::parseFloat($input['amount']);
         if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
             $credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get();
             $remaining = $amount;
             foreach ($credits as $credit) {
                 $remaining -= $credit->apply($remaining);
                 if (!$remaining) {
                     break;
                 }
             }
         }
         $payment->invoice_id = $input['invoice_id'];
         $payment->client_id = $clientId;
         $payment->amount = $amount;
     }
     $payment->save();
     return $payment;
 }
 public function createPayment(Request $request)
 {
     \Auth::user();
     $user = $request->user()->id;
     $m_shop = '75722594';
     $m_orderid = mt_rand();
     $m_amount = number_format($request->get('OutSum'), 2, '.', '');
     $m_curr = 'RUB';
     $m_desc = base64_encode('Пополнение баланса');
     $m_key = 'halyava';
     $arHash = array($m_shop, $m_orderid, $m_amount, $m_curr, $m_desc, $m_key);
     $sign = strtoupper(hash('sha256', implode(':', $arHash)));
     //dd($sign);
     if ($m_amount != 0) {
         try {
             DB::beginTransaction();
             $payment = new Payment();
             $payment->uid = $m_orderid;
             $payment->user_id = $user;
             $payment->balance = $m_amount;
             $payment->description = base64_decode($m_desc);
             $payment->operation = '+';
             $payment->save();
             DB::commit();
         } catch (\PDOException $e) {
             print $e->getMessage();
             DB::connection()->getPdo()->rollBack();
         }
     }
     /*return redirect()->action('ZaLaravel\LaravelPayeer\Controllers\IpnPayeerController@getResult',
       array('m_shop' => $m_shop,
           'm_amount' => $m_amount,
           'm_orderid' => $m_orderid,
           'm_curr' => $m_curr,
           'm_desc' => $m_desc,
           'm_sign' => $sign));*/
     header("Location:https://payeer.com/merchant/?m_shop={$m_shop}&m_orderid={$m_orderid}&m_amount={$m_amount}&m_curr={$m_curr}&m_desc={$m_desc}&m_sign={$sign}");
 }
Example #18
0
 /**
  * report generation functions DTR
  */
 public function getPaymentsCount()
 {
     $year = date("Y");
     $current_month = (int) date("m");
     $months = [];
     $j = $current_month;
     for ($i = 0; $i < $j; $i++) {
         $month = $current_month;
         $monthly = Payment::find()->where('MONTH(date) =  :month AND YEAR(date) = :year', [':month' => $month, ':year' => $year])->count();
         array_push($months, $monthly);
         $current_month--;
     }
     $before = array_map('intval', array_reverse($months));
     return json_encode($before);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Payment::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'amount' => $this->amount, 'status' => $this->status, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'customer_id', $this->customer_id])->andFilterWhere(['like', 'subcription_id', $this->subcription_id])->andFilterWhere(['like', 'ip_address', $this->ip_address])->andFilterWhere(['>=', 'date', $this->start_date])->andFilterWhere(['<=', 'date', $this->end_date]);
     return $dataProvider;
 }
 /**
  * @SWG\Get(
  *   path="/payments",
  *   tags={"payment"},
  *   summary="List of payments",
  *   @SWG\Response(
  *     response=200,
  *     description="A list with payments",
  *      @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Payment"))
  *   ),
  *   @SWG\Response(
  *     response="default",
  *     description="an ""unexpected"" error"
  *   )
  * )
  */
 public function index()
 {
     $paginator = Payment::scope();
     $payments = Payment::scope()->with('client.contacts', 'invitation', 'user', 'invoice');
     if ($clientPublicId = Input::get('client_id')) {
         $filter = function ($query) use($clientPublicId) {
             $query->where('public_id', '=', $clientPublicId);
         };
         $payments->whereHas('client', $filter);
         $paginator->whereHas('client', $filter);
     }
     $payments = $payments->orderBy('created_at', 'desc')->paginate();
     $paginator = $paginator->paginate();
     $transformer = new PaymentTransformer(Auth::user()->account, Input::get('serializer'));
     $data = $this->createCollection($payments, $transformer, 'payments', $paginator);
     return $this->response($data);
 }
 public function save($input)
 {
     $publicId = isset($input['public_id']) ? $input['public_id'] : false;
     if ($publicId) {
         $payment = Payment::scope($publicId)->firstOrFail();
     } else {
         $payment = Payment::createNew();
     }
     $paymentTypeId = false;
     if (isset($input['payment_type_id'])) {
         $paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null;
         $payment->payment_type_id = $paymentTypeId;
     }
     if (isset($input['payment_date_sql'])) {
         $payment->payment_date = $input['payment_date_sql'];
     } elseif (isset($input['payment_date'])) {
         $payment->payment_date = Utils::toSqlDate($input['payment_date']);
     } else {
         $payment->payment_date = date('Y-m-d');
     }
     if (isset($input['transaction_reference'])) {
         $payment->transaction_reference = trim($input['transaction_reference']);
     }
     if (!$publicId) {
         $clientId = Client::getPrivateId(isset($input['client_id']) ? $input['client_id'] : $input['client']);
         $amount = Utils::parseFloat($input['amount']);
         if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
             $credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get();
             $applied = 0;
             foreach ($credits as $credit) {
                 $applied += $credit->apply($amount);
                 if ($applied >= $amount) {
                     break;
                 }
             }
         }
         $payment->client_id = $clientId;
         $payment->amount = $amount;
         $invoicePublicId = isset($input['invoice_id']) ? $input['invoice_id'] : $input['invoice'];
         $payment->invoice_id = Invoice::getPrivateId($invoicePublicId);
     }
     $payment->save();
     return $payment;
 }
 /**
  * @todo   Refactoring :')
  * @return array|RedirectResponse
  */
 public function update($id)
 {
     $input = Request::only('is_orga', 'allergy', 'phone', 'email', 'gave_parental_authorization', 'birthdate');
     // Convert to timestamp (for Carbon usage).
     $date = new \DateTime($input['birthdate']);
     $input['birthdate'] = $date->getTimestamp();
     $input['gave_parental_authorization'] = $input['gave_parental_authorization'] === null ? false : true;
     $input['is_orga'] = $input['is_orga'] === null ? false : true;
     $registration = WEIRegistration::findOrFail($id);
     $registration->update($input);
     // Payment handling.
     $mean = Request::input('mean_of_payment');
     if ($mean === 'none') {
         $registration->payment_id = null;
     } else {
         $payment = Payment::create(['mean' => $mean, 'bank' => Request::input('payment_bank'), 'emitter' => Request::input('payment_emitter'), 'number' => Request::input('payment_number')]);
         $registration->payment_id = $payment->id;
     }
     // Deposit handling.
     if (empty(Request::input('deposit_bank')) && empty(Request::input('deposit_emitter')) && empty(Request::input('deposit_number'))) {
         $registration->deposit_id = null;
     } else {
         $deposit = Payment::create(['mean' => 'check', 'bank' => Request::input('deposit_bank'), 'emitter' => Request::input('deposit_emitter'), 'number' => Request::input('deposit_number')]);
         $registration->deposit_id = $deposit->id;
     }
     // Everything fullfilled?
     $start = Carbon::parse(Config::get('wei.dates.start'));
     $isUnderage = $registration->birthdate->diffInYears($start) < 18;
     if (empty($registration->phone) || empty($registration->email) || $registration->payment_id === null || $registration->deposit_id === null || $isUnderage && $registration->gave_parental_authorization === false) {
         $registration->complete = false;
     } else {
         $registration->complete = true;
     }
     // Save the registration and tell the user about its status.
     if ($registration->save()) {
         if (!$registration->complete) {
             return $this->success('Inscription ajoutée. Cependant, il <b>MANQUE</b> des pièces.');
         }
         return $this->success('Inscription ajoutée !');
     }
     return $this->error('Impossible de mettre à jour l\'inscription.');
 }
Example #23
0
 public function index(Request $request)
 {
     $data = $request->json()->all('bags');
     $payment = Payment::findOrFail($data['payment_id']);
     $logistics = Logistics::findOrFail($data['logistics_id']);
     $bags = Bag::with('stock.product')->find($data['bags']);
     $order = new Order(array_except($data, 'bags'));
     \DB::transaction(function () use($bags, $logistics, $payment, $order, $data, $request) {
         $order_products = [];
         foreach ($bags as $bag) {
             $order_products[] = $bag->stock->pick($bag->quantity);
             $bag->stock->save();
         }
         $order->user_id = $request->user->id;
         $order->calc($order_products);
         $order->save();
         $order->products()->saveMany($order_products);
         Bag::destroy($data['bags']);
     });
     return response()->created($order);
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|void
  */
 public function getResult(Request $request)
 {
     if ($_SERVER['REMOTE_ADDR'] != '37.59.221.230') {
         return;
     }
     //dd(\Request::all());
     $m_key = 'halyava';
     $m_shop = $request->get('m_shop');
     $m_orderid = $request->get('m_orderid');
     $m_amount = $request->get('m_amount');
     $m_curr = $request->get('m_curr');
     $m_desc = $request->get('m_desc');
     $checksum = $request->get('m_sign');
     $user = Payment::select('user_id')->where('uid', '=', $m_orderid)->first();
     if (isset($_POST['m_operation_id']) && isset($checksum)) {
         $arHash = array($m_shop, $m_orderid, $m_amount, $m_curr, $m_desc, $m_key);
         $sign_hash = strtoupper(hash('sha256', implode(':', $arHash)));
         if ($checksum == $sign_hash && $_POST['m_status'] == 'success') {
             if (Payment::where('uid', '=', $m_orderid) && Payment::where('balance', '=', $m_amount)) {
                 try {
                     DB::beginTransaction();
                     $payment = Payment::where('uid', '=', $m_orderid)->first();
                     if ($payment->status == 0) {
                         $payment->status = 1;
                         $payment->update();
                         $addBalanceToUser = User::find($user->user_id);
                         $addBalanceToUser->balance += $m_amount;
                         $addBalanceToUser->update();
                     }
                     DB::commit();
                 } catch (\PDOException $e) {
                     \Session::flash('message', "{$e->getMessage}()");
                     DB::connection()->getPdo()->rollBack();
                 }
             }
         }
     }
     return redirect()->action('ProfileController@index');
 }
 private function getData($request)
 {
     $account = Auth::user()->account;
     $data = ['account' => $account, 'title' => 'Invoice Ninja v' . NINJA_VERSION . ' - ' . $account->formatDateTime($account->getDateTime()), 'multiUser' => $account->users->count() > 1];
     if ($request->input(ENTITY_CLIENT)) {
         $data['clients'] = Client::scope()->with('user', 'contacts', 'country')->withArchived()->get();
         $data['contacts'] = Contact::scope()->with('user', 'client.contacts')->withTrashed()->get();
         $data['credits'] = Credit::scope()->with('user', 'client.contacts')->get();
     }
     if ($request->input(ENTITY_TASK)) {
         $data['tasks'] = Task::scope()->with('user', 'client.contacts')->withArchived()->get();
     }
     if ($request->input(ENTITY_INVOICE)) {
         $data['invoices'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_quote', '=', false)->where('is_recurring', '=', false)->get();
         $data['quotes'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_quote', '=', true)->where('is_recurring', '=', false)->get();
         $data['recurringInvoices'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status', 'frequency')->withArchived()->where('is_quote', '=', false)->where('is_recurring', '=', true)->get();
     }
     if ($request->input(ENTITY_PAYMENT)) {
         $data['payments'] = Payment::scope()->withArchived()->with('user', 'client.contacts', 'payment_type', 'invoice', 'account_gateway.gateway')->get();
     }
     if ($request->input(ENTITY_VENDOR)) {
         $data['clients'] = Vendor::scope()->with('user', 'vendorcontacts', 'country')->withArchived()->get();
         $data['vendor_contacts'] = VendorContact::scope()->with('user', 'vendor.contacts')->withTrashed()->get();
         /*
         $data['expenses'] = Credit::scope()
             ->with('user', 'client.contacts')
             ->get();
         */
     }
     return $data;
 }
Example #26
0
 public function createPayment($invitation, $ref, $payerId = null)
 {
     $invoice = $invitation->invoice;
     $accountGateway = $invoice->client->account->getGatewayByType(Session::get('payment_type'));
     // sync pro accounts
     if ($invoice->account->account_key == NINJA_ACCOUNT_KEY && $invoice->amount == PRO_PLAN_PRICE) {
         $account = Account::with('users')->find($invoice->client->public_id);
         if ($account->pro_plan_paid && $account->pro_plan_paid != '0000-00-00') {
             $date = DateTime::createFromFormat('Y-m-d', $account->pro_plan_paid);
             $account->pro_plan_paid = $date->modify('+1 year')->format('Y-m-d');
         } else {
             $account->pro_plan_paid = date_create()->format('Y-m-d');
         }
         $account->save();
         $user = $account->users()->first();
         $this->accountRepo->syncAccounts($user->id, $account->pro_plan_paid);
     }
     $payment = Payment::createNew($invitation);
     $payment->invitation_id = $invitation->id;
     $payment->account_gateway_id = $accountGateway->id;
     $payment->invoice_id = $invoice->id;
     $payment->amount = $invoice->getRequestedAmount();
     $payment->client_id = $invoice->client_id;
     $payment->contact_id = $invitation->contact_id;
     $payment->transaction_reference = $ref;
     $payment->payment_date = date_create()->format('Y-m-d');
     if ($payerId) {
         $payment->payer_id = $payerId;
     }
     $payment->save();
     Event::fire(new InvoicePaid($payment));
     return $payment;
 }
 private function export()
 {
     $output = fopen('php://output', 'w') or Utils::fatalError();
     header('Content-Type:application/csv');
     header('Content-Disposition:attachment;filename=export.csv');
     $clients = Client::scope()->get();
     Utils::exportData($output, $clients->toArray());
     $contacts = Contact::scope()->get();
     Utils::exportData($output, $contacts->toArray());
     $invoices = Invoice::scope()->get();
     Utils::exportData($output, $invoices->toArray());
     $invoiceItems = InvoiceItem::scope()->get();
     Utils::exportData($output, $invoiceItems->toArray());
     $payments = Payment::scope()->get();
     Utils::exportData($output, $payments->toArray());
     $credits = Credit::scope()->get();
     Utils::exportData($output, $credits->toArray());
     fclose($output);
     exit;
 }
 /**
  * Display user dashboard
  */
 public function actionDashboard()
 {
     //$model = Yii::$app->user->identity;
     $journals = new ActiveDataProvider(['query' => Journal::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     $events = new ActiveDataProvider(['query' => \app\models\Event::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]);
     $photos = \app\models\Photos::find()->orderBy(['id' => SORT_DESC])->limit(5)->all();
     $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['status' => 0])->orderBy('id')->limit(5), 'pagination' => false]);
     $DataProvider = new ActiveDataProvider(['query' => User::find()->where('level !=0 AND parent_id=0')->orderBy('id')]);
     $RegisteredMembers = count(User::find()->where('level > :level', [':level' => 3])->orWhere('level > :level', [':level' => 2])->orWhere('level > :level', [':level' => 1])->all());
     $famillies = User::find()->where(['level' => '1'])->count();
     $orders = count(\app\models\Payment::find()->all());
     $payments = Payment::getPaymentsCount();
     $months = Payment::getMonths();
     $epercent = Payment::earningPercentage();
     $earning = Payment::getMonthlyEarning();
     $revenue = Payment::totalRevenue();
     $rpercent = payment::revenuePercentage();
     $mearning = Payment::getPaymentsMonth();
     return $this->render('dashboard', ['dataProvider' => $DataProvider, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists, 'RegisteredMembers' => $RegisteredMembers, 'orders' => $orders, 'payments' => $payments, 'months' => $months, 'epercent' => $epercent, 'earning' => $earning, 'revenue' => $revenue, 'rpercent' => $rpercent, 'mearning' => $mearning, 'famillies' => $famillies]);
 }
 public function bulk($ids, $action)
 {
     if (!$ids) {
         return 0;
     }
     $payments = Payment::withTrashed()->scope($ids)->get();
     foreach ($payments as $payment) {
         if ($action == 'restore') {
             $payment->restore();
         } else {
             if ($action == 'delete') {
                 $payment->is_deleted = true;
                 $payment->save();
             }
             $payment->delete();
         }
     }
     return count($payments);
 }
 public function completeOffsitePurchase($input)
 {
     $this->input = $input;
     $ref = array_get($this->input, 'token') ?: $this->invitation->transaction_reference;
     if (method_exists($this->gateway(), 'completePurchase')) {
         $details = $this->paymentDetails();
         $response = $this->gateway()->completePurchase($details)->send();
         $ref = $response->getTransactionReference() ?: $ref;
         if ($response->isCancelled()) {
             return false;
         } elseif (!$response->isSuccessful()) {
             throw new Exception($response->getMessage());
         }
     }
     // check invoice still has balance
     if (!floatval($this->invoice()->balance)) {
         throw new Exception(trans('texts.payment_error_code', ['code' => 'NB']));
     }
     // check this isn't a duplicate transaction reference
     if (Payment::whereAccountId($this->invitation->account_id)->whereTransactionReference($ref)->first()) {
         throw new Exception(trans('texts.payment_error_code', ['code' => 'DT']));
     }
     return $this->createPayment($ref);
 }