Index: branches/Abonament/BazaReklam/ZamowieniaForm.cs
===================================================================
--- branches/Abonament/BazaReklam/ZamowieniaForm.cs (revision 704)
+++ branches/Abonament/BazaReklam/ZamowieniaForm.cs (revision 705)
@@ -8,4 +8,5 @@
 using Baza_Reklam.Classes.Helpers;
 using Baza_Reklam.Classes.Interfaces;
+using Baza_Reklam.Classes.Model;
 using Baza_Reklam.Classes.Model.Enums;
 using Baza_Reklam.Classes.Repositories;
@@ -18,10 +19,9 @@
         private List<IProduct> productsWithOrder = new List<IProduct>();
         private List<IProduct> productsWithoutOrder = new List<IProduct>();
+        private AgentRepository agentRepository;
+        private Agent agent;
         
         private REKLAMADataSet.KLIENCIRow klient;
-
         private int idZamowienia;
-
-        private REKLAMADataSet.REKLAMADataTable reklamyBezZamowienia;
 
         private REKLAMADataSetTableAdapters.KLIENCITableAdapter klienciTableAdapter =
@@ -49,14 +49,5 @@
             new SLOWNIKDataSetTableAdapters.Kursy_WalutTableAdapter();
 
-        #region properties
-
-        public REKLAMADataSet.REKLAMADataTable ReklamyBezZamowienia
-        {
-            get { return reklamyBezZamowienia; }
-            set { reklamyBezZamowienia = value; }
-        }
-
-        #endregion properties
-
+        
         public ZamowieniaForm(REKLAMADataSet.KLIENCIRow klient)
         {
@@ -82,5 +73,4 @@
             klient = klienciTableAdapter.GetDataByCustomerId(idKlienta)[0];
             this.idZamowienia = idZamowienia;
-
         }
 
@@ -88,9 +78,9 @@
         {
             customerRepository = new CustomerRepository(ConnString.getConnString().Value);
+            agentRepository = new AgentRepository(ConnString.getConnString().Value);
 
             productsWithOrder = customerRepository.FindProductsWithOrders(customerId);
             productsWithoutOrder = customerRepository.FindProductsWithoutOrders(customerId);
 
-            rEKLAMABindingSource1.DataSource = ReklamyBezZamowienia;
             zamowieniaTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
             rEKLAMATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
@@ -131,6 +121,4 @@
             zamowieniaBindingSource.CurrentChanged += zamowieniaBindingSource_CurrentChanged;
 
-            ReklamyBezZamowienia = rEKLAMATableAdapter.GetDataByCustomerIdandIdZamowienia(klient.CustomerID);
-            rEKLAMABindingSource1.DataSource = ReklamyBezZamowienia;
             zamowieniaTableAdapter.FillByIdKlienta(rEKLAMADataSet.zamowienia, klient.CustomerID);
 
@@ -140,23 +128,15 @@
 
                 BindProductsWithOrders(idZamowienia);
-                
+
                 fAKTURYTableAdapter.FillByIdZamowienia(rEKLAMADataSet.FAKTURY, idZamowienia);
             }
             else
-            {
                 zamowieniaBindingSource.Position = 0;
-            }
-
-            if (klient != null)
-            {
-                if (klient.IskodKlientaNull())
-                {
-                    KlientLabel.Text = "BRAK KODU KLIENTA";
-                }
-                else
-                {
-                    KlientLabel.Text = "KOD KLIENTA:  " + klient.kodKlienta;
-                }
-            }
+
+            if (klient == null) return;
+            
+            KlientLabel.Text = klient.IskodKlientaNull()
+                                   ? "BRAK KODU KLIENTA"
+                                   : "KOD KLIENTA:  " + klient.kodKlienta;
         }
 
@@ -172,6 +152,4 @@
             if (azf.ShowDialog() == DialogResult.OK)
             {
-                //rEKLAMADataSet.zamowienia.Clear();
-                //this.zamowieniaTableAdapter.FillByIdKlienta(this.rEKLAMADataSet.zamowienia, klient.CustomerID);
                 rEKLAMADataSet.zamowienia.ImportRow(azf.Zamowienia[0]);
                 int idZam = azf.Zamowienia[0].idZamowienia;
@@ -217,21 +195,5 @@
             }
 
-            //TODO: move that piece to separate method
-            if (product.ProductType == ProductType.Advertisment)
-            {
-                if (zamowienie.IsidKontaNull())
-                {
-                    // zmiana domylnego konta do faktury dla EUR
-                    if (User.Instance().IdAgencji != 4 && product.Currency == "EUR")
-                    {
-                        if (User.Instance().IdAgencji == 1223940396 || User.Instance().IdAgencji == 1223940398)
-                            zamowienie.idKonta = 3;
-                        else
-                            zamowienie.idKonta = 5;
-
-                        zamowieniaTableAdapter.Update(rEKLAMADataSet.zamowienia);
-                    }
-                }
-            }
+            UpdateOrderAccount(product, zamowienie);
 
             product.OrderId = zamowienie.idZamowienia;
@@ -243,4 +205,20 @@
             BindProductsWithOrders(zamowienie.idZamowienia);
             BindProductsWithoutOrders();
+        }
+
+        private void UpdateOrderAccount(IProduct product, REKLAMADataSet.zamowieniaRow order)
+        {
+            if (product.ProductType != ProductType.Advertisment || !order.IsidKontaNull()) return;
+
+            // zmiana domylnego konta do faktury dla EUR
+            if (User.Instance().IdAgencji != 4 && product.Currency == "EUR")
+            {
+                if (User.Instance().IdAgencji == 1223940396 || User.Instance().IdAgencji == 1223940398)
+                    order.idKonta = 3;
+                else
+                    order.idKonta = 5;
+
+                zamowieniaTableAdapter.Update(rEKLAMADataSet.zamowienia);
+            }
         }
 
@@ -315,10 +293,7 @@
                 REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow) z.Row;
 
-                REKLAMADataSet.KLIENCIRow klientRow =
-                    (REKLAMADataSet.KLIENCIRow) klienciTableAdapter.GetDataByCustomerId(zamowienie.idKlienta).Rows[0];
-
                 InitIssueTables(zamowienie);
 
-                string errorMessage = CzyMoznaZafakturowac(zamowienie, klientRow);
+                string errorMessage = CzyMoznaZafakturowac(zamowienie, klient);
 
                 if (errorMessage != string.Empty)
@@ -329,5 +304,7 @@
                 }
 
-                WystawFakture(zamowienie, klientRow, false);
+                List<IProduct> subscriptionsToInvoice = GetSubscriptionsToInvoice(productsWithOrder);
+
+                WystawFakture(zamowienie, klient, subscriptionsToInvoice, false);
 
                 RestoreConnections();
@@ -343,19 +320,10 @@
         }
 
-        private int WystawFakture(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow, bool proforma)
+        private int WystawFakture(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow, List<IProduct> subscriptions, bool proforma)
         {
             int idNaglowka;
-            
+
             try
             {
-                REKLAMADataSet.FAKTURYRow naglowekFaktury = UtworzNaglowekFaktury(zamowienie, klientRow, proforma);
-                rEKLAMADataSet.FAKTURY.AddFAKTURYRow(naglowekFaktury);
-                PobierzOznaczEmisje(zamowienie, naglowekFaktury);
-                UtworzPozycjeFaktury(naglowekFaktury, klientRow);
-                DodajWplate(naglowekFaktury);
-
-                zamowienie.zafakturowano = true;
-                zamowienie.EndEdit();
-
                 SqlConnection conn = new SqlConnection(ConnString.getConnString().Value);
 
@@ -377,6 +345,16 @@
                 wplatyTableAdapter.AttachTransaction(transaction);
 
+
+                REKLAMADataSet.FAKTURYRow naglowekFaktury = UtworzNaglowekFaktury(zamowienie, klientRow, proforma);
                 try
                 {
+                    rEKLAMADataSet.FAKTURY.AddFAKTURYRow(naglowekFaktury);
+                    PobierzOznaczEmisje(zamowienie, naglowekFaktury);
+                    UtworzPozycjeFaktury(naglowekFaktury, klientRow, subscriptions);
+                    DodajWplate(naglowekFaktury);
+
+                    zamowienie.zafakturowano = true;
+                    zamowienie.EndEdit();
+
                     fAKTURYTableAdapter.Update(rEKLAMADataSet.FAKTURY);
                     idNaglowka = naglowekFaktury.ID_FAKTURY;
@@ -385,6 +363,5 @@
                     wplatyTableAdapter.Update(rEKLAMADataSet.Wplaty);
 
-                    int il = (int)emisjeTableAdapter.iloscNiezafakturowanychEmisjiWZamowieniu(
-                        zamowienie.idZamowienia);
+                    int il = (int) emisjeTableAdapter.iloscNiezafakturowanychEmisjiWZamowieniu(zamowienie.idZamowienia);
                     if (il == 0 && !proforma)
                     {
@@ -427,5 +404,5 @@
                 fAKTURYDataGridView.Refresh();
                 zamowieniaBindingSource.ResetBindings(false);
-                
+
             }
 
@@ -441,5 +418,5 @@
         }
 
-        private void UtworzPozycjeFaktury(REKLAMADataSet.FAKTURYRow naglowekFaktury, REKLAMADataSet.KLIENCIRow klientRow)
+        private void UtworzPozycjeFaktury(REKLAMADataSet.FAKTURYRow naglowekFaktury, REKLAMADataSet.KLIENCIRow klientRow, List<IProduct> subscriptionsToInvoice)
         {
             decimal bruttoWaluta = 0;
@@ -532,4 +509,45 @@
             }
 
+            foreach (IProduct subscription in subscriptionsToInvoice)
+            {
+
+                foreach (IProductDetail subscriptionDetail in subscription.ProductDetails)
+                {
+                    REKLAMADataSet.FAKTURA_DETAILSRow fakturaDetailsRow = rEKLAMADataSet.FAKTURA_DETAILS.NewFAKTURA_DETAILSRow();
+
+                    fakturaDetailsRow.ROK = subscriptionDetail.Year;
+                    fakturaDetailsRow.MIESIAC = (short)subscriptionDetail.Month;
+                    //TODO: Add Title to Subscription schema
+                    //fakturaDetailsRow.TYTUL = subscriptionDetail;
+                    //TODO: Nazwa uslugi dla reklamy i abonamentu
+                    fakturaDetailsRow.NAZWA_USLUGI = subscriptionDetail.ProductId + " | " + subscriptionDetail.Id;
+                    fakturaDetailsRow.reklamaId = subscription.Id;
+                    fakturaDetailsRow.CENA_JEDN = subscription.Price;
+                    fakturaDetailsRow.ILOSC = 1;
+                    fakturaDetailsRow.JM = "szt.";
+
+                    fakturaDetailsRow.NETTO = subscriptionDetail.PricePln;
+                    fakturaDetailsRow.BRUTTO = Math.Round(subscriptionDetail.PricePln * (1 + subscription.Vat));
+                    fakturaDetailsRow.S_VAT = (double)subscription.Vat;
+                    fakturaDetailsRow.VAT = Math.Round(subscriptionDetail.PricePln * subscription.Vat);
+
+                    //TODO: Get discount from parent
+                    //fakturaDetailsRow.UPUST_PR = subscription.Discount;
+                    //fakturaDetailsRow.UPUST_NETTO = fakturaDetailsRow.UPUST_PR != 0 ? Math.Round(netto / Convert.ToDecimal(reklama.RABAT) - netto, 2) : 0;
+
+                    fakturaDetailsRow.TYP = 1;
+                    fakturaDetailsRow.PODTYP = 1;
+                    fakturaDetailsRow.ID_FAKTURY = naglowekFaktury.ID_FAKTURY;
+
+                    rEKLAMADataSet.FAKTURA_DETAILS.AddFAKTURA_DETAILSRow(fakturaDetailsRow);
+
+                    if (subscription.Currency != "PLN")
+                        bruttoWaluta += subscriptionDetail.Price;
+                }
+                
+                
+            }
+
+
             if (bruttoWaluta != 0)
             {
@@ -546,4 +564,5 @@
             rEKLAMADataSet.UKAZE_SIE_W_NR.Clear();
             rEKLAMADataSet.DatyWydan.Clear();
+            rEKLAMATableAdapter.FillByIdZamowienia(rEKLAMADataSet.REKLAMA, zamowienie.idZamowienia);
 
             REKLAMADataSet.DatyWydanDataTable t = datyWydanTableAdapter.GetDataByPierwszaEmisjaWZamowieniu(zamowienie.idZamowienia);
@@ -551,12 +570,7 @@
 
             DateTime d = t[0].DATA_W;
-            //d = zamowienie.IsdataOstatniejZafakturowanejEmisjiNull() ? d : zamowienie.dataOstatniejZafakturowanejEmisji.AddMonths(1);
-
-            List<string> adIds = new List<string>();
-
-            foreach (DataRow r in rEKLAMADataSet.REKLAMA.Rows)
-            {
-                REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)r;
-                adIds.Add(reklama.ID_REKLAMY);
+
+            foreach (REKLAMADataSet.REKLAMARow reklama in rEKLAMADataSet.REKLAMA.Rows)
+            {
                 switch (zamowienie.rodzajFakturowania)
                 {
@@ -593,6 +607,4 @@
         private void PobierzOznaczEmisje(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.FAKTURYRow naglowekFaktury)
         {
-            //InitIssueTables(zamowienie);
-
             if (zamowienie.IsdataOstatniejZafakturowanejEmisjiNull())
             {
@@ -600,8 +612,6 @@
             }
 
-            foreach (DataRow r in rEKLAMADataSet.REKLAMA.Rows)
-            {
-                REKLAMADataSet.REKLAMARow reklama = (REKLAMADataSet.REKLAMARow)r;
-                
+            foreach (REKLAMADataSet.REKLAMARow reklama in rEKLAMADataSet.REKLAMA.Rows)
+            {
                 foreach (DataRow em in rEKLAMADataSet.UKAZE_SIE_W_NR)
                 {
@@ -648,7 +658,7 @@
         private REKLAMADataSet.FAKTURYRow UtworzNaglowekFaktury(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow, bool proforma)
         {
-            SLOWNIKDataSet.AGENCIRow agent = (SLOWNIKDataSet.AGENCIRow)agenciTableAdapter.GetDataByKodAgenta(zamowienie.kodAgenta).Rows[0];
-            IInvoiceProvider invoiceProvider = InvoiceProviderFactory.GetInvoiceProviderById(agent.InvoiceProviderId);
-
+            agent = agentRepository.FindByShortName(zamowienie.kodAgenta);
+
+            IInvoiceProvider invoiceProvider = InvoiceProviderFactory.GetInvoiceProviderById(agent.InvoiceProvider);
 
             REKLAMADataSet.FAKTURYRow naglowekFaktury = (REKLAMADataSet.FAKTURYRow)rEKLAMADataSet.FAKTURY.NewRow();
@@ -661,40 +671,31 @@
             naglowekFaktury.DATA_WYSTAWIENIA = DateTime.Today;
 
-            if (User.Instance().IsKierownik)
-            {
-                if (dtpZmianaDaty.Value != DateTime.Today)
-                {
-                    naglowekFaktury.DATA_WYSTAWIENIA = dtpZmianaDaty.Value;
-                }
-            }
+            //TODO: pass issueDate as parameter
+            if (dtpZmianaDaty.Value != DateTime.Today && User.Instance().IsKierownik)
+                naglowekFaktury.DATA_WYSTAWIENIA = dtpZmianaDaty.Value;
 
             SLOWNIKDataSet.AGENCJERow agencja = (SLOWNIKDataSet.AGENCJERow)agencjeTableAdapter.GetDataByKodAgenta(zamowienie.kodAgenta).Rows[0];
             naglowekFaktury.ID_SPRZEDAWCY = agencja.Id_agencji;
             
-            if (naglowekFaktury.ID_SPRZEDAWCY == 4 || naglowekFaktury.ID_SPRZEDAWCY == 6 ||
-                naglowekFaktury.ID_SPRZEDAWCY == 1223940400)
-            {
+            //Set EKSPORT to true to avoid to export this invoice to SoftLab FK accounting system
+            if (naglowekFaktury.ID_SPRZEDAWCY == 4 || naglowekFaktury.ID_SPRZEDAWCY == 6)
                 naglowekFaktury.EKSPORT = true;
-            }
 
             naglowekFaktury.MIEJSCOWOSC_WYSTAWIENIA = agencja.miasto;
-            naglowekFaktury.SPRZEDAWCA_ADRES = invoiceProvider.GetAddress(); //agencja.Adres_Fk;
-            naglowekFaktury.SPRZEDAWCA_NIP = invoiceProvider.TaxNumber; //agencja.NIP;
+            naglowekFaktury.SPRZEDAWCA_ADRES = invoiceProvider.GetAddress();
+            naglowekFaktury.SPRZEDAWCA_NIP = invoiceProvider.TaxNumber;
             naglowekFaktury.SystemKsiegowyId = Convert.ToByte(invoiceProvider.SystemKsiegowyId);
-            
-
-            //SLOWNIKDataSet.AGENCIRow agent = (SLOWNIKDataSet.AGENCIRow)agenciTableAdapter.GetDataByKodAgenta(zamowienie.kodAgenta).Rows[0];
-            naglowekFaktury.PODPIS_WYSTAWIL = agent.Imiê + " " + agent.Nazwisko;
+
+            naglowekFaktury.PODPIS_WYSTAWIL = agent.ToString();
             naglowekFaktury.DATA_SPRZEDAZY = naglowekFaktury.DATA_WYSTAWIENIA;
 
-            naglowekFaktury.ID_NABYWCY = zamowienie.idKlienta;
+            naglowekFaktury.ID_NABYWCY = klientRow.CustomerID;
             naglowekFaktury.NABYWCA_ADRES = klientRow.Adres_Fkatura;
             naglowekFaktury.NABYWCA_NIP = klientRow.Nip;
             naglowekFaktury.opis = "Faktura za reklamy zgodnie z zamówieniem: " 
-                + klientRow.kodKlienta + 
-                "/" + zamowienie.nrZamowienia + 
-                "/" + zamowienie.kodAgenta + 
-                "/" + zamowienie.rokZamowienia;
-
+                                                + klientRow.kodKlienta + 
+                                                "/" + zamowienie.nrZamowienia + 
+                                                "/" + zamowienie.kodAgenta + 
+                                                "/" + zamowienie.rokZamowienia;
 
             naglowekFaktury.SPOSOB_ZAPLATY = FakturaHelper.GetPaymentType(zamowienie.sposobZaplaty);
@@ -708,8 +709,6 @@
             naglowekFaktury.waluta_kurs = 1d;
             //WALUTOWE
-            if (!rEKLAMADataSet.REKLAMA[0].IsBrutto_Euro_MianoNull() &&
-                rEKLAMADataSet.REKLAMA[0].Brutto_Euro_Miano != string.Empty)
-            {
-                //naglowekFaktury.SPRZEDAWCA_NIP = agencja.vies;
+            if (!rEKLAMADataSet.REKLAMA[0].IsBrutto_Euro_MianoNull() && rEKLAMADataSet.REKLAMA[0].Brutto_Euro_Miano != string.Empty)
+            {
                 naglowekFaktury.SPRZEDAWCA_NIP = invoiceProvider.TaxCountryPrefix + " " + invoiceProvider.TaxNumber; //agencja.vies;
                 naglowekFaktury.NABYWCA_NIP = klientRow.nipKraj + " " + klientRow.Nip;
@@ -741,6 +740,4 @@
             return naglowekFaktury;
         }
-
-        
 
         private string CzyMoznaZafakturowac(REKLAMADataSet.zamowieniaRow zamowienie, REKLAMADataSet.KLIENCIRow klientRow)
@@ -1172,10 +1169,8 @@
         {
             if (zamowieniaBindingSource.Current == null) return;
-            
-            
-            DataRowView z = (DataRowView)zamowieniaBindingSource.Current;
-            REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow)z.Row;
-                
-            //rEKLAMATableAdapter.FillByIdZamowienia(rEKLAMADataSet.REKLAMA, zamowienie.idZamowienia);
+
+            DataRowView z = (DataRowView) zamowieniaBindingSource.Current;
+            REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow) z.Row;
+
             BindProductsWithOrders(zamowienie.idZamowienia);
 
@@ -1394,10 +1389,7 @@
             REKLAMADataSet.zamowieniaRow zamowienie = (REKLAMADataSet.zamowieniaRow) z.Row;
 
-            REKLAMADataSet.KLIENCIRow _klient =
-                (REKLAMADataSet.KLIENCIRow) klienciTableAdapter.GetDataByCustomerId(zamowienie.idKlienta).Rows[0];
-
             InitIssueTables(zamowienie);
 
-            string errorMessage = CzyMoznaZafakturowac(zamowienie, _klient);
+            string errorMessage = CzyMoznaZafakturowac(zamowienie, klient);
 
             if (errorMessage != string.Empty)
@@ -1411,6 +1403,8 @@
             try
             {
-                id = WystawFakture(zamowienie, _klient, true);
-                FactureViewer fv = new FactureViewer(id, true, _klient.kodKlienta);
+                List<IProduct> subscriptionsToInvoice = GetSubscriptionsToInvoice(productsWithOrder);
+
+                id = WystawFakture(zamowienie, klient, subscriptionsToInvoice, true);
+                FactureViewer fv = new FactureViewer(id, true, klient.kodKlienta);
                 fv.ShowDialog();
             }
@@ -1419,6 +1413,6 @@
                 DataRow[] rows = rEKLAMADataSet.FAKTURY.Select("id_faktury=" + id);
                 if (rows.Length > 0)
-                    usunFakture((REKLAMADataSet.FAKTURYRow) rows[0]);
-                
+                    usunFakture((REKLAMADataSet.FAKTURYRow)rows[0]);
+
                 RestoreConnections();
                 Cursor = Cursors.Default;
@@ -1435,4 +1429,14 @@
             wplatyTableAdapter.Connection = new SqlConnection(ConnString.getConnString().Value);
         }
+
+        private List<IProduct> GetSubscriptionsToInvoice(List<IProduct> products)
+        {
+            ProductRepository productRepository = new ProductRepository(ConnString.getConnString().Value);
+            List<IProduct> subscriptions = products.FindAll(delegate(IProduct p) { return p.ProductType == ProductType.Subscription; });
+            DateTime date = productRepository.FindFirstDateForInvoice(subscriptions);
+            List<IProduct> subscriptionsToInvoice = productRepository.FindProductsToInvoice(subscriptions, InvoicingType.ThreeMonths, date);
+            return subscriptionsToInvoice;
+        }
+
     }
 }
Index: branches/Abonament/BazaReklam/FacturesFormNew.cs
===================================================================
--- branches/Abonament/BazaReklam/FacturesFormNew.cs (revision 676)
+++ branches/Abonament/BazaReklam/FacturesFormNew.cs (revision 705)
@@ -332,12 +332,22 @@
         private void zamowieniaToolStripButton_Click(object sender, EventArgs e)
         {
-            if (VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource.Current != null)
-            {
+            if (VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource.Current == null) return;
+            
+            
+            try
+            {
+                Cursor = Cursors.WaitCursor;
                 DataRowView row = (DataRowView)VIEW_ZESTAWIENIE_FAKTUR_NOWEBindingSource.Current;
                 REKLAMADataSet.VIEW_ZESTAWIENIE_FAKTUR_NOWERow f = (REKLAMADataSet.VIEW_ZESTAWIENIE_FAKTUR_NOWERow)row.Row;
 
                 ZamowieniaForm zf = new ZamowieniaForm(f.ID_NABYWCY, f.idZamowienia);
-                zf.ShowDialog();
-            }
+                zf.ShowDialog();                
+            }
+            finally
+            {
+                Cursor = Cursors.Default; 
+            }
+
+
         }
 
Index: branches/Abonament/BazaReklam/Baza Reklam.csproj
===================================================================
--- branches/Abonament/BazaReklam/Baza Reklam.csproj (revision 704)
+++ branches/Abonament/BazaReklam/Baza Reklam.csproj (revision 705)
@@ -142,4 +142,6 @@
     <Compile Include="Classes\Interfaces\IForm.cs" />
     <Compile Include="Classes\Interfaces\IProduct.cs" />
+    <Compile Include="Classes\Interfaces\IProductDetail.cs" />
+    <Compile Include="Classes\Model\Enums\InvoicingType.cs" />
     <Compile Include="Classes\Model\Enums\ProductType.cs" />
     <Compile Include="Classes\Model\Product.cs" />
@@ -153,4 +155,5 @@
     <Compile Include="Classes\Global.cs" />
     <Compile Include="Classes\Logger.cs" />
+    <Compile Include="Classes\Model\ProductDetail.cs" />
     <Compile Include="Classes\Model\State.cs" />
     <Compile Include="Classes\Model\Subscription.cs" />
@@ -165,4 +168,5 @@
     <Compile Include="Classes\Repositories\CustomerRepository.cs" />
     <Compile Include="Classes\Repositories\IRepository.cs" />
+    <Compile Include="Classes\Repositories\ProductRepository.cs" />
     <Compile Include="Classes\Repositories\Repository.cs" />
     <Compile Include="Classes\Repositories\StateRepository.cs" />
Index: branches/Abonament/BazaReklam/ZamowieniaForm.Designer.cs
===================================================================
--- branches/Abonament/BazaReklam/ZamowieniaForm.Designer.cs (revision 704)
+++ branches/Abonament/BazaReklam/ZamowieniaForm.Designer.cs (revision 705)
@@ -30,14 +30,14 @@
         {
             this.components = new System.ComponentModel.Container();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle11 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle12 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle17 = new System.Windows.Forms.DataGridViewCellStyle();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ZamowieniaForm));
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle18 = new System.Windows.Forms.DataGridViewCellStyle();
             this.zamowieniaDataGridView = new System.Windows.Forms.DataGridView();
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
@@ -49,7 +49,16 @@
             this.rEKLAMADataSet = new Baza_Reklam.REKLAMADataSet();
             this.rEKLAMADataGridView = new System.Windows.Forms.DataGridView();
-            this.rEKLAMABindingSource = new System.Windows.Forms.BindingSource(this.components);
+            this.TYP = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.ShortName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.VAT = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.Brutto_Euro_Miano = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.ZATWIERDZONO_DO_DRUKU = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.rEKLAMADataGridView1 = new System.Windows.Forms.DataGridView();
-            this.rEKLAMABindingSource1 = new System.Windows.Forms.BindingSource(this.components);
+            this.Data1Emisji = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.ShortName1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dataGridViewTextBoxColumn43 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.dataGridViewTextBoxColumn44 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.ZATWIERDZONO_DO_DRUKU2 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.dodajButton = new System.Windows.Forms.Button();
             this.dodajDoZamButton = new System.Windows.Forms.Button();
@@ -89,22 +98,9 @@
             this.toolTip = new System.Windows.Forms.ToolTip(this.components);
             this.KlientLabel = new System.Windows.Forms.Label();
-            this.TYP = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ShortName = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.VAT = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.Brutto_Euro_Miano = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ZATWIERDZONO_DO_DRUKU = new System.Windows.Forms.DataGridViewCheckBoxColumn();
-            this.Data1Emisji = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ShortName1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn43 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn44 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.ZATWIERDZONO_DO_DRUKU2 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             ((System.ComponentModel.ISupportInitialize)(this.zamowieniaDataGridView)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.zamowieniaBindingSource)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataSet)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataGridView)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.rEKLAMABindingSource)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataGridView1)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.rEKLAMABindingSource1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.fAKTURYDataGridView)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.fAKTURYBindingSource)).BeginInit();
@@ -118,18 +114,18 @@
             this.zamowieniaDataGridView.AllowUserToAddRows = false;
             this.zamowieniaDataGridView.AllowUserToDeleteRows = false;
