Ejemplo n.º 1
0
 public function action_taxpaymentprep()
 {
     $tax_id = $this->request->post('tax_id');
     $payment_id = $this->request->post('payment_id');
     $date_start = $this->request->post('date_start');
     $date_end = $this->request->post('date_end');
     $tax_prep = new Beans_Tax_Prep($this->_beans_data_auth((object) array('id' => $tax_id, 'payment_id' => $payment_id, 'date_start' => $date_start, 'date_end' => $date_end)));
     $tax_prep_result = $tax_prep->execute();
     if (!$tax_prep_result->success) {
         return $this->_return_error("An unexpected error has occurred:<br>" . $this->_beans_result_get_error($tax_prep_result));
     }
     $this->_return_object->data = $tax_prep_result->data;
 }
Ejemplo n.º 2
0
 public function action_taxes()
 {
     $tax_id = FALSE;
     $tax_payment_id = FALSE;
     if ($this->request->post('tax_id')) {
         $tax_id = $this->request->post('tax_id');
     }
     if ($this->request->post('tax_payment_id')) {
         $tax_payment_id = $this->request->post('tax_payment_id');
     }
     if ($tax_id) {
         $tax_payment_search_data = new stdClass();
         $tax_payment_search_data->sort_by = 'newest';
         $tax_payment_search_data->page_size = 24;
         $tax_payment_search_data->search_tax_id = $tax_id;
         $tax_payment_search = new Beans_Tax_Payment_Search($this->_beans_data_auth($tax_payment_search_data));
         $tax_payment_search_result = $tax_payment_search->execute();
         if ($this->_beans_result_check($tax_payment_search_result)) {
             $this->_view->tax_payments = $tax_payment_search_result->data->payments;
         }
     }
     if ($tax_id && $tax_payment_id) {
         if ($tax_payment_id == "prep") {
             $date_start = date("Y-m-d");
             $date_end = date("Y-m-d");
             $tax_prep = new Beans_Tax_Prep($this->_beans_data_auth((object) array('id' => $tax_id, 'date_start' => $date_start, 'date_end' => $date_end)));
             $tax_prep_result = $tax_prep->execute();
             if ($this->_beans_result_check($tax_prep_result)) {
                 $this->_view->payment = (object) array('id' => NULL, 'prep' => TRUE, 'tax' => $tax_prep_result->data->tax, 'amount' => NULL, 'writeoff_amount' => NULL, 'date' => NULL, 'date_start' => $tax_prep_result->data->date_start, 'date_end' => $tax_prep_result->data->date_end, 'check_number' => NULL, 'invoiced_line_amount' => $tax_prep_result->data->taxes->due->invoiced->form_line_amount, 'invoiced_line_taxable_amount' => $tax_prep_result->data->taxes->due->invoiced->form_line_taxable_amount, 'invoiced_amount' => $tax_prep_result->data->taxes->due->invoiced->amount, 'refunded_line_amount' => $tax_prep_result->data->taxes->due->refunded->form_line_amount, 'refunded_line_taxable_amount' => $tax_prep_result->data->taxes->due->refunded->form_line_taxable_amount, 'refunded_amount' => $tax_prep_result->data->taxes->due->refunded->amount, 'net_line_amount' => $tax_prep_result->data->taxes->due->net->form_line_amount, 'net_line_taxable_amount' => $tax_prep_result->data->taxes->due->net->form_line_taxable_amount, 'net_amount' => $tax_prep_result->data->taxes->due->net->amount, 'liabilities' => array_merge($tax_prep_result->data->taxes->due->invoiced->liabilities, $tax_prep_result->data->taxes->due->refunded->liabilities), 'amount' => NULL, 'writeoff_amount' => NULL);
             }
         } else {
             $tax_payment_lookup = new Beans_Tax_Payment_Lookup($this->_beans_data_auth((object) array('id' => $tax_payment_id)));
             $tax_payment_lookup_result = $tax_payment_lookup->execute();
             if ($this->_beans_result_check($tax_payment_lookup_result)) {
                 $this->_view->payment = $tax_payment_lookup_result->data->payment;
             }
         }
     }
     $this->_action_tab_name = "Sales Tax";
     $this->_action_tab_uri = '/' . $this->request->uri();
 }
