/** * ledgerentries method * * @return void */ public function ledgerentries() { $this->set('title_for_layout', __d('webzash', 'Ledger Entries')); /* Create list of ledgers to pass to view */ $ledgers = new LedgerTree(); $ledgers->Group =& $this->Group; $ledgers->Ledger =& $this->Ledger; $ledgers->current_id = -1; $ledgers->restriction_bankcash = 1; $ledgers->build(0); $ledgers->toList($ledgers, -1); $ledgers_disabled = array(); foreach ($ledgers->ledgerList as $row => $data) { if ($row < 0) { $ledgers_disabled[] = $row; } } $this->set('ledgers', $ledgers->ledgerList); $this->set('ledgers_disabled', $ledgers_disabled); if ($this->request->is('post')) { /* 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' => 'ledgerentries')); } if (!empty($this->request->data['Report']['startdate']) || !empty($this->request->data['Report']['enddate'])) { return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'ledgerentries', 'ledgerid' => $this->request->data['Report']['ledger_id'], 'options' => 1, 'startdate' => $this->request->data['Report']['startdate'], 'enddate' => $this->request->data['Report']['enddate'])); } else { return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'ledgerentries', 'ledgerid' => $this->request->data['Report']['ledger_id'])); } } $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' => 'ledgerentries')); } $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', 'Ledger entries 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['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', 'Ledger entries 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', 'Ledger entries 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', 'Ledger entries for %s from %s to %s', h($ledger['Ledger']['name']), dateFromSql(Configure::read('Account.startdate')), dateFromSql(dateToSQL($this->passedArgs['enddate'])))); } } } } /* 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))); } /* 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); /* 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/ledgerentries'); $this->response->body($response); $this->response->type('text/csv'); $this->response->download('ledgerentries.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/ledgerentries'); $this->response->body($response); $this->response->type('application/vnd.ms-excel'); $this->response->download('ledgerentries.xls'); return $this->response; } /* Print report */ if (isset($this->passedArgs['print'])) { $this->layout = 'print'; $view = new View($this, false); $response = $view->render('Reports/print/ledgerentries'); $this->response->body($response); return $this->response; } return; }
/** * Add a row in the entry via ajax * * @param string $addType * @return void */ function addrow($restriction_bankcash) { $this->layout = null; /* Ledger selection */ $ledgers = new LedgerTree(); $ledgers->Group =& $this->Group; $ledgers->Ledger =& $this->Ledger; $ledgers->current_id = -1; $ledgers->restriction_bankcash = $restriction_bankcash; $ledgers->build(0); $ledgers->toList($ledgers, -1); $ledgers_disabled = array(); $this->set('ledger_options', $ledgers->ledgerList); }
/** * index method * * @return void */ public function index() { $this->set('title_for_layout', __d('webzash', 'Search')); $this->set('showEntries', false); /* Ledger selection */ $ledgers = new LedgerTree(); $ledgers->Group =& $this->Group; $ledgers->Ledger =& $this->Ledger; $ledgers->current_id = -1; $ledgers->restriction_bankcash = 1; $ledgers->default_text = '(ALL)'; $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); /* Entrytypes */ $entrytype_options = array(); $entrytype_options[0] = '(ALL)'; $rawentrytypes = $this->Entrytype->find('all', array('order' => 'Entrytype.id')); foreach ($rawentrytypes as $row => $rawentrytype) { $entrytype_options[$rawentrytype['Entrytype']['id']] = h($rawentrytype['Entrytype']['name']); } $this->set('entrytype_options', $entrytype_options); /* Tags */ $tag_options = array(); $tag_options[0] = '(ALL)'; $rawtags = $this->Tag->find('all', array('order' => 'Tag.title')); foreach ($rawtags as $row => $rawtag) { $tag_options[$rawtag['Tag']['id']] = h($rawtag['Tag']['title']); } $this->set('tag_options', $tag_options); if ($this->request->is('post') || $this->request->is('put')) { $ledger_ids = ''; if (empty($this->request->data['Search']['ledger_ids'])) { $ledger_ids = '0'; } else { if (in_array('0', $this->request->data['Search']['ledger_ids'])) { $ledger_ids = '0'; } else { $ledger_ids = implode(',', $this->request->data['Search']['ledger_ids']); } } $entrytype_ids = ''; if (empty($this->request->data['Search']['entrytype_ids'])) { $entrytype_ids = '0'; } else { if (in_array('0', $this->request->data['Search']['entrytype_ids'])) { $entrytype_ids = '0'; } else { $entrytype_ids = implode(',', $this->request->data['Search']['entrytype_ids']); } } $tag_ids = ''; if (empty($this->request->data['Search']['tag_ids'])) { $tag_ids = '0'; } else { if (in_array('0', $this->request->data['Search']['tag_ids'])) { $tag_ids = '0'; } else { $tag_ids = implode(',', $this->request->data['Search']['tag_ids']); } } return $this->redirect(array('plugin' => 'webzash', 'controller' => 'search', 'action' => 'index', 'search' => 1, 'ledger_ids' => $ledger_ids, 'entrytype_ids' => $entrytype_ids, 'entrynumber_restriction' => $this->request->data['Search']['entrynumber_restriction'], 'entrynumber1' => $this->request->data['Search']['entrynumber1'], 'entrynumber2' => $this->request->data['Search']['entrynumber2'], 'amount_dc' => $this->request->data['Search']['amount_dc'], 'amount_restriction' => $this->request->data['Search']['amount_restriction'], 'amount1' => $this->request->data['Search']['amount1'], 'amount2' => $this->request->data['Search']['amount2'], 'fromdate' => $this->request->data['Search']['fromdate'], 'todate' => $this->request->data['Search']['todate'], 'tag_ids' => $tag_ids, 'narration' => $this->request->data['Search']['narration'])); } /* Check if search is active */ if (empty($this->passedArgs['search']) || $this->passedArgs['search'] != 1) { return; } /* Initialize data from passedArgs */ $this->request->data['Search']['ledger_ids'] = explode(',', $this->passedArgs['ledger_ids']); $this->request->data['Search']['entrytype_ids'] = explode(',', $this->passedArgs['entrytype_ids']); $this->request->data['Search']['entrynumber_restriction'] = $this->passedArgs['entrynumber_restriction']; $this->request->data['Search']['entrynumber1'] = $this->passedArgs['entrynumber1']; $this->request->data['Search']['entrynumber2'] = $this->passedArgs['entrynumber2']; $this->request->data['Search']['amount_dc'] = $this->passedArgs['amount_dc']; $this->request->data['Search']['amount_restriction'] = $this->passedArgs['amount_restriction']; $this->request->data['Search']['amount1'] = $this->passedArgs['amount1']; $this->request->data['Search']['amount2'] = $this->passedArgs['amount2']; $this->request->data['Search']['fromdate'] = $this->passedArgs['fromdate']; $this->request->data['Search']['todate'] = $this->passedArgs['todate']; $this->request->data['Search']['tag_ids'] = explode(',', $this->passedArgs['tag_ids']); $this->request->data['Search']['narration'] = $this->passedArgs['narration']; /* Setup search conditions */ $conditions = array(); if (!empty($this->passedArgs['ledger_ids'])) { if (!in_array('0', $this->request->data['Search']['ledger_ids'])) { $conditions['Entryitem.ledger_id'] = $this->request->data['Search']['ledger_ids']; } } if (!empty($this->passedArgs['entrytype_ids'])) { if (!in_array('0', $this->request->data['Search']['entrytype_ids'])) { $conditions['Entry.entrytype_id'] = $this->request->data['Search']['entrytype_ids']; } } if (!empty($this->passedArgs['entrynumber1'])) { if ($this->passedArgs['entrynumber_restriction'] == 1) { /* Equal to */ $conditions['Entry.number'] = $this->passedArgs['entrynumber1']; } else { if ($this->passedArgs['entrynumber_restriction'] == 2) { /* Less than or equal to */ $conditions['Entry.number <='] = $this->passedArgs['entrynumber1']; } else { if ($this->passedArgs['entrynumber_restriction'] == 3) { /* Greater than or equal to */ $conditions['Entry.number >='] = $this->passedArgs['entrynumber1']; } else { if ($this->passedArgs['entrynumber_restriction'] == 4) { /* In between */ if (!empty($this->passedArgs['entrynumber2'])) { $conditions['Entry.number >='] = $this->passedArgs['entrynumber1']; $conditions['Entry.number <='] = $this->passedArgs['entrynumber2']; } else { $conditions['Entry.number >='] = $this->passedArgs['entrynumber1']; } } } } } } if ($this->passedArgs['amount_dc'] == 'D') { /* Dr */ $conditions['Entryitem.dc'] = 'D'; } else { if ($this->passedArgs['amount_dc'] == 'C') { /* Cr */ $conditions['Entryitem.dc'] = 'C'; } } if (!empty($this->passedArgs['amount1'])) { if ($this->passedArgs['amount_restriction'] == 1) { /* Equal to */ $conditions['Entryitem.amount'] = $this->passedArgs['amount1']; } else { if ($this->passedArgs['amount_restriction'] == 2) { /* Less than or equal to */ $conditions['Entryitem.amount <='] = $this->passedArgs['amount1']; } else { if ($this->passedArgs['amount_restriction'] == 3) { /* Greater than or equal to */ $conditions['Entryitem.amount >='] = $this->passedArgs['amount1']; } else { if ($this->passedArgs['amount_restriction'] == 4) { /* In between */ if (!empty($this->passedArgs['amount2'])) { $conditions['Entryitem.amount >='] = $this->passedArgs['amount1']; $conditions['Entryitem.amount <='] = $this->passedArgs['amount2']; } else { $conditions['Entryitem.amount >='] = $this->passedArgs['amount1']; } } } } } } if (!empty($this->passedArgs['fromdate'])) { /* TODO : Validate date */ $fromdate = dateToSql($this->passedArgs['fromdate']); $conditions['Entry.date >='] = $fromdate; } if (!empty($this->passedArgs['todate'])) { /* TODO : Validate date */ $todate = dateToSql($this->passedArgs['todate']); $conditions['Entry.date <='] = $todate; } if (!empty($this->passedArgs['tag_ids'])) { if (!in_array('0', $this->request->data['Search']['tag_ids'])) { $conditions['Entry.tag_id'] = $this->request->data['Search']['tag_ids']; } } if (!empty($this->passedArgs['narration'])) { $conditions['Entry.narration LIKE'] = '%' . $this->passedArgs['narration'] . '%'; } /* Pass varaibles to view which are used in Helpers */ $this->set('allTags', $this->Tag->fetchAll()); /* Setup pagination */ $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' => 'asc'), 'conditions' => $conditions, 'joins' => array(array('table' => 'entryitems', 'alias' => 'Entryitem', 'conditions' => array('Entry.id = Entryitem.entry_id'))))); $this->set('entries', $this->CustomPaginator->paginate('Entry')); $this->set('showEntries', true); return; }