Ejemplo n.º 1
0
        public JsonResult CreateInvoice(InvoiceMasterViewModel order)
        {
            bool status = false;

            order  = (new InvoiceRepository()).AddinvoiceMaster(order);
            status = true;
            return(new JsonResult {
                Data = new { status = status, model = order }
            });
        }
Ejemplo n.º 2
0
        public InvoiceMasterViewModel UpdateInvoiceMaster(InvoiceMasterViewModel Quotmater)
        {
            var q = from invmstr in cntxt.InvoiceMasters
                    where invmstr.InvoicemasterID == Quotmater.InvoiceMasterId
                    select invmstr;

            foreach (var element in q)
            {
                element.CustomerID    = Quotmater.CustomerID;
                element.PayMentModeId = Quotmater.PayMentModeId;
                element.InvoiceDate   = Quotmater.InvoiceDate;
                element.Remark        = Quotmater.Remark;
                element.TotalBill     = Quotmater.TotalBill;
                element.TotalPaid     = Quotmater.PaidValue;
                element.TotalDiscount = Quotmater.TotalDiscount;
            }

            foreach (InvoiceDetailsViewModel invoicedet in Quotmater.InvoiceDetails)
            {
                if (!cntxt.InvoiceDetails.Any(f => f.InvoiceDetailID == invoicedet.InvoiceDetailID))
                {
                    InvoiceDetail quotationDetail = new InvoiceDetail();

                    quotationDetail.InvoicemasterID = Quotmater.InvoiceMasterId;
                    quotationDetail.ProductId       = invoicedet.ProductId;
                    quotationDetail.Qty             = invoicedet.Qty;
                    quotationDetail.TotalPrice      = invoicedet.InvoicePrice;

                    quotationDetail.AddedUser = System.Web.HttpContext.Current.Session["username"].ToString();
                    quotationDetail.AddedDate = DateTime.Now;
                    quotationDetail.IsDeleted = false;



                    cntxt.InvoiceDetails.Add(quotationDetail);
                }
                else
                {
                    if (invoicedet.InvoiceDetailID != 0)
                    {
                        var q1 = from ivoidedetail in cntxt.InvoiceDetails
                                 where ivoidedetail.InvoiceDetailID == invoicedet.InvoiceDetailID
                                 select ivoidedetail;
                        foreach (var element in q1)
                        {
                            element.ProductId  = invoicedet.ProductId;
                            element.Qty        = invoicedet.Qty;
                            element.TotalPrice = invoicedet.InvoicePrice;

                            element.ModifiedUser = System.Web.HttpContext.Current.Session["username"].ToString();
                            element.ModifiedDate = DateTime.Now;
                            element.IsDeleted    = false;
                        }
                    }
                    else
                    {
                        InvoiceDetail quotationDetail = new InvoiceDetail();

                        quotationDetail.InvoicemasterID = Quotmater.InvoiceMasterId;
                        quotationDetail.ProductId       = invoicedet.ProductId;
                        quotationDetail.Qty             = invoicedet.Qty;
                        quotationDetail.TotalPrice      = invoicedet.InvoicePrice;

                        quotationDetail.AddedUser = System.Web.HttpContext.Current.Session["username"].ToString();
                        quotationDetail.AddedDate = DateTime.Now;
                        quotationDetail.IsDeleted = false;



                        cntxt.InvoiceDetails.Add(quotationDetail);
                    }
                }
            }

            var alreadyenteredinvoicelist = from ivoidedetail in cntxt.InvoiceDetails
                                            where ivoidedetail.InvoicemasterID == Quotmater.InvoiceMasterId && ivoidedetail.InvoiceDetailID != 0
                                            select ivoidedetail;

            foreach (var element in alreadyenteredinvoicelist)
            {
                //if (!Quotmater.InvoiceDetails.Any(f => f.InvoiceDetailID == element.InvoiceDetailID))
                if (!Quotmater.InvoiceDetails.Any(f => f.InvoiceDetailID == element.InvoiceDetailID))
                {
                    element.IsDeleted   = true;
                    element.DeletedUser = System.Web.HttpContext.Current.Session["username"].ToString();
                    element.Deleteddate = DateTime.Now;
                    element.Qty         = 0;
                }
            }

            cntxt.SaveChanges();

            return(Quotmater);
        }
