1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <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, person)" :
- "loss (time, item, quantity, reason, person)");
- 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 ?
- ", :user)" :
- ", '" + reason.text + "', :user)");
- query = new QSqlQuery();
- query.prepare(q);
- query.bind(":user", Application.currentTypicaUser());
- query.exec();
- updateStatus();
- });
- items['currentIndexChanged(int)'].connect(updateStatus);
- types['currentIndexChanged(int)'].connect(optionalDisplay.setCurrentIndex);
- updateStatus();
- ]]>
- </program>
- </window>
|