Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(TTR("inventory", "inventory"));
  34. types.addItem(TTR("inventory", "loss"));
  35. var optionalDisplay = findChildObject(this, 'optional');
  36. var units = findChildObject(this, 'units');
  37. units.addItem(TTR("inventory", "bag"));
  38. units.addItem(TTR("inventory", "Lb"));
  39. units.addItem(TTR("inventory", "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 += TTR("inventory", " Lb (");
  53. text += query.value(1);
  54. text += TTR("inventory", " Kg), ");
  55. text += query.value(2);
  56. text += (query.value(2) == "1" ? TTR("inventory", " bag") :
  57. TTR("inventory", " bags"));
  58. query = query.invalidate();
  59. status.plainText = text;
  60. }
  61. var button = findChildObject(this, 'update');
  62. var value = findChildObject(this, 'quantity');
  63. var reason = findChildObject(this, 'reason');
  64. var reasonlabel = findChildObject(this, 'reasonlabel');
  65. button.clicked.connect(function() {
  66. q = "INSERT INTO ";
  67. q += (types.currentIndex == 0 ?
  68. "inventory (time, item, quantity, person)" :
  69. "loss (time, item, quantity, reason, person)");
  70. q += " VALUES ('now', ";
  71. q = q + items.currentData();
  72. q = q + ", ";
  73. if(units.currentText == TTR("inventory", "Lb")) {
  74. q = q + value.text;
  75. } else if (units.currentText == TTR("inventory", "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. ", :user)" :
  86. ", '" + reason.text + "', :user)");
  87. query = new QSqlQuery();
  88. query.prepare(q);
  89. query.bind(":user", Application.currentTypicaUser());
  90. query.exec();
  91. updateStatus();
  92. });
  93. items['currentIndexChanged(int)'].connect(updateStatus);
  94. types['currentIndexChanged(int)'].connect(optionalDisplay.setCurrentIndex);
  95. updateStatus();
  96. ]]>
  97. </program>
  98. </window>