123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <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');
- 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>
|