コード例 #1
0
        public static string DeleteSaleInvoice(string voucherNo, int empID, System.Data.Entity.DbContextTransaction trans = null, AprosysAccountingEntities context = null)
        {
            AprosysAccountingEntities db = context == null ? new AprosysAccountingEntities() : context;
            var transaction = trans == null?db.Database.BeginTransaction() : trans;

            try
            {
                var snv = db.Acc_GL.Where(x => x.InvoiceNo == voucherNo && x.IsActive == true
                                          &&
                                          x.TranTypeId == 2
                                          ).ToList();
                foreach (var item in snv.Where(x => x.CoaId == 6))
                {
                    var txLinks = db.Acc_GLTxLinks.Where(x => x.GLID == item.GlId && x.IsActive == true).ToList();
                    //Revert Stock to purchases
                    foreach (var txlinks in txLinks)
                    {
                        var pnv = db.Acc_GL.SingleOrDefault(x => x.GlId == txlinks.RelGLID);
                        pnv.QuantityBalance += txlinks.Quantity;
                        txlinks.IsActive     = false;
                    }
                }
                foreach (var item in snv)
                {
                    item.IsActive = false;
                    if (trans == null)
                    {
                        item.ModifiedBy = empID; item.ModifiedDate = DateTime.Now;
                    }
                }
                BL_CreditSales.DeletePartialPayments(db, voucherNo, empID);

                db.SaveChanges();

                if (trans == null)
                {
                    transaction.Commit();
                    db.Dispose();
                    transaction.Dispose();
                }

                return("Success");
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw;
            }
        }
コード例 #2
0
        public static List <Report_GetSaleInvoice_Result> GetSaleByInvoiceId(string _saleInvoiceId)
        {
            List <Report_GetSaleInvoice_Result> _si = new List <Report_GetSaleInvoice_Result>();

            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                _si = db.Report_GetSaleInvoice(_saleInvoiceId).ToList();
            }
            //Partial Credit
            var PartialPayments = BL_CreditSales.GetAllPartialPayments().GroupBy(x => x.InvoiceNum).ToDictionary(x => x.Key);

            foreach (var item in _si)
            {
                if (item.IsSalesCredit.GetValueOrDefault() > 0)
                {
                    item.PAID = 0;
                    if (PartialPayments.ContainsKey(item.InvoiceNo))
                    {
                        item.PAID = PartialPayments[item.InvoiceNo].Sum(x => x.Amount);
                    }
                }
            }
            return(_si);
        }
コード例 #3
0
        public static List <BO_Sales> GetSales(JQueryDataTableParamModel Param)
        {
            using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
            {
                //Param.Start_Date = BL_Common.GetDatetime().AddDays(-7);
                Param.End_Date = Param.End_Date.AddDays(1);
                var             lst       = db_aa.GetSaleInvoiceList(Param.Start_Date, Param.End_Date);
                List <BO_Sales> lst_Sales = new List <BO_Sales>();
                BO_Sales        obj;
                var             partial = BL_CreditSales.GetAllPartialPayments().GroupBy(x => x.InvoiceNum).ToDictionary(x => x.Key);
                foreach (var _sales in lst.ToList())
                {
                    obj              = new BO_Sales();
                    obj.invoiceNo    = _sales.InvoiceNo;
                    obj.sellDate     = _sales.ActivityTimestamp.Value;
                    obj.customerName = _sales.cstName;
                    obj.netAmount    = _sales.NETAMOUNT ?? 0;
                    obj.paid         = _sales.PAID;
                    if (_sales.IsSalesCredit.GetValueOrDefault())
                    {
                        obj.paid = 0;
                        if (partial.ContainsKey(obj.invoiceNo))
                        {
                            obj.paid           = partial[obj.invoiceNo].Sum(x => x.Amount);
                            obj.creditPaidDate = partial[obj.invoiceNo].Max(x => x.CreatedDate);
                        }
                    }

                    obj.isCustomerDeleted = _sales.isCustomerActive;
                    obj.isSalesCredit     = _sales.IsSalesCredit ?? false;
                    obj.creditPaidDate    = _sales.CreditPaidDate;
                    lst_Sales.Add(obj);
                }
                return(lst_Sales.OrderByDescending(x => (Convert.ToInt32(x.invoiceNo.Remove(0, 4)))).ToList());
            }
        }
