コード例 #1
0
 /**
  * edit method
  *
  * @param string $entrytypeLabel
  * @param string $id
  * @return void
  */
 public function edit($entrytypeLabel = null, $id = null)
 {
     /* Check for valid entry type */
     if (!$entrytypeLabel) {
         $this->Session->setFlash(__d('webzash', 'Entry type not specified.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
     }
     $entrytype = $this->Entrytype->find('first', array('conditions' => array('Entrytype.label' => $entrytypeLabel)));
     if (!$entrytype) {
         $this->Session->setFlash(__d('webzash', 'Entry type not found.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
     }
     $this->set('entrytype', $entrytype);
     $this->set('title_for_layout', __d('webzash', 'Edit %s Entry', $entrytype['Entrytype']['name']));
     $this->set('tag_options', $this->Tag->listAll());
     /* Ledger selection */
     $ledgers = new LedgerTree();
     $ledgers->Group =& $this->Group;
     $ledgers->Ledger =& $this->Ledger;
     $ledgers->current_id = -1;
     $ledgers->restriction_bankcash = $entrytype['Entrytype']['restriction_bankcash'];
     $ledgers->build(0);
     $ledgers->toList($ledgers, -1);
     $ledgers_disabled = array();
     foreach ($ledgers->ledgerList as $row => $data) {
         if ($row < 0) {
             $ledgers_disabled[] = $row;
         }
     }
     $this->set('ledger_options', $ledgers->ledgerList);
     $this->set('ledgers_disabled', $ledgers_disabled);
     /* Check for valid entry id */
     if (empty($id)) {
         $this->Session->setFlash(__d('webzash', 'Entry not specified.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
     }
     $entry = $this->Entry->findById($id);
     if (!$entry) {
         $this->Session->setFlash(__d('webzash', 'Entry not found.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
     }
     /* Initial data */
     if ($this->request->is('post') || $this->request->is('put')) {
         $curEntryitems = array();
         foreach ($this->request->data['Entryitem'] as $row => $entryitem) {
             $curEntryitems[$row] = array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'dr_amount' => isset($entryitem['dr_amount']) ? $entryitem['dr_amount'] : '', 'cr_amount' => isset($entryitem['cr_amount']) ? $entryitem['cr_amount'] : '');
         }
         $this->set('curEntryitems', $curEntryitems);
     } else {
         $curEntryitems = array();
         $curEntryitemsData = $this->Entryitem->find('all', array('conditions' => array('Entryitem.entry_id' => $id)));
         foreach ($curEntryitemsData as $row => $data) {
             if ($data['Entryitem']['dc'] == 'D') {
                 $curEntryitems[$row] = array('dc' => $data['Entryitem']['dc'], 'ledger_id' => $data['Entryitem']['ledger_id'], 'dr_amount' => $data['Entryitem']['amount'], 'cr_amount' => '');
             } else {
                 $curEntryitems[$row] = array('dc' => $data['Entryitem']['dc'], 'ledger_id' => $data['Entryitem']['ledger_id'], 'dr_amount' => '', 'cr_amount' => $data['Entryitem']['amount']);
             }
         }
         $curEntryitems[] = array('dc' => 'D');
         $curEntryitems[] = array('dc' => 'D');
         $curEntryitems[] = array('dc' => 'D');
         $this->set('curEntryitems', $curEntryitems);
     }
     /* On POST */
     if ($this->request->is('post') || $this->request->is('put')) {
         if (!empty($this->request->data)) {
             /* Check if acccount is locked */
             if (Configure::read('Account.locked') == 1) {
                 $this->Session->setFlash(__d('webzash', 'Sorry, no changes are possible since the account is locked.'), 'danger');
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
             }
             /***************************************************************************/
             /*********************************** ENTRY *********************************/
             /***************************************************************************/
             $entrydata = null;
             /* Entry id */
             unset($this->request->data['Entry']['id']);
             $this->Entry->id = $id;
             $entrydata['Entry']['id'] = $id;
             /***** Entry number ******/
             $entrydata['Entry']['number'] = $this->request->data['Entry']['number'];
             /****** Entrytype remains the same *****/
             $entrydata['Entry']['entrytype_id'] = $entrytype['Entrytype']['id'];
             /****** Check tag ******/
             if (empty($this->request->data['Entry']['tag_id'])) {
                 $entrydata['Entry']['tag_id'] = null;
             } else {
                 $entrydata['Entry']['tag_id'] = $this->request->data['Entry']['tag_id'];
             }
             /***** Narration *****/
             $entrydata['Entry']['narration'] = $this->request->data['Entry']['narration'];
             /***** Date *****/
             $entrydata['Entry']['date'] = dateToSql($this->request->data['Entry']['date']);
             /***************************************************************************/
             /***************************** ENTRY ITEMS *********************************/
             /***************************************************************************/
             /* Check ledger restriction */
             $dc_valid = false;
             foreach ($this->request->data['Entryitem'] as $row => $entryitem) {
                 if ($entryitem['ledger_id'] <= 0) {
                     continue;
                 }
                 $ledger = $this->Ledger->findById($entryitem['ledger_id']);
                 if (!$ledger) {
                     $this->Session->setFlash(__d('webzash', 'Invalid ledger selected.'), 'danger');
                     return;
                 }
                 if ($entrytype['Entrytype']['restriction_bankcash'] == 4) {
                     if ($ledger['Ledger']['type'] != 1) {
                         $this->Session->setFlash(__d('webzash', 'Only bank or cash ledgers are allowed for this entry type.'), 'danger');
                         return;
                     }
                 }
                 if ($entrytype['Entrytype']['restriction_bankcash'] == 5) {
                     if ($ledger['Ledger']['type'] == 1) {
                         $this->Session->setFlash(__d('webzash', 'Bank or cash ledgers are not allowed for this entry type.'), 'danger');
                         return;
                     }
                 }
                 if ($entryitem['dc'] == 'D') {
                     if ($entrytype['Entrytype']['restriction_bankcash'] == 2) {
                         if ($ledger['Ledger']['type'] == 1) {
                             $dc_valid = true;
                         }
                     }
                 } else {
                     if ($entryitem['dc'] == 'C') {
                         if ($entrytype['Entrytype']['restriction_bankcash'] == 3) {
                             if ($ledger['Ledger']['type'] == 1) {
                                 $dc_valid = true;
                             }
                         }
                     }
                 }
             }
             if ($entrytype['Entrytype']['restriction_bankcash'] == 2) {
                 if (!$dc_valid) {
                     $this->Session->setFlash(__d('webzash', 'Atleast one bank or cash ledger has to be on debit side for this entry type.'), 'danger');
                     return;
                 }
             }
             if ($entrytype['Entrytype']['restriction_bankcash'] == 3) {
                 if (!$dc_valid) {
                     $this->Session->setFlash(__d('webzash', 'Atleast one bank or cash ledger has to be on credit side for this entry type.'), 'danger');
                     return;
                 }
             }
             $dr_total = 0;
             $cr_total = 0;
             /* Check equality of debit and credit total */
             foreach ($this->request->data['Entryitem'] as $row => $entryitem) {
                 if ($entryitem['ledger_id'] <= 0) {
                     continue;
                 }
                 if ($entryitem['dc'] == 'D') {
                     if ($entryitem['dr_amount'] <= 0) {
                         $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Amount cannot be negative or zero.'), 'danger');
                         return;
                     }
                     if (countDecimal($entryitem['dr_amount']) > Configure::read('Account.decimal_places')) {
                         $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Maximum %s decimal places allowed.', Configure::read('Account.decimal_places')), 'danger');
                         return;
                     }
                     $dr_total = calculate($dr_total, $entryitem['dr_amount'], '+');
                 } else {
                     if ($entryitem['dc'] == 'C') {
                         if ($entryitem['cr_amount'] <= 0) {
                             $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Amount cannot be negative or zero.'), 'danger');
                             return;
                         }
                         if (countDecimal($entryitem['cr_amount']) > Configure::read('Account.decimal_places')) {
                             $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Maximum %s decimal places allowed.', Configure::read('Account.decimal_places')), 'danger');
                             return;
                         }
                         $cr_total = calculate($cr_total, $entryitem['cr_amount'], '+');
                     } else {
                         $this->Session->setFlash(__d('webzash', 'Invalid Dr/Cr option selected.'), 'danger');
                         return;
                     }
                 }
             }
             if (calculate($dr_total, $cr_total, '!=')) {
                 $this->Session->setFlash(__d('webzash', 'Debit and Credit total do not match.'), 'danger');
                 return;
             }
             $entrydata['Entry']['dr_total'] = $dr_total;
             $entrydata['Entry']['cr_total'] = $cr_total;
             /* Add item to entryitemdata array if everything is ok */
             $entryitemdata = array();
             foreach ($this->request->data['Entryitem'] as $row => $entryitem) {
                 if ($entryitem['ledger_id'] <= 0) {
                     continue;
                 }
                 if ($entryitem['dc'] == 'D') {
                     $entryitemdata[] = array('Entryitem' => array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'amount' => $entryitem['dr_amount']));
                 } else {
                     $entryitemdata[] = array('Entryitem' => array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'amount' => $entryitem['cr_amount']));
                 }
             }
             /* Save entry */
             $ds = $this->Entry->getDataSource();
             $ds->begin();
             if ($this->Entry->save($entrydata)) {
                 /* Delete all original entryitems */
                 if (!$this->Entryitem->deleteAll(array('Entryitem.entry_id' => $id))) {
                     $ds->rollback();
                     $this->Session->setFlash(__d('webzash', 'Previous entry items could not be deleted.'), 'danger');
                     return;
                 }
                 /* Save new entry items */
                 foreach ($entryitemdata as $id => $itemdata) {
                     $itemdata['Entryitem']['entry_id'] = $this->Entry->id;
                     $this->Entryitem->create();
                     if (!$this->Entryitem->save($itemdata)) {
                         foreach ($this->Entryitem->validationErrors as $field => $msg) {
                             $errmsg = $msg[0];
                             break;
                         }
                         $ds->rollback();
                         $this->Session->setFlash(__d('webzash', 'Failed to save entry ledgers. Error is : %s', $errmsg), 'danger');
                         return;
                     }
                 }
                 $tempentry = $this->Entry->read(null, $this->Entry->id);
                 if (!$tempentry) {
                     $this->Session->setFlash(__d('webzash', 'Oh snap ! Failed to update entry. Please, try again.'), 'danger');
                     $ds->rollback();
                     return;
                 }
                 $entryNumber = h(toEntryNumber($tempentry['Entry']['number'], $entrytype['Entrytype']['id']));
                 $this->Log->add('Edited ' . $entrytype['Entrytype']['name'] . ' entry numbered ' . $entryNumber, 1);
                 $ds->commit();
                 $this->Session->setFlash(__d('webzash', '%s entry numbered "%s" updated.', $entrytype['Entrytype']['name'], $entryNumber), 'success');
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index'));
             } else {
                 $ds->rollback();
                 $this->Session->setFlash(__d('webzash', 'Failed to update entry. Please, try again.'), 'danger');
                 return;
             }
         } else {
             $this->Session->setFlash(__d('webzash', 'No data. Please, try again.'), 'danger');
             return;
         }
     } else {
         $entry['Entry']['date'] = dateFromSql($entry['Entry']['date']);
         $this->request->data = $entry;
         return;
     }
 }
コード例 #2
0
 /**
  * reconciliation method
  *
  * @return void
  */
 public function reconciliation()
 {
     $this->set('title_for_layout', __d('webzash', 'Ledger Reconciliation'));
     /* Create list of ledgers to pass to view */
     $ledgers_q = $this->Ledger->find('all', array('fields' => array('Ledger.id', 'Ledger.name', 'Ledger.code'), 'order' => array('Ledger.name'), 'conditions' => array('Ledger.reconciliation' => '1')));
     $ledgers = array(0 => __d('webzash', 'Please select...'));
     foreach ($ledgers_q as $row) {
         $ledgers[$row['Ledger']['id']] = toCodeWithName($row['Ledger']['code'], $row['Ledger']['name']);
     }
     $this->set('ledgers', $ledgers);
     if ($this->request->is('post')) {
         /* Ledger selection form submitted */
         if (!empty($this->request->data['Report']['submitledger'])) {
             /* If valid data then redirect with POST values are URL parameters so that pagination works */
             if (empty($this->request->data['Report']['ledger_id'])) {
                 $this->Session->setFlash(__d('webzash', 'Invalid ledger.'), 'danger');
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation'));
             }
             if (!empty($this->request->data['Report']['startdate']) || !empty($this->request->data['Report']['enddate']) || !empty($this->request->data['Report']['showall'])) {
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation', 'ledgerid' => $this->request->data['Report']['ledger_id'], 'options' => 1, 'showall' => $this->request->data['Report']['showall'], 'startdate' => $this->request->data['Report']['startdate'], 'enddate' => $this->request->data['Report']['enddate']));
             } else {
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation', 'ledgerid' => $this->request->data['Report']['ledger_id']));
             }
         } else {
             if (!empty($this->request->data['ReportRec']['submitrec'])) {
                 /* Check if acccount is locked */
                 if (Configure::read('Account.locked') == 1) {
                     $this->Session->setFlash(__d('webzash', 'Sorry, no changes are possible since the account is locked.'), 'danger');
                     return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation'));
                 }
                 /* Reconciliation form submitted */
                 foreach ($this->request->data['ReportRec'] as $row => $recitem) {
                     if (empty($recitem['id'])) {
                         continue;
                     }
                     if (!empty($recitem['recdate'])) {
                         $recdate = dateToSql($recitem['recdate']);
                         if (!$recdate) {
                             $this->Session->setFlash(__d('webzash', 'Invalid reconciliation date.'), 'danger');
                             continue;
                         }
                     } else {
                         $recdate = '';
                     }
                     $this->Entryitem->id = $recitem['id'];
                     if (!$this->Entryitem->read()) {
                         continue;
                     }
                     $this->Entryitem->saveField('reconciliation_date', $recdate);
                 }
                 /* Unset all POST data so that data for reconciliation date is loaded from database */
                 unset($this->request->data['ReportRec']);
             } else {
                 return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation'));
             }
         }
     }
     $this->set('showEntries', false);
     $this->set('options', false);
     /* Check if ledger id is set in parameters, if not return and end view here */
     if (empty($this->passedArgs['ledgerid'])) {
         return;
     }
     $ledgerId = $this->passedArgs['ledgerid'];
     /* Check if ledger exists */
     $ledger = $this->Ledger->findById($ledgerId);
     if (!$ledger) {
         $this->Session->setFlash(__d('webzash', 'Ledger not found.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'reconciliation'));
     }
     $this->set('ledger', $ledger);
     $this->request->data['Report']['ledger_id'] = $ledgerId;
     /* Set the approprite search conditions */
     $conditions = array();
     $conditions['Entryitem.ledger_id'] = $ledgerId;
     /* Set the approprite search conditions if custom date is selected */
     $startdate = null;
     $enddate = null;
     if (empty($this->passedArgs['options'])) {
         $this->set('options', false);
         /* Sub-title*/
         $this->set('subtitle', __d('webzash', 'Reconciliation report for %s from %s to %s', h(toCodeWithName($ledger['Ledger']['code'], $ledger['Ledger']['name'])), dateFromSql(Configure::read('Account.startdate')), dateFromSql(Configure::read('Account.enddate'))));
     } else {
         $this->set('options', true);
         if (!empty($this->passedArgs['showall'])) {
             $this->request->data['Report']['showall'] = 1;
         }
         if (!empty($this->passedArgs['startdate'])) {
             /* TODO : Validate date */
             $startdate = dateToSql($this->passedArgs['startdate']);
             $this->request->data['Report']['startdate'] = $this->passedArgs['startdate'];
             $conditions['Entry.date >='] = $startdate;
         }
         if (!empty($this->passedArgs['enddate'])) {
             /* TODO : Validate date */
             $enddate = dateToSql($this->passedArgs['enddate']);
             $this->request->data['Report']['enddate'] = $this->passedArgs['enddate'];
             $conditions['Entry.date <='] = $enddate;
         }
         /* Sub-title*/
         if (!empty($this->passedArgs['startdate']) && !empty($this->passedArgs['enddate'])) {
             $this->set('subtitle', __d('webzash', 'Reconciliation report for %s from %s to %s', h($ledger['Ledger']['name']), dateFromSql(dateToSQL($this->passedArgs['startdate'])), dateFromSql(dateToSQL($this->passedArgs['enddate']))));
         } else {
             if (!empty($this->passedArgs['startdate'])) {
                 $this->set('subtitle', __d('webzash', 'Reconciliation report for %s from %s to %s', h($ledger['Ledger']['name']), dateFromSql(dateToSQL($this->passedArgs['startdate'])), dateFromSql(Configure::read('Account.enddate'))));
             } else {
                 if (!empty($this->passedArgs['enddate'])) {
                     $this->set('subtitle', __d('webzash', 'Reconciliation report for %s from %s to %s', h($ledger['Ledger']['name']), dateFromSql(Configure::read('Account.startdate')), dateFromSql(dateToSQL($this->passedArgs['enddate']))));
                 } else {
                     if (empty($this->passedArgs['startdate']) && empty($this->passedArgs['enddate'])) {
                         $this->set('subtitle', __d('webzash', 'Reconciliation report for %s from %s to %s', h($ledger['Ledger']['name']), dateFromSql(Configure::read('Account.startdate')), dateFromSql(Configure::read('Account.enddate'))));
                     }
                 }
             }
         }
     }
     if (!empty($this->passedArgs['showall'])) {
         /* Nothing to do */
     } else {
         $conditions['Entryitem.reconciliation_date'] = NULL;
     }
     /* Opening and closing titles */
     if (is_null($startdate)) {
         $this->set('opening_title', __d('webzash', 'Opening balance as on %s', dateFromSql(Configure::read('Account.startdate'))));
     } else {
         $this->set('opening_title', __d('webzash', 'Opening balance as on %s', dateFromSql($startdate)));
     }
     if (is_null($enddate)) {
         $this->set('closing_title', __d('webzash', 'Closing balance as on %s', dateFromSql(Configure::read('Account.enddate'))));
     } else {
         $this->set('closing_title', __d('webzash', 'Closing balance as on %s', dateFromSql($enddate)));
     }
     /* Reconciliation pending title */
     $this->set('recpending_title', '');
     if (is_null($startdate) && is_null($enddate)) {
         $this->set('recpending_title', __d('webzash', 'Reconciliation pending from %s to %s', dateFromSql(Configure::read('Account.startdate')), dateFromSql(Configure::read('Account.enddate'))));
     } else {
         if (!is_null($startdate) && !is_null($enddate)) {
             $this->set('recpending_title', __d('webzash', 'Reconciliation pending from %s to %s', dateFromSql($startdate), dateFromSql($enddate)));
         } else {
             if (is_null($startdate)) {
                 $this->set('recpending_title', __d('webzash', 'Reconciliation pending from %s to %s', dateFromSql(Configure::read('Account.startdate')), dateFromSql($enddate)));
             } else {
                 if (is_null($enddate)) {
                     $this->set('recpending_title', __d('webzash', 'Reconciliation pending from %s to %s', dateFromSql($startdate), dateFromSql(Configure::read('Account.enddate'))));
                 }
             }
         }
     }
     /* Calculating opening balance */
     $op = $this->Ledger->openingBalance($ledgerId, $startdate);
     $this->set('op', $op);
     /* Calculating closing balance */
     $cl = $this->Ledger->closingBalance($ledgerId, null, $enddate);
     $this->set('cl', $cl);
     /* Calculating reconciliation pending balance */
     $rp = $this->Ledger->reconciliationPending($ledgerId, $startdate, $enddate);
     $this->set('rp', $rp);
     /* Setup pagination */
     if (isset($this->passedArgs['download']) || isset($this->passedArgs['downloadxls']) || isset($this->passedArgs['print'])) {
         $this->CustomPaginator->settings = array('Entry' => array('fields' => array('Entry.id', 'Entry.tag_id', 'Entry.entrytype_id', 'Entry.number', 'Entry.date', 'Entry.dr_total', 'Entry.cr_total', 'Entry.narration', 'Entryitem.id', 'Entryitem.entry_id', 'Entryitem.ledger_id', 'Entryitem.amount', 'Entryitem.dc', 'Entryitem.reconciliation_date'), 'limit' => 100000000000, 'order' => array('Entry.date' => 'desc'), 'conditions' => $conditions, 'joins' => array(array('table' => 'entryitems', 'alias' => 'Entryitem', 'conditions' => array('Entry.id = Entryitem.entry_id')))));
     } else {
         $this->CustomPaginator->settings = array('Entry' => array('fields' => array('Entry.id', 'Entry.tag_id', 'Entry.entrytype_id', 'Entry.number', 'Entry.date', 'Entry.dr_total', 'Entry.cr_total', 'Entry.narration', 'Entryitem.id', 'Entryitem.entry_id', 'Entryitem.ledger_id', 'Entryitem.amount', 'Entryitem.dc', 'Entryitem.reconciliation_date'), 'limit' => $this->Session->read('Wzsetting.row_count'), 'order' => array('Entry.date' => 'desc'), 'conditions' => $conditions, 'joins' => array(array('table' => 'entryitems', 'alias' => 'Entryitem', 'conditions' => array('Entry.id = Entryitem.entry_id')))));
     }
     /* Pass varaibles to view which are used in Helpers */
     $this->set('allTags', $this->Tag->fetchAll());
     $this->set('entries', $this->CustomPaginator->paginate('Entry'));
     $this->set('showEntries', true);
     /* Download report */
     if (isset($this->passedArgs['downloadcsv'])) {
         Configure::write('Account.currency_format', 'none');
         $this->layout = false;
         $view = new View($this, false);
         $response = $view->render('Reports/downloadcsv/reconciliation');
         $this->response->body($response);
         $this->response->type('text/csv');
         $this->response->download('reconciliation.csv');
         return $this->response;
     }
     /* Download report */
     if (isset($this->passedArgs['downloadxls'])) {
         Configure::write('Account.currency_format', 'none');
         $this->layout = 'xls';
         $view = new View($this, false);
         $response = $view->render('Reports/downloadxls/reconciliation');
         $this->response->body($response);
         $this->response->type('application/vnd.ms-excel');
         $this->response->download('reconciliation.xls');
         return $this->response;
     }
     /* Print report */
     if (isset($this->passedArgs['print'])) {
         $this->layout = 'print';
         $view = new View($this, false);
         $response = $view->render('Reports/print/reconciliation');
         $this->response->body($response);
         return $this->response;
     }
     return;
 }
コード例 #3
0
 /**
  * account settings method
  *
  * @return void
  */
 public function account()
 {
     $this->set('title_for_layout', __d('webzash', 'Account Settings'));
     $setting = $this->Setting->findById(1);
     if (!$setting) {
         $this->Session->setFlash(__d('webzash', 'Account settings not found.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'settings', 'action' => 'index'));
     }
     /* on POST */
     if ($this->request->is('post') || $this->request->is('put')) {
         /* Check if acccount is locked */
         if (Configure::read('Account.locked') == 1) {
             $this->Session->setFlash(__d('webzash', 'Sorry, no changes are possible since the account is locked.'), 'danger');
             return $this->redirect(array('plugin' => 'webzash', 'controller' => 'settings', 'action' => 'index'));
         }
         /* Set setting id */
         unset($this->request->data['Setting']['id']);
         $this->Setting->id = 1;
         $settings = $this->request->data;
         $settings['Setting']['fy_start'] = dateToSql($this->request->data['Setting']['fy_start']);
         $settings['Setting']['fy_end'] = dateToSql($this->request->data['Setting']['fy_end']);
         /* Check if any entries are beyond start and end data */
         $count = $this->Entry->find('count', array('conditions' => array('OR' => array('Entry.date <' => dateToSql($this->request->data['Setting']['fy_start']), 'Entry.date >' => dateToSql($this->request->data['Setting']['fy_end'])))));
         if ($count != 0) {
             $this->Session->setFlash(__d('webzash', 'Failed to update account setting since there are %d entries beyond the selected financial year start and end dates.', $count), 'danger');
             return;
         }
         /* Check if financial year end is after financial year start */
         $start_date = strtotime($this->request->data['Setting']['fy_start'] . ' 00:00:00');
         $end_date = strtotime($this->request->data['Setting']['fy_end'] . ' 00:00:00');
         if ($start_date >= $end_date) {
             $this->Session->setFlash(__d('webzash', 'Failed to update account setting since financial year end should be after financial year start.'), 'danger');
             return;
         }
         /* Save settings */
         $ds = $this->Setting->getDataSource();
         $ds->begin();
         if ($this->Setting->save($settings, true, array('name', 'address', 'email', 'fy_start', 'fy_end', 'currency_symbol', 'currency_format', 'date_format'))) {
             $this->Log->add('Updated account settings', 1);
             $ds->commit();
             $this->Session->setFlash(__d('webzash', 'Account settings updated.'), 'success');
             return $this->redirect(array('plugin' => 'webzash', 'controller' => 'settings', 'action' => 'index'));
         } else {
             $ds->rollback();
             $this->Session->setFlash(__d('webzash', 'Failed to update account settings. Please, try again.'), 'danger');
             return;
         }
     } else {
         $setting['Setting']['fy_start'] = dateFromSql($setting['Setting']['fy_start']);
         $setting['Setting']['fy_end'] = dateFromSql($setting['Setting']['fy_end']);
         $this->request->data = $setting;
         return;
     }
     return;
 }
コード例 #4
0
ファイル: grids.php プロジェクト: Knah-Tsaeb/OpenVPN-Admin
    }
} else {
    if (isset($_POST['add_user'])) {
        // Put some default values
        $id = $_POST['user_id'];
        $pass = "";
        $mail = "";
        $phone = "";
        $online = 0;
        $enable = 1;
        $start = "0000-00-00";
        $end = "0000-00-00";
        $req = $bdd->prepare('INSERT INTO user (user_id, user_pass, user_mail, user_phone, user_online, user_enable, user_start_date, user_end_date)
                        VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
        $req->execute(array($id, $pass, $mail, $phone, $online, $enable, $start, $end));
        $res = array("user_id" => $id, "user_pass" => $pass, "user_mail" => $mail, "user_phone" => $phone, "user_online" => $online, "user_enable" => $enable, "user_start_date" => dateFromSql($start), "user_end_date" => dateFromSql($end));
        echo json_encode($res);
    } else {
        if (isset($_POST['set_user'])) {
            $valid = array("user_id", "user_pass", "user_mail", "user_phone", "user_enable", "user_start_date", "user_end_date");
            $set_field = $set_value = array();
            // Only update what was modified
            foreach ($_POST as $key => $value) {
                if (in_array($key, $valid)) {
                    array_push($set_field, $key . "=?");
                    if ($key == "user_pass") {
                        if ($value == "") {
                            array_push($set_value, $value);
                        } else {
                            array_push($set_value, hashPass($value));
                        }