示例#1
0
 public function action_expenses()
 {
     $expense_id = $this->request->param('id');
     $vendor_expense_search = new Beans_Vendor_Expense_Search($this->_beans_data_auth((object) array('page_size' => 20, 'sort_by' => 'newest')));
     $vendor_expense_search_result = $vendor_expense_search->execute();
     if ($this->_beans_result_check($vendor_expense_search_result)) {
         $this->_view->vendor_expense_search_result = $vendor_expense_search_result;
     }
     $this->_view->requested_expense_id = $expense_id;
     $this->_view->force_current_uri = "/vendors/expenses";
 }
示例#2
0
 protected function _execute()
 {
     if (!$this->_vendor->loaded()) {
         throw new Exception("Vendor could not be found.");
     }
     $vendor_purchase_search = new Beans_Vendor_Purchase_Search($this->_beans_data_auth((object) array('vendor_id' => $this->_vendor->id)));
     $vendor_purchase_search_result = $vendor_purchase_search->execute();
     if (!$vendor_purchase_search_result->success) {
         throw new Exception("An error occurred when looking up vendor purchase purchases.");
     }
     $vendor_expense_search = new Beans_Vendor_Expense_Search($this->_beans_data_auth((object) array('vendor_id' => $this->_vendor->id)));
     $vendor_expense_search_result = $vendor_expense_search->execute();
     if (!$vendor_expense_search_result->success) {
         throw new Exception("An error occurred when looking up vendor expenses.");
     }
     return (object) array("vendor" => $this->_return_vendor_element($this->_vendor), "purchases" => $vendor_purchase_search_result->data->purchases, "expenses" => $vendor_expense_search_result->data->expenses);
 }
示例#3
0
文件: json.php 项目: rrsc/beansbooks
 public function action_expensesloadmore()
 {
     $last_expense_id = $this->request->post('last_expense_id');
     $last_expense_date = $this->request->post('last_expense_date');
     $search_terms = $this->request->post('search_terms');
     $search_vendor_id = $this->request->post('search_vendor_id');
     $count = $this->request->post('count');
     if (!$count) {
         $count = 20;
     }
     $this->_return_object->data->expenses = array();
     $page = 0;
     $search_parameters = new stdClass();
     $search_parameters->sort_by = 'newest';
     $search_parameters->page_size = $count * 2;
     $search_parameters->search_date_before = $last_expense_date ? date("Y-m-d", strtotime($last_expense_date . " +1 Day")) : NULL;
     // ALL
     // NULLs itself from $this->request->post();
     if ($search_vendor_id and strlen(trim($search_vendor_id))) {
         $search_parameters->search_vendor_id = $search_vendor_id;
     }
     $search_parameters->keywords = $search_terms;
     do {
         $search_parameters->page = $page;
         $vendor_expenses = new Beans_Vendor_Expense_Search($this->_beans_data_auth($search_parameters));
         $vendor_expenses_result = $vendor_expenses->execute();
         if (!$vendor_expenses_result->success) {
             return $this->_return_error("An unexpected error occurred: " . $this->_beans_result_get_error($vendor_expenses_result));
         }
         foreach ($vendor_expenses_result->data->expenses as $expense) {
             if (strtotime($expense->date_created) <= strtotime($last_expense_date) and $expense->id < $last_expense_id or strtotime($expense->date_created) < strtotime($last_expense_date) or !$last_expense_id) {
                 $html = new View_Partials_Vendors_Expenses_Expense();
                 $html->expense = $expense;
                 $expense->html = $html->render();
                 $this->_return_object->data->expenses[] = $expense;
             }
             if (count($this->_return_object->data->expenses) >= $count) {
                 return;
             }
         }
         $page++;
     } while ($page < $vendor_expenses_result->data->pages and count($this->_return_object->data->expenses) < $count);
 }