/** * Edit Tags * if id is set, instanciate an edit function * if not instanciate an add tag function. */ public function action_role() { $this->xml_content_types = $this->xml_content->appendChild($this->dom->createElement('roles')); xml::to_XML(Uvtag::get_tags(), $this->xml_content_types, 'role'); if (!empty($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'role'); $post->rule('Valid::not_empty', 'uri'); if (isset($role)) { $tag->update($post->as_array()); $this->add_message('Role name updated'); } else { if (Uvtag::add($post->get('role'), $post->get('uri'))) { $this->add_message('Role "' . $post->get('name') . '" was added'); } else { $this->add_message('Role "' . $post->get('name') . '" could not be added'); } } } elseif (isset($tag)) { // Set the form input to the tag name. $this->set_formdata($tag->get()); } }
public function action_edit_customer() { $customer_id = $this->request->param('options'); $customer_model = new Customer($customer_id); xml::to_XML(array('customer' => $customer_model->get()), $this->xml_content, NULL, 'id'); if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); if ($post->validate()) { $customer_model->set($post->as_array()); $this->add_message('Customer "' . $post->get('name') . '" updated'); } } $this->set_formdata($customer_model->get()); }
public function action_entry() { // Set employees node $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees')); $employees = array('0option' => array('@value' => '0', 'None')); $counter = 1; foreach (Employees::get() as $employee) { $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']); $counter++; } xml::to_XML($employees, $employees_node); // This is for the select box if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post->filter('floatval', 'sum'); $post->filter('floatval', 'vat'); $post->rule('strtotime', 'accounting_date'); $post->rule('strtotime', 'transfer_date'); $post->rule('Valid::not_empty', 'description'); if ($post->Validate()) { $new_transaction_data = array('accounting_date' => $post->get('accounting_date'), 'transfer_date' => $post->get('transfer_date'), 'description' => $post->get('description'), 'journal_id' => $post->get('journal_id'), 'vat' => $post->get('vat'), 'sum' => $post->get('sum'), 'employee_id' => $post->get('employee_id')); if (!isset($_GET['id'])) { $transaction = new Transaction(NULL, $new_transaction_data); $this->add_message('Transaction ' . $transaction->get_id() . ' added'); } else { $transaction = new Transaction($_GET['id']); $transaction->set($new_transaction_data); $this->add_message('Transaction ' . $transaction->get_id() . ' updated'); $this->set_formdata($transaction->get()); } } else { $this->add_form_errors($post->errors()); $this->set_formdata($post->as_array()); } } elseif (isset($_GET['id'])) { $transaction = new Transaction($_GET['id']); $this->set_formdata($transaction->get()); } else { $this->set_formdata(array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => date('Y-m-d', time()))); } }
public function action_employee() { $statuses = array('0option' => array('@value' => 'active', '$content' => 'Active'), '1option' => array('@value' => 'inactive', '$content' => 'Inactive')); xml::to_XML($statuses, $this->xml_content->appendChild($this->dom->createElement('statuses'))); if (isset($_GET['id'])) { $employee = new Employee($_GET['id']); if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $employee->set($post->as_array()); $this->add_message('Employee ' . $_GET['id'] . ' information updated'); } $this->set_formdata($employee->get()); xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content); xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id'); } elseif (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $employee_id = Employee::new_employee($post->as_array()); $this->add_message($post->get('firstname') . ' (ID: ' . $employee_id . ') was added as employee'); } else { $this->redirect(); } }
public function action_bill() { $this->xml_content_customers = $this->xml_content->appendChild($this->dom->createElement('customers')); xml::to_XML(Customers::get_customers(), $this->xml_content_customers, 'customer', 'id'); $template = array(); foreach (glob(MODPATH . 'larvconomy/xsl/bills/*') as $file) { $file_paths = explode('/', $file); $template_file = explode('.', end($file_paths)); $template[] = reset($template_file); } $this->xml_content_bill_template = $this->xml_content->appendChild($this->dom->createElement('templates')); xml::to_XML($template, $this->xml_content_bill_template, 'template'); if (!isset($_SESSION['bills']['items'])) { $_SESSION['bills']['items']['1item'] = 1; } if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post_array = $post->as_array(); if (isset($post_array['add_item'])) { $_SESSION['bills']['items'][count($_SESSION['bills']['items']) + 1 . 'item'] = count($_SESSION['bills']['items']) + 1; $this->set_formdata($post_array); } else { $items = array(); $sum = 0; $vat_sum = 0; foreach ($_SESSION['bills']['items'] as $item_nr) { $item = array('artnr' => $post->get('artnr_item_' . $item_nr), 'spec' => $post->get('spec_item_' . $item_nr), 'price' => (double) $post->get('price_item_' . $item_nr), 'qty' => (double) $post->get('qty_item_' . $item_nr), 'delivery_date' => date('Y-m-d', time())); if ($item != array('artnr' => '', 'spec' => '', 'price' => 0, 'qty' => 0, 'delivery_date' => date('Y-m-d', time()))) { $items[] = $item; $sum += $item['qty'] * $item['price'] * 1.25; $vat_sum += $item['qty'] * $item['price'] * 0.25; } } if (count($items) && $post->validate()) { $bill_id = Bill::new_bill($post->get('customer_id'), strtotime($post->get('due_date')), $post->get('contact'), $items, $post->get('comment'), $post->get('template'), $post->get('mail_body')); $this->add_message('Created bill nr ' . $bill_id); unset($_SESSION['bills']['items']); // Create the transaction $data = array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => '0000-00-00', 'description' => 'Bill ' . $bill_id, 'vat' => $vat_sum, 'sum' => $sum, 'employee_id' => NULL, 'journal_id' => NULL); $transaction = new Transaction(NULL, $data); // End of Create the transaction // Set new default due date $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60))); // Make the PDF if (Kohana::$config->load('larv.htpassword.password') && Kohana::$config->load('larv.htpassword.username')) { shell_exec('wkhtmltopdf --ignore-load-errors --username ' . Kohana::$config->load('larv.htpassword.username') . ' --password ' . Kohana::$config->load('larv.htpassword.password') . ' "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"'); } else { shell_exec('wkhtmltopdf --ignore-load-errors "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"'); } if (isset($_FILES)) { Bill::upload($_FILES, 'attachments/' . $bill_id); } } else { $this->add_error('Not enough data'); $post->set('due_date', date('Y-m-d', strtotime($post->get('due_date')))); $post->set('mail_body', Kohana::$config->load('larv.email.bill_message')); $this->set_formdata($post->as_array()); } } } else { $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60), 'mail_body' => Kohana::$config->load('larv.email.bill_message'))); } xml::to_XML($_SESSION['bills'], $this->xml_content); }