-            dataGridViewCellStyle1.BackColor = System.Drawing.Color.MintCream;
-            this.zamowieniaDataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
+            dataGridViewCellStyle10.BackColor = System.Drawing.Color.MintCream;
+            this.zamowieniaDataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle10;
             this.zamowieniaDataGridView.AutoGenerateColumns = false;
             this.zamowieniaDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
             this.zamowieniaDataGridView.BackgroundColor = System.Drawing.Color.White;
             this.zamowieniaDataGridView.CausesValidation = false;
-            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.zamowieniaDataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
+            dataGridViewCellStyle11.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle11.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle11.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
+            dataGridViewCellStyle11.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle11.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle11.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle11.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.zamowieniaDataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle11;
             this.zamowieniaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.dataGridViewCheckBoxColumn1,
@@ -206,12 +202,12 @@
             this.rEKLAMADataGridView.BackgroundColor = System.Drawing.Color.White;
             this.rEKLAMADataGridView.CausesValidation = false;
-            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.rEKLAMADataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle3;
+            dataGridViewCellStyle12.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle12.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
+            dataGridViewCellStyle12.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle12.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle12.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle12.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.rEKLAMADataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle12;
             this.rEKLAMADataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.TYP,
@@ -229,8 +225,45 @@
             this.rEKLAMADataGridView.TabIndex = 1;
             // 