Ejemplo n.º 3
0
        public InvoiceMasterViewModel AddinvoiceMaster(InvoiceMasterViewModel str)
        {
            InvoiceMaster pur = new InvoiceMaster();

            pur.CustomerID    = str.CustomerID;
            pur.PayMentModeId = str.PayMentModeId;
            pur.InvoiceDate   = str.InvoiceDate;
            pur.Remark        = (str.Remark + "").Trim();
            pur.TotalBill     = str.TotalBill.ZeroIfNullorEmpty();
            pur.TotalPaid     = str.PaidValue.ZeroIfNullorEmpty();
            pur.TotalDiscount = str.TotalDiscount.ZeroIfNullorEmpty();
            pur.Balance       = str.Balance.ZeroIfNullorEmpty();
            pur.StoreID       = int.Parse(System.Web.HttpContext.Current.Session["storeid"].ToString());
            pur.UserID        = int.Parse(System.Web.HttpContext.Current.Session["userid"].ToString());
            pur.AddedUser     = System.Web.HttpContext.Current.Session["username"].ToString();
            pur.AddedDate     = DateTime.Now;
            pur.IsCommited    = false;
            pur.IsDeleted     = false;
            cntxt.InvoiceMasters.Add(pur);
            cntxt.SaveChanges();

            pur.InvoiceNum      = "HST" + pur.InvoicemasterID.ToString().PadLeft(4, '0');
            str.InvoiceMasterId = pur.InvoicemasterID;
            str.InvoiceNum      = pur.InvoiceNum;
            foreach (InvoiceDetailsViewModel strdet in str.InvoiceDetails)
            {
                Product p = cntxt.Products.Find(strdet.ProductId);


                InvoiceDetail quotationDetail = new InvoiceDetail();

                quotationDetail.InvoicemasterID = pur.InvoicemasterID;
                quotationDetail.ProductId       = strdet.ProductId;
                quotationDetail.Qty             = strdet.Qty;


                quotationDetail.AddedUser = System.Web.HttpContext.Current.Session["username"].ToString();
                quotationDetail.AddedDate = DateTime.Now;
                quotationDetail.IsDeleted = false;

                quotationDetail.InvoiceUnitPrice = strdet.InvoicePrice;
                quotationDetail.TotalPrice       = strdet.InvoicePrice * strdet.Qty;

                quotationDetail.CGSTPercent    = Decimal.Parse(p.CGSTpercent.ToString()).ZeroIfNullorEmpty();
                quotationDetail.TotalCGSTValue = calculateGST(quotationDetail.CGSTPercent, quotationDetail.TotalPrice);

                quotationDetail.SGSTPercent    = Decimal.Parse(p.SGSTPercent.ToString()).ZeroIfNullorEmpty();
                quotationDetail.TotalSGSTValue = calculateGST(quotationDetail.SGSTPercent, quotationDetail.TotalPrice);


                quotationDetail.DisplayTotalPrice = quotationDetail.TotalPrice - (quotationDetail.TotalCGSTValue + quotationDetail.TotalSGSTValue);

                quotationDetail.DisplayUnitPrice = quotationDetail.DisplayTotalPrice / quotationDetail.Qty;



                quotationDetail.TotalTax = quotationDetail.TotalCGSTValue + quotationDetail.TotalSGSTValue;



                cntxt.InvoiceDetails.Add(quotationDetail);


                p.IsAvailable = false;
            }

            cntxt.SaveChanges();

            return(str);
        }