Esempio n. 1
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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function action_import()
 {
     $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->_view->account_lookup_result = $account_lookup_result;
         $this->_action_tab_name = $account_lookup_result->data->account->name;
         $this->_view->force_current_uri = '/accounts/view/' . $account_id;
         $account_transactions = array();
         if (isset($_FILES['transactionsfile']) and $_FILES['transactionsfile']['error'] == UPLOAD_ERR_OK) {
             $extension = strtolower(substr($_FILES['transactionsfile']['name'], 1 + strrpos($_FILES['transactionsfile']['name'], '.')));
             if ($extension == "csv") {
                 $this->_view->transactionsfilestring = file_get_contents($_FILES['transactionsfile']['tmp_name']);
                 return;
             } else {
                 if ($extension == "qbo" or $extension == "qfx" or $extension == "ofx") {
                     try {
                         $account_table_sign = $account_lookup_result->data->account->type->table_sign;
                         $ofx = new SimpleXMLElement("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n" . $this->_fix_ofx(file_get_contents($_FILES['transactionsfile']['tmp_name'])));
                         $i = 0;
                         foreach ($ofx->BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKTRANLIST->STMTTRN as $transaction) {
                             $account_transactions[] = (object) array('account_id' => $account_id, 'hash' => $i++, 'amount' => $this->_get_numeric_value($transaction->TRNAMT) * $account_table_sign, 'description' => $transaction->NAME, 'date' => substr($transaction->DTPOSTED, 0, 4) . '-' . substr($transaction->DTPOSTED, 4, 2) . '-' . substr($transaction->DTPOSTED, 6, 2), 'number' => isset($transaction->CHECKNUM) ? $transaction->CHECKNUM : $transaction->TRNTYPE);
                         }
                         $account_transactions_match = new Beans_Account_Transaction_Match($this->_beans_data_auth((object) array('date_range_days' => 3, 'account_transactions' => $account_transactions)));
                         $account_transactions_match_result = $account_transactions_match->execute();
                         if ($this->_beans_result_check($account_transactions_match_result)) {
                             $this->_view->account_transactions = $account_transactions_match_result->data->account_transactions;
                         }
                         $this->_view->account_table_sign = $account_table_sign;
                         return;
                     } catch (Exception $e) {
                         return $this->_view->send_error_message("An error occurred when trying to read that file. " . $e->getMessage());
                     }
                 } else {
                     // Error - Unsupported format.
                     return $this->_view->send_error_message("Error - that file type is not supported.  Please upload a QBO, QFX, or CSV.");
                 }
             }
         }
         if ($this->request->post('transactionsfilestring')) {
             $date_index = $this->request->post('date_index');
             $description_index = $this->request->post('description_index');
             $number_index = $this->request->post('number_index');
             $amount_index = $this->request->post('amount_index');
             $account_table_sign = $this->request->post('account_table_sign');
             if ($date_index === NULL or $description_index === NULL or $number_index === NULL or $amount_index === NULL or $account_table_sign === NULL) {
                 return $this->_view->send_error_message("Error - missing required values.");
             } else {
                 // Create a bunch of transactions - search for matches - etc.
                 $transactionsfilelines = explode("\n", $this->request->post('transactionsfilestring'));
                 foreach ($transactionsfilelines as $i => $transactionfileline) {
                     if (strlen($transactionfileline) > 5) {
                         $line = explode(",", $transactionfileline);
                         if (substr($line[$description_index], 0, 1) == '"' and substr($line[$description_index], -1) == '"') {
                             $line = str_getcsv($transactionfileline, ',', '"');
                         }
                         $account_transactions[] = (object) array('account_id' => $account_id, 'hash' => $i, 'amount' => $line[$amount_index] * $account_table_sign, 'description' => $line[$description_index], 'date' => date("Y-m-d", strtotime($line[$date_index])), 'number' => $line[$number_index]);
                     }
                 }
                 $account_transactions_match = new Beans_Account_Transaction_Match($this->_beans_data_auth((object) array('date_range_days' => 3, 'account_transactions' => $account_transactions)));
                 $account_transactions_match_result = $account_transactions_match->execute();
                 if ($this->_beans_result_check($account_transactions_match_result)) {
                     $this->_view->account_transactions = $account_transactions_match_result->data->account_transactions;
                 }
                 $this->_view->account_table_sign = $account_table_sign;
             }
         }
         $this->_action_tab_name = $account_lookup_result->data->account->name;
         $this->_action_tab_uri = '/accounts/view/' . $account_lookup_result->data->account->id;
     }
 }