-            // rEKLAMABindingSource
-            // 
-            this.rEKLAMABindingSource.DataMember = "REKLAMA";
-            this.rEKLAMABindingSource.DataSource = this.rEKLAMADataSet;
+            // TYP
+            // 
+            this.TYP.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+            this.TYP.DataPropertyName = "Type";
+            this.TYP.HeaderText = "Typ";
+            this.TYP.Name = "TYP";
+            this.TYP.ReadOnly = true;
+            this.TYP.Width = 50;
+            // 
+            // ShortName
+            // 
+            this.ShortName.DataPropertyName = "ShortName";
+            this.ShortName.HeaderText = "Symbol";
+            this.ShortName.Name = "ShortName";
+            this.ShortName.ReadOnly = true;
+            // 
+            // VAT
+            // 
+            this.VAT.DataPropertyName = "Vat";
+            dataGridViewCellStyle13.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle13.Format = "P";
+            this.VAT.DefaultCellStyle = dataGridViewCellStyle13;
+            this.VAT.HeaderText = "Vat";
+            this.VAT.Name = "VAT";
+            this.VAT.ReadOnly = true;
+            // 
+            // Brutto_Euro_Miano
+            // 
+            this.Brutto_Euro_Miano.DataPropertyName = "Currency";
+            this.Brutto_Euro_Miano.HeaderText = "Waluta";
+            this.Brutto_Euro_Miano.Name = "Brutto_Euro_Miano";
+            this.Brutto_Euro_Miano.ReadOnly = true;
+            // 
+            // ZATWIERDZONO_DO_DRUKU
+            // 
+            this.ZATWIERDZONO_DO_DRUKU.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+            this.ZATWIERDZONO_DO_DRUKU.DataPropertyName = "IsActivated";
+            this.ZATWIERDZONO_DO_DRUKU.HeaderText = "ZD";
+            this.ZATWIERDZONO_DO_DRUKU.Name = "ZATWIERDZONO_DO_DRUKU";
+            this.ZATWIERDZONO_DO_DRUKU.ReadOnly = true;
+            this.ZATWIERDZONO_DO_DRUKU.Width = 25;
             // 
             // rEKLAMADataGridView1
