示例#1
0
 public function savejournal()
 {
     $flash = Flash::Instance();
     $errors = array();
     if (!$this->checkParams('Vat')) {
         sendBack();
     }
     $data = $this->_data['Vat'];
     if ($data['value']['net'] <= 0 || $data['value']['vat'] <= 0) {
         $errors[] = 'Net and Vat values must be greater than zero';
     } else {
         $glparams = DataObjectFactory::Factory('GLParams');
         $vat_type = 'vat_' . $data['vat_type'];
         $data['vat_account'] = call_user_func(array($glparams, $vat_type));
         if ($data['vat_type'] == 'input') {
             $data['value']['net'] = bcmul($data['value']['net'], -1);
             $data['value']['vat'] = bcmul($data['value']['vat'], -1);
         }
         $data['transaction_date'] = date(DATE_FORMAT);
         $gltransactions = GLTransaction::makeFromVATJournalEntry($data, $errors);
         if (count($errors) == 0 && GLTransaction::saveTransactions($gltransactions, $errors)) {
             $flash->addMessage('VAT Journal created OK');
             sendTo($this->name, '', $this->_modules);
         }
     }
     $flash->addErrors($errors);
     $this->_data['vat_type'] = $data['vat_type'];
     $this->_data['glaccount_id'] = $data['glaccount_id'];
     $this->refresh();
 }