Example #1
0
 /**
  * Calculate the total price for the whole cart
  *
  * @return number
  */
 public function calculate_price()
 {
     $total = 0;
     foreach ($_SESSION['cart_items'] as $id => $quantity) {
         $item = Item::find_by_id($id);
         $total += $item->get_price() * $quantity;
     }
     return $total;
 }
 function item($id = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         $_POST = array_map('htmlspecialchars', $_POST);
         if ($_POST['name'] != "") {
             $_POST['name'] = $_POST['name'];
             $_POST['value'] = $_POST['value'];
             $_POST['type'] = $_POST['type'];
         } else {
             if ($_POST['item_id'] == "-") {
                 $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
                 redirect('estimates/view/' . $_POST['invoice_id']);
             } else {
                 $itemvalue = Item::find_by_id($_POST['item_id']);
                 $_POST['name'] = $itemvalue->name;
                 $_POST['type'] = $itemvalue->type;
                 $_POST['value'] = $itemvalue->value;
             }
         }
         $item = InvoiceHasItem::create($_POST);
         if (!$item) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_add_item_success'));
         }
         redirect('estimates/view/' . $_POST['invoice_id']);
     } else {
         $this->view_data['estimate'] = Invoice::find($id);
         $this->view_data['items'] = Item::find('all', array('conditions' => array('inactive=?', '0')));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_add_item');
         $this->view_data['form_action'] = 'estimates/item';
         $this->content_view = 'estimates/_item';
     }
 }
 function item($id = FALSE)
 {
     if ($_POST) {
         unset($_POST['send']);
         $_POST = array_map('htmlspecialchars', $_POST);
         if ($_POST['name'] != "") {
             $_POST['name'] = $_POST['name'];
             $_POST['value'] = $_POST['value'];
             $_POST['type'] = $_POST['type'];
         } else {
             if ($_POST['item_id'] == "-") {
                 $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
                 redirect('invoices/view/' . $_POST['invoice_id']);
             } else {
                 $rebill = explode("_", $_POST['item_id']);
                 if ($rebill[0] == "rebill") {
                     $itemvalue = Expense::find_by_id($rebill[1]);
                     $_POST['name'] = $itemvalue->description;
                     $_POST['type'] = $_POST['item_id'];
                     $_POST['value'] = $itemvalue->value;
                     $itemvalue->rebill = 2;
                     $itemvalue->invoice_id = $_POST['invoice_id'];
                     $itemvalue->save();
                 } else {
                     $itemvalue = Item::find_by_id($_POST['item_id']);
                     $_POST['name'] = $itemvalue->name;
                     $_POST['type'] = $itemvalue->type;
                     $_POST['value'] = $itemvalue->value;
                 }
             }
         }
         $item = InvoiceHasItem::create($_POST);
         if (!$item) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_add_item_success'));
         }
         redirect('invoices/view/' . $_POST['invoice_id']);
     } else {
         $this->view_data['invoice'] = Invoice::find($id);
         $this->view_data['items'] = Item::find('all', array('conditions' => array('inactive=?', '0')));
         $this->view_data['rebill'] = Expense::find('all', array('conditions' => array('project_id=? and (rebill=? or invoice_id=?)', $this->view_data['invoice']->project_id, 1, $id)));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_add_item');
         $this->view_data['form_action'] = 'invoices/item';
         $this->content_view = 'invoices/_item';
     }
 }
Example #4
0
<?php

require_once __DIR__ . "/../../_includes/initialize.php";
$sql = "SELECT * FROM categories";
$result_set = $database->query($sql);
include_once LAYOUT_PATH . "header.php";
$output = "";
$output .= "<div class='productsheet'>";
while ($cat_row = $database->fetch_array($result_set)) {
    $sql = "SELECT * FROM products WHERE active=1 AND  category_id=" . $cat_row['id'];
    $product_set = $database->query($sql);
    if ($database->num_rows($product_set) > 0) {
        $output .= "<p><strong>" . $cat_row['name'] . "</strong></p>";
        while ($prodrow = $database->fetch_array($product_set)) {
            $item = Item::find_by_id($prodrow['id']);
            $output .= "<div class='left'>" . $item->name . "</div><div class='right'>" . number_format($item->price, 2) . "</div><br />";
        }
    }
}
$output .= "</div>";
echo $output;
Example #5
0
<?php

require_once __DIR__ . "/../../_includes/initialize.php";
// Get product with the id that matches from the database
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $item = Item::find_by_id($id);
} else {
    $item = new Item();
    $item->set_category('Krukväxter');
}
if (isset($_POST['submit'])) {
    $item->name = $_POST['name'];
    $item->set_category($_POST['category']);
    $item->price = $_POST['price'];
    $item->set_sub_cat($_POST['sub_cat']);
    if (isset($_POST['active'])) {
        $item->active = $_POST['active'];
    } else {
        $item->active = 0;
    }
    $item->save();
}
include_once LAYOUT_PATH . "header.php";
?>

<form action="manageproduct.php?id=<?php 
echo $id;
?>
" method="POST">
	<table>