public static void updateinventorylogonproductcreate(data.dapper.product p) { if (p.quantity != 0) { var inventorylogrepo = new inventorylogrepo(); data.dapper.inventorylog ir = new inventorylog(); ir.quantity = p.quantity; ir.date = DateTime.Now; ir.fk_product_in_inventorylog = p.id; ir.note = "Added inventory on product create"; inventorylogrepo.save(ir); } }
void getone(int productid) { //var db = new dbctx(); selectedproduct = productrepo.get(productid); tb_name.Text = selectedproduct.name; tb_category.Text = selectedproduct.category; if (selectedproduct.saleprice != null) { tb_saleprice.Text = selectedproduct.saleprice.ToString(); } if (selectedproduct.purchaseprice != null) { tb_purchaseprice.Text = selectedproduct.purchaseprice.ToString(); } if (selectedproduct.discount != null) { tb_discount.Text = selectedproduct.discount.ToString(); } if (selectedproduct.carrycost != null) { tb_carrycost.Text = selectedproduct.carrycost.ToString(); } if (selectedproduct.barcode != null) { tb_barcode.Text = selectedproduct.barcode.ToString(); } if (selectedproduct.quantity != null) { tb_quantity.Text = selectedproduct.quantity.ToString(); } cbx_SaleActive.IsChecked = selectedproduct.saleactive; cbx_PurchaseActive.IsChecked = selectedproduct.purchaseactive; //var productsubs = db.productsub.Where(a => a.fk_product_product_productsub == productid).ToList(); var productsubs = this.productsubrepo.getproduct_productsubs(productid); foreach (var item in productsubs) { dg.Items.Add(item); } }
//inventorylogcomment argument for inserting value in inventory report to check wheather it is sold as it is on as a subproduct private static void recursiveupdateinventoryonpurchase(int productid, double productquantity, int purchaseid, string inventorylogcomment) { var productrepo = new productrepo(); data.dapper.product p = productrepo.get(productid); var productsubrepo = new productsubrepo(); var productsubs = productsubrepo.getproduct_productsubs(productid); if (productsubs.Count == 0) { // if products has no sub product. then its inventory will be updated, it is better approach for handling inventory of deal in case of purchase purchase p.quantity = p.quantity + productquantity; productrepo.update(p); updateinventorylogonpurchase(productid, productquantity, purchaseid, inventorylogcomment); } foreach (var productsub in productsubs) { recursiveupdateinventoryonpurchase(productsub.fk_product_sub_in_productsub, productquantity * productsub.quantity, purchaseid, ", purchased as sub of " + p.name); } }
private void btn_Save(object sender, RoutedEventArgs e) { if (tb_name.Text == "" || tb_saleprice.Text == "" || tb_purchaseprice.Text == "") { MessageBox.Show("Please fill form", "Information"); return; } if (this.createmode) { data.dapper.product r = new data.dapper.product(); r.name = tb_name.Text; r.barcode = tb_barcode.Text; r.category = tb_category.Text; r.saleprice = Convert.ToInt32(tb_saleprice.Text); r.purchaseprice = Convert.ToInt32(tb_purchaseprice.Text); if (tb_discount.Text != "") { try { r.discount = Convert.ToInt32(tb_discount.Text); } catch (Exception ex) { } } if (tb_carrycost.Text != "") { try { r.carrycost = Convert.ToInt32(tb_carrycost.Text); } catch (Exception ex) { } } r.quantity = 0; if (tb_quantity.Text != "") { try { r.quantity = Convert.ToDouble(tb_quantity.Text); }catch (Exception ex) { } } r.saleactive = cbx_SaleActive.IsChecked.Value; r.purchaseactive = cbx_PurchaseActive.IsChecked.Value; var savedproductresult = productrepo.save(r); if (savedproductresult) { inventoryutils.updateinventorylogonproductcreate(r); MessageBox.Show("Product saved", "Information"); Close(); new ProductAdd().Show(); } } else { selectedproduct.name = tb_name.Text; selectedproduct.barcode = tb_barcode.Text; selectedproduct.category = tb_category.Text; selectedproduct.saleprice = Convert.ToInt32(tb_saleprice.Text); selectedproduct.purchaseprice = Convert.ToInt32(tb_purchaseprice.Text); if (tb_discount.Text != "") { selectedproduct.discount = Convert.ToInt32(tb_discount.Text); } if (tb_carrycost.Text != "") { selectedproduct.carrycost = Convert.ToInt32(tb_carrycost.Text); } double selectedproductoldinventory = (selectedproduct.quantity != null)? (double)selectedproduct.quantity:0; if (tb_quantity.Text != "") { try { selectedproduct.quantity = Convert.ToDouble(tb_quantity.Text); } catch (Exception ex) { } } selectedproduct.saleactive = cbx_SaleActive.IsChecked.Value; selectedproduct.purchaseactive = cbx_PurchaseActive.IsChecked.Value; var updateproductresult = this.productrepo.update(selectedproduct); if (updateproductresult) { inventoryutils.updateinventorylogonproductupdate(selectedproduct.id, (double)selectedproduct.quantity, selectedproductoldinventory); MessageBox.Show("product update", "Information"); Close(); new ProductAdd(selectedproduct.id).Show(); } } }
public static int insertSaleTransactions(string accountname, List <productsaleorpurchaseviewmodel> saleList, double totalpayment, int targetuserid) { var loggedinuserid = userutils.loggedinuserd.id; //var db = new dbctx(); productrepo productrepo = new productrepo(); financeaccountrepo financeaccountrepo = new financeaccountrepo(); financetransactionrepo financetransactionrepo = new financetransactionrepo(); //List<financeaccount> accounts = db.financeaccount.ToList(); List <data.dapper.financeaccount> accounts = financeaccountrepo.get(); var saleaccountid = accounts.Where(a => a.name == accountname).FirstOrDefault().id; var discountaccountid = accounts.Where(a => a.name == "discount").FirstOrDefault().id; var cashaccountid = accounts.Where(a => a.name == "cash").FirstOrDefault().id; var accountreciveableaccountid = accounts.Where(a => a.name == "account receivable").FirstOrDefault().id; var cgsaccountid = accounts.Where(a => a.name == "cgs").FirstOrDefault().id; var inventoryaccountid = accounts.Where(a => a.name == "inventory").FirstOrDefault().id; double totalbill = 0; double costofgoodssold = 0; foreach (var item in saleList) { totalbill += (item.price * item.quantity); //product p = db.product.Find(item.id); data.dapper.product p = productrepo.get(item.id); double productcarrycost = 0; if (p.carrycost != null) { productcarrycost = (double)p.carrycost; } double productpurchaseprice = 0; if (p.purchaseprice != null) { productpurchaseprice = (double)p.purchaseprice; } costofgoodssold += ((double)((productpurchaseprice + productcarrycost) * item.quantity)); } //New Sale Transaction //financetransaction ftsale = new financetransaction(); data.dapper.financetransaction ftsale = new data.dapper.financetransaction(); ftsale.amount = -totalbill; ftsale.date = DateTime.Now; ftsale.status = "posted"; ftsale.fk_user_createdby_in_financetransaction = loggedinuserid; if (targetuserid != 0) { ftsale.fk_user_targetto_in_financetransaction = targetuserid; } ftsale.fk_financeaccount_in_financetransaction = saleaccountid; financetransactionrepo.save(ftsale); //db.financetransaction.Add(ftsale); //db.SaveChanges(); //New Payment Transaction against sale . if customer is paying some money if (totalpayment > 0) { //financetransaction ftpayment = new financetransaction(); data.dapper.financetransaction ftpayment = new data.dapper.financetransaction(); ftpayment.amount = totalpayment; ftpayment.date = DateTime.Now; ftpayment.status = "posted"; ftpayment.fk_user_createdby_in_financetransaction = loggedinuserid; if (targetuserid != 0) { ftpayment.fk_user_targetto_in_financetransaction = targetuserid; } ftpayment.fk_financeaccount_in_financetransaction = cashaccountid; //db.financetransaction.Add(ftpayment); //db.SaveChanges(); financetransactionrepo.save(ftpayment); } // New AR Transaction if Ledger is true if (totalpayment != totalbill) { //financetransaction ftar = new financetransaction(); data.dapper.financetransaction ftar = new data.dapper.financetransaction(); ftar.amount = totalbill - totalpayment; ftar.date = DateTime.Now; ftar.status = "posted"; ftar.fk_user_createdby_in_financetransaction = loggedinuserid; if (targetuserid != 0) { ftar.fk_user_targetto_in_financetransaction = targetuserid; } ftar.fk_financeaccount_in_financetransaction = accountreciveableaccountid; //db.financetransaction.Add(ftar); //db.SaveChanges(); financetransactionrepo.save(ftar); } // new cost of goods transaction against sale //financetransaction ftcgs = new financetransaction(); data.dapper.financetransaction ftcgs = new data.dapper.financetransaction(); ftcgs.amount = costofgoodssold; ftcgs.fk_financeaccount_in_financetransaction = cgsaccountid; ftcgs.date = DateTime.Now; ftcgs.status = "posted"; ftcgs.fk_user_createdby_in_financetransaction = loggedinuserid; //db.financetransaction.Add(ftcgs); //db.SaveChanges(); financetransactionrepo.save(ftcgs); // new inventory detct transaction against against sale //financetransaction ftid = new financetransaction(); data.dapper.financetransaction ftid = new data.dapper.financetransaction(); ftid.name = "--inventory--on--sale--"; ftid.amount = -costofgoodssold; ftid.fk_financeaccount_in_financetransaction = inventoryaccountid; ftid.date = DateTime.Now; ftid.status = "posted"; ftid.fk_user_createdby_in_financetransaction = loggedinuserid; //db.financetransaction.Add(ftid); //db.SaveChanges(); financetransactionrepo.save(ftid); return(ftsale.id); }
public void inventorylog(object sender, RoutedEventArgs e) { data.dapper.product obj = ((FrameworkElement)sender).DataContext as data.dapper.product; new Views.product.inventorylog(obj.id).Show(); }
public void edit(object sender, RoutedEventArgs e) { data.dapper.product obj = ((FrameworkElement)sender).DataContext as data.dapper.product; new ProductAdd(obj.id).Show(); }