public ActionResult ReceiveGeneralReturn(long salesReturnId, FormCollection collection) { try { var user = (ViewUser)Session["user"]; var returnById = _iProductReturnManager.GetSalesReturnBySalesReturnId(salesReturnId); returnById.IsGeneralReturn = true; //List<ViewReturnDetails> models = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList(); ICollection <ViewReturnDetails> returnDetailses = _iProductReturnManager.GetGeneralReturnDetailsByReturnId(salesReturnId); List <ViewReturnDetails> newReturnDetailsList = new List <ViewReturnDetails>(); var firstOrdefault = returnDetailses.FirstOrDefault(); if (firstOrdefault != null) { int branchId = Convert.ToInt32(Session["BranchId"]); var filePath = GetReceiveProductFilePath(salesReturnId, branchId); //------------read Scanned barcode form text file--------- var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); foreach (ViewReturnDetails item in returnDetailses) { item.UnitPrice = _iProductManager.GetProductDetailsByProductId(item.ProductId).UnitPrice; newReturnDetailsList.Add(item); } var grossAmount = newReturnDetailsList.Sum(n => (n.UnitPrice + n.VatAmount) * n.Quantity); var financialModel = new FinancialTransactionModel { //--------Expence Cr ------------------- ExpenceCode = "2601011", ExpenceAmount = grossAmount, //--------Inventory Dr ------------------- InventoryCode = "3301011", InventoryAmount = grossAmount }; var result = _iInventoryManager.ReceiveProduct(barcodeList, branchId, user.UserId, financialModel, returnById); if (result) { System.IO.File.Create(filePath).Close(); return(RedirectToAction("PendingReturnList")); } } return(View()); } catch (Exception exception) { Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }
public ActionResult Receive(long salesReturnId, FormCollection collection) { try { var user = (ViewUser)Session["user"]; var returnById = _iProductReturnManager.GetSalesReturnBySalesReturnId(salesReturnId); List <ViewReturnDetails> models = _iProductReturnManager.GetReturnDetailsBySalesReturnId(salesReturnId).ToList(); List <ViewReturnDetails> newReturnDetailsList = new List <ViewReturnDetails>(); var firstOrdefault = models.FirstOrDefault(); if (firstOrdefault != null) { var delivery = _iDeliveryManager.GetOrderByDeliveryId(firstOrdefault.DeliveryId); var invoicedOrder = _iInvoiceManager.GetInvoicedOrderByInvoiceId(delivery.InvoiceId); var deliveryDetails = _iDeliveryManager.GetDeliveryDetailsInfoByDeliveryId(firstOrdefault.DeliveryId); var orderInfo = _iOrderManager.GetOrderInfoByTransactionRef(delivery.TransactionRef); var client = _iClientManager.GetClientDeailsById(orderInfo.ClientId); int branchId = Convert.ToInt32(Session["BranchId"]); var filePath = GetReceiveProductFilePath(salesReturnId, branchId); //------------read Scanned barcode form text file--------- var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); var invoice = new ViewInvoiceModel { Order = orderInfo, DeliveryDetails = deliveryDetails, Client = client }; foreach (ViewReturnDetails item in models) { item.UnitPrice = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId) .UnitPrice; item.VatAmount = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId) .VatAmount; item.DiscountAmount = invoice.DeliveryDetails.ToList().Find(n => n.ProductId == item.ProductId) .UnitDiscount; newReturnDetailsList.Add(item); } var grossAmount = newReturnDetailsList.Sum(n => (n.UnitPrice + n.VatAmount) * n.Quantity); var tradeDiscount = newReturnDetailsList.Sum(n => n.DiscountAmount * n.Quantity); var invoiceDiscount = (invoicedOrder.SpecialDiscount / invoicedOrder.Quantity) * newReturnDetailsList.Sum(n => n.Quantity); var grossDiscount = tradeDiscount + invoiceDiscount; var vat = newReturnDetailsList.Sum(n => n.VatAmount * n.Quantity); var financialModel = new FinancialTransactionModel { //--------Cr ------------------- ClientCode = invoice.Client.SubSubSubAccountCode, ClientCrAmount = grossAmount - grossDiscount, GrossDiscountAmount = grossDiscount, GrossDiscountCode = "2102018", //--------Dr ------------------- SalesRevenueCode = "2001021", SalesRevenueAmount = grossAmount - vat, VatCode = "2102013", VatAmount = vat, //--------------Sales Return--------- SalesReturnAmount = returnById.LessAmount, SalesReturnCode = "1001022", ClientDrAmount = returnById.LessAmount, TradeDiscountCode = "2102012", TradeDiscountAmount = tradeDiscount, InvoiceDiscountAmount = invoiceDiscount, InvoiceDiscountCode = "2102011" }; var result = _iInventoryManager.ReceiveProduct(barcodeList, branchId, user.UserId, financialModel, returnById); if (result) { System.IO.File.Create(filePath).Close(); return(RedirectToAction("PendingReturnList")); } } return(View()); } catch (Exception exception) { Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }
//------------Receive Sales Return Product---------------- public bool ReceiveProduct(List <ScannedProduct> barcodeList, int branchId, int userId, FinancialTransactionModel financialModel, ReturnModel returnModel) { int rowAffected = _iInventoryGateway.ReceiveProduct(barcodeList, branchId, userId, financialModel, returnModel); return(rowAffected > 0); }
public ActionResult Delivery(FormCollection collection) { try { int branchId = Convert.ToInt32(Session["BranchId"]); int companyId = Convert.ToInt32(Session["CompanyId"]); var transport = collection["ownTransport"]; bool isOwnTransport = transport != null; int deliverebyUserId = ((ViewUser)Session["user"]).UserId; var requisitionId = Convert.ToInt64(collection["RequisitionId"]); var requisition = _iProductManager.GetGeneralRequisitionById(requisitionId); var details = _iProductManager.GetGeneralRequisitionDetailsById(requisitionId); string fileName = "Scanned_GR_Product_List_For_" + requisitionId; var filePath = Server.MapPath("~/Files/" + fileName); //if the file is exists read the file var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); var deliveredProductList = new List <ViewGeneralRequistionDetailsModel>(); foreach (ScannedProduct product in barcodeList.DistinctBy(n => n.ProductId)) { var model = details.ToList().Find(n => n.ProductId.Equals(product.ProductId)); var up = _iProductManager.GetProductDetailsByProductId(product.ProductId).UnitPrice; var qty = barcodeList.ToList().FindAll(n => n.ProductId == product.ProductId).Count; model.Quantity = qty; model.UnitPrice = up; deliveredProductList.Add(model); } var grossAmount = deliveredProductList.Sum(n => (n.UnitPrice + n.Vat) * n.Quantity); var financialModel = new FinancialTransactionModel { //--------Expence Dr ------------------- ExpenceCode = "2601011", ExpenceAmount = grossAmount, //--------Inventory Cr ------------------- InventoryCode = "3301011", InventoryAmount = grossAmount }; var aDelivery = new Delivery { IsOwnTransport = isOwnTransport, TransactionRef = requisition.RequisitionRef, InvoiceRef = requisition.RequisitionRef, DeliveredByUserId = deliverebyUserId, Transportation = collection["Transportation"], DriverName = collection["DriverName"], DriverPhone = collection["DriverPhone"], TransportationCost = Convert.ToDecimal(collection["TransportationCost"]), VehicleNo = collection["VehicleNo"], DeliveryDate = Convert.ToDateTime(collection["DeliveryDate"]).Date, CompanyId = companyId, ToBranchId = branchId, RequisitionId = requisitionId, FromBranchId = branchId, FinancialTransactionModel = financialModel }; var result = _iFactoryDeliveryManager.SaveDeliveredGeneralRequisition(barcodeList, aDelivery); if (result) { System.IO.File.Create(filePath).Close(); return(RedirectToAction("GeneralRequisitionList")); } return(View()); } catch (Exception exception) { TempData["Error"] = exception.Message; Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }
public ActionResult OrderDelivery(FormCollection collection) { try { var branchId = Convert.ToInt32(Session["BranchId"]); var user = (ViewUser)Session["user"]; var transport = collection["ownTransport"]; bool isOwnTransport = transport != null; int deliverebyUserId = ((ViewUser)Session["user"]).UserId; int invoiceId = Convert.ToInt32(collection["InvoiceId"]); var invoice = _iInvoiceManager.GetInvoicedOrderByInvoiceId(invoiceId); IEnumerable <InvoiceDetails> details = _iInvoiceManager.GetInvoicedOrderDetailsByInvoiceId(invoiceId); var client = _iClientManager.GetById(invoice.ClientId); var deliveredQty = _iInvoiceManager.GetDeliveredProductsByInvoiceRef(invoice.InvoiceRef).Count; var remainingToDeliverQty = invoice.Quantity - deliveredQty; string fileName = "Scanned_Ordered_Product_List_For_" + user.UserId + "_" + invoiceId; var filePath = Server.MapPath("~/Files/" + fileName); //if the file is exists read the file var barcodeList = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); int invoiceStatus = Convert.ToInt32(InvoiceStatus.PartiallyDelivered); int orderStatus = Convert.ToInt32(OrderStatus.PartiallyDelivered); if (remainingToDeliverQty == barcodeList.Count) { invoiceStatus = Convert.ToInt32(InvoiceStatus.Delivered); orderStatus = Convert.ToInt32(OrderStatus.Delivered); } List <InvoiceDetails> deliveredProductList = new List <InvoiceDetails>(); foreach (ScannedProduct product in barcodeList.DistinctBy(n => n.ProductId)) { var invoiceDetails = details.ToList().Find(n => n.ProductId.Equals(product.ProductId)); var qty = barcodeList.ToList().FindAll(n => n.ProductId == product.ProductId).Count; invoiceDetails.Quantity = qty; deliveredProductList.Add(invoiceDetails); } //-----------------Credit sale account code =1001021 --------------- //financialModel.InvoiceDiscountCode = "2102011"; //financialModel.InvoiceDiscountAmount = (invoice.SpecialDiscount/invoice.Quantity)*barcodeList.Count; //-----------------Credit vat account code =2102013 --------------- //-----------------Credit invoice discount account code =2102012 --------------- //var up= deliveredProductList.Sum(n => n.UnitPrice); // var discount = deliveredProductList.Sum(n => n.Discount); var grossAmount = deliveredProductList.Sum(n => (n.UnitPrice + n.Vat) * n.Quantity); var tradeDiscount = deliveredProductList.Sum(n => n.Discount * n.Quantity); var invoiceDiscount = (invoice.SpecialDiscount / invoice.Quantity) * barcodeList.Count; var grossDiscount = tradeDiscount + invoiceDiscount; var vat = deliveredProductList.Sum(n => n.Vat * n.Quantity); var financialModel = new FinancialTransactionModel { //--------Dr ------------------- ClientCode = client.SubSubSubAccountCode, ClientDrAmount = grossAmount - grossDiscount, GrossDiscountAmount = grossDiscount, GrossDiscountCode = "2102018", //--------Cr ------------------- //SalesRevenueCode = "1001021" old, SalesRevenueCode = "1001011", SalesRevenueAmount = grossAmount - vat, // VatCode = "2102013 test", VatCode = "3108011", VatAmount = vat, TradeDiscountCode = "2102012", TradeDiscountAmount = tradeDiscount, InvoiceDiscountAmount = invoiceDiscount, InvoiceDiscountCode = "2102011" }; var aDelivery = new Delivery { IsOwnTransport = isOwnTransport, TransactionRef = invoice.TransactionRef, InvoiceRef = invoice.InvoiceRef, DeliveredByUserId = deliverebyUserId, Transportation = collection["Transportation"], DriverName = collection["DriverName"], DriverPhone = collection["DriverPhone"], TransportationCost = Convert.ToDecimal(collection["TransportationCost"]), VehicleNo = collection["VehicleNo"], DeliveryDate = Convert.ToDateTime(collection["DeliveryDate"]).Date, CompanyId = invoice.CompanyId, ToBranchId = invoice.BranchId, DistributionPointId = branchId, InvoiceId = invoiceId, FromBranchId = invoice.BranchId, FinancialTransactionModel = financialModel, SpecialDiscount = invoiceDiscount }; //----------SMS Buildder Model----------- var aModel = new MessageModel { PhoneNumber = client.Phone.Replace("-", "").Trim(), CustomerName = client.ClientName, TotalQuantity = deliveredProductList.Sum(n => n.Quantity), Amount = financialModel.ClientDrAmount, TransactionDate = DateTime.Now, }; aDelivery.MessageModel = aModel; if (client.IsConsiderCreditLimit == 1) { var netAmount = grossAmount - grossDiscount; if (netAmount <= client.CreditLimit) { string result = _iInventoryManager.SaveDeliveredOrderFromFactory(barcodeList, aDelivery, invoiceStatus, orderStatus); aModel.MessageBody = aModel.GetMessageForDistribution(); if (result.StartsWith("S")) { System.IO.File.Create(filePath).Close(); //-----------Send SMS after successfull delivery info save------------ var res = _iCommonManager.SendSms(aModel); return(RedirectToAction("DeliverableOrderList")); } } else { TempData["CreditLimit"] = "Credit Limit exceed!!"; return(View()); } } else { string result = _iInventoryManager.SaveDeliveredOrderFromFactory(barcodeList, aDelivery, invoiceStatus, orderStatus); aModel.MessageBody = aModel.GetMessageForDistribution(); if (result.StartsWith("S")) { System.IO.File.Create(filePath).Close(); //-----------Send SMS after successfull delivery info save------------ var res = _iCommonManager.SendSms(aModel); return(RedirectToAction("DeliverableOrderList")); } return(View()); } return(View()); } catch (Exception exception) { TempData["Error"] = exception.Message; Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }