示例#1
0
        public IEnumerable <SaleInvoiceListViewModel> GetPendingInvoices(int id, int SaleInvoiceReturnHeaderId)
        {
            var SaleInvoiceReturnHeader = new SaleInvoiceReturnHeaderService(_unitOfWork).Find(SaleInvoiceReturnHeaderId);

            var settings = new SaleInvoiceSettingService(_unitOfWork).GetSaleInvoiceSettingForDocument(SaleInvoiceReturnHeader.DocTypeId, SaleInvoiceReturnHeader.DivisionId, SaleInvoiceReturnHeader.SiteId);

            string[] contraDocTypes = null;
            if (!string.IsNullOrEmpty(settings.filterContraDocTypes))
            {
                contraDocTypes = settings.filterContraDocTypes.Split(",".ToCharArray());
            }
            else
            {
                contraDocTypes = new string[] { "NA" };
            }

            string[] contraSites = null;
            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                contraSites = settings.filterContraSites.Split(",".ToCharArray());
            }
            else
            {
                contraSites = new string[] { "NA" };
            }

            string[] contraDivisions = null;
            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                contraDivisions = settings.filterContraDivisions.Split(",".ToCharArray());
            }
            else
            {
                contraDivisions = new string[] { "NA" };
            }

            int CurrentSiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int CurrentDivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];


            return(from p in db.ViewSaleInvoiceBalance
                   join t in db.SaleInvoiceHeader on p.SaleInvoiceHeaderId equals t.SaleInvoiceHeaderId into table
                   from tab in table.DefaultIfEmpty()
                   join t1 in db.SaleDispatchLine on p.SaleDispatchLineId equals t1.SaleDispatchLineId into table1
                   from tab1 in table1.DefaultIfEmpty()
                   join t2 in db.SaleInvoiceLine on p.SaleDispatchLineId equals t2.SaleDispatchLineId into InvoiceTable
                   from InvTab in InvoiceTable.DefaultIfEmpty()
                   where InvTab.ProductId == id && tab.SaleToBuyerId == SaleInvoiceReturnHeader.BuyerId && p.BalanceQty > 0 &&
                   (string.IsNullOrEmpty(settings.filterContraSites) ? p.SiteId == CurrentSiteId : contraSites.Contains(p.SiteId.ToString())) &&
                   (string.IsNullOrEmpty(settings.filterContraDivisions) ? p.DivisionId == CurrentDivisionId : contraDivisions.Contains(p.DivisionId.ToString()))
                   select new SaleInvoiceListViewModel
            {
                SaleInvoiceLineId = p.SaleInvoiceLineId,
                SaleInvoiceHeaderId = p.SaleInvoiceHeaderId,
                DocNo = tab.DocNo,
                Dimension1Name = InvTab.Dimension1.Dimension1Name,
                Dimension2Name = InvTab.Dimension2.Dimension2Name,
            }
                   );
        }
示例#2
0
        public bool addnewInvoice(classInvoice c)
        {
            var newInvoice = new InvoiceTable
            {
                UserID     = c.urID,
                TotalPrice = c.totalprice,
                Tax        = c.tax,
                CartTotal  = c.carttotal,
                Discount   = c.discount,
                PointApply = c.points,
                Date       = DateTime.Now,
                Reference  = c.refNum
            };

            db.InvoiceTables.InsertOnSubmit(newInvoice);
            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                return(false);
            }
        }
	    public void Insert(int? OrderNumber,int? DepartmentID,DateTime? InvoiceDate,int? Customer,float? InvoiceCurrencyID,string Description,decimal? ExchangeRate,string Notes,bool? Crosstrade,DateTime? PaymentDueDate,int? InvoiceRaisedBy,DateTime? InvoiceRaised,decimal? InsuranceValue,string Contact,decimal? OriginalProfitMargin,DateTime? OriginalProfitDate,DateTime? DateQueryRaised,string DetailsOfQuery,string Resolution,int? ConfirmedCompleted,DateTime? CompletionDate,int? Controller,string LossApproved,DateTime? LossApprovedDate,byte[] Tscol)
	    {
		    InvoiceTable item = new InvoiceTable();
		    
            item.OrderNumber = OrderNumber;
            
            item.DepartmentID = DepartmentID;
            
            item.InvoiceDate = InvoiceDate;
            
            item.Customer = Customer;
            
            item.InvoiceCurrencyID = InvoiceCurrencyID;
            
            item.Description = Description;
            
            item.ExchangeRate = ExchangeRate;
            
            item.Notes = Notes;
            
            item.Crosstrade = Crosstrade;
            
            item.PaymentDueDate = PaymentDueDate;
            
            item.InvoiceRaisedBy = InvoiceRaisedBy;
            
            item.InvoiceRaised = InvoiceRaised;
            
            item.InsuranceValue = InsuranceValue;
            
            item.Contact = Contact;
            
            item.OriginalProfitMargin = OriginalProfitMargin;
            
            item.OriginalProfitDate = OriginalProfitDate;
            
            item.DateQueryRaised = DateQueryRaised;
            
            item.DetailsOfQuery = DetailsOfQuery;
            
            item.Resolution = Resolution;
            
            item.ConfirmedCompleted = ConfirmedCompleted;
            
            item.CompletionDate = CompletionDate;
            
            item.Controller = Controller;
            
            item.LossApproved = LossApproved;
            
            item.LossApprovedDate = LossApprovedDate;
            
            item.Tscol = Tscol;
            
	    
		    item.Save(UserName);
	    }
