Commit 0911dad0 authored by Karamel's avatar Karamel

Desktop-like receipt list (but keep the content).

parent c259be82
......@@ -54,6 +54,10 @@ public class Receipt implements Serializable {
return this.ticket;
}
public User getUser() {
return this.cashier;
}
public Collection<Payment> getPayments() {
return this.payments;
}
......
......@@ -27,8 +27,10 @@ import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
......@@ -152,6 +154,11 @@ public class StringUtils {
return TextUtils.join("/", dateSplit);
}
public static String formatTimeNumeric(long mils) {
Date date = new Date(mils);
return DateFormat.getTimeInstance().format(date);
}
public static String formatToCurrency(double money) {
//TODO: make currency locale customizable.
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.FRANCE);
......
......@@ -18,8 +18,12 @@
package fr.pasteque.client.widgets;
import fr.pasteque.client.R;
import fr.pasteque.client.models.Customer;
import fr.pasteque.client.models.Payment;
import fr.pasteque.client.models.PaymentMode;
import fr.pasteque.client.models.Receipt;
import fr.pasteque.client.models.TicketLine;
import fr.pasteque.client.utils.StringUtils;
import android.content.Context;
import android.view.LayoutInflater;
......@@ -31,6 +35,12 @@ public class ReceiptItem extends RelativeLayout {
private Receipt receipt;
private TextView label;
private TextView date;
private TextView time;
private TextView customer;
private TextView paymentMode;
private TextView amount;
private TextView user;
private TextView content;
public ReceiptItem(Context context, Receipt r) {
......@@ -38,15 +48,54 @@ public class ReceiptItem extends RelativeLayout {
LayoutInflater.from(context).inflate(R.layout.receipt_item,
this, true);
this.label = (TextView) this.findViewById(R.id.receipt_label);
this.date = (TextView) this.findViewById(R.id.receipt_date);
this.time = (TextView) this.findViewById(R.id.receipt_time);
this.customer = (TextView) this.findViewById(R.id.receipt_customer);
this.paymentMode = (TextView) this.findViewById(R.id.receipt_payment_mode);
this.amount = (TextView) this.findViewById(R.id.receipt_amount);
this.user = (TextView) this.findViewById(R.id.receipt_user);
this.content = (TextView) this.findViewById(R.id.receipt_content);
this.reuse(r);
}
public void reuse(Receipt r) {
this.receipt = r;
String label = this.getContext().getString(R.string.ticket_label,
this.receipt.getTicket().getTicketId());
this.label.setText(label);
// Ticket number and amount
this.label.setText("[" + r.getTicket().getTicketId() + "]");
this.amount.setText(this.getContext().getString(R.string.ticket_total,
r.getTicket().getTicketPrice()));
// Date and time
this.date.setText(StringUtils.formatDateNumeric(this.getContext(), r.getPaymentTime() * 1000));
this.time.setText(StringUtils.formatTimeNumeric(r.getPaymentTime() * 1000));
// Customer
Customer c = this.receipt.getTicket().getCustomer();
if (c != null) {
this.customer.setText(c.getName());
} else {
this.customer.setText("");
}
// Payment mode
boolean multiplePm = false;
PaymentMode pm = null;
for (Payment p : r.getPayments()) {
if (pm != null && !(p.getMode().getCode().equals(pm.getCode()))) {
multiplePm = true;
break;
}
pm = p.getMode();
}
if (multiplePm) {
this.paymentMode.setText(R.string.ticket_pm_multiple);
} else {
if (pm != null) {
this.paymentMode.setText(pm.getLabel());
} else {
this.paymentMode.setText("");
}
}
// User
this.user.setText(r.getUser().getName());
// Content
String content = "";
for (TicketLine l : r.getTicket().getLines()) {
content += l.getProduct().getLabel() + " x " + l.getQuantity() + ", ";
......
......@@ -18,15 +18,60 @@
-->
<!-- Designed to be merged as RelativeLayout -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Left part: number -->
<TextView android:id="@+id/receipt_label"
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="@dimen/contentMargin" />
<!-- Left part 2: Date and time -->
<TextView android:id="@+id/receipt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/receipt_label"
android:layout_margin="@dimen/contentMargin" />
<TextView android:id="@+id/receipt_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/receipt_date"
android:layout_below="@id/receipt_date"
android:layout_margin="@dimen/contentMargin" />
<!-- Rightmost part: user -->
<TextView android:id="@+id/receipt_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/contentMargin" />
<!-- Rightmost part 2: amount -->
<TextView android:id="@+id/receipt_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/receipt_user"
android:layout_margin="@dimen/contentMargin" />
<!-- Center: Payment mode and customer (stretchable) -->
<TextView android:id="@+id/receipt_payment_mode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/receipt_date"
android:layout_toLeftOf="@id/receipt_amount"
android:gravity="center_horizontal"
android:layout_weight="1"
android:layout_margin="@dimen/contentMargin" />
<TextView android:id="@+id/receipt_customer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_toRightOf="@id/receipt_time"
android:layout_toLeftOf="@id/receipt_amount"
android:layout_below="@id/receipt_label"
android:layout_weight="1"
android:layout_margin="@dimen/contentMargin" />
<!-- Bottom part: content -->
<TextView android:id="@+id/receipt_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/receipt_label"
android:layout_below="@id/receipt_customer"
android:layout_margin="@dimen/contentMargin" />
</merge>
......@@ -69,6 +69,7 @@
<string name="ticket_label">Ticket %s</string>
<string name="ticket_articles">%d article(s)</string>
<string name="ticket_total">%.2f€</string>
<string name="ticket_pm_multiple">Multiple</string>
<string name="customer_prepaid_label">%1$s (Solde %2$.2f€)</string>
<string name="ticket_pay">Payer</string>
<string name="ticket_access">Accéder au ticket</string>
......
......@@ -69,6 +69,7 @@
<string name="ticket_label">Ticket %s</string>
<string name="ticket_articles">%d article(s)</string>
<string name="ticket_total">%.2f€</string>
<string name="ticket_pm_multiple">Multiple</string>
<string name="customer_prepaid_label">%1$s (%2$.2f€ prepaid)</string>
<string name="ticket_pay">Pay</string>
<string name="ticket_access">Access to ticket</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment