diff --git a/doc/db.dia b/doc/db.dia
new file mode 100644
index 0000000..f101b8a
--- /dev/null
+++ b/doc/db.dia
@@ -0,0 +1,2803 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ #A4#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #pr_purchases (view)#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #item_id#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #date#
+
+
+ #datetime#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #buyer_id#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #sum#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #pr_ids#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #prod_id#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #inn#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #name#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #id#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #pr_items_unknown (view)#
+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
+
+ #1#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #rcp_receipt#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #buyerAddress#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #totalSum#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #addressToCheckFiscalSign#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #fiscalDriveNumber#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #rawData#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #kktRegId#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #user#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #operationType#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #shiftNumber#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #ecashTotalSum#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #nds18#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #retailPlaceAddress#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #userInn#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #taxationType#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #cashTotalSum#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #operator#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #senderAddress#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #receiptCode#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #fiscalSign#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #nds10#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #fiscalDocumentNumber#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #requestNumber#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #dateTime#
+
+
+ #datetime#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #id#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #user_id#
+
+
+ #int#
+
+
+ #id пользователя в системе#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #rcp_item#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #name#
+
+
+ #string#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #receiptID#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #sum#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #nds10#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #quantity#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #price#
+
+
+ #integer#
+
+
+ ##
+
+
+
+
+
+
+
+
+
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+
+ #Ищем(добавляем) запись в pr_ids
+согласно связанным rcp_item и
+ rcp_receipt#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #pr_users#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #id#
+
+
+ #int#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #name#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #login#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #password#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #text#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #photo#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #email#
+
+
+ #text#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #date_change#
+
+
+ #timestamp#
+
+
+ ##
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #buyerAddress#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #totalSum#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #addressToCheckFiscalSign#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #fiscalDriveNumber#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #rawData#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #kktRegId#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #user#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #operationType#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #shiftNumber#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ecashTotalSum#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #nds18#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #retailPlaceAddress#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #userInn#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #taxationType#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #cashTotalSum#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #operator#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #senderAddress#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #receiptCode#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #fiscalSign#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #nds10#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #fiscalDocumentNumber#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #requestNumber#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #dateTime#
-
-
- #datetime#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #id#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #user_id#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #item#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #sum#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #nds10#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #name#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #quantity#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #price#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #nds18#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #receiptID#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #id#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #modifier#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #discountName#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #markupName#
-
-
- #string#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #discountSum#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
- #itemID#
-
-
- #integer#
-
-
- ##
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #1#
-
-
- #∞#
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #1#
-
-
- #∞#
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #1#
-
-
- #∞#
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #pr_user#
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git "a/doc/\321\200\320\260\320\267\320\262\320\265\321\200\321\202\321\213\320\262\320\260\320\275\320\270\320\265.txt" "b/doc/\321\200\320\260\320\267\320\262\320\265\321\200\321\202\321\213\320\262\320\260\320\275\320\270\320\265.txt"
index 6f94324..951828a 100755
--- "a/doc/\321\200\320\260\320\267\320\262\320\265\321\200\321\202\321\213\320\262\320\260\320\275\320\270\320\265.txt"
+++ "b/doc/\321\200\320\260\320\267\320\262\320\265\321\200\321\202\321\213\320\262\320\260\320\275\320\270\320\265.txt"
@@ -1,6 +1,6 @@
-Скрипты для инициализации базы данных находятся в каталоге sql. В MySQL выполнить скрипт создания таблиц init.sql, а затем остальные скрипты для заполнения таблиц базовыми данными. Создать пользователя - прописать логин и пароль в таблице pr_users.
+Скрипты для инициализации базы данных находятся в каталоге sql. В MySQL выполнить все скрипты по порядку. Они пронумерованы. Создать пользователя - прописать логин и пароль в таблице pr_users.
-Скопировать содержимое каталога pr на HTTP-сервер. Скорректировать файл pr/template/connect.php, указав там логин, пароль, имя БД и ip сервера MySQL. Создать каталог для загружаемых изображений и установить на него правильные права на запись. При необходимости скорректировать файл pr/products/save.php, указав там правильный путь для сохранения загружаемых изображений в переменной photoFileName.
+Скопировать содержимое каталога pr на HTTP-сервер. Скорректировать файл pr/template/connect.php, указав там логин, пароль, имя БД и ip сервера MySQL. Создать каталог для загружаемых изображений и установить на него правильные права на запись. При необходимости скорректировать файл pr/products/save.php, указав там правильный путь для сохранения загружаемых изображений в константе UPLOADS_FOLDER_PATH.
Название проекта "Ценовичок" - в 6 местах в файле pr/template/header.php
diff --git a/pr/products/save.php b/pr/products/save.php
index 47f5b01..cfa8216 100644
--- a/pr/products/save.php
+++ b/pr/products/save.php
@@ -1,4 +1,8 @@
prepare("SELECT id FROM pr_products WHERE name = ? and id != ?");
+$stmt = $db->prepare("SELECT id FROM " . PRODUCTS_TABLE_NAME . " WHERE name = ? and id != ?");
$stmt->execute(array($_REQUEST['product_name'], $_REQUEST['id']));
if($stmt->fetch()){
echo json_encode(array('result' => 'Товар с таким названием уже есть', 'error' => '1'));
die();
}
if (isset($_REQUEST['id'])) {
- $stmt = $db->prepare("UPDATE pr_products SET name = ?, ed_izm_id = ?, in_box = ? WHERE id = ?");
+ $stmt = $db->prepare("UPDATE " . PRODUCTS_TABLE_NAME . " SET name = ?, ed_izm_id = ?, in_box = ? WHERE id = ?");
if(!$stmt->execute(array($_REQUEST['product_name'], $_REQUEST['ed_izm'], doKolvo($_REQUEST['in_box']), $_REQUEST['id']))){
echo json_encode(array('result' => 'Ошибка изменения товара.', 'error' => '1'));
//echo 'Ошибка изменения товара'; print_r($stmt->errorInfo());
@@ -40,7 +44,7 @@ function doKolvo($s){
echo json_encode(array('result' => 'Ошибка при загрузке изображения', 'error' => '1'));
die();
}
- $photoFileName = '/pricer/uploaded/'.$_FILES['image']['name'];
+ $photoFileName = UPLOADS_FOLDER_PATH . $_FILES['image']['name'];
$fullPath = $_SERVER['DOCUMENT_ROOT'].$photoFileName;
if(file_exists($fullPath)){
function on_file_exist($path){
@@ -76,7 +80,7 @@ function on_file_exist($path){
if(move_uploaded_file($_FILES['image']['tmp_name'], $fullPath)){
$pieces = explode("/", $fullPath);
$photoFileName = array_pop($pieces);
- $stmt = $db->prepare("UPDATE pr_products SET photo = ? WHERE id = ?");
+ $stmt = $db->prepare("UPDATE " . PRODUCTS_TABLE_NAME . " SET photo = ? WHERE id = ?");
if(!$stmt->execute(array($photoFileName, $_REQUEST['id']))){
echo json_encode(array('result' => 'Ошибка изменения фото товара.', 'error' => '1'));
//echo 'Ошибка изменения фото товара'; print_r($stmt->errorInfo());
@@ -91,8 +95,8 @@ function on_file_exist($path){
echo json_encode($result);
exit();
} else {
- $stmt = $db->prepare("INSERT pr_products(name, ed_izm_id, in_box, main_clsf_id, creator) values(?, ?, ?, ?, ?)");
- if(!$stmt->execute(array($_REQUEST['product_name'], $_REQUEST['ed_izm'], doKolvo($_REQUEST['in_box']), $_REQUEST['main_clsf_id'], $_SESSION['user']['id']))){
+ $stmt = $db->prepare("INSERT INTO " . PRODUCTS_TABLE_NAME . " (name, ed_izm_id, in_box, id_hi, creator) values(?, ?, ?, ?, ?)");
+ if(!$stmt->execute(array($_REQUEST['product_name'], $_REQUEST['ed_izm'], doKolvo($_REQUEST['in_box']), $_REQUEST['id_hi'], $_SESSION['user']['id']))){
echo json_encode(array('result' => 'Ошибка добавления товара.', 'error' => '1'));
//echo 'Ошибка добавления товара'; print_r($stmt->errorInfo());
exit();
diff --git a/pr/products/stats.php b/pr/products/stats.php
new file mode 100644
index 0000000..703d5f5
--- /dev/null
+++ b/pr/products/stats.php
@@ -0,0 +1,370 @@
+
+
+define('OK', "{\"status\":\"OK\"}");
+define('ERROR', "{\"error\":\"ERROR\"}");
+
+include '../template/connect.php';
+
+if(isset($_POST['operation']))
+{
+ $op = $_POST['operation'];
+
+ if(isset($_POST['date_from'])) {
+ $pieces = explode("/", $_POST['date_from']);
+ $dateFrom = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];
+ }
+ if(isset($_POST['date_to'])) {
+ $pieces = explode("/", $_POST['date_to']);
+ $dateTo = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];
+ }
+
+ $filter = isset($dateFrom) && isset($dateTo);
+
+ if($op == 'get') {
+
+ $params = array();
+ $itemId = isset($_POST['itemId']) ? $_POST['itemId'] : false;
+
+ if($itemId) {
+
+ $req = "SELECT
+ `b`.`buyer_id` AS `buyer_id`,
+ `c`.`login` AS `buyer`,
+ `b`.`date` AS `date`,
+ `a`.`name` AS `name`,
+ `a`.`id` AS `pr_id`,
+ `a`.`id_hi` AS `group_id`,
+ if(`b`.`sum` IS NULL, 0, `b`.`sum`) AS `sum`
+ FROM `pr_consumption_clsf` `a`
+ LEFT JOIN `pr_purchases` `b` ON `a`.`id` = `b`.`item_id`
+ LEFT JOIN `pr_users` `c` ON `b`.`buyer_id` = `c`.`id`"
+ .($filter ? 'WHERE `b`.`date` BETWEEN DATE(?) AND DATE(?) ' : '');
+
+ }
+ else {
+
+ $req = "SELECT
+ `b`.`buyer_id` AS `buyer_id`,
+ `a`.`name` AS `name`,
+ `a`.`id` AS `pr_id`,
+ `a`.`id_hi` AS `group_id`,
+ if(`b`.`sum` IS NULL, 0, `b`.`sum`) AS `sum`
+ FROM `pr_consumption_clsf` `a`
+ LEFT JOIN `pr_purchases` `b` ON `a`.`id` = `b`.`item_id`
+ LEFT JOIN `pr_users` `c` ON `b`.`buyer_id` = `c`.`id` "
+ .($filter ? 'WHERE `b`.`date` BETWEEN DATE(?) AND DATE(?) ' : '');
+
+ }
+
+ if($filter) {
+ $params[] = $dateFrom;
+ $params[] = $dateTo;
+ }
+
+ $stmt = $db->prepare($req);
+ if($stmt->execute($params)) {
+
+ $res = array();
+
+ $root = array(
+ 'name' => 'Всего',
+ 'pr_id' => '-1',
+ 'buyer' => null,
+ 'date' => null,
+ 'buy_num' => 0,
+ 'buyers_num' => 0,
+ 'buyers' => [],
+ 'sum' => 0,
+ 'children' => []);
+
+ $i = 0;
+ foreach($stmt as $row) {
+ $empty = $row['buyer_id'] === null;
+ $res[] = array(
+ 'name' => $row['name'],
+ 'pr_id' => $row['pr_id'],
+ 'buyer' => $row['buyer'],
+ 'date' => $row['date'],
+ 'group_id' => $row['group_id'],
+ 'buy_num' => $empty ? 0 : 1,
+ 'buyers_num' => 0,
+ 'buyers' => ($empty ? [] :
+ array($row['buyer_id'] => false)),
+ 'sum' => $row['sum'],
+ 'children' => []);
+ }
+
+ $arr = array();
+ foreach($res as &$val) {
+ $id = $val['pr_id'];
+ $empty = count($val['buyers']) == 0;
+
+ if(array_key_exists($id, $arr)) {
+
+ if(!$empty)
+ $arr[$id]['buyers'][key($val['buyers'])] = true;
+
+ $arr[$id]['buy_num'] += $val['buy_num'];
+ $arr[$id]['sum'] += $val['sum'];
+ }
+ else
+ $arr[$id] = $val;
+ }
+
+ if($itemId) {
+
+ foreach($arr as &$val) {
+ $par = $val['group_id'];
+ if($par === null) {
+ $root['children'][] = &$val;
+ $val['group_id'] = '-1';
+ }
+ else
+ $arr[$par]['children'][] = &$val;
+ }
+
+ $ids = array();
+ getChildrenIds($root, $itemId, $ids);
+ $n = count($res);
+ for($i = 0; $i < $n; $i++) {
+ unset($res[$i]['children'],
+ $res[$i]['buyers'],
+ $res[$i]['group_id']);
+ if($res[$i]['sum'] == 0 || !array_key_exists($res[$i]['pr_id'], $ids)) {
+ array_splice($res, $i, 1);
+ $i--; $n--;
+ }
+ }
+ }
+ else {
+ $res = array();
+ foreach($arr as &$val) {
+ $par = $val['group_id'];
+ if($par === null) {
+ $root['children'][] = &$val;
+ $val['group_id'] = '-1';
+ }
+ else
+ $arr[$par]['children'][] = &$val;
+
+ $res[] = &$val;
+ }
+ countNodeSums($root);
+ for($i = 0; $i < $n; $i++) {
+ unset($res[$i]['children'],
+ $res[$i]['buyers'],
+ $res[$i]['group_id']);
+ }
+ array_unshift($res, $root);
+ }
+
+ print json_encode($res);
+ }
+ else
+ print ERROR;
+ }
+ else
+ print ERROR;
+
+ exit;
+}
+
+function getChildrenIds(&$node, $id, &$res) {
+
+ if($node['pr_id'] === $id) {
+ $res[$id] = true;
+ foreach($node['children'] as &$val)
+ getChildrenIds($val, $val['pr_id'], $res);
+ }
+ else {
+ foreach($node['children'] as &$val)
+ getChildrenIds($val, $id, $res);
+ }
+}
+
+function countNodeSums(&$node) {
+ foreach($node['children'] as &$val) {
+ countNodeSums($val);
+ $node['sum'] += $val['sum'];
+
+ foreach($val['buyers'] as $usrId => $checked)
+ $node['buyers'][$usrId] = true;
+ $node['buy_num'] += $val['buy_num'];
+ }
+ $node['buyers_num'] = count($node['buyers']);
+}
+
+ include '../template/header.php';
+ include '../template/oft_table.php';
+
+ headerOut('Статистика покупок товаров', array('prod'));
+
+ if($_SESSION['user']['id']) {
+
+?>
+
+
+
+
+
+
+
+
+ }else
+ print "Необходима авторизация";
+include('../template/footer.php'); ?>
\ No newline at end of file
diff --git a/pr/products/translation_table.php b/pr/products/translation_table.php
new file mode 100644
index 0000000..8f4a32b
--- /dev/null
+++ b/pr/products/translation_table.php
@@ -0,0 +1,308 @@
+
+
+define('OK', "{\"status\":\"OK\"}");
+define('ERROR', "{\"error\":\"ERROR\"}");
+
+include '../template/connect.php';
+
+if(isset($_POST['operation']))
+{
+ $op = $_POST['operation'];
+
+ if($op == 'get') {
+
+ $id = isset($_POST['cl_id']) ? $_POST['cl_id'] : false;
+ $stmt = $db->prepare('SELECT `a`.`id` AS `id`,
+ `a`.`prod_id` AS `cl_id`,
+ `a`.`name` AS `name`,
+ `a`.`inn` AS `inn`,
+ `b`.`name` AS `cl_name`
+ FROM `pr_ids` `a`
+ JOIN `pr_consumption_clsf` `b` ON `a`.`prod_id` = `b`.`id`
+ WHERE ' . ($id ? "`a`.`prod_id` = ?" : '1'));
+ $params = array();
+ if($id)
+ $params[] = $id;
+
+ if($stmt->execute($params)) {
+
+ $n = $stmt->rowCount();
+ $arr = array();
+ foreach($stmt as $row) {
+ $arr[] = array('id' => $row['id'],
+ 'cl_id' => $row['cl_id'],
+ 'name' => $row['name'],
+ 'inn' => $row['inn'],
+ 'cl_name' => $row['cl_name']);
+ }
+
+ print json_encode($arr);
+ }
+ else
+ print ERROR;
+
+ }
+ else if($op == 'get_path') {
+
+ if(isset($_POST['id'])) {
+ $id = $_POST['id'];
+ $stmt = $db->prepare('select `pr_get_product_path`(?) AS `path`');
+
+ if($stmt->execute(array($id))) {
+ $path = $stmt->fetch()['path'];
+ if(empty($path))
+ print '"path":[]';
+ else {
+ $path .= $id;
+ $arr = explode('/', $path);
+
+ $pathArr = array('path' => $arr);
+ print json_encode($pathArr);
+ }
+ }
+ else
+ print ERROR;
+ }
+ else
+ print ERROR;
+
+ }
+ else if($op == 'item_remove') {
+
+ if(isset($_POST['id'])) {
+
+ $id = $_POST['id'];
+ $stmt = $db->prepare('DELETE FROM `pr_ids` WHERE id=?');
+
+ if($stmt->execute(array($id)))
+ print OK;
+ else
+ print ERROR;
+ }
+ else
+ print ERROR;
+ }
+ else if($op == 'item_add') {
+
+ if(isset($_POST['id']) && isset($_POST['name']) && isset($_POST['inn'])) {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $inn = $_POST['inn'];
+
+ $stmt = $db->prepare('INSERT INTO `pr_ids` (`prod_id`, `name`, `inn`) VALUES (?, ?, ?)');
+ $exec_prms = array($_POST['id'], $_POST['name'], $_POST['inn']);
+
+ if($stmt->execute($exec_prms))
+ print OK;
+ else
+ print ERROR;
+ }
+ else
+ print ERROR;
+
+ }
+ else
+ print ERROR;
+
+ exit;
+}
+
+include '../template/header.php';
+include '../template/oft_table.php';
+include '../template/jstree/jstree.php';
+
+headerOut('Соответствие товара', array('prod'));
+
+?>
+
+
+
+|
+
+
+putTree('prod', '');
+?>
+
+ |
+
+
+ if($_SESSION['user']['id']) {
+
+ oftTable::init('Выбранный товар:', 'selectedItemTable');
+
+ oftTable::header(array('ИНН', 'Наименование', 'Товар(Классификатор)', 'Действия'));
+ oftTable::end();
+
+ oftTable::init('Соответствие товара', 'itemsTable');
+
+ oftTable::header(array('ИНН', 'Наименование', 'Товар(Классификатор)', 'Действия'));
+ oftTable::end();
+?>
+
+ |
+
+
+
+
+
+
+
+ }else
+ print "Необходима авторизация";
+include('../template/footer.php'); ?>
diff --git a/pr/products/tree.php b/pr/products/tree.php
index 56c0df2..45d8110 100644
--- a/pr/products/tree.php
+++ b/pr/products/tree.php
@@ -1,46 +1,42 @@
| Цена | Магазин | Дата';
- $stmt = $db->prepare(
- "SELECT s.name, po1.date_buy, min(price) pr
- FROM pr_product_offers po1, pr_shops s
- WHERE po1.product = ?
- and (po1.shop, po1.date_buy) in (
- SELECT shop, max(date_buy)
- FROM pr_product_offers
- WHERE product = ?
- GROUP BY shop
- )
- and po1.shop = s.id
- GROUP BY s.name, po1.date_buy
- ORDER BY pr"
- );
- $stmt->execute(array($id, $id));
- while($price = $stmt->fetch()){
- $r .= ' |
| '.$price['pr'].' | '.$price['name'].' | '.$price['date_buy'];
- }
- $r .= '';
+ $r .= '| Цена | Магазин | Дата';
+ $stmt = $db->prepare(
+ "SELECT s.name, po1.date_buy, min(price) pr
+ FROM pr_product_offers po1, pr_shops s
+ WHERE po1.product = ?
+ and (po1.shop, po1.date_buy) in (
+ SELECT shop, max(date_buy)
+ FROM pr_product_offers
+ WHERE product = ?
+ GROUP BY shop
+ )
+ and po1.shop = s.id
+ GROUP BY s.name, po1.date_buy
+ ORDER BY pr"
+ );
+ $stmt->execute(array($id, $id));
+ while($price = $stmt->fetch()){
+ $r .= ' | | '.$price['pr'].' | '.$price['name'].' | '.$price['date_buy'];
}
+ $r .= ' | ';
}else{
$readonly = ($_SESSION['user']['id']==null);
- if($is_file){
- $stmt = $db->prepare(
- "SELECT pr_products.name, photo, pr_ed_izm.name as ed_izm, ed_izm_id, in_box
- FROM pr_products
- LEFT JOIN pr_ed_izm on pr_ed_izm.id = pr_products.ed_izm_id
- WHERE pr_products.id = ?"
- );
- $stmt->execute(array($id));
- if(!($product = $stmt->fetch())){
- return array('content' => 'Товар не найден');
- }
- }else{
- if($readonly)
- return array('content' => '');
+
+ $stmt = $db->prepare(
+ "SELECT `a`.name, photo, `b`.name as ed_izm, ed_izm_id, in_box
+ FROM " . PRODUCTS_TABLE_NAME . " `a`" .
+ "LEFT JOIN `pr_ed_izm` `b` on `b`.id = `a`.ed_izm_id
+ WHERE `a`.id = ?"
+ );
+ $stmt->execute(array($id));
+ if(!($product = $stmt->fetch())){
+ return array('content' => 'Товар не найден');
}
$r = '';
}
- return ($is_file)?
- array('content' => $r, 'product_id' => $id)
- :array('content' => $r, 'product_id' => '');
+ return array('content' => $r, 'product_id' => $id);
}
- doTreeOperation('pr_products_main_clsf', 'pr_products', 'showProduct');
+ doTreeOperation('', PRODUCTS_TABLE_NAME, 'showProduct');
?>
diff --git a/pr/products/unknown_products.php b/pr/products/unknown_products.php
new file mode 100644
index 0000000..0c493f3
--- /dev/null
+++ b/pr/products/unknown_products.php
@@ -0,0 +1,143 @@
+
+ define('OK', "{\"status\":\"OK\"}");
+ define('ERROR', "{\"error\":\"ERROR\"}");
+
+ include '../template/connect.php';
+
+
+ if($_POST['operation'] === 'get') {
+
+ $stmt = $db->query('SELECT `name`, `inn`, `address`, `date` FROM `pr_items_unknown`');
+ if($stmt) {
+ $n = $stmt->rowCount();
+ $arr = array();
+ foreach($stmt as $row) {
+ $arr[] = array('name' => $row['name'],
+ 'inn' => $row['inn'],
+ 'address' => $row['address'],
+ 'date' => $row['date']);
+ }
+
+ print json_encode($arr);
+ }
+ else
+ print ERROR;
+
+ exit;
+ }
+
+ include '../template/header.php';
+
+ headerOut('Неизвестные товары', array('prod'));
+
+ if($_SESSION['user']['id']) {
+
+ include '../template/oft_table.php';
+ include '../template/jstree/jstree.php';
+
+?>
+
+
+
+|
+
+ putTree('prod', '');
+?>
+ |
+
+
+ oftTable::init('Неизвестные товары', 'itemsTable');
+
+ oftTable::header(array('Название', 'ИНН', 'Адрес', 'Добавлен', 'Действия'));
+
+
+ oftTable::end();
+?>
+ |
+
+
+
+
+
+
+ }else
+ print "Необходима авторизация";
+include('../template/footer.php'); ?>
\ No newline at end of file
diff --git a/pr/template/jstree/basetree.php b/pr/template/jstree/basetree.php
index 073c075..123df6e 100755
--- a/pr/template/jstree/basetree.php
+++ b/pr/template/jstree/basetree.php
@@ -7,83 +7,80 @@ function checkRights(){
throw new Exception('Требуется авторизация');
}
- function doTreeOperation($tbl_dir, $tbl_term, $showTerm){
+ function doTreeOperation($tbl_dir, $tbl_term, $showTerm, $rootText = 'Корень'){
global $db;
$res = array();
+ $id = $_GET['id'];
+ if($id == '-1')
+ $id = NULL;
+
try {
switch($_GET['operation']){
case "get_node":
if($_GET['id']=="#"){
- // $res[] = array('text' => 'Мои товары', 'children' => true, 'id' => '2', 'icon' => 'folder');
- foreach($db->query("select id, name from $tbl_dir where id_hi is null".(($tbl_term == null)?" and creator=".$_SESSION['user']['id']:"")) as $v){
- $res[] = array('text' => $v['name'], 'children' => true, 'id' => $v['id'], 'icon' => 'folder', 'state' => array('opened' => 'true'));
- }
+ $qres = $db->query("select `id` from `$tbl_term`");
+ $res[] = array('text' => $rootText,
+ 'children' => $qres->rowCount() != 0,
+ 'id' => '-1',
+ 'icon' => 'folder',
+ 'state' => array('opened' => 'true'));
}else{
$stmt = $db->prepare(
- "select id, name,
- (".(($tbl_term != null)
- ?"select count(*) from $tbl_term tt where tt.main_clsf_id = t1.id"
- :"0"
- ).
- ") termCnt,
- (
- select count(*)
- from $tbl_dir t2
- where t2.id_hi = t1.id
- ) childCnt
- from $tbl_dir t1
- where id_hi=?
- order by name");
- $stmt->execute(array($_GET['id']));
- while($v = $stmt->fetch()){
- $res[] = array('text' => $v['name'], 'children' => ($v['termCnt'] + $v['childCnt'] > 0), 'id' => $v['id'], 'icon' => 'folder');
- }
- if ($tbl_term != null) {
- $stmt = $db->prepare("select id, name from $tbl_term where main_clsf_id=? order by name");
- $stmt->execute(array($_GET['id']));
- while($v = $stmt->fetch()){
- $res[] = array('text' => $v['name'], 'children' => false, 'id' => 'f'.$v['id'], 'type' => 'file', 'icon' => 'file');
- }
- }
+ "SELECT
+ `a`.`id` AS `id`,
+ `a`.`name` AS `name`,
+ (
+ SELECT COUNT(*) != 0
+ FROM `$tbl_term` `b`
+ WHERE `b`.`id_hi` = `a`.`id`
+ ) `is_group`
+ FROM `$tbl_term` `a`" .
+ ($id == NULL ? "WHERE `a`.`id_hi` IS NULL" : "WHERE `a`.`id_hi` = ?"));
+ $stmt->execute(array($id));
+ foreach($stmt as $v)
+ $res[] = array('text' => $v['name'],
+ 'children' => $v['is_group'] == 1 ? true : false,
+ 'id' => $v['id'],
+ 'icon' => $v['is_group'] ? 'folder' : 'file');
}
break;
case "create_node":
checkRights();
- $stmt = $db->prepare("insert into $tbl_dir(name, id_hi)values(?, ?)");
- $stmt->execute(array($_GET['text'], $_GET['id']));
+ $stmt = $db->prepare("insert into $tbl_term(name, id_hi)values(?, ?)");
+ $id = $_GET['id'];
+ if($id == '-1')
+ $id = null;
+ $stmt->execute(array($_GET['text'], $id));
$res = array('id' => $db->lastInsertId());
break;
case "rename_node":
checkRights();
- $stmt = $db->prepare("update $tbl_dir set name=? where id=?");
+ $stmt = $db->prepare("update $tbl_term set name=? where id=?");
$stmt->execute(array($_GET['text'], $_GET['id']));
break;
default:
- $is_file = (substr($_GET['id'], 0, 1) == 'f');
- $id = $is_file?substr($_GET['id'], 1):$_GET['id'];
switch($_GET['operation']){
case "copy_node":
checkRights();
- $stmt = $db->prepare($is_file?
- "insert into pr_products(name, ed_izm_id, in_box, main_clsf_id, creator)
- select name, ed_izm_id, in_box, ?, ? from pr_products where id=?"
- :"insert into $tbl_dir(name, id_hi) select name, ? from pr_products_main_clsf where id=?");
- $stmt->execute($is_file?
- array($_GET['parent'], $_SESSION['user']['id'], $id)
- :array($_GET['parent'], $id));
+ $parent = $_GET['parent'];
+ if($parent == '-1')
+ $parent = NULL;
+ $stmt = $db->prepare("insert into $tbl_term(name, ed_izm_id, in_box, id_hi, creator)
+ select name, ed_izm_id, in_box, ?, ? from $tbl_term where id=?");
+ $stmt->execute(array($parent, $_SESSION['user']['id'], $id));
break;
case "move_node":
checkRights();
- $stmt = $db->prepare($is_file?
- "update $tbl_term set main_clsf_id=? where id=?"
- :"update $tbl_dir set id_hi=? where id=?");
- $stmt->execute(array($_GET['parent'], $id));
+ $parent = $_GET['parent'];
+ if($parent == '-1')
+ $parent = NULL;
+
+ $stmt = $db->prepare("update $tbl_term set id_hi=? where id=?");
+ $stmt->execute(array($parent, $id));
break;
case "delete_node":
checkRights();
- $stmt = $db->prepare($is_file?
- "delete from $tbl_term where id=?"
- :"delete from $tbl_dir where id=?");
+ $stmt = $db->prepare("delete from $tbl_term where id=?");
if(!$stmt->execute(array($id))){
throw new Exception('Ошибка удаления '.$stmt->errorInfo());
}
diff --git a/pr/template/jstree/jstree.php b/pr/template/jstree/jstree.php
index f32aceb..e0deb3a 100644
--- a/pr/template/jstree/jstree.php
+++ b/pr/template/jstree/jstree.php
@@ -44,28 +44,50 @@ function putTree($suf, $path){
'contextmenu' : {
'items' : function(node) {
var tmp = $.jstree.defaults.contextmenu.items();
-
- tmp.remove.label = "Удалить";
- tmp.ccp.label = "Редактирование";
- tmp.ccp.submenu.copy.label = "Копировать";
- tmp.ccp.submenu.cut.label = "Вырезать";
-
- if(this.get_type(node) === "file") {
- delete tmp.create;
+ if(node.id == '-1') {
+ delete tmp.remove;
delete tmp.rename;
- delete tmp.ccp.submenu.paste;
- }else{
- tmp.create.action = function (data) {
- var inst = $.jstree.reference(data.reference),
- obj = inst.get_node(data.reference);
- inst.create_node(obj, { type : "default" }, "last", function (new_node) {
- setTimeout(function () { inst.edit(new_node); },0);
- });
+ delete tmp.ccp.submenu.copy;
+ delete tmp.ccp.submenu.cut;
+ }
+ else{
+ tmp.remove.label = "Удалить";
+ tmp.remove.action = function(data) {
+ var inst = $.jstree.reference(data.reference),
+ obj = inst.get_node(data.reference),
+ parent = inst.get_node(inst.get_parent(obj));
+
+ if(inst.delete_node(obj)) {
+ if(parent.id != '-1' && !parent.children.length == 1) {
+ inst.set_type(parent, "file");
+ inst.set_icon(parent, "file");
+ }
}
- tmp.create.label = "Добавить каталог";
+ }
+
tmp.rename.label = "Переименовать";
- tmp.ccp.submenu.paste.label = "Вставить";
+
+ tmp.ccp.submenu.copy.label = "Копировать";
+ tmp.ccp.submenu.cut.label = "Вырезать";
}
+
+ tmp.create.action = function (data) {
+ var inst = $.jstree.reference(data.reference),
+ obj = inst.get_node(data.reference);
+
+ if(obj.id != '-1') {
+ inst.set_type(obj, "default");
+ inst.set_icon(obj, "folder");
+ }
+ inst.create_node(obj, { type : "file" }, "last", function (new_node) {
+ setTimeout(function () { inst.edit(new_node); },0);
+ });
+
+ }
+ tmp.create.label = "Добавить товар";
+
+ tmp.ccp.label = "Редактирование";
+ tmp.ccp.submenu.paste.label = "Вставить";
return tmp;
}
},
@@ -85,6 +107,7 @@ function putTree($suf, $path){
$.get('=$path?>tree.php?operation=create_node', { 'type' : data.node.type, 'id' : data.node.parent, 'text' : data.node.text })
.done(function (d) {
data.instance.set_id(data.node, d.id);
+
})
.fail(function () {
data.instance.refresh();
diff --git a/pr/template/oft_table.php b/pr/template/oft_table.php
index ed60043..15c7470 100644
--- a/pr/template/oft_table.php
+++ b/pr/template/oft_table.php
@@ -13,7 +13,7 @@ static function header($h){
static function row($r){
echo " |
";
foreach ($r as $i => $value) {
- echo "| $value";
+ echo " | $value | ";
}
echo "
";
}
@@ -31,3 +31,17 @@ static function addCol($a,$num,$value){
};
?>
+
+
diff --git a/sql/init.sql b/sql/0_init.sql
old mode 100755
new mode 100644
similarity index 95%
rename from sql/init.sql
rename to sql/0_init.sql
index 1fab395..958df96
--- a/sql/init.sql
+++ b/sql/0_init.sql
@@ -111,9 +111,14 @@ CREATE TABLE `pr_product_offers` (
CREATE TABLE `pr_consumption_clsf` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
- `creator` int(11),
+ `creator` int(11) DEFAULT NULL,
`name` text COLLATE utf8_unicode_ci NOT NULL,
- `id_hi` int(11),
+ `id_hi` int(11) DEFAULT NULL,
+ `photo` text COLLATE utf8_unicode_ci,
+ `text` text COLLATE utf8_unicode_ci,
+ `ed_izm_id` int(11) DEFAULT NULL,
+ `in_box` double DEFAULT NULL,
+ `date_change` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `pr_consumption_clsf_creator` FOREIGN KEY (`creator`) REFERENCES `pr_users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `pr_consumption_clsf_id_hi` FOREIGN KEY (`id_hi`) REFERENCES `pr_consumption_clsf` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
diff --git a/sql/pr_ed_izm.sql b/sql/1_pr_ed_izm.sql
old mode 100755
new mode 100644
similarity index 100%
rename from sql/pr_ed_izm.sql
rename to sql/1_pr_ed_izm.sql
diff --git a/sql/pr_getBasePrice.sql b/sql/2_pr_getBasePrice.sql
similarity index 100%
rename from sql/pr_getBasePrice.sql
rename to sql/2_pr_getBasePrice.sql
diff --git a/sql/receipt_ddl.sql b/sql/3_receipt_ddl.sql
similarity index 95%
rename from sql/receipt_ddl.sql
rename to sql/3_receipt_ddl.sql
index 46df71b..efda18c 100644
--- a/sql/receipt_ddl.sql
+++ b/sql/3_receipt_ddl.sql
@@ -3,7 +3,7 @@ CREATE TABLE `rcp_receipt` (
`buyerAddress` text,
`totalSum` int(11) DEFAULT NULL,
`addressToCheckFiscalSign` text,
- `fiscalDriveNumber` int(20),
+ `fiscalDriveNumber` varchar(100),
`rawData` text,
`kktRegId` text,
`user` text,
@@ -25,7 +25,7 @@ CREATE TABLE `rcp_receipt` (
`dateTime` DATETIME DEFAULT NULL,
`ndsNo` int(11) DEFAULT NULL,
`user_id` int(11) NOT NULL,
- CONSTRAINT `rcp_receipt_uk` UNIQUE KEY (`dateTime`, `totalSum`, `fiscalDriveNumber`, `fiscalDocumentNumber`, `fiscalSign`),
+ CONSTRAINT `rcp_receipt_uk` UNIQUE KEY (`dateTime`, `totalSum`, `fiscalDocumentNumber`, `fiscalSign`, `fiscalDriveNumber`),
CONSTRAINT `rcp_receipt_user_id` FOREIGN KEY (`user_id`) REFERENCES `pr_users` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
diff --git a/sql/4_products.sql b/sql/4_products.sql
new file mode 100644
index 0000000..7f1d100
--- /dev/null
+++ b/sql/4_products.sql
@@ -0,0 +1,50 @@
+CREATE TABLE `pr_ids` (
+ `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ `prod_id` int(11) NOT NULL,
+ `inn` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ UNIQUE KEY `name_inn` (`inn`,`name`) USING BTREE,
+ CONSTRAINT `pr_ids_ibfk_1` FOREIGN KEY (`prod_id`) REFERENCES `pr_consumption_clsf` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+CREATE VIEW `pr_items_unknown` AS
+select distinct
+ `i`.`name` AS `name`,
+ `r`.`userInn` AS `inn`,
+ `r`.`dateTime` AS `date`,
+ `r`.`retailPlaceAddress` AS `address`
+from `rcp_item` `i`
+ join `rcp_receipt` `r` on`i`.`receipt_id` = `r`.`id`
+ left join `pr_ids` `p` on `r`.`userInn` = `p`.`inn` and `i`.`name` = `p`.`name`
+where `p`.`inn` IS NULL;
+
+CREATE VIEW `pr_purchases` AS
+select
+ `a`.`sum` AS `sum`,
+ `b`.`dateTime` AS `date`,
+ `c`.`id` AS `buyer_id`,
+ `d`.`prod_id` AS `item_id`
+from `rcp_item` `a`
+ join `rcp_receipt` `b` on `a`.`receipt_id` = `b`.`id`
+ join `pr_users` `c` on `b`.`user_id` = `c`.`id`
+ join `pr_ids` `d` on `b`.`userInn` = `d`.`inn` and `a`.`name` = `d`.`name`;
+
+DELIMITER $$
+CREATE FUNCTION `pr_get_product_path`(`id` INT(11) UNSIGNED) RETURNS text CHARSET utf8
+ READS SQL DATA
+BEGIN
+ DECLARE cur INT DEFAULT NULL;
+ DECLARE res TEXT DEFAULT '';
+
+ SELECT `a`.`id_hi` INTO cur FROM `pr_consumption_clsf` `a`
+ WHERE `a`.`id` = id;
+
+ WHILE cur IS NOT NULL DO
+ SET res := CONCAT(cur, '/', res);
+ SELECT `a`.`id_hi` INTO cur FROM `pr_consumption_clsf` `a`
+ WHERE `a`.`id` = cur;
+ END WHILE;
+
+ RETURN res;
+END$$
+DELIMITER ;
\ No newline at end of file
diff --git a/sql/pr_products_main_clsf.sql b/sql/pr_products_main_clsf.sql
deleted file mode 100755
index f57961a..0000000
--- a/sql/pr_products_main_clsf.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO pr_products_main_clsf (name) VALUES
-('Главный классификатор товаров');
diff --git a/sql/pr_shops_main_clsf.sql b/sql/pr_shops_main_clsf.sql
deleted file mode 100755
index 4f93561..0000000
--- a/sql/pr_shops_main_clsf.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO pr_shops_main_clsf (name) VALUES
-('Главный классификатор магазинов');