public function save()
 {
     $Transaction = new Transaction($this->data->Transaction);
     $Transaction->save();
     $go = '>auth/Transaction/formObject/' . $Transaction->getId();
     $this->renderPrompt('information', 'OK', $go);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($for = null, $mass_id = null)
 {
     $model = new MassBooking();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MassBooking'])) {
         $tr = Yii::app()->db->beginTransaction();
         $acct = Account::get('Mass Bookings');
         $trans = new Transaction();
         $trans->type = 'credit';
         $trans->account_id = $acct->id;
         $trans->amount = $_POST['amount'];
         $trans->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
         $trans->creator = Yii::app()->user->id;
         $trans->descr = "Mass booking";
         if ($trans->save()) {
             $model->attributes = $_POST['MassBooking'];
             $model->trans_id = $trans->id;
             if ($model->save()) {
                 $trans->saveAttributes(array('descr' => "Mass booking #" . $model->id));
                 $tr->commit();
                 $this->redirect(array('view', 'id' => $model->id));
                 return;
             }
         }
         $tr->rollback();
     }
     $parms = array('model' => $model);
     $parms['mass_dt'] = isset($for) ? $for : '';
     $parms['mass_id'] = isset($mass_id) ? $mass_id : '';
     $this->render('create', $parms);
 }
