public function executeDoManualMembership(sfWebRequest $request) { $this->authorizeUser(); global $CFG; $form = $request->getPostParameters(); if ($form['id'] != '') { // Edit of existing purchase $purchase = $this->getManualPurchase($form['id'], 'membership'); $institution = $this->eschool->getInstitution(); if (!($mhr_user = $institution->selectFromMhrTable('usr', 'id', $form['purchase_user_field'], true))) { $CFG->current_app->gcError('Invalid user ID ' . $form['purchase_user_field'], 'gcdatabaseerror'); } $manual_purchase_form = new GcrPurchaseMembershipManualForm($purchase, array('eschool' => $institution)); $form['user_id'] = $mhr_user->id; $form['amount'] = $form['amount_field']; $form['gc_fee'] = $this->eschool->getGcFeeMembership(); $form['bill_cycle'] = GcrPurchaseTable::convertDatetoTimestamp($form['bill_cycle']); $form['trans_time'] = GcrPurchaseTable::convertDatetoTimestamp($form['trans_time']); $manual_purchase_form->bind($form); if ($manual_purchase_form->isValid()) { $purchase = $manual_purchase_form->save(); $purchase->updateRelatedAccounting(); $this->redirect($CFG->current_app->getUrl() . '/account/view?eschool=' . $institution->getShortName()); } } else { // New purchase if ($short_name = $form['user_institution_id']) { $this->eschool = GcrInstitutionTable::getInstitution($short_name); } else { $CFG->current_app->gcError('eSchool Parameter Missing', 'gcdatabaseerror'); } $institution = $this->eschool->getInstitution(); $manual_purchase_form = new GcrPurchaseMembershipManualForm(array(), array('eschool' => $institution)); $form['purchase_type'] = 'membership_manual'; $form['purchase_type_description'] = 'Manual Membership Transaction'; $form['purchase_type_quantity'] = 1; $form['purchase_type_id'] = $institution->getShortName(); $form['user_id'] = $form['purchase_user_field']; $form['purchase_type_eschool_id'] = $institution->getShortName(); $form['user_institution_id'] = $institution->getShortName(); $form['amount'] = $form['amount_field']; $form['gc_fee'] = $institution->getGcFeeMembership(); $form['owner_fee'] = 0; $form['seller_id'] = 0; $form['bill_cycle'] = GcrPurchaseTable::convertDatetoTimestamp($form['bill_cycle']); $form['trans_time'] = GcrPurchaseTable::convertDatetoTimestamp($form['trans_time']); $manual_purchase_form->bind($form); if ($manual_purchase_form->isValid()) { if (!$institution->getUserById($form['purchase_user_field'])) { $CFG->current_app->gcError('Invalid user ID ' . $form['purchase_user_field'], 'gcdatabaseerror'); } $purchase = $manual_purchase_form->save(); $purchase->assignSeller(); $purchase->updateRelatedAccounting(); $this->redirect($CFG->current_app->getUrl() . '/account/view?eschool=' . $institution->getShortName()); } } $this->memerbship_form = $manual_purchase_form; $this->setTemplate('manualMembership'); }
public function executeDoManualPayoff(sfWebRequest $request) { global $CFG; $CFG->current_app->requireLogin(); $this->current_user = $CFG->current_app->getCurrentUser(); if (!$this->current_user->getRoleManager()->hasPrivilege('GCUser')) { $CFG->current_app->gcError('Non-privileged attempted access to ' . $form['user_eschool_id'] . ' createWithdrawal with user ID ' . $form['user_id'], 'gcpageaccessdenied'); } $form = $request->getPostParameters(); if ($form['payoff_id'] != '') { if (!($this->payoff = Doctrine::getTable('GcrPayoff')->find($form['payoff_id']))) { $CFG->current_app->gcError('Payoff ID: ' . $form['id'] . ' does not exist', 'gcdatabaseerror'); } if (!$this->payoff->isManual()) { $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' is not of type manual', 'gcdatabaseerror'); } $this->institution = GcrInstitutionTable::getInstitution($this->payoff->getEschoolId()); $user_institution = GcrInstitutionTable::getInstitution($this->payoff->getUserEschoolId()); if (!($this->user = $user_institution->getUserById($this->payoff->getUserId()))) { $CFG->current_app->gcError('Local User with ID ' . $this->payoff->getUserId() . ' on eschool ' . $user_institution->getShortName() . ' does not exist', 'gcdatabaseerror'); } if (!($this->credentials = $this->payoff->getCredentials())) { $CFG->current_app - gcError('Payoff ID ' . $this->payoff->getId() . ' has no credentials', 'gcdatabaserror'); } if (!($purchase = $this->payoff->getPurchase())) { $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' purchase ID ' . $this->payoff->getPurchaseId() . ' does not exist.', 'gcdatabaseerror'); } } else { $this->institution = GcrInstitutionTable::getInstitution($form['eschool_id']); $user_institution = GcrInstitutionTable::getInstitution($form['user_eschool_id']); if (!($this->user = $user_institution->getUserById($form['user_id']))) { $CFG->current_app->gcError('Local User with ID ' . $form['user_id'] . ' on eschool ' . $user_institution->getShortName() . ' does not exist', 'gcdatabaseerror'); } if (!($this->credentials = $this->user->getAccountManager()->getPayoffCredentials())) { $CFG->current_app->gcError('No payoff credentials found for ' . $form['user_eschool_id'] . ' createWithdrawal with user ID ' . $form['user_id'], 'gcpageaccessdenied'); } $this->payoff = new GcrPayoff(); $this->payoff->setUserId($this->user->getObject()->id); $this->payoff->setUserEschoolId($form['user_eschool_id']); $this->payoff->setEschoolId($form['eschool_id']); $this->payoff->setPayoffStatus('completed'); $this->payoff->setCredentialsId($this->credentials->getId()); } unset($form['payoff_id']); $manual_payoff_form = new GcrPayoffManualForm(); $manual_payoff_form->bind($form); if ($manual_payoff_form->isValid()) { $this->payoff->setAmount($form['amount']); $form['transtime'] = GcrPurchaseTable::convertDatetoTimestamp($form['transtime']); $this->payoff->setTransTime($form['transtime']); $this->payoff->setPayoffType($this->user->getAccountManager()->getPayoffType() . '_manual'); $url = GcrEschoolTable::getHome()->getUrl() . '/account/view?eschool=' . $this->institution->getShortName() . '&user='******'type'] == 'check') { if ($this->payoff->isManualCheckPayment()) { if (!($address = $this->payoff->getAddressObject())) { $CFG->current_app->gcError('Payoff ID ' . $this->payoff->getId() . ' has non-existant address value'); } } else { $address = new GcrAddress(); } $address->setStreet1($form['street1']); $address->setStreet2($form['street2']); $address->setCity($form['city']); $address->setZipcode($form['zipcode']); $address->setState($form['state']); $address->setCountry($form['country']); $address->save(); $this->payoff->setAddress($address->getId()); } if ($form['description'] == '') { $description = 'Manual Account Withdrawal'; } else { $description = $form['description']; } if ($purchase) { $purchase->setPurchaseTypeDescription($description); $purchase->setAmount($this->payoff->getAmount()); $purchase->setTransTime($form['transtime']); $purchase->setProfileId($form['reference_id']); $purchase->save(); } else { $purchase = $this->payoff->createPurchaseRecord($description, $form['transtime'], $form['reference_id']); } $this->payoff->save(); $purchase->updateRelatedAccounting(); $this->redirect($url); } $this->payoff_id = $this->payoff->getId(); $this->payoff_form = $manual_payoff_form; $this->setTemplate('manualPayoff'); }