public static string invoiceItemData(dynamic log_invoice) { string json = ""; InvoiceItemModel invitem = new InvoiceItemModel(); dynamic invoice_item = invitem.find(invitem, log_invoice.ref_id); if (invoice_item != null) { dynamic dataObject = new ExpandoObject(); dataObject.id = log_invoice.id; dataObject.key = log_invoice.action; dataObject.trackable_id = invoice_item.id; dataObject.trackable_type = log_invoice.model; if (log_invoice.action != "delete") { dynamic data = new ExpandoObject(); data.global_id = invoice_item.id; data.name = invoice_item.name; data.date = invoice_item.date; data.invoice_global_id = invoice_item.invoice_id; data.product_id = invoice_item.product_id; data.price = invoice_item.price; data.total = invoice_item.total; data.quantity = invoice_item.quantity; data.unit = invoice_item.unit; data.vat = invoice_item.vat; data.discount = invoice_item.discount; dataObject.data = data; } json = JsonConvert.SerializeObject(dataObject); } return(json); }
public void addProduct(dynamic product) { if (this.inv != null) { int existing_item = searchExistingItem(product.id); if (existing_item != -1) { DataGridViewRow selected_row = invoiceItems.Rows[existing_item]; int quantity = Int32.Parse(selected_row.Cells["quantity"].Value.ToString()); string item_id = selected_row.Cells["invoiceItemId"].Value.ToString(); double total = product.sale_price; this.inv.invoice_total += total; quantity += 1; InvoiceItemModel inv_item = new InvoiceItemModel(); dynamic obj_invoice_item = inv_item.find(inv_item, item_id); if (obj_invoice_item != null) { total *= quantity; selected_row.Cells["quantity"].Value = quantity; selected_row.Cells["total"].Value = total; double invoiceVat = product.sale_price * (product.vat / 100); this.inv.vat += invoiceVat; obj_invoice_item.quantity = quantity; obj_invoice_item.total = total; obj_invoice_item.vat = invoiceVat * quantity; obj_invoice_item.save(obj_invoice_item); barcodeInput.Text = ""; updateAmount(); } else { MessageDialog.ShowAlert("Unable to process the product item!"); } } else { topDisplay.Text = "1" + product.unit + " @ " + Math.Round(product.sale_price, 2) + " Tk"; double total = product.sale_price * 1; total = Math.Round(total, 2); this.inv.invoice_total += total; //calculate vat per product double vat = product.sale_price * (product.vat / 100); //add per product vat to total vat this.inv.vat += vat; string item_id = createLineItem(product); this.invoiceItems.Rows.Add(product.id, item_id, product.barcode, product.name, product.unit, Math.Round(product.sale_price, 2), 1, Math.Round(product.vat, 2), "0%", total); barcodeInput.Text = ""; updateAmount(); } } else { MessageBox.Show("Invoice not initialize", "No invoice"); } }