Просмотр исходного кода

Add inventory transaction editing and deletion

Neal Wilson 6 лет назад
Родитель
Сommit
019234fa2a
Подписано: neal <neal@typica.us> Идентификатор GPG ключа: D6F25C90DD5819DF
3 измененных файлов: 92 добавлений и 3 удалений
  1. 20
    3
      config/Reports/itemtransactions.xml
  2. 71
    0
      config/Windows/editinventorytransaction.xml
  3. 1
    0
      config/config.xml

+ 20
- 3
config/Reports/itemtransactions.xml Просмотреть файл

@@ -225,7 +225,7 @@
225 225
                     }, 0));
226 226
                     output.writeEndElement();
227 227
                     output.writeEndElement();
228
-                    query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2, (SELECT files FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)), (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE'), (SELECT vendor || ' ' || invoice FROM invoices WHERE id = (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE')), (SELECT name FROM items WHERE id = (SELECT roasted_id FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id))), customer, reason, (SELECT person FROM transactions WHERE time = item_history.time AND item = item_history.item), (SELECT machine || '@' || time FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)) AS link FROM item_history(:item) WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
228
+                    query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2, (SELECT files FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)), (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE'), (SELECT vendor || ' ' || invoice FROM invoices WHERE id = (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE')), (SELECT name FROM items WHERE id = (SELECT roasted_id FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id))), customer, reason, (SELECT person FROM transactions WHERE time = item_history.time AND item = item_history.item), (SELECT machine || '@' || time FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)) AS link, time::text FROM item_history(:item) WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
229 229
                     query.bind(":sd", startDate);
230 230
                     query.bind(":ed", endDate);
231 231
                     switch(unitBox.currentIndex)
@@ -279,7 +279,7 @@
279 279
                             output.writeTextElement("td", (Number(query.value(2)).toFixed(prec)));
280 280
                         }
281 281
                         output.writeTextElement("td", (Number(query.value(3)).toFixed(prec)));
282
-                                prev_balance = query.value(3);
282
+                        prev_balance = query.value(3);
283 283
                         if(query.value(1) == "PURCHASE") {
284 284
                             output.writeStartElement("td");
285 285
                             output.writeStartElement("a");
@@ -298,7 +298,14 @@
298 298
                             output.writeTextElement("td", query.value(9));
299 299
                         } else if(query.value(1) == "SALE") {
300 300
                             output.writeTextElement("td", query.value(8));
301
-                        } else {
301
+                        } else if(query.value(1) == "INVENTORY") {
302
+							output.writeStartElement("td");
303
+							output.writeStartElement("a");
304
+							output.writeAttribute("href", "typica://script/n/" + itemBox.currentData() + "@" + query.value(12));
305
+							output.writeCDATA("Edit");
306
+							output.writeEndElement();
307
+							output.writeEndElement();
308
+						} else {
302 309
                             output.writeTextElement("td", "");
303 310
                         }
304 311
 						output.writeTextElement("td", query.value(10));
@@ -351,6 +358,13 @@
351 358
                 var details = createWindow("batchDetails");
352 359
                 details.loadBatch(key[0], key[1]);
353 360
             };
361
+			/* Open inventory transaction editor */
362
+			var openInventory = function(url) {
363
+				var arg = decodeURI(url.slice(2, url.length));
364
+				var key = arg.split("@");
365
+				var editor = createWindow("editinventorytransaction");
366
+				editor.loadTransaction(key[0], key[1]);
367
+			};
354 368
             view.scriptLinkClicked.connect(function(url) {
355 369
                 var linkType = url[0];
356 370
                 switch(linkType) {
@@ -360,6 +374,9 @@
360 374
                     case 'b':
361 375
                         openProfile(url);
362 376
                         break;
377
+					case 'n':
378
+						openInventory(url);
379
+						break;
363 380
                 }
364 381
             });
365 382
         ]]>

