View difference between Paste ID: L2yCRAQN and 20jFGyZD
SHOW: | | - or go back to the newest paste.
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 PASSS
26+
namespace PASSSS
27
{
28-
    class ActGenerator : IDocumentGenerator
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 _tahoma16Bold;
36+
        private static Font _tahoma14Bold;
37
        private static Font _tahomaSmall;
38
39
        // Files
40-
        private iTextSharp.text.Document _actDoc;
40+
        private iTextSharp.text.Document _invoiceDoc;
41-
        private PdfWriter _actWriter;
41+
        private PdfWriter _invoiceWriter;
42
43
        // Overall sum row
44
        private PdfPRow _overallSumRow;
45
46-
        public ActGenerator(DocumentHandler handler)
46+
        public InvoiceGenerator(DocumentHandler handler)
47
        {
48
            _handler = handler;
49
50
            PrepareFonts();
51
        }
52
53-
        // Prepare fonts
53+
54
        {
55
            _baseTahoma = BaseFont.CreateFont("c:/windows/fonts/tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
56
            _tahomaBold = new Font(_baseTahoma, 8, Font.BOLD);
57-
            _tahomaBold = new Font(_baseTahoma, 10, Font.BOLD);
57+
            _tahoma = new Font(_baseTahoma, 8, Font.NORMAL);
58-
            _tahoma = new Font(_baseTahoma, 10, Font.NORMAL);
58+
            _tahoma14Bold = new Font(_baseTahoma, 14, Font.BOLD);
59-
            _tahoma16Bold = new Font(_baseTahoma, 18, Font.BOLD);
59+
            _tahomaSmall = new Font(_baseTahoma, 6, Font.NORMAL);
60-
            _tahomaSmall = new Font(_baseTahoma, 8, 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-
            string actFileName = 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-
                _actDoc = new iTextSharp.text.Document(PageSize.A4, 45, 45, 45, 45);
70+
                _invoiceWriter = PdfWriter.GetInstance(_invoiceDoc, new FileStream(invoiceFileName, FileMode.Create));
71-
                _actWriter = PdfWriter.GetInstance(_actDoc, new FileStream(actFileName, FileMode.Create));
71+
72
            catch (IOException)
73
            {
74
                MessageBox.Show(Resources.DocumentIsOpenedError, Resources.ErrorHeaderForDialogs, MessageBoxButtons.OK, MessageBoxIcon.Error);
75
                return new FileInfo(invoiceFileName);
76-
                return new FileInfo(actFileName);
76+
77
78
            // Name
79-
            string header = "Акт  № " + _handler.DocData.DocumentNum + " от " + dateOfDoc.ToString("dd.MM.yyyy");
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-
            _actWriter.PageEvent = hfEvent;
83+
84-
            _actDoc.Open();
84+
                correctionText = "Исправление № ------ от \"----\"--------------";
85
86
            HeaderFooter hfEvent = new HeaderFooter();
87
            hfEvent.SetHeader(header);
88
            _invoiceWriter.PageEvent = hfEvent;
89
            _invoiceDoc.Open();
90
91-
            title.SpacingBefore = 10;
91+
            AddInvoiceAnnex();
92-
            title.SpacingAfter = 10;
92+
93-
            title.Font = _tahoma16Bold;
93+
94
            Paragraph title = new Paragraph();
95
            title.Font = _tahoma14Bold;
96-
            _actDoc.Add(title);
96+
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-
            if (_actWriter.GetVerticalPosition(true) < 100)
104+
105
            // Globus hypermarkt
106-
                _actDoc.NewPage();
106+
            AddRetoureMarkt();
107
108-
                _actDoc.Add(Chunk.NEWLINE);
108+
            // Supplier retour address
109
            AddSuppRetoureAddress();
110
111-
            // Sum by words and agreement
111+
            // Applied to payment-account documents...
112-
            AddSumAndAgreement();
112+
            Paragraph applToDocsPar = new Paragraph("К платежно-расчетному документу №  _______ от ________________", _tahoma);
113
            applToDocsPar.FirstLineIndent = 2;
114
            _invoiceDoc.Add(applToDocsPar);
115
116
            // Supplier juridical address
117-
            AddGlobusBankDetails();
117+
            AddSuppJurAddress();
118
119
            // Currency : RUB
120-
            _actDoc.Close();
120+
            Paragraph currencyPar = new Paragraph("Валюта: наименование, код: Российский рубль, 643 ", _tahoma);
121
            currencyPar.IndentationLeft = 2;
122-
            return new FileInfo(actFileName);
122+
            _invoiceDoc.Add(currencyPar);
123
124
            // Debitor and Kreditor numbers
125
            AddKreDebNumbers();
126
127-
            Paragraph globusJurInfo = new Paragraph();
127+
            // Some empty lines
128-
            globusJurInfo.Leading = 10;
128+
            _invoiceDoc.Add(Chunk.NEWLINE);
129-
            globusJurInfo.Add(new Phrase("OOO", _tahomaBold));
129+
130-
            globusJurInfo.Add(Chunk.NEWLINE);
130+
131-
            globusJurInfo.Add(new Phrase(_handler.GlobusJurAddress, _tahomaBold));
131+
132-
            _actDoc.Add(globusJurInfo);
132+
133
            if (_invoiceWriter.GetVerticalPosition(true) < 100)
134
            {
135
                _invoiceDoc.NewPage();
136
                AddInvoiceEmptyTableHeader();
137
                _invoiceDoc.Add(Chunk.NEWLINE);
138
            }
139-
            kredDebInfo.Add(new Phrase("Заказчик: " + _handler.DocData.Bills.Select(bill => bill.SupplierName).FirstOrDefault(), _tahoma));
139+
140
            // Footer
141
            AddInvoiceSignatures();
142
143-
            kredDebInfo.Add(new Phrase("Номер дебитора: " + _handler.DocData.Bills.Select(bill => bill.DebitorNum).FirstOrDefault(), _tahoma));
143+
            // Little note
144-
            _actDoc.Add(kredDebInfo);
144+
            _invoiceDoc.Add(new Phrase("ПРИМЕЧАНИЕ. Первый экземпляр - покупателю, второй экземпляр - продавцу", _tahoma));
145
146
            // Save document
147
            _invoiceDoc.Close();
148
149-
            PdfPTable table = new PdfPTable(6);
149+
            return new FileInfo(invoiceFileName);
150-
            table.WidthPercentage = 100;
150+
151-
            table.SpacingBefore = 10;
151+
152-
            table.SpacingAfter = 10;
152+
153-
            float[] colWidths = new[] { 0.3f, 2.1f, 0.5f, 0.5f, 1.0f, 1.0f };
153+
        private void AddInvoiceAnnex()
154-
            table.SetWidths(colWidths);
154+
155
            PdfPTable annexTable = new PdfPTable(3);
156-
            table.AddCell(VariousCells.GetCell("№", _tahomaBold));
156+
            float[] widthsAnnexTable = new[] { 1.0f, 2.0f, 1.0f };
157-
            table.AddCell(VariousCells.GetCell("Наименование работы (услуги)", _tahomaBold));
157+
            annexTable.SetWidths(widthsAnnexTable);
158-
            table.AddCell(VariousCells.GetCell("Ед. изм.", _tahomaBold));
158+
            annexTable.HorizontalAlignment = 0;
159-
            table.AddCell(VariousCells.GetCell("Количество", _tahomaBold));
159+
            annexTable.WidthPercentage = 100;
160-
            table.AddCell(VariousCells.GetCell("Цена", _tahomaBold));
160+
            annexTable.DefaultCell.Border = 0;
161-
            table.AddCell(VariousCells.GetCell("Сумма", _tahomaBold));
161+
162
            Image barcode = Image.GetInstance(_handler.Barcode.FullName);
163-
            int rowCounter = 1;
163+
164
            Paragraph annex = new Paragraph();
165
            annex.Leading = 10;
166
            annex.Add(new Phrase("Приложение №1", _tahoma));
167-
                table.AddCell(VariousCells.GetCell(rowCounter++.ToString(CultureInfo.InvariantCulture), _tahoma));
167+
            annex.Add(Chunk.NEWLINE);
168-
                table.AddCell(VariousCells.GetCell(bill.Description, _tahoma));
168+
            annex.Add(new Phrase("к постановлению Правительства Российской Федерации ", _tahoma));
169-
                table.AddCell(VariousCells.GetCell("усл.", _tahoma));
169+
            annex.Add(Chunk.NEWLINE);
170-
                table.AddCell(VariousCells.GetCell(bill.Quantity, "{0:#,##0.00}", _tahoma));
170+
            annex.Add(new Phrase("от 26.12.2011 №1137", _tahoma));
171-
                table.AddCell(VariousCells.GetCell(bill.Price, "{0:#,##0.00}", _tahoma));
171+
            annex.IndentationLeft = 600;
172-
                table.AddCell(VariousCells.GetCell(bill.Sum, "{0:#,##0.00}", _tahomaBold));
172+
173
            annexTable.AddCell(barcode);
174
            annexTable.AddCell("");
175-
            PdfPCell sumLabelCell = VariousCells.GetCell("Итого:", Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE, 5, 1, _tahomaBold);
175+
            annexTable.AddCell(annex);
176-
            sumLabelCell.Border = Rectangle.NO_BORDER;
176+
177-
            table.AddCell(sumLabelCell);
177+
            _invoiceDoc.Add(annexTable);
178
        }
179-
            PdfPCell sumCell = VariousCells.GetCell(_handler.Sum, "{0:#,##0.00}", _tahomaBold);
179+
180-
            table.AddCell(sumCell);
180+
181
        {
182-
            PdfPCell taxLabelCell = VariousCells.GetCell("Итого НДС:", Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE, 5, 1, _tahomaBold);
182+
            PdfPTable globJurAddTable = new PdfPTable(2);
183-
            taxLabelCell.Border = Rectangle.NO_BORDER;
183+
            globJurAddTable.SpacingBefore = 5;
184-
            table.AddCell(taxLabelCell);
184+
            float[] widthsGlobusJur = new[] { 0.5f, 2.5f };
185
            globJurAddTable.SetWidths(widthsGlobusJur);
186-
            PdfPCell taxCell = VariousCells.GetCell(_handler.Tax, "{0:#,##0.00}", _tahomaBold);
186+
            globJurAddTable.HorizontalAlignment = 0;
187-
            table.AddCell(taxCell);
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 overallSumLabelCell = VariousCells.GetCell("Всего (с учетом НДС):", Element.ALIGN_RIGHT, Element.ALIGN_MIDDLE, 5, 1, _tahomaBold);
189+
            PdfPCell globusAddressTitleCell = VariousCells.GetCell("Адрес: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
190-
            overallSumLabelCell.Border = Rectangle.NO_BORDER;
190+
            PdfPCell globusAddressCell = VariousCells.GetCell(_handler.GlobusJurAddress, Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
191-
            table.AddCell(overallSumLabelCell);
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-
            PdfPCell overallSumCell = VariousCells.GetCell(_handler.OverallSum, "{0:#,##0.00}", _tahomaBold);
193+
194-
            table.AddCell(overallSumCell);
194+
            globusNameTitleCell.Border = 0;
195
            globusNameCell.Border = 0;
196-
            _overallSumRow = table.GetRow(table.Size - 1);
196+
            globusAddressTitleCell.Border = 0;
197
            globusAddressCell.Border = 0;
198-
            _actDoc.Add(table);
198+
            globusInnKppTitleCell.Border = 0;
199
            globusInnKppCell.Border = 0;
200
201
            globJurAddTable.AddCell(globusNameTitleCell);
202
            globJurAddTable.AddCell(globusNameCell);
203-
            PdfPTable table = new PdfPTable(6);
203+
            globJurAddTable.AddCell(globusAddressTitleCell);
204-
            table.WidthPercentage = 100;
204+
            globJurAddTable.AddCell(globusAddressCell);
205-
            table.SpacingBefore = 10;
205+
            globJurAddTable.AddCell(globusInnKppTitleCell);
206-
            table.SpacingAfter = 10;
206+
            globJurAddTable.AddCell(globusInnKppCell);
207-
            float[] colWidths = new[] { 0.3f, 2.1f, 0.5f, 0.5f, 1.0f, 1.0f };
207+
208-
            table.SetWidths(colWidths);
208+
            _invoiceDoc.Add(globJurAddTable);
209
        }
210-
            table.AddCell(VariousCells.GetCell("№", _tahomaBold));
210+
211-
            table.AddCell(VariousCells.GetCell("Наименование работы (услуги)", _tahomaBold));
211+
        private void AddRetoureMarkt()
212-
            table.AddCell(VariousCells.GetCell("Ед. изм.", _tahomaBold));
212+
213-
            table.AddCell(VariousCells.GetCell("Количество", _tahomaBold));
213+
            PdfPTable globRetTable = new PdfPTable(2);
214-
            table.AddCell(VariousCells.GetCell("Цена", _tahomaBold));
214+
            float[] widthsGlobusRet = new[] { 0.8f, 2.2f };
215-
            table.AddCell(VariousCells.GetCell("Сумма", _tahomaBold));
215+
            globRetTable.SetWidths(widthsGlobusRet);
216
            globRetTable.HorizontalAlignment = 0;
217-
            table.Rows.Add(_overallSumRow);
217+
218
            PdfPCell globusRetNameTitleCell = VariousCells.GetCell("Грузоотправитель и его адрес:", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
219-
            _actDoc.Add(table);
219+
            PdfPCell globusRetNameCell = VariousCells.GetCell(new string('-', 20), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
220
221
            globusRetNameTitleCell.Border = 0;
222-
        private void AddSumAndAgreement()
222+
            globusRetNameCell.Border = 0;
223
224-
            Paragraph sumAndAgreement = new Paragraph();
224+
            globRetTable.AddCell(globusRetNameTitleCell);
225-
            sumAndAgreement.Leading = 10;
225+
            globRetTable.AddCell(globusRetNameCell);
226-
            sumAndAgreement.Add(new Phrase("Всего оказано услуг на сумму: " + _handler.MakeStringSum(_handler.OverallSum) + " ,", _tahomaBold));
226+
227-
            sumAndAgreement.Add(Chunk.NEWLINE);
227+
            _invoiceDoc.Add(globRetTable);
228-
            sumAndAgreement.Add(new Phrase("в т.ч.: НДС - " + _handler.MakeStringSum(_handler.Tax), _tahomaBold));
228+
229-
            sumAndAgreement.Add(Chunk.NEWLINE);
229+
230-
            sumAndAgreement.Add(new Phrase("Вышеперечисленные услуги выполнены полностью и в срок.", _tahomaBold));
230+
        private void AddSuppRetoureAddress()
231-
            sumAndAgreement.Add(Chunk.NEWLINE);
231+
232-
            sumAndAgreement.Add(new Phrase("Заказчик претензий по объему, качеству и срокам оказания услуг не имеет.", _tahomaBold));
232+
            PdfPTable suppRetTable = new PdfPTable(2);
233-
            _actDoc.Add(sumAndAgreement);
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-
            PdfPTable table = new PdfPTable(3);
238+
            PdfPCell suppRetNameCell = VariousCells.GetCell(new string('-', 20), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
239-
            table.SpacingBefore = 20;
239+
240-
            table.WidthPercentage = 100;
240+
            suppRetNameTitleCell.Border = 0;
241-
            float[] colWidths = new[] { 1.0f, 0.2f, 1.0f };
241+
            suppRetNameCell.Border = 0;
242-
            table.SetWidths(colWidths);
242+
243
            // Nested table
244-
            PdfPCell emptyCell = VariousCells.GetEmptyCell(_tahoma);
244+
            suppRetTable.AddCell(suppRetNameTitleCell);
245-
            emptyCell.Border = Rectangle.NO_BORDER;
245+
            suppRetTable.AddCell(suppRetNameCell);
246
247-
            PdfPCell cell = VariousCells.GetCell("Исполнитель:", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
247+
            _invoiceDoc.Add(suppRetTable);
248-
            cell.Border = Rectangle.NO_BORDER;
248+
249-
            table.AddCell(cell);
249+
250-
            table.AddCell(emptyCell);
250+
        private void AddSuppJurAddress()
251-
            cell = VariousCells.GetCell("Заказчик:", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
251+
252-
            cell.Border = Rectangle.NO_BORDER;
252+
            PdfPTable suppJurAddTable = new PdfPTable(2);
253-
            table.AddCell(cell);
253+
            suppJurAddTable.SpacingBefore = 10;
254-
            cell = VariousCells.GetCell("".PadLeft(50) + "подпись", Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, _tahomaSmall);
254+
            float[] widthsSuppJur = new[] { 0.5f, 2.5f };
255-
            cell.Border = Rectangle.NO_BORDER;
255+
            suppJurAddTable.SetWidths(widthsSuppJur);
256-
            table.AddCell(cell);
256+
            suppJurAddTable.HorizontalAlignment = 0;
257-
            table.AddCell(emptyCell);
257+
            PdfPCell suppNameTitleCell = VariousCells.GetCell("Покупатель: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
258-
            cell = VariousCells.GetCell("".PadLeft(50) + "подпись", Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, _tahomaSmall);
258+
            PdfPCell suppNameCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.SupplierName).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
259-
            cell.Border = Rectangle.NO_BORDER;
259+
            PdfPCell suppAddressTitleCell = VariousCells.GetCell("Адрес: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
260-
            table.AddCell(cell);
260+
            PdfPCell suppAddressCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.SupplierAddress).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
261-
            cell = VariousCells.GetCell("М.П.", Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, _tahoma);
261+
            PdfPCell suppInnKppTitleCell = VariousCells.GetCell("ИНН/КПП покупателя: ", Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
262-
            cell.Border = Rectangle.NO_BORDER;
262+
            PdfPCell suppInnKppCell = VariousCells.GetCell(_handler.DocData.Bills.Select(bill => bill.INN + " / " + bill.KPP).FirstOrDefault(), Element.ALIGN_LEFT, Element.ALIGN_MIDDLE, _tahoma);
263-
            table.AddCell(cell);
263+
264-
            table.AddCell(emptyCell);
264+
            suppNameTitleCell.Border = 0;
265-
            cell = VariousCells.GetCell("М.П.", Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, _tahoma);
265+
            suppNameCell.Border = 0;
266-
            cell.Border = Rectangle.NO_BORDER;
266+
            suppAddressTitleCell.Border = 0;
267-
            table.AddCell(cell);
267+
            suppAddressCell.Border = 0;
268
            suppInnKppTitleCell.Border = 0;
269-
            _actDoc.Add(table);
269+
            suppInnKppCell.Border = 0;
270
271
            suppJurAddTable.AddCell(suppNameTitleCell);
272-
        private void AddGlobusBankDetails()
272+
            suppJurAddTable.AddCell(suppNameCell);
273
            suppJurAddTable.AddCell(suppAddressTitleCell);
274-
            Paragraph bankDetails = new Paragraph();
274+
            suppJurAddTable.AddCell(suppAddressCell);
275-
            bankDetails.Leading = 10;
275+
            suppJurAddTable.AddCell(suppInnKppTitleCell);
276-
            bankDetails.Add(new Phrase("Наши реквизиты:", _tahomaSmall));
276+
            suppJurAddTable.AddCell(suppInnKppCell);
277-
            bankDetails.Add(Chunk.NEWLINE);
277+
278-
            bankDetails.Add(new Phrase("ИНН " + _handler.Inn + ", КПП " + _handler.Kpp, _tahomaSmall));
278+
            _invoiceDoc.Add(suppJurAddTable);
279-
            bankDetails.Add(Chunk.NEWLINE);
279+
280-
            bankDetails.Add(new Phrase("р/с ", _tahomaSmall));
280+
281-
            bankDetails.Add(Chunk.NEWLINE);
281+
282-
            bankDetails.Add(new Phrase("к/с  ", _tahomaSmall));
282+
283-
            _actDoc.Add(bankDetails);
283+
284
            kredDebInfo.IndentationLeft = 2;
285
            kredDebInfo.Leading = 10;
286
            kredDebInfo.Add(new Phrase("Номер кредитора: " + _handler.DocData.SupplierNum, _tahoma));
287-
    public class HeaderFooter : PdfPageEventHelper
287+
288
            kredDebInfo.Add(new Phrase("Номер кредитора: " + _handler.DocData.Bills.Select(bill => bill.DebitorNum).FirstOrDefault(), _tahoma));
289-
        string _header;
289+
            _invoiceDoc.Add(kredDebInfo);
290
        }
291-
        public void SetHeader(String header)
291+
292
        private void AddPositionsTable()
293-
            _header = header;
293+
294
            PdfPTable positionsTable = new PdfPTable(13);
295
            positionsTable.HeaderRows = 3;
296-
        public override void OnStartPage(PdfWriter writer, iTextSharp.text.Document document)
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-
            BaseFont baseCourBold = BaseFont.CreateFont("c:/windows/fonts/tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
298+
            positionsTable.SetWidths(positTableWidth);
299-
            Font courierBold = new Font(baseCourBold, 8, Font.BOLD);
299+
300
            positionsTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
301-
            PdfPTable headerTable = new PdfPTable(2);
301+
            positionsTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
302-
            headerTable.WidthPercentage = 65;
302+
303-
            headerTable.DefaultCell.Border = 0;
303+
            // Positions table header
304-
            headerTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
304+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Наименование товара (описание выполненых работ, оказанных услуг), имущественного права", 1, 2, _tahomaBold));
305-
            float[] headerTableWidths = { 1.0f, 0.4f };
305+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Единица измерения", 2, 1, _tahomaBold));
306-
            headerTable.SetWidths(headerTableWidths);
306+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Количество (объем)", 1, 2, _tahomaBold));
307
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Цена (тариф) за единицу измерения", 1, 2, _tahomaBold));
308-
            Paragraph fullPar = new Paragraph();
308+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг) имуществен-ных прав без налога - всего", 1, 2, _tahomaBold));
309-
            fullPar.Alignment = Element.ALIGN_CENTER;
309+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("В том числе сумма акциза", 1, 2, _tahomaBold));
310
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Налого-вая ставка", 1, 2, _tahomaBold));
311-
            if (document.PageNumber == 1)
311+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Сумма налога, предъявляе-мая покупателю", 1, 2, _tahomaBold));
312
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("Стоимость товаров (работ,услуг), имущественных прав с налогом - всего", 1, 2, _tahomaBold));
313-
                //
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-
                fullPar.Add(new Phrase(_header, courierBold));
317+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("цифровой код", 1, 1, _tahomaBold));
318-
                headerTable.AddCell(fullPar);
318+
            positionsTable.AddCell(VariousCells.GetTableHeaderCell("краткое наименование", 1, 1, _tahomaBold));
319-
                headerTable.AddCell(new Phrase("        стр. " + writer.PageNumber, courierBold));
319+
320
            // Numbers
321
            positionsTable.AddCell(VariousCells.GetCell("1", _tahomaBold));
322-
            document.Add(headerTable);
322+
            positionsTable.AddCell(VariousCells.GetCell("2", _tahomaBold));
323-
            document.Add(Chunk.NEWLINE);
323+
            positionsTable.AddCell(VariousCells.GetCell("2а", _tahomaBold));
324
            positionsTable.AddCell(VariousCells.GetCell("3", _tahomaBold));
325-
            base.OnStartPage(writer, document);
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
}