Пример #1
0
 public function action_taxpaymentupdate()
 {
     $tax_id = $this->request->post('tax_id');
     $payment_account_id = $this->request->post('payment_account_id');
     $writeoff_account_id = $this->request->post('writeoff_account_id');
     $date = $this->request->post('date') ? $this->request->post('date') : date("Y-m-d");
     $date_start = $this->request->post('date_start');
     $date_end = $this->request->post('date_end');
     $amount = $this->request->post('amount');
     $writeoff_amount = $this->request->post('writeoff_amount');
     $check_number = $this->request->post('check_number');
     $payment_id = $this->request->post('payment_id');
     // This is the payment we end up creating.
     $payment = FALSE;
     if ($this->request->post('replace_transaction_id') and $this->request->post('replace_transaction_id') != "new") {
         $tax_payment_replace_data = (object) array('transaction_id' => $this->request->post('replace_transaction_id'), 'tax_id' => $tax_id, 'date' => $date, 'check_number' => $check_number, 'date_start' => $date_start, 'date_end' => $date_end, 'amount' => $amount, 'payment_account_id' => $payment_account_id, 'writeoff_account_id' => $writeoff_account_id, 'writeoff_amount' => $writeoff_amount);
         $tax_payment_replace_data->validate_only = TRUE;
         $tax_payment_validate = new Beans_Tax_Payment_Replace($this->_beans_data_auth($tax_payment_replace_data));
         $tax_payment_validate_result = $tax_payment_validate->execute();
         if (!$tax_payment_validate_result->success) {
             return $this->_return_error($this->_beans_result_get_error($tax_payment_validate_result));
         }
         // DELETE
         $tax_payment_cancel = new Beans_Tax_Payment_Delete($this->_beans_data_auth((object) array('id' => $payment_id)));
         $tax_payment_cancel_result = $tax_payment_cancel->execute();
         if (!$tax_payment_cancel_result->success) {
             return $this->_return_error($this->_beans_result_get_error($tax_payment_cancel_result));
         }
         // REPLACE
         $tax_payment_replace_data->validate_only = FALSE;
         $tax_payment_replace = new Beans_Tax_Payment_Replace($this->_beans_data_auth($tax_payment_replace_data));
         $tax_payment_replace_result = $tax_payment_replace->execute();
         if (!$tax_payment_replace_result->success) {
             return $this->_return_error($this->_beans_result_get_error($tax_payment_replace_result));
         }
         $payment = $tax_payment_replace_result->data->payment;
     } else {
         // Check for duplicates
         if ($this->request->post('replace_transaction_id') != "new") {
             if (!$payment_account_id) {
                 return $this->_return_error("Please select a payment account.");
             }
             $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $payment_account_id)));
             $account_lookup_result = $account_lookup->execute();
             if (!$account_lookup_result->success) {
                 return $this->_return_error("An unexpected error has occurred.<br>" . $this->_beans_result_get_error($account_lookup_result));
             }
             // Check for duplicate transactions.
             $account_transaction_match = new Beans_Account_Transaction_Match($this->_beans_data_auth((object) array('date_range_days' => 7, 'ignore_payments' => TRUE, 'account_transactions' => array((object) array('account_id' => $payment_account_id, 'hash' => 'taxpayment', 'amount' => $amount * $account_lookup_result->data->account->type->table_sign, 'date' => $date)))));
             $account_transaction_match_result = $account_transaction_match->execute();
             if (!$account_transaction_match_result->success) {
                 return $this->_return_error("An error occurred when checking for duplicate transactions:<br>" . $this->_beans_result_get_error($account_transaction_match_result));
             }
             // There should only be one result to this - and it should match, etc.
             if ($account_transaction_match_result->data->account_transactions[0]->duplicate) {
                 // Duplicate transaction detected.
                 $this->_return_object->data->duplicate_transaction = $account_transaction_match_result->data->account_transactions[0]->transaction;
                 $error_message = "It looks like that might be a duplicate transaction that is already recorded in the system.<br><br>";
                 $error_message .= "Is this transaction the same as the payment you are trying to record?<br><br>";
                 $error_message .= "Transaction ID: " . $account_transaction_match_result->data->account_transactions[0]->transaction->id . "<br>";
                 $error_message .= "Description: " . $account_transaction_match_result->data->account_transactions[0]->transaction->description . "<br>";
                 $error_message .= "Date: " . $account_transaction_match_result->data->account_transactions[0]->transaction->date . "<br>";
                 $error_message .= "Amount: \$" . number_format($account_transaction_match_result->data->account_transactions[0]->transaction->amount, 2, '.', ',') . "<br>";
                 $error_message .= "<br>You can either add your payment info to this transaction if this is the same, or create a brand new transaction record in the journal.";
                 return $this->_return_error($error_message);
             }
         }
         $tax_payment_update = new Beans_Tax_Payment_Update($this->_beans_data_auth((object) array('id' => $payment_id, 'tax_id' => $tax_id, 'date' => $date, 'date_start' => $date_start, 'date_end' => $date_end, 'amount' => $amount, 'check_number' => $check_number, 'payment_account_id' => $payment_account_id, 'writeoff_account_id' => $writeoff_account_id, 'writeoff_amount' => $writeoff_amount)));
         $tax_payment_update_result = $tax_payment_update->execute();
         if (!$tax_payment_update_result->success) {
             return $this->_return_error($this->_beans_result_get_error($tax_payment_update_result));
         }
         $payment = $tax_payment_update_result->data->payment;
     }
     $this->_print_check_queue_taxpayment_remove($payment_id);
     if ($this->request->post("print_check") and $this->request->post("print_check") == "1") {
         $this->_print_check_queue_taxpayment_add($payment->id);
     }
     $html = new View_Partials_Taxes_Payments_Payment();
     $html->payment = $payment;
     $payment->html = $html->render();
     $this->_return_object->data->payment = $payment;
 }
Пример #2
0
 public function action_reconcile()
 {
     $account_id = $this->request->param('id');
     $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $account_id)));
     $account_lookup_result = $account_lookup->execute();
     if ($this->_beans_result_check($account_lookup_result)) {
         $this->_action_tab_name = $account_lookup_result->data->account->name;
         $this->_view->force_current_uri = '/accounts/view/' . $account_id;
         if (!$account_lookup_result->data->account->reconcilable) {
             $this->_view->send_error_message("This account cannot be reconciled.");
         } else {
             $this->_view->account_lookup_result = $account_lookup_result;
             // Look up last reconcile...
             $account_reconcile = new Beans_Account_Reconcile_Search($this->_beans_data_auth((object) array('account_id' => $account_lookup_result->data->account->id, 'page' => 0, 'page_size' => 1, 'sort_by' => 'newest')));
             $account_reconcile_result = $account_reconcile->execute();
             if ($this->_beans_result_check($account_reconcile_result)) {
                 $this->_view->account_reconcile_result = $account_reconcile_result;
             }
             $account_transactions = new Beans_Account_Transaction_Search($this->_beans_data_auth((object) array('account_id' => $account_lookup_result->data->account->id, 'page_size' => 50000, 'page' => 0, 'reconciled' => FALSE, 'sort_by' => 'oldest')));
             $account_transactions_result = $account_transactions->execute();
             if ($this->_beans_result_check($account_transactions_result)) {
                 $this->_view->account_transactions_result = $account_transactions_result;
             }
         }
         $this->_action_tab_name = $account_lookup_result->data->account->name;
         $this->_action_tab_uri = '/accounts/view/' . $account_lookup_result->data->account->id;
     }
 }
