| 1 | using System;
|
|---|
| 2 | using System.Data.SqlClient;
|
|---|
| 3 | using System.Text.RegularExpressions;
|
|---|
| 4 |
|
|---|
| 5 | namespace ExportFaktur
|
|---|
| 6 | {
|
|---|
| 7 | class ExpoToCDNExport
|
|---|
| 8 | {
|
|---|
| 9 |
|
|---|
| 10 | #region Fields (3)
|
|---|
| 11 |
|
|---|
| 12 | public CDNDataSet CDNDataset;
|
|---|
| 13 | readonly SqlConnection CDN_conn = new SqlConnection(ConnString.CDNConnection);
|
|---|
| 14 |
|
|---|
| 15 | #endregion Fields
|
|---|
| 16 |
|
|---|
| 17 | #region Methods (10)
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | // Public Methods (10)
|
|---|
| 21 |
|
|---|
| 22 | public void DodajElementyFaktury(EXPODataSet.FAKTURA_DETAILSDataTable table, CDNDataSet.TraNagRow naglowekFaktury)
|
|---|
| 23 | {
|
|---|
| 24 | int lp = 1;
|
|---|
| 25 |
|
|---|
| 26 | CDNDataSet.TraNagRow naglowek = naglowekFaktury;
|
|---|
| 27 |
|
|---|
| 28 | foreach (EXPODataSet.FAKTURA_DETAILSRow row in table.Rows)
|
|---|
| 29 | {
|
|---|
| 30 | CDNDataSet.TraElemRow pozycjaFaktury = (CDNDataSet.TraElemRow)CDNDataset.TraElem.NewRow();
|
|---|
| 31 |
|
|---|
| 32 | pozycjaFaktury.TrE_TrNId = naglowek.TrN_TrNID;
|
|---|
| 33 | // pozycjaFaktury.tre_tran
|
|---|
| 34 | if (istniejeKorekta())
|
|---|
| 35 | {
|
|---|
| 36 | pozycjaFaktury.TrE_ZwrId = 0;
|
|---|
| 37 | }
|
|---|
| 38 | pozycjaFaktury.TrE_Lp = lp;
|
|---|
| 39 | pozycjaFaktury.TrE_TypDokumentu = 302;
|
|---|
| 40 | pozycjaFaktury.TrE_Aktywny = 1;
|
|---|
| 41 | pozycjaFaktury.TrE_DataDok = naglowek.TrN_DataDok;
|
|---|
| 42 | pozycjaFaktury.TrE_DataOpe = naglowek.TrN_DataOpe;
|
|---|
| 43 | pozycjaFaktury.TrE_PodmiotTyp = 1;
|
|---|
| 44 | pozycjaFaktury.TrE_PodID = naglowek.TrN_PodID;
|
|---|
| 45 |
|
|---|
| 46 | if ((row.ROK > naglowekFaktury.TrN_DataDok.Year) ||
|
|---|
| 47 | ((row.ROK == naglowekFaktury.TrN_DataDok.Year) && (row.MIESIAC > naglowekFaktury.TrN_DataDok.Month)))
|
|---|
| 48 | {
|
|---|
| 49 | pozycjaFaktury.TrE_KatID = podajIDKategorii(row.ROK, row.MIESIAC);
|
|---|
| 50 | }
|
|---|
| 51 | else
|
|---|
| 52 | {
|
|---|
| 53 | pozycjaFaktury.TrE_KatID = naglowek.TrN_KatID;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | pozycjaFaktury.TrE_TwrId = 1;
|
|---|
| 57 | pozycjaFaktury.TrE_TwrNazwa = row.NAZWA_USLUGI + " " + row.MIESIAC + "/" + row.ROK;
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | pozycjaFaktury.TrE_TwrOpis = "";
|
|---|
| 61 | pozycjaFaktury.TrE_TwrSWW = "";
|
|---|
| 62 | pozycjaFaktury.TrE_Stawka = (decimal)row.S_VAT * 100; //svat' @P14 numeric(5,2) 22.00
|
|---|
| 63 | pozycjaFaktury.TrE_Flaga = 2;
|
|---|
| 64 | pozycjaFaktury.TrE_Zrodlowa = 0.00M;
|
|---|
| 65 | pozycjaFaktury.TrE_TwCNumer = 2;
|
|---|
| 66 | pozycjaFaktury.TrE_TypNB = 1;
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | pozycjaFaktury.TrE_CenaT = row.NETTO; //Math.Abs(rsdet("netto"));
|
|---|
| 70 | // pozycjaFaktury.TrE_CenaT = row.CENA_JEDN; //Math.Abs(rsdet("netto"));
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | pozycjaFaktury.TrE_Cena0 = row.NETTO; //Math.Abs(netto);
|
|---|
| 74 | //pozycjaFaktury.TrE_Cena0 = row.CENA_JEDN; //Math.Abs(netto);
|
|---|
| 75 | pozycjaFaktury.TrE_Rabat = (decimal)row.UPUST_PR * 100;
|
|---|
| 76 | // pozycjaFaktury.TrE_Rabat = 0;
|
|---|
| 77 | pozycjaFaktury.TrE_CenaW = row.NETTO; //Math.Abs(netto);
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | /*
|
|---|
| 81 | * if rsdet("netto")<0 then
|
|---|
| 82 | pozycjaFaktury.TrE_Ilosc")=-1.0000' @P27 numeric(15,4) 1.0000
|
|---|
| 83 | else
|
|---|
| 84 | pozycjaFaktury.TrE_Ilosc=1.0000' @P27 numeric(15,4) 1.0000
|
|---|
| 85 | end if */
|
|---|
| 86 | pozycjaFaktury.TrE_Ilosc = 1M;
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | pozycjaFaktury.TrE_Jm = "szt.";
|
|---|
| 90 | pozycjaFaktury.TrE_JmCalkowite = 0;
|
|---|
| 91 | pozycjaFaktury.TrE_JMPrzelicznikL = 1.00M;
|
|---|
| 92 | pozycjaFaktury.TrE_JMPrzelicznikM = 1;
|
|---|
| 93 | pozycjaFaktury.TrE_IloscJM = pozycjaFaktury.TrE_Ilosc;
|
|---|
| 94 | pozycjaFaktury.TrE_WartoscNetto = row.NETTO; //rsdet("netto")' @P33 numeric(15,2) 1000.00
|
|---|
| 95 | pozycjaFaktury.TrE_WartoscBrutto = row.BRUTTO; //rsdet("brutto")' @P34 numeric(15,2) 1220.00
|
|---|
| 96 | pozycjaFaktury.TrE_TwrEAN = "";
|
|---|
| 97 | pozycjaFaktury.TrE_TwrNumerKat = "";
|
|---|
| 98 | pozycjaFaktury.TrE_TwrKod = "REKLAMA PRASOWA"; //towarkod' @P37 varchar(3) '125'
|
|---|
| 99 | pozycjaFaktury.TrE_JmZ = "";
|
|---|
| 100 | pozycjaFaktury.TrE_LpPow = lp;
|
|---|
| 101 | pozycjaFaktury.TrE_Cena0WD = row.CENA_JEDN; //abs(rsdet("netto"))' @P40 numeric(15,2) 1000.00
|
|---|
| 102 | pozycjaFaktury.TrE_CenaWWD = row.NETTO;//abs(rsdet("netto"))' @P41 numeric(15,2) 1000.00
|
|---|
| 103 | pozycjaFaktury.TrE_WartoscNettoWal = row.NETTO; //rsdet("netto")' @P42 numeric(15,2) 1000.00
|
|---|
| 104 | pozycjaFaktury.TrE_WartoscBruttoWal = row.BRUTTO; //rsdet("brutto")' @P43 numeric(15,2) 1220.00
|
|---|
| 105 | pozycjaFaktury.TrE_Prog = 0.00M;
|
|---|
| 106 | pozycjaFaktury.TrE_UpustTyp = 0;
|
|---|
| 107 | pozycjaFaktury.TrE_Upust = 0.00M;
|
|---|
| 108 | pozycjaFaktury.TrE_UpustKnt = 0.00M;
|
|---|
| 109 | pozycjaFaktury.TrE_UpustKntTyp = 0;
|
|---|
| 110 | pozycjaFaktury.TrE_KosztUslugi = 0.00M;
|
|---|
| 111 | pozycjaFaktury.TrE_RabatPromocyjny = 0.0000M;
|
|---|
| 112 | pozycjaFaktury.TrE_RabatKorekta = 0.0000M;
|
|---|
| 113 | pozycjaFaktury.TrE_Kaucja = 0;
|
|---|
| 114 | pozycjaFaktury.TrE_IloscKW = 0.0000M;
|
|---|
| 115 | pozycjaFaktury.TrE_IloscJMKW = 0.0000M;
|
|---|
| 116 | pozycjaFaktury.TrE_MagId = 1;
|
|---|
| 117 |
|
|---|
| 118 | // ?????????????????????????????
|
|---|
| 119 | // pozycjaFaktury.TrE_Atr1_DeAId = DBNull.Value;
|
|---|
| 120 | pozycjaFaktury.TrE_Atr1_Kod = "";
|
|---|
| 121 | pozycjaFaktury.TrE_Atr1_Wartosc = "";
|
|---|
| 122 | // pozycjaFaktury.TrE_Atr2_DeAId = DBNull.Value;
|
|---|
| 123 | pozycjaFaktury.TrE_Atr2_Kod = "";
|
|---|
| 124 | pozycjaFaktury.TrE_Atr2_Wartosc = "";
|
|---|
| 125 | // pozycjaFaktury.TrE_Atr3_DeAId = DBNull.Value;
|
|---|
| 126 | pozycjaFaktury.TrE_Atr3_Kod = "";
|
|---|
| 127 | pozycjaFaktury.TrE_Atr3_Wartosc = "";
|
|---|
| 128 | // pozycjaFaktury.TrE_Atr4_DeAId = DBNull.Value;
|
|---|
| 129 | pozycjaFaktury.TrE_Atr4_Kod = "";
|
|---|
| 130 | pozycjaFaktury.TrE_Atr4_Wartosc = "";
|
|---|
| 131 | // pozycjaFaktury.TrE_Atr5_DeAId = DBNull.Value;
|
|---|
| 132 | pozycjaFaktury.TrE_Atr5_Kod = "";
|
|---|
| 133 | pozycjaFaktury.TrE_Atr5_Wartosc = "";
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | pozycjaFaktury.TrE_WartoscZakupuWylicz = 0;
|
|---|
| 137 | //'pozycjaFaktury.TrE_WartoscZakupu=0
|
|---|
| 138 |
|
|---|
| 139 | pozycjaFaktury.TrE_Waluta = "PLN";
|
|---|
| 140 | pozycjaFaktury.TrE_KursNumer = 2;
|
|---|
| 141 | pozycjaFaktury.TrE_KursL = 1.000M;
|
|---|
| 142 | pozycjaFaktury.TrE_KursM = 1;
|
|---|
| 143 |
|
|---|
| 144 | if (naglowek.TrN_Export == 7)
|
|---|
| 145 | {
|
|---|
| 146 | pozycjaFaktury.TrE_Flaga = 4;
|
|---|
| 147 | pozycjaFaktury.TrE_Cena0WD = row.CENA_JEDN / naglowek.TrN_KursL;
|
|---|
| 148 | pozycjaFaktury.TrE_CenaWWD = row.NETTO / naglowek.TrN_KursL;
|
|---|
| 149 | pozycjaFaktury.TrE_WartoscBruttoWal = row.BRUTTO / naglowek.TrN_KursL;
|
|---|
| 150 | pozycjaFaktury.TrE_WartoscNettoWal = row.NETTO / naglowek.TrN_KursL;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | CDNDataset.TraElem.AddTraElemRow(pozycjaFaktury);
|
|---|
| 154 |
|
|---|
| 155 | lp++;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | public void DodajKlienta(EXPODataSet.KLIENCIRow klient)
|
|---|
| 162 | {
|
|---|
| 163 | CDNDataSetTableAdapters.KontrahenciTableAdapter adapter = new CDNDataSetTableAdapters.KontrahenciTableAdapter();
|
|---|
| 164 | adapter.Connection = CDN_conn;
|
|---|
| 165 |
|
|---|
| 166 | adapter.FillByKnt_Kod(CDNDataset.Kontrahenci, klient.CustomerID.ToString());
|
|---|
| 167 |
|
|---|
| 168 | bool klientIstnieje;
|
|---|
| 169 | CDNDataSet.KontrahenciRow kontrahent;
|
|---|
| 170 |
|
|---|
| 171 | if (CDNDataset.Kontrahenci.Count == 0)
|
|---|
| 172 | {
|
|---|
| 173 | klientIstnieje = false;
|
|---|
| 174 | kontrahent = (CDNDataSet.KontrahenciRow)CDNDataset.Kontrahenci.NewRow();
|
|---|
| 175 | }
|
|---|
| 176 | else
|
|---|
| 177 | {
|
|---|
| 178 | klientIstnieje = true;
|
|---|
| 179 | kontrahent = CDNDataset.Kontrahenci[0];
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | kontrahent.Knt_ZgodaNaEFaktury = 0;
|
|---|
| 183 | kontrahent.Knt_PodmiotTyp = 1;
|
|---|
| 184 | kontrahent.Knt_Kod = klient.CustomerID.ToString();
|
|---|
| 185 | kontrahent.Knt_GLN = "";
|
|---|
| 186 | kontrahent.Knt_EAN = "";
|
|---|
| 187 | kontrahent.Knt_Grupa = "ODBIORCA";
|
|---|
| 188 | kontrahent.Knt_Nazwa1 = klient.IsFirstNameNull() ? "" : klient.FirstName;
|
|---|
| 189 | kontrahent.Knt_Nazwa2 = klient.IsLastNameNull() ? "" : klient.LastName;
|
|---|
| 190 | kontrahent.Knt_Nazwa3 = klient.IsOrganizationNameNull() ? "" : klient.OrganizationName;
|
|---|
| 191 |
|
|---|
| 192 | string kraj = "";
|
|---|
| 193 | if (!klient.IsCountryNull())
|
|---|
| 194 | {
|
|---|
| 195 | kraj = (klient.Country.Length > 40) ? klient.Country.Substring(0, 40) : klient.Country;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | kontrahent.Knt_Kraj = kraj;
|
|---|
| 199 |
|
|---|
| 200 | string wojewodztwo = "";
|
|---|
| 201 | if (!klient.IsStateNull())
|
|---|
| 202 | {
|
|---|
| 203 | wojewodztwo = (klient.State.Length > 40) ? klient.State.Substring(0, 40) : klient.State;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | kontrahent.Knt_Wojewodztwo = wojewodztwo;
|
|---|
| 207 |
|
|---|
| 208 | kontrahent.Knt_Powiat = "";
|
|---|
| 209 | kontrahent.Knt_Gmina = "";
|
|---|
| 210 |
|
|---|
| 211 | string adres = "";
|
|---|
| 212 | if (!klient.IsAddressNull())
|
|---|
| 213 | {
|
|---|
| 214 | adres = (klient.Address.Length > 40) ? klient.Address.Substring(0, 40) : klient.Address;
|
|---|
| 215 | }
|
|---|
| 216 | kontrahent.Knt_Ulica = adres;
|
|---|
| 217 |
|
|---|
| 218 | kontrahent.Knt_NrDomu = "";
|
|---|
| 219 | kontrahent.Knt_NrLokalu = "";
|
|---|
| 220 |
|
|---|
| 221 | string miasto = "";
|
|---|
| 222 | if (!klient.IsCityNull())
|
|---|
| 223 | {
|
|---|
| 224 | miasto = (klient.City.Length > 40) ? klient.City.Substring(0, 40) : klient.City;
|
|---|
| 225 | }
|
|---|
| 226 | kontrahent.Knt_Miasto = miasto;
|
|---|
| 227 | kontrahent.Knt_Poczta = miasto;
|
|---|
| 228 |
|
|---|
| 229 | string kodPocztowy = "";
|
|---|
| 230 | if (!klient.IsPostalCodeNull())
|
|---|
| 231 | {
|
|---|
| 232 | kodPocztowy = (klient.PostalCode.Length > 10) ? klient.PostalCode.Substring(0, 10) : klient.PostalCode;
|
|---|
| 233 | }
|
|---|
| 234 | kontrahent.Knt_KodPocztowy = kodPocztowy;
|
|---|
| 235 |
|
|---|
| 236 | kontrahent.Knt_Adres2 = "";
|
|---|
| 237 |
|
|---|
| 238 | if (!klient.IsNipNull())
|
|---|
| 239 | {
|
|---|
| 240 | // kontrahent.Knt_NipKraj = PodajKrajNIP(klient.Nip);
|
|---|
| 241 | // kontrahent.Knt_NipE = PodajNumerNIP(klient.Nip);
|
|---|
| 242 | // kontrahent.Knt_Nip = PodajNumerNIP(klient.Nip);
|
|---|
| 243 | if (klient.nipKraj == "" && klient.Country.Trim() == "Polska")
|
|---|
| 244 | {
|
|---|
| 245 | kontrahent.Knt_NipKraj = "PL";
|
|---|
| 246 | kontrahent.Knt_KrajISO = "PL";
|
|---|
| 247 | }
|
|---|
| 248 | else
|
|---|
| 249 | {
|
|---|
| 250 | kontrahent.Knt_NipKraj = klient.nipKraj.Length > 2 ? klient.nipKraj.Substring(0, 2) : klient.nipKraj;
|
|---|
| 251 | kontrahent.Knt_KrajISO = klient.nipKraj.Length > 2 ? klient.nipKraj.Substring(0, 2) : klient.nipKraj;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | kontrahent.Knt_NipE = klient.Nip.Length > 13 ? klient.Nip.Substring(0, 13) : klient.Nip;
|
|---|
| 255 | kontrahent.Knt_Nip = klient.Nip.Length > 13 ? klient.Nip.Substring(0, 13) : klient.Nip;
|
|---|
| 256 |
|
|---|
| 257 | }
|
|---|
| 258 | else
|
|---|
| 259 | {
|
|---|
| 260 | kontrahent.Knt_NipKraj = "";
|
|---|
| 261 | kontrahent.Knt_NipE = "";
|
|---|
| 262 | kontrahent.Knt_Nip = "";
|
|---|
| 263 | kontrahent.Knt_KrajISO = "";
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | kontrahent.Knt_Regon = "";
|
|---|
| 267 | kontrahent.Knt_Pesel = "";
|
|---|
| 268 | kontrahent.Knt_Telefon1 = "";
|
|---|
| 269 | kontrahent.Knt_Telefon2 = "";
|
|---|
| 270 | kontrahent.Knt_Fax = "";
|
|---|
| 271 |
|
|---|
| 272 | string email = "";
|
|---|
| 273 | if (!klient.IsEmailNull())
|
|---|
| 274 | {
|
|---|
| 275 | email = (klient.Email.Length > 40) ? klient.Email.Substring(0, 40) : klient.Email;
|
|---|
| 276 | }
|
|---|
| 277 | kontrahent.Knt_Email = email;
|
|---|
| 278 |
|
|---|
| 279 | kontrahent.Knt_URL = "";
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 | if (!klientIstnieje)
|
|---|
| 283 | {
|
|---|
| 284 | kontrahent.Knt_Zezwolenie = "";
|
|---|
| 285 | kontrahent.Knt_KodTransakcji = "";
|
|---|
| 286 | //kontrahent.Knt_BNaID=""
|
|---|
| 287 | kontrahent.Knt_RachunekNr = "";
|
|---|
| 288 | kontrahent.Knt_IBAN = 0;
|
|---|
| 289 | //kontrahent.Knt_RachunekNr0=""
|
|---|
| 290 | kontrahent.Knt_OsTytul = "";
|
|---|
| 291 | kontrahent.Knt_OsPlec = 1;
|
|---|
| 292 | kontrahent.Knt_OsNazwisko = "";
|
|---|
| 293 | kontrahent.Knt_OsKraj = kontrahent.Knt_Kraj;
|
|---|
| 294 | kontrahent.Knt_OsWojewodztwo = kontrahent.Knt_Wojewodztwo;
|
|---|
| 295 | kontrahent.Knt_OsPowiat = "";
|
|---|
| 296 | kontrahent.Knt_OsGmina = "";
|
|---|
| 297 | kontrahent.Knt_OsUlica = "";
|
|---|
| 298 | kontrahent.Knt_OsNrDomu = "";
|
|---|
| 299 | kontrahent.Knt_OsNrLokalu = "";
|
|---|
| 300 | kontrahent.Knt_OsMiasto = "";
|
|---|
| 301 | kontrahent.Knt_OsKodPocztowy = "";
|
|---|
| 302 | kontrahent.Knt_OsPoczta = "";
|
|---|
| 303 | kontrahent.Knt_OsAdres2 = "";
|
|---|
| 304 | kontrahent.Knt_OsTelefon = "";
|
|---|
| 305 | kontrahent.Knt_OsGSM = "";
|
|---|
| 306 | kontrahent.Knt_OsEmail = "";
|
|---|
| 307 | kontrahent.Knt_Informacje = 0;
|
|---|
| 308 | kontrahent.Knt_Upust = 0;
|
|---|
| 309 | kontrahent.Knt_LimitFlag = 0;
|
|---|
| 310 | kontrahent.Knt_LimitKredytu = 0;
|
|---|
| 311 | kontrahent.Knt_LimitPrzeterKredytFlag = 0;
|
|---|
| 312 | kontrahent.Knt_LimitPrzeterKredytWartosc = 0;
|
|---|
| 313 | kontrahent.Knt_Ceny = 0;
|
|---|
| 314 | kontrahent.Knt_FplID = 1;
|
|---|
| 315 | kontrahent.Knt_MaxZwloka = 7;
|
|---|
| 316 | kontrahent.Knt_TerminPlat = 1;
|
|---|
| 317 | kontrahent.Knt_Termin = 7;
|
|---|
| 318 | kontrahent.Knt_KontoOdb = "";
|
|---|
| 319 | kontrahent.Knt_KontoDost = "";
|
|---|
| 320 | //kontrahent.Knt_KatID=
|
|---|
| 321 | kontrahent.Knt_BlokadaDok = 0;
|
|---|
| 322 | kontrahent.Knt_LimitKredytuWal = "";
|
|---|
| 323 | kontrahent.Knt_LimitKredytuWykorzystany = 0;
|
|---|
| 324 | kontrahent.Knt_NieRozliczac = 0;
|
|---|
| 325 | kontrahent.Knt_PodatekVat = 1;
|
|---|
| 326 | kontrahent.Knt_Finalny = 0;
|
|---|
| 327 | kontrahent.Knt_Export = 0;
|
|---|
| 328 |
|
|---|
| 329 | if (kontrahent.Knt_NipKraj != "PL")
|
|---|
| 330 | {
|
|---|
| 331 | kontrahent.Knt_Export = 7;
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | kontrahent.Knt_Rodzaj = 0;
|
|---|
| 335 | kontrahent.Knt_Rodzaj_Dostawca = 0;
|
|---|
| 336 | kontrahent.Knt_Rodzaj_Odbiorca = 1;
|
|---|
| 337 | kontrahent.Knt_Rodzaj_Konkurencja = 0;
|
|---|
| 338 | kontrahent.Knt_Rodzaj_Partner = 0;
|
|---|
| 339 | kontrahent.Knt_Rodzaj_Potencjalny = 0;
|
|---|
| 340 | kontrahent.Knt_Medialny = 0;
|
|---|
| 341 | kontrahent.Knt_MalyPod = 0;
|
|---|
| 342 | kontrahent.Knt_Rolnik = 0;
|
|---|
| 343 | kontrahent.Knt_Nieaktywny = 0;
|
|---|
| 344 | kontrahent.Knt_Chroniony = 0;
|
|---|
| 345 | kontrahent.Knt_Opis = "";
|
|---|
| 346 | //kontrahent.Knt_OdbiorcaId=
|
|---|
| 347 | //kontrahent.Knt_OpiekunTyp=
|
|---|
| 348 | //kontrahent.Knt_OpiekunId=
|
|---|
| 349 | kontrahent.Knt_TerminZwrotuKaucji = 60;
|
|---|
| 350 | kontrahent.Knt_NaliczajPlatnosc = 0;
|
|---|
| 351 | kontrahent.Knt_ZakazDokumentowHaMag = 0;
|
|---|
| 352 | //'kontrahent.Knt_TS_Export=
|
|---|
| 353 | //'kontrahent.Knt_ImportAppId=
|
|---|
| 354 | //'kontrahent.Knt_ImportRowId=
|
|---|
| 355 | kontrahent.Knt_OpeZalID = 11;
|
|---|
| 356 | kontrahent.Knt_StaZalId = 6;
|
|---|
| 357 | kontrahent.Knt_TS_Zal = DateTime.Now;
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | kontrahent.Knt_OpeModID = 11;
|
|---|
| 361 | kontrahent.Knt_StaModId = 6;
|
|---|
| 362 | kontrahent.Knt_TS_Mod = DateTime.Now;
|
|---|
| 363 | //kontrahent.Knt_GIDTyp=
|
|---|
| 364 | //kontrahent.Knt_GIDFirma=
|
|---|
| 365 | //kontrahent.Knt_GIDNumer=
|
|---|
| 366 | //kontrahent.Knt_GIDLp=
|
|---|
| 367 |
|
|---|
| 368 | if (!klientIstnieje)
|
|---|
| 369 | {
|
|---|
| 370 | CDNDataset.Kontrahenci.AddKontrahenciRow(kontrahent);
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | public void DodajNaglowekFaktury(EXPODataSet.FAKTURYRow EXPOfaktura, CDNDataSet.KontrahenciRow kontrahent, decimal sumaNETTO, decimal VAT, decimal rabatProcent)
|
|---|
| 376 | {
|
|---|
| 377 |
|
|---|
| 378 | CDNDataSet.TraNagRow nowaFaktura = (CDNDataSet.TraNagRow)CDNDataset.TraNag.NewRow();
|
|---|
| 379 |
|
|---|
| 380 | //!!!!!!!!!!!!!!!
|
|---|
| 381 | //nowaFaktura.TrN_DDfId = 1;
|
|---|
| 382 |
|
|---|
| 383 | CDNDataSetTableAdapters.DokDefinicjeTableAdapter adapter = new CDNDataSetTableAdapters.DokDefinicjeTableAdapter();
|
|---|
| 384 | adapter.Connection = CDN_conn;
|
|---|
| 385 |
|
|---|
| 386 | CDNDataSet.DokDefinicjeRow dokDef = adapter.GetDataByNumerRozHandlowca(EXPOfaktura.NUMER_ROZ)[0];
|
|---|
| 387 |
|
|---|
| 388 | nowaFaktura.TrN_DDfId = dokDef.DDf_DDfID;
|
|---|
| 389 | nowaFaktura.TrN_TypDokumentu = 302;
|
|---|
| 390 |
|
|---|
| 391 | nowaFaktura.TrN_NumerNr = EXPOfaktura.NUMER;
|
|---|
| 392 | nowaFaktura.TrN_NumerString = "@numerS" + "/" + EXPOfaktura.NUMER_ROZ + "/" + EXPOfaktura.NUMER_ROK; //numerstring' @P4 varchar(13) '@numer/O/2007'
|
|---|
| 393 |
|
|---|
| 394 | // 'rsnag("TrN_NumerPelny=numerpelny
|
|---|
| 395 | nowaFaktura.TrN_Bufor = 1;
|
|---|
| 396 | nowaFaktura.TrN_DataDok = EXPOfaktura.DATA_WYSTAWIENIA;
|
|---|
| 397 | nowaFaktura.TrN_DataWys = EXPOfaktura.DATA_WYSTAWIENIA;
|
|---|
| 398 | nowaFaktura.TrN_DataOpe = EXPOfaktura.DATA_SPRZEDAZY;
|
|---|
| 399 | nowaFaktura.TrN_NumerObcy = "";
|
|---|
| 400 | nowaFaktura.TrN_DataKur = DateTime.Now;
|
|---|
| 401 | if (istniejeKorekta())
|
|---|
| 402 | {
|
|---|
| 403 | nowaFaktura.TrN_Korekta = 1;
|
|---|
| 404 | nowaFaktura.TrN_Rodzaj = 302001;
|
|---|
| 405 | const int idkorekty = 0;
|
|---|
| 406 | nowaFaktura.TrN_ZwrId = idkorekty;
|
|---|
| 407 | }
|
|---|
| 408 | else
|
|---|
| 409 | {
|
|---|
| 410 | nowaFaktura.TrN_Korekta = 0;
|
|---|
| 411 | nowaFaktura.TrN_Rodzaj = 302000;
|
|---|
| 412 | }
|
|---|
| 413 | nowaFaktura.TrN_Fiskalna = 0;
|
|---|
| 414 | nowaFaktura.TrN_Detal = 0;
|
|---|
| 415 | nowaFaktura.TrN_PodmiotTyp = 1;
|
|---|
| 416 | nowaFaktura.TrN_PodID = kontrahent.Knt_KntId;
|
|---|
| 417 |
|
|---|
| 418 | nowaFaktura.TrN_PodNazwa1 = kontrahent.Knt_Nazwa1;
|
|---|
| 419 | nowaFaktura.TrN_PodNazwa2 = kontrahent.Knt_Nazwa2;
|
|---|
| 420 | nowaFaktura.TrN_PodNazwa3 = kontrahent.Knt_Nazwa3;
|
|---|
| 421 |
|
|---|
| 422 | /*
|
|---|
| 423 | if (kontrahent.Knt_Kraj){
|
|---|
| 424 | nowaFaktura.TrN_PodKraj="Polska";
|
|---|
| 425 | }
|
|---|
| 426 | else {
|
|---|
| 427 | nowaFaktura.TrN_PodKraj=kontrahent.Knt_Kraj;
|
|---|
| 428 | }*/
|
|---|
| 429 |
|
|---|
| 430 | nowaFaktura.TrN_PodKraj = kontrahent.Knt_Kraj;
|
|---|
| 431 |
|
|---|
| 432 | nowaFaktura.TrN_PodWojewodztwo = kontrahent.Knt_Wojewodztwo;
|
|---|
| 433 | nowaFaktura.TrN_PodPowiat = "";
|
|---|
| 434 | nowaFaktura.TrN_PodGmina = "";
|
|---|
| 435 | nowaFaktura.TrN_PodUlica = kontrahent.Knt_Ulica;
|
|---|
| 436 | nowaFaktura.TrN_PodNrDomu = kontrahent.Knt_NrDomu;
|
|---|
| 437 | nowaFaktura.TrN_PodNrLokalu = kontrahent.Knt_NrLokalu;
|
|---|
| 438 | nowaFaktura.TrN_PodMiasto = kontrahent.Knt_Miasto;
|
|---|
| 439 | nowaFaktura.TrN_PodKodPocztowy = kontrahent.Knt_KodPocztowy;
|
|---|
| 440 | nowaFaktura.TrN_PodPoczta = kontrahent.Knt_Poczta;
|
|---|
| 441 | nowaFaktura.TrN_PodAdres2 = "";
|
|---|
| 442 | nowaFaktura.TrN_PodNipKraj = kontrahent.Knt_NipKraj;
|
|---|
| 443 | nowaFaktura.TrN_PodNipE = kontrahent.Knt_NipE;
|
|---|
| 444 | nowaFaktura.TrN_Finalny = 0;
|
|---|
| 445 | nowaFaktura.TrN_Export = 0;
|
|---|
| 446 | nowaFaktura.TrN_OdbiorcaTyp = 1;
|
|---|
| 447 |
|
|---|
| 448 | //ustawione w dataset
|
|---|
| 449 | nowaFaktura.TrN_OdbID = kontrahent.Knt_KntId;
|
|---|
| 450 | nowaFaktura.TrN_OdbNazwa1 = kontrahent.Knt_Nazwa1;
|
|---|
| 451 | nowaFaktura.TrN_OdbNazwa2 = kontrahent.Knt_Nazwa2;
|
|---|
| 452 | nowaFaktura.TrN_OdbNazwa3 = kontrahent.Knt_Nazwa3;
|
|---|
| 453 |
|
|---|
| 454 | nowaFaktura.TrN_OdbKraj = kontrahent.Knt_Kraj;
|
|---|
| 455 |
|
|---|
| 456 | nowaFaktura.TrN_OdbWojewodztwo = kontrahent.Knt_Wojewodztwo;
|
|---|
| 457 | nowaFaktura.TrN_OdbPowiat = "";
|
|---|
| 458 | nowaFaktura.TrN_OdbGmina = "";
|
|---|
| 459 | nowaFaktura.TrN_OdbUlica = kontrahent.Knt_Ulica;
|
|---|
| 460 | nowaFaktura.TrN_OdbNrDomu = kontrahent.Knt_NrDomu;
|
|---|
| 461 | nowaFaktura.TrN_OdbNrLokalu = kontrahent.Knt_NrLokalu;
|
|---|
| 462 | nowaFaktura.TrN_OdbMiasto = kontrahent.Knt_Miasto;
|
|---|
| 463 | nowaFaktura.TrN_OdbKodPocztowy = kontrahent.Knt_KodPocztowy;
|
|---|
| 464 | nowaFaktura.TrN_OdbPoczta = kontrahent.Knt_Poczta;
|
|---|
| 465 | nowaFaktura.TrN_OdbAdres2 = "";
|
|---|
| 466 | nowaFaktura.TrN_OdbNipKraj = kontrahent.Knt_NipKraj;
|
|---|
| 467 | nowaFaktura.TrN_OdbNipE = kontrahent.Knt_NipE;
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 | //w zaleznosci od handlowca
|
|---|
| 471 | /*
|
|---|
| 472 | nowaFaktura.TrN_KatID = 42;
|
|---|
| 473 | nowaFaktura.TrN_Kategoria = "Dorota";
|
|---|
| 474 | */
|
|---|
| 475 | nowaFaktura.TrN_KatID = 1;
|
|---|
| 476 | nowaFaktura.TrN_Kategoria = "SPRZEDA¯";
|
|---|
| 477 |
|
|---|
| 478 | nowaFaktura.TrN_FPlId = 3;
|
|---|
| 479 | nowaFaktura.TrN_Termin = EXPOfaktura.TERMIN_ZAPLATY;
|
|---|
| 480 |
|
|---|
| 481 | //NETT, VAT itp.
|
|---|
| 482 | nowaFaktura.TrN_RazemNetto = sumaNETTO;
|
|---|
| 483 | nowaFaktura.TrN_RazemVAT = VAT * sumaNETTO;
|
|---|
| 484 | nowaFaktura.TrN_RazemBrutto = (1 + VAT) * nowaFaktura.TrN_RazemNetto;
|
|---|
| 485 | nowaFaktura.TrN_BlokadaPlatnosci = 0;
|
|---|
| 486 | nowaFaktura.TrN_MagZrdId = 1;
|
|---|
| 487 | nowaFaktura.TrN_TypNB = 1;
|
|---|
| 488 | nowaFaktura.TrN_Rabat = rabatProcent * 100;
|
|---|
| 489 | //nowaFaktura.TrN_Rabat = 0;
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 | nowaFaktura.TrN_Odebral = EXPOfaktura.IsPODPIS_ODEBRALNull() ? "zgodnie z owiadczeniem nabywcy" : EXPOfaktura.PODPIS_ODEBRAL;
|
|---|
| 493 |
|
|---|
| 494 | nowaFaktura.TrN_Opis = EXPOfaktura.opis;
|
|---|
| 495 | nowaFaktura.TrN_OpeZalID = 9;
|
|---|
| 496 | nowaFaktura.TrN_TS_Zal = EXPOfaktura.TERMIN_ZAPLATY;
|
|---|
| 497 | nowaFaktura.TrN_OpeModID = 9;
|
|---|
| 498 | nowaFaktura.TrN_TS_Mod = EXPOfaktura.TERMIN_ZAPLATY;
|
|---|
| 499 | nowaFaktura.TrN_NotaKorPrzed = "";
|
|---|
| 500 | nowaFaktura.TrN_NotaKorPo = "";
|
|---|
| 501 | nowaFaktura.TrN_TrSTyp = 3;
|
|---|
| 502 | nowaFaktura.TrN_RazemNettoWal = sumaNETTO;
|
|---|
| 503 | nowaFaktura.TrN_Waluta = "";
|
|---|
| 504 | nowaFaktura.TrN_KursNumer = 2;
|
|---|
| 505 | nowaFaktura.TrN_KursL = (decimal)1.00;
|
|---|
| 506 | nowaFaktura.TrN_KursM = 1;
|
|---|
| 507 | nowaFaktura.TrN_PodNazwa3 = "";
|
|---|
| 508 | nowaFaktura.TrN_OdbNazwa3 = "";
|
|---|
| 509 | nowaFaktura.TrN_Centrala = 0;
|
|---|
| 510 | nowaFaktura.TrN_PodmiotGLN = "";
|
|---|
| 511 | nowaFaktura.TrN_OdbiorcaGLN = "";
|
|---|
| 512 | nowaFaktura.TrN_NumerPelnyPrw = "";
|
|---|
| 513 | nowaFaktura.TrN_PlatElemWalSys = 0;
|
|---|
| 514 |
|
|---|
| 515 | nowaFaktura.TrN_RazemVATWal = VAT * 100;
|
|---|
| 516 | nowaFaktura.TrN_RazemBruttoWal = (1 + VAT) * nowaFaktura.TrN_RazemNetto;
|
|---|
| 517 | nowaFaktura.TrN_StaZalId = 1;
|
|---|
| 518 | nowaFaktura.TrN_StaModId = 1;
|
|---|
| 519 | // 'rsnag("TrN_PodNipKraj=""' @P84 varchar(1) ''
|
|---|
| 520 | // 'rsnag("TrN_OdbNipKraj="" ' @P85 varchar(1) ''
|
|---|
| 521 | nowaFaktura.TrN_KodTransakcji = "";
|
|---|
| 522 |
|
|---|
| 523 | //???
|
|---|
| 524 | DateTime datadok = DateTime.Now;
|
|---|
| 525 | nowaFaktura.TrN_DataTransportu = datadok;
|
|---|
| 526 | nowaFaktura.TrN_KodKraju = "";
|
|---|
| 527 | nowaFaktura.TrN_Anulowany = 0;
|
|---|
| 528 | nowaFaktura.TrN_TerminZwrotuKaucji = datadok.AddDays(30);
|
|---|
| 529 | nowaFaktura.TrN_PlatKaucje = 0;
|
|---|
| 530 | nowaFaktura.TrN_TaxFreePotwierdzony = 0;
|
|---|
| 531 | nowaFaktura.TrN_VatDlaDokWal = 0;
|
|---|
| 532 |
|
|---|
| 533 | if (!EXPOfaktura.Iswaluta_bruttoNull() && EXPOfaktura.waluta_brutto > 0)
|
|---|
| 534 | {
|
|---|
| 535 | nowaFaktura.TrN_Export = 7;
|
|---|
| 536 | nowaFaktura.TrN_WartoscZakupu = 0;
|
|---|
| 537 | nowaFaktura.TrN_RazemVATWal = VAT * 100;
|
|---|
| 538 | nowaFaktura.TrN_RazemBruttoWal = (decimal)EXPOfaktura.waluta_brutto;
|
|---|
| 539 | nowaFaktura.TrN_RazemNettoWal = ((decimal)EXPOfaktura.waluta_brutto / (1 + VAT));
|
|---|
| 540 | nowaFaktura.TrN_Waluta = EXPOfaktura.Iswaluta_mianoNull() ? "" : EXPOfaktura.waluta_miano;
|
|---|
| 541 | nowaFaktura.TrN_KursL = EXPOfaktura.Iswaluta_kursNull() ? 1M : (decimal)EXPOfaktura.waluta_kurs;
|
|---|
| 542 | nowaFaktura.TrN_KursM = 1;
|
|---|
| 543 | nowaFaktura.TrN_KursNumer = 1;
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | CDNDataset.TraNag.AddTraNagRow(nowaFaktura);
|
|---|
| 547 |
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | public void DodajVAT(CDNDataSet.TraNagRow naglowekFaktury, decimal sumaNetto, decimal stawkaVAT)
|
|---|
| 551 | {
|
|---|
| 552 | CDNDataSet.TraVatRow nowyVat = (CDNDataSet.TraVatRow)CDNDataset.TraVat.NewRow();
|
|---|
| 553 |
|
|---|
| 554 | nowyVat.TrV_TrNID = naglowekFaktury.TrN_TrNID;
|
|---|
| 555 | nowyVat.TrV_Stawka = stawkaVAT * 100;
|
|---|
| 556 | nowyVat.TrV_Flaga = 2;
|
|---|
| 557 | nowyVat.TrV_Zrodlowa = 0.00M;
|
|---|
| 558 | nowyVat.TrV_Netto = sumaNetto;
|
|---|
| 559 | nowyVat.TrV_VAT = stawkaVAT * sumaNetto;
|
|---|
| 560 | nowyVat.TrV_NettoWal = sumaNetto;
|
|---|
| 561 | nowyVat.TrV_VATWal = stawkaVAT * sumaNetto;
|
|---|
| 562 | nowyVat.TrV_Typ = 0;
|
|---|
| 563 |
|
|---|
| 564 | if (naglowekFaktury.TrN_Export == 7)
|
|---|
| 565 | {
|
|---|
| 566 | nowyVat.TrV_Flaga = 4;
|
|---|
| 567 | nowyVat.TrV_VATWal = naglowekFaktury.TrN_RazemBruttoWal - naglowekFaktury.TrN_RazemNettoWal;
|
|---|
| 568 | nowyVat.TrV_NettoWal = naglowekFaktury.TrN_RazemNettoWal;
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | CDNDataset.TraVat.AddTraVatRow(nowyVat);
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | public bool isNumeric(string a)
|
|---|
| 575 | {
|
|---|
| 576 | Regex reNum = new Regex(@"^\d+$");
|
|---|
| 577 | return reNum.Match(a).Success;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | public bool istniejeKorekta()
|
|---|
| 581 | {
|
|---|
| 582 | return false;
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | //przyszle okresy
|
|---|
| 586 | public int podajIDKategorii(int rok, int ms)
|
|---|
| 587 | {
|
|---|
| 588 | switch (rok)
|
|---|
| 589 | {
|
|---|
| 590 | case 2008:
|
|---|
| 591 | switch (ms)
|
|---|
| 592 | {
|
|---|
| 593 | case 6:
|
|---|
| 594 | return 107;
|
|---|
| 595 | case 7:
|
|---|
| 596 | return 108;
|
|---|
| 597 | case 8:
|
|---|
| 598 | return 109;
|
|---|
| 599 | case 9:
|
|---|
| 600 | return 110;
|
|---|
| 601 | case 10:
|
|---|
| 602 | return 111;
|
|---|
| 603 | case 11:
|
|---|
| 604 | return 112;
|
|---|
| 605 | case 12:
|
|---|
| 606 | return 113;
|
|---|
| 607 | }
|
|---|
| 608 | break;
|
|---|
| 609 | case 2009:
|
|---|
| 610 | switch (ms)
|
|---|
| 611 | {
|
|---|
| 612 | case 1:
|
|---|
| 613 | return 121;
|
|---|
| 614 | case 2:
|
|---|
| 615 | return 122;
|
|---|
| 616 | case 3:
|
|---|
| 617 | return 123;
|
|---|
| 618 | case 4:
|
|---|
| 619 | return 124;
|
|---|
| 620 | case 5:
|
|---|
| 621 | return 125;
|
|---|
| 622 | }
|
|---|
| 623 | break;
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | return 1;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | public string PodajKrajNIP(string NIP)
|
|---|
| 630 | {
|
|---|
| 631 | string nip = NIP.Replace(" ", "").Replace("-", "").Trim();
|
|---|
| 632 |
|
|---|
| 633 | if (polskiNIP(nip))
|
|---|
| 634 | {
|
|---|
| 635 | return "PL";
|
|---|
| 636 | }
|
|---|
| 637 | if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
|
|---|
| 638 | {
|
|---|
| 639 | return nip.Substring(0, 2);
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | return "";
|
|---|
| 643 | }
|
|---|
| 644 |
|
|---|
| 645 | public string PodajNumerNIP(string NIP)
|
|---|
| 646 | {
|
|---|
| 647 | string nip = NIP.Replace(" ", "").Replace("-", "").Trim();
|
|---|
| 648 |
|
|---|
| 649 | if (polskiNIP(nip))
|
|---|
| 650 | {
|
|---|
| 651 | return nip.Length > 13 ? nip.Substring(0, 13) : nip;
|
|---|
| 652 | }
|
|---|
| 653 | if ((nip.Length >= 2) && (!isNumeric(nip.Substring(0, 2))))
|
|---|
| 654 | {
|
|---|
| 655 | return nip.Length > 15 ? nip.Substring(2, 13) : nip.Substring(2, nip.Length - 2);
|
|---|
| 656 | }
|
|---|
| 657 | return nip.Length > 13 ? nip.Substring(0, 13) : nip;
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | public bool polskiNIP(string nip)
|
|---|
| 661 | {
|
|---|
| 662 | int[] wagi = new int[] { 6, 5, 7, 2, 3, 4, 5, 6, 7 };
|
|---|
| 663 |
|
|---|
| 664 | int suma = 0;
|
|---|
| 665 | string shortNIP = nip.Replace(" ", "").Replace("-", "").Trim();
|
|---|
| 666 |
|
|---|
| 667 | if ((shortNIP.Length == 10) && isNumeric(shortNIP))
|
|---|
| 668 | {
|
|---|
| 669 |
|
|---|
| 670 | for (int i = 0; i <= 8; i++)
|
|---|
| 671 | {
|
|---|
| 672 | int iloczyn = Convert.ToInt32(shortNIP.Substring(i, 1)) * wagi[i];
|
|---|
| 673 | suma = suma + iloczyn;
|
|---|
| 674 | }
|
|---|
| 675 | int kontrolny = suma % 11;
|
|---|
| 676 |
|
|---|
| 677 | if (kontrolny == Convert.ToInt32(shortNIP.Substring(shortNIP.Length - 1, 1)))
|
|---|
| 678 | {
|
|---|
| 679 | return true;
|
|---|
| 680 | }
|
|---|
| 681 | }
|
|---|
| 682 | return false;
|
|---|
| 683 | }
|
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 | #endregion Methods
|
|---|
| 687 |
|
|---|
| 688 | }
|
|---|
| 689 | } |
|---|