Changed products to always have a manufacturer field

This commit is contained in:
Erik Thuning 2019-07-16 14:47:44 +02:00
parent 8654206c72
commit 720551af8d
4 changed files with 34 additions and 6 deletions

@ -1,6 +1,7 @@
create table `product` (
`id` bigint(20) not null auto_increment,
primary key(`id`),
`brand` varchar(64) not null,
`name` varchar(64) not null,
`invoice` varchar(64) not null,
`serial` varchar(64) not null,

@ -180,6 +180,16 @@
value="¤name¤" />
</td>
</tr>
<tr>
<td>
Tillverkare:
</td>
<td>
<input type="text"
name="brand"
value="¤brand¤" />
</td>
</tr>
<tr>
<td>
Fakturanummer:

@ -1,6 +1,7 @@
<?php
class Product {
private $id = 0;
private $brand = '';
private $name = '';
private $invoice = '';
private $serial = '';
@ -10,9 +11,10 @@ class Product {
private $tags = array();
public static function create_product(
$name = '',
$invoice = '',
$serial = '',
$brand,
$name,
$invoice,
$serial,
$info = array(),
$tags = array()
) {
@ -20,10 +22,10 @@ class Product {
begin_trans();
try {
$stmt = 'insert into
`product`(`name`, `invoice`, `serial`, `createtime`)
values (?, ?, ?, ?)';
`product`(`brand`, `name`, `invoice`, `serial`, `createtime`)
values (?, ?, ?, ?, ?)';
$ins_prod = prepare($stmt);
bind($ins_prod, 'sssi', $name, $invoice, $serial, $now);
bind($ins_prod, 'ssssi', $brand, $name, $invoice, $serial, $now);
execute($ins_prod);
$product = new Product($serial, 'serial');
foreach($info as $field => $value) {
@ -72,6 +74,7 @@ class Product {
bind($get, 'i', $this->id);
execute($get);
$product = result_single($get);
$this->brand = $product['brand'];
$this->name = $product['name'];
$this->invoice = $product['invoice'];
$this->serial = $product['serial'];
@ -120,6 +123,7 @@ class Product {
case 'status':
$matchvalues[] = $this->get_loan_status();
case 'fritext':
$matchvalues[] = $this->brand;
$matchvalues[] = $this->name;
$matchvalues[] = $this->serial;
$matchvalues[] = $this->invoice;
@ -160,6 +164,18 @@ class Product {
return true;
}
public function get_brand() {
return $this->brand;
}
public function set_brand($newbrand) {
$update = prepare('update `product` set `brand`=? where `id`=?');
bind($update, 'si', $newbrand, $this->id);
execute($update);
$this->brand = $newbrand;
return true;
}
public function get_name() {
return $this->name;
}

@ -74,6 +74,7 @@ class ProductPage extends Page {
$this->fragments['tag']);
}
$fields = array('id' => $this->product->get_id(),
'brand' => $this->product->get_brand(),
'name' => $this->product->get_name(),
'serial' => $this->product->get_serial(),
'invoice' => $this->product->get_invoice(),