示例#1
0
 public function toList($tree, $c = 0)
 {
     $counter = $c;
     if ($tree->id != 0) {
         $this->groupList[$tree->id] = $this->space($counter) . h(toCodeWithName($tree->code, $tree->name));
     }
     /* Process child groups recursively */
     foreach ($tree->children_groups as $id => $data) {
         $counter++;
         $this->toList($data, $counter);
         $counter--;
     }
 }
示例#2
0
 public function toList($tree, $c = 0)
 {
     /* Add group name to list */
     if ($tree->id != 0) {
         /* Set the group id to negative value since we want to disable it */
         $this->ledgerList[-$tree->id] = $this->space($c) . h(toCodeWithName($tree->code, $tree->name));
     } else {
         $this->ledgerList[0] = __d('webzash', $this->default_text);
     }
     /* Add child ledgers */
     if (count($tree->children_ledgers) > 0) {
         $c++;
         foreach ($tree->children_ledgers as $id => $data) {
             $ledger_name = h(toCodeWithName($data['code'], $data['name']));
             /* Add ledgers as per restrictions */
             if ($this->restriction_bankcash == 1 || $this->restriction_bankcash == 2 || $this->restriction_bankcash == 3) {
                 /* All ledgers */
                 $this->ledgerList[$data['id']] = $this->space($c) . $ledger_name;
             } else {
                 if ($this->restriction_bankcash == 4) {
                     /* Only bank or cash ledgers */
                     if ($data['type'] == 1) {
                         $this->ledgerList[$data['id']] = $this->space($c) . $ledger_name;
                     }
                 } else {
                     if ($this->restriction_bankcash == 5) {
                         /* Only NON bank or cash ledgers */
                         if ($data['type'] == 0) {
                             $this->ledgerList[$data['id']] = $this->space($c) . $ledger_name;
                         }
                     }
                 }
             }
         }
         $c--;
     }
     /* Process child groups recursively */
     foreach ($tree->children_groups as $id => $data) {
         $c++;
         $this->toList($data, $c);
         $c--;
     }
 }
示例#3
0
 public function getName($id)
 {
     $ledger = $this->findById($id);
     if ($ledger) {
         return toCodeWithName($ledger['Ledger']['code'], $ledger['Ledger']['name']);
     } else {
         return __d('webzash', 'ERROR');
     }
 }
示例#4
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;
 }
示例#5
0
 /**
  * index method
  *
  * @return void
  */
 public function index()
 {
     $this->set('title_for_layout', __d('webzash', 'Account Dashboard'));
     /**** Start initial check if all tables are present ****/
     try {
         $this->Group->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Groups table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     try {
         $this->Ledger->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Ledgers table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     try {
         $this->Entry->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Entries table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     try {
         $this->Entryitem->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Entryitems table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     try {
         $this->Tag->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Tags table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     try {
         $this->Log->find('first');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Logs table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     /* End intial check */
     /* Cash and bank sumary */
     $ledgers = '';
     try {
         $ledgers = $this->Ledger->find('all', array('order' => array('Ledger.name'), 'conditions' => array('Ledger.type' => 1)));
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Ledgers table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     $ledgersCB = array();
     foreach ($ledgers as $ledger) {
         $ledgersCB[] = array('name' => h(toCodeWithName($ledger['Ledger']['code'], $ledger['Ledger']['name'])), 'balance' => $this->Ledger->closingBalance($ledger['Ledger']['id']));
     }
     $this->set('ledgers', $ledgersCB);
     /* Account summary */
     $assets = new AccountList();
     $assets->Group =& $this->Group;
     $assets->Ledger =& $this->Ledger;
     $assets->only_opening = false;
     $assets->start_date = null;
     $assets->end_date = null;
     $assets->affects_gross = -1;
     $assets->start(1);
     $liabilities = new AccountList();
     $liabilities->Group =& $this->Group;
     $liabilities->Ledger =& $this->Ledger;
     $liabilities->only_opening = false;
     $liabilities->start_date = null;
     $liabilities->end_date = null;
     $liabilities->affects_gross = -1;
     $liabilities->start(2);
     $income = new AccountList();
     $income->Group =& $this->Group;
     $income->Ledger =& $this->Ledger;
     $income->only_opening = false;
     $income->start_date = null;
     $income->end_date = null;
     $income->affects_gross = -1;
     $income->start(3);
     $expense = new AccountList();
     $expense->Group =& $this->Group;
     $expense->Ledger =& $this->Ledger;
     $expense->only_opening = false;
     $expense->start_date = null;
     $expense->end_date = null;
     $expense->affects_gross = -1;
     $expense->start(4);
     $accsummary = array('assets_total_dc' => $assets->cl_total_dc, 'assets_total' => $assets->cl_total, 'liabilities_total_dc' => $liabilities->cl_total_dc, 'liabilities_total' => $liabilities->cl_total, 'income_total_dc' => $income->cl_total_dc, 'income_total' => $income->cl_total, 'expense_total_dc' => $expense->cl_total_dc, 'expense_total' => $expense->cl_total);
     $this->set('accsummary', $accsummary);
     $logs = $this->Log->find('all', array('limit' => 17, 'order' => array('Log.date DESC')));
     $this->set('logs', $logs);
     return;
 }