add payment, invoice
This commit is contained in:
parent
be03724217
commit
67b7c5aa9a
BIN
excel/Invoices.xls
Normal file
BIN
excel/Invoices.xls
Normal file
Binary file not shown.
BIN
excel/Payments.xls
Normal file
BIN
excel/Payments.xls
Normal file
Binary file not shown.
Binary file not shown.
BIN
excel/Quotes.xls
BIN
excel/Quotes.xls
Binary file not shown.
@ -909,26 +909,33 @@ object PaymentCtrl {
|
|||||||
fun create(ctx: Context) {
|
fun create(ctx: Context) {
|
||||||
val pmt = ctx.bodyAsClass(Payment::class.java)
|
val pmt = ctx.bodyAsClass(Payment::class.java)
|
||||||
//update the status of invoices pertaining to payment.vendor
|
//update the status of invoices pertaining to payment.vendor
|
||||||
|
val vendors: List<Long>? = pmt.vendor?.let { listOf(it.sysPk) }
|
||||||
val invoices = searchInvoices(
|
val invoices = searchInvoices(
|
||||||
CommonFilters(sortBy = "date", sortAsc = true),
|
CommonFilters(sortBy = "date", sortAsc = true, vendor = vendors),
|
||||||
InvoiceFilters(status = InvoiceStatus.PAID_NONE)
|
InvoiceFilters(status = InvoiceStatus.PAID_FULL)
|
||||||
)
|
)
|
||||||
println(invoices)
|
// println(invoices)
|
||||||
|
//pmt.invoicesAffected = mutableMapOf()
|
||||||
|
var totalAmount = pmt.amount
|
||||||
|
var totalDeduct = 0.0
|
||||||
for (invoice in invoices) {
|
for (invoice in invoices) {
|
||||||
val deduct = Math.min(pmt.amount, invoice.totalAmount)
|
val deduct = Math.min(totalAmount, invoice.totalAmount)
|
||||||
invoice.totalAmount -= deduct
|
invoice.totalAmount -= deduct
|
||||||
pmt.amount -= deduct
|
totalDeduct += deduct
|
||||||
|
totalAmount -= deduct
|
||||||
if (invoice.totalAmount <= 0.0) {
|
if (invoice.totalAmount <= 0.0) {
|
||||||
invoice.status = InvoiceStatus.PAID_FULL
|
invoice.status = InvoiceStatus.PAID_FULL
|
||||||
} else {
|
} else {
|
||||||
invoice.status = InvoiceStatus.PAID_SOME
|
invoice.status = InvoiceStatus.PAID_SOME
|
||||||
}
|
}
|
||||||
|
//println(invoice)
|
||||||
database.update(invoice)
|
database.update(invoice)
|
||||||
pmt.invoicesAffected?.toMutableMap()?.put(invoice.sysPk, deduct)
|
pmt.invoicesAffected?.put(invoice.sysPk, deduct)
|
||||||
if (pmt.amount <= 0.0) break
|
println(pmt.invoicesAffected)
|
||||||
|
if (totalAmount <= 0.0) break
|
||||||
}
|
}
|
||||||
pmt.excessAmount = pmt.amount
|
pmt.amountDeducted = totalDeduct
|
||||||
|
pmt.excessAmount = pmt.amount - pmt.amountDeducted!!
|
||||||
database.save(pmt)
|
database.save(pmt)
|
||||||
ctx.json(pmt).status(HttpStatus.CREATED)
|
ctx.json(pmt).status(HttpStatus.CREATED)
|
||||||
}
|
}
|
||||||
@ -942,6 +949,7 @@ object PaymentCtrl {
|
|||||||
val inv = database.find(Invoice::class.java, entry.key)
|
val inv = database.find(Invoice::class.java, entry.key)
|
||||||
?: throw NotFoundResponse("No invoice found for $entry.key")
|
?: throw NotFoundResponse("No invoice found for $entry.key")
|
||||||
inv.totalAmount += entry.value
|
inv.totalAmount += entry.value
|
||||||
|
inv.status = InvoiceStatus.PAID_SOME
|
||||||
database.update(inv)
|
database.update(inv)
|
||||||
}
|
}
|
||||||
database.delete(pmt)
|
database.delete(pmt)
|
||||||
@ -960,10 +968,10 @@ object PaymentCtrl {
|
|||||||
fun getAll(ctx: Context) {
|
fun getAll(ctx: Context) {
|
||||||
val filters = ctx.bodyAsClass<PMTF>()
|
val filters = ctx.bodyAsClass<PMTF>()
|
||||||
val payments = searchPayments(filters.common, filters.paymentFilters)
|
val payments = searchPayments(filters.common, filters.paymentFilters)
|
||||||
println(payments)
|
// println(payments)
|
||||||
val excel = ctx.queryParam("excel")
|
val excel = ctx.queryParam("excel")
|
||||||
if (excel !== null) {
|
if (excel !== null) {
|
||||||
// exportPayments(payments)
|
exportPayments(payments)
|
||||||
val inputStream = FileInputStream("./excel/Payments.xls")
|
val inputStream = FileInputStream("./excel/Payments.xls")
|
||||||
ctx.result(inputStream).status(HttpStatus.OK)
|
ctx.result(inputStream).status(HttpStatus.OK)
|
||||||
} else {
|
} else {
|
||||||
@ -1003,7 +1011,7 @@ object InvoiceCtrl {
|
|||||||
val invoices = searchInvoices(filters.common, filters.invoiceFilters)
|
val invoices = searchInvoices(filters.common, filters.invoiceFilters)
|
||||||
val excel = ctx.queryParam("excel")
|
val excel = ctx.queryParam("excel")
|
||||||
if (excel !== null) {
|
if (excel !== null) {
|
||||||
// exportPayments(payments)
|
exportInvoices(invoices)
|
||||||
val inputStream = FileInputStream("./excel/Invoices.xls")
|
val inputStream = FileInputStream("./excel/Invoices.xls")
|
||||||
ctx.result(inputStream).status(HttpStatus.OK)
|
ctx.result(inputStream).status(HttpStatus.OK)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -101,6 +101,7 @@ enum class FileType {
|
|||||||
enum class EnumFor {
|
enum class EnumFor {
|
||||||
UOM, DocType
|
UOM, DocType
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveExcelFileLocally(fileName: String, wb: Workbook) {
|
fun saveExcelFileLocally(fileName: String, wb: Workbook) {
|
||||||
val path = "./excel/"
|
val path = "./excel/"
|
||||||
val out = FileOutputStream(path + fileName)
|
val out = FileOutputStream(path + fileName)
|
||||||
@ -245,7 +246,17 @@ fun exportVendors(vendors: List<Vendor>) {
|
|||||||
val sh = wb.createSheet()
|
val sh = wb.createSheet()
|
||||||
|
|
||||||
val headers: List<String> =
|
val headers: List<String> =
|
||||||
listOf("No.", "Name", "MSME", "GST Number", "Address", "Rating", "Contact Name", "Contact Email", "Contact Mobile")
|
listOf(
|
||||||
|
"No.",
|
||||||
|
"Name",
|
||||||
|
"MSME",
|
||||||
|
"GST Number",
|
||||||
|
"Address",
|
||||||
|
"Rating",
|
||||||
|
"Contact Name",
|
||||||
|
"Contact Email",
|
||||||
|
"Contact Mobile"
|
||||||
|
)
|
||||||
createHeaderRow(headers, sh, wb)
|
createHeaderRow(headers, sh, wb)
|
||||||
|
|
||||||
val totalCols = headers.size
|
val totalCols = headers.size
|
||||||
@ -338,7 +349,7 @@ fun exportPos(pos: List<PurchaseOrder>) {
|
|||||||
saveExcelFileLocally("Pos.xls", wb)
|
saveExcelFileLocally("Pos.xls", wb)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportIncomingInventory(tickets : List<IncomingInventory>) {
|
fun exportIncomingInventory(tickets: List<IncomingInventory>) {
|
||||||
val wb = HSSFWorkbook()
|
val wb = HSSFWorkbook()
|
||||||
val sh = wb.createSheet()
|
val sh = wb.createSheet()
|
||||||
|
|
||||||
@ -379,7 +390,7 @@ fun exportIncomingInventory(tickets : List<IncomingInventory>) {
|
|||||||
saveExcelFileLocally("IncomingInventory.xls", wb)
|
saveExcelFileLocally("IncomingInventory.xls", wb)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportOutgoingInventory(tickets : List<OutgoingInventory>) {
|
fun exportOutgoingInventory(tickets: List<OutgoingInventory>) {
|
||||||
val wb = HSSFWorkbook()
|
val wb = HSSFWorkbook()
|
||||||
val sh = wb.createSheet()
|
val sh = wb.createSheet()
|
||||||
|
|
||||||
@ -417,6 +428,73 @@ fun exportOutgoingInventory(tickets : List<OutgoingInventory>) {
|
|||||||
}
|
}
|
||||||
saveExcelFileLocally("OutgoingInventory.xls", wb)
|
saveExcelFileLocally("OutgoingInventory.xls", wb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun exportPayments(payments: List<Payment>) {
|
||||||
|
val wb = HSSFWorkbook()
|
||||||
|
val sh = wb.createSheet()
|
||||||
|
|
||||||
|
val headers: List<String> = listOf("Reference Number", "Vendor", "Amount Paid", "Amount Deducted", "Excess Amount")
|
||||||
|
createHeaderRow(headers, sh, wb)
|
||||||
|
|
||||||
|
var rowCnt = 1
|
||||||
|
|
||||||
|
for (pmt in payments) {
|
||||||
|
val row = sh.createRow(rowCnt++)
|
||||||
|
var i = 0
|
||||||
|
row.createCell(i++).setCellValue(pmt.refNumber)
|
||||||
|
row.createCell(i++).setCellValue(pmt.vendor?.name)
|
||||||
|
row.createCell(i++).setCellValue(pmt.amount)
|
||||||
|
pmt.amountDeducted?.let { row.createCell(i++).setCellValue(it) }
|
||||||
|
pmt.excessAmount?.let { row.createCell(i++).setCellValue(it) }
|
||||||
|
}
|
||||||
|
saveExcelFileLocally("Payments.xls", wb)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun exportInvoices(invoices: List<Invoice>) {
|
||||||
|
val wb = HSSFWorkbook()
|
||||||
|
val sh = wb.createSheet()
|
||||||
|
|
||||||
|
val headers: List<String> = listOf(
|
||||||
|
"Number",
|
||||||
|
"Date",
|
||||||
|
"Reference PO",
|
||||||
|
"Status",
|
||||||
|
"Vendor Name",
|
||||||
|
"Vendor Address",
|
||||||
|
"Product Id",
|
||||||
|
"Product Name",
|
||||||
|
"Unit Price",
|
||||||
|
"Quantity",
|
||||||
|
"Total Amount"
|
||||||
|
)
|
||||||
|
createHeaderRow(headers, sh, wb)
|
||||||
|
|
||||||
|
var rowCnt = 1
|
||||||
|
for (invoice in invoices) {
|
||||||
|
val prodCnt = invoice.products?.size
|
||||||
|
|
||||||
|
for (j in 0..<prodCnt!!) {
|
||||||
|
val row = sh.createRow(rowCnt++)
|
||||||
|
var i = 0
|
||||||
|
row.createCell(i++).setCellValue(invoice.number)
|
||||||
|
row.createCell(i++).setCellValue(invoice.date)
|
||||||
|
row.createCell(i++).setCellValue(invoice.poNum)
|
||||||
|
row.createCell(i++).setCellValue(invoice.status.toString())
|
||||||
|
row.createCell(i++).setCellValue(invoice.vendor?.name)
|
||||||
|
row.createCell(i++).setCellValue(invoice.vendor?.address)
|
||||||
|
|
||||||
|
//6 would be repeated
|
||||||
|
row.createCell(i++).setCellValue(invoice.products?.get(j)?.productId ?: "NA")
|
||||||
|
row.createCell(i++).setCellValue(invoice.products?.get(j)?.productName ?: "NA")
|
||||||
|
invoice.products?.get(j)?.let { row.createCell(i++).setCellValue(it.unitPrice) }
|
||||||
|
invoice.products?.get(j)?.let { row.createCell(i++).setCellValue(it.quantity) }
|
||||||
|
|
||||||
|
row.createCell(i++).setCellValue(invoice.totalAmount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveExcelFileLocally("Invoices.xls", wb)
|
||||||
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
//ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
|
//ImportFromExcel(FileType.QUOTES, "C:\\Users\\arsalan\\Downloads\\Book.xlsx")
|
||||||
TemplateExcelFile(FileType.PRODS)
|
TemplateExcelFile(FileType.PRODS)
|
||||||
|
|||||||
@ -246,7 +246,7 @@ fun searchInvoices(commonFilters: CommonFilters, invoiceFilters: InvoiceFilters)
|
|||||||
.where()
|
.where()
|
||||||
.ilike("number", "%" + invoiceFilters.numLike + "%")
|
.ilike("number", "%" + invoiceFilters.numLike + "%")
|
||||||
if (invoiceFilters.status != InvoiceStatus.ALL) {
|
if (invoiceFilters.status != InvoiceStatus.ALL) {
|
||||||
q.eq("status", invoiceFilters.status)
|
q.ne("status", invoiceFilters.status)
|
||||||
}
|
}
|
||||||
applyFromToHelper(q, commonFilters.from, commonFilters.to, "date")
|
applyFromToHelper(q, commonFilters.from, commonFilters.to, "date")
|
||||||
applyVendorHelper(q, commonFilters.vendor)
|
applyVendorHelper(q, commonFilters.vendor)
|
||||||
@ -258,8 +258,8 @@ fun searchPayments(commonFilters: CommonFilters, paymentFilters: PaymentFilters)
|
|||||||
val q = database.find(Payment::class.java)
|
val q = database.find(Payment::class.java)
|
||||||
.where()
|
.where()
|
||||||
.ilike("refNumber", "%" + paymentFilters.refNumberLike + "%")
|
.ilike("refNumber", "%" + paymentFilters.refNumberLike + "%")
|
||||||
.ge("amount", paymentFilters.amountExceeds)
|
// .ge("amount", paymentFilters.amountExceeds)
|
||||||
.le("amount", paymentFilters.amountLessThan)
|
//.le("amount", paymentFilters.amountLessThan)
|
||||||
applyFromToHelper(q, commonFilters.from, commonFilters.to, "date")
|
applyFromToHelper(q, commonFilters.from, commonFilters.to, "date")
|
||||||
applyVendorHelper(q, commonFilters.vendor)
|
applyVendorHelper(q, commonFilters.vendor)
|
||||||
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
applySortHelper(q, commonFilters.sortBy, commonFilters.sortAsc)
|
||||||
|
|||||||
@ -509,10 +509,12 @@ open class Payment : BaseTenantModel() {
|
|||||||
var amount: Double = 0.0
|
var amount: Double = 0.0
|
||||||
var date: LocalDate? = null
|
var date: LocalDate? = null
|
||||||
var remark: String? = null
|
var remark: String? = null
|
||||||
var excessAmount : Double ?= null
|
var amountDeducted: Double? = null
|
||||||
|
var excessAmount: Double? = null
|
||||||
|
|
||||||
@DbJsonB
|
@DbJsonB
|
||||||
var invoicesAffected: Map<Long, Double>? = null
|
var invoicesAffected: MutableMap<Long, Double>? = mutableMapOf()
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
var vendor: Vendor? = null
|
var vendor: Vendor? = null
|
||||||
}
|
}
|
||||||
2
src/main/resources/dbmigration/1.14.sql
Normal file
2
src/main/resources/dbmigration/1.14.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- apply alter tables
|
||||||
|
alter table payment add column if not exists amount_deducted float;
|
||||||
8
src/main/resources/dbmigration/model/1.14.model.xml
Normal file
8
src/main/resources/dbmigration/model/1.14.model.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
|
||||||
|
<changeSet type="apply">
|
||||||
|
<addColumn tableName="payment">
|
||||||
|
<column name="amount_deducted" type="double"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</migration>
|
||||||
Loading…
x
Reference in New Issue
Block a user