+ 71
- 0
config/Windows/editinventorytransaction.xml Просмотреть файл

@@ -0,0 +1,71 @@
1
+<window id="editinventorytransaction">
2
+	<layout type="vertical">
3
+		<layout type="horizontal">
4
+			<label>Time:</label>
5
+			<line id="time" writable="false" />
6
+			<label>Item:</label>
7
+			<line id="item" writable="false" />
8
+			<label>Quantity:</label>
9
+			<line id="quantity" />
10
+		</layout>
11
+		<layout type="horizontal">
12
+			<button id="delete" name="Delete Transaction" type="push" />
13
+			<stretch />
14
+			<button id="save" name="Save Changes" type="push" />
15
+		</layout>
16
+	</layout>
17
+	<program>
18
+		<![CDATA[
19
+			var window = this;
20
+			var w = window;
21
+			this.windowTitle = TTR("editinventorytransaction", "Typica - Edit Inventory Transaction");
22
+			timeField = findChildObject(this, 'time');
23
+			itemField = findChildObject(this, 'item');
24
+			quantityField = findChildObject(this, 'quantity');
25
+			deleteButton = findChildObject(this, 'delete');
26
+			saveButton = findChildObject(this, 'save');
27
+			this.loadTransaction = function(item, timestamp) {
28
+				w.itemID = item;
29
+				w.timestamp = timestamp;
30
+				timeField.text = timestamp;
31
+				itemField.text = item;
32
+				var query = new QSqlQuery();
33
+				query.prepare("SELECT quantity FROM inventory WHERE time = :timestamp AND item = :item");
34
+				query.bind(":timestamp", timestamp);
35
+				query.bind(":item", item);
36
+				query.exec();
37
+				if(query.next()) {
38
+					quantityField.text = query.value(0);
39
+				}
40
+                query = query.invalidate();
41
+			};
42
+			saveButton.clicked.connect(function() {
43
+				var query = new QSqlQuery();
44
+				query.prepare("UPDATE inventory SET quantity = :quantity WHERE item = :item AND time = :timestamp");
45
+				query.bind(":quantity", Number(quantityField.text));
46
+				query.bind(":item", Number(itemField.text));
47
+				query.bind(":timestamp", timeField.text);
48
+				query.exec();
49
+				query.prepare("UPDATE items SET quantity = (SELECT balance FROM item_history(:item) ORDER BY time DESC LIMIT 1) WHERE id = :item2");
50
+				query.bind(":item", Number(itemField.text));
51
+				query.bind(":item2", Number(itemField.text));
52
+				query.exec();
53
+				query = query.invalidate();
54
+				window.close();
55
+			});
56
+			deleteButton.clicked.connect(function() {
57
+				var query = new QSqlQuery();
58
+				query.prepare("DELETE FROM inventory WHERE item = :item AND time = :timestamp");
59
+				query.bind(":item", Number(itemField.text));
60
+				query.bind(":timestamp", timeField.text);
61
+				query.exec();
62
+				query.prepare("UPDATE items SET quantity = (SELECT balance FROM item_history(:item) ORDER BY time DESC LIMIT 1) WHERE id = :item2");
63
+				query.bind(":item", Number(itemField.text));
64
+				query.bind(":item2", Number(itemField.text));
65
+				query.exec();
66
+				query = query.invalidate();
67
+				window.close();
68
+			});
69
+		]]>
70
+	</program>
71
+</window>

+ 1
- 0
config/config.xml Просмотреть файл

@@ -35,6 +35,7 @@
35 35
     <include src="Windows/roastspec.xml" />
36 36
 	<include src="Windows/manuallogentry.xml" />
37 37
     <include src="Windows/schedule.xml" />
38
+	<include src="Windows/editinventorytransaction.xml" />
38 39
     <program>
39 40
         <![CDATA[
40 41
             Windows = new Object();

Загрузка…
Отмена
Сохранить