public RetailSalesInvoiceDetail ConfirmObject(RetailSalesInvoiceDetail retailSalesInvoiceDetail, IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService,
                                               IWarehouseService _warehouseService, IItemService _itemService, IBarringService _barringService, IStockMutationService _stockMutationService)
 {
     if (_validator.ValidConfirmObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService))
     {
         RetailSalesInvoice retailSalesInvoice = _retailSalesInvoiceService.GetObjectById(retailSalesInvoiceDetail.RetailSalesInvoiceId);
         WarehouseItem      warehouseItem      = _warehouseItemService.FindOrCreateObject(retailSalesInvoice.WarehouseId, retailSalesInvoiceDetail.ItemId);
         Item          item          = _itemService.GetObjectById(retailSalesInvoiceDetail.ItemId);
         StockMutation stockMutation = new StockMutation()
         {
             ItemId                   = retailSalesInvoiceDetail.ItemId,
             ItemCase                 = Core.Constants.Constant.ItemCase.Ready,
             Status                   = Core.Constants.Constant.MutationStatus.Deduction,
             Quantity                 = retailSalesInvoiceDetail.Quantity,
             SourceDocumentCode       = retailSalesInvoice.Code,
             SourceDocumentId         = retailSalesInvoice.Id,
             SourceDocumentType       = Core.Constants.Constant.SourceDocumentType.RetailSalesInvoice,
             SourceDocumentDetailCode = retailSalesInvoiceDetail.Code,
             SourceDocumentDetailId   = retailSalesInvoiceDetail.Id,
             SourceDocumentDetailType = Core.Constants.Constant.SourceDocumentDetailType.RetailSalesInvoiceDetail,
             WarehouseId              = retailSalesInvoice.WarehouseId,
             WarehouseItemId          = warehouseItem.Id
         };
         stockMutation           = _stockMutationService.CreateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
         stockMutation.CreatedAt = (DateTime)retailSalesInvoice.ConfirmationDate.GetValueOrDefault();
         _stockMutationService.UpdateObject(stockMutation, _warehouseService, _warehouseItemService, _itemService, _barringService);
         _stockMutationService.StockMutateObject(stockMutation, _itemService, _barringService, _warehouseItemService);
         retailSalesInvoiceDetail.CoGS = retailSalesInvoiceDetail.Quantity * item.AvgPrice;
         retailSalesInvoiceDetail      = _repository.ConfirmObject(retailSalesInvoiceDetail);
     }
     return(retailSalesInvoiceDetail);
 }
        public RetailSalesInvoice VIsConfirmableRetailSalesInvoiceDetails(RetailSalesInvoice retailSalesInvoice, IRetailSalesInvoiceDetailService _retailSalesInvoiceDetailService,
                                                                          IRetailSalesInvoiceService _retailSalesInvoiceService, IWarehouseItemService _warehouseItemService)
        {
            IList <RetailSalesInvoiceDetail> retailSalesInvoiceDetails = _retailSalesInvoiceDetailService.GetObjectsByRetailSalesInvoiceId(retailSalesInvoice.Id);

            if (!retailSalesInvoiceDetails.Any())
            {
                retailSalesInvoice.Errors.Add("Generic", "RetailSalesInvoiceDetails Tidak ada");
            }
            else
            {
                IRetailSalesInvoiceDetailValidator validator = _retailSalesInvoiceDetailService.GetValidator();
                foreach (var retailSalesInvoiceDetail in retailSalesInvoiceDetails)
                {
                    retailSalesInvoiceDetail.Errors = new Dictionary <string, string>();
                    if (!validator.ValidConfirmObject(retailSalesInvoiceDetail, _retailSalesInvoiceService, _warehouseItemService))
                    {
                        retailSalesInvoice.Errors.Add("Generic", "RetailSalesInvoiceDetails harus confirmable semua");
                        return(retailSalesInvoice);
                    }
                }
            }
            return(retailSalesInvoice);
        }