示例#4
0
        public JsonResult Proceeds(int Id, string Status)
        {
            MvcPurchaseModel            PurchaseModel        = new MvcPurchaseModel();
            List <MvcPurchaseViewModel> _PurcchaseDetailList = new List <MvcPurchaseViewModel>();

            InvoiceTable    InvoiceTable    = new InvoiceTable();
            MVCInvoiceModel mvcInvoiceModel = new MVCInvoiceModel();

            PurchaseOrderTable purchasemodel = new PurchaseOrderTable();

            try
            {
                PurchaseModel        = GetPurchasae(Id);
                _PurcchaseDetailList = GetPurchaseDetail(Id);
                if (PurchaseModel != null)
                {
                    BillTable billtable = new BillTable();

                    billtable.CompanyId      = PurchaseModel.CompanyId;
                    billtable.UserId         = Convert.ToInt32(Session["LoginUserID"]);
                    billtable.Bill_ID        = PurchaseModel.PurchaseID.ToString();
                    billtable.PurchaseId     = PurchaseModel.PurchaseOrderID;
                    billtable.VenderId       = PurchaseModel.VenderId;
                    billtable.RefNumber      = PurchaseModel.PurchaseRefNumber;
                    billtable.BillDate       = Convert.ToDateTime(PurchaseModel.PurchaseDate);
                    billtable.BillDueDate    = Convert.ToDateTime(PurchaseModel.PurchaseDueDate);
                    billtable.SubTotal       = PurchaseModel.PurchaseSubTotal;
                    billtable.DiscountAmount = PurchaseModel.PurchaseTotoalAmount;
                    billtable.TotalAmount    = PurchaseModel.PurchaseTotoalAmount;
                    billtable.CustomerNote   = PurchaseModel.PurchaseVenderNote;
                    billtable.TotalVat6      = PurchaseModel.Vat6;
                    billtable.TotalVat21     = PurchaseModel.Vat21;
                    billtable.Status         = "accepted";
                    billtable.Type           = StatusEnum.Goods.ToString();
                    // bill Api
                    HttpResponseMessage response      = GlobalVeriables.WebApiClient.PostAsJsonAsync("AddBill", billtable).Result;
                    BillTable           billviewmodel = response.Content.ReadAsAsync <BillTable>().Result;


                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        if (_PurcchaseDetailList != null)
                        {
                            foreach (var item in _PurcchaseDetailList)
                            {
                                BillDetailTable billdetailtable = new BillDetailTable();

                                billdetailtable.BillID      = billviewmodel.BilID;
                                billdetailtable.ItemId      = item.PurchaseItemId;
                                billdetailtable.Description = item.PurchaseDescription;
                                billdetailtable.Quantity    = item.PurchaseQuantity;
                                billdetailtable.Rate        = item.PurchaseItemRate;
                                billdetailtable.Total       = item.PurchaseTotal;
                                billdetailtable.Type        = item.Type;
                                billdetailtable.RowSubTotal = Convert.ToDouble(item.RowSubTotal);
                                billdetailtable.Vat         = item.PurchaseVatPercentage;
                                billdetailtable.ServiceDate = item.ServiceDate;
                                // APIBill
                                HttpResponseMessage responsses = GlobalVeriables.WebApiClient.PostAsJsonAsync("AddBillDetail", billdetailtable).Result;

                                if (responsses.StatusCode != System.Net.HttpStatusCode.OK)
                                {
                                    return(new JsonResult {
                                        Data = new { Status = "Fail", Message = "Fail to Proceed" }
                                    });
                                }
                            }

                            if (UpdateQuatationStation(Id))
                            {
                                return(new JsonResult {
                                    Data = new { Status = "Success", Message = "Proceed successfullly" }
                                });
                            }
                        }
                    }
                }
            }

            catch (Exception)
            {
                throw;
            }

            return(new JsonResult {
                Data = new { Status = "Success", Message = "Proceed successfullly" }
            });
        }