Пример #3
0
 public function action_paymentupdate()
 {
     $payment_id = $this->request->post('payment_id');
     $sales = array();
     foreach ($this->request->post() as $key => $value) {
         if ($value == "sale-key") {
             $sales[] = (object) array('sale_id' => $key, 'amount' => $this->request->post('sale-amount-' . $key), 'writeoff_balance' => $this->request->post('sale-balance-writeoff-' . $key) ? TRUE : FALSE, 'writeoff_amount' => $this->request->post('sale-balance-writeoff-' . $key));
         }
     }
     // This is the payment we end up creating.
     $payment = FALSE;
     if ($this->request->post('replace_transaction_id') and $this->request->post('replace_transaction_id') != "new") {
         $customer_payment_replace_data = (object) array('transaction_id' => $this->request->post('replace_transaction_id'), 'date' => $this->request->post('date') ? $this->request->post('date') : date("Y-m-d"), 'amount' => $this->request->post('amount'), 'adjustment_amount' => $this->request->post('adjustment_amount'), 'deposit_account_id' => $this->request->post('deposit_account_id'), 'writeoff_account_id' => $this->request->post('writeoff_account_id'), 'adjustment_account_id' => $this->request->post('adjustment_account_id'), 'sales' => $sales);
         // REPLACE
         $customer_payment_replace_data->validate_only = FALSE;
         $customer_payment_replace = new Beans_Customer_Payment_Replace($this->_beans_data_auth($customer_payment_replace_data));
         $customer_payment_replace_result = $customer_payment_replace->execute();
         if (!$customer_payment_replace_result->success) {
             return $this->_return_error($this->_beans_result_get_error($customer_payment_replace_result));
         }
         $payment = $customer_payment_replace_result->data->payment;
     } else {
         // Check for duplicates
         if ($this->request->post('replace_transaction_id') != "new") {
             if (!$this->request->post('deposit_account_id')) {
                 return $this->_return_error("Please select a deposit account.");
             }
             $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $this->request->post('deposit_account_id'))));
             $account_lookup_result = $account_lookup->execute();
             if (!$account_lookup_result->success) {
                 return $this->_return_error("An unexpected error has occurred.<br>" . $this->_beans_result_get_error($account_lookup_result));
             }
             // Check for duplicate transactions.
             $account_transaction_match = new Beans_Account_Transaction_Match($this->_beans_data_auth((object) array('date_range_days' => 7, 'ignore_payments' => TRUE, 'account_transactions' => array((object) array('account_id' => $this->request->post('deposit_account_id'), 'hash' => 'checkpayment', 'amount' => $this->request->post('amount') * $account_lookup_result->data->account->type->table_sign, 'date' => $this->request->post('date') ? $this->request->post('date') : date("Y-m-d"))))));
             $account_transaction_match_result = $account_transaction_match->execute();
             if (!$account_transaction_match_result->success) {
                 return $this->_return_error("An error occurred when checking for duplicate transactions:<br>" . $this->_beans_result_get_error($account_transaction_match_result));
             }
             // There should only be one result to this - and it should match, etc.
             if ($account_transaction_match_result->data->account_transactions[0]->duplicate and $account_transaction_match_result->data->account_transactions[0]->transaction->id != $payment_id) {
                 // Duplicate transaction detected.
                 $this->_return_object->data->duplicate_transaction = $account_transaction_match_result->data->account_transactions[0]->transaction;
                 $error_message = "It looks like that might be a duplicate transaction that is already recorded in the system.<br><br>";
                 $error_message .= "Is this transaction the same as the payment you are trying to record?<br><br>";
                 $error_message .= "Transaction ID: " . $account_transaction_match_result->data->account_transactions[0]->transaction->id . "<br>";
                 $error_message .= "Description: " . $account_transaction_match_result->data->account_transactions[0]->transaction->description . "<br>";
                 $error_message .= "Date: " . $account_transaction_match_result->data->account_transactions[0]->transaction->date . "<br>";
                 $error_message .= "Amount: \$" . number_format($account_transaction_match_result->data->account_transactions[0]->transaction->amount, 2, '.', ',') . "<br>";
                 $error_message .= "<br>You can either add your payment info to this transaction if this is the same, or create a brand new transaction record in the journal.";
                 return $this->_return_error($error_message);
             }
         }
         $customer_payment_update = new Beans_Customer_Payment_Update($this->_beans_data_auth((object) array('id' => $payment_id, 'date' => $this->request->post('date') ? $this->request->post('date') : date("Y-m-d"), 'amount' => $this->request->post('amount'), 'adjustment_amount' => $this->request->post('adjustment_amount'), 'deposit_account_id' => $this->request->post('deposit_account_id'), 'writeoff_account_id' => $this->request->post('writeoff_account_id'), 'adjustment_account_id' => $this->request->post('adjustment_account_id'), 'sales' => $sales)));
         $customer_payment_update_result = $customer_payment_update->execute();
         if (!$customer_payment_update_result->success) {
             return $this->_return_error($this->_beans_result_get_error($customer_payment_update_result));
         }
         $payment = $customer_payment_update_result->data->payment;
     }
     $html = new View_Partials_Customers_Payments_Payment();
     $html->payment = $payment;
     $payment->html = $html->render();
     $this->_return_object->data->payment = $payment;
 }