@@ -238,17 +271,17 @@
             this.rEKLAMADataGridView1.AllowUserToAddRows = false;
             this.rEKLAMADataGridView1.AllowUserToDeleteRows = false;
-            dataGridViewCellStyle5.BackColor = System.Drawing.Color.MintCream;
-            this.rEKLAMADataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle5;
+            dataGridViewCellStyle14.BackColor = System.Drawing.Color.MintCream;
+            this.rEKLAMADataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle14;
             this.rEKLAMADataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
             this.rEKLAMADataGridView1.BackgroundColor = System.Drawing.Color.White;
             this.rEKLAMADataGridView1.CausesValidation = false;
-            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.rEKLAMADataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle6;
+            dataGridViewCellStyle15.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle15.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle15.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
+            dataGridViewCellStyle15.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle15.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle15.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle15.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.rEKLAMADataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle15;
             this.rEKLAMADataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.Data1Emisji,
@@ -267,8 +300,55 @@
             this.rEKLAMADataGridView1.TabIndex = 2;
             // 
-            // rEKLAMABindingSource1
-            // 
-            this.rEKLAMABindingSource1.DataMember = "REKLAMA";
-            this.rEKLAMABindingSource1.DataSource = this.rEKLAMADataSet;
+            // Data1Emisji
+            // 
+            this.Data1Emisji.DataPropertyName = "StartDate";
+            dataGridViewCellStyle16.Format = "d";
+            dataGridViewCellStyle16.NullValue = null;
+            this.Data1Emisji.DefaultCellStyle = dataGridViewCellStyle16;
+            this.Data1Emisji.HeaderText = "1 Emisja";
+            this.Data1Emisji.Name = "Data1Emisji";
+            this.Data1Emisji.ReadOnly = true;
+            // 
+            // ShortName1
+            // 
+            this.ShortName1.DataPropertyName = "ShortName";
+            this.ShortName1.HeaderText = "Symbol";
+            this.ShortName1.Name = "ShortName1";
+            this.ShortName1.ReadOnly = true;
+            // 
+            // dataGridViewTextBoxColumn1
+            // 
+            this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+            this.dataGridViewTextBoxColumn1.DataPropertyName = "Type";
+            this.dataGridViewTextBoxColumn1.HeaderText = "Typ";
+            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
+            this.dataGridViewTextBoxColumn1.ReadOnly = true;
+            this.dataGridViewTextBoxColumn1.Width = 50;
+            // 
+            // dataGridViewTextBoxColumn43
+            // 
+            this.dataGridViewTextBoxColumn43.DataPropertyName = "Vat";
+            dataGridViewCellStyle17.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle17.Format = "P";
+            this.dataGridViewTextBoxColumn43.DefaultCellStyle = dataGridViewCellStyle17;
+            this.dataGridViewTextBoxColumn43.HeaderText = "Vat";
+            this.dataGridViewTextBoxColumn43.Name = "dataGridViewTextBoxColumn43";
+            this.dataGridViewTextBoxColumn43.ReadOnly = true;
+            // 
+            // dataGridViewTextBoxColumn44
+            // 
+            this.dataGridViewTextBoxColumn44.DataPropertyName = "Currency";
+            this.dataGridViewTextBoxColumn44.HeaderText = "Waluta";
+            this.dataGridViewTextBoxColumn44.Name = "dataGridViewTextBoxColumn44";
+            this.dataGridViewTextBoxColumn44.ReadOnly = true;
+            // 
+            // ZATWIERDZONO_DO_DRUKU2
+            // 
+            this.ZATWIERDZONO_DO_DRUKU2.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+            this.ZATWIERDZONO_DO_DRUKU2.DataPropertyName = "IsActivated";
+            this.ZATWIERDZONO_DO_DRUKU2.HeaderText = "ZD";
+            this.ZATWIERDZONO_DO_DRUKU2.Name = "ZATWIERDZONO_DO_DRUKU2";
+            this.ZATWIERDZONO_DO_DRUKU2.ReadOnly = true;
+            this.ZATWIERDZONO_DO_DRUKU2.Width = 25;
             // 
             // dodajButton
@@ -335,6 +415,6 @@
             this.fAKTURYDataGridView.AllowUserToAddRows = false;
             this.fAKTURYDataGridView.AllowUserToDeleteRows = false;