示例#5
0
        public IHttpActionResult PostInvoice([FromBody] InvoiceViewModel invoiceViewModel)
        {
            InvoiceTable Table = new InvoiceTable();

            using (DBEntities context = new DBEntities())
            {
                using (DbContextTransaction transaction = context.Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        Table.Invoice_ID         = invoiceViewModel.Invoice_ID;
                        Table.CompanyId          = invoiceViewModel.CompanyId;
                        Table.UserId             = invoiceViewModel.UserId;
                        Table.ContactId          = invoiceViewModel.ContactId;
                        Table.RefNumber          = invoiceViewModel.RefNumber;
                        Table.InvoiceDate        = invoiceViewModel.InvoiceDate;
                        Table.InvoiceDueDate     = invoiceViewModel.InvoiceDueDate;
                        Table.SubTotal           = invoiceViewModel.SubTotal;
                        Table.DiscountAmount     = invoiceViewModel.DiscountAmount;
                        Table.TotalAmount        = invoiceViewModel.TotalAmount;
                        Table.CustomerNote       = invoiceViewModel.CustomerNote;
                        Table.TotalVat21         = invoiceViewModel.TotalVat21;
                        Table.TotalVat6          = invoiceViewModel.TotalVat6;
                        Table.Type               = StatusEnum.Goods.ToString();
                        Table.Status             = "accepted";
                        Table.InvoiceDescription = invoiceViewModel.InvoiceDescription;

                        if (Table.TotalVat6 != null)
                        {
                            double vat61 = Math.Round((double)Table.TotalVat6, 2, MidpointRounding.AwayFromZero);
                            Table.TotalVat6 = vat61;
                        }
                        if (Table.TotalVat21 != null)
                        {
                            double vat21 = Math.Round((double)Table.TotalVat21, 2, MidpointRounding.AwayFromZero);
                            Table.TotalVat21 = vat21;
                        }

                        Table = context.InvoiceTables.Add(Table);
                        context.SaveChanges();

                        if (invoiceViewModel.InvoiceDetailsTable != null)
                        {
                            foreach (InvoiceDetailsTable InvoiceDetailsList in invoiceViewModel.InvoiceDetailsTable)
                            {
                                InvoiceDetailsTable InvoiceDetails = new InvoiceDetailsTable();
                                InvoiceDetails.ItemId      = Convert.ToInt32(InvoiceDetailsList.ItemId);
                                InvoiceDetails.InvoiceId   = Table.InvoiceID;
                                InvoiceDetails.Description = InvoiceDetailsList.Description;
                                InvoiceDetails.Quantity    = InvoiceDetailsList.Quantity;
                                InvoiceDetails.Rate        = Convert.ToDouble(InvoiceDetailsList.Rate);
                                InvoiceDetails.Total       = Convert.ToDouble(InvoiceDetailsList.Total);
                                InvoiceDetails.ServiceDate = InvoiceDetailsList.ServiceDate;
                                InvoiceDetails.RowSubTotal = InvoiceDetailsList.RowSubTotal;
                                InvoiceDetails.Vat         = Convert.ToDouble(InvoiceDetailsList.Vat);
                                InvoiceDetails.Type        = InvoiceDetailsList.Type;

                                if (InvoiceDetails.InvoiceDetailId == 0)
                                {
                                    InvoiceDetails = context.InvoiceDetailsTables.Add(InvoiceDetails);
                                    context.SaveChanges();
                                }
                            }
                        }

                        AccountTransictionTable Account = new AccountTransictionTable();
                        Account.TransictionDate       = DateTime.Now;
                        Account.TransictionNumber     = base64Guid;
                        Account.TransictionType       = "Invoice";
                        Account.TransictionRefrenceId = Table.InvoiceID.ToString();
                        Account.CreationTime          = DateTime.Now.TimeOfDay;
                        Account.AddedBy       = 1;
                        Account.FK_CompanyId  = invoiceViewModel.CompanyId;
                        Account.FKPaymentTerm = 1;

                        //Cash Account Transaction
                        int CashtAccountId = AccountIdByName("Cash on hand", (int)invoiceViewModel.CompanyId);

                        if (CashtAccountId != 0)
                        {
                            Account.Dr           = invoiceViewModel.TotalAmount;
                            Account.Cr           = 0.00;
                            Account.FK_AccountID = CashtAccountId;
                            context.AccountTransictionTables.Add(Account);
                            context.SaveChanges();
                        }
                        // Sale Account Transaction
                        int SaleAccount = AccountIdByName("Seles", (int)invoiceViewModel.CompanyId);
                        if (SaleAccount != 0)
                        {
                            Account.Cr           = invoiceViewModel.SubTotal;
                            Account.Dr           = 0.00;
                            Account.FK_AccountID = SaleAccount;
                            context.AccountTransictionTables.Add(Account);
                            context.SaveChanges();
                        }
                        // vat Out Put Trnsaction
                        int VatAccountId = AccountIdByName("VAT Payable", (int)invoiceViewModel.CompanyId);
                        if (VatAccountId != 0)
                        {
                            Account.Cr           = invoiceViewModel.TotalVat6 + invoiceViewModel.TotalVat21;
                            Account.Dr           = 0.00;
                            Account.FK_AccountID = VatAccountId;
                            context.AccountTransictionTables.Add(Account);
                            int Id = context.SaveChanges();
                        }
                        InvoiceModel inc = new InvoiceModel();
                        inc.InvoiceID = Table.InvoiceID;
                        transaction.Commit();
                        return(Ok(inc));
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(BadRequest());
                    }
                }
            }
        }
        public JsonResult Proceeds(int QutationId, string Status, string Type)
        {
            HttpResponseMessage responsses = new HttpResponseMessage();

            MVCQutationModel            QutationModel        = new MVCQutationModel();
            List <MVCQutationViewModel> _QuatationDetailList = new List <MVCQutationViewModel>();

            InvoiceTable    InvoiceTable    = new InvoiceTable();
            MVCInvoiceModel mvcInvoiceModel = new MVCInvoiceModel();

            try
            {
                QutationModel        = GetQutationById(QutationId);
                _QuatationDetailList = GetQuatationDetailListById(QutationId);
                if (QutationModel != null)
                {
                    mvcInvoiceModel.Invoice_ID     = QutationModel.Qutation_ID;
                    mvcInvoiceModel.QutationId     = QutationModel.QutationID;
                    mvcInvoiceModel.CompanyId      = QutationModel.CompanyId;
                    mvcInvoiceModel.UserId         = Convert.ToInt32(Session["LoginUserID"]);
                    mvcInvoiceModel.ContactId      = QutationModel.ContactId;
                    mvcInvoiceModel.InvoiceID      = 0;
                    mvcInvoiceModel.RefNumber      = QutationModel.RefNumber;
                    mvcInvoiceModel.InvoiceDate    = QutationModel.QutationDate;
                    mvcInvoiceModel.InvoiceDueDate = QutationModel.DueDate;
                    mvcInvoiceModel.SubTotal       = QutationModel.SubTotal;
                    mvcInvoiceModel.DiscountAmount = QutationModel.DiscountAmount;
                    mvcInvoiceModel.TotalAmount    = QutationModel.TotalAmount;
                    mvcInvoiceModel.CustomerNote   = QutationModel.CustomerNote;
                    mvcInvoiceModel.TotalVat21     = QutationModel.TotalVat21;
                    mvcInvoiceModel.TotalVat6      = QutationModel.TotalVat6;
                    mvcInvoiceModel.Type           = StatusEnum.Goods.ToString();
                    mvcInvoiceModel.Status         = "accepted";
                    HttpResponseMessage InvoiceResponse = GlobalVeriables.WebApiClient.PostAsJsonAsync("PostInvoice", mvcInvoiceModel).Result;
                    InvoiceTable = InvoiceResponse.Content.ReadAsAsync <InvoiceTable>().Result;

                    if (InvoiceResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        if (_QuatationDetailList != null)
                        {
                            foreach (var item in _QuatationDetailList)
                            {
                                InvoiceDetailsTable InvoiceDetails = new InvoiceDetailsTable();
                                InvoiceDetails.ItemId      = Convert.ToInt32(item.ItemId);
                                InvoiceDetails.InvoiceId   = InvoiceTable.InvoiceID;
                                InvoiceDetails.Description = item.Description;
                                InvoiceDetails.Quantity    = item.Quantity;
                                InvoiceDetails.Rate        = Convert.ToDouble(item.Rate);
                                InvoiceDetails.Total       = Convert.ToDouble(item.Total);
                                InvoiceDetails.ServiceDate = item.ServiceDate;
                                InvoiceDetails.RowSubTotal = item.RowSubTotal;
                                InvoiceDetails.Vat         = Convert.ToDouble(item.Vat);
                                InvoiceDetails.Type        = item.Type;
                                responsses = GlobalVeriables.WebApiClient.PostAsJsonAsync("PostinvoiceDetails", InvoiceDetails).Result;

                                if (responsses.StatusCode != System.Net.HttpStatusCode.OK)
                                {
                                    return(new JsonResult {
                                        Data = new { Status = "Fail", Message = "Fail to Proceed" }
                                    });
                                }
                            }

                            if (UpdateQuatationStation(QutationId))
                            {
                                if (Transaction(QutationModel, "Add"))
                                {
                                    return(new JsonResult {
                                        Data = new { Status = "Success", Message = "Proceed successfullly" }
                                    });
                                }
                            }
                        }
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = new { Status = "Fail", Message = "Fail Proceed successfullly" }
                        });
                    }
                }
            }

            catch (Exception)
            {
                throw;
            }

            return(new JsonResult {
                Data = new { Status = "Success", Message = "Proceed successfullly" }
            });
        }