Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

greensales.xml 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <window id="greensales">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Date:</label>
  5. <calendar time="true" 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. unitBox.currentIndex = (QSettings.value("script/greensales_unit", unitBox.findText("lb")));
  31. unitBox['currentIndexChanged(int)'].connect(function() {
  32. QSettings.setValue("script/greensales_unit", unitBox.currentIndex);
  33. });
  34. var convertToPounds = function(w, u) {
  35. switch(u)
  36. {
  37. case "g":
  38. return w * 0.0022;
  39. case "oz":
  40. return w * 0.0625;
  41. case "Kg":
  42. return w * 2.2;
  43. }
  44. return w;
  45. };
  46. var dateField = findChildObject(this, 'date');
  47. var customerField = findChildObject(this, 'customer');
  48. var items = findChildObject(this, 'coffees');
  49. var model = items.model();
  50. model.dataChanged.connect(function() {
  51. items.resizeColumnToContents(0);
  52. });
  53. var submit = findChildObject(this, 'submit');
  54. submit.clicked.connect(function() {
  55. var query = new QSqlQuery();
  56. query.prepare("INSERT INTO sale (time, item, quantity, customer) VALUES(:time, :item, :quantity, :customer)");
  57. query.bind(":time", dateField.text);
  58. if(customerField.text == "") {
  59. query.bind(":customer", null);
  60. }
  61. else {
  62. query.bind(":customer", customerField.text);
  63. }
  64. var coffeesArray = sqlToArray(items.columnArray(0, 32));
  65. if(coffeesArray.length > 0)
  66. {
  67. for(var i = 0; i < coffeesArray.length; i++)
  68. {
  69. if(items.data(i, 0, 32).value == '')
  70. {
  71. continue;
  72. }
  73. if(items.data(i, 1, 0).value == '')
  74. {
  75. continue;
  76. }
  77. query.bind(":item", items.data(i, 0, 32).value);
  78. query.bind(":quantity", convertToPounds(items.data(i, 1, 0).value, unitBox.currentText));
  79. query.exec();
  80. }
  81. }
  82. query = query.invalidate();
  83. window.close();
  84. });
  85. ]]>
  86. </program>
  87. </window>