示例#1
0
        public ResponseModel CreateOutletWarrentyRepair(InvOutletWarrentyRepair aObj)
        {
            try
            {
                if (aObj.OutletWarrentyRepairId == 0)
                {
                    aObj.CreatedDate = DateTime.Now;

                    aObj.RepairTokenNo = (_invoiceNo.GetNewInvoiceNo());
                    aObj.Note          = "RepairRequest";
                    aObj.IsActive      = true;
                    aObj.IsReceived    = true;
                    aObj.IsRepaired    = false;
                    aObj.IsReturned    = 1;
                    _aRepository.Insert(aObj);
                    _aRepository.Save();
                    return(_aModel.Respons(true, "Repair request successfully saved"));
                }
                else
                {
                    _aRepository.Update(aObj);
                    _aRepository.Save();
                    return(_aModel.Respons(true, "Outlet Warrenty Repair Successfully Updated"));
                }
            }
            catch (Exception)
            {
                return(_aModel.Respons(false, "Sorry! Some Error Happned."));
            }
        }
        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"));
                }
            }
        }
示例#3
0
        public ResponseModel ChangeStatusValue(InvWarehousePOMaster aObj)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (aObj.Status != null)
                    {
                        DateTime             aDate = DateTime.Now;
                        InvWarehousePOMaster invWarehousePoMaster = _db.InvWarehousePOMasters.Find(aObj.WarehousePOMasterId);
                        invWarehousePoMaster.ModifiedDate = aDate;
                        invWarehousePoMaster.Status       = aObj.Status;
                        _db.InvWarehousePOMasters.Attach(invWarehousePoMaster);
                        _db.Entry(invWarehousePoMaster).State = EntityState.Modified;
                        _db.SaveChanges();

                        if (aObj.Status == 2)
                        {
                            transaction.Commit();
                            return(_aModel.Respons(true, "Approved All  Successfully"));
                        }
                        else if (aObj.Status == 3)
                        {
                            var data = (from m in _db.InvWarehousePOMasters
                                        join d in _db.InvWarehousePODetails on m.WarehousePOMasterId equals d.WarehousePOMasterId
                                        where m.WarehousePOMasterId == aObj.WarehousePOMasterId
                                        select
                                        new
                            {
                                m.WarehouseId,
                                d.ProductId,
                                d.ProductQuantity,
                            }).ToList();
                            foreach (var p in data)
                            {
                                InvWarehouseStock aStock = new InvWarehouseStock()
                                {
                                    ProductId              = p.ProductId,
                                    WarehouseId            = p.WarehouseId,
                                    InOut                  = 2,
                                    WarehouseStockQuantity = p.ProductQuantity,
                                    CreatedDate            = DateTime.Now
                                };
                                _db.InvWarehouseStocks.Add(aStock);
                                _db.SaveChanges();
                            }

                            transaction.Commit();
                            return(_aModel.Respons(true, "Sent Successfully"));
                        }
                        else if (aObj.Status == 4)
                        {
                            InvWarehousePOInvoiceMaster aWarehousePoInvoiceMaster = new InvWarehousePOInvoiceMaster()
                            {
                                Original_WarehousePOMasterId = invWarehousePoMaster.WarehousePOMasterId,
                                WarehousePOInvoiceNo         = (_invoiceNo.GetNewInvoiceNo()),

                                WarehouseId = invWarehousePoMaster.WarehouseId,

                                Status      = 0,
                                IsActive    = true,
                                IsEdited    = false,
                                IsDeleted   = false,
                                IsReturned  = false,
                                CreatedDate = aDate
                            };
                            _db.InvWarehousePOInvoiceMasters.Add(aWarehousePoInvoiceMaster);
                            _db.SaveChanges();

                            var data = (from m in _db.InvWarehousePOMasters
                                        join d in _db.InvWarehousePODetails on m.WarehousePOMasterId equals d.WarehousePOMasterId
                                        where m.WarehousePOMasterId == aObj.WarehousePOMasterId
                                        select
                                        new
                            {
                                m.WarehouseId,
                                d.WarehousePODetailsId,             ///// added 04-05-2017
                                d.ProductId,
                                d.ProductQuantity,
                            }).ToList();
                            foreach (var p in data)
                            {
                                ///// added 04-05-2017
                                InvWarehousePOInvoiceDetail invWarehousePoInvoiceDetail = new InvWarehousePOInvoiceDetail()
                                {
                                    WarehousePOInvoiceMasterId    = aWarehousePoInvoiceMaster.WarehousePOInvoiceMasterId,
                                    Original_WarehousePODetailsId = p.WarehousePODetailsId,
                                    ProductId       = p.ProductId,
                                    ProductQuantity = p.ProductQuantity,

                                    Status      = 0,
                                    IsActive    = true,
                                    IsEdited    = false,
                                    IsDeleted   = false,
                                    IsReturned  = false,
                                    CreatedDate = aDate
                                };
                                _db.InvWarehousePOInvoiceDetails.Add(invWarehousePoInvoiceDetail);
                                _db.SaveChanges();


                                InvWarehouseStock aStock = new InvWarehouseStock()
                                {
                                    ProductId              = p.ProductId,
                                    WarehouseId            = p.WarehouseId,
                                    InOut                  = 1,
                                    WarehouseStockQuantity = p.ProductQuantity,
                                    CreatedDate            = DateTime.Now
                                };
                                _db.InvWarehouseStocks.Add(aStock);
                                _db.SaveChanges();
                            }
                            transaction.Commit();
                            return(_aModel.Respons(true, "Received  Successfully"));
                        }
                    }
                    transaction.Commit();
                    return(_aModel.Respons(false, "Failed to Update Status"));
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return(_aModel.Respons(false, "Sorry! Some  Error Happned"));
                }
            }
        }
示例#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"));
                }
            }
        }