public RetailPurchaseInvoiceDetail VHasRetailPurchaseInvoice(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService)
        {
            RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);

            if (retailPurchaseInvoice == null)
            {
                retailPurchaseInvoiceDetail.Errors.Add("RetailPurchaseInvoiceId", "Tidak valid");
            }
            return(retailPurchaseInvoiceDetail);
        }
Exemple #2
0
 public RetailPurchaseInvoiceDetail SoftDeleteObject(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService)
 {
     if (_validator.ValidDeleteObject(retailPurchaseInvoiceDetail, _retailPurchaseInvoiceService))
     {
         RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);
         _repository.SoftDeleteObject(retailPurchaseInvoiceDetail);
         retailPurchaseInvoice.Total = CalculateTotal(retailPurchaseInvoice.Id);
         _retailPurchaseInvoiceService.GetRepository().Update(retailPurchaseInvoice);
     }
     return(retailPurchaseInvoiceDetail);
 }
        public RetailPurchaseInvoiceDetail VIsValidQuantity(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService, IWarehouseItemService _warehouseItemService)
        {
            RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);
            WarehouseItem         warehouseItem         = _warehouseItemService.FindOrCreateObject(retailPurchaseInvoice.WarehouseId, retailPurchaseInvoiceDetail.ItemId);

            if (retailPurchaseInvoiceDetail.Quantity <= 0 || retailPurchaseInvoiceDetail.Quantity >= warehouseItem.Quantity)
            {
                retailPurchaseInvoiceDetail.Errors.Add("Quantity", "Quantity harus lebih besar dari 0 dan lebih kecil dari WarehouseItem Quantity");
                return(retailPurchaseInvoiceDetail);
            }
            return(retailPurchaseInvoiceDetail);
        }
        public RetailPurchaseInvoiceDetail VIsValidQuantityOrdered(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService, IWarehouseItemService _warehouseItemService)
        {
            RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);
            WarehouseItem         warehouseItem         = _warehouseItemService.FindOrCreateObject(retailPurchaseInvoice.WarehouseId, retailPurchaseInvoiceDetail.ItemId);

            if (warehouseItem.Quantity - retailPurchaseInvoiceDetail.Quantity < 0)
            {
                retailPurchaseInvoiceDetail.Errors.Add("Generic", "Quantity harus lebih kecil atau sama dengan WarehouseItem Quantity");
                return(retailPurchaseInvoiceDetail);
            }
            return(retailPurchaseInvoiceDetail);
        }
        public RetailPurchaseInvoiceDetail VIsParentNotConfirmed(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService)
        {
            RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);

            if (retailPurchaseInvoice != null)
            {
                if (retailPurchaseInvoice.IsConfirmed)
                {
                    retailPurchaseInvoiceDetail.Errors.Add("Generic", "RetailPurchaseInvoice tidak boleh terkonfirmasi");
                }
            }
            return(retailPurchaseInvoiceDetail);
        }
Exemple #6
0
 public RetailPurchaseInvoiceDetail UpdateObject(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService,
                                                 IItemService _itemService, IWarehouseItemService _warehouseItemService, IPriceMutationService _priceMutationService)
 {
     if (_validator.ValidUpdateObject(retailPurchaseInvoiceDetail, _retailPurchaseInvoiceService, this, _itemService, _warehouseItemService))
     {
         Item                  item                  = _itemService.GetObjectById(retailPurchaseInvoiceDetail.ItemId);
         PriceMutation         priceMutation         = _priceMutationService.GetObjectById(item.PriceMutationId);
         RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);
         retailPurchaseInvoiceDetail.PriceMutationId = item.PriceMutationId;
         retailPurchaseInvoiceDetail.Amount          = priceMutation.Amount * retailPurchaseInvoiceDetail.Quantity;
         retailPurchaseInvoiceDetail = _repository.UpdateObject(retailPurchaseInvoiceDetail);
         retailPurchaseInvoice.Total = CalculateTotal(retailPurchaseInvoice.Id);
         _retailPurchaseInvoiceService.GetRepository().Update(retailPurchaseInvoice);
     }
     return(retailPurchaseInvoiceDetail);
 }
Exemple #7
0
        public RetailPurchaseInvoiceDetail ConfirmObject(RetailPurchaseInvoiceDetail retailPurchaseInvoiceDetail, IRetailPurchaseInvoiceService _retailPurchaseInvoiceService, IWarehouseItemService _warehouseItemService,
                                                         IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService)
        {
            if (_validator.ValidConfirmObject(retailPurchaseInvoiceDetail, _retailPurchaseInvoiceService, _warehouseItemService))
            {
                RetailPurchaseInvoice retailPurchaseInvoice = _retailPurchaseInvoiceService.GetObjectById(retailPurchaseInvoiceDetail.RetailPurchaseInvoiceId);
                WarehouseItem         warehouseItem         = _warehouseItemService.FindOrCreateObject(retailPurchaseInvoice.WarehouseId, retailPurchaseInvoiceDetail.ItemId);
                Item          item          = _itemService.GetObjectById(retailPurchaseInvoiceDetail.ItemId);
                StockMutation stockMutation = new StockMutation()
                {
                    ItemId                   = retailPurchaseInvoiceDetail.ItemId,
                    ItemCase                 = Core.Constants.Constant.ItemCase.Ready,
                    Status                   = Core.Constants.Constant.MutationStatus.Addition,
                    Quantity                 = retailPurchaseInvoiceDetail.Quantity,
                    SourceDocumentCode       = retailPurchaseInvoice.Code,
                    SourceDocumentId         = retailPurchaseInvoice.Id,
                    SourceDocumentType       = Core.Constants.Constant.SourceDocumentType.RetailPurchaseInvoice,
                    SourceDocumentDetailCode = retailPurchaseInvoiceDetail.Code,
                    SourceDocumentDetailId   = retailPurchaseInvoiceDetail.Id,
                    SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.RetailPurchaseInvoiceDetail,
                    WarehouseId              = retailPurchaseInvoice.WarehouseId,
                    WarehouseItemId          = warehouseItem.Id
                };

                decimal itemPrice = retailPurchaseInvoiceDetail.Amount / retailPurchaseInvoiceDetail.Quantity;
                item.AvgPrice = _itemService.CalculateAndUpdateAvgPrice(item, retailPurchaseInvoiceDetail.Quantity, itemPrice);

                stockMutation           = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                stockMutation.CreatedAt = (DateTime)retailPurchaseInvoice.ConfirmationDate.GetValueOrDefault();
                _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
                _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
                retailPurchaseInvoiceDetail.CoGS = retailPurchaseInvoiceDetail.Quantity * item.AvgPrice;
                retailPurchaseInvoiceDetail      = _repository.ConfirmObject(retailPurchaseInvoiceDetail);
            }
            return(retailPurchaseInvoiceDetail);
        }