Ejemplo n.º 3
0
 protected function _execute()
 {
     if (!isset($this->_data->tax_id)) {
         throw new Exception("Invalid tax ID: none provided.");
     }
     $tax = $this->_load_tax($this->_data->tax_id);
     if (!$tax->loaded()) {
         throw new Exception("Invalid tax ID: not found.");
     }
     // Check for some basic data.
     if (!isset($this->_data->payment_account_id)) {
         throw new Exception("Invalid payment account ID: none provided.");
     }
     $payment_account = $this->_load_account($this->_data->payment_account_id);
     if (!$payment_account->loaded()) {
         throw new Exception("Invalid payment account ID: not found.");
     }
     if (!$payment_account->payment) {
         throw new Exception("Invalid payment account ID: account must be marked as payment.");
     }
     if (!isset($this->_data->amount) || !strlen($this->_data->amount)) {
         throw new Exception("Invalid payment amount: none provided.");
     }
     if (!isset($this->_data->total) || !strlen($this->_data->total)) {
         throw new Exception("Invalid payment total: none provided.");
     }
     // Payment.
     $this->_payment->amount = $this->_data->amount;
     $this->_payment->tax_id = $tax->id;
     $this->_payment->date = isset($this->_data->date) ? $this->_data->date : NULL;
     $this->_payment->date_start = isset($this->_data->date_start) ? $this->_data->date_start : NULL;
     $this->_payment->date_end = isset($this->_data->date_end) ? $this->_data->date_end : NULL;
     $this->_payment->writeoff_amount = isset($this->_data->writeoff_amount) ? $this->_data->writeoff_amount : 0.0;
     $this->_validate_tax_payment($this->_payment);
     $tax_prep = new Beans_Tax_Prep($this->_beans_data_auth((object) array('date_start' => $this->_payment->date_start, 'date_end' => $this->_payment->date_end, 'id' => $this->_payment->tax_id)));
     $tax_prep_result = $tax_prep->execute();
     if (!$tax_prep_result->success) {
         throw new Exception("Could not run tax prep: " . $tax_prep_result->error);
     }
     if ($tax_prep_result->data->taxes->due->net->amount > 0 && $tax_prep_result->data->taxes->due->net->amount != $this->_data->total) {
         throw new Exception("Invalid payment total: please make sure the payment and writeoff amounts add up to the expected total.");
         // throw new Exception("Invalid payment total: expected ".number_format($tax_prep_result->data->taxes->due->net->amount,2,'.','')." but received ".number_format($this->_data->total,2,'.',''));
     }
     if ($this->_data->total > 0 && $this->_data->total != $this->_beans_round($this->_payment->amount + $this->_payment->writeoff_amount)) {
         throw new Exception("Payment amount and writeoff amount must total the payment total.");
     }
     // Kind of strange to the use case - but unless we can think of a good way to get
     // all affected tax_items returned in Beans_Tax_Prep - we have to do this here.
     $due_tax_items = ORM::Factory('tax_item')->where('tax_id', '=', $this->_payment->tax_id)->where('tax_payment_id', 'IS', NULL)->where('date', '<=', $this->_payment->date_end)->find_all();
     $due_tax_items_total = 0.0;
     foreach ($due_tax_items as $due_tax_item) {
         $due_tax_items_total = $this->_beans_round($due_tax_items_total + $due_tax_item->total);
     }
     if ($due_tax_items_total > 0 && $due_tax_items_total != $this->_data->total) {
         throw new Exception("Unexpected error: tax item and payment totals do not match.  Try re-running Beans_Tax_Prep.");
     }
     // Copy over the appropriate Tax_Prep information so that we know the state at which
     // this tax payment was created.  Updates from this point forward will allow only changing
     // the payment amount and writeoff amount.
     $this->_payment->invoiced_line_amount = $tax_prep_result->data->taxes->due->invoiced->form_line_amount;
     $this->_payment->invoiced_line_taxable_amount = $tax_prep_result->data->taxes->due->invoiced->form_line_taxable_amount;
     $this->_payment->invoiced_amount = $tax_prep_result->data->taxes->due->invoiced->amount;
     $this->_payment->refunded_line_amount = $tax_prep_result->data->taxes->due->refunded->form_line_amount;
     $this->_payment->refunded_line_taxable_amount = $tax_prep_result->data->taxes->due->refunded->form_line_taxable_amount;
     $this->_payment->refunded_amount = $tax_prep_result->data->taxes->due->refunded->amount;
     $this->_payment->net_line_amount = $tax_prep_result->data->taxes->due->net->form_line_amount;
     $this->_payment->net_line_taxable_amount = $tax_prep_result->data->taxes->due->net->form_line_taxable_amount;
     $this->_payment->net_amount = $tax_prep_result->data->taxes->due->net->amount;
     if ($due_tax_items_total < 0.0 && $this->_payment->amount != 0.0) {
         throw new Exception("Tax payments must be 0.00 when no positive balance is due.");
     }
     if ($this->_payment->amount == 0) {
         $this->_payment->save();
         $this->_tax_update_due_date($this->_payment->tax_id);
         return (object) array("payment" => $this->_return_tax_payment_element($this->_payment));
     }
     $this->_payment->save();
     // Formulate data request object for Beans_Account_Transaction_Create
     $create_transaction_data = new stdClass();
     $create_transaction_data->code = isset($this->_data->number) ? $this->_data->number : NULL;
     $create_transaction_data->description = isset($this->_data->description) ? $this->_data->description : NULL;
     if (!$create_transaction_data->description) {
         $create_transaction_data->description = "Tax Remittance: " . $tax->name;
     } else {
         $create_transaction_data->description = "Tax Remittance: " . $create_transaction_data->description;
     }
     $create_transaction_data->date = isset($this->_data->date) ? $this->_data->date : NULL;
     $create_transaction_data->reference = isset($this->_data->check_number) ? $this->_data->check_number : NULL;
     if (!$create_transaction_data->code and $create_transaction_data->reference) {
         $create_transaction_data->code = $create_transaction_data->reference;
     }
     // Positive Payment = Negative to Balance
     $create_transaction_data->account_transactions = array();
     $create_transaction_data->form_type = 'tax_payment';
     $create_transaction_data->form_id = $this->_payment->id;
     // Payment Account
     $create_transaction_data->account_transactions[] = (object) array('account_id' => $payment_account->id, 'transfer' => TRUE, 'amount' => $this->_payment->amount * -1 * $payment_account->account_type->table_sign);
     if (isset($this->_data->writeoff_amount) and $this->_data->writeoff_amount != 0.0) {
         $writeoff_amount = isset($this->_data->writeoff_amount) ? $this->_data->writeoff_amount : NULL;
         $writeoff_account_id = isset($this->_data->writeoff_account_id) ? $this->_data->writeoff_account_id : NULL;
         if (!$writeoff_amount) {
             throw new Exception("That payment will require a specifc writeoff amount - please provide that value.");
         }
         if (!$writeoff_account_id) {
             throw new Exception("That payment will require a writeoff - please provide a writeoff account ID.");
         }
         $writeoff_account = $this->_load_account($writeoff_account_id);
         if (!$writeoff_account->loaded()) {
             throw new Exception("Invalid writeoff account: not found.");
         }
         if (!$writeoff_account->writeoff) {
             throw new Exception("Invalid writeoff account: must be marked as a valid writeoff account.");
         }
         $create_transaction_data->account_transactions[] = (object) array('account_id' => $writeoff_account->id, 'writeoff' => TRUE, 'amount' => $writeoff_amount * -1 * $payment_account->account_type->table_sign);
         $this->_payment->amount = $this->_beans_round($this->_payment->amount + $writeoff_amount);
     }
     // Tax Account
     $create_transaction_data->account_transactions[] = (object) array('account_id' => $tax->account_id, 'amount' => $this->_payment->amount * $payment_account->account_type->table_sign);
     if ($this->_validate_only) {
         $create_transaction_data->validate_only = TRUE;
     }
     $create_transaction = new Beans_Account_Transaction_Create($this->_beans_data_auth($create_transaction_data));
     $create_transaction_result = $create_transaction->execute();
     if (!$create_transaction_result->success) {
         $this->_payment->delete();
         throw new Exception("An error occurred creating that tax payment: " . $create_transaction_result->error);
     }
     if ($this->_validate_only) {
         return (object) array();
     }
     // Assign transaction to payment and save
     $this->_payment->transaction_id = $create_transaction_result->data->transaction->id;
     $this->_payment->save();
     // Update tax_items
     foreach ($due_tax_items as $due_tax_item) {
         $due_tax_item->tax_payment_id = $this->_payment->id;
         $due_tax_item->balance = 0.0;
         $due_tax_item->save();
     }
     // Update tax balance
     $this->_tax_payment_update_balance($this->_payment->tax_id);
     // Update tax due date.
     $this->_tax_update_due_date($this->_payment->tax_id);
     return (object) array("payment" => $this->_return_tax_payment_element($this->_payment, TRUE));
 }
