Beispiel #1
0
        public ResponseModel UpdteInvoiceDataByOutletSaleInvoiceNo(InvOutletInvoiceMaster aObj)
        {
            try
            {
                DateTime aDate = DateTime.Now;
                InvOutletInvoiceMaster aOutletSaleInvoiceMaster = _db.InvOutletInvoiceMasters.Where(aa => aa.OutletSaleInvoiceNo == aObj.OutletSaleInvoiceNo).FirstOrDefault();



                aOutletSaleInvoiceMaster.ModifiedDate = aDate;
                aOutletSaleInvoiceMaster.Cash         = aObj.Cash;
                aOutletSaleInvoiceMaster.Credit       = aObj.Credit;
                aOutletSaleInvoiceMaster.Rounding     = aObj.Rounding;
                aOutletSaleInvoiceMaster.PaidAmount   = aObj.PaidAmount;
                aOutletSaleInvoiceMaster.DueOrRefund  = aObj.DueOrRefund;

                _db.InvOutletInvoiceMasters.Attach(aOutletSaleInvoiceMaster);
                _db.Entry(aOutletSaleInvoiceMaster).State = EntityState.Modified;
                _db.SaveChanges();
                return(_aModel.Respons(true, " Successfully Updated data by Invoive No."));
            }
            catch (Exception e)
            {
                return(_aModel.Respons(false, "Sorry! Some  Error Happned"));
            }
        }
Beispiel #2
0
        //////////GET: /Inventory/OutletInvoice/UpdteInvoiceDataByOutletSaleInvoiceNo
        public JsonResult UpdteInvoiceDataByOutletSaleInvoiceNo(InvOutletInvoiceMaster aObj)
        {
            var data = _aManager.UpdteInvoiceDataByOutletSaleInvoiceNo(aObj);

            return(Json(data, JsonRequestBehavior.AllowGet));;
        }
        public ResponseModel CreateOutletSaleUIDetails(OutletSaleUIDetailsViewModel OutletSaleUIData, List <OutletSaleUIVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;


                    InvOutletInvoiceMaster aOutletSaleInvoiceMaster = new InvOutletInvoiceMaster()
                    {
                        OutletInvoiceMasterId = OutletSaleUIData.OutletInvoiceMasterId,
                        OutletSaleInvoiceNo   = Convert.ToInt32(_invoiceNo.GetNewInvoiceNo()),
                        //OutletId = OutletSaleUIData.OutletId,
                        OutletId     = 1,
                        CustomerId   = 1, //// Now default value is 1 but after add Identity it will be >> CustomerId = OutletSaleUIData.CustomerId,
                        SalePersonId = 1, /////Now default value is 1 but after add Identity it will be >>SalePersonId = OutletSaleUIData.SalePersonId,


                        TotalItem       = OutletSaleUIData.TotalItem,
                        TotalGrandPrice = OutletSaleUIData.TotalGrandPrice,
                        VAT             = OutletSaleUIData.VAT,
                        PaymentMode     = OutletSaleUIData.PaymentMode,
                        Cash            = OutletSaleUIData.Cash,
                        Credit          = OutletSaleUIData.Credit,
                        Discount        = OutletSaleUIData.Discount,
                        Rounding        = OutletSaleUIData.Rounding,
                        PayableAmount   = OutletSaleUIData.PayableAmount,
                        PaidAmount      = OutletSaleUIData.PaidAmount,
                        DueOrRefund     = OutletSaleUIData.DueOrRefund,

                        //IsFullPaid = OutletSaleUIData.IsFullPaid,
                        IsActive  = true,
                        IsChanged = false,
                        IsDeleted = false,
                        IsEdited  = false,


                        IsReturned  = -1,////////
                        Status      = 2,
                        Note        = "Sold",
                        CreatedDate = DateTime.Now,
                    };
                    aOutletSaleInvoiceMaster.IsFullPaid = OutletSaleUIData.DueOrRefund <= 0;   //////////OR, if (OutletSaleUIData.DueOrRefund <= 0) { aOutletSaleInvoiceMaster.IsFullPaid = true; } else { aOutletSaleInvoiceMaster.IsFullPaid = false; }
                    //aOutletSaleInvoiceMaster.OutletSaleInvoiceNo = aDate.Year +''+ aDate.Month +''+ aDate.Day +''+ aOutletSaleInvoiceMaster.OutletId;
                    // var invoiceId = aDate.Year().toString().substr(2) + "" + (aDate.Month() + 1) + "" + (aDate.Day() + "" + 1);

                    if (OutletSaleUIData.OutletInvoiceMasterId == 0)
                    {
                        if ((OutletSaleUIData.Cash > 0) && (OutletSaleUIData.Credit <= 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Cash";
                        }
                        else if ((OutletSaleUIData.Credit > 0) && (OutletSaleUIData.Cash <= 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Credit";
                        }
                        else if ((OutletSaleUIData.Cash > 0) && (OutletSaleUIData.Credit > 0) && (OutletSaleUIData.PaidAmount > 0))
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "Cash & Credit";
                        }
                        else
                        {
                            aOutletSaleInvoiceMaster.PaymentMode = "None";
                        }
                        _db.InvOutletInvoiceMasters.Add(aOutletSaleInvoiceMaster);
                        _db.SaveChanges();


                        foreach (var aData in productList)
                        {
                            //break;
                            InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                            {
                                OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                                ProductId             = aData.ProductId,
                                ProductQuantity       = aData.ProductQuantity,
                                Discount = aData.Discount,
                                //DiscountPercent = aData.DiscountPercent,
                                UnitPrice   = aData.UnitPrice,
                                TotalPrice  = aData.TotalPrice,
                                IsActive    = true,
                                IsChanged   = false,
                                IsDeleted   = false,
                                IsEdited    = false,
                                IsReturned  = -1,
                                Note        = "Sold",
                                CreatedDate = DateTime.Now
                            };
                            _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                            _db.SaveChanges();

                            InvOutletStock aStock = new InvOutletStock()
                            {
                                ProductId = aData.ProductId,
                                //OutletId = aData.OutletId,
                                OutletId            = aOutletSaleInvoiceMaster.OutletId,
                                IsActive            = true,
                                IsChanged           = false,
                                IsDeleted           = false,
                                IsEdited            = false,
                                IsReturned          = -1,
                                InOut               = 2,
                                Note                = "Sold",
                                OutletStockQuantity = aData.ProductQuantity,
                                CreatedDate         = DateTime.Now
                            };
                            _db.InvOutletStocks.Add(aStock);
                            _db.SaveChanges();
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                        var invoiceData = _db.spSaleInvoice(aOutletSaleInvoiceMaster.OutletSaleInvoiceNo).ToList();
                        //return _aModel.Respons(true, "Sale Info Successfully Saved");
                        return(_aModel.Respons(invoiceData));
                    }

                    else if (OutletSaleUIData.OutletInvoiceMasterId > 0)
                    {
                        _db.InvOutletInvoiceMasters.Attach(aOutletSaleInvoiceMaster);
                        _db.Entry(aOutletSaleInvoiceMaster).State = EntityState.Modified;
                        _db.SaveChanges();

                        var invOutletInvoice = _db.InvOutletInvoiceDetails.Find(OutletSaleUIData.OutletInvoiceDetailsId);

                        invOutletInvoice.IsActive     = false;
                        invOutletInvoice.ModifiedDate = DateTime.Now;

                        _db.InvOutletInvoiceDetails.Attach(invOutletInvoice);
                        _db.Entry(invOutletInvoice).State = EntityState.Modified;
                        _db.SaveChanges();

                        foreach (var aData in productList)
                        {
                            InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                            {
                                OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                                ProductId             = aData.ProductId,
                                ProductQuantity       = aData.ProductQuantity,
                                CreatedDate           = DateTime.Now,
                            };
                            _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                            _db.Entry(aOutletSaleInvoiceDetails).State = EntityState.Modified;
                            _db.SaveChanges();
                        }
                        transaction.Commit();
                        return(_aModel.Respons(true, "Successfully Updated  Sale Data"));
                    }
                    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry Failed to Update  Sale Data"));
                }
                catch (Exception ex)
                {
                    //_db.SaveChanges();
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }
Beispiel #4
0
        public ResponseModel UpdteInvoiceForDuePaymentReturn(OutletSaleUIDetailsViewModel OutletSaleUIData, List <OutletSaleUIVM> productList)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    DateTime aDate = DateTime.Now;

                    var newInvoiceNo = _invoiceNo.GetNewInvoiceNo();

                    var toBeUpdatedInvoice = _aRepository.SelectedById(OutletSaleUIData.OutletInvoiceMasterId);
                    toBeUpdatedInvoice.IsActive   = false;
                    toBeUpdatedInvoice.NewInvoice = newInvoiceNo;//OutletSaleUIData.OutletSaleInvoiceNo.ToString();
                    // toBeUpdatedInvoice.

                    _db.InvOutletInvoiceMasters.Attach(toBeUpdatedInvoice);
                    _db.Entry(toBeUpdatedInvoice).State = EntityState.Modified;
                    _db.SaveChanges();
                    InvOutletInvoiceMaster aOutletSaleInvoiceMaster = new InvOutletInvoiceMaster()
                    {
                        OutletInvoiceMasterId = 0,
                        OutletSaleInvoiceNo   = Convert.ToInt32(newInvoiceNo),
                        //OutletId = OutletSaleUIData.OutletId,
                        OutletId     = 1,
                        SalePersonId = OutletSaleUIData.SalePersonId,
                        CustomerId   = OutletSaleUIData.CustomerId,

                        TotalItem       = OutletSaleUIData.TotalItem,
                        TotalGrandPrice = OutletSaleUIData.TotalGrandPrice,
                        VAT             = OutletSaleUIData.VAT,
                        PaymentMode     = OutletSaleUIData.PaymentMode,
                        Cash            = OutletSaleUIData.Cash,
                        Credit          = OutletSaleUIData.Credit,
                        Discount        = OutletSaleUIData.Discount,
                        Rounding        = OutletSaleUIData.Rounding,
                        PayableAmount   = OutletSaleUIData.PayableAmount,
                        PaidAmount      = OutletSaleUIData.PaidAmount,
                        DueOrRefund     = OutletSaleUIData.DueOrRefund,

                        IsFullPaid = OutletSaleUIData.IsFullPaid,
                        IsEdited   = true,
                        //IsReturned = OutletSaleUIData.IsReturned,
                        //IsChanged = OutletSaleUIData.IsChanged,
                        Status          = 2,
                        CreatedDate     = aDate,
                        PreviousInvoice = OutletSaleUIData.OutletSaleInvoiceNo.ToString()
                    };

                    //aOutletSaleInvoiceMaster.OutletSaleInvoiceNo = aDate.Year +''+ aDate.Month +''+ aDate.Day +''+ aOutletSaleInvoiceMaster.OutletId;
                    // var invoiceId = aDate.Year().toString().substr(2) + "" + (aDate.Month() + 1) + "" + (aDate.Day() + "" + 1);

                    if (OutletSaleUIData.OutletInvoiceMasterId != 0)
                    {
                        _db.InvOutletInvoiceMasters.Add(aOutletSaleInvoiceMaster);
                        _db.SaveChanges();


                        foreach (var aData in productList)
                        {
                            //break;
                            InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                            {
                                OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                                ProductId             = aData.ProductId,
                                ProductQuantity       = aData.ProductQuantity,
                                Discount = aData.Discount,
                                //DiscountPercent = aData.DiscountPercent,
                                UnitPrice  = aData.UnitPrice,
                                TotalPrice = aData.TotalPrice,
                                IsEdited   = true,
                                //IsReturned = aData.IsReturned,
                                //IsChanged = aData.IsChanged,
                                IsDeleted   = aData.IsDeleted,
                                CreatedDate = aDate,
                            };
                            _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                            _db.SaveChanges();

                            InvOutletStock aStock = new InvOutletStock()
                            {
                                ProductId = aData.ProductId,
                                //OutletId = aData.OutletId,
                                OutletId            = aOutletSaleInvoiceMaster.OutletId,
                                InOut               = 2,
                                Note                = "Sale",
                                OutletStockQuantity = aData.ProductQuantity,
                                CreatedDate         = DateTime.Now
                            };

                            _db.InvOutletStocks.Add(aStock);
                            _db.SaveChanges();
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                        return(_aModel.Respons(true, "New OutletSaleUI Successfully Saved"));
                    }

                    //else if (OutletSaleUIData.OutletInvoiceMasterId > 0)
                    //{
                    //    _db.InvOutletInvoiceMasters.Attach(aOutletSaleInvoiceMaster);
                    //    _db.Entry(aOutletSaleInvoiceMaster).State = EntityState.Modified;
                    //    _db.SaveChanges();

                    //    var invOutletInvoice = _db.InvOutletInvoiceDetails.Find(OutletSaleUIData.OutletInvoiceDetailsId);

                    //    invOutletInvoice.IsActive = false;
                    //    invOutletInvoice.ModifiedDate = aDate;

                    //    _db.InvOutletInvoiceDetails.Attach(invOutletInvoice);
                    //    _db.Entry(invOutletInvoice).State = EntityState.Modified;
                    //    _db.SaveChanges();

                    //    foreach (var aData in productList)
                    //    {
                    //        InvOutletInvoiceDetail aOutletSaleInvoiceDetails = new InvOutletInvoiceDetail()
                    //        {
                    //            OutletInvoiceMasterId = aOutletSaleInvoiceMaster.OutletInvoiceMasterId,
                    //            ProductId = aData.ProductId,
                    //            ProductQuantity = aData.ProductQuantity,
                    //            CreatedDate = aDate,
                    //        };
                    //        _db.InvOutletInvoiceDetails.Add(aOutletSaleInvoiceDetails);
                    //        _db.Entry(aOutletSaleInvoiceDetails).State = EntityState.Modified;
                    //        _db.SaveChanges();
                    //    }
                    //    transaction.Commit();
                    //    return _aModel.Respons(true, "Successfully Updated  Sale Data");
                    //}
                    //    _db.SaveChanges();
                    transaction.Commit();
                    return(_aModel.Respons(true, "Sorry Failed to Update  Sale Data"));
                }
                catch (Exception)
                {
                    _db.SaveChanges();
                    transaction.Rollback();
                    return(_aModel.Respons(true, "Sorry Some Error Happned"));
                }
            }
        }