public function getpromotionAction()
 {
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $promotion_id = $this->_getParam('promotion_id');
         $promotion = new PAP_Model_Promotion();
         $data = $promotion->getViewRecord($promotion_id);
         $this->_helper->json($data);
     }
 }
 public function getpromodetailAction()
 {
     $this->_helper->layout->setLayout('json');
     $callback = $this->getRequest()->getParam('jsoncallback');
     if ($callback != "") {
         // strip all non alphanumeric elements from callback
         $callback = preg_replace('/[^a-zA-Z0-9_]/', '', $callback);
     }
     $this->view->callback = $callback;
     $lat = $this->_getParam('lat');
     //$_GET['lat'];
     $lng = $this->_getParam('lng');
     //$_GET['lng'];
     $promotion_id = $this->_getParam('promoid');
     //$_GET['lng'];
     $promotion = new PAP_Model_Promotion();
     $data = $promotion->getPromotionById($promotion_id, $lat, $lng);
     $data["logo"] = $this->getDataURI("./images" . $data["logo"]);
     $data["path"] = $this->getDataURI("./images" . $this->getThumb($data["path"]));
     $data["promo_photo"] = "./images" . $data["path"];
     $response = $this->getFrontController()->getResponse();
     $response->appendBody($callback . '(' . json_encode($data) . ')');
     $this->getFrontController()->setResponse($response);
 }
 private function loadForm(PAP_Model_Promotion $promo, $formName = null)
 {
     $form = $this->view->form;
     $control = $form->getElement('promoId');
     $control->setValue($promo->getId());
     $control = $form->getElement('promoCode');
     $control->setValue($promo->getPromoCode());
     $control = $form->getElement('shortDescription');
     $control->setValue($promo->getShortDescription());
     $control = $form->getElement('longDescription');
     $control->setValue($promo->getLongDescription());
     $control = $form->getElement('longDescription');
     $control->setValue($promo->getLongDescription());
     $control = $form->getElement('starts');
     $control->setValue($promo->getStarts());
     $control = $form->getElement('ends');
     $control->setValue($promo->getEnds());
     $control = $form->getElement('promoValue');
     $control->setValue($promo->getPromoValue());
     //$control = $form->getElement('totalCost');
     //$control->setValue($promo->getTotalPromoCost());
     $control = $form->getElement('valueSince');
     $control->setValue($promo->getValueSince());
     $control = $form->getElement('quantity');
     $control->setValue($promo->getQuantity());
     $control = $form->getElement('promoType');
     $control->setValue($promo->getPromoType());
     $control = $form->getElement('displayedText');
     $control->setValue($promo->getDisplayedText());
     $control = $form->getElement('alertType');
     $control->setValue($promo->getAlertType());
     $control = $form->getElement('state');
     $control->setValue($promo->getState());
     $control = $form->getElement('promoCost');
     $control->setValue($promo->getPromoCost());
     $control = $form->getElement('visited');
     $control->setValue($promo->getVisited());
     $control = $form->getElement('imagePromo');
     $img = $promo->getImage();
     if (isset($img)) {
         $control->setOptions(array('src' => '/images' . $img->getPath()));
     } else {
         $control->setOptions(array('src' => '/images' . $this->user->getBranch()->getLogo()));
     }
 }
 public function loadImages(PAP_Model_Promotion $promo)
 {
     $imageTable = new PAP_Model_DbTable_Image();
     $images = array();
     $select = $imageTable->select();
     $select->where('parent_id = ?', $promo->getId())->where('parent_type = ?', 'P');
     $result = $imageTable->fetchAll($select);
     if (count($result) == 0) {
         return false;
     }
     $i = 0;
     foreach ($result as $r) {
         $images[] = new PAP_Model_Image($r->path);
     }
     $promo->setImages($images);
     return true;
 }
 public function createchargesAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $config = new PAP_Helper_Config();
     $lastPeriod = $config->getLastPeriod();
     //$lastPeriod = "2MAR13";
     $currentPeriod = $this->getCurrentPeriodCode();
     //$currentPeriod = "1ABR13";
     if ($lastPeriod != $currentPeriod) {
         if ($lastPeriod != "") {
             $payments = null;
             $promos = PAP_Model_Promotion::getPromotionsByPeriod($lastPeriod);
             $period = new PAP_Model_Period();
             $period->loadByCode($lastPeriod);
             $periods = array();
             $periods[] = $period;
             $payments = PAP_Model_Payment::getAllPayments($periods);
             foreach ($payments as $payment) {
                 $charge = new PAP_Model_Charge();
                 $charge->setAmount($payment["total"])->setDiscount(0)->setPeriod($payment["periodo"])->setStatus('N')->setUserId($payment["user_id"])->setFinalAmount($payment["total"]);
                 if ($payment["total"] == "0.00") {
                     $charge->setStatus('A');
                 }
                 $charge->save();
             }
         }
         $config->setLastPeriod($currentPeriod);
     }
 }
Beispiel #6
0
 public static function getTotal(PAP_Model_Promotion $promo, $from, $to)
 {
     $days = PAP_Model_Payment::getWorkingDays($from, $to);
     $cost = (double) explode('-', $promo->getPromoCost());
     if ($days > 0) {
         $total = $days * $cost[1];
         return $total;
     } else {
         return 0;
     }
 }