Пример #4
0
 public function action_transactionupdate()
 {
     $transaction_id = $this->request->post("transaction-id");
     $split_keys = array();
     foreach ($this->request->post() as $key => $value) {
         if (strpos($key, 'transaction-split-transfer') !== FALSE and $value) {
             $split_keys[] = str_replace('transaction-split-transfer-', '', $key);
         }
     }
     $new_transaction = new stdClass();
     $new_transaction->date = $this->request->post('transaction-date') ? date("Y-m-d", strtotime($this->request->post('transaction-date'))) : date("Y-m-d");
     $new_transaction->code = $this->request->post('transaction-number');
     $new_transaction->description = $this->request->post('transaction-description');
     $new_transaction->account_transactions = array();
     $new_transaction->account_transactions[] = (object) array('account_id' => $this->request->post('transaction-account-id'), 'amount' => $this->_get_numeric_value($this->request->post('transaction-credit')) ? $this->_get_numeric_value($this->request->post('transaction-credit')) * $this->request->post('transaction-account-table_sign') : $this->_get_numeric_value($this->request->post('transaction-debit')) * -1 * $this->request->post('transaction-account-table_sign'));
     if ($this->request->post('transaction-transfer')) {
         $new_transaction->account_transactions[] = (object) array('account_id' => $this->request->post('transaction-transfer'), 'amount' => $new_transaction->account_transactions[0]->amount * -1);
     } else {
         // Loop all split transactions and go for it.
         foreach ($split_keys as $split_key) {
             if ($this->request->post('transaction-split-transfer-' . $split_key) and ($this->request->post('transaction-split-credit-' . $split_key) or $this->request->post('transaction-split-debit-' . $split_key))) {
                 $new_transaction->account_transactions[] = (object) array('account_id' => $this->request->post('transaction-split-transfer-' . $split_key), 'amount' => $this->request->post('transaction-split-credit-' . $split_key) ? $this->request->post('transaction-split-credit-' . $split_key) * $this->request->post('transaction-account-table_sign') : $this->request->post('transaction-split-debit-' . $split_key) * -1 * $this->request->post('transaction-account-table_sign'));
             }
         }
     }
     if (count($new_transaction->account_transactions) == 1) {
         return $this->_return_error("Please either select a transfer account or create a split.");
     }
     $new_transaction->id = $transaction_id;
     $account_transaction_update = new Beans_Account_Transaction_Update($this->_beans_data_auth($new_transaction));
     $account_transaction_update_result = $account_transaction_update->execute();
     if (!$account_transaction_update_result->success) {
         return $this->_return_error($this->_beans_result_get_error($account_transaction_update_result));
     }
     $account_lookup = new Beans_Account_Lookup($this->_beans_data_auth((object) array('id' => $this->request->post('transaction-account-id'))));
     $account_lookup_result = $account_lookup->execute();
     $html = new View_Partials_Accounts_View_Transaction();
     $html->setup_company_list_result = $this->_setup_company_list_result;
     $html->account_lookup_result = $account_lookup_result;
     $html->transaction = $account_transaction_update_result->data->transaction;
     $html->account_id = $this->request->post('transaction-account-id');
     $this->_return_object->data->transaction = $account_transaction_update_result->data->transaction;
     $this->_return_object->data->transaction->html = $html->render();
 }