12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <window id="inventory">
- <layout type="vertical">
- <layout type="horizontal">
- <label>Transaction type: </label>
- <sqldrop id="transactiontype" />
- <stretch />
- </layout>
- <layout type="horizontal">
- <sqldrop data="0" display="1" showdata="true" id="item">
- <query><![CDATA[SELECT id, name FROM coffees WHERE quantity <> 0 ORDER BY name ASC]]></query>
- </sqldrop>
- <line id="quantity" />
- <sqldrop id="units" />
- <layout type="stack" id="optional">
- <page />
- <page>
- <layout type="horizontal">
- <label id="reasonlabel">Reason: </label>
- <line id="reason" />
- </layout>
- </page>
- </layout>
- </layout>
- <layout type="horizontal">
- <button type="push" name="Update" id="update" />
- <stretch />
- </layout>
- <textarea id="current" />
- </layout>
- <program>
- <![CDATA[
- var types = findChildObject(this, 'transactiontype');
- types.addItem(TTR("inventory", "inventory"));
- types.addItem(TTR("inventory", "loss"));
- var optionalDisplay = findChildObject(this, 'optional');
- var units = findChildObject(this, 'units');
- units.addItem(TTR("inventory", "bag"));
- units.addItem(TTR("inventory", "Lb"));
- units.addItem(TTR("inventory", "Kg"));
- var items = findChildObject(this, 'item');
- var status = findChildObject(this, 'current');
- function updateStatus() {
- query = new QSqlQuery();
- 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");
- query.bind(":id1", items.currentData());
- query.bind(":id2", items.currentData());
- query.exec();
- query.next();
- var text = items.currentText;
- text += " Current inventory: ";
- text += query.value(0);
- text += TTR("inventory", " Lb (");
- text += query.value(1);
- text += TTR("inventory", " Kg), ");
- text += query.value(2);
- text += (query.value(2) == "1" ? TTR("inventory", " bag") :
- TTR("inventory", " bags"));
- query = query.invalidate();
- status.plainText = text;
- }
- var button = findChildObject(this, 'update');
- var value = findChildObject(this, 'quantity');
- var reason = findChildObject(this, 'reason');
- var reasonlabel = findChildObject(this, 'reasonlabel');
- reason.enabled = false;
- button.clicked.connect(function() {
- q = "INSERT INTO ";
- q += (types.currentIndex == 0 ?
- "inventory (time, item, quantity)" :
- "loss (time, item, quantity, reason)");
- q += " VALUES ('now', ";
- q = q + items.currentData();
- q = q + ", ";
- if(units.currentText == TTR("inventory", "Lb")) {
- q = q + value.text;
- } else if (units.currentText == TTR("inventory", "Kg")) {
- q = q + (value.text * 2.2);
- }
- else {
- q = q + value.text;
- q = q + " * (SELECT conversion FROM lb_bag_conversion WHERE item = ";
- q = q + items.currentData();
- q = q + ")";
- }
- q += (types.currentIndex == 0 ?
- ")" :
- ", '" + reason.text + "')");
- query = new QSqlQuery();
- query.exec(q);
- updateStatus();
- });
- items['currentIndexChanged(int)'].connect(updateStatus);
- types['currentIndexChanged(int)'].connect(optionalDisplay.setCurrentIndex);
- updateStatus();
- ]]>
- </program>
- </window>
|