Пример #1
0
 public function save_reconciliation()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $account = $this->_uses[$this->modeltype];
     $data = $this->_data[$this->modeltype];
     $start_balance = $account->statement_balance;
     $new_balance = $data['statement_balance'];
     $new_page = $data['statement_page'];
     $new_date = fix_date($data['statement_date']);
     $total = 0;
     $flash = Flash::Instance();
     if (!isset($this->_data['transactions'])) {
         $flash->addError('You must select at least one transaction');
     } else {
         $transactions = $this->_data['transactions'];
         foreach ($transactions as $id => $on) {
             $trans = new CBTransaction();
             $trans->load($id);
             $total = bcadd($total, $trans->gross_value);
             $trans_store[] = $trans;
         }
         $db = DB::Instance();
         $db->StartTrans();
         if (bcadd($start_balance, $total) == $new_balance) {
             foreach ($trans_store as $transaction) {
                 $result = $transaction->update($transaction->id, array('statement_date', 'statement_page', 'status'), array($new_date, $new_page, 'R'));
                 if ($result === false) {
                     $flash->addError('Failed to update Transaction');
                     $db->FailTrans();
                 }
             }
             $result = $account->update($data['id'], array('statement_balance', 'statement_date', 'statement_page'), array($new_balance, $new_date, $new_page));
             if ($result !== false) {
                 $db->CompleteTrans();
                 $flash->addMessage('Transactions matched to statement');
                 sendTo($this->name, 'view', $this->_modules, array('id' => $data['id']));
             } else {
                 $flash->addError('Failed to update Account');
                 $db->FailTrans();
                 $db->CompleteTrans();
             }
         } else {
             $flash->addError('Selected transactions do not match to new statement balance');
         }
     }
     $this->_data['id'] = $data['id'];
     $this->refresh();
 }
Пример #2
0
 public function saveMovement()
 {
     $flash = Flash::Instance();
     $errors = array();
     $data = $this->_data['CBTransaction'];
     $trans = CBTransaction::moveMoney($data, $errors);
     if ($trans) {
         $flash->addMessage('Transfer completed');
         if (isset($this->_data['saveAnother'])) {
             $this->context['cb_account_id'] = $data['cb_account_id'];
             $this->saveAnother();
         }
         sendTo($this->name, 'index', $this->_modules);
     }
     $flash->addErrors($errors);
     $flash->addError('Error saving money transfer');
     $this->_data['cb_account_id'] = $data['cb_account_id'];
     $this->_data['to_account_id'] = $data['to_account_id'];
     $this->refresh();
 }
Пример #3
0
 public function savePayments()
 {
     $flash = Flash::Instance();
     $errors = array();
     $data = $this->_data['PeriodicPayment'];
     $db = DB::Instance();
     $db->StartTrans();
     foreach ($data as $id => $set) {
         if (isset($set['pay']) || isset($set['skip'])) {
             $pp = new PeriodicPayment();
             $pp->load($id);
             if (isset($set['pay'])) {
                 //	Create payment record array
                 $data = $pp->makePaymentTransaction();
                 $data['description'] = $set['description'];
                 $data['ext_reference'] = $set['ext_reference'];
                 if (isset($set['next_due_date'])) {
                     $data['transaction_date'] = $set['next_due_date'];
                 }
                 if (isset($set['net_value'])) {
                     $data['net_value'] = $set['net_value'];
                     $data['tax_value'] = $set['tax_value'];
                     $data['value'] = bcadd($data['net_value'], $data['tax_value']);
                 }
                 if (isset($set['gross_value'])) {
                     $data['tax_value'] = 0.0;
                     $data['net_value'] = $data['value'] = $set['gross_value'];
                 }
                 if ($pp->source == 'CR' || $pp->source == 'CP') {
                     if ($pp->source == 'CP') {
                         $data['net_value'] = bcmul($data['net_value'], -1);
                         $data['tax_value'] = bcmul($data['tax_value'], -1);
                         $data['value'] = bcmul($data['value'], -1);
                     }
                     CBTransaction::saveCashPayment($data, $errors);
                 } else {
                     if ($pp->source == 'PP') {
                         $payment = new PLTransaction();
                     } else {
                         $payment = new SLTransaction();
                     }
                     $payment->saveTransaction($data, $errors);
                 }
                 //	Update Periodic Payment record
                 $pp->current++;
                 if (!is_null($pp->end_date) && $pp->next_due_date > $pp->end_date) {
                     $pp->status = 'S';
                 }
                 if (!is_null($pp->occurs) && $pp->current >= $pp->occurs) {
                     $pp->status = 'S';
                 }
                 if ($pp->variable == 't' && $pp->write_variance == 't') {
                     $pp->net_value = $data['net_value'];
                     $pp->tax_value = $data['tax_value'];
                     $pp->gross_value = $data['value'];
                 }
                 if ($pp->status == 'S') {
                     $pp->glaccount_centre_id = null;
                 } else {
                     $pp->glaccount_centre_id = GLAccountCentre::getAccountCentreId($pp->glaccount_id, $pp->glcentre_id, $errors);
                 }
             }
             // Update the date if skipping or paying
             $pp->nextDate();
             if (count($errors) > 0 || !$pp->save()) {
                 $errors[] = 'Failed to update Periodic Payment details';
                 break;
             }
         }
     }
     if (count($errors) == 0 && $db->completeTrans()) {
         $flash->addMessage('Payments processed OK');
         sendTo($_SESSION['refererPage']['controller'], $_SESSION['refererPage']['action'], $_SESSION['refererPage']['modules'], isset($_SESSION['refererPage']['other']) ? $_SESSION['refererPage']['other'] : null);
     } else {
         $db->FailTrans();
         $db->completeTrans();
         $flash->addErrors($errors);
         $flash->addError('Failed to make payments');
         $this->refresh();
     }
 }
Пример #4
0
 public function saveCBTransaction(&$data, &$errors)
 {
     //	Need to write cash transactions to cashbook
     if ($data['transaction_type'] == 'P' || $data['transaction_type'] == 'RP' || $data['transaction_type'] == 'R' || $data['transaction_type'] == 'RR') {
         $db = DB::Instance();
         $db->StartTrans();
         $data['company_id'] = $this->getOwner()->company_id;
         if (isset($data['cb_account_id'])) {
             $bank_account = DataObjectFactory::Factory('CBAccount');
             $bank_account->load($data['cb_account_id']);
             $data['glaccount_id'] = $bank_account->glaccount_id;
             $data['glcentre_id'] = $bank_account->glcentre_id;
         }
         $data['net_value'] = $data['transaction_type'] == 'R' || $data['transaction_type'] == 'RR' ? $data['net_value'] * -1 : $data['net_value'];
         $data['type'] = $data['transaction_type'];
         if (!CBTransaction::savePayment($data, $errors)) {
             $errors[] = 'Error saving Cashbook entry';
             $db->FailTrans();
         }
         $this->our_reference = $data['our_reference'] = $data['reference'];
         if (isset($data['description']) && !isset($data['comment'])) {
             $this->comment = $data['comment'] = $data['description'];
         }
         return $db->CompleteTrans();
     }
     return true;
 }