예제 #1
0
 public static void DuplicateAttributes <T>(Document source, ICollection <T> destination) where T : Document
 {
     foreach (Document doc in destination)
     {
         DuplicableAttributeFactory.DuplicateAttributes(source, doc, null);
     }
 }
예제 #2
0
        public static void CreateCorrectiveDocument(XElement source, CommercialDocument destination)
        {
            Guid           sourceDocumentId = new Guid(source.Element("correctedDocumentId").Value);
            DocumentMapper mapper           = DependencyContainerManager.Container.Get <DocumentMapper>();

            ICollection <Guid> previousDocumentsId = mapper.GetCommercialCorrectiveDocumentsId(sourceDocumentId);

            CommercialDocument sourceDocument = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, sourceDocumentId);

            CommercialDocument lastDoc = sourceDocument;

            foreach (Guid corrId in previousDocumentsId)
            {
                CommercialDocument correctiveDoc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, corrId);

                CommercialCorrectiveDocumentFactory.RelateTwoCorrectiveDocuments(lastDoc, correctiveDoc, true);

                lastDoc = correctiveDoc;
            }

            CommercialCorrectiveDocumentFactory.CalculateDocumentsAfterCorrection(lastDoc);
            CommercialCorrectiveDocumentFactory.CreateNextCorrectiveDocument(lastDoc, destination);
            DuplicableAttributeFactory.DuplicateAttributes(lastDoc, destination);

            var salesOrderRelation = sourceDocument.Relations.Where(r => r.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault();

            if (salesOrderRelation != null)             //dokument jest do ZS wiec korekte tez tam podpinamy
            {
                var relation = destination.Relations.CreateNew();
                relation.RelationType    = DocumentRelationType.SalesOrderToCorrectiveCommercialDocument;
                relation.RelatedDocument = salesOrderRelation.RelatedDocument;
            }
        }
예제 #3
0
        public static void CreateOutcomeShiftFromWarehouseDocument(XElement source, WarehouseDocument destination)
        {
            /*
             * <root>
             *   <warehouseDocumentId>GUID</warehouseDocumentId>
             * </root>
             */
            DocumentMapper    mapper         = DependencyContainerManager.Container.Get <DocumentMapper>();
            WarehouseDocument incomeDocument = (WarehouseDocument)mapper.LoadBusinessObject(BusinessObjectType.WarehouseDocument, new Guid(source.Element("warehouseDocumentId").Value));

            destination.WarehouseId = incomeDocument.WarehouseId;

            //create lines
            foreach (var incLine in incomeDocument.Lines)
            {
                WarehouseDocumentLine line = destination.Lines.CreateNew();

                line.ItemId     = incLine.ItemId;
                line.ItemName   = incLine.ItemName;
                line.Quantity   = incLine.Quantity;
                line.UnitId     = incLine.UnitId;
                line.ItemTypeId = incLine.ItemTypeId;
            }

            //Duplicate attributes
            DuplicableAttributeFactory.DuplicateAttributes(incomeDocument, destination);
        }
예제 #4
0
        private static List <XElement> ShiftDuplicableAttributesList(XElement shiftDbXml)
        {
            List <XElement> result = new List <XElement>();

            foreach (XElement documentAttrValueElement in shiftDbXml.Element("documentAttrValue").Elements("entry"))
            {
                DocumentField df = DictionaryMapper.Instance.GetDocumentField(new Guid(documentAttrValueElement.Element(XmlName.DocumentFieldId).Value));
                if (df.ShiftDuplicateAction != DuplicatedAttributeAction.NoDuplicate)
                {
                    result.Add(DuplicableAttributeFactory.ConvertAttributeFromDbToBoXmlFormat(documentAttrValueElement, df.DataType));
                }
            }
            return(result);
        }
예제 #5
0
        public static void GeneratePurchaseInvoiceFromMultipleSalesOrders(XElement source, CommercialDocument destination)
        {
            /*
             *  robimy fakture zakupową na pozycje usługowe
             */

            DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>();

            List <CommercialDocument> soDocs = new List <CommercialDocument>();

            CalculationType?calcType = CalculationType.Net;

            destination.CalculationType = calcType.Value;

            foreach (XElement soId in source.Elements("salesOrderId"))
            {
                Guid docId = new Guid(soId.Value);

                var exists = soDocs.Where(d => d.Id.Value == docId).FirstOrDefault();

                if (exists != null)
                {
                    continue;
                }

                CommercialDocument doc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, docId);
                soDocs.Add(doc);
            }


            //kopiujemy atrybuty jezeli sa jakies takie
            DuplicableAttributeFactory.DuplicateAttributes(soDocs, destination);

            XElement tagXml = new XElement("salesOrders");

            foreach (CommercialDocument salesOrder in soDocs)
            {
                //Dla dokumentu zakupowego nie ma ograniczenia
                //if (salesOrder.Relations.Where(rr => rr.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault() != null)
                //    throw new ClientException(ClientExceptionId.UnableToCreateInvoiceToSalesOrder, null, "orderNumber:" + salesOrder.Number.FullNumber);

                SalesOrderFactory.CopyLinesFromSalesOrder(salesOrder, destination, true, false, true, false);
                tagXml.Add(new XElement("salesOrder", new XAttribute("id", salesOrder.Id.ToUpperString()), new XAttribute("version", salesOrder.Version.ToUpperString())));
            }

            destination.Calculate();
            destination.Tag = tagXml.ToString(SaveOptions.DisableFormatting);
        }
예제 #6
0
        //istniejący obiekt
        public static void DuplicateShiftAttributes(XElement source, Document destination)
        {
            var attrsToDuplicate = DuplicableAttributeFactory.ShiftDuplicableAttributesList(source);

            if (attrsToDuplicate.Count > 0)
            {
                foreach (XElement attrToDuplicate in attrsToDuplicate)
                {
                    string            documentFieldId   = attrToDuplicate.Element(XmlName.DocumentFieldId).Value;
                    DocumentField     documentField     = DictionaryMapper.Instance.GetDocumentField(new Guid(documentFieldId));
                    DocumentFieldName documentFieldName = documentField.TypeName;
                    DocumentAttrValue destAttr          = destination.Attributes.GetOrCreateNew(documentFieldName);
                    destAttr.Value = new XElement(XmlName.Value, attrToDuplicate.Element(XmlName.Value).Nodes());
                }
            }
        }
예제 #7
0
        public static void DuplicateAttributes <T>(ICollection <T> source, Document destination) where T : Document
        {
            List <Guid> blockedAttributes = new List <Guid>();

            List <Guid> potentialyBlockedAttributes = new List <Guid>();

            //sprawdzamy czy atrybuty o akcji OneInstance wystepuja na kazdym dokumencie
            foreach (Document doc in source)
            {
                foreach (DocumentAttrValue attr in doc.Attributes.Children)
                {
                    if (attr.IsDuplicableTo(destination.DocumentTypeId) && attr.DuplicateAction == DuplicatedAttributeAction.OneInstance)
                    {
                        potentialyBlockedAttributes.Add(attr.DocumentFieldId);
                    }
                }
            }

            //sprawdzamy czy kazdy atrybut wystepuje na kazdym ze zrodlowych dok.
            foreach (Document doc in source)
            {
                foreach (Guid docFieldId in potentialyBlockedAttributes)
                {
                    if (doc.Attributes.Children.Where(a => a.DocumentFieldId == docFieldId).FirstOrDefault() == null)
                    {
                        if (!blockedAttributes.Contains(docFieldId))
                        {
                            blockedAttributes.Add(docFieldId);
                        }
                    }
                }
            }

            foreach (Document doc in source)
            {
                DuplicableAttributeFactory.DuplicateAttributes(doc, destination, blockedAttributes);
            }
        }
예제 #8
0
        //nowy obiekt tylko nowe atrybuty
        public static void DuplicateShiftAttributes(XElement source, XDocument destination)
        {
            var attrsToDuplicate = DuplicableAttributeFactory.ShiftDuplicableAttributesList(source);

            if (attrsToDuplicate.Count > 0)
            {
                var destAttrsElement = destination.XPathSelectElement("/*/*/attributes");
                var destAttrs        = destAttrsElement.Elements(XmlName.Attribute);
                int order            = destAttrs.Count() + 1;

                foreach (XElement attrToDuplicate in attrsToDuplicate)
                {
                    XElement attr = new XElement(XmlName.Attribute
                                                 , new XElement(XmlName.Id, Guid.NewGuid().ToUpperString())
                                                 , new XElement(attrToDuplicate.Element(XmlName.Value))
                                                 , new XElement(attrToDuplicate.Element(XmlName.DocumentFieldId))
                                                 , new XElement(XmlName.Order, order)
                                                 );
                    destAttrsElement.Add(attr);
                    order++;
                }
            }
        }
예제 #9
0
        public static void CreateCorrectiveDocument(XElement source, WarehouseDocument destination)
        {
            Guid           sourceDocumentId = new Guid(source.Element("correctedDocumentId").Value);
            DocumentMapper mapper           = DependencyContainerManager.Container.Get <DocumentMapper>();

            WarehouseDocument  sourceDocument = (WarehouseDocument)mapper.LoadBusinessObject(BusinessObjectType.WarehouseDocument, sourceDocumentId);
            WarehouseDirection direction      = sourceDocument.WarehouseDirection;

            if (ConfigurationMapper.Instance.PreventDocumentCorrectionBeforeSystemStart &&
                sourceDocument.IsBeforeSystemStart)
            {
                throw new ClientException(ClientExceptionId.DocumentCorrectionBeforeSystemStartError);
            }

            destination.Contractor  = sourceDocument.Contractor;
            destination.WarehouseId = sourceDocument.WarehouseId;

            DuplicableAttributeFactory.DuplicateAttributes(sourceDocument, destination);

            foreach (WarehouseDocumentLine line in sourceDocument.Lines.Children)
            {
                WarehouseDocumentLine correctedLine = mapper.GetWarehouseDocumentLineAfterCorrection(line, direction);

                if (correctedLine != null)
                {
                    destination.Lines.AppendChild(correctedLine);
                }
            }

            if (destination.Lines.Children.Count == 0)
            {
                throw new ClientException(ClientExceptionId.FullyCorrectedCorrectionError);
            }

            destination.InitialCorrectedDocument = sourceDocument;
        }
예제 #10
0
        private static void GenerateFinancialDocumentToPayment(Payment payment, CommercialDocument document)
        {
            DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>();

            using (DocumentCoordinator coordinator = new DocumentCoordinator(false, false))
            {
                PaymentMethod paymentMethod = DictionaryMapper.Instance.GetPaymentMethod(payment.PaymentMethodId.Value);

                Guid branchId = SessionManager.User.BranchId;

                if (DictionaryMapper.Instance.IsPaymentMethodSupportedByRegister(paymentMethod.Id.Value, branchId))
                {
                    FinancialRegister register = DictionaryMapper.Instance.GetFinancialRegisterForSpecifiedPaymentMethod(paymentMethod.Id.Value, branchId, payment.PaymentCurrencyId);

                    if (register == null)
                    {
                        throw new ClientException(ClientExceptionId.UnableToIssueFinancialDocument3);
                    }

                    FinancialDirection direction = FinancialDocumentFactory.GetFinancialDirectionForPayment(document, payment);

                    Guid?reportId = mapper.GetOpenedFinancialReportId(register.Id.Value);

                    if (reportId == null)
                    {
                        throw new ClientException(ClientExceptionId.UnableToIssueDocumentToClosedFinancialReport);
                    }

                    FinancialDocument financialDoc = new FinancialDocument();
                    financialDoc.RelatedCommercialDocument = document;
                    coordinator.TrySaveProfileIdAttribute(financialDoc);

                    if (direction == FinancialDirection.Income)
                    {
                        financialDoc.DocumentTypeId         = register.IncomeDocumentTypeId;
                        financialDoc.Number.NumberSettingId = register.IncomeNumberSettingId;
                    }
                    else
                    {
                        financialDoc.DocumentTypeId         = register.OutcomeDocumentTypeId;
                        financialDoc.Number.NumberSettingId = register.OutcomeNumberSettingId;
                    }

                    financialDoc.Contractor          = payment.Contractor;
                    financialDoc.ContractorAddressId = payment.ContractorAddressId;
                    FinancialReport report = new FinancialReport();
                    report.Id = reportId;
                    report.FinancialRegisterId   = register.Id.Value;
                    financialDoc.FinancialReport = report;
                    financialDoc.DocumentStatus  = DocumentStatus.Committed;
                    DuplicableAttributeFactory.DuplicateAttributes(document, financialDoc);

                    Payment pt = financialDoc.Payments.CreateNew();
                    pt.Amount                       = Math.Abs(payment.Amount);
                    pt.ExchangeRate                 = financialDoc.ExchangeRate = document.ExchangeRate;
                    pt.ExchangeScale                = financialDoc.ExchangeScale = document.ExchangeScale;
                    pt.ExchangeDate                 = financialDoc.ExchangeDate = document.ExchangeDate;
                    financialDoc.Amount             = pt.Amount;
                    financialDoc.DocumentCurrencyId = payment.PaymentCurrencyId;
                    PaymentSettlement settlement = pt.Settlements.CreateNew();
                    settlement.IsAutoGenerated = true;
                    settlement.RelatedPayment  = payment;
                    settlement.Amount          = pt.Amount;

                    document.AddRelatedObject(financialDoc);
                }
            }
        }
예제 #11
0
        public static void GenerateInvoiceFromMultipleSalesOrders(XElement source, CommercialDocument destination)
        {
            /*
             *      <source type="multipleSalesOrders">
             *        <salesOrderId>{documentId}</salesOrderId>
             *        <salesOrderId>{documentId}</salesOrderId>
             *        <salesOrderId>{documentId}</salesOrderId>
             *        .........
             *      </source>
             */

            DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>();

            List <CommercialDocument> soDocs = new List <CommercialDocument>();

            CalculationType?calcType = null;

            foreach (XElement soId in source.Elements("salesOrderId"))
            {
                Guid docId = new Guid(soId.Value);

                var exists = soDocs.Where(d => d.Id.Value == docId).FirstOrDefault();

                if (exists != null)
                {
                    continue;
                }

                CommercialDocument doc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, docId);
                soDocs.Add(doc);

                if (calcType == null)
                {
                    calcType = doc.CalculationType;
                }
                else if (calcType.Value != doc.CalculationType)
                {
                    throw new ClientException(ClientExceptionId.DifferentCalculationTypes);
                }
            }

            if (calcType.Value != destination.CalculationType && destination.DocumentType.CommercialDocumentOptions.AllowCalculationTypeChange)
            {
                destination.CalculationType = calcType.Value;
            }

            //sprawdzamy czy dok. zrodlowe maja wspolnego kontrahenta. jezeli tak to kopiujemy go na fakture
            bool copyContractor = true;

            //jezeli gdzies nie ma kontrahenta to nie kopiujemy
            var emptyContractor = soDocs.Where(w => w.Contractor == null).FirstOrDefault();

            if (emptyContractor != null)
            {
                copyContractor = false;
            }

            if (copyContractor)
            {
                var differentContractor = soDocs.Where(ww => ww.Contractor.Id.Value != soDocs[0].Contractor.Id.Value).FirstOrDefault();

                if (differentContractor != null)
                {
                    copyContractor = false;
                }
            }

            if (copyContractor)
            {
                destination.Contractor = soDocs[0].Contractor;

                if (destination.Contractor != null)
                {
                    var address = destination.Contractor.Addresses.GetBillingAddress();

                    if (address != null)
                    {
                        destination.ContractorAddressId = address.Id.Value;
                    }
                }
            }

            //kopiujemy atrybuty jezeli sa jakies takie
            DuplicableAttributeFactory.DuplicateAttributes(soDocs, destination);

            XElement tagXml = new XElement("salesOrders");

            foreach (CommercialDocument salesOrder in soDocs)
            {
                if (salesOrder.Relations.Where(rr => rr.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault() != null)
                {
                    throw new ClientException(ClientExceptionId.UnableToCreateInvoiceToSalesOrder, null, "orderNumber:" + salesOrder.Number.FullNumber);
                }

                SalesOrderFactory.CopyLinesFromSalesOrder(salesOrder, destination, true, false, true, true);
                tagXml.Add(new XElement("salesOrder", new XAttribute("id", salesOrder.Id.ToUpperString()), new XAttribute("version", salesOrder.Version.ToUpperString())));
            }

            destination.Calculate();
            destination.Tag = tagXml.ToString(SaveOptions.DisableFormatting);
        }
예제 #12
0
        public static void GeneratePrepaymentDocument(XElement source, CommercialDocument destination)
        {
            /*
             *      <source type="salesOrder">
             *        <salesOrderId>{documentId}</salesOrderId>
             *        <processObject>prepaidInvoice</processObject>
             *        <closeOrder>false</closeOrder>
             *      </source>
             */
            DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>();

            bool closeOrder = false;

            if (source.Element("closeOrder") != null && source.Element("closeOrder").Value.ToUpperInvariant() == "TRUE")
            {
                closeOrder = true;
            }

            CommercialDocument salesOrder = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(source.Element("salesOrderId").Value));


            SalesOrderFactory.CheckIfSalesOrderHasWarehouseDocumentsWithInvoices(salesOrder, closeOrder);

            SalesOrderSettlements salesOrderSettlements = new SalesOrderSettlements();

            salesOrderSettlements.LoadSalesOrder(salesOrder);
            XElement settledAmount = mapper.GetSalesOrderSettledAmount(salesOrder.Id.Value);

            salesOrderSettlements.LoadPrepaids(settledAmount);
            destination.SalesOrderSettlements = salesOrderSettlements;

            string processType   = salesOrder.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value;
            string processObject = source.Element("processObject").Value;
            bool   isSimulated   = processObject == "simulatedInvoice";
            bool   hasProtocole  = source.Element("protocole") != null && source.Element("protocole").Value == "true";

            ProcessManager.Instance.AppendProcessAttributes(destination, processType, processObject, null, null);
            DuplicableAttributeFactory.DuplicateAttributes(salesOrder, destination);

            if (isSimulated && hasProtocole)
            {
                destination.Attributes.GetOrCreateNew(DocumentFieldName.Attribute_IsSimulateSettlementInvoiceWithProtocole).Value.Value = "1";
            }

            //sprawdzamy czy dokumenty zrodlowe maja zgodne sposoby liczenia

            if (salesOrder.CalculationType != destination.CalculationType && destination.DocumentType.CommercialDocumentOptions.AllowCalculationTypeChange)
            {
                destination.CalculationType = salesOrder.CalculationType;
            }

            if (salesOrder.Contractor != null)
            {
                destination.Contractor = (Contractor)salesOrder.Contractor;
            }

            if (salesOrder.ContractorAddressId != null)
            {
                destination.ContractorAddressId = salesOrder.ContractorAddressId;
            }

            int prepaidDocuments = 0;

            prepaidDocuments = salesOrder.Relations.Where(r => r.RelationType == DocumentRelationType.SalesOrderToInvoice).Count();

            destination.Tag = prepaidDocuments.ToString(CultureInfo.InvariantCulture);

            /* teraz wybieramy odpowiednia sciezke algorytmu. mamy takie mozliwosc:
             * 1) wystawiamy zaliczke
             *    - w takiej sytuacji wybieramy id towaru zaliczkowego dla kazdej ze stawek vat i wpisujemy tam wartosci nierozliczone
             * 2) wystawiamy fakture rozliczajaca (closeOrder == true) podczas gdy mamy zaliczki (prepaidDocuments > 0)
             *    - kopiujemy wszystkie pozycje z ZS 1:1, a tabele vat pomniejszamy o sume zaliczek
             * 3) wystawiamy fakture rozliczajaca (closeOrder == true) i nie mamy dokumentow zaliczkowych (prepaidDocuments == 0)
             *    - w takim przypadku zamowienie sprzedazowe traktujemy jako proforme, kopiujemy wszystkie pozycje i tabele vat bez zmian i tyle
             */


            //wstawiamy odpowiedni towar na zaliczke + ustawiamy odpowiednai wartosc
            int stage = 0;

            if (closeOrder)
            {
                stage = 0;
            }
            else if (prepaidDocuments == 0)
            {
                stage = 1;
            }
            else if (prepaidDocuments == 1)
            {
                stage = 2;
            }
            else if (prepaidDocuments == 2)
            {
                stage = 3;
            }
            else if (prepaidDocuments >= 3)
            {
                stage = 4;
            }

            List <Guid> items = new List <Guid>(2);

            ICollection <SalesOrderSettlement> unsettledValues = salesOrderSettlements.GetUnsettledValues();

            foreach (var v in salesOrder.VatTableEntries.GetVatRates())
            {
                items.Add(ProcessManager.Instance.GetPrepaidItemId(salesOrder, stage, v));
            }

            XDocument xml = DependencyContainerManager.Container.Get <ItemMapper>().GetItemsDetailsForDocument(false, null, null, items);

            if (closeOrder)
            {
                SalesOrderFactory.CopyLinesFromSalesOrder(salesOrder, destination, false, true, false, true);
                destination.Calculate();

                //Ostatnia rata pchamy do atrybutu zeby wydruk fiskalny wiedzial co ma wydrukowac
                if (destination.CalculationType == CalculationType.Gross && !isSimulated)
                {
                    XElement fiscalLines = new XElement("fiscalLines");

                    foreach (var v in unsettledValues)
                    {
                        XElement itemXml    = xml.Root.Elements().Where(i => i.Attribute("id").Value == ProcessManager.Instance.GetPrepaidItemId(salesOrder, stage, v.VatRateId).ToUpperString()).First();
                        XElement fiscalLine = new XElement("fiscalLine");
                        fiscalLine.Add(new XElement("itemName", itemXml.Attribute("name").Value));
                        fiscalLine.Add(new XElement("quantity", "1"));
                        fiscalLine.Add(new XElement("vatRateId", itemXml.Attribute("vatRateId").Value));
                        fiscalLine.Add(new XElement("grossPrice", v.GrossValue.ToString(CultureInfo.InvariantCulture)));
                        fiscalLine.Add(new XElement("grossValue", v.GrossValue.ToString(CultureInfo.InvariantCulture)));
                        fiscalLine.Add(new XElement("unitId", itemXml.Attribute("unitId").Value));
                        fiscalLines.Add(fiscalLine);
                    }

                    var attribute = destination.Attributes.CreateNew(DocumentFieldName.Attribute_FiscalPrepayment);
                    attribute.Value = fiscalLines;
                }

                if (prepaidDocuments > 0)                 // *2)
                {
                    decimal maxDifference = ProcessManager.Instance.GetMaxSettlementDifference(salesOrder);

                    foreach (var v in salesOrderSettlements.Prepaids)
                    {
                        if (v.NetValue > 0 || v.GrossValue > 0 || v.VatValue > 0)
                        {
                            var vt        = destination.VatTableEntries.Where(t => t.VatRateId == v.VatRateId).FirstOrDefault();
                            var prepaidVt = destination.VatTableEntries.CreateNewAfter(vt, v.VatRateId);
                            prepaidVt.VatRateId  = v.VatRateId;
                            prepaidVt.NetValue   = -v.NetValue;
                            prepaidVt.GrossValue = -v.GrossValue;
                            prepaidVt.VatValue   = -v.VatValue;

                            decimal vtNetValue   = 0;
                            decimal vtGrossValue = 0;
                            decimal vtVatValue   = 0;
                            if (vt != null)
                            {
                                vtNetValue   = vt.NetValue;
                                vtGrossValue = vt.GrossValue;
                                vtVatValue   = vt.VatValue;
                            }

                            decimal grossBalance = vtGrossValue + prepaidVt.GrossValue;
                            decimal netBalance   = vtNetValue + prepaidVt.NetValue;
                            decimal vatBalance   = vtVatValue + prepaidVt.VatValue;

                            SalesOrderBalanceValidator validator =
                                new SalesOrderBalanceValidator(maxDifference, grossBalance, netBalance, vatBalance);

                            if (validator.IsIllegalOverPayment)
                            {
                                throw new ClientException(ClientExceptionId.SalesOrderSettlementOverpaidError, null, "value:" + (-grossBalance).ToString(CultureInfo.InvariantCulture).Replace('.', ',')); //nadpłata powyżej granicy błędu
                            }
                            else if (validator.IsAcceptableOverPayment)                                                                                                                                    //czyli mamy nadplate w granicy bledu
                            {
                                prepaidVt.NetValue   = -vtNetValue;
                                prepaidVt.GrossValue = -vtGrossValue;
                                prepaidVt.VatValue   = -vtVatValue;
                            }
                        }
                    }
                }
                else
                {
                    throw new ClientException(ClientExceptionId.UnableToCreateSettlementDocument3);
                }

                decimal netValue   = 0;
                decimal grossValue = 0;
                decimal vatValue   = 0;

                foreach (var vt in destination.VatTableEntries)
                {
                    netValue   += vt.NetValue;
                    grossValue += vt.GrossValue;
                    vatValue   += vt.VatValue;
                }

                destination.NetValue   = netValue;
                destination.GrossValue = grossValue;
                destination.VatValue   = vatValue;

                destination.DisableLinesChange = DisableDocumentChangeReason.LINES_SETTLEMENT_INVOICE;

                if (!isSimulated)
                {
                    var attr = destination.Attributes.CreateNew(DocumentFieldName.Attribute_IsSettlementDocument);
                    attr.Value.Value = "1";
                }
            }
            else             //1) wystawiamy zaliczke
            {
                foreach (XElement itemXml in xml.Root.Elements("item"))
                {
                    CommercialDocumentLine line = destination.Lines.CreateNew();
                    line.ItemId = new Guid(itemXml.Attribute("id").Value);
                    Guid vatRateId = new Guid(itemXml.Attribute("vatRateId").Value);

                    if (itemXml.Attribute("code") != null)
                    {
                        line.ItemCode = itemXml.Attribute("code").Value;
                    }

                    line.UnitId      = new Guid(itemXml.Attribute("unitId").Value);
                    line.VatRateId   = vatRateId;
                    line.ItemVersion = new Guid(itemXml.Attribute("version").Value);
                    line.Quantity    = 1;
                    line.ItemName    = itemXml.Attribute("name").Value;
                }

                destination.Calculate();
            }
        }
예제 #13
0
 public static void DuplicateAttributes(Document source, Document destination)
 {
     DuplicableAttributeFactory.DuplicateAttributes(source, destination, null);
 }