コード例 #4
0
        public static List <BO_DailyCashFlow> GetDailyCashFlow(DateTime date)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var day   = date.DayOfWeek.ToString();
                var toret = db.GetDailyCashFlow(date).ToList().Select(x => new BO_DailyCashFlow {
                    AMOUNT = x.AMOUNT, GROUPID = x.GROUPID, ID = x.ID, NAME = x.NAME, Quantity = x.Quantity, TAX = x.TAX, TYPEID = x.TYPEID, TYPENAME = x.TYPENAME, UnitPrice = x.UnitPrice, WeekDay = day
                }).ToList();
                #region PartialPaymentFix
                var partials = BL_CreditSales.GetAllPartialPayments();
                var opening  = toret.Where(x => x.TYPEID == 0 && x.GROUPID == 0).First();

                partials.Where(x => x.CreatedDate.Date == date.Date).GroupBy(x => x.InvoiceNum).ToList().ForEach(x =>
                {
                    toret.Add(
                        new BO_DailyCashFlow
                    {
                        AMOUNT   = x.Sum(y => y.Amount),
                        TYPEID   = 10,
                        GROUPID  = 1,
                        TYPENAME = "Partial Credit Collected",
                        NAME     = x.Key,
                    });
                });
                var lst_partialCreditInvoiceNo = toret.Where(x => x.TYPENAME == "Partial Credit Collected").ToList();
                toret = toret.Where(x => x.TYPENAME != "Partial Credit Collected").ToList();
                if (lst_partialCreditInvoiceNo != null && lst_partialCreditInvoiceNo.Count > 0)
                {
                    decimal ReceivedCreditAmount = lst_partialCreditInvoiceNo.Select(x => x.AMOUNT).Sum();
                    for (int i = 0; i < lst_partialCreditInvoiceNo.Count; i++)
                    {
                        string  invoiceno = lst_partialCreditInvoiceNo[i].NAME;
                        decimal amount    = lst_partialCreditInvoiceNo[i].AMOUNT;
                        //var lst_unitPrice = db.Acc_GL.Where(x => x.InvoiceNo == invoiceno && x.CoaId == 14).OrderBy(x => x.UnitPrice).ToList();
                        var lst_unitPrice = (from Acc in db.Acc_GL
                                             join COA in db.Acc_COA on Acc.CoaId equals COA.CoaId
                                             where Acc.IsActive == true && COA.IsActive == true && (COA.PId == 101 || Acc.CoaId == 14) &&
                                             Acc.InvoiceNo == invoiceno
                                             select Acc).OrderBy(x => x.UnitPrice).ToList();


                        if (lst_unitPrice != null && lst_unitPrice.Count > 0)
                        {
                            for (int j = 0; j < lst_unitPrice.Count; j++) /*Unit Prices in Ascending order*/
                            {
                                if (amount >= lst_unitPrice[j].UnitPrice) /*Paid Amount is Greater then Unit price*/
                                {
                                    //toret.Add(new BO_DailyCashFlow { AMOUNT = lst_unitPrice[j].UnitPrice ?? 0, TYPEID = 1, GROUPID = 1, TYPENAME = "Sales", NAME = BL_Item.GetItemNameByItemId(lst_unitPrice[j].ItemId ?? 0), UnitPrice = lst_unitPrice[j].UnitPrice ?? 0, TAX = (lst_unitPrice[j].TaxPercent ?? 0) / (lst_unitPrice[j].Quantity ?? 0), Quantity = 1});

                                    for (int k = 1; k <= lst_unitPrice[j].Quantity; k++) /*Multiple Quantity of Item*/
                                    {
                                        if (amount >= lst_unitPrice[j].UnitPrice)
                                        {
                                            if (lst_unitPrice[j].CoaId == 14)
                                            {
                                                toret.Add(new BO_DailyCashFlow {
                                                    AMOUNT = lst_unitPrice[j].UnitPrice ?? 0, TYPEID = 1, GROUPID = 1, TYPENAME = "Sales", NAME = BL_Item.GetItemNameByItemId(lst_unitPrice[j].ItemId ?? 0), UnitPrice = lst_unitPrice[j].UnitPrice ?? 0, TAX = (lst_unitPrice[j].TaxPercent ?? 0) / (lst_unitPrice[j].Quantity ?? 0), Quantity = 1
                                                });
                                            }
                                            else
                                            {
                                                toret.Add(new BO_DailyCashFlow {
                                                    AMOUNT = lst_unitPrice[j].UnitPrice ?? 0, TYPEID = 3, GROUPID = 1, TYPENAME = "Shop", NAME = BL_Service.GetServiceByID(lst_unitPrice[j].CoaId ?? 0).name, UnitPrice = lst_unitPrice[j].UnitPrice ?? 0, TAX = (lst_unitPrice[j].TaxPercent ?? 0) / (lst_unitPrice[j].Quantity ?? 0), Quantity = 1
                                                });
                                            }
                                            amount = amount - lst_unitPrice[j].UnitPrice ?? 0;
                                            ReceivedCreditAmount = ReceivedCreditAmount - lst_unitPrice[j].UnitPrice ?? 0;
                                        }
                                        //if (k == lst_unitPrice[j].Quantity)
                                        //    toret.Add(new BO_DailyCashFlow { AMOUNT = lst_unitPrice[j].UnitPrice * k ?? 0, TYPEID = 1, GROUPID = 1, TYPENAME = "Sales", NAME = BL_Item.GetItemNameByItemId(lst_unitPrice[j].ItemId ?? 0), UnitPrice = lst_unitPrice[j].UnitPrice ?? 0, TAX = (lst_unitPrice[j].TaxPercent ?? 0) / (lst_unitPrice[j].Quantity ?? 0), Quantity = k });
                                    }
                                }
                            }
                        }
                        toret.Add(new BO_DailyCashFlow {
                            AMOUNT = amount, TYPEID = 10, GROUPID = 1, TYPENAME = "Partial Credit Collected", NAME = invoiceno,
                        });
                    }
                    decimal check = ReceivedCreditAmount;
                }
                //toret = toret.Where(x => x.TYPENAME != "Partial Credit Collected").ToList();

                toret = toret.GroupBy(x => x.NAME).Select(y => new BO_DailyCashFlow {
                    WeekDay = y.First().WeekDay, NAME = y.First().NAME, TYPENAME = y.First().TYPENAME, GROUPID = y.First().GROUPID, TYPEID = y.First().TYPEID, AMOUNT = y.Sum(z => z.AMOUNT), TAX = y.Sum(z => z.TAX), Quantity = y.Sum(z => z.Quantity), UnitPrice = y.First().UnitPrice
                }).ToList();
                var toretShop = toret.Where(x => x.TYPENAME == "Shop").ToList(); if (toretShop == null || toretShop.Count == 0)
                {
                    toret.Add(new BO_DailyCashFlow {
                        AMOUNT = 0, TYPEID = 3, GROUPID = 1, TYPENAME = "Shop", NAME = ""
                    });
                }
                var toretMonthly = toret.Where(x => x.TYPENAME == "Monthly").ToList(); if (toretMonthly == null || toretMonthly.Count == 0)
                {
                    toret.Add(new BO_DailyCashFlow {
                        AMOUNT = 0, TYPEID = 2, GROUPID = 1, TYPENAME = "Monthly", NAME = ""
                    });
                }

                var salescount = toret.Where(x => x.TYPENAME == "Sales").ToList();
                if (salescount.Count >= 2)
                {
                    /*Delete Sales , when TypeNAme of Sales count > 2 , its an empty entry*/
                    toret.RemoveAll(x => x.TYPENAME == "Sales" && x.NAME == "");
                }
                #endregion
                return(toret);
            }
        }