123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <window id="greensales">
- <layout type="vertical">
- <layout type="horizontal">
- <label>Date:</label>
- <calendar time="true" id="date" />
- <label>Customer:</label>
- <line id="customer" />
- <label>Weight Unit:</label>
- <sqldrop data="0" display="0" showdata="false" editable="false" id="units" />
- </layout>
- <sqltablearray columns="2" id="coffees">
- <column name="Coffee" delegate="sql" showdata="true" null="false" data="0" display="1">
- <![CDATA[
- SELECT id, name FROM coffees WHERE quantity <> 0 ORDER BY name
- ]]>
- </column>
- <column name="Weight" delegate="numeric" />
- </sqltablearray>
- <button name="Submit" id="submit" type="push" />
- </layout>
- <program>
- <![CDATA[
- var window = this;
- this.windowTitle = 'Typica - Enter Green Coffee Sales';
- var unitBox = findChildObject(this, 'units');
- unitBox.addItem("g");
- unitBox.addItem("Kg");
- unitBox.addItem("oz");
- unitBox.addItem("lb");
- unitBox.currentIndex = (QSettings.value("script/greensales_unit", unitBox.findText("lb")));
- unitBox['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/greensales_unit", unitBox.currentIndex);
- });
- var convertToPounds = function(w, u) {
- switch(u)
- {
- case "g":
- return w * 0.0022;
- case "oz":
- return w * 0.0625;
- case "Kg":
- return w * 2.2;
- }
- return w;
- };
- var dateField = findChildObject(this, 'date');
- var customerField = findChildObject(this, 'customer');
- var items = findChildObject(this, 'coffees');
- var model = items.model();
- model.dataChanged.connect(function() {
- items.resizeColumnToContents(0);
- });
- var submit = findChildObject(this, 'submit');
- submit.clicked.connect(function() {
- var query = new QSqlQuery();
- query.prepare("INSERT INTO sale VALUES(:time, :item, :quantity, :customer)");
- query.bind(":time", dateField.text);
- if(customerField.text == "") {
- query.bind(":customer", null);
- }
- else {
- query.bind(":customer", customerField.text);
- }
- var coffeesArray = sqlToArray(items.columnArray(0, 32));
- if(coffeesArray.length > 0)
- {
- for(var i = 0; i < coffeesArray.length; i++)
- {
- if(items.data(i, 0, 32).value == '')
- {
- continue;
- }
- if(items.data(i, 1, 0).value == '')
- {
- continue;
- }
- query.bind(":item", items.data(i, 0, 32).value);
- query.bind(":quantity", convertToPounds(items.data(i, 1, 0).value, unitBox.currentText));
- query.exec();
- }
- }
- query = query.invalidate();
- window.close();
- });
- ]]>
- </program>
- </window>
|