Esempio n. 1
0
 /**
  * Add or edit donation
  * CODE: donation_create
  */
 public function executeUpdate(sfWebRequest $request)
 {
     # security
     if (!$this->getUser()->hasCredential(array('Administrator'), false)) {
         $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer());
         $this->redirect('dashboard/index');
     }
     if ($request->getParameter('id')) {
         $dona = DonationPeer::retrieveByPK($request->getParameter('id'));
         $this->forward404Unless($dona);
         $this->title = 'Edit donation';
         $success = 'Donation information has been successfully changed!';
     } else {
         $dona = new Donation();
         $this->title = 'Add new donation';
         $success = 'Donation information has been successfully created!';
     }
     $this->form = new DonationForm($dona);
     if ($request->isMethod('post')) {
         $this->referer = $request->getParameter('referer');
         $this->form->bind($request->getParameter('dona'));
         if ($this->form->isValid() && $this->form->getValue('campain_id') && $this->form->getValue('donor_id') && $this->form->getValue('fund_id') && $this->form->getValue('gift_type')) {
             $donor = DonorPeer::getByPersonId($this->form->getValue('donor_id'));
             if ($donor) {
                 $id = $donor->getId();
             }
             $dona->setDonorId($id);
             $dona->setGiftDate($this->form->getValue('gift_date'));
             $dona->setGiftAmount($this->form->getValue('gift_amount'));
             $dona->setDeductibleAmount($this->form->getValue('deductible_amount'));
             $dona->setGiftType($this->form->getValue('gift_type'));
             $dona->setCheckNumber($this->form->getValue('check_number'));
             $dona->setCampainId($this->form->getValue('campain_id'));
             $dona->setFundId($this->form->getValue('fund_id'));
             $dona->setGiftNote($this->form->getValue('gift_note'));
             $dona->setPrintedNote($this->form->getValue('printed_note'));
             $dona->setReceiptGeneratedDate($this->form->getValue('receipt_generated_date'));
             if ($this->form->getValue('follow_up') == null) {
                 $dona->setFollowUp(0);
             } else {
                 $dona->setFollowUp($this->form->getValue('follow_up'));
             }
             $dona->setPremiumOrderDate($this->form->getValue('premium_order_date'));
             $dona->save();
             $this->getUser()->setFlash('success', $success);
             $this->redirect('@donation');
         } else {
             $this->getUser()->setFlash('success', 'Please choice Donor, Gift Type, Campaign or Fund!');
         }
     } else {
         # Set referer URL
         $this->referer = $request->getReferer() ? $request->getReferer() : '@danation';
     }
     $this->dona = $dona;
 }