Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

greeninventory.xml 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <window id="inventory">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Transaction type: </label>
  5. <sqldrop id="transactiontype" />
  6. <stretch />
  7. </layout>
  8. <layout type="horizontal">
  9. <sqldrop data="0" display="1" showdata="true" id="item">
  10. <query><![CDATA[SELECT id, name FROM coffees WHERE quantity <> 0 ORDER BY name ASC]]></query>
  11. </sqldrop>
  12. <line id="quantity" />
  13. <sqldrop id="units" />
  14. <layout type="stack" id="optional">
  15. <page />
  16. <page>
  17. <layout type="horizontal">
  18. <label id="reasonlabel">Reason: </label>
  19. <line id="reason" />
  20. </layout>
  21. </page>
  22. </layout>
  23. </layout>
  24. <layout type="horizontal">
  25. <button type="push" name="Update" id="update" />
  26. <stretch />
  27. </layout>
  28. <textarea id="current" />
  29. </layout>
  30. <program>
  31. <![CDATA[
  32. var types = findChildObject(this, 'transactiontype');
  33. types.addItem("inventory");
  34. types.addItem("loss");
  35. var optionalDisplay = findChildObject(this, 'optional');
  36. var units = findChildObject(this, 'units');
  37. units.addItem("bag");
  38. units.addItem("lb");
  39. units.addItem("kg");
  40. var items = findChildObject(this, 'item');
  41. var status = findChildObject(this, 'current');
  42. function updateStatus() {
  43. query = new QSqlQuery();
  44. query.prepare("SELECT quantity, (quantity / 2.2)::numeric(12,3), (quantity / (SELECT conversion FROM lb_bag_conversion WHERE item = :id1))::numeric(12,2) FROM items WHERE id = :id2");
  45. query.bind(":id1", items.currentData());
  46. query.bind(":id2", items.currentData());
  47. query.exec();
  48. query.next();
  49. var text = items.currentText;
  50. text += " Current inventory: ";
  51. text += query.value(0);
  52. text += " Lb (";
  53. text += query.value(1);
  54. text += " Kg), ";
  55. text += query.value(2);
  56. text += (query.value(2) == "1" ? " bag" : " bags");
  57. query = query.invalidate();
  58. status.plainText = text;
  59. }
  60. var button = findChildObject(this, 'update');
  61. var value = findChildObject(this, 'quantity');
  62. var reason = findChildObject(this, 'reason');
  63. var reasonlabel = findChildObject(this, 'reasonlabel');
  64. reason.enabled = false;
  65. button.clicked.connect(function() {
  66. q = "INSERT INTO ";
  67. q += (types.currentIndex == 0 ?
  68. "inventory (time, item, quantity)" :
  69. "loss (time, item, quantity, reason)");
  70. q += " VALUES ('now', ";
  71. q = q + items.currentData();
  72. q = q + ", ";
  73. if(units.currentText == "lb") {
  74. q = q + value.text;
  75. } else if (units.currentText == "kg") {
  76. q = q + (value.text * 2.2);
  77. }
  78. else {
  79. q = q + value.text;
  80. q = q + " * (SELECT conversion FROM lb_bag_conversion WHERE item = ";
  81. q = q + items.currentData();
  82. q = q + ")";
  83. }
  84. q += (types.currentIndex == 0 ?
  85. ")" :
  86. ", '" + reason.text + "')");
  87. query = new QSqlQuery();
  88. query.exec(q);
  89. updateStatus();
  90. });
  91. items['currentIndexChanged(int)'].connect(updateStatus);
  92. types['currentIndexChanged(int)'].connect(optionalDisplay.setCurrentIndex);
  93. updateStatus();
  94. ]]>
  95. </program>
  96. </window>