-            dataGridViewCellStyle9.BackColor = System.Drawing.Color.MintCream;
-            this.fAKTURYDataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle9;
+            dataGridViewCellStyle18.BackColor = System.Drawing.Color.MintCream;
+            this.fAKTURYDataGridView.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle18;
             this.fAKTURYDataGridView.AutoGenerateColumns = false;
             this.fAKTURYDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
@@ -658,98 +738,4 @@
             this.KlientLabel.Text = "----";
             // 
-            // TYP
-            // 
-            this.TYP.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
-            this.TYP.DataPropertyName = "Type";
-            this.TYP.HeaderText = "Typ";
-            this.TYP.Name = "TYP";
-            this.TYP.ReadOnly = true;
-            this.TYP.Width = 50;
-            // 
-            // ShortName
-            // 
-            this.ShortName.DataPropertyName = "ShortName";
-            this.ShortName.HeaderText = "Symbol";
-            this.ShortName.Name = "ShortName";
-            this.ShortName.ReadOnly = true;
-            // 
-            // VAT
-            // 
-            this.VAT.DataPropertyName = "Vat";
-            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle4.Format = "P";
-            this.VAT.DefaultCellStyle = dataGridViewCellStyle4;
-            this.VAT.HeaderText = "Vat";
-            this.VAT.Name = "VAT";
-            this.VAT.ReadOnly = true;
-            // 
-            // Brutto_Euro_Miano
-            // 
-            this.Brutto_Euro_Miano.DataPropertyName = "Currency";
-            this.Brutto_Euro_Miano.HeaderText = "Waluta";
-            this.Brutto_Euro_Miano.Name = "Brutto_Euro_Miano";
-            this.Brutto_Euro_Miano.ReadOnly = true;
-            // 
-            // ZATWIERDZONO_DO_DRUKU
-            // 
-            this.ZATWIERDZONO_DO_DRUKU.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
-            this.ZATWIERDZONO_DO_DRUKU.DataPropertyName = "IsActivated";
-            this.ZATWIERDZONO_DO_DRUKU.HeaderText = "ZD";
-            this.ZATWIERDZONO_DO_DRUKU.Name = "ZATWIERDZONO_DO_DRUKU";
-            this.ZATWIERDZONO_DO_DRUKU.ReadOnly = true;
-            this.ZATWIERDZONO_DO_DRUKU.Width = 25;
-            // 
-            // Data1Emisji
-            // 
-            this.Data1Emisji.DataPropertyName = "StartDate";
-            dataGridViewCellStyle7.Format = "d";
-            dataGridViewCellStyle7.NullValue = null;
-            this.Data1Emisji.DefaultCellStyle = dataGridViewCellStyle7;
-            this.Data1Emisji.HeaderText = "1 Emisja";
-            this.Data1Emisji.Name = "Data1Emisji";
-            this.Data1Emisji.ReadOnly = true;
-            // 
-            // ShortName1
-            // 
-            this.ShortName1.DataPropertyName = "ShortName";
-            this.ShortName1.HeaderText = "Symbol";
-            this.ShortName1.Name = "ShortName1";
-            this.ShortName1.ReadOnly = true;
-            // 
-            // dataGridViewTextBoxColumn1
-            // 
-            this.dataGridViewTextBoxColumn1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
-            this.dataGridViewTextBoxColumn1.DataPropertyName = "Type";
-            this.dataGridViewTextBoxColumn1.HeaderText = "Typ";
-            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
-            this.dataGridViewTextBoxColumn1.ReadOnly = true;
-            this.dataGridViewTextBoxColumn1.Width = 50;
-            // 
-            // dataGridViewTextBoxColumn43
-            // 
-            this.dataGridViewTextBoxColumn43.DataPropertyName = "Vat";
-            dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle8.Format = "P";
-            this.dataGridViewTextBoxColumn43.DefaultCellStyle = dataGridViewCellStyle8;
-            this.dataGridViewTextBoxColumn43.HeaderText = "Vat";
-            this.dataGridViewTextBoxColumn43.Name = "dataGridViewTextBoxColumn43";
-            this.dataGridViewTextBoxColumn43.ReadOnly = true;
-            // 
-            // dataGridViewTextBoxColumn44
-            // 
-            this.dataGridViewTextBoxColumn44.DataPropertyName = "Currency";
-            this.dataGridViewTextBoxColumn44.HeaderText = "Waluta";
-            this.dataGridViewTextBoxColumn44.Name = "dataGridViewTextBoxColumn44";
-            this.dataGridViewTextBoxColumn44.ReadOnly = true;
-            // 
-            // ZATWIERDZONO_DO_DRUKU2
-            // 
-            this.ZATWIERDZONO_DO_DRUKU2.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
-            this.ZATWIERDZONO_DO_DRUKU2.DataPropertyName = "IsActivated";
-            this.ZATWIERDZONO_DO_DRUKU2.HeaderText = "ZD";
-            this.ZATWIERDZONO_DO_DRUKU2.Name = "ZATWIERDZONO_DO_DRUKU2";
-            this.ZATWIERDZONO_DO_DRUKU2.ReadOnly = true;
-            this.ZATWIERDZONO_DO_DRUKU2.Width = 25;
-            // 
             // ZamowieniaForm
             // 
@@ -769,7 +755,5 @@
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataSet)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataGridView)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.rEKLAMABindingSource)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.rEKLAMADataGridView1)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.rEKLAMABindingSource1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.fAKTURYDataGridView)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.fAKTURYBindingSource)).EndInit();
@@ -801,6 +785,4 @@
         private System.Windows.Forms.DataGridView fAKTURYDataGridView;
         private System.Windows.Forms.Button WydrukButton;
-        private System.Windows.Forms.BindingSource rEKLAMABindingSource;
-        private System.Windows.Forms.BindingSource rEKLAMABindingSource1;
         private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
         private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
Index: branches/Abonament/BazaReklam/ZamowieniaForm.resx
===================================================================
--- branches/Abonament/BazaReklam/ZamowieniaForm.resx (revision 704)
+++ branches/Abonament/BazaReklam/ZamowieniaForm.resx (revision 705)
@@ -136,4 +136,7 @@
     <value>17, 17</value>
   </metadata>
+  <metadata name="rEKLAMADataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
   <metadata name="TYP.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
@@ -151,7 +154,4 @@
     <value>True</value>
   </metadata>
-  <metadata name="rEKLAMABindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>1087, 17</value>
-  </metadata>
   <metadata name="Data1Emisji.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
@@ -171,7 +171,4 @@
   <metadata name="ZATWIERDZONO_DO_DRUKU2.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
-  </metadata>
-  <metadata name="rEKLAMABindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>17, 54</value>
   </metadata>
   <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
@@ -546,5 +543,5 @@
   </data>
   <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>87</value>
+    <value>52</value>
   </metadata>
 </root>
