/// <summary> /// Gets the outcome strategy for the requested warehouse. /// </summary> /// <param name="warehouseId">The warehouse id for which to get the outcome strategy.</param> /// <returns>Outcome strategy object that implements <see cref="IOutcomeStrategy"/>.</returns> public IOutcomeStrategy GetOutcomeStrategy(Guid warehouseId) { Warehouse wh = DictionaryMapper.Instance.GetWarehouse(warehouseId); if (wh.ValuationMethod == ValuationMethod.DeliverySelection) { return(new DeliverySelectionStrategy(BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(wh).Value)); } else if (wh.ValuationMethod == ValuationMethod.Fifo) { return(new FifoStrategy(BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(wh).Value)); } else { throw new InvalidOperationException("Unknown warehouse strategy."); } }
public override void Validate() { foreach (ShiftAttrValue attribute in this.Children) { //ShiftField df = DictionaryMapper.Instance.GetShiftField(attribute.ShiftFieldId); var count = this.Children.Where(c => c.ShiftFieldId == attribute.ShiftFieldId && c != attribute).Count(); if (count > 0) { var field = DictionaryMapper.Instance.GetDocumentField(attribute.ShiftFieldId); if (field.Metadata.Element("allowMultiple") == null) { throw new ClientException(ClientExceptionId.SingleAttributeMultipled, null, "name:" + BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(field).Value); } } } base.Validate(); }
/// <summary> /// Validates the collection. /// </summary> public override void Validate() { Document parent = (Document)this.Parent; DocumentType dt = parent.DocumentType; decimal totalAmountOnPayments = 0; bool doesAnyPaymentExist = false; #region Walidacja ilości płatności na dokumencie if (!dt.AllowedPayments.IsUndefined) { if (!dt.AllowedPayments.IsInRange(this.Children.Count)) { if (dt.AllowedPayments.IsSingleValue && dt.AllowedPayments.Min == 0) { throw new ClientException(ClientExceptionId.IncorrectNumberOfPayments); } else if (dt.AllowedPayments.IsMaxInfinity && dt.AllowedPayments.Min == 1) { throw new ClientException(ClientExceptionId.IncorrectNumberOfPayments2); } else { throw new ClientException(ClientExceptionId.IncorrectNumberOfPayments3, null, "count:" + dt.AllowedPayments.Serialize()); } } } else { DocumentCategory dc = dt.DocumentCategory; if (dc == DocumentCategory.SalesOrder || dc == DocumentCategory.Service) { if (this.Children.Count != 0) { throw new ClientException(ClientExceptionId.IncorrectNumberOfPayments); } } else if (dc == DocumentCategory.Sales && this.Children.Count == 0) { throw new ClientException(ClientExceptionId.IncorrectNumberOfPayments2); } } #endregion //validate if all payments contains forbidden payment method id foreach (Payment pt in this.Children) { doesAnyPaymentExist = true; if (pt.Amount > 0 || parent == null || parent.BOType != BusinessObjectType.FinancialDocument) { totalAmountOnPayments += pt.Amount; } if (dt.CommercialDocumentOptions != null) { bool exists = false; foreach (XElement id in dt.CommercialDocumentOptions.PaymentMethods.Elements()) { if (pt.PaymentMethodId == new Guid(id.Value)) { exists = true; break; } } if (!exists) { string paymentMethod = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetPaymentMethod(pt.PaymentMethodId.Value)).Value; throw new ClientException(ClientExceptionId.PaymentMethodForbidden, null, "paymentMethodName:" + paymentMethod); } } } if (doesAnyPaymentExist) { totalAmountOnPayments = Math.Round(Math.Abs(totalAmountOnPayments), 2, MidpointRounding.AwayFromZero); DocumentCategory parentCategory = parent.DocumentType.DocumentCategory; if (parent.BOType == BusinessObjectType.CommercialDocument && parentCategory != DocumentCategory.Purchase && parentCategory != DocumentCategory.PurchaseCorrection) { CommercialDocument parentDocument = (CommercialDocument)parent; decimal grossValueToCompare = parentDocument.DifferentialPaymentsAndDocumentValueCheck ? parentDocument.GrossValue + parentDocument.GrossValueBeforeCorrection : parentDocument.GrossValue; if (Math.Abs(grossValueToCompare) != totalAmountOnPayments) { throw new ClientException(ClientExceptionId.DifferentPaymentsAndDocumentValue); } } else if (parent.BOType == BusinessObjectType.FinancialDocument && Math.Round(Math.Abs(((FinancialDocument)parent).Amount), 2, MidpointRounding.AwayFromZero) != totalAmountOnPayments) { throw new ClientException(ClientExceptionId.DifferentPaymentsAndDocumentValue); } } base.Validate(); }
/// <summary> /// Validates the collection. /// </summary> public override void Validate() { //check for forbidden document featues foreach (DocumentAttrValue attribute in this.Children) { DocumentField df = DictionaryMapper.Instance.GetDocumentField(attribute.DocumentFieldId); if (df.Name.StartsWith("DocumentFeature_", StringComparison.Ordinal)) { DocumentType dt = DictionaryMapper.Instance.GetDocumentType(((Document)this.Parent).DocumentTypeId); bool exists = false; IEnumerable <XElement> allowedDocumentFeatures = null; if (this.Parent.BOType == BusinessObjectType.CommercialDocument) { allowedDocumentFeatures = dt.CommercialDocumentOptions.DocumentFeatures.Elements(); } else if (this.Parent.BOType == BusinessObjectType.WarehouseDocument) { allowedDocumentFeatures = dt.WarehouseDocumentOptions.DocumentFeatures.Elements(); } else if (this.Parent.BOType == BusinessObjectType.FinancialDocument) { allowedDocumentFeatures = dt.FinancialDocumentOptions.DocumentFeatures.Elements(); } if (allowedDocumentFeatures != null) { foreach (XElement id in allowedDocumentFeatures) { if (attribute.DocumentFieldId == new Guid(id.Value)) { exists = true; break; } } if (!exists) { string featureName = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetDocumentField(attribute.DocumentFieldId)).Value; throw new ClientException(ClientExceptionId.DocumentFeatureForbidden, null, "documentFeatureName:" + featureName); } } } var count = this.Children.Where(c => c.DocumentFieldId == attribute.DocumentFieldId && c != attribute).Count(); if (count > 0) { var field = DictionaryMapper.Instance.GetDocumentField(attribute.DocumentFieldId); if (field.Metadata.Element("allowMultiple") == null) { throw new ClientException(ClientExceptionId.SingleAttributeMultipled, null, "name:" + BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(field).Value); } } } base.Validate(); }
private bool CheckForQuantityBelowRelated(WarehouseDocument document) { bool outcomeCorrectionNeeded = false; WarehouseItemQuantityDictionary whItemDict = new WarehouseItemQuantityDictionary(); List <DeliveryRequest> deliveryRequests = new List <DeliveryRequest>(); foreach (WarehouseDocumentLine line in document.Lines.Children) { decimal relatedQuantity = ((WarehouseDocumentLine)line.AlternateVersion).IncomeOutcomeRelations.Children.Sum(s => s.Quantity); if (relatedQuantity > 0) { outcomeCorrectionNeeded = true; } /* * if (line.Quantity < relatedQuantity) * { * string unit = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetUnit(line.UnitId)).Attribute("symbol").Value; * throw new ClientException(ClientExceptionId.WarehouseCorrectionError4, null, * "itemName:" + line.ItemName, * "count:" + relatedQuantity.ToString("G", CultureInfo.CreateSpecificCulture("pl-PL")), * "unit:" + unit); * }*///to byla dawna walidacja zeby nie moznabylo korygowac ponizej wartosci rozchodowanej. teraz jest ona inna bo mozna, ale nie mozna zejsc globalnie z towarem ponizej zera decimal differentialQuantity = line.Quantity - ((WarehouseDocumentLine)line.AlternateVersion).Quantity; whItemDict.Add(document.WarehouseId, line.ItemId, differentialQuantity); DeliveryRequest delivery = deliveryRequests.Where(d => d.ItemId == line.ItemId && d.WarehouseId == line.WarehouseId).FirstOrDefault(); if (delivery == null) { deliveryRequests.Add(new DeliveryRequest(line.ItemId, line.WarehouseId, line.UnitId)); } } //pobieramy dostawy ICollection <DeliveryResponse> deliveryResponses = this.mapper.GetDeliveries(deliveryRequests); //iterujemy po naszym slowniku i sprawdzamy czy ilosci sa na stanie if (whItemDict.Dictionary.ContainsKey(document.WarehouseId)) { var dctItemQuantity = whItemDict.Dictionary[document.WarehouseId]; foreach (var key in dctItemQuantity.Keys) //iterujemy po itemId { var delivery = deliveryResponses.Where(d => d.ItemId == key).First(); if (delivery.QuantityInStock - Math.Abs(dctItemQuantity[key]) < 0) { //wyciagamy nazwe towaru string itemName = document.Lines.Where(l => l.ItemId == delivery.ItemId).First().ItemName; string warehouseName = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetWarehouse(document.WarehouseId)).Value; throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + warehouseName); } } } return(outcomeCorrectionNeeded); }
private void ValidateServiceReservation(ServiceDocument document) { //sumujemy ile towarow potrzebujemy "dorezerwowac" //sprawdzamy czy jest an stanie tyle dostepnych //jezeli nie to rzucamy wyjatek WarehouseItemUnitQuantityDictionary dict = new WarehouseItemUnitQuantityDictionary(); this.mapper.AddItemsToItemTypesCache(document); IDictionary <Guid, Guid> cache = SessionManager.VolatileElements.ItemTypesCache; foreach (var line in document.Lines) { Guid itemTypeId = cache[line.ItemId]; ItemType itemType = DictionaryMapper.Instance.GetItemType(itemTypeId); if (!itemType.IsWarehouseStorable) { continue; } if (line.OrderDirection == -1) { decimal quantity = line.Quantity; CommercialDocumentLine altLine = line.AlternateVersion as CommercialDocumentLine; if (altLine != null) { quantity -= altLine.Quantity; } dict.Add(line.WarehouseId.Value, line.ItemId, line.UnitId, quantity); } } ServiceDocument alternateDocument = document.AlternateVersion as ServiceDocument; if (alternateDocument != null) { foreach (var line in alternateDocument.Lines) { if (line.Status == BusinessObjectStatus.Deleted && line.OrderDirection == -1) { dict.Add(line.WarehouseId.Value, line.ItemId, line.UnitId, -line.Quantity); } } } List <DeliveryRequest> deliveryRequests = new List <DeliveryRequest>(); foreach (Guid warehouseId in dict.Dictionary.Keys) { var itemUnitQtyDict = dict.Dictionary[warehouseId]; foreach (Guid itemId in itemUnitQtyDict.Keys) { var unitQtyDict = itemUnitQtyDict[itemId]; foreach (Guid unitId in unitQtyDict.Keys) { decimal quantity = unitQtyDict[unitId]; if (quantity > 0) { DeliveryRequest delivery = deliveryRequests.Where(d => d.ItemId == itemId && d.WarehouseId == warehouseId).FirstOrDefault(); if (delivery == null) { deliveryRequests.Add(new DeliveryRequest(itemId, warehouseId, unitId)); } } } } } ICollection <DeliveryResponse> deliveryResponses = this.mapper.GetDeliveries(deliveryRequests); foreach (Guid warehouseId in dict.Dictionary.Keys) { var itemUnitQtyDict = dict.Dictionary[warehouseId]; foreach (Guid itemId in itemUnitQtyDict.Keys) { var unitQtyDict = itemUnitQtyDict[itemId]; foreach (Guid unitId in unitQtyDict.Keys) { decimal quantity = unitQtyDict[unitId]; if (quantity > 0) { var deliveryResponse = deliveryResponses.Where(d => d.ItemId == itemId && d.WarehouseId == warehouseId).First(); if (quantity > deliveryResponse.AvailableQuantity) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(itemId); string warehouseName = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetWarehouse(warehouseId)).Value; throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + warehouseName); } } } } } }