Ejemplo n.º 4
0
 public function action_taxprep()
 {
     $tax_id = $this->request->param('id');
     // 2014-01-01_2014-01-30
     $date_range = $this->request->param('code');
     $date_start = substr($date_range, 0, 10);
     $date_end = substr($date_range, 11);
     $tax_prep = new Beans_Tax_Prep($this->_beans_data_auth((object) array('id' => $tax_id, 'date_start' => $date_start, 'date_end' => $date_end)));
     $tax_prep_result = $tax_prep->execute();
     if (!$tax_prep_result->success) {
         // V2Item - Clean up and output nicely.
         die("An error occurred: " . $tax_prep_result->auth_error . $tax_prep_result->error);
     }
     $vendors_print_taxpayment = new View_Vendors_Print_Taxpayment();
     $vendors_print_taxpayment->setup_company_list_result = $this->_setup_company_list_result;
     $vendors_print_taxpayment->payment = (object) array('id' => NULL, 'tax' => $tax_prep_result->data->tax, 'amount' => NULL, 'writeoff_amount' => NULL, 'date' => NULL, 'date_start' => $tax_prep_result->data->date_start, 'date_end' => $tax_prep_result->data->date_end, 'check_number' => NULL, 'invoiced_line_amount' => $tax_prep_result->data->taxes->due->invoiced->form_line_amount, 'invoiced_line_taxable_amount' => $tax_prep_result->data->taxes->due->invoiced->form_line_taxable_amount, 'invoiced_amount' => $tax_prep_result->data->taxes->due->invoiced->amount, 'refunded_line_amount' => $tax_prep_result->data->taxes->due->refunded->form_line_amount, 'refunded_line_taxable_amount' => $tax_prep_result->data->taxes->due->refunded->form_line_taxable_amount, 'refunded_amount' => $tax_prep_result->data->taxes->due->refunded->amount, 'net_line_amount' => $tax_prep_result->data->taxes->due->net->form_line_amount, 'net_line_taxable_amount' => $tax_prep_result->data->taxes->due->net->form_line_taxable_amount, 'net_amount' => $tax_prep_result->data->taxes->due->net->amount, 'liabilities' => array_merge($tax_prep_result->data->taxes->due->invoiced->liabilities, $tax_prep_result->data->taxes->due->refunded->liabilities), 'amount' => NULL, 'writeoff_amount' => NULL);
     die($vendors_print_taxpayment->render());
 }