public int DeleteSales(SalesMaster salesMaster) { int num; try { IQueryable <SalesDetail> salesdetails = this.salesDetailsService.GetAll((SalesDetail a) => a.SalesMasterId == salesMaster.Id); foreach (SalesDetail item in salesdetails) { (new DBService <SalesDetail>()).Delete(item.Id); } this.serviceSalesMaster.Delete(salesMaster.Id); foreach (SalesDetail salesDetail in salesMaster.SalesDetails) { List <Inventory> existingItem = this.inventory.GetAll((Inventory a) => a.ProductId == salesDetail.ProductId && a.IsActive && a.WarehouseId == salesDetail.WarehouseId).ToList <Inventory>(); if (existingItem.Count > 0) { foreach (Inventory inv in existingItem) { inv.UpdatedDate = new DateTime?(DateTime.Now); inv.UpdatedBy = ""; Inventory nullable = inv; decimal? salesQty = inv.SalesQty; nullable.SalesQty = new decimal?((salesQty.HasValue ? salesQty.GetValueOrDefault() : 0 - salesDetail.Qty)); inv.BalanceQty = inv.BalanceQty + salesDetail.Qty; this.inventory.Update(inv, inv.Id); } } } Customer customer = this.customerService.GetById(new int?(salesMaster.CustomerID)); foreach (LedgerPosting item in this.ledgerService.GetAll(salesMaster.SalesInvoice, true)) { item.IsActive = false; this.ledgerService.Update(item, item.Id); } PartyBalanceService partyBalanceService = this.partyBalanceService; int? ledgerId = customer.LedgerId; PartyBalance paymentObj = partyBalanceService.GetByVoucher(customer.LedgerId ?? 0, salesMaster.SalesInvoice); this.partyBalanceService.Delete(paymentObj.PartyBalanceId); num = 1; } catch (Exception exception) { num = 0; } return(num); }
public int Delete(ReceiveMaster master) { try { var salesdetails = serviceDetails.GetAll(a => a.ReceiveMasterId == master.Id).ToList(); foreach (var item in salesdetails) { try { var isdetails = new DBService <ReceiveDetail>().Delete(item.Id); } catch (Exception ex) { } } var isDeleted = service.Delete(master.Id); foreach (var item in master.ReceiveDetails) { var existingItem = _inventoryService.GetAll(a => a.ProductId == item.ProductId && a.IsActive == true && a.WarehouseId == item.WarehouseId).ToList(); if (existingItem.Count > 0) { foreach (var inv in existingItem) { inv.UpdatedDate = DateTime.Now; inv.UpdatedBy = ""; inv.BalanceQty = inv.BalanceQty - item.Qty; inv.ReceiveQty = inv.ReceiveQty ?? 0 - item.Qty; _inventoryService.Update(inv, inv.Id); } } } var supplier = supplierService.GetById(master.SupplierID); foreach (LedgerPosting item in this.ledgerService.GetAllByInvoice(master.InvoiceNo, true)) { item.IsActive = false; this.ledgerService.Update(item, item.Id); } PartyBalanceService partyBalanceService = this.partyBalanceService; int? ledgerId = supplier.LedgerId; PartyBalance paymentObj = partyBalanceService.GetByInvoiceNo(supplier.LedgerId ?? 0, master.InvoiceNo); this.partyBalanceService.Delete(paymentObj.PartyBalanceId); // Ledger Saves credit //var ledgerObj = new LedgerPosting(); //ledgerObj.VoucherTypeId = (int)VoucherType.PurchaseInvoice; //ledgerObj.VoucherNo = master.InvoiceNoPaper; //ledgerObj.PostingDate = master.InvoiceDate; //ledgerObj.LedgerId = (int)DefaultLedger.PurchaseAccount; //ledgerObj.InvoiceNo = master.InvoiceNo; //ledgerObj.Debit = 0; //ledgerObj.Credit = master.GrandTotal; //ledgerObj.Extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo; //var save = ledgerService.Save(ledgerObj); //Ledger posting to customer ledger credit //var detailsLedger = new LedgerPosting(); //detailsLedger.VoucherTypeId = (int)VoucherType.PurchaseInvoice; //detailsLedger.VoucherNo = master.InvoiceNoPaper; //detailsLedger.PostingDate = master.InvoiceDate; //detailsLedger.LedgerId = supplier.LedgerId; //detailsLedger.InvoiceNo = master.InvoiceNo; //detailsLedger.Debit = master.GrandTotal; //detailsLedger.Credit = 0; //detailsLedger.Extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo; //var detailsLedgerResult = ledgerService.Save(detailsLedger); //var party = new PartyBalance(); //party.InvoiceNo = master.InvoiceNo; //party.LedgerId = supplier.LedgerId ?? 0; //party.Debit = master.GrandTotal; //party.CreditPeriod = 60; //party.Credit = 0; //party.FinancialYearId =CurrentSession.GetCurrentSession().FinancialYear; //party.PostingDate = master.InvoiceDate; //party.VoucherTypeId = (int)VoucherType.PurchaseInvoice; //party.extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo; //partyBalanceService.Save(party); return(1); } catch (Exception ex) { return(0); } }