コード例 #1
0
 public AccountDocumentPositionsBuilder()
 {
     SumInWordsConverter  = new SumInWordsConverter();
     ShowDiscount         = false;
     CurrencyFormatString = "#,0.00'руб.'";
 }
コード例 #2
0
        private void FillTableFooter(Table table)
        {
            var mergedColumns = ShowDiscount ? 5 : 3;

            #region ИТОГО

            var totalRow = new TableRow();

            var textTotal = Math.Abs(Account.Nds) < 1e-8
                ? "Итого "
                : string.Format("Итого, включая НДС : {0} % ", Account.Nds);

            AppendMergedCellsToRow(totalRow, textTotal, mergedColumns, RpAccountPositions);

            totalRow.AppendChild(
                CreateTableCell(
                    Account.Sum.ToString(CurrencyFormatString),
                    RpAccountPositions,
                    justification: JustificationValues.Right));

            table.AppendChild(totalRow);

            #endregion

            #region НДС

            var ndsRow = new TableRow();

            if (Math.Abs(Account.Nds) < 1e-8 && Account.BusinessUnitId == 3 /* ЦКП */)
            {
                AppendMergedCellsToRow(ndsRow, "Без налога (НДС)", mergedColumns, RpAccountPositions);

                ndsRow.AppendChild(
                    CreateTableCell("-", RpAccountPositions, justification: JustificationValues.Right));
            }
            else if (Math.Abs(Account.Nds) < 1e-8)
            {
                AppendMergedCellsToRow(ndsRow, "НДС не облагается в связи с применением упрощенной системы налогообложения",
                                       mergedColumns + 1, RpAccountPositionsBold, justification: JustificationValues.Center);
            }
            else
            {
                var sumNds = Account.AccountPositions.ToArray()
                             .Sum(position => position.Sum * (Account.Nds / (Account.Nds + 100)));

                AppendMergedCellsToRow(ndsRow, "В том числе НДС:", mergedColumns, RpAccountPositions);

                ndsRow.AppendChild(
                    CreateTableCell(
                        sumNds.ToString(CurrencyFormatString), RpAccountPositions, justification: JustificationValues.Right));
            }

            table.AppendChild(ndsRow);

            #endregion

            var printNewTotal = false;

            #region Счет на доплату

            if (Account.Prepaid > 0)
            {
                printNewTotal = true;

                var prepaidRow = new TableRow();

                AppendMergedCellsToRow(prepaidRow, "В авансе:", mergedColumns, RpAccountPositions);

                prepaidRow.AppendChild(
                    CreateTableCell(
                        Account.Prepaid.ToString(CurrencyFormatString),
                        RpAccountPositions, justification: JustificationValues.Right));

                table.AppendChild(prepaidRow);

                if (Math.Abs(Account.Nds) >= 1e-8)
                {
                    var prepaidNdsRow = new TableRow();

                    var prepaidNdsSum = Account.Prepaid * (1 - 100 / (100 + Account.Nds));

                    AppendMergedCellsToRow(prepaidNdsRow, "В том числе НДС:", mergedColumns, RpAccountPositions);

                    prepaidNdsRow.AppendChild(
                        CreateTableCell(
                            prepaidNdsSum.ToString(CurrencyFormatString),
                            RpAccountPositions,
                            justification: JustificationValues.Right));

                    table.AppendChild(prepaidNdsRow);
                }
            }

            #endregion

            #region Счет на оплату долга

            if (Account.Prepaid > 0)
            {
                printNewTotal = true;

                var debtRow = new TableRow();

                AppendMergedCellsToRow(debtRow, "Долг:", mergedColumns, RpAccountPositions);

                debtRow.AppendChild(
                    CreateTableCell(
                        Account.Debt.ToString(CurrencyFormatString),
                        RpAccountPositions,
                        justification: JustificationValues.Right));

                table.AppendChild(debtRow);

                if (Math.Abs(Account.Nds) >= 1e-8)
                {
                    var debtNdsRow = new TableRow();

                    var debtNdsSum = Account.Debt * (1 - 100 / (100 + Account.Nds));

                    AppendMergedCellsToRow(debtNdsRow, "В том числе НДС:", mergedColumns, RpAccountPositions);

                    debtNdsRow.AppendChild(
                        CreateTableCell(
                            debtNdsSum.ToString(CurrencyFormatString),
                            RpAccountPositions,
                            justification: JustificationValues.Right));

                    table.AppendChild(debtNdsRow);
                }
            }

            #endregion

            #region Итого к оплате

            if (printNewTotal)
            {
                var totalToPayRow = new TableRow();

                var totalToPay = Account.Sum - Account.Prepaid + Account.Debt;

                AppendMergedCellsToRow(totalToPayRow, "Итого к оплате:", mergedColumns, RpAccountPositions);

                totalToPayRow.AppendChild(
                    CreateTableCell(
                        totalToPay.ToString(CurrencyFormatString),
                        RpAccountPositions,
                        justification: JustificationValues.Right));

                table.AppendChild(totalToPayRow);
            }

            #endregion

            #region Итого прописью

            var totalToPayInWords = new TableRow();

            var totalToPayInWordsText = string.Format("Итого прописью: {0}",
                                                      SumInWordsConverter.Convert((decimal)(Account.Sum - Account.Prepaid + Account.Debt)));

            AppendMergedCellsToRow(totalToPayInWords, totalToPayInWordsText, mergedColumns + 1, RpAccountPositionsBoldItalic, justification: JustificationValues.Left);

            table.AppendChild(totalToPayInWords);

            #endregion
        }