Index: branches/Abonament/BazaReklam/Classes/Interfaces/IProductDetail.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Interfaces/IProductDetail.cs (revision 705)
+++ branches/Abonament/BazaReklam/Classes/Interfaces/IProductDetail.cs (revision 705)
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Baza_Reklam.Classes.Interfaces
+{
+    public interface IProductDetail
+    {
+        int Id { get; set; }
+        int ProductId { get; set; }
+        decimal Price { get; set; }
+        decimal PricePln { get; set; }
+        decimal Vat { get; set; }
+        int? InvoiceId { get; set; }
+        int Year { get; set; }
+        int Month { get; set; }
+    }
+}
Index: branches/Abonament/BazaReklam/Classes/Interfaces/IProduct.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Interfaces/IProduct.cs (revision 704)
+++ branches/Abonament/BazaReklam/Classes/Interfaces/IProduct.cs (revision 705)
@@ -1,3 +1,4 @@
 using System;
+using System.Collections.Generic;
 using Baza_Reklam.Classes.Model.Enums;
 
@@ -10,5 +11,5 @@
         string Type { get; set; }
         string ShortName { get; set; }
-        DateTime StartDate { get; set; }
+        DateTime? StartDate { get; set; }
         decimal Price { get; set; }
         decimal TotalPrice { get; set; }
@@ -18,4 +19,6 @@
         int? OrderId { get; set; }
         bool HasInvoice { get; set; }
+        List<IProductDetail> ProductDetails { get; }
+        void AddProductDetail(IProductDetail productDetail);
     }
 }
Index: branches/Abonament/BazaReklam/Classes/Repositories/AgentRepository.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Repositories/AgentRepository.cs (revision 702)
+++ branches/Abonament/BazaReklam/Classes/Repositories/AgentRepository.cs (revision 705)
@@ -54,5 +54,5 @@
         public Agent FindByShortName(string shortName)
         {
-            const string query = "SELECT Symbol, F_ROZ, InvoiceProviderId FROM dbo.Agenci WHERE F_ROZ=@shortName";
+            const string query = "SELECT Symbol, F_ROZ, InvoiceProviderId, [Imiê], Nazwisko FROM dbo.Agenci WHERE F_ROZ=@shortName";
             SqlConnection conn = null;
             SqlCommand cmd = null;
@@ -64,9 +64,15 @@
                 conn.Open();
                 cmd = new SqlCommand(query, conn);
+                cmd.Parameters.AddWithValue("@shortName", shortName);
                 reader = cmd.ExecuteReader();
                 if (reader != null && reader.Read())
-                    return new Agent(reader.GetString(0).Trim().ToLower(),
-                                     reader.GetString(1).Trim().ToUpper(),
-                                     reader.GetInt32(2));
+                {
+                    Agent agent = new Agent(reader.GetString(0).Trim().ToLower());
+                    agent.ShortName = reader.GetString(1).Trim().ToUpper();
+                    agent.InvoiceProvider = reader.GetInt32(2);
+                    agent.FirstName = reader.GetString(3);
+                    agent.LastName = reader.GetString(4);
+                    return agent;
+                }
             }
             finally
Index: branches/Abonament/BazaReklam/Classes/Repositories/ProductRepository.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Repositories/ProductRepository.cs (revision 705)
+++ branches/Abonament/BazaReklam/Classes/Repositories/ProductRepository.cs (revision 705)
@@ -0,0 +1,123 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Diagnostics;
+using System.Text;
+using Baza_Reklam.Classes.Interfaces;
+using Baza_Reklam.Classes.Model;
+using Baza_Reklam.Classes.Model.Enums;
+
+namespace Baza_Reklam.Classes.Repositories
+{
+    public class ProductRepository : Repository<IProduct>
+    {
+        public ProductRepository(string connectionString)
+            : base(connectionString)
+        {
+        }
+
+        public DateTime FindFirstDateForInvoice(List<IProduct> products)
+        {
+            string query = "SELECT  MIN(CAST(CAST([Year] AS varchar) + '-' + CAST([Month] AS varchar) + '-01' AS datetime)) "
+                           + "FROM SubscriptionDetail PD INNER JOIN Subscription P ON P.Id=PD.SubscriptionId "
+                           + "WHERE PD.InvoiceId IS NULL AND P.Id IN ({0}) ";
+            query = string.Format(query, ProductsIdToCommaSeparatedList(products));
+            try
+            {
+                _connection.Open();
+                _command = new SqlCommand(query, _connection);
+                object date = _command.ExecuteScalar();
+                if (date != null && date != DBNull.Value)
+                    return Convert.ToDateTime(date);
+            }
+            finally
+            {
+                CleanUp();
+            }
+
+            return DateTime.MinValue;
+        }
+
+        public List<IProduct> FindProductsToInvoice(List<IProduct> products, InvoicingType invoicingType, DateTime date)
+        {
+            string query = "SELECT PD.Id, P.Id, PD.Price, PD.PricePLN, PD.Vat, PD.InvoiceId, [Year], [Month] FROM SubscriptionDetail PD "
+                           + "INNER JOIN Subscription P ON P.Id=PD.SubscriptionId "
+                           + "WHERE PD.InvoiceId IS NULL ";
+
+            if (invoicingType == InvoicingType.OneMonth)
+            {
+                query += "AND PD.[Year] = YEAR(@date) AND PD.[Month]=MONTH(@date) ";
+            }
+            if (invoicingType == InvoicingType.ThreeMonths)
+            {
+                query +=
+                    "AND ((PD.[Year] = YEAR(@date) AND PD.[Month]=MONTH(@date)) OR (PD.[Year] = YEAR(DATEADD(MONTH, 1, @date)) AND PD.[Month]=MONTH(DATEADD(MONTH, 1, @date))) OR PD.[Year] = YEAR(DATEADD(MONTH, 2, @date)) AND PD.[Month]=MONTH(DATEADD(MONTH, 2, @date))) ";
+            }
+            query += "AND P.Id IN ({0})";
+
+            query = string.Format(query, ProductsIdToCommaSeparatedList(products));
+
+            Debug.WriteLine(query);
+
+            List<IProductDetail> productDetails = new List<IProductDetail>();
+
+            try
+            {
+                _connection.Open();
+                _command = new SqlCommand(query, _connection);
+                if (invoicingType == InvoicingType.OneMonth || invoicingType == InvoicingType.ThreeMonths)
+                    _command.Parameters.AddWithValue("@date", date);
+                _reader = _command.ExecuteReader();
+                if (_reader != null)
+                {
+                    while (_reader.Read())
+                    {
+                        IProductDetail productDetail = new ProductDetail();
+                        productDetail.Id = _reader.GetInt32(0);
+                        productDetail.ProductId = _reader.GetInt32(1);
+                        productDetail.Price = _reader.GetDecimal(2);
+                        productDetail.PricePln = _reader.GetDecimal(3);
+                        productDetail.Vat = _reader.GetDecimal(4);
+                        productDetail.Year = _reader.GetInt32(6);
+                        productDetail.Month = _reader.GetInt32(7);
+
+                        productDetails.Add(productDetail);
+                    }
+                }
+
+            }
+            finally
+            {
+                CleanUp();
+            }
+
+            List<IProduct> invoiceProducts = new List<IProduct>();
+            foreach (IProduct product in products)
+            {
+                List<IProductDetail> invoiceProductDetails = productDetails.FindAll(delegate(IProductDetail pd)
+                                                                                  {
+                                                                                      return pd.ProductId == product.Id;
+                                                                                  });
+                foreach (IProductDetail productDetail in invoiceProductDetails)
+                {
+                    product.AddProductDetail(productDetail);  
+                }
+                invoiceProducts.Add(product);
+            }
+
+
+            return invoiceProducts;
+        }
+
+        private string ProductsIdToCommaSeparatedList(List<IProduct> products)
+        {
+            StringBuilder sb = new StringBuilder();
+            foreach (IProduct product in products)
+            {
+                sb.Append(product.Id + ",");
+            }
+
+            return sb.ToString().Remove(sb.ToString().Length - 1);
+        }
+    }
+}
Index: branches/Abonament/BazaReklam/Classes/Repositories/CustomerRepository.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Repositories/CustomerRepository.cs (revision 704)
+++ branches/Abonament/BazaReklam/Classes/Repositories/CustomerRepository.cs (revision 705)
@@ -3,4 +3,5 @@
 using System.Data;
 using System.Data.SqlClient;
