Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

editinventorytransaction.xml 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 proceed = displayWarning(TTR("editinventorytransaction", "Are you sure?"), TTR("editinventorytransaction", "Deleting this transaction can not be undone. Continue?"));
  58. if(proceed) {
  59. var query = new QSqlQuery();
  60. query.prepare("DELETE FROM inventory WHERE item = :item AND time = :timestamp");
  61. query.bind(":item", Number(itemField.text));
  62. query.bind(":timestamp", timeField.text);
  63. query.exec();
  64. query.prepare("UPDATE items SET quantity = (SELECT balance FROM item_history(:item) ORDER BY time DESC LIMIT 1) WHERE id = :item2");
  65. query.bind(":item", Number(itemField.text));
  66. query.bind(":item2", Number(itemField.text));
  67. query.exec();
  68. query = query.invalidate();
  69. window.close();
  70. }
  71. });
  72. ]]>
  73. </program>
  74. </window>