Example #1
0
 /// <summary>
 /// Sprawdza czy dokument realizuje zamknięte ZSP oraz opcjonalnie czy na liniach realizujących ZSP niekoniecznie zamknięte doszło do zmiany ilości
 /// </summary>
 /// <param name="checkQuantityChange">czy sprawdzać zmianę ilości na pozycjach realizujących ZSP</param>
 internal void ValidateSalesOrderRealizedLines(bool checkQuantityChange)
 {
     if (!this.IsNew && !this.SkipRealizeClosedSalesOrderCheck)
     {
         CommercialDocument alternateDocument = this.AlternateVersion != null ?
                                                (CommercialDocument)this.AlternateVersion : null;
         DocumentMapper mapper =
             (DocumentMapper)DependencyContainerManager.Container.Get <DocumentMapper>();
         foreach (CommercialDocumentLine commLine in this.Lines)
         {
             Guid?relatedSalesOrderId = commLine.Attributes.
                                        GetGuidValueByFieldName(DocumentFieldName.LineAttribute_RealizedSalesOrderLineId);
             //test czy realizuje zamknięte ZSP
             if (relatedSalesOrderId.HasValue)
             {
                 //test czy pozmieniały się ilości
                 if (checkQuantityChange && alternateDocument != null)
                 {
                     CommercialDocumentLine altLine = alternateDocument.Lines.Where(line => line.Id == commLine.Id).FirstOrDefault();
                     if (altLine != null && commLine.Quantity != altLine.Quantity)
                     {
                         throw new ClientException(ClientExceptionId.LineQuantityEditForbiddenRelatedSalesOrder, null, "order:" + commLine.Order);
                     }
                 }
                 CommercialDocument relatedSalesOrder =
                     mapper.GetCommercialDocumentByLineId(relatedSalesOrderId.Value);
                 if (SalesOrderFactory.IsSalesOrderClosed(relatedSalesOrder))
                 {
                     throw new ClientException(ClientExceptionId.DocumentEditForbiddenRelatedSalesOrderClosed);
                 }
             }
         }
     }
 }