+using System.Diagnostics;
 using Baza_Reklam.Classes.Interfaces;
 using Baza_Reklam.Classes.Model;
@@ -180,5 +181,8 @@
                         product.ProductType = (ProductType)_reader.GetInt32(2);
                         product.ShortName = _reader.GetString(3);
-                        product.StartDate = _reader.GetDateTime(4);
+                        if (_reader[4] != DBNull.Value)
+                            product.StartDate = _reader.GetDateTime(4);
+                        else
+                            Debug.WriteLine(product.ShortName);
                         product.Price = _reader.GetDecimal(5);
                         product.TotalPrice = _reader.GetDecimal(6);
Index: branches/Abonament/BazaReklam/Classes/Model/Agent.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Model/Agent.cs (revision 621)
+++ branches/Abonament/BazaReklam/Classes/Model/Agent.cs (revision 705)
@@ -6,4 +6,6 @@
         private string _loginName;
         private string _shortName;
+        private string _firstName;
+        private string _lastName;
 
         public Agent(string loginName)
@@ -36,4 +38,21 @@
             set { _invoiceProvider = value; }
         }
+
+        public string FirstName
+        {
+            get { return _firstName; }
+            set { _firstName = value; }
+        }
+
+        public string LastName
+        {
+            get { return _lastName; }
+            set { _lastName = value; }
+        }
+
+        public override string ToString()
+        {
+            return _firstName + " " + _lastName;
+        }
     }
 }
Index: branches/Abonament/BazaReklam/Classes/Model/Product.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Model/Product.cs (revision 704)
+++ branches/Abonament/BazaReklam/Classes/Model/Product.cs (revision 705)
@@ -1,3 +1,4 @@
 using System;
+using System.Collections.Generic;
 using Baza_Reklam.Classes.Interfaces;
 using Baza_Reklam.Classes.Model.Enums;
@@ -11,5 +12,5 @@
         private string _type;
         private string _shortName;
-        private DateTime _startDate;
+        private DateTime? _startDate;
         private decimal _price;
         private decimal _totalPrice;
@@ -19,4 +20,5 @@
         private int? _orderId;
         private bool _hasInvoice;
+        private List<IProductDetail> _productDetails = new List<IProductDetail>();
 
         public int Id
@@ -44,5 +46,5 @@
         }
 
-        public DateTime StartDate
+        public DateTime? StartDate
         {
             get { return _startDate; }
@@ -91,4 +93,15 @@
             set { _hasInvoice = value; }
         }
+
+        public List<IProductDetail> ProductDetails
+        {
+            get { return _productDetails; }
+        }
+
+        public void AddProductDetail(IProductDetail productDetail)
+        {
+            productDetail.ProductId = _id;
+            _productDetails.Add(productDetail);
+        }
     }
 }
Index: branches/Abonament/BazaReklam/Classes/Model/Enums/ProductType.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Model/Enums/ProductType.cs (revision 704)
+++ branches/Abonament/BazaReklam/Classes/Model/Enums/ProductType.cs (revision 705)
@@ -3,6 +3,6 @@
     public enum ProductType
     {
-        Advertisment = 1,
-        Subscription = 2
+        Subscription = 1,
+        Advertisment = 2,
     }
 }
Index: branches/Abonament/BazaReklam/Classes/Model/Enums/InvoicingType.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Model/Enums/InvoicingType.cs (revision 705)
+++ branches/Abonament/BazaReklam/Classes/Model/Enums/InvoicingType.cs (revision 705)
@@ -0,0 +1,9 @@
+namespace Baza_Reklam.Classes.Model.Enums
+{
+    public enum InvoicingType
+    {
+        OneMonth = 1,
+        ThreeMonths = 2,
+        All = 3
+    }
+}
Index: branches/Abonament/BazaReklam/Classes/Model/ProductDetail.cs
===================================================================
--- branches/Abonament/BazaReklam/Classes/Model/ProductDetail.cs (revision 705)
+++ branches/Abonament/BazaReklam/Classes/Model/ProductDetail.cs (revision 705)
@@ -0,0 +1,64 @@
+using Baza_Reklam.Classes.Interfaces;
+
+namespace Baza_Reklam.Classes.Model
+{
+    public class ProductDetail : IProductDetail
+    {
+        private int _id;
+        private int _productId;
+        private decimal _price;
+        private decimal _pricePln;
+        private decimal _vat;
+        private int? _invoiceId;
+        private int _year;
+        private int _month;
+
+        public int Id
+        {
+            get { return _id; }
+            set { _id = value; }
+        }
+
+        public int ProductId
+        {
+            get { return _productId; }
+            set { _productId = value; }
+        }
+
+        public decimal Price
+        {
+            get { return _price; }
+            set { _price = value; }
+        }
+
+        public decimal PricePln
+        {
+            get { return _pricePln; }
+            set { _pricePln = value; }
+        }
+
+        public decimal Vat
+        {
+            get { return _vat; }
+            set { _vat = value; }
+        }
+
+        public int? InvoiceId
+        {
+            get { return _invoiceId; }
+            set { _invoiceId = value; }
+        }
+
+        public int Year
+        {
+            get { return _year; }
+            set { _year = value; }
+        }
+
+        public int Month
+        {
+            get { return _month; }
+            set { _month = value; }
+        }
+    }
+}
Index: branches/Abonament/BazaReklam/ClientsForm.cs
===================================================================
--- branches/Abonament/BazaReklam/ClientsForm.cs (revision 703)
+++ branches/Abonament/BazaReklam/ClientsForm.cs (revision 705)
@@ -2307,12 +2307,20 @@
         private void toolStripButton1_Click(object sender, EventArgs e)
         {
-            if (kLIENCIBindingSource.Current != null)
-            {
+            if (kLIENCIBindingSource.Current == null) return;
+            
+            try
+            {
+                Cursor = Cursors.WaitCursor;
                 DataRowView row = (DataRowView)kLIENCIBindingSource.Current;
                 REKLAMADataSet.KLIENCIRow klient = (REKLAMADataSet.KLIENCIRow)row.Row;
 
                 ZamowieniaForm zam = new ZamowieniaForm(klient);
-                zam.ShowDialog();
-            }
+                zam.ShowDialog();                
+            }
+            finally
+            {
+                Cursor = Cursors.Default;
+            }
+
         }
 
