Пример #1
0
        public CustomPurchaseInvoiceDetail VHasCustomPurchaseInvoice(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService)
        {
            CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);

            if (customPurchaseInvoice == null)
            {
                customPurchaseInvoiceDetail.Errors.Add("CustomPurchaseInvoiceId", "Tidak valid");
            }
            return(customPurchaseInvoiceDetail);
        }
 public CustomPurchaseInvoiceDetail SoftDeleteObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService)
 {
     if (_validator.ValidDeleteObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService))
     {
         CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         _repository.SoftDeleteObject(customPurchaseInvoiceDetail);
         customPurchaseInvoice.Total = CalculateTotal(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         customPurchaseInvoice.CoGS  = CalculateCoGS(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         _customPurchaseInvoiceService.GetRepository().Update(customPurchaseInvoice);
     }
     return(customPurchaseInvoiceDetail);
 }
 public CustomPurchaseInvoiceDetail UpdateObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService,
                                                 IItemService _itemService, IWarehouseItemService _warehouseItemService)
 {
     if (_validator.ValidUpdateObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService, this, _itemService, _warehouseItemService))
     {
         Item item = _itemService.GetObjectById(customPurchaseInvoiceDetail.ItemId);
         CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         customPurchaseInvoiceDetail.Price  = customPurchaseInvoiceDetail.ListedUnitPrice * (100 - customPurchaseInvoiceDetail.Discount) / 100;
         customPurchaseInvoiceDetail.Amount = customPurchaseInvoiceDetail.Price * customPurchaseInvoiceDetail.Quantity;
         customPurchaseInvoiceDetail.CoGS   = customPurchaseInvoiceDetail.Quantity * _itemService.CalculateAvgPrice(item, customPurchaseInvoiceDetail.Quantity, customPurchaseInvoiceDetail.Price);
         customPurchaseInvoiceDetail        = _repository.UpdateObject(customPurchaseInvoiceDetail);
         customPurchaseInvoice.Total        = CalculateTotal(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         customPurchaseInvoice.CoGS         = CalculateCoGS(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
         _customPurchaseInvoiceService.GetRepository().Update(customPurchaseInvoice);
     }
     return(customPurchaseInvoiceDetail);
 }
Пример #4
0
        public CustomPurchaseInvoiceDetail VIsParentNotConfirmed(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService)
        {
            CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);

            if (customPurchaseInvoice != null)
            {
                if (customPurchaseInvoice.IsConfirmed)
                {
                    customPurchaseInvoiceDetail.Errors.Add("Generic", "CustomPurchaseInvoice tidak boleh terkonfirmasi");
                }
            }
            else
            {
                customPurchaseInvoiceDetail.Errors.Add("Generic", "CustomPurchaseInvoice tidak ada");
            }
            return(customPurchaseInvoiceDetail);
        }
        public CustomPurchaseInvoiceDetail ConfirmObject(CustomPurchaseInvoiceDetail customPurchaseInvoiceDetail, ICustomPurchaseInvoiceService _customPurchaseInvoiceService, IWarehouseItemService _warehouseItemService,
                                                         IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService, IPriceMutationService _priceMutationService)
        {
            if (_validator.ValidConfirmObject(customPurchaseInvoiceDetail, _customPurchaseInvoiceService, _warehouseItemService))
            {
                CustomPurchaseInvoice customPurchaseInvoice = _customPurchaseInvoiceService.GetObjectById(customPurchaseInvoiceDetail.CustomPurchaseInvoiceId);
                WarehouseItem         warehouseItem         = _warehouseItemService.FindOrCreateObject(customPurchaseInvoice.WarehouseId, customPurchaseInvoiceDetail.ItemId);
                Item          item          = _itemService.GetObjectById(customPurchaseInvoiceDetail.ItemId);
                StockMutation stockMutation = new StockMutation()
                {
                    ItemId                   = customPurchaseInvoiceDetail.ItemId,
                    ItemCase                 = Core.Constants.Constant.ItemCase.Ready,
                    Status                   = Core.Constants.Constant.MutationStatus.Addition,
                    Quantity                 = customPurchaseInvoiceDetail.Quantity,
                    SourceDocumentCode       = customPurchaseInvoice.Code,
                    SourceDocumentId         = customPurchaseInvoice.Id,
                    SourceDocumentType       = Core.Constants.Constant.SourceDocumentType.CustomPurchaseInvoice,
                    SourceDocumentDetailCode = customPurchaseInvoiceDetail.Code,
                    SourceDocumentDetailId   = customPurchaseInvoiceDetail.Id,
                    SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.CustomPurchaseInvoiceDetail,
                    WarehouseId              = customPurchaseInvoice.WarehouseId,
                    WarehouseItemId          = warehouseItem.Id
                };

                decimal hiPrice  = GetHighestPrice(/*customPurchaseInvoice.Id,*/ customPurchaseInvoiceDetail.ItemId);
                decimal newPrice = hiPrice * (100 + item.Margin) / 100;
                if (newPrice > item.SellingPrice)
                {
                    item.SellingPrice = newPrice;
                    PriceMutation priceMutation = _priceMutationService.CreateObject(item.Id, item.SellingPrice, DateTime.Now);
                    item.PriceMutationId = priceMutation.Id;
                }
                decimal itemPrice = customPurchaseInvoiceDetail.Amount / customPurchaseInvoiceDetail.Quantity;
                item.AvgPrice = _itemService.CalculateAndUpdateAvgPrice(item, customPurchaseInvoiceDetail.Quantity, itemPrice);

                stockMutation           = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                stockMutation.CreatedAt = (DateTime)customPurchaseInvoice.ConfirmationDate.GetValueOrDefault();
                _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
                customPurchaseInvoiceDetail.CoGS = customPurchaseInvoiceDetail.Quantity * item.AvgPrice;
                customPurchaseInvoiceDetail      = _repository.ConfirmObject(customPurchaseInvoiceDetail);
            }
            return(customPurchaseInvoiceDetail);
        }
        public dynamic GetInfo(int Id)
        {
            CustomPurchaseInvoice model = new CustomPurchaseInvoice();

            try
            {
                model = _customPurchaseInvoiceService.GetObjectById(Id);
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.Code,
                model.Description,
                model.PurchaseDate,
                model.DueDate,
                model.Discount,
                model.Tax,
                model.Allowance,
                model.Total,
                model.ContactId,
                model.IsGBCH,
                model.GBCH_No,
                model.GBCH_DueDate,
                Contact = _contactService.GetObjectById(model.ContactId).Name,
                model.CashBankId,
                CashBank = _cashBankService.GetObjectById((int)model.CashBankId.GetValueOrDefault()).Name,
                model.WarehouseId,
                Warehouse = _warehouseService.GetObjectById(model.WarehouseId).Name,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Пример #7
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"));
        }