Skip to content

Commit

Permalink
fixed error
Browse files Browse the repository at this point in the history
  • Loading branch information
shivshankar9 committed Nov 18, 2024
1 parent a173306 commit d739862
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 175 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/bigdatanyze/ems1/AddPartyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class AddPartyActivity extends AppCompatActivity {

private EditText nameEditText;
private EditText contactEditText;
private EditText gstinEditText;
private EditText BillingAddressEditText;
private EditText ShippingAddressEditText;
private Button saveButton;
private PartyDao partyDao;

Expand All @@ -24,6 +27,9 @@ protected void onCreate(Bundle savedInstanceState) {

nameEditText = findViewById(R.id.editTextName);
contactEditText = findViewById(R.id.editTextContact);
gstinEditText= findViewById(R.id.editTextGstin);
BillingAddressEditText=findViewById(R.id.editTextBillingAddress);
ShippingAddressEditText=findViewById(R.id.editTextShippingAddress);
saveButton = findViewById(R.id.buttonSave);

partyDao = AppDatabase.getDatabase(this).partyDao();
Expand All @@ -34,13 +40,16 @@ protected void onCreate(Bundle savedInstanceState) {
private void saveParty() {
String name = nameEditText.getText().toString().trim();
String contact = contactEditText.getText().toString().trim();
String gstin= gstinEditText.getText().toString().trim();
String billing_address= BillingAddressEditText.toString().trim();
String shipping_address=ShippingAddressEditText.toString().trim();

if (name.isEmpty() || contact.isEmpty()) {
Toast.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT).show();
return;
}

Party party = new Party(name, contact);
Party party = new Party(name, contact,gstin,billing_address,shipping_address);
AppDatabase.databaseWriteExecutor.execute(() -> {
partyDao.insert(party);
runOnUiThread(() -> {
Expand Down
67 changes: 42 additions & 25 deletions app/src/main/java/com/bigdatanyze/ems1/ViewInvoicesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.bigdatanyze.ems1.adapter.InvoiceAdapter;
import com.bigdatanyze.ems1.model.Invoice;
import com.bigdatanyze.ems1.util.PdfUtils;
import com.bigdatanyze.ems1.viewmodel.InvoiceViewModel;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
Expand Down Expand Up @@ -123,33 +124,49 @@ private void updateTotalSales(List<Invoice> invoices) {
totalSalesTextView.setText(String.format("Total Sales: $%.2f", totalSales));
}

@Override
public void onInvoiceClick(Invoice invoice) {
if (invoice == null || isFinishing()) {
// If the activity is finishing or invoice is null, return early
return;
}

// Use app-specific directory for storing PDFs
File pdfDir = new File(getExternalFilesDir(null), "Finverge");
if (!pdfDir.exists()) {
pdfDir.mkdirs(); // Create the directory if it doesn't exist
}

File pdfFile = new File(pdfDir, "Invoice_" + invoice.getInvoiceNumber() + ".pdf");
// @Override
// public void onInvoiceClick(Invoice invoice) {
// if (invoice == null || isFinishing()) {
// // If the activity is finishing or invoice is null, return early
// return;
// }
//
// // Use app-specific directory for storing PDFs
// File pdfDir = new File(getExternalFilesDir(null), "Finverge");
// if (!pdfDir.exists()) {
// pdfDir.mkdirs(); // Create the directory if it doesn't exist
// }
//
// File pdfFile = new File(pdfDir, "Invoice_" + invoice.getInvoiceNumber() + ".pdf");
//
// if (pdfFile.exists()) {
// openGeneratedPDF(pdfFile);
// } else {
// try {
// generateInvoicePdf(invoice, pdfFile);
// openGeneratedPDF(pdfFile);
// } catch (Exception e) {
// Log.e("ViewInvoicesActivity", "Error generating PDF: " + e.getMessage(), e);
// Toast.makeText(this, "Error generating PDF.", Toast.LENGTH_SHORT).show();
// }
// }
// }
@Override
public void onInvoiceClick(Invoice invoice) {
if (invoice == null || isFinishing()) {
return; // Return early if no invoice or the activity is finishing
}

if (pdfFile.exists()) {
openGeneratedPDF(pdfFile);
} else {
try {
generateInvoicePdf(invoice, pdfFile);
openGeneratedPDF(pdfFile);
} catch (Exception e) {
Log.e("ViewInvoicesActivity", "Error generating PDF: " + e.getMessage(), e);
Toast.makeText(this, "Error generating PDF.", Toast.LENGTH_SHORT).show();
}
}
try {
// Generate PDF using utility method
File pdfFile = PdfUtils.generateInvoicePdf(this, invoice);
openGeneratedPDF(pdfFile);
} catch (Exception e) {
Log.e("ViewInvoicesActivity", "Error generating PDF: " + e.getMessage(), e);
Toast.makeText(this, "Error generating PDF.", Toast.LENGTH_SHORT).show();
}
}


private void generateInvoicePdf(Invoice invoice, File pdfFile) throws DocumentException, IOException {
Document document = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Database(entities = {Employee.class, Expense.class, Invoice.class, InvoiceItem.class, Party.class, Item.class, BusinessProfile.class}, version = 9, exportSchema = false)
@Database(entities = {Employee.class, Expense.class, Invoice.class, InvoiceItem.class, Party.class, Item.class, BusinessProfile.class}, version = 12, exportSchema = false)
@TypeConverters({Converters.class}) // Register the Converters class here
public abstract class AppDatabase extends RoomDatabase {

Expand Down
44 changes: 43 additions & 1 deletion app/src/main/java/com/bigdatanyze/ems1/model/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,53 @@ public class Party {
private int id;
private String name;
private String contact;
private String gstin;
private String billing_address;
private String shipping_address;

public String getGstin() {
return gstin;
}

public void setGstin(String gstin) {
this.gstin = gstin;
}

public String getBilling_address() {
return billing_address;
}

public void setBilling_address(String billing_address) {
this.billing_address = billing_address;
}

public String getShipping_address() {
return shipping_address;
}

public void setShipping_address(String shipping_address) {
this.shipping_address = shipping_address;
}








// Constructor
public Party(String name, String contact) {
// public Party(String name, String contact) {
// this.name = name;
// this.contact = contact;
// }
public Party(String name, String contact,String gstin,String billing_address,String shipping_address) {
this.name = name;
this.contact = contact;
this.gstin=gstin;
this.billing_address=billing_address;
this.shipping_address=shipping_address;

}

// Getters and Setters
Expand Down
Loading

0 comments on commit d739862

Please sign in to comment.