public async Task <ActionResult <SalesMaster> > PostSalesMaster(SalesMaster salesMaster) { _context.SalesMasters.Add(salesMaster); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSalesMaster", new { id = salesMaster.ID }, salesMaster)); }
public async Task <IActionResult> PutSalesMaster(int id, SalesMaster salesMaster) { if (id != salesMaster.ID) { return(BadRequest()); } _context.Entry(salesMaster).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesMasterExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool Add(SalesMaster SalesMaster) { try { string connectionString = @"Server=FARHANAMOSTO-PC; Database=SmallBusiness; Integrated Security=True"; SqlConnection sqlConnection = new SqlConnection(connectionString); string commandString = @"INSERT INTO SalesMaster (CustomerID, Date,GrandTotal,Discount,DiscountAmount,PayableAmount) Values ('" + SalesMaster.CustomerID + "', '" + SalesMaster.Date + "'," + SalesMaster.GrandTotal + "," + SalesMaster.Discount + "," + SalesMaster.DiscountAmount + "," + SalesMaster.PayableAmount + ")"; SqlCommand sqlCommand = new SqlCommand(commandString, sqlConnection); sqlConnection.Open(); int isExecuted = sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); if (isExecuted > 0) { return(true); } else { return(false); } } catch { throw; } }
public SalesMaster SaveSalesMaster(SalesMaster salesMaster) { var result = serviceSalesMaster.Save(salesMaster); if (result != null || result.Id > 0) { foreach (var item in salesMaster.SalesDetails) { var existingItem = inventory.GetAll(a => a.ProductId == item.ProductId && a.IsActive == true && a.QtyInBale == item.BaleQty).ToList(); if (existingItem.Count > 0) { foreach (var inv in existingItem) { inv.UpdatedDate = DateTime.Now; inv.UpdatedBy = ""; inv.BalanceQty = inv.BalanceQty - item.BaleQty; inventory.Update(inv, inv.Id); } } } // Ledger Saves var ledgerObj = new LedgerPosting(); ledgerObj.YearId = 1; ledgerObj.VoucherTypeId = 14; ledgerObj.VoucherNo = result.SalesInvoice; ledgerObj.PostingDate = result.SalesDate; ledgerObj.LedgerId = 3; ledgerObj.InvoiceNo = result.SalesInvoice; ledgerObj.Credit = result.TotalAmount; ledgerObj.Debit = result.TotalAmount; var save = ledgerService.Save(ledgerObj); } return(result); }
private void btnPurchaseEntry_Click(object sender, EventArgs e) { SalesMaster pm = new SalesMaster(0); pm.ShowDialog(); dataGridBind(); }
public List <SalesDetail> GetAllSalesDetails(string voucherNo) { List <SalesDetail> salesDetails1; List <SalesDetail> salesDetails = new List <SalesDetail>(); SalesMaster sales = this.serviceSalesMaster.GetAll((SalesMaster a) => a.SalesInvoice == voucherNo && a.IsActive).FirstOrDefault <SalesMaster>(); salesDetails1 = (sales == null ? new List <SalesDetail>() : sales.SalesDetails.ToList <SalesDetail>()); return(salesDetails1); }
public ActionResult Add(SalesViewModel salesViewModel) { string message = ""; if (ModelState.IsValid) { var resetLoyaltyPoint = salesViewModel.LoyaltyPoint - (salesViewModel.LoyaltyPoint / 10); var newLoyaltyPoint = Convert.ToInt32(resetLoyaltyPoint + ((salesViewModel.GrandTotal) / 1000)); var customer = _customerManager.GetById(salesViewModel.CustomerId); customer.LoyaltyPoint = newLoyaltyPoint; _customerManager.Update(customer); salesViewModel.SalesCode = _salesManager.GetSalesCode(); SalesMaster salesMaster = Mapper.Map <SalesMaster>(salesViewModel); if (_salesManager.Add(salesMaster)) { message = "Sale Info Saved"; } else { message = "Sale Info not saved"; } } else { var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); message = "modelstate is invalid"; } ViewBag.Message = message; ModelState.Clear(); SalesViewModel emptySalesViewModel = new SalesViewModel(); emptySalesViewModel.CustomerSelectListItems = _customerManager.GetAll() .Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name }).ToList(); emptySalesViewModel.CategorySelectListItems = _categoryManager.GetAll() .Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name }).ToList(); return(View(emptySalesViewModel)); }
bool Delete(int SalesID) { //return objSalesMaster.Delete(p => p.SalesID == SalesID); objSalesMaster = objSalesMaster.Single(p => p.SalesID == SalesID); // totalpurchase-payments Double rest = objSalesMaster.Rest;//محصله الفاتوره النهائيه الا هى عباره عن اجمالى الفاتوره ناقص مدفوع العميل List <SalesDetail> itemslist = objSalesMaster.SalesDetails.ToList(); var payments = objSalesMaster.CustomersPayment; objCustomer = objSalesMaster.Customer; try { objSalesMaster.BeginTransaction(); //update Customer balance objCustomer.Balance -= rest; objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); //update products (store) itemslist.ForEach(p => { //update qty SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, p.Quantity); } ); // delete purchaseitems(PurchasesDetails) itemslist.DeleteAll(); //delete masetr(PurchasesMaster) objSalesMaster.Delete(p => p.SalesID == SalesID); //delete payments if (payments != null) { payments.Delete(p => p.CustomerPaymentID == payments.CustomerPaymentID); } objSalesMaster.EndTransaction(); } catch (Exception ex) { ExtenssionClass.Rollback(); Page.Show(ex.Message); return(false); } return(true); }
public async Task <ActionResult> Put([FromBody] SalesMaster value) { try { var result = await salesMasterService.Update(value); return(Ok(result)); } catch (Exception) { return(BadRequest()); } }
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.QtyInBale == (int?)salesDetail.Qty && 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); }
bool deleteSalesDetail(int SalesDetailID) { // objSalesDetail.BeginTransaction(); // objSalesDetail = objSalesDetail.Single(p => p.SalesDetailID == SalesDetailID); //// double Totalproductprice = objSalesDetail.Price * objSalesDetail.Quantity; // // update balance // objCustomer = objCustomer.Single(p => p.CustomerID == Convert.ToInt32(ddlCustomer.SelectedValue)); //// objCustomer.Balance =(objCustomer.Balance)- (Totalproductprice); // objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); // //update qty // SalesManager.UpdateproductQTY(QTYOperation.Increment, objSalesDetail.ProductID, objSalesDetail.Quantity); // // delete row // bool status = objSalesDetail.Delete(p => p.SalesDetailID == SalesDetailID); // objSalesDetail.EndTransaction(); // return status; objSalesDetail.BeginTransaction(); objSalesDetail = objSalesDetail.Single(p => p.SalesDetailID == SalesDetailID); //var payment = objPurchasesDetail.PurchasesMaster.PaymentsForSupplier; //payment.Delete(p => p.SupplierPaymentID == payment.SupplierPaymentID); objSalesMaster = objSalesDetail.SalesMaster; objSalesMaster.TotalSales -= objSalesDetail.TotalPrice; objSalesMaster.Rest -= objSalesDetail.TotalPrice; objSalesMaster.Update(p => p.SalesID == objSalesMaster.SalesID); hfOldRest.Value = objSalesMaster.Rest.ToString(); // update balance if (ddlCustomer.SelectedIndex > 0) { objCustomer = objCustomer.Single(p => p.CustomerID == objSalesDetail.SalesMaster.CustomerID); objCustomer.Balance = (objCustomer.Balance) - (objSalesDetail.TotalPrice); objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); } //update qty SalesManager.UpdateproductQTY(QTYOperation.Increment, objSalesDetail.ProductID, objSalesDetail.Quantity); bool status = objSalesDetail.Delete(p => p.SalesDetailID == SalesDetailID); objSalesDetail.EndTransaction(); return(status); }
public string submitOnlineSales(string companyCode, string json) { clsDataAccessor dataAccessor = new clsDataAccessor(); dataAccessor.connectionstring = dataAccessor.getConnectionString_Vapt(dataAccessor, companyCode); SalesMaster sales = new SalesMaster(); var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string response = ""; /* json = @"{""TransNo"":""A1234512"", * ""RetailID"":""ONLINE"", * ""SalesDate"":""2020/02/24 15:20:43"", * ""SalesStatus"":""SALES"", * ""MemberID"":""CUST917800001944774"", * ""SalesTaxType"":""I"", * ""SalesTaxRate"":""7"", * ""SalesTaxTtl"":""49"", * ""SalesRounding"":""0"", * ""SalesTotalAmount"":""700"", * ""ItemSales"":[{""ItemID"":""BSBN104"",""SupBarCode"":"""",""ItemSellPrice"":""350"",""ItemQty"":""2"", * ""ItemUOMDesc"":""Ctn (75gx72)"",""ItemDisc"":""0"",""ItemDisc2"":""0"",""ItemDisc3"":""0"", * ""ItemPrice"":""384.000"",""ItemTax"":""24.50"",""ItemTotal"":""700"", * ""ItemVoucher"":[{""VoucherNo"":""VC123"",""VoucherAmount"":""700"" * }] * }], * ""SalesPayments"":[{""paymentID"":"""",""strPayment"":""VISA"",""SalesPayTtl"":""700"", * ""SalesBalTtl"":""700"",""ChangeAmount"":""0"",""TipsAmount"":""0"", * ""SaleVoucher"":[{""VoucherNo"":""VC122"",""VoucherAmount"":""700"" * }] * }], * ""SalesPersons"":[] * }"; */ try { sales = serializer.Deserialize <SalesMaster>(json); } catch (Exception ex) { return(ex.ToString()); } response = dataAccessor.saveOnlineSales(sales); return(response); }
private void dgSalesDetails_DoubleClick(object sender, EventArgs e) { try { if (dgSalesDetails.CurrentRow.Index != -1 && dgSalesDetails.CurrentRow.Cells[1].Value != null) { var lID = Convert.ToInt32(dgSalesDetails.CurrentRow.Cells[0].Value); SalesMaster acc = new SalesMaster(lID); acc.ShowDialog(); dataGridBind(); } } catch (Exception x) { MessageBox.Show(x.ToString()); } }
private void dgSalesDetails_DoubleClick(object sender, EventArgs e) { try { if (dgSalesDetails.CurrentRow.Index != -1 && dgSalesDetails.CurrentRow.Cells[1].Value != null) { var lID = Convert.ToInt32(dgSalesDetails.CurrentRow.Cells[0].Value); SalesMaster acc = new SalesMaster(lID); acc.ShowDialog(); dataGridBind(); } } catch (Exception x) { MessageBox.Show("Something went wrong. Contact your system administrator"); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SalesMaster sales = salesService.GetById(id); if (sales == null) { return(HttpNotFound()); } //if (sales.SalesDate.Value.AddDays(3) > DateTime.Now) //{ // return View("Index"); //} sales.SalesDate = DateTime.Now; var result = salesService.DeleteSales(sales); return(View("Index")); }
void Dir(SalesMaster entity) { txtID.Text = entity.SalesID.ToString(); ddlCustomer.SelectedValue = (entity.CustomerID == null)?"0":entity.CustomerID.Value.ToString(); txtCustomerName.Text = entity.CustomerName; ddlEmployee.SelectedValue = (entity.EmployeeID != null) ? entity.EmployeeID.Value.ToString() : "0"; txtNotes.Text = entity.Notes; txtSalesDateM.Text = entity.SalesDateM.ToString("MM/dd/yyyy", culture); txtSalesDateH.Text = entity.SalesDateH; cboxIsCash.Checked = entity.IsCash; //oldCustomerid = entity.CustomerID; //oldPaymentType = entity.IsCash; FillgvProducts(entity.SalesID); lblTotalSalesPrice.Text = entity.TotalSales.ToString(); txtPayment.Text = entity.Payments.ToString(); hfOldRest.Value = lblRest.Text = entity.Rest.ToString(); lblCustomerBalance.Text = lblNewCustomerBalance.Text = (entity.CustomerID == null)?"0": entity.Customer.Balance.ToString(); ddlCustomer.Enabled = false; }
public void Update(SalesMaster salesMaster) { throw new NotImplementedException(); }
public bool Add(SalesMaster SalesMaster) { return(_SalesMasterRepository.Add(SalesMaster)); }
public SalesMaster SaveSalesMaster(SalesMaster salesMaster) { salesMaster.YearId = yearId; salesMaster.IsLastYear = true; SalesMaster result = this.serviceSalesMaster.Save(salesMaster); if ((result != null ? true : result.Id > 0)) { //foreach (SalesDetail salesDetail in salesMaster.SalesDetails) //{ //} Customer customer = this.customerService.GetById(new int?(salesMaster.CustomerID)); LedgerPosting ledgerObj = new LedgerPosting() { VoucherTypeId = new int?(19), VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate, LedgerId = (int)DefaultLedger.SalesAccount, InvoiceNo = result.SalesInvoice, Credit = new decimal?(result.GrandTotal) }; decimal num = new decimal(); ledgerObj.Debit = new decimal?(num); this.ledgerService.Save(ledgerObj); LedgerPosting detailsLedger = new LedgerPosting() { VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice, VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate, LedgerId = customer.LedgerId, InvoiceNo = result.SalesInvoice }; num = new decimal(); detailsLedger.Credit = new decimal?(num); detailsLedger.Debit = new decimal?(salesMaster.GrandTotal - salesMaster.Discount); this.ledgerService.Save(detailsLedger); if (salesMaster.Discount > 0) { LedgerPosting detailsLedgerDiscount = new LedgerPosting() { VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice, VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate, LedgerId = customer.LedgerId, InvoiceNo = result.SalesInvoice }; num = new decimal(); detailsLedger.Credit = new decimal?(num); detailsLedger.Debit = new decimal?(salesMaster.Discount); this.ledgerService.Save(detailsLedgerDiscount); } PartyBalance balance = new PartyBalance() { AgainstInvoiceNo = result.SalesInvoice, AgainstVoucherNo = result.SalesInvoice, AgainstVoucherTypeId = new int?(19), VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate }; PartyBalance partyBalance = balance; int? ledgerId = customer.LedgerId; partyBalance.LedgerId = (ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0); balance.InvoiceNo = result.SalesInvoice; balance.Debit = new decimal?(salesMaster.GrandTotal - salesMaster.Discount); num = new decimal(); balance.Credit = new decimal?(num); balance.VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice; balance.extra1 = string.Concat("Sales Invoice: ", salesMaster.SalesInvoice, " Challan:", salesMaster.Coutha); balance.extra2 = result.Id.ToString(); this.partyBalanceService.Save(balance); } return(result); }
public bool Add(SalesMaster salesMaster) { return(_salesRepository.Add(salesMaster)); }
public static string[] GetCompletionList(string prefixText, int count, string contextKey) { SalesMaster objSalesMaster = new SalesMaster(); return(objSalesMaster.Get(p => p.SalesID.ToString().ToLower().StartsWith(prefixText.ToLower()), p => p.SalesID.ToString()).ToArray()); }
public ActionResult SaveSales(List <SalesMaster> salesMasters, decimal Discount, List <SalesDetail> salesDetail, string DriverName, decimal RentAmount = 0.0m) { var salesinvoiceid = "DR" + DateTime.Now.Year + new GlobalClass().GetMaxId("Id", "SalesMaster"); decimal? deliveryQty; decimal baleQty; ActionResult actionResult; decimal? nullable; int customerId = 0; string message = ""; SalesMaster result = new SalesMaster(); result.SalesInvoice = salesinvoiceid; foreach (var item in salesMasters) { item.SalesInvoice = salesinvoiceid; } SalesMaster FinalResult = new SalesMaster(); FinalResult.SalesInvoice = salesinvoiceid; SalesDetail FinalResultDetail = new SalesDetail(); SalesOrder resultOrder = new SalesOrder(); SalesOrder FinalResultOrder = new SalesOrder(); List <int> lstSalesMasterId = new List <int>(); try { foreach (SalesMaster item in salesMasters) { customerId = item.CustomerID; result.SalesInvoice = item.SalesInvoice; result.SalesOrderId = item.SalesOrderId; result.SalesDate = item.SalesDate; if (!result.SalesDate.HasValue) { result.SalesDate = new DateTime?(DateTime.Now); } result.SalesBy = CurrentSession.GetCurrentSession().UserName; result.CustomerID = item.CustomerID; result.AdditionalCost = decimal.Zero; result.Discount = Discount; result.Notes = item.Notes; result.Coutha = item.Coutha; result.TransportNo = item.TransportNo; result.TransportType = item.TransportType; result.CreatedBy = CurrentSession.GetCurrentSession().UserName; result.CreatedDate = new DateTime?(DateTime.Now); result.IsActive = true; } result.TotalAmount = ( from a in salesMasters select a.TotalAmount).Sum(); result.GrandTotal = (( from a in salesMasters select a.TotalAmount).Sum() + result.AdditionalCost) - result.Discount; int count = 0; foreach (SalesDetail item in salesDetail) { SalesDetail resultDetail = new SalesDetail() { SalesMasterId = result.Id, SalesInvoice = result.SalesInvoice, ProductId = item.ProductId, Qty = item.Qty, SD = item.SD, Tax = item.Tax, Rate = item.Rate, Amount = item.Amount, Notes = FinalResult.Notes, CreatedBy = CurrentSession.GetCurrentSession().UserName, CreatedDate = new DateTime?(DateTime.Now), IsActive = new bool?(true), WarehouseId = item.WarehouseId }; result.SalesDetails.Add(resultDetail); count += item.Qty; } result.DriverName = DriverName; result.RentAmount = RentAmount; SalesMaster saved = this.salesService.SaveSalesMaster(result); actionResult = base.Json(FinalResult, 0); } catch (Exception exception) { exception.ErrorWritter(); actionResult = base.Json("Error", 0); } return(actionResult); }
public ActionResult Authorize(int id, bool isSendSMS) { var item = salesService.GetByTempId(id); decimal? deliveryQty; decimal baleQty; ActionResult actionResult; decimal? nullable; string message = ""; SalesMaster result = new SalesMaster(); result.SalesInvoice = item.SalesInvoice; SalesMaster FinalResult = new SalesMaster(); FinalResult.SalesInvoice = item.SalesInvoice; SalesDetail FinalResultDetail = new SalesDetail(); SalesOrder resultOrder = new SalesOrder(); SalesOrder FinalResultOrder = new SalesOrder(); List <int> lstSalesMasterId = new List <int>(); try { result.SalesInvoice = item.SalesInvoice; result.SalesOrderId = item.SalesOrderId; result.SalesDate = item.SalesDate; if (!result.SalesDate.HasValue) { result.SalesDate = new DateTime?(DateTime.Now); } result.SalesBy = CurrentSession.GetCurrentSession().UserName; result.CustomerID = item.CustomerID; result.AdditionalCost = decimal.Zero; result.Discount = item.Discount; result.Notes = item.Notes; result.Coutha = item.Coutha; result.TransportNo = item.TransportNo; result.TransportType = item.TransportType; result.CreatedBy = CurrentSession.GetCurrentSession().UserName; result.CreatedDate = new DateTime?(DateTime.Now); result.TotalAmount = item.TotalAmount; result.GrandTotal = item.GrandTotal; result.IsActive = true; int count = 0; foreach (TempSalesDetail itemDetails in item.TempSalesDetails) { SalesDetail resultDetail = new SalesDetail() { SalesMasterId = result.Id, SalesInvoice = result.SalesInvoice, ProductId = itemDetails.ProductId, Qty = itemDetails.BaleQty, SD = itemDetails.BaleWeight, Tax = itemDetails.TotalQtyInKG, Rate = itemDetails.Rate, Amount = itemDetails.Amount, Notes = FinalResult.Notes, CreatedBy = CurrentSession.GetCurrentSession().UserName, CreatedDate = new DateTime?(DateTime.Now), IsActive = new bool?(true), WarehouseId = itemDetails.WarehouseId }; count += itemDetails.BaleQty; result.SalesDetails.Add(resultDetail); } message = string.Concat(message, "Tk=", string.Format("{0:#,#.}", decimal.Round(result.GrandTotal), ""), "="); if (item.SalesOrder != null) { string orderid = ""; SalesOrder order = this.salesService.GetSalesOrderById(new int?(Convert.ToInt32(item.SalesOrderId))); orderid = string.Concat(",", order.SalesOrderId); message = string.Concat(message, orderid); } message = string.Concat(message, ",SO-", result.SalesInvoice); message = string.Concat(message, ",T/No:", item.TransportType + ",Mob:" + result.TransportNo); result.DriverName = item.DriverName; result.RentAmount = item.RentAmount; SalesMaster saved = this.salesService.SaveSalesMaster(result); if (item.SalesOrder != null) { item.SalesOrder.DeliveryDate = new DateTime?(DateTime.Now); SalesOrder order = this.salesService.GetSalesOrderById(new int?(Convert.ToInt32(item.SalesOrderId))); SalesOrder salesOrder = order; deliveryQty = order.DeliveryQty; baleQty = order.BaleQty; if (deliveryQty.HasValue) { nullable = new decimal?(deliveryQty.GetValueOrDefault() + baleQty); } else { nullable = null; } salesOrder.DeliveryQty = nullable; order.BaleQty = order.BaleQty - order.BaleQty; order.DeliveryDate = new DateTime?(DateTime.Now); order.IsActive = false; FinalResultOrder = this.salesService.Update(order, order.Id); } if (saved.Id > 0) { if (item.CustomerID != 0) { Customer customer = (new CustomerService()).GetById(new int?(item.CustomerID)); int? ledgerId = customer.LedgerId; rptIndividualLedger_Result due = customerService.GetBalance((ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0)); string balanceText = ""; deliveryQty = due.Balance; baleQty = new decimal(); if ((deliveryQty.GetValueOrDefault() < baleQty ? !deliveryQty.HasValue : true)) { deliveryQty = due.Balance; balanceText = string.Concat("Balance with Dada Rice Tk=", string.Format("{0:#,#.}", decimal.Round((deliveryQty.HasValue ? deliveryQty.GetValueOrDefault() : decimal.Zero)), ""), "="); } else { decimal minusOne = decimal.MinusOne; deliveryQty = due.Balance; balanceText = string.Concat("Balance with Dada Rice Tk=", string.Format("{0:#,#.}", minusOne * decimal.Round((deliveryQty.HasValue ? deliveryQty.GetValueOrDefault() : decimal.Zero)), ""), "="); } SMSEmailService sMSEmailService = new SMSEmailService(); string phone = customer.Phone; string[] str = new string[] { "Dear Customer,Del Qty=", count.ToString(), " BAGS ", message, ",Dated:", null, null, null }; str[5] = DateTime.Now.ToString("dd-MM-yyyy"); str[6] = "."; str[7] = balanceText; if (isSendSMS) { sMSEmailService.SendOneToOneSingleSms(phone, string.Concat(str)); } } //update temp item.IsActive = false; item.UpdatedDate = DateTime.Now.ToString(); this.salesService.Update(item, id); } var r = AutoMapper.Mapper.Map <SalesMaster, SalesMasterResponse>(saved); actionResult = base.Json(r, 0); } catch (Exception exception) { exception.ErrorWritter(); actionResult = base.Json("Error", 0); } return(actionResult); }
public SalesMaster SaveSalesMaster(SalesMaster salesMaster) { salesMaster.YearId = yearId; SalesMaster result = this.serviceSalesMaster.Save(salesMaster); if ((result != null ? true : result.Id > 0)) { 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() : salesDetail.Qty)); inv.BalanceQty = inv.BalanceQty - salesDetail.Qty; this.inventory.Update(inv, inv.Id); } } } Customer customer = this.customerService.GetById(new int?(salesMaster.CustomerID)); LedgerPosting ledgerObj = new LedgerPosting() { VoucherTypeId = new int?(19), VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate, LedgerId = new int?(10), InvoiceNo = result.SalesInvoice, Credit = new decimal?(result.GrandTotal) }; decimal num = new decimal(); ledgerObj.Debit = new decimal?(num); this.ledgerService.Save(ledgerObj); LedgerPosting detailsLedger = new LedgerPosting() { VoucherTypeId = new int?(19), VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate, LedgerId = customer.LedgerId, InvoiceNo = result.SalesInvoice }; num = new decimal(); detailsLedger.Credit = new decimal?(num); detailsLedger.Debit = new decimal?(salesMaster.GrandTotal); this.ledgerService.Save(detailsLedger); PartyBalance balance = new PartyBalance() { AgainstInvoiceNo = result.SalesInvoice, AgainstVoucherNo = result.SalesInvoice, AgainstVoucherTypeId = new int?(19), VoucherNo = result.SalesInvoice, PostingDate = salesMaster.SalesDate }; PartyBalance partyBalance = balance; int? ledgerId = customer.LedgerId; partyBalance.LedgerId = (ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0); balance.InvoiceNo = result.SalesInvoice; balance.Debit = new decimal?(salesMaster.GrandTotal); num = new decimal(); balance.Credit = new decimal?(num); balance.VoucherTypeId = 19; balance.extra1 = string.Concat("Sales Invoice: ", salesMaster.SalesInvoice, " Challan:", salesMaster.Coutha); balance.extra2 = result.Id.ToString(); this.partyBalanceService.Save(balance); } return(result); }
bool Insert() { objSalesMaster = new SalesMaster(); objSalesMaster.CustomerID = (ddlCustomer.SelectedIndex == 0)?null:(Nullable <int>)Convert.ToInt32(ddlCustomer.SelectedValue); objSalesMaster.CustomerName = txtCustomerName.Text; objSalesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null; objSalesMaster.Notes = txtNotes.Text.Trim(); objSalesMaster.SalesDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture); objSalesMaster.SalesDateH = txtSalesDateH.Text.Trim(); objSalesMaster.IsCash = cboxIsCash.Checked; // new------------------- objSalesMaster.TotalSales = Convert.ToDouble(lblTotalSalesPrice.Text); objSalesMaster.Rest = Convert.ToDouble(lblRest.Text); double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0"); objSalesMaster.Payments = Payments; //----------- List <SalesDetail> saleslist = new List <SalesDetail>(); saleslist = CurrentgvProducts(gvProducts); saleslist.ForEach(p => { p.Quantity = SalesManager.UnitConvert(p.UnitID, p.SQTY); p.UnitPrice = SalesManager.UnitPriceConvert(p.UnitID, p.SUnitPrice); p.BasicUnitID = SalesManager.getBasicUnitID; }); //var q = saleslist.Select(p => new { SalesID = p["SalesID"], ProductID = p["ProductID"] }).GroupBy(p => p.ProductID).Select(z => new { ProductID = z.Key, Count = z.Count() }).Where(p => p.Count > 1); //if (q.Count() > 0) //{ // MessageBox.Show(this.Page, "Cant Insert same Product more than once in Sales."); // return false ; //} // double TotalSalesPrice = saleslist.Sum(p=> (p.Quantity*p.Price)); objSalesMaster.SalesDetails.AddRange(saleslist); objSalesMaster.BeginTransaction(); // update qty product in store(table product) saleslist.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity)); if (Payments > 0) { CustomersPayment CustomersPayment = new CustomersPayment(); CustomersPayment.CustomerID = objSalesMaster.CustomerID; CustomersPayment.PaymentDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture); CustomersPayment.PaymentDateH = txtSalesDateH.Text.Trim(); CustomersPayment.Payment = Payments; objSalesMaster.CustomerPaymentID = Convert.ToInt32(CustomersPayment.Insert()); } objSalesMaster.Insert(); if (cboxIsCash.Checked != true) { if (ddlCustomer.SelectedIndex > 0) { objCustomer = objCustomer.Single(p => p.CustomerID == int.Parse(ddlCustomer.SelectedValue)); objCustomer.Balance += objSalesMaster.Rest;; objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); } } objSalesMaster.EndTransaction(); return(true); }
bool Update() { objSalesMaster = new SalesMaster(); objSalesMaster = objSalesMaster.Single(p => p.SalesID == Convert.ToInt32(txtID.Text.Trim())); objSalesMaster.CustomerName = txtCustomerName.Text; objSalesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null; //objSalesMaster.CustomerID = int.Parse(ddlCustomer .SelectedValue);//? objSalesMaster.Notes = txtNotes.Text.Trim(); objSalesMaster.SalesDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture); objSalesMaster.SalesDateH = txtSalesDateH.Text.Trim(); objSalesMaster.IsCash = cboxIsCash.Checked; double oldrest = objSalesMaster.Rest; bool oldPaymentType = objSalesMaster.IsCash; int? paymentid = objSalesMaster.CustomerPaymentID; objSalesMaster.TotalSales = Convert.ToDouble(lblTotalSalesPrice.Text); objSalesMaster.Rest = Convert.ToDouble(lblRest.Text); double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0"); objSalesMaster.Payments = Payments; objSalesMaster.BeginTransaction(); CustomersPayment CustomersPayment = new CustomersPayment(); if (paymentid == null) { if (Payments > 0) { CustomersPayment.CustomerID = objSalesMaster.CustomerID;; CustomersPayment.PaymentDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture); CustomersPayment.PaymentDateH = txtSalesDateH.Text.Trim(); CustomersPayment.Payment = Payments; CustomersPayment.CustomerPaymentID = Convert.ToInt32(CustomersPayment.Insert()); } } else if (paymentid != null) { CustomersPayment = objSalesMaster.CustomersPayment; CustomersPayment.PaymentDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture); CustomersPayment.PaymentDateH = txtSalesDateH.Text.Trim(); CustomersPayment.Payment = Payments; CustomersPayment.Update(p => p.CustomerPaymentID == CustomersPayment.CustomerPaymentID); } objSalesMaster.Update(p => p.SalesID == objSalesMaster.SalesID); //var q=objPurchasesDetail.Filter(p => p.PurchaseID == objPurchasesMaster.PurchaseID).Select(p => (p.TotalPrice )); //double oldTotalPurchasePrice =(q!=null )?q.Sum():0.0; List <SalesDetail> SalesList = CurrentgvProducts(gvProducts); SalesList.ForEach(p => { p.Quantity = SalesManager.UnitConvert(p.UnitID, p.SQTY); p.UnitPrice = SalesManager.UnitPriceConvert(p.UnitID, p.SUnitPrice); p.BasicUnitID = SalesManager.getBasicUnitID; }); //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice ); List <SalesDetail> newSalesList = SalesList.Where(p => p.SalesDetailID == 0).ToList(); List <SalesDetail> updateSalesList = SalesList.Where(p => p.SalesDetailID > 0).ToList(); if (newSalesList.Count > 0) { newSalesList.ForEach(p => p.SalesID = objSalesMaster.SalesID); newSalesList.InsertAll(); // update qty product in store(table product) newSalesList.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity)); } if (updateSalesList.Count > 0) { updateSalesList.ForEach(p => { p.Update(z => z.SalesDetailID == p.SalesDetailID); SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, (p.Quantity - p.oldQty)); }); } //========= composite calcualtion balance --- compare between old value and new value if (oldPaymentType != true)// not cash { if (ddlCustomer.SelectedIndex > 0) { // any way( - balance) form old supplier if user change supplier objCustomer = objCustomer.Single(p => p.CustomerID == objSalesMaster.CustomerID); objCustomer.Balance -= oldrest; // objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID); if (cboxIsCash.Checked != true)// if (not cash) add new price to balance { //objSupplier = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue)); objCustomer.Balance += objSalesMaster.Rest; } objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); } } else if (oldPaymentType == true) // cash { if (cboxIsCash.Checked != true) // if user change to (not cash) will add new price to supplier balance { if (ddlCustomer.SelectedIndex > 0) { objCustomer = objCustomer.Single(p => p.CustomerID == objSalesMaster.CustomerID); objCustomer.Balance += objSalesMaster.Rest; objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID); } } } objSalesMaster.EndTransaction(); return(true); }
public ActionResult SaveSales(List <SalesMaster> salesMasters, List <SalesDetail> salesDetail, List <SalesOrder> salesOrders, List <string> lstDeliveryQunatities) { foreach (var VARIABLE in salesMasters) { VARIABLE.SalesDetails = salesDetail; } SalesMaster result = new SalesMaster(); SalesMaster FinalResult = new SalesMaster(); SalesDetail resultDetail = new SalesDetail(); SalesDetail FinalResultDetail = new SalesDetail(); SalesOrder resultOrder = new SalesOrder(); SalesOrder FinalResultOrder = new SalesOrder(); List <int> lstSalesMasterId = new List <int>(); foreach (var item in salesMasters) { result.SalesInvoice = item.SalesInvoice; result.SalesOrderId = item.SalesOrderId; result.SalesDate = item.SalesDate; result.SalesBy = CurrentSession.GetCurrentSession().UserName; result.CustomerID = item.CustomerID; result.AdditionalCost = 0; result.Discount = item.Discount; result.TotalAmount = item.TotalAmount; result.Notes = item.Notes; result.CreatedBy = CurrentSession.GetCurrentSession().UserName; result.CreatedDate = DateTime.Now; result.IsActive = true; // FinalResult = salesService.SaveSalesMaster(result); // lstSalesMasterId.Add(FinalResult.Id); } // int count = 0; foreach (var item in salesDetail) { //resultDetail.SalesMasterId = lstSalesMasterId[count]; // count++; resultDetail.SalesMasterId = result.Id; resultDetail.SalesInvoice = result.SalesInvoice; resultDetail.ProductId = item.ProductId; resultDetail.BaleQty = item.BaleQty; resultDetail.BaleWeight = item.BaleWeight; resultDetail.TotalQtyInKG = item.TotalQtyInKG; resultDetail.Rate = item.Rate; resultDetail.Amount = item.Amount; resultDetail.Notes = FinalResult.Notes; resultDetail.CreatedBy = CurrentSession.GetCurrentSession().UserName; resultDetail.CreatedDate = DateTime.Now; resultDetail.IsActive = true; result.SalesDetails.Add(resultDetail); } var saved = salesService.SaveSalesMaster(result); for (int i = 0; i < salesOrders.Count; i++) { salesOrders[i].DeliveryQty = salesOrders[i].DeliveryQty + decimal.Parse(lstDeliveryQunatities[i]); //salesOrders[i].DeliveryDate = DateTime.Now; //salesOrders[i].CreatedDate = DateTime.Now; //salesOrders[i].OrderDate = DateTime.Now; //salesOrders[i].PricingDate = DateTime.Now; salesOrders[i].DeliveryDate = DateTime.Parse(salesOrders[i].DeliveryDate.ToString()); salesOrders[i].CreatedDate = DateTime.Parse(salesOrders[i].CreatedDate.ToString()); salesOrders[i].OrderDate = DateTime.Parse(salesOrders[i].OrderDate.ToString()); salesOrders[i].PricingDate = DateTime.Parse(salesOrders[i].PricingDate.ToString()); FinalResultOrder = salesService.Update(salesOrders[i], salesOrders[i].Id); } return(Json(FinalResult, JsonRequestBehavior.AllowGet)); }
public bool Add(SalesMaster salesMaster) { _dbContext.SalesMasters.Add(salesMaster); return(_dbContext.SaveChanges() > 0); }