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 = inventory.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;
                            inventory.Update(inv, inv.Id);
                        }
                    }
                }
                var supplier = supplierService.GetById(master.SupplierID);

                // 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);
            }
        }