public dynamic Check(CustomPurchaseInvoice model, decimal DailySalesProjection, bool IncludeSaturdaySales, bool IncludeSundaySales)
        {
            Dictionary <string, string> Errors = new Dictionary <string, string>();

            try
            {
                DateTime startDate = DateTime.Today;
                DateTime endDate   = model.DueDate.GetValueOrDefault();

                var     data          = _customPurchaseInvoiceService.GetObjectById(model.Id);
                decimal total         = _customPurchaseInvoiceService.CalculateTotalAmountAfterDiscountAndTax(data) - model.Allowance;
                decimal totalcashbank = _cashBankService.GetTotalCashBank();

                DateTime curDate = startDate;
                decimal  funds   = totalcashbank;
                while (curDate <= endDate)
                {
                    if ((curDate.DayOfWeek != DayOfWeek.Saturday && curDate.DayOfWeek != DayOfWeek.Sunday) ||
                        (curDate.DayOfWeek == DayOfWeek.Saturday && IncludeSaturdaySales) ||
                        (curDate.DayOfWeek == DayOfWeek.Sunday && IncludeSundaySales))
                    {
                        funds += DailySalesProjection;
                    }
                    funds += _receivableService.GetTotalRemainingAmountByDueDate(curDate, curDate);
                    funds -= _payableService.GetTotalRemainingAmountByDueDate(curDate, curDate);

                    curDate = curDate.AddDays(1);
                }

                if (funds < total)
                {
                    Errors.Add("Generic", "Dana Tidak tersedia");
                }
            }
            catch (Exception ex)
            {
                LOG.Error("Check Funds Failed", ex);
                Errors.Add("Generic", "Error " + ex);
            }

            return(Json(new
            {
                Errors
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult ReportFunds(int Id, DateTime DueDate, decimal Discount, decimal Tax, decimal Allowance, decimal DailySalesProjection, bool IncludeSaturdaySales, bool IncludeSundaySales)
        {
            var      company   = _companyService.GetQueryable().FirstOrDefault();
            DateTime startDate = DateTime.Today;
            DateTime endDate   = DueDate.Date;

            var data = _customPurchaseInvoiceService.GetObjectById(Id);

            data.DueDate   = DueDate;
            data.Discount  = Discount;
            data.Tax       = Tax;
            data.Allowance = Allowance;
            decimal total         = _customPurchaseInvoiceService.CalculateTotalAmountAfterDiscountAndTax(data) - Allowance;
            decimal totalcashbank = _cashBankService.GetTotalCashBank();

            DateTime curDate = startDate;
            decimal  funds   = totalcashbank;
            var      query   = new List <ModelFund>();

            while (curDate <= endDate)
            {
                decimal receivable = _receivableService.GetTotalRemainingAmountByDueDate(curDate, curDate);
                decimal payable    = _payableService.GetTotalRemainingAmountByDueDate(curDate, curDate);
                decimal sales      = 0;
                if ((curDate.DayOfWeek != DayOfWeek.Saturday && curDate.DayOfWeek != DayOfWeek.Sunday) ||
                    (curDate.DayOfWeek == DayOfWeek.Saturday && IncludeSaturdaySales) ||
                    (curDate.DayOfWeek == DayOfWeek.Sunday && IncludeSundaySales))
                {
                    sales = DailySalesProjection;
                }

                var curFund = new ModelFund()
                {
                    FromDueDate          = startDate,
                    ToDueDate            = endDate,
                    CurDate              = curDate,
                    cashBank             = funds,
                    payable              = payable,
                    receivable           = receivable,
                    dailySalesProjection = sales,
                    CompanyName          = company.Name,
                    CompanyAddress       = company.Address,
                    CompanyContactNo     = company.ContactNo
                };
                query.Add(curFund);

                funds += sales;
                funds += receivable;
                funds -= payable;

                curDate = curDate.AddDays(1);
            }

            var rd = new ReportDocument();

            //Loading Report
            rd.Load(Server.MapPath("~/") + "Reports/General/Funds.rpt");

            // Setting report data source
            rd.SetDataSource(query);

            var stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            //var response = Request.CreateResponse(HttpStatusCode.OK);
            //response.Headers.Clear();
            //response.Content = new StreamContent(pdf);
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            //return response;

            return(File(stream, "application/pdf"));
        }