public static void printDuplicateRecipt(int saleid) { var financetransactionrepo = new financetransactionrepo(); var userrepo = new userrepo(); var productrepo = new productrepo(); var productsalepurchaserepo = new productsalepurchaserepo(); var ft = financetransactionrepo.get(saleid); data.dapper.user customer = null; if (ft.fk_user_targetto_in_financetransaction != null) { customer = userrepo.get((int)ft.fk_user_targetto_in_financetransaction); } // var soldproducts = db.productsalepurchase.Where(a => a.fk_financetransaction_in_productsalepurchase == saleid).ToList(); var soldproducts = productsalepurchaserepo.getmultiplebytransactionid(saleid); float totalbill = 0; var salelist = new List <productsaleorpurchaseviewmodel>(); foreach (var item in soldproducts) { totalbill = totalbill + (float)(item.price * item.quantity); //var dbproduct = db.product.Find(item.fk_product_in_productsalepurchase); var dbproduct = productrepo.get((int)item.fk_product_in_productsalepurchase); var p = new productsaleorpurchaseviewmodel(); p.id = dbproduct.id; p.name = dbproduct.name; p.price = (double)item.price; p.quantity = (double)item.quantity; p.total = (double)item.total; } ; //int salesId, List< ItemOrDealSaleModel > list, int totalBill,int remaining, int saleType,string customerAddress string customerAddress = ""; if (customer != null) { customerAddress = customer.address + " " + customer.phone; } printing.printSaleReceipt(saleid, salelist, (int)totalbill, (int)totalbill, 0, false, customerAddress); }
//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); } }
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); }