-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateitem.php
More file actions
executable file
·60 lines (52 loc) · 1.68 KB
/
createitem.php
File metadata and controls
executable file
·60 lines (52 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
include "classes/db.php";
//Open database connection
$db = new db();
$barcode = filter_input(INPUT_POST, 'BarCode'); //$db->clearstr(filter_input(INPUT_POST, 'barcode'));
$price = trim(str_replace(',', '.', filter_input(INPUT_POST, 'price')));
try
{
$table = 'ZzItem';
// создаем новый товар
$data = array(
"Name" => "Без названия",
"BarCode" => $barcode
);
//Insert record into database
$q = $db->insert($data, $table);
if ($q->error <>'') {
throw new Exception($q->error);
}
//Get last inserted record (to return to jTable)
$rows = $q->all();
$q = $db->select("*", $table, "Id = (SELECT IDENT_CURRENT ('$table') AS Id)");
$itemrow = $q->single();
// добавляем новую цену
$data = array(
"Date" => date("Ymd G:i:s"),
"ItemId" => $itemrow[Id],
"Value" => $price
);
$table = 'ZzPrice';
//Insert record into database
$q = $db->insert($data, $table);
if ($q->error <>'') {
throw new Exception($q->error);
}
//Get last inserted record (to return to jTable)
$q = $db->select("*", $table, "Id = (SELECT IDENT_CURRENT ('$table') AS Id)");
$rows = $q->single();
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Options'] = $rows;
print json_encode($jTableResult);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>