Exemplo n.º 3
0
 public function actionIndex()
 {
     $user = Yii::app()->user->data();
     if (Yii::app()->user->isGuest) {
         $this->layout = '//layouts/landing';
         $this->render('index');
     } elseif ($user->isActivated()) {
         if ($user->isVerified()) {
             $buyform = new BuyBtcForm();
             // $transactions = Transaction::model ()->findAllByAttributes(array('id_user' => $user->id, 'type' => 1));
             $avail_balance_local = money_format('%.2n', count($user->balance) > 0 ? $user->balance->local : 0);
             $avail_balance_usd = money_format('%.2n', count($user->balance) > 0 ? $user->balance->usd : 0);
             $avail_balance_btc = money_format('%.2n', count($user->balance) > 0 ? $user->balance->btc : 0);
             $request = Yii::app()->request;
             $formData = $request->getPost(get_class($buyform), false);
             if ($formData) {
                 $buyform->amount_btc = $formData['amount_btc'];
                 $buyform->amount_fiat = $formData['amount_fiat'];
                 $buyform->type_trans = $formData['type_trans'];
                 /*if ($buyform->hasErrors ()) {
                 
                 				}
                 				
                 				else{
                 				*/
                 if ($buyform->validate(array(''))) {
                     $tran = new Transaction();
                     $tran->id_user = $user->id;
                     $tran->status = 0;
                     if ($buyform->type_trans == "BUY") {
                         $tran->type = 4;
                         $tran->descr = "You purchased Bitcoins";
                         $tran->currency = "USD";
                         $tran->amount = $buyform->amount_btc;
                     } elseif ($buyform->type_trans == "SELL") {
                         $tran->type = 3;
                         $tran->descr = "You sold Bitcoins";
                         $tran->currency = "BTC";
                         $tran->amount = $buyform->amount_fiat;
                     } else {
                         Yii::app()->user->setFlash('error', Yii::t('translation', 'Error! Unable to create transaction'));
                     }
                     if (!$tran->save()) {
                         Yii::app()->user->setFlash('error', Yii::t('translation', 'Error! Unable to create transaction'));
                     }
                 } else {
                     Yii::app()->user->setFlash('error', Yii::t('translation', 'Error in the fields'));
                 }
             }
             $this->render('index-activated', compact('avail_balance_local', 'user', 'buyform', 'avail_balance_local', 'avail_balance_usd', 'avail_balance_btc'));
         } else {
             $this->render('notverified');
         }
     } else {
         $this->render('index');
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Transaction();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Transaction'])) {
         $model->attributes = $_POST['Transaction'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 5
0
 function edit()
 {
     if ($this->request->is_post()) {
         $transaction = new Transaction($_POST);
         $transaction->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         $this->transaction = new Transaction();
         $this->transaction->find_by_id($_GET['id']);
         $this->transaction->stock = new Stock();
         $this->transaction->stock->find_by_id($this->transaction->isin);
     }
 }
Exemplo n.º 6
0
 public function actionCreate()
 {
     $model = new Transaction();
     if (isset($_POST['Transaction'])) {
         $model->setAttributes($_POST['Transaction']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Transaction();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Transaction'])) {
         $model->attributes = $_POST['Transaction'];
         $model->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
         $model->creator = Yii::app()->user->id;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 8
0
 public function deductAmount($userId, $amount, $type = 9)
 {
     $model = $this->findByAttributes(array('fk_user' => $userId));
     if ($model) {
         if ($model->amount >= $amount) {
             $model->amount = $model->amount - $amount;
             $model->save();
             $transObj = new Transaction();
             $transObj->attributes = array('fk_user' => $userId, 'type' => $type, 'amount' => $amount);
             $transObj->save();
             return true;
         }
     }
     return false;
 }
Exemplo n.º 9
0
 function new_transaction()
 {
     if (!$this->auth->logged_in()) {
         $this->auth->login();
         return;
     }
     $account = new Account();
     $transaction = new Transaction();
     $account->get_by_id($this->input->post('account_id'));
     $transaction->date = $this->input->post('date');
     $transaction->description = $this->input->post('description');
     $transaction->credit = $this->input->post('credit');
     $transaction->debit = $this->input->post('debit');
     $transaction->save($account);
     $this->index();
 }
 public function actionCreate()
 {
     $model = new Transaction();
     if (isset($_POST['Transaction'])) {
         $model->attributes = $_POST['Transaction'];
         $model->account_id = Account::get('Collection')->id;
         $model->type = 'credit';
         Yii::trace("Transaction account id: " . $model->account_id, 'application.controllers.CollectionController');
         $model->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
         $model->creator = Yii::app()->user->id;
         $date = $_POST['date'];
         $model->descr = "Collection for {$date}";
         if ($model->save()) {
             $this->redirect(array('/transaction/view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 11
0
 function checkoutAction($params)
 {
     if ($this->isGuest()) {
         $this->redirect("Site", "login");
     }
     $userId = $this->signedInUser()->id;
     $itemId = $params["itemId"];
     $item = Item::model()->find($itemId);
     $item->quantity--;
     $transaction = new Transaction();
     $transaction->userId = $userId;
     $transaction->itemId = $item->id;
     $transaction->date = date("Y-m-d H:i:s");
     $item->save();
     $transaction->save();
     $this->addFlash("Item bought successfully!");
     return $this->redirect("Site", "index");
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = array('item' => 'required|min:2', 'amount' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         //return to form with erros
         return Redirect::to('transactions/create')->withErrors($validator)->withInput(Input::all());
     } else {
         //save record
         $transaction = new Transaction();
         $transaction->user_id = Auth::user()->id;
         $transaction->amount = Input::get('amount');
         $transaction->item = Input::get('item');
         $transaction->date_purchased = date('Y-m-d H:i:s', strtotime(Input::get('date_purchased')));
         $transaction->save();
         Session::flash('message', $transaction->item . ' added to ' . Auth::user()->firstname);
         return Redirect::to(Request::url());
     }
 }
 /**
  * Creates a new transaction
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "transaction", "action" => "index"));
     }
     $transaction = new Transaction();
     $transaction->id = $this->request->getPost("id");
     $transaction->student_id = $this->request->getPost("student_id");
     $transaction->librarian_id = $this->request->getPost("librarian_id");
     $transaction->book_id = $this->request->getPost("book_id");
     $transaction->action = $this->request->getPost("action");
     $transaction->time = $this->request->getPost("time");
     if (!$transaction->save()) {
         foreach ($transaction->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "transaction", "action" => "new"));
     }
     $this->flash->success("transaction was created successfully");
     return $this->dispatcher->forward(array("controller" => "transaction", "action" => "index"));
 }
Exemplo n.º 14
0
 /**
  * Ajoute une transaction
  * Utilisé uniquement par le code
  *
  * @param $user_id
  * @param $bet_id
  * @param $value
  * @param $type
  * @return bool
  */
 public static function addTransaction($user_id, $bet_id, $value, $type)
 {
     if (in_array($type, array('gain', 'bet')) && Bet::find($bet_id)) {
         $transaction = new Transaction();
         $transaction->user_id = $user_id;
         $transaction->bet_id = $bet_id;
         $transaction->value = $value;
         $transaction->type = $type;
         $transaction->save();
         //On déduit/ajoute les point de la transaction
         $user = User::find($user_id);
         if ($transaction->type == "bet") {
             $user->points -= $transaction->value;
         } else {
             if ($transaction->type == "gain") {
                 $user->points += $transaction->value;
             }
         }
         $user->save();
     }
     return false;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $input['reference_number'] = date('Ymd') . '-' . str_random(5);
     $validation = Validator::make($input, Transaction::$rules);
     if ($validation->passes()) {
         // CREATE NEW TRANSACTION
         $transaction = new Transaction();
         $transaction->reference_number = date('Ymd') . '-' . str_random(5);
         $transaction->property_id = Input::get('property_id');
         $transaction->reservation_id = Input::get('reservation_id');
         $transaction->status = Input::get('status');
         $transaction->amount = Input::get('amount');
         $transaction->firstname = Input::get('firstname');
         $transaction->lastname = Input::get('lastname');
         $transaction->contact_number = Input::get('contact_number');
         $transaction->address = Input::get('address');
         $transaction->email = Input::get('email');
         $transaction->remarks = Input::get('remarks');
         $transaction->save();
         // GENERATE INVOICE
         $html = View::make('admin.transactions.show', compact('transaction'));
         $pdf = storage_path() . '/invoices/' . $transaction->reference_number . '.pdf';
         $dompdf = new DOMPDF();
         $dompdf->load_html($html);
         $dompdf->render();
         $output = $dompdf->output();
         file_put_contents($pdf, $output);
         // EMAIL THE INVOICE
         $data['transaction'] = $transaction;
         Mail::send('mails.default', $data, function ($message) use($transaction, $pdf) {
             $message->to($transaction->email)->subject("Your Invoice");
             $message->attach($pdf);
         });
         return Redirect::route('admin.transactions.index')->with('success', 'An invoice has been sent to the client.');
     }
     return Redirect::route('admin.transactions.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }
Exemplo n.º 16
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aClocking !== null) {
             if ($this->aClocking->isModified() || $this->aClocking->isNew()) {
                 $affectedRows += $this->aClocking->save($con);
             }
             $this->setClocking($this->aClocking);
         }
         if ($this->aTransaction !== null) {
             if ($this->aTransaction->isModified() || $this->aTransaction->isNew()) {
                 $affectedRows += $this->aTransaction->save($con);
             }
             $this->setTransaction($this->aTransaction);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 17
0
 /**
  * Creates a new transaction.
  *
  * @param array $transactionData An associative array with the properties
  *     "UserId", "Start", "End" and "Comment".
  * @param array $bookingData An array of booking data. Existing bookings are
  *     specified by ID, new bookings must be specified as objects:
  *     <code>{ "BookingTypeId": ..., "Label": ..., "Value": ... }</code>
  * @param array $clockingIds Optional. An array of clocking IDs to assign
  *     to the new transaction. Default is NULL.
  * @throws Exception
  * @return bool
  */
 public function do_create(array $transactionData = null, array $bookingData = null, array $clockingIds = null)
 {
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $user = $this->requireUser();
         if (!$user->isAdmin()) {
             throw new Exception('Non-administrative user "' . $user->getFQN($con) . '" cannot create transactions.');
         }
         $account = $user->getAccount($con);
         if ($account === null) {
             throw new Exception('Could not determine the account the authenticated user "' . $user->getName() . '" #' . $user->getId() . ' belongs to.');
         }
         if (empty($bookingData)) {
             throw new Exception('Transaction must contain at least one booking.');
         }
         $transaction = new Transaction();
         $transaction->fromArray(array_intersect_key($transactionData, array('UserId' => true, 'Start' => true, 'End' => true, 'Comment' => true)));
         $employeeId = $transaction->getUserId();
         $employee = $this->findUserById($employeeId, $con);
         if ($employee === null) {
             throw new Exception('Employee with ID ' . $employeeId . ' could not be found.');
         }
         // Separate new and existing bookings (the latter are specified by ID)
         $bookingIds = array();
         foreach ($bookingData as $bookingIndex => $bookingItem) {
             if (!is_array($bookingItem)) {
                 $bookingIds[$bookingItem] = $bookingItem;
                 unset($bookingData[$bookingIndex]);
             }
         }
         $bookingTypeIds = BookingTypeQuery::create()->findByAccountId($account->getId(), $con)->getArrayCopy('Id');
         $newBookings = array_values($this->createBookings($bookingData, $bookingTypeIds, $con));
         // Load existing bookings and check for missing records
         $bookingsById = BookingQuery::create()->joinBookingType()->add(BookingTypePeer::ACCOUNT_ID, $user->getAccountId())->findPks($bookingIds)->getArrayCopy('Id');
         $missingBookingIds = array_diff_key($bookingIds, $bookingsById);
         if (count($missingBookingIds) > 0) {
             throw new Exception('Could not find bookings with the following IDs: ' . implode(', ', array_keys($missingBookingIds)));
         }
         if (empty($clockingIds)) {
             $clockings = array();
         } else {
             $clockings = ClockingQuery::create()->filterByUserRelatedByUserId($employee)->addAscendingOrderByColumn(ClockingPeer::START)->addAscendingOrderByColumn(ClockingPeer::END)->addAscendingOrderByColumn(ClockingPeer::ID)->findPks($clockingIds, $con);
             $clockingsById = $clockings->getArrayCopy('Id');
             $missingClockingIds = array_diff_key(array_fill_keys($clockingIds, true), $clockingsById);
             if (count($missingClockingIds) > 0) {
                 throw new Exception('Could not find clockings of user "' . $employee->getName() . '" #' . $employeeId . ' with the following IDs: ' . implode(', ', array_keys($missingClockingIds)));
             }
         }
         $start = isset($transactionData['Start']) ? $transactionData['Start'] : null;
         if ((string) $start === '') {
             throw new Exception('Start date must be specified for transaction.');
         }
         $end = isset($transactionData['End']) ? $transactionData['End'] : null;
         if ((string) $end === '') {
             throw new Exception('End date must be specified for transaction.');
         }
         $transaction->save($con);
         // Link bookings to transaction
         foreach (array_merge(array_values($bookingsById), $newBookings) as $booking) {
             $booking->setTransaction($transaction)->save($con);
         }
         // Link clockings
         $this->linkTransactionClockings($transaction, $clockings, $con);
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return true;
 }
Exemplo n.º 18
0
                // Get just accepted items
                if ($clothes[$j]->accepted == true) {
                    $clothes[$j]->actualAmount = $clothes[$j]->actualAmount + 1;
                    $clothes[$j]->saveClothData();
                }
            }
            break;
        case "Waiting for customer":
            //$transaction->PaymentDate = date("Y-m-d H:i:s");
            break;
        case "Return":
            $transaction->PaymentDate = date("Y-m-d H:i:s");
            break;
        case "Donate":
            $transaction->PaymentDate = date("Y-m-d H:i:s");
            break;
        case "Payment":
            $transaction->PaymentDate = date("Y-m-d H:i:s");
            break;
        case "Finished":
            $transaction->FinishedDate = date("Y-m-d H:i:s");
            break;
    }
    // Store to DB
    $transaction->save();
    // Send email
    post_request("http://" . $_SERVER['HTTP_HOST'] . "/sendStatusMail.php", array("id" => $id));
    echo "successfully stored {$id} with new status {$statusName}";
} else {
    echo "error no POST data";
}
 public function reserve_post($id)
 {
     $property = Property::find($id);
     $admin_email = User::find(1)->email;
     $developer_email = $property->developer->email;
     if (is_null($property)) {
         return App::abort(404);
     }
     $validator = Validator::make(Input::all(), Reservation::$rules);
     if ($validator->passes()) {
         // REMOVE PROPERTY FROM THE LIST BECAUSE ITS ALREADY BEEN RESERVED
         $property->status = 0;
         $property->save();
         // EMAIL DEVELOPER
         $reservation = new Reservation();
         $reservation->property_id = $id;
         $reservation->firstname = Input::get('firstname');
         $reservation->lastname = Input::get('lastname');
         $reservation->phone = Input::get('phone');
         $reservation->mobile = Input::get('mobile');
         $reservation->home_address = Input::get('home_address');
         $reservation->work_address = Input::get('work_address');
         $reservation->work = Input::get('work');
         $reservation->company = Input::get('company');
         $reservation->tin_number = Input::get('tin_number');
         $reservation->terms = Input::get('terms');
         $reservation->email = Input::get('email');
         $reservation->unit_type = Input::get('unit_type');
         $reservation->save();
         // CREATE NEW TRANSACTION
         $transaction = new Transaction();
         $transaction->reference_number = date('Ymd') . '-' . str_random(5);
         $transaction->property_id = $id;
         $transaction->reservation_id = $reservation->id;
         $transaction->status = 'Pending';
         $transaction->amount = $property->reservation_fee;
         $transaction->firstname = $reservation->firstname;
         $transaction->lastname = $reservation->lastname;
         $transaction->contact_number = $reservation->mobile;
         $transaction->address = $reservation->home_address;
         $transaction->email = $reservation->email;
         $transaction->remarks = "Reservation Fee";
         $transaction->save();
         // GENERATE INVOICE
         $html = View::make('admin.transactions.show', compact('transaction'));
         $pdf = storage_path() . '/invoices/' . $transaction->reference_number . '.pdf';
         $dompdf = new DOMPDF();
         $dompdf->load_html($html);
         $dompdf->render();
         $output = $dompdf->output();
         file_put_contents($pdf, $output);
         // EMAIL THE INVOICE
         $data['transaction'] = $transaction;
         Mail::send('mails.default', $data, function ($message) use($transaction, $pdf) {
             $message->to($transaction->email)->subject("Your Invoice");
             $message->attach($pdf);
         });
         // EMAIL DEVELOPER AND ADMINISTRATOR
         $data['property'] = $property;
         $data['firstname'] = Input::get('firstname');
         $data['lastname'] = Input::get('lastname');
         $data['phone'] = Input::get('phone');
         $data['mobile'] = Input::get('mobile');
         $data['tin_number'] = Input::get('tin_number');
         $data['home_address'] = Input::get('home_address');
         $data['work_address'] = Input::get('work_address');
         $data['work'] = Input::get('work');
         $data['company'] = Input::get('company');
         $data['terms'] = Input::get('terms');
         $data['email'] = Input::get('email');
         $data['unit_type'] = Input::get('unit_type');
         Mail::send('mails.reservation', $data, function ($message) use($admin_email, $developer_email) {
             $message->to($admin_email, 'Live and Love')->subject('Property Reservation');
             if ($developer_email) {
                 $message->to($developer_email, 'Live and Love')->subject('Property Reservation');
             }
         });
         return Redirect::to('properties/reserve/' . $id)->with('success', 'Email has been sent to administrator. Well send you an invoice for billing the reservation fee.');
     } else {
         return Redirect::to('properties/reserve/' . $id)->withErrors($validator)->withInput();
     }
 }
Exemplo n.º 20
0
 public function addAchat(Transaction $transaction)
 {
     $transaction->setNoteDeFrais($this);
     $transaction->save();
     $this->getTransaction()->montant += $transaction->getMontant();
 }
Exemplo n.º 21
0
switch ($filtered['support-type']) {
	case 5:
		$paymentAmount = 5.00;
		break;
	case 1:
	default:
		$paymentAmount = 1.00;
}

// Generate Transaction stuff
$txn                   = new Transaction();

if ($filteredG['token'] and $filteredG['PayerID'] and !$filtered['paypal-verify-txn']) {
	$txn->getByToken($filteredG['token']);
	$txn->payerId = $filteredG['PayerID'];
	$txn->save();
	$t->ppVerify = $txn;
	$for = new User();
	$t->forName = '';
	if ($txn->id) {
		$for->get($txn->forId);
		$t->forName = $for->getNameLink();
	}
}
else if ($filtered['token'] and $filtered['paypal-verify-txn']) {
	$txn->getByToken($filtered['token']);
	$pp = new Paypal();
	if ($pp->step4($txn)) {
		// good, can update the user.
		$u = new User();
		$u->get($txn->forId);
Exemplo n.º 22
0
 public function doOldImport()
 {
     DB::delete('DELETE FROM `cache`');
     // delete old data:
     foreach (Auth::user()->accounts()->get() as $acc) {
         $acc->delete();
     }
     foreach (Auth::user()->budgets()->get() as $b) {
         $b->delete();
     }
     foreach (Auth::user()->categories()->get() as $b) {
         $b->delete();
     }
     foreach (Auth::user()->beneficiaries()->get() as $b) {
         $b->delete();
     }
     foreach (Icon::get() as $icon) {
         $icon->delete();
     }
     $data = file_get_contents('http://commondatastorage.googleapis.com/nder/import.json');
     $json = json_decode($data);
     $map = array();
     $map['accounts'] = array();
     $map['icons'] = array();
     // all accounts:
     foreach ($json->accounts as $account) {
         $newAccount = new Account();
         $newAccount->name = Crypt::encrypt($account->name);
         $newAccount->balance = floatval($account->balance);
         $newAccount->fireflyuser_id = Auth::user()->id;
         $newAccount->date = $account->date;
         $newAccount->save();
         $map['accounts'][$account->id] = $newAccount->id;
     }
     // all icons:
     foreach ($json->icons as $icon) {
         $newIcon = new Icon();
         $newIcon->file = $icon->file;
         $newIcon->save();
         $map['icons'][intval($icon->id)] = $newIcon->id;
     }
     // all beneficiaries:
     foreach ($json->beneficiaries as $ben) {
         $nb = new Beneficiary();
         $nb->fireflyuser_id = Auth::user()->id;
         $nb->name = Crypt::encrypt($ben->name);
         $nb->save();
         $map['beneficiaries'][$ben->id] = $nb->id;
     }
     // all budgets
     foreach ($json->budgets as $bd) {
         $nbg = new Budget();
         $nbg->fireflyuser_id = Auth::user()->id;
         $nbg->name = Crypt::encrypt($bd->name);
         $nbg->date = $bd->date;
         $nbg->amount = floatval($bd->amount);
         $nbg->save();
         $map['budgets'][$bd->id] = $nbg->id;
     }
     // all categories:
     foreach ($json->categories as $c) {
         $nc = new Category();
         $nc->fireflyuser_id = Auth::user()->id;
         $nc->icon_id = intval($map['icons'][intval($c->icon_id)]);
         $nc->name = Crypt::encrypt($c->name);
         $nc->showtrend = intval($c->showtrend);
         $nc->save();
         $map['categories'][$c->id] = $nc->id;
     }
     foreach ($json->targets as $t) {
         $nt = new Target();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_id = $map['accounts'][$t->account_id];
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->duedate = $t->duedate;
         $nt->startdate = $t->startdate;
         $nt->save();
         $map['targets'][$t->id] = $nt->id;
     }
     foreach ($json->transactions as $t) {
         $nt = new Transaction();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_id = $map['accounts'][$t->account_id];
         $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]);
         $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id];
         $nt->beneficiary_id = is_null($t->beneficiary_id) ? NULL : $map['beneficiaries'][$t->beneficiary_id];
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->date = $t->date;
         $nt->onetime = intval($t->onetime);
         $nt->save();
         $map['transactions'][$t->id] = $nt->id;
     }
     foreach ($json->transfers as $t) {
         $nt = new Transfer();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_from = $map['accounts'][$t->account_from];
         $nt->account_to = $map['accounts'][$t->account_to];
         $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id];
         $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]);
         $nt->target_id = is_null($t->target_id) ? NULL : intval($map['targets'][$t->target_id]);
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->date = $t->date;
         $nt->save();
         $map['targets'][$t->id] = $nt->id;
     }
     //
     //var_dump($data);
     // create everything from this file.
     // we map the old id's to the new one to save problems.
     return 'Old data successfully imported.';
 }
Exemplo n.º 23
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $parameters = $request->getParameter($form->getName());
     $form->bind($parameters, $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $this->getContext()->getConfiguration()->loadHelpers('Number');
         // On crée la transaction correspondante
         $transaction = new Transaction();
         $transaction->asso_id = $parameters['asso_id'];
         $transaction->compte_id = $parameters['compte_id'];
         $transaction->libelle = 'Remboursement ' . $parameters['nom'];
         $transaction->commentaire = "Remboursement des achats suivants :\n";
         // Voir ci-dessous
         $transaction->montant = 0;
         // On fera le total plus tard !
         $transaction->date_transaction = date('Y-m-d');
         $transaction->moyen_id = $parameters['moyen_id'];
         $transaction->moyen_commentaire = $parameters['moyen_commentaire'];
         $transaction->save();
         $form->setValue('transaction_id', $transaction->getPrimaryKey());
         $note_de_frais = $form->save();
         foreach ($parameters['transactions'] as $transaction_id) {
             $transaction2 = $note_de_frais->addAchatFromId($transaction_id);
             $transaction->commentaire .= $this->format_transaction($transaction2) . "\n";
         }
         $transaction->save();
         $this->redirect('ndf', $note_de_frais->getAsso());
     }
 }
Exemplo n.º 24
0
 public function newTransaction()
 {
     $transaction = new Transaction();
     $transaction->amount = floatval(Input::get('amount'));
     $transaction->fireflyuser_id = Auth::user()->id;
     $transaction->date = Input::get('date');
     $transaction->onetime = Input::get('onetime') == 'on' ? 1 : 0;
     $transaction->description = Input::get('description');
     if (Input::get('type') == 'min') {
         $transaction->amount = $transaction->amount * -1;
     }
     if (!is_null(Input::get('account'))) {
         $account = Auth::user()->accounts()->find(Input::get('account'));
         if (!is_null($account)) {
             $transaction->account_id = $account->id;
         }
     }
     // budget
     if (intval(Input::get('budget')) > 0) {
         $budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
         if (!is_null($budget)) {
             $transaction->budget_id = $budget->id;
         }
     }
     // category
     if (strlen(Input::get('category')) != 0) {
         $categories = Auth::user()->categories()->get();
         //->where('name','=',Input::get('category'))->first();
         $category = null;
         foreach ($categories as $cat) {
             if (Crypt::decrypt($cat->name) == Input::get('category')) {
                 $category = $cat;
                 break;
             }
         }
         unset($cat, $categories);
         if (is_null($category)) {
             $category = new Category();
             $category->fireflyuser_id = Auth::user()->id;
             $category->name = Input::get('category');
             $category->showtrend = 0;
             $category->icon_id = Icon::first()->id;
             // FIXME moet niet hardcoded
             $validator = Validator::make($category->toArray(), Category::$rules);
             if ($validator->passes()) {
                 $category->name = Crypt::encrypt($category->name);
                 $category->save();
                 $transaction->category_id = $category->id;
             }
         } else {
             $transaction->category_id = $category->id;
         }
     }
     // beneficiary
     if (strlen(Input::get('beneficiary')) != 0) {
         $beneficiaries = Auth::user()->beneficiaries()->get();
         //->where('name','=',Input::get('beneficiary'))->first();
         $beneficiary = null;
         foreach ($beneficiaries as $ben) {
             if (Crypt::decrypt($ben->name) == Input::get('beneficiary')) {
                 $beneficiary = $ben;
                 break;
             }
         }
         unset($ben, $categories);
         if (is_null($beneficiary)) {
             $beneficiary = new Beneficiary();
             $beneficiary->fireflyuser_id = Auth::user()->id;
             $beneficiary->name = Input::get('beneficiary');
             $validator = Validator::make($beneficiary->toArray(), Beneficiary::$rules);
             if ($validator->passes()) {
                 $beneficiary->name = Crypt::encrypt($beneficiary->name);
                 $beneficiary->save();
                 $transaction->beneficiary_id = $beneficiary->id;
             }
         } else {
             $transaction->beneficiary_id = $beneficiary->id;
         }
     }
     $validator = Validator::make($transaction->toArray(), Transaction::$rules);
     $transaction->description = Crypt::encrypt($transaction->description);
     if ($validator->fails()) {
         return Redirect::to('/home/transaction/add')->withErrors($validator)->withInput();
     } else {
         // the transaction was valid! lets save some tags!
         $transaction->save();
         if (Input::get('tags') != null && strlen(Input::get('tags')) > 0) {
             $tags = explode(',', Input::get('tags'));
             foreach ($tags as $tag) {
                 $dbTag = Tag::findOrCreate($tag);
                 $transaction->tags()->attach($dbTag);
             }
         }
         return Redirect::to('/home/transaction/add');
     }
 }
Exemplo n.º 25
0
            $this->OrderDate = $row->OrderDate;
            $this->ReceptionDate = $row->ReceptionDate;
            $this->ProcessedDate = $row->ProcessedDate;
            $this->PaymentDate = $row->PaymentDate;
            $this->FinishedDate = $row->FinishedDate;
            break;
        }
        closeDB($connection);
    }
    public function save()
    {
        $connection = connectDB();
        $query = "UPDATE Transactions\n\t\t\t\tSET FirstName = '{$this->fname}',\n\t\t\t\tLastName = '{$this->lname}',\n\t\t\t\tEmail = '{$this->email}',\n\t\t\t\tPayment = '{$this->payment}',\n\t\t\t\tFinalToPay = '{$this->finalToPay}',\n\t\t\t\tPaypalMail = '{$this->PaypalMail}',\n\t\t\t\tBankNr = '{$this->BankNr}',\n\t\t\t\tAccountNr = '{$this->AccountNr}',\n\t\t\t\tStatusDate = '{$this->StatusDate}',\n\t\t\t\tRejectOption = '{$this->RejectOption}',\n\t\t\t\tOrderDate = '{$this->OrderDate}',\n\t\t\t\tReceptionDate = '{$this->ReceptionDate}',\n\t\t\t\tProcessedDate = '{$this->ProcessedDate}',\n\t\t\t\tPaymentDate = '{$this->PaymentDate}',\n\t\t\t\tFinishedDate = '{$this->FinishedDate}'\n\t\t\t\tWHERE id={$this->id}";
        echo $query;
        mysql_query($query);
        closeDB($connection);
    }
}
$myTrans = new Transaction();
$myTrans->loadById(8);
echo $myTrans->id;
echo $myTrans->fname;
echo $myTrans->lname;
echo $myTrans->email;
$myTrans->email = "*****@*****.**";
$myTrans->save();
$myTrans->loadById(8);
echo $myTrans->id;
echo $myTrans->fname;
echo $myTrans->lname;
echo $myTrans->email;
Exemplo n.º 26
0
 public function actionpayredirect()
 {
     if (!isset($_POST['id_bank'])) {
         Yii::app()->user->setFlash('error', Yii::t('translation', 'Please select a bank'));
         $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
     }
     if (isset($_POST['amount']) && ($_POST['amount'] <= 0 or $_POST['amount'] > 10000)) {
         Yii::app()->user->setFlash('error', Yii::t('translation', 'The amount cant be zero or more than 10000'));
         $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
     }
     if (isset($_POST['id_bank']) && isset($_POST['amount'])) {
         if ($_POST['amount'] <= 0 or $_POST['amount'] > 10000 or $_POST['id_bank'] == "") {
             Yii::app()->user->setFlash('error', Yii::t('translation', 'Invalid amount or bank'));
             $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
         }
         $user = Yii::app()->user->data();
         $tran = new Transaction();
         $tran->id_user = $user->id;
         $tran->status = 0;
         $tran->type = 1;
         $tran->amount = $_POST['amount'];
         $tran->currency = "MXN";
         $tran->descr = "Deposito de pesos en tu cuenta usando astropay";
         $tran->save();
         $invo = new Invoices();
         $invo->id_user = $user->id;
         $invo->invoice_number = dechex(time());
         $invo->amount = $_POST['amount'];
         $invo->status = 0;
         $invo->id_bank = $_POST['id_bank'];
         $invo->name_bank = "Bank Test";
         $invo->id_country = "MX";
         $invo->id_currency = "MXN";
         $invo->descr = "Deposit via Astropay";
         $invo->id_cpf = "";
         $invo->id_sub_code = "";
         $invo->id_trans = $tran->id_trans;
         $invo->save();
         $return_url = "http://mercadobtx.com/deposit/return";
         $confirmation_url = "http://mercadobtx.com/deposit/confirm";
         $apd = new AstroPayDirect();
         $jdata = $apd->create($invo->invoice_number, $invo->amount, $user->id, $invo->id_bank, $invo->id_country, $invo->id_currency, $invo->descr, $invo->id_cpf, $invo->id_sub_code, $return_url, $confirmation_url, $response_type = 'json');
         $dat = json_decode($jdata);
         if ($dat->{"status"} == "OK") {
             $this->redirect($dat->{"link"});
         } else {
             Yii::app()->user->setFlash('error', Yii::t('translation', 'Returned error from Astropay') . " " . $dat->{"desc"});
             $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
         }
     }
     $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
 }
 /**
  * Store a newly created transaction in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Transaction::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // USER
     $data['user_id'] = Auth::id();
     // AMOUNT Format
     $data['amount'] = str_replace('.', '', $data['amount']);
     $data['amount'] = str_replace(',', '.', $data['amount']);
     // TYPE
     if ($data['type'] == 'despesa') {
         $data['amount'] = 0 - $data['amount'];
         // Deixa o número negativo
     }
     // CATEGORIA
     $category = Category::where('name', '=', @$data['category'])->first();
     // cria se não existir
     if (!$category) {
         $category = Category::create(['name' => ucfirst($data['category']), 'owner_type' => 'transaction']);
     }
     $now = Carbon::now();
     switch (@$data['recurring_type']) {
         // REPETIR DIARIAMENTE
         case 'daily':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addDays($i)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR SEMAMANLMENTE
         // REPETIR SEMAMANLMENTE
         case 'weekly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addWeeks($i)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR QUINZENALMENTE
         // REPETIR QUINZENALMENTE
         case 'biweekly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addWeeks($i * 2)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR MENSALMENTE
         // REPETIR MENSALMENTE
         case 'monthly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addMonths($i)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR BIMESTRALMENTE
         // REPETIR BIMESTRALMENTE
         case 'bimonthly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addMonths($i * 2)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR TRIMESTRAL
         // REPETIR TRIMESTRAL
         case 'trimonthly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addMonths($i * 3)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR SEMESTRAL
         // REPETIR SEMESTRAL
         case 'sixmonthly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addMonths($i * 6)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->save();
             }
             break;
             // REPETIR ANUAL
         // REPETIR ANUAL
         case 'yearly':
             // CRIA AS TRANSACTIONS
             for ($i = 0; $i < $data['recurring_times']; $i++) {
                 $transaction = new Transaction();
                 $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
                 $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
                 $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
                 $transaction->date = (new Carbon($data['date']))->addYears($i)->format('Y-m-d');
                 $transaction->done = $data['done'];
                 $transaction->recurring_type = $data['recurring_type'];
                 $transaction->recurring_times = $data['recurring_type'] != 'never' ? $data['recurring_times'] : '';
                 $transaction->recurring_cycle = $i + 1;
                 $transaction->category_id = $category->id;
                 $transaction->save();
                 $transaction_owner = isset($transaction_owner) ? $transaction_owner : $transaction->id;
                 $transaction->recurring_transaction_id = $transaction_owner;
                 $transaction->user_id = Auth::id();
                 $transaction->save();
             }
             break;
         default:
             $transaction = new Transaction();
             $transaction->type = isset($data['type']) ? $data['type'] : 'despesa';
             $transaction->amount = isset($data['amount']) ? $data['amount'] : '0.00';
             $transaction->description = isset($data['description']) ? $data['description'] : '( sem descrição )';
             $transaction->date = (new Carbon($data['date']))->format('Y-m-d');
             $transaction->done = $data['done'];
             $transaction->category_id = $category->id;
             $transaction->recurring_times = 0;
             $transaction->user_id = Auth::id();
             $transaction->save();
             // if( $transaction ){
             // 	$alert[] = [  'class' 	=> 'alert-success',
             //               'message' => '<strong><i class="fa fa-check"></i></strong> Lançamento registrado!' ];
             // }else{
             // 	$alert[] = [  'class' 	=> 'alert-danger',
             //               'message' => '<strong><i class="fa fa-warning"></i></strong> Um erro ocorreu!' ];
             // }
             break;
     }
     // echo "<pre>";
     // print_r($data);
     // echo "</pre>";
     // exit;
     //return Response::json($data);
     //exit;
     if ($data['recurring_times'] > 1) {
         $alert[] = ['class' => 'alert-success', 'message' => '<strong><i class="fa fa-check"></i></strong> Lançamentos registrados!'];
     } else {
         $alert[] = ['class' => 'alert-success', 'message' => '<strong><i class="fa fa-check"></i></strong> Lançamento registrado!'];
     }
     Session::flash('alerts', $alert);
     return Redirect::back()->withInput();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($fid = null)
 {
     $model = new Subscription();
     $parms = array();
     if (isset($_POST['Subscription']) and isset($_POST['Subscription']['family_id'])) {
         $fid = $_POST['Subscription']['family_id'];
     }
     if (isset($fid)) {
         $family = Families::model()->findByPk($fid);
         $parms['family'] = $family;
         $dt = $this->getStartDate($family);
         $parms['start_dt'] = $dt;
         Yii::trace("SC.create: fid:" . $family->id . ", dt=" . date_format($dt, 'Y-m-d'), 'application.controllers.SubscriptionController');
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Subscription'])) {
         $till = $_POST['Subscription']['till'];
         $amt = $_POST['Subscription']['amount'];
         $start_dt = new DateTime(date_format($dt, 'Y-m-d'));
         $end_dt = new DateTime(date_format($dt, 'Y-m-d'));
         $end_dt->add(new DateInterval('P' . $till . 'M'));
         $tr = Yii::app()->db->beginTransaction();
         $trans = new Transaction();
         $acct = Account::get('Family Subscriptions');
         $trans->account_id = $acct->id;
         $trans->type = 'credit';
         if ('total' == $_POST['duration']) {
             $total = $amt;
             $amt = $amt / $till;
         } else {
             $total = $till * $amt;
         }
         $trans->amount = $total;
         $trans->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
         $trans->creator = Yii::app()->user->id;
         $trans->descr = "Family #" . $family->id . ' subscription from ' . date_format($start_dt, 'M Y') . ' to ' . date_format($end_dt, 'M Y');
         if ($trans->save()) {
             $model = new Subscription();
             $model->paid_by = $_POST['Subscription']['paid_by'];
             $model->family_id = $family->id;
             $model->start_month = date_format($start_dt, 'n');
             $model->start_year = date_format($start_dt, 'Y');
             $model->end_month = date_format($end_dt, 'n');
             $model->end_year = date_format($end_dt, 'Y');
             $model->amount = $amt;
             $model->trans_id = $trans->id;
             if ($model->save()) {
                 $tr->commit();
                 $this->redirect(array('view', 'id' => $model->id));
                 return;
             }
         }
         $tr->rollback();
     }
     $parms['model'] = $model;
     $this->render('create', $parms);
 }
Exemplo n.º 29
0
    $paypalEmail = $ppMailadress;
} else {
    $paypalEmail = $email;
}
require_once "Transaction.php";
$t = new Transaction();
$t->loadById($transaction);
//print_r($t);
$t->fname = $fn;
$t->lname = $ln;
$t->email = $email;
$t->payment = $payment;
$t->BankNr = $blz;
$t->AccountNr = $kto;
$t->PaypalMail = $paypalEmail;
$t->save();
echo "<table>";
echo "\t<tr><td>{$confirm_label1}</td><td>" . $t->fname . "</td></tr>\n\t\t  \t<tr><td>{$confirm_label2}</td><td>" . $t->lname . "</td></tr>\n\t\t\t<tr><td>{$confirm_label3}</td><td>" . $t->email . "</td></tr>\n\t\t\t<tr><td>{$confirm_label4}</td><td>" . $t->payment . "</td></tr>";
if (strtolower($t->payment) == "paypal") {
    echo "\t<tr><td>{$confirm_label5}</td><td>" . $t->PaypalMail . "</td></tr>";
} else {
    echo "\t<tr><td>{$confirm_label6}</td><td>" . $t->BankNr . "</td></tr>\n\t\t\t  \t<tr><td>{$confirm_label7}</td><td>" . $t->getAccountNr() . "</td></tr>";
}
echo "</table>";
?>
    
    <div id="error_on_submit" class="orange"></div>
	<input	type="checkbox" id="agb" /><label>
    <?php 
echo $confirm_checkbox1;
?>
 public function reserve_post($id)
 {
     // GET THE LAST RESERVATION
     $last_user_reservation = Reservation::where('user_id', Sentry::getUser()->id)->orderBy('created_at', 'desc')->first();
     if (!is_null($last_user_reservation)) {
         $current_time = time();
         $last_user_reservation_time = strtotime($last_user_reservation->created_at);
         $interval = abs($current_time - $last_user_reservation_time) / 3600;
         if ($interval < 15) {
             return Redirect::to('clients')->with('info', 'You must wait 15 hours before you can reserve again.');
         }
     }
     if (is_null(Property::find($id))) {
         return Redirect::to('properties');
     }
     $monitoring = Monitoring::where('block', Input::get('block'))->where('lot', Input::get('lot')) - first();
     if (!is_null($monitoring) && $monitoring->status == false) {
         return Redirect::to('clients')->with('info', 'This s**t is not available sorry.');
     }
     $rules = array('total_contract_price' => 'required', 'reservation_fee' => 'required', 'downpayment' => 'required', 'equity' => 'required', 'total_months' => 'required', 'monthly_fee' => 'required', 'agent_id' => 'required', 'terms' => 'required', 'block' => 'required|numeric', 'lot' => 'required|numeric');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('clients/reserve/' . $id)->withInput()->withErrors($validator);
     } else {
         $property = Property::find($id);
         $user = $this->user;
         // 0. CHANGE PROPERTY STATUS TO 0
         $downpayment = intval(Input::get('downpayment')) / 100 * $property->price;
         $equity = $property->price - $downpayment - $property->reservation_fee;
         $total_months = intval(Input::get('total_months'));
         // 1. SAVE TO THE DATABASE
         $reservation = new Reservation();
         $reservation->property_id = $id;
         $reservation->user_id = $this->user->id;
         $reservation->agent_id = Input::get('agent_id');
         $reservation->total_contract_price = intval(Input::get('total_contract_price'));
         $reservation->downpayment = $downpayment;
         $reservation->reservation_fee = $property->reservation_fee;
         $reservation->block = Input::get('block');
         $reservation->lot = Input::get('lot');
         // LOANABLE AMOUNT
         $reservation->equity = $equity;
         $reservation->total_months = $total_months;
         $reservation->monthly_fee = $equity / $total_months;
         $reservation->terms = Input::get('terms');
         //$reservation->unit_type = Input::get('unit_type');
         $reservation->save();
         // 2. NEW TRANSACTION
         $transaction = new Transaction();
         $transaction->reference_number = date('Ymd') . '-' . strtoupper(str_random(5));
         $transaction->property_id = $id;
         $transaction->user_id = $this->user->id;
         $transaction->reservation_id = $reservation->id;
         $transaction->status = 'Pending';
         $transaction->amount = $property->reservation_fee;
         $transaction->remarks = "Property Reservation";
         $transaction->save();
         // UPDATE MONITORING
         DB::table('monitorings')->where('block', Input::get('block'))->where('lot', Input::get('lot'))->update(array('status' => false));
         // 3.GENERATE INVOICE
         $x = View::make('admin.transactions.show', compact('transaction', 'user', 'property'));
         $pdf = storage_path() . '/invoices/' . $transaction->reference_number . '.pdf';
         $dompdf = new DOMPDF();
         $dompdf->load_html($x);
         $dompdf->render();
         $output = $dompdf->output();
         @file_put_contents($pdf, $output);
         // 3.1 GENERATE RESERVATION INFORMATION PDF
         $y = View::make('admin.reservations.pdf', compact('transaction', 'user', 'reservation', 'property'));
         $res = storage_path() . '/reservations/reservation-' . $transaction->reference_number . '.pdf';
         $dompdf = new DOMPDF();
         $dompdf->load_html($y);
         $dompdf->render();
         $output = $dompdf->output();
         @file_put_contents($res, $output);
         // 4. EMAIL DEVELOPER,ADMIN AND BUYER
         $admin = User::find(1);
         $developer = $property->developer;
         $data['transaction'] = $transaction;
         Mail::send('mails.default', $data, function ($message) use($transaction, $pdf, $developer, $admin, $res) {
             $user = Sentry::getUser();
             $message->to($user->email)->subject("Property Reservation Notification");
             $message->to($developer->email)->subject("Property Reservation Notification");
             $message->to($admin->email)->subject("Property Reservation Notification");
             $message->attach($pdf);
             $message->attach($res);
         });
         return Redirect::to('clients')->with('success', 'Your reservation has been sent to administrator for approval.');
     }
 }