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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <window id="greensales">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Date:</label>
  5. <calendar id="date" />
  6. <label>Customer:</label>
  7. <line id="customer" />
  8. <label>Weight Unit:</label>
  9. <sqldrop data="0" display="0" showdata="false" editable="false" id="units" />
  10. </layout>
  11. <sqltablearray columns="2" id="coffees">
  12. <column name="Coffee" delegate="sql" showdata="true" null="false" data="0" display="1">
  13. <![CDATA[
  14. SELECT id, name FROM coffees WHERE quantity <> 0 ORDER BY name
  15. ]]>
  16. </column>
  17. <column name="Weight" delegate="numeric" />
  18. </sqltablearray>
  19. <button name="Submit" id="submit" type="push" />
  20. </layout>
  21. <program>
  22. <![CDATA[
  23. var window = this;
  24. this.windowTitle = 'Typica - Enter Green Coffee Sales';
  25. var unitBox = findChildObject(this, 'units');
  26. unitBox.addItem("g");
  27. unitBox.addItem("Kg");
  28. unitBox.addItem("oz");
  29. unitBox.addItem("lb");
  30. var convertToPounds = function(w, u) {
  31. switch(u)
  32. {
  33. case "g":
  34. return w * 0.0022;
  35. case "oz":
  36. return w * 0.0625;
  37. case "Kg":
  38. return w * 2.2;
  39. }
  40. return w;
  41. };
  42. var dateField = findChildObject(this, 'date');
  43. var customerField = findChildObject(this, 'customer');
  44. var items = findChildObject(this, 'coffees');
  45. var model = items.model();
  46. model.dataChanged.connect(function() {
  47. items.resizeColumnToContents(0);
  48. });
  49. var submit = findChildObject(this, 'submit');
  50. submit.clicked.connect(function() {
  51. var query = new QSqlQuery();
  52. query.prepare("INSERT INTO sale VALUES(:time, :item, :quantity, :customer)");
  53. query.bind(":time", dateField.text);
  54. if(customerField.text == "") {
  55. query.bind(":customer", null);
  56. }
  57. else {
  58. query.bind(":customer", customerField.text);
  59. }
  60. var coffeesArray = sqlToArray(items.columnArray(0, 32));
  61. if(coffeesArray.length > 0)
  62. {
  63. for(var i = 0; i < coffeesArray.length; i++)
  64. {
  65. if(items.data(i, 0, 32).value == '')
  66. {
  67. continue;
  68. }
  69. if(items.data(i, 1, 0).value == '')
  70. {
  71. continue;
  72. }
  73. query.bind(":item", items.data(i, 0, 32).value);
  74. query.bind(":quantity", convertToPounds(items.data(i, 1, 0).value, unitBox.currentText));
  75. query.exec();
  76. }
  77. }
  78. query = query.invalidate();
  79. window.close();
  80. });
  81. ]]>
  82. </program>
  83. </window>