Пример #1
0
 public function save(Default_Model_RecurrentExpenses $value)
 {
     $data = array('idMember' => Zend_Registry::get('user')->getId(), 'idGroup' => $value->getIdGroup(), 'name' => $value->getName(), 'price' => $value->getPrice(), 'date' => $value->getDate(), 'datePaid' => $value->getDatePaid(), 'type' => $value->getType(), 'deleted' => '0');
     $action_done = '';
     if (null === ($id = $value->getId())) {
         $data['created'] = new Zend_Db_Expr('NOW()');
         $id = $this->getDbTable()->insert($data);
         //logs	action done
         //$user_name = $value->getUserName()->getName().' '.$value->getUserName()->getSurname();
         $user_name = "User";
         $product_name = $value->getName();
         $action_done = ' ' . $user_name . ' a adaugat proiectul ' . $product_name . ' ';
         //$value->getIdUser() adaugat in baza de date ca 0
         Needs_Logs::DbLogTracking(Zend_Registry::get('user')->getId(), $id, 'products', 'adaugare', $action_done);
         //end logs action done
     } else {
         $data['modified'] = new Zend_Db_Expr('NOW()');
         $this->getDbTable()->update($data, array('id = ?' => $id));
         //logs	action done
         //$user_name = $value->getUserName()->getName().' '.$value->getUserName()->getSurname();
         $product_name = $value->getName();
         $user_name = "User";
         $action_done = '' . $user_name . ' modified the product ' . $product_name . ' ';
         Needs_Logs::DbLogTracking(Zend_Registry::get('user')->getId(), $id, 'products', 'editare', $action_done);
         //end logs action done
     }
     return $id;
 }
Пример #2
0
 function cronjob($runHours = 'month')
 {
     $updatedRE = false;
     //Get Time
     $now = date('Y-m-d');
     //data de azi
     //Convert Time
     $model = new Default_Model_RecurrentExpenses();
     $select = $model->getMapper()->getDbTable()->select()->where('NOT `deleted`');
     $result = $model->fetchAll($select);
     if ($result) {
         foreach ($result as $values) {
             $date = $values->getDatePaid() ? $values->getDatePaid() : $values->getDate();
             //1 mai 2014
             $day = date('d', strtotime($date));
             $feb = date('L', strtotime($date)) ? 29 : 28;
             //an bisect
             $days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31);
             //nr zile pe luna
             //$month=array(1,2,3,4,5,6,7,8,9,10,11,12);
             $newdate = strtotime('+' . $days[date('n', strtotime($date))] . ' days', strtotime($date));
             if ($day < 29 && $day > 1) {
                 $newdate = date('Y-m', $newdate) . "-{$day}";
             } else {
                 if (date('n', strtotime($date)) == 1) {
                     //january
                     if ($feb == 29) {
                         $newdate = date('Y-02') . "-" . ($day == 1 ? '01' : '29');
                     } else {
                         $newdate = date('Y-02') . "-" . ($day == 1 ? '01' : '28');
                     }
                 } else {
                     if ($days[date('n', strtotime($date))] > $days[date('n', strtotime($date)) + 1] && $day > 1) {
                         $newdate = date('Y-m-d', strtotime('+' . $days[date('n', strtotime($date)) + 1] . ' days', strtotime($date)));
                     } else {
                         $newdate = date('Y-m-d', $newdate);
                     }
                 }
                 //$newdate=date ( 'Y-m-d' , $newdate );
             }
             if ($newdate <= date('Y-m-d')) {
                 $model->find($values->getId());
                 $model->setDatePaid($newdate);
                 if ($model->save()) {
                     $modelExpenses = new Default_Model_Expenses();
                     $modelExpenses->setIdMember($model->getIdMember());
                     $modelExpenses->setName($model->getName());
                     $modelExpenses->setPrice($model->getPrice());
                     $modelExpenses->setType($model->getType());
                     $modelExpenses->setDate($model->getDatePaid());
                     if ($expenseId = $modelExpenses->save()) {
                         $productGroups = new Default_Model_ProductGroups();
                         $select = $productGroups->getMapper()->getDbTable()->select()->where('idProduct=?', $model->getId())->where('repeated=?', 1);
                         $result = $productGroups->fetchRow($select);
                         if (NULL != $result) {
                             $idGroup = $result->getIdGroup();
                             $productGroups->setIdProduct($expenseId);
                             $productGroups->setIdGroup($idGroup);
                             $productGroups->setId('');
                             $productGroups->setRepeated(0);
                             $productGroups->save();
                         }
                     }
                     $updatedRE = true;
                 }
             }
         }
     }
     return $updatedRE;
 }