Advertisement
Guest User

PDF generation and printing

a guest
Dec 3rd, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         private void GenerateDocuments()
  2.         {
  3.             if (_haveTax)
  4.             {
  5.                 ActGenerator ag = new ActGenerator(this);
  6.                 InvoiceGenerator ig = new InvoiceGenerator(this);
  7.                 _act = ag.Generate();
  8.                 _invoice = ig.Generate();
  9.             }
  10.             else
  11.             {
  12.                 NoticeGenerator ng = new NoticeGenerator(this);
  13.                 _notice = ng.Generate();
  14.             }
  15.         }
  16.  
  17.  
  18. using System;
  19. using System.Globalization;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Windows.Forms;
  23. using iTextSharp.text;
  24. using iTextSharp.text.pdf;
  25.  
  26. namespace PASSSS
  27. {
  28.     class InvoiceGenerator : IDocumentGenerator
  29.     {
  30.         private readonly DocumentHandler _handler;
  31.  
  32.         // Fonts
  33.         private static BaseFont _baseTahoma;
  34.         private static Font _tahomaBold;
  35.         private static Font _tahoma;
  36.         private static Font _tahoma14Bold;
  37.         private static Font _tahomaSmall;
  38.  
  39.         // Files
  40.         private iTextSharp.text.Document _invoiceDoc;
  41.         private PdfWriter _invoiceWriter;
  42.  
  43.         // Overall sum row
  44.         private PdfPRow _overallSumRow;
  45.  
  46.         public InvoiceGenerator(DocumentHandler handler)
  47.         {
  48.             _handler = handler;
  49.  
  50.             PrepareFonts();
  51.         }
  52.  
  53.         private static void PrepareFonts()
  54.         {
  55.             _baseTahoma = BaseFont.CreateFont("c:/windows/fonts/tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
  56.             _tahomaBold = new Font(_baseTahoma, 8, Font.BOLD);
  57.             _tahoma = new Font(_baseTahoma, 8, Font.NORMAL);
  58.             _tahoma14Bold = new Font(_baseTahoma, 14, Font.BOLD);
  59.             _tahomaSmall = new Font(_baseTahoma, 6, Font.NORMAL);
  60.         }
  61.  
  62.         public FileInfo Generate()
  63.         {
  64.             DateTime dateOfDoc = _handler.DocData.DocumentDate;
  65.             string invoiceFileName = Settings.Default.PDFPath + "\\" + "Бонус_№_" + _handler.DocData.DocumentNum + "_СФ_от_" + dateOfDoc.ToString("dd.MM.yyyy") + ".pdf";
  66.  
  67.             try
  68.             {
  69.                 _invoiceDoc = new iTextSharp.text.Document(PageSize.A4.Rotate(), 15, 15, 15, 15);
  70.                 _invoiceWriter = PdfWriter.GetInstance(_invoiceDoc, new FileStream(invoiceFileName, FileMode.Create));
  71.             }
  72.             catch (IOException)
  73.             {
  74.                 MessageBox.Show(Resources.DocumentIsOpenedError, Resources.ErrorHeaderForDialogs, MessageBoxButtons.OK, MessageBoxIcon.Error);
  75.                 return new FileInfo(invoiceFileName);
  76.             }
  77.  
  78.             // Name
  79.             string header = "Счёт-фактура  № " + _handler.DocData.DocumentNum + " от " + dateOfDoc.ToString("dd.MM.yyyy");
  80.             string correctionText;
  81.             if (_handler.DocData.CorrectionNum != 0)
  82.                 correctionText = "Исправление № " + _handler.DocData.CorrectionNum + " от " + _handler.DocData.CorrectionDate.ToString("dd.MM.yyyy");
  83.             else
  84.                 correctionText = "Исправление № ------ от \"----\"--------------";
  85.  
  86.             HeaderFooter hfEvent = new HeaderFooter();
  87.             hfEvent.SetHeader(header);
  88.             _invoiceWriter.PageEvent = hfEvent;
  89.             _invoiceDoc.Open();
  90.  
  91.             AddInvoiceAnnex();
  92.  
  93.             // Title
  94.             Paragraph title = new Paragraph();
  95.             title.Font = _tahoma14Bold;
  96.             title.Alignment = Element.ALIGN_CENTER;
  97.             title.Add(header);
  98.             title.Add(Chunk.NEWLINE);
  99.             title.Add(correctionText);
  100.             _invoiceDoc.Add(title);
  101.  
  102.             // Globus Juridical Address
  103.             AddGlobusJurSection();
  104.  
  105.             // Globus hypermarkt
  106.             AddRetoureMarkt();
  107.  
  108.             // Supplier retour address
  109.             AddSuppRetoureAddress();
  110.  
  111.             // Applied to payment-account documents...
  112.             Paragraph applToDocsPar = new Paragraph("К платежно-расчетному документу №  _______ от ________________", _tahoma);
  113.             applToDocsPar.FirstLineIndent = 2;
  114.             _invoiceDoc.Add(applToDocsPar);
  115.  
  116.             // Supplier juridical address
  117.             AddSuppJurAddress();
  118.  
  119.             // Currency : RUB
  120.             Paragraph currencyPar = new Paragraph("Валюта: наименование, код: Российский рубль, 643 ", _tahoma);
  121.             currencyPar.IndentationLeft = 2;
  122.             _invoiceDoc.Add(currencyPar);
  123.  
  124.             // Debitor and Kreditor numbers
  125.             AddKreDebNumbers();
  126.  
  127.             // Some empty lines
  128.             _invoiceDoc.Add(Chunk.NEWLINE);
  129.  
  130.             // Retoure positions table
  131.             AddPositionsTable();
  132.  
  133.             if (_invoiceWriter.GetVerticalPosition(true) < 100)
  134.             {
  135.                 _invoiceDoc.NewPage();
  136.                 AddInvoiceEmptyTableHeader();
  137.                 _invoiceDoc.Add(Chunk.NEWLINE);
  138.             }
  139.  
  140.             // Footer
  141.             AddInvoiceSignatures();
  142.  
  143.             // Little note
  144.             _invoiceDoc.Add(new Phrase("ПРИМЕЧАНИЕ. Первый экземпляр - покупателю, второй экземпляр - продавцу", _tahoma));
  145.  
  146.             // Save document
  147.             _invoiceDoc.Close();
  148.  
  149.             return new FileInfo(invoiceFileName);
  150.  
  151.         }
  152.  
  153.         private void AddInvoiceAnnex()
  154.         {
  155.             PdfPTable annexTable = new PdfPTable(3);
  156.             float[] widthsAnnexTable = new[] { 1.0f, 2.0f, 1.0f };
  157.             annexTable.SetWidths(widthsAnnexTable);
  158.             annexTable.HorizontalAlignment = 0;
  159.             annexTable.WidthPercentage = 100;
  160.             annexTable.DefaultCell.Border = 0;
  161.  
  162.             Image barcode = Image.GetInstance(_handler.Barcode.FullName);
  163.  
  164.             Paragraph annex = new Paragraph();
  165.             annex.Leading = 10;
  166.             annex.Add(new Phrase("Приложение №1", _tahoma));
  167.             annex.Add(Chunk.NEWLINE);
  168.             annex.Add(new Phrase("к постановлению Правительства Российской Федерации ", _tahoma));
  169.             annex.Add(Chunk.NEWLINE);
  170.             annex.Add(new Phrase("от 26.12.2011 №1137", _tahoma));
  171.             annex.IndentationLeft = 600;
  172.  
  173.             annexTable.AddCell(barcode);
  174.             annexTable.AddCell("");
  175.             annexTable.AddCell(annex);
  176.  
  177.             _invoiceDoc.Add(annexTable);
  178.         }
  179.  
  180.         private void AddGlobusJurSection()
  181.         {
  182.             PdfPTable globJurAddTable = new PdfPTable(2);
  183.             globJurAddTable.SpacingBefore = 5;
  184.             float[] widthsGlobusJur = new[] { 0.5f, 2.5f };
  185.             globJurAddTable.SetWidths(widthsGlobusJur);
  186.             globJurAddTable.HorizontalAlignment = 0;
  187.             PdfPCell globusNameTitleCell = VariousCells.GetCell("Продавец: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  188.             PdfPCell globusNameCell = VariousCells.GetCell("ООО", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  189.             PdfPCell globusAddressTitleCell = VariousCells.GetCell("Адрес: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  190.             PdfPCell globusAddressCell = VariousCells.GetCell(_handler.GlobusJurAddress, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  191.             PdfPCell globusInnKppTitleCell = VariousCells.GetCell("ИНН/КПП продавца: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  192.             PdfPCell globusInnKppCell = VariousCells.GetCell(_handler.Inn + " / " + _handler.Kpp, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  193.  
  194.             globusNameTitleCell.Border = 0;
  195.             globusNameCell.Border = 0;
  196.             globusAddressTitleCell.Border = 0;
  197.             globusAddressCell.Border = 0;
  198.             globusInnKppTitleCell.Border = 0;
  199.             globusInnKppCell.Border = 0;
  200.  
  201.             globJurAddTable.AddCell(globusNameTitleCell);
  202.             globJurAddTable.AddCell(globusNameCell);
  203.             globJurAddTable.AddCell(globusAddressTitleCell);
  204.             globJurAddTable.AddCell(globusAddressCell);
  205.             globJurAddTable.AddCell(globusInnKppTitleCell);
  206.             globJurAddTable.AddCell(globusInnKppCell);
  207.  
  208.             _invoiceDoc.Add(globJurAddTable);
  209.         }
  210.  
  211.         private void AddRetoureMarkt()
  212.         {
  213.             PdfPTable globRetTable = new PdfPTable(2);
  214.             float[] widthsGlobusRet = new[] { 0.8f, 2.2f };
  215.             globRetTable.SetWidths(widthsGlobusRet);
  216.             globRetTable.HorizontalAlignment = 0;
  217.  
  218.             PdfPCell globusRetNameTitleCell = VariousCells.GetCell("Грузоотправитель и его адрес:", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  219.             PdfPCell globusRetNameCell = VariousCells.GetCell(new string('-', 20), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  220.  
  221.             globusRetNameTitleCell.Border = 0;
  222.             globusRetNameCell.Border = 0;
  223.  
  224.             globRetTable.AddCell(globusRetNameTitleCell);
  225.             globRetTable.AddCell(globusRetNameCell);
  226.  
  227.             _invoiceDoc.Add(globRetTable);
  228.         }
  229.  
  230.         private void AddSuppRetoureAddress()
  231.         {
  232.             PdfPTable suppRetTable = new PdfPTable(2);
  233.             float[] widthsSuppRet = new[] { 0.8f, 2.2f };
  234.             suppRetTable.SetWidths(widthsSuppRet);
  235.             suppRetTable.HorizontalAlignment = 0;
  236.  
  237.             PdfPCell suppRetNameTitleCell = VariousCells.GetCell("Грузополучатель и его адрес:", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  238.             PdfPCell suppRetNameCell = VariousCells.GetCell(new string('-', 20), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  239.  
  240.             suppRetNameTitleCell.Border = 0;
  241.             suppRetNameCell.Border = 0;
  242.  
  243.             // Nested table
  244.             suppRetTable.AddCell(suppRetNameTitleCell);
  245.             suppRetTable.AddCell(suppRetNameCell);
  246.  
  247.             _invoiceDoc.Add(suppRetTable);
  248.         }
  249.  
  250.         private void AddSuppJurAddress()
  251.         {
  252.             PdfPTable suppJurAddTable = new PdfPTable(2);
  253.             suppJurAddTable.SpacingBefore = 10;
  254.             float[] widthsSuppJur = new[] { 0.5f, 2.5f };
  255.             suppJurAddTable.SetWidths(widthsSuppJur);
  256.             suppJurAddTable.HorizontalAlignment = 0;
  257.             PdfPCell suppNameTitleCell = VariousCells.GetCell("Покупатель: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  258.             PdfPCell suppNameCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.SupplierName).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  259.             PdfPCell suppAddressTitleCell = VariousCells.GetCell("Адрес: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  260.             PdfPCell suppAddressCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.SupplierAddress).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  261.             PdfPCell suppInnKppTitleCell = VariousCells.GetCell("ИНН/КПП покупателя: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  262.             PdfPCell suppInnKppCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.INN + " / " + bill.KPP).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  263.  
  264.             suppNameTitleCell.Border = 0;
  265.             suppNameCell.Border = 0;
  266.             suppAddressTitleCell.Border = 0;
  267.             suppAddressCell.Border = 0;
  268.             suppInnKppTitleCell.Border = 0;
  269.             suppInnKppCell.Border = 0;
  270.  
  271.             suppJurAddTable.AddCell(suppNameTitleCell);
  272.             suppJurAddTable.AddCell(suppNameCell);
  273.             suppJurAddTable.AddCell(suppAddressTitleCell);
  274.             suppJurAddTable.AddCell(suppAddressCell);
  275.             suppJurAddTable.AddCell(suppInnKppTitleCell);
  276.             suppJurAddTable.AddCell(suppInnKppCell);
  277.  
  278.             _invoiceDoc.Add(suppJurAddTable);
  279.         }
  280.  
  281.         private void AddKreDebNumbers()
  282.         {
  283.             Paragraph kredDebInfo = new Paragraph();
  284.             kredDebInfo.IndentationLeft = 2;
  285.             kredDebInfo.Leading = 10;
  286.             kredDebInfo.Add(new Phrase("Номер кредитора: " + _handler.DocData.SupplierNum, _tahoma));
  287.             kredDebInfo.Add(Chunk.NEWLINE);
  288.             kredDebInfo.Add(new Phrase("Номер кредитора: " + _handler.DocData.Bills.Select(bill => bill.DebitorNum).FirstOrDefault(), _tahoma));
  289.             _invoiceDoc.Add(kredDebInfo);
  290.         }
  291.  
  292.         private void AddPositionsTable()
  293.         {
  294.             PdfPTable positionsTable = new PdfPTable(13);
  295.             positionsTable.HeaderRows = 3;
  296.             positionsTable.WidthPercentage = 100;
  297.             float[] positTableWidth = new[] { 2.8f, 0.3f, 0.6f, 0.7f, 0.7f, 0.9f, 0.5f, 0.6f, 0.8f, 1.1f, 0.3f, 1.1f, 1.4f };
  298.             positionsTable.SetWidths(positTableWidth);
  299.  
  300.             positionsTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
  301.             positionsTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
  302.  
  303.             // Positions table header
  304.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Наименование товара (описание выполненых работ, оказанных услуг), имущественного права", 1, 2, _tahomaBold));
  305.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Единица измерения", 2, 1, _tahomaBold));
  306.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Количество (объем)", 1, 2, _tahomaBold));
  307.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Цена (тариф) за единицу измерения", 1, 2, _tahomaBold));
  308.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг) имуществен-ных прав без налога - всего", 1, 2, _tahomaBold));
  309.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("В том числе сумма акциза", 1, 2, _tahomaBold));
  310.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Налого-вая ставка", 1, 2, _tahomaBold));
  311.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Сумма налога, предъявляе-мая покупателю", 1, 2, _tahomaBold));
  312.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг), имущественных прав с налогом - всего", 1, 2, _tahomaBold));
  313.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Страна происхождения товара", 2, 1, _tahomaBold));
  314.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("Номер таможенной декларации", 1, 2, _tahomaBold));
  315.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("код", 1, 1, _tahomaBold));
  316.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("условное обозначение (национальное)", 1, 1, _tahomaBold));
  317.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("цифровой код", 1, 1, _tahomaBold));
  318.             positionsTable.AddCell(VariousCells.GetTableHeaderCell("краткое наименование", 1, 1, _tahomaBold));
  319.  
  320.             // Numbers
  321.             positionsTable.AddCell(VariousCells.GetCell("1", _tahomaBold));
  322.             positionsTable.AddCell(VariousCells.GetCell("2", _tahomaBold));
  323.             positionsTable.AddCell(VariousCells.GetCell("2а", _tahomaBold));
  324.             positionsTable.AddCell(VariousCells.GetCell("3", _tahomaBold));
  325.             positionsTable.AddCell(VariousCells.GetCell("4", _tahomaBold));
  326.             positionsTable.AddCell(VariousCells.GetCell("5", _tahomaBold));
  327.             positionsTable.AddCell(VariousCells.GetCell("6", _tahomaBold));
  328.             positionsTable.AddCell(VariousCells.GetCell("7", _tahomaBold));
  329.             positionsTable.AddCell(VariousCells.GetCell("8", _tahomaBold));
  330.             positionsTable.AddCell(VariousCells.GetCell("9", _tahomaBold));
  331.             positionsTable.AddCell(VariousCells.GetCell("10", _tahomaBold));
  332.             positionsTable.AddCell(VariousCells.GetCell("10а", _tahomaBold));
  333.             positionsTable.AddCell(VariousCells.GetCell("11", _tahomaBold));
  334.  
  335.             positionsTable.DefaultCell.Border = 0;
  336.  
  337.             foreach (Bonus bill in _handler.BonusList)
  338.             {
  339.                 // Article info
  340.                 PdfPCell infoCell = VariousCells.GetCell(bill.Description, _tahoma);
  341.                 positionsTable.AddCell(infoCell);
  342.  
  343.                 // code in OKEI (Russian National Classification of Units of Measurement)
  344.                 PdfPCell unitCodeCell = VariousCells.GetCell("---", _tahoma);
  345.                 positionsTable.AddCell(unitCodeCell);
  346.  
  347.                 // Unit
  348.                 PdfPCell unitCell = VariousCells.GetCell("---", _tahoma);
  349.                 positionsTable.AddCell(unitCell);
  350.  
  351.                 // Quantity
  352.                 PdfPCell quantCell = VariousCells.GetCell(bill.Quantity, "{0:#,##0.00}", _tahoma);
  353.                 positionsTable.AddCell(quantCell);
  354.  
  355.                 // Price
  356.                 PdfPCell priceCell = VariousCells.GetCell(bill.Price, "{0:#,##0.00}", _tahoma);
  357.                 positionsTable.AddCell(priceCell);
  358.  
  359.                 // Price * Quantity
  360.                 PdfPCell priceQuantCell = VariousCells.GetCell(bill.Sum, "{0:#,##0.00}", _tahoma);
  361.                 positionsTable.AddCell(priceQuantCell);
  362.  
  363.                 // Excise
  364.                 PdfPCell dashesCell = VariousCells.GetCell("Без акциза", _tahoma);
  365.                 positionsTable.AddCell(dashesCell);
  366.  
  367.                 // TaxPercent
  368.                 PdfPCell taxCell = VariousCells.GetCell(bill.TaxPercent.ToString(CultureInfo.InvariantCulture) + "%", _tahoma);
  369.                 positionsTable.AddCell(taxCell);
  370.  
  371.                 // Price * tax / 100
  372.                 PdfPCell artTaxCell = VariousCells.GetCell(bill.Tax, "{0:#,##0.00}", _tahoma);
  373.                 positionsTable.AddCell(artTaxCell);
  374.  
  375.                 // Overall cost
  376.                 PdfPCell overallCell = VariousCells.GetCell(bill.PositionSum, "{0:#,##0.00}", _tahoma);
  377.                 positionsTable.AddCell(overallCell);
  378.  
  379.                 // Code of land of production
  380.                 PdfPCell landCodeCell = VariousCells.GetCell("---", _tahoma);
  381.                 positionsTable.AddCell(landCodeCell);
  382.  
  383.                 // Land of production
  384.                 PdfPCell landCell = VariousCells.GetCell("---", _tahoma);
  385.                 positionsTable.AddCell(landCell);
  386.  
  387.                 // Declaration
  388.                 PdfPCell declCell = VariousCells.GetCell("---", _tahoma);
  389.                 positionsTable.AddCell(declCell);
  390.             }
  391.  
  392.             PdfPCell noBorderCell = new PdfPCell();
  393.             noBorderCell.Border = Rectangle.NO_BORDER;
  394.  
  395.             PdfPCell emptyCells = new PdfPCell();
  396.  
  397.             PdfPCell overAllText = VariousCells.GetCell("Всего к оплате", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, 7, 1, _tahomaBold);
  398.             overAllText.Border = Rectangle.BOTTOM_BORDER | Rectangle.LEFT_BORDER;
  399.             positionsTable.AddCell(overAllText);
  400.  
  401.             positionsTable.AddCell(emptyCells);
  402.  
  403.             PdfPCell overallTaxCell = VariousCells.GetCell(_handler.Tax, "{0:#,##0.00}", _tahoma);
  404.             positionsTable.AddCell(overallTaxCell);
  405.  
  406.             PdfPCell overallPriceCell = VariousCells.GetCell(_handler.OverallSum, "{0:#,##0.00}", _tahomaBold);
  407.             positionsTable.AddCell(overallPriceCell);
  408.  
  409.             positionsTable.CompleteRow();
  410.  
  411.             _overallSumRow = positionsTable.GetRow(positionsTable.Size - 1);
  412.  
  413.             _invoiceDoc.Add(positionsTable);
  414.         }
  415.  
  416.         private void AddInvoiceEmptyTableHeader()
  417.         {
  418.             PdfPTable emptyTable = new PdfPTable(13);
  419.             emptyTable.HeaderRows = 3;
  420.             emptyTable.SpacingBefore = 10;
  421.             emptyTable.WidthPercentage = 100;
  422.             float[] positTableWidth = new[] { 2.8f, 0.3f, 0.6f, 0.7f, 0.7f, 0.9f, 0.5f, 0.6f, 0.7f, 1.0f, 0.3f, 1.1f, 1.6f };
  423.             emptyTable.SetWidths(positTableWidth);
  424.  
  425.             emptyTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
  426.             emptyTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
  427.  
  428.             // Positions table header
  429.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Наименование товара (описание выполненых работ, оказанных услуг), имущественного права", 1, 2, _tahomaBold));
  430.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Единица измерения", 2, 1, _tahomaBold));
  431.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Количество (объем)", 1, 2, _tahomaBold));
  432.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Цена (тариф) за единицу измерения", 1, 2, _tahomaBold));
  433.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг) имуществен-ных прав без налога - всего", 1, 2, _tahomaBold));
  434.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("В том числе сумма акциза", 1, 2, _tahomaBold));
  435.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Налого-вая ставка", 1, 2, _tahomaBold));
  436.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Сумма налога, предъявляе-мая покупателю", 1, 2, _tahomaBold));
  437.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг), имущественных прав с налогом - всего", 1, 2, _tahomaBold));
  438.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Страна происхождения товара", 2, 1, _tahomaBold));
  439.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("Номер таможенной декларации", 1, 2, _tahomaBold));
  440.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("код", 1, 1, _tahomaBold));
  441.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("условное обозначение (национальное)", 1, 1, _tahomaBold));
  442.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("цифровой код", 1, 1, _tahomaBold));
  443.             emptyTable.AddCell(VariousCells.GetTableHeaderCell("краткое наименование", 1, 1, _tahomaBold));
  444.  
  445.             // Numbers
  446.             emptyTable.AddCell(VariousCells.GetCell("1", _tahomaBold));
  447.             emptyTable.AddCell(VariousCells.GetCell("2", _tahomaBold));
  448.             emptyTable.AddCell(VariousCells.GetCell("2а", _tahomaBold));
  449.             emptyTable.AddCell(VariousCells.GetCell("3", _tahomaBold));
  450.             emptyTable.AddCell(VariousCells.GetCell("4", _tahomaBold));
  451.             emptyTable.AddCell(VariousCells.GetCell("5", _tahomaBold));
  452.             emptyTable.AddCell(VariousCells.GetCell("6", _tahomaBold));
  453.             emptyTable.AddCell(VariousCells.GetCell("7", _tahomaBold));
  454.             emptyTable.AddCell(VariousCells.GetCell("8", _tahomaBold));
  455.             emptyTable.AddCell(VariousCells.GetCell("9", _tahomaBold));
  456.             emptyTable.AddCell(VariousCells.GetCell("10", _tahomaBold));
  457.             emptyTable.AddCell(VariousCells.GetCell("10а", _tahomaBold));
  458.             emptyTable.AddCell(VariousCells.GetCell("11", _tahomaBold));
  459.  
  460.             emptyTable.Rows.Add(_overallSumRow);
  461.  
  462.             _invoiceDoc.Add(emptyTable);
  463.         }
  464.  
  465.         private void AddInvoiceSignatures()
  466.         {
  467.             PdfPTable footerTable = new PdfPTable(2);
  468.             footerTable.SpacingBefore = 10;
  469.             footerTable.WidthPercentage = 100;
  470.             footerTable.DefaultCell.Border = 0;
  471.             float[] footerTableWidth = new[] { 1.1f, 0.9f };
  472.             footerTable.SetWidths(footerTableWidth);
  473.  
  474.             // Prepare duplicated cells
  475.             PdfPCell signCell = VariousCells.GetCell("(подпись)", _tahoma);
  476.             signCell.Border = Rectangle.NO_BORDER;
  477.  
  478.             PdfPCell fioCell = VariousCells.GetCell("(Ф.И.О.)", _tahoma);
  479.             fioCell.Border = Rectangle.NO_BORDER;
  480.  
  481.             // General director
  482.             PdfPTable genDirNestedTable = new PdfPTable(3);
  483.             genDirNestedTable.DefaultCell.Border = Rectangle.NO_BORDER;
  484.             float[] genDirNestedTableWidth = new[] { 1.2f, 0.6f, 1.2f };
  485.             genDirNestedTable.SetWidths(genDirNestedTableWidth);
  486.  
  487.             PdfPCell genDirTitleCell = VariousCells.GetCell("Руководитель организации или иное уполномоченное лицо", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  488.             genDirTitleCell.Border = Rectangle.NO_BORDER;
  489.             genDirNestedTable.AddCell(genDirTitleCell);
  490.  
  491.             // Fields to fill
  492.             genDirNestedTable.AddCell("____________");
  493.  
  494.             PdfPCell generalDirectorCell = VariousCells.GetCell(_handler.GeneralDirector, _tahoma);
  495.             generalDirectorCell.Border = Rectangle.NO_BORDER;
  496.             genDirNestedTable.AddCell(generalDirectorCell);
  497.  
  498.             // Empty cell
  499.             genDirNestedTable.AddCell("");
  500.  
  501.             // under lines...
  502.             genDirNestedTable.AddCell(signCell);
  503.             genDirNestedTable.AddCell(fioCell);
  504.  
  505.             footerTable.AddCell(genDirNestedTable);
  506.  
  507.             // Accountant
  508.             PdfPTable accountantNestedTable = new PdfPTable(3);
  509.             accountantNestedTable.DefaultCell.Border = Rectangle.NO_BORDER;
  510.             float[] accountNestedTableWidth = new[] { 1.1f, 0.8f, 1.1f };
  511.             accountantNestedTable.SetWidths(accountNestedTableWidth);
  512.  
  513.             PdfPCell accountantTitleCell = VariousCells.GetCell("Главный бухгалтер или иное уполномоченное лицо", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  514.             accountantTitleCell.Border = Rectangle.NO_BORDER;
  515.             accountantNestedTable.AddCell(accountantTitleCell);
  516.  
  517.             // Fields to fill
  518.             accountantNestedTable.AddCell("____________");
  519.  
  520.             PdfPCell accountantCell = VariousCells.GetCell(_handler.Accountant, _tahoma);
  521.             accountantCell.Border = Rectangle.NO_BORDER;
  522.             accountantNestedTable.AddCell(accountantCell);
  523.  
  524.             // Empty cell
  525.             accountantNestedTable.AddCell("");
  526.  
  527.             // under lines...
  528.             accountantNestedTable.AddCell(signCell);
  529.             accountantNestedTable.AddCell(fioCell);
  530.  
  531.             footerTable.AddCell(accountantNestedTable);
  532.  
  533.             // Business owner
  534.             PdfPTable busOwnerNestedTable = new PdfPTable(3);
  535.             busOwnerNestedTable.DefaultCell.Border = Rectangle.NO_BORDER;
  536.             float[] busOwnerNestedTableWidth = new[] { 1.2f, 0.6f, 1.2f };
  537.             busOwnerNestedTable.SetWidths(busOwnerNestedTableWidth);
  538.  
  539.             PdfPCell busOwnerTitleCell = VariousCells.GetCell("Индивидуальный предприниматель", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
  540.             busOwnerTitleCell.Border = Rectangle.NO_BORDER;
  541.             busOwnerNestedTable.AddCell(busOwnerTitleCell);
  542.  
  543.             // Fields to fill
  544.             busOwnerNestedTable.AddCell("___________");
  545.             busOwnerNestedTable.AddCell("________________________");
  546.  
  547.             // Empty cell
  548.             busOwnerNestedTable.AddCell("");
  549.  
  550.             // under lines...
  551.             busOwnerNestedTable.AddCell(signCell);
  552.             busOwnerNestedTable.AddCell(fioCell);
  553.  
  554.             footerTable.AddCell(busOwnerNestedTable);
  555.  
  556.             // Certificate details
  557.             PdfPCell certDetails = VariousCells.GetCell("(реквизиты свидетельства о государственной регистрации индивидуального предпринимателя)", _tahoma);
  558.             certDetails.Border = Rectangle.NO_BORDER;
  559.  
  560.             footerTable.AddCell(certDetails);
  561.  
  562.             // Add to document
  563.             _invoiceDoc.Add(footerTable);
  564.         }